Question: parsing hammer 2.3.2 results using biopython
0
gravatar for frcamacho
6.0 years ago by
frcamacho190
United States
frcamacho190 wrote:

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! 

hmmer biopython • 3.4k views
ADD COMMENTlink modified 5.7 years ago • written 6.0 years ago by frcamacho190
2
gravatar for frcamacho
5.7 years ago by
frcamacho190
United States
frcamacho190 wrote:

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 COMMENTlink modified 4.3 years ago • written 5.7 years ago by frcamacho190

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

ADD REPLYlink written 4.3 years ago by frcamacho190

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 REPLYlink written 4 weeks ago by lwu80

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 REPLYlink written 4 weeks ago by frcamacho190

Thank you for answering my questions

ADD REPLYlink written 26 days ago by lwu80
2
gravatar for Peter
6.0 years ago by
Peter5.8k
Scotland, UK
Peter5.8k wrote:

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 COMMENTlink written 6.0 years ago by Peter5.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2231 users visited in the last hour