This example is adapted from the [fetchMGs](https://github.com/motu-tool/fetchMGs/) Perl script used in [mOTU](https://motu-tool.org/) to extract the 40 single-copy universal marker genes from a genome, annotating proteins to find the highest scoring proteins mapping to each of these marker genes.
In this notebook, we show how to reproduce this kind of analysis, using `pyhmmer` instead of HMMER3 to perform the alignments and extract the bit scores.
<divclass="alert alert-info">
References
*[Ciccarelli FD, Doerks T, von Mering C, Creevey CJ, Snel B, Bork P. *Toward automatic reconstruction of a highly resolved tree of life.* Science. 2006 Mar 3;311(5765):1283-7. Erratum in: Science. 2006 May 5;312(5774):697.](https://pubmed.ncbi.nlm.nih.gov/16513982/)
*[Sorek R, Zhu Y, Creevey CJ, Francino MP, Bork P, Rubin EM. *Genome-wide experimental determination of barriers to horizontal gene transfer.* Science. 2007 Nov 30;318(5855):1449-52.](https://pubmed.ncbi.nlm.nih.gov/17947550/)
</div>
%% Cell type:code id:f21f9ece tags:
``` python
importpyhmmer
pyhmmer.__version__
```
%% Cell type:markdown id:37db1b70 tags:
## Getting the cutoffs
Each HMM has been calibrated and contains custom cutoffs, but they are not in Pfam format, so we need to use them externaly. Let's start by downloading the file with these cutoffs from the GitHub repository of `fetchMG`:
Since the HMMs for the universal marker genes are also hosted on the `fetchMG` GitHub repository, we can download them from there too. `pyhmmer.plan7.HMMFile` supports reading from a file-handle, so we can parse each HMM as we download it. We also use the occasion to update the bitscore cutoffs specific to each HMM that we just obtained in the previous step.
Now we need protein sequences to annotate. Let's use our set of protein sequences identified in the chromosome of [Anaerococcus provencensis](https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=938293).
With the proteins loaded, let's make a `namedtuple` that will contain the data we need to extract for each `hmmsearch` hit: the name of the query gene, the name of the marker gene which produced a hit, and the bitscore for the alignment.
Now we can run the search pipeline: we annotate all the proteins will all the HMMs using the `pyhmmer.hmmsearch` function. Each HMM gives us a `TopHits` instance to process. Note that we run the search pipeline using the *trusted* bitscore cutoffs so that the cutoffs that we manually set on each HMMs are used to filter the results. We only keep hits that fall under the inclusion threshold for each HMM.
Now that we have all the hits that pass the bitscore thresholds, we can create a dictionary that maps each query protein to its highest scoring bitscore alignment, like in the original script. If a protein has alignments to two different marker genes with the same score, that query is ignored.
All set! You can now use this list of identifiers to filter the initial protein array, to write proteins grouped by marker genes in a FASTA file, compute alignment against the [mOTUs database](https://zenodo.org/record/3364101), or just save it for future use.