parsing hammer 2.3.2 results using biopython
2
0
Entering edit mode
10.1 years ago
frcamacho ▴ 210

Hi there,

I want to use SearchIO in Biopython to parse hmmer results. I have seen perl scripts, but I am not familiar with perl to understand how SearchIO works. Right now, what I am doing is a sorta hacky way, but running the hmmersearch and then outputing the results in a temp file to then parse the results. If anyone can explain how searchIO works in python and possible show some code that would be much appreciated.

Thanks!

biopython hmmer • 6.0k views
ADD COMMENT
3
Entering edit mode
9.8 years ago
frcamacho ▴ 210

Sorry for the late response, but this helped a lot!

To access the hmmer parsers from Biopython use: from Bio import SearchIO

with open (hmmFile,'rU') as handle: 
    for record in SearchIO.parse(handle, 'hmmer3-text'):
        query_id = record.id #seqID from fasta 
        hits = record.hits 
        num_hits = len(hits) # how many pfam hits per queries? 

        if num_hits > 0: # if there are more than 0 hits per query then we need to extract the info 
            for I in range(0,num_hits): 
                hmm_name = hits[i].id # hit name
                hmm_description = hits[i].description # hit decription 
                current_evalue = hits[i].evalue # evalue of hit

    handle.close() # close file
ADD COMMENT
0
Entering edit mode

For more attributes of HMMER object to parse look at post: Biopython SearchIO HMMer 3 parsing, HMM model length?

ADD REPLY
0
Entering edit mode

Hi, I am trying to using this script to parse hmmer results, but every time, I run it, it show for "hits=record.hits": AttributeError: 'Hit' object has no attribute 'hits' could you help me?

ADD REPLY
0
Entering edit mode

Hi, this script works with hmmer3-text format (https://lifebit.gitbook.io/cloudos/pipelines-documentations-and-examples-1/docker-pipelines-and-tools/hmmer) Is this the format you are trying to parse? If not, SearchIO has the following options, you can change the code to other forms

for record in SearchIO.parse(handle, 'hmmer3-text'):

hmmer3-domtab

1.61    1.61    1.61    HMMER3.0 domain table output format. The name hmmer3-domtab per se is in fact not used, since the program name has to be specified. For example, when parsing hmmscan output, the format name would be hmmscan-domtab.

hmmer3-tab  1.61    1.61    1.61    HMMER 3.0 table output format.

hmmer3-text 1.61    n/a 1.61    HMMER 3.0 plain text output format.

hmmer2-text 1.61    n/a 1.61    HMMER 2.x plain text output format.
ADD REPLY
0
Entering edit mode

Thank you for answering my questions

ADD REPLY
2
Entering edit mode
10.1 years ago
Peter 6.0k

There is an entire chapter on Biopython's SearchIO in the Biopython Tutorial, with examples, so I urge you to try that:

And yes, you can run hmmersearch, save the output to a file, parse the file. Or (and this is more advanced), you can try running hmmersearch from Python with the output to stdout, and parsing that directly within Python.

ADD COMMENT

Login before adding your answer.

Traffic: 2420 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6