How To Get Number Of Hit For A Query??
4
0
Entering edit mode
12.4 years ago
Aziz ▴ 10

hi , i'm using biopython to parse my blast xml output i make condition print on the number of for query. i print my query and sbject if the query have only one hit. but it's not working here is my script please help. thanks

result_handle = open("result.xml")
blast_records = NCBIXML.parse(result_handle)
 for blast_record in blast_records:
    for alignment in blast_record.alignments:
           for hsp in alignment.hsps:
              if(hsp.num_alignments == 1):
                   print "Query:",blast_record.query
                   print "subjet:",alignment.hit_def
                   print "length:", alignment.length
                   print "nombre de gaps:",hsp.gaps
blast xml output • 4.5k views
ADD COMMENT
0
Entering edit mode

Please indent lines of code with 4 or more spaces to make it readable.

ADD REPLY
0
Entering edit mode

And please elaborate: what are you trying to do, what is the result you want to get, and what do you get instead? In this form, it is not clear what you're asking at all.

ADD REPLY
0
Entering edit mode
12.4 years ago
Fabian Bull ★ 1.3k

I always do it with the commandline:

cut -f 1 blastFile | grep queryId | sort -u | wc

this example works for tabular output. (-m 8). For XML just drop the cut.

ADD COMMENT
0
Entering edit mode
12.4 years ago

It's not clear to me if you want to find all the HSPs for one HIT or if you want to find the result having one HSP for one Hit. However, the following XSLT stylesheet prints all the HSPs if there is only one hit.


<xsl:stylesheet xmlns:xsl="&lt;a href=" http:="" www.w3.org="" 1999="" XSL="" Transform"="" rel="nofollow">http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    >

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:apply-templates select="BlastOutput"/>
  </xsl:template>

  <xsl:template match="BlastOutput">
  <xsl:if test="count(BlastOutput_iterations/Iteration/Iteration_hits/Hit)=1">
    <xsl:variable name="q" select="BlastOutput_query-def"/>
    <xsl:variable name="h" select="BlastOutput_iterations/Iteration/Iteration_hits/Hit[1]/Hit_def"/>
    <xsl:for-each select="BlastOutput_iterations/Iteration/Iteration_hits/Hit[1]/Hit_hsps/Hsp">
        <xsl:value-of select="$q"/>
        <xsl:text>  </xsl:text>
        <xsl:value-of select="$h"/>
        <xsl:text>  </xsl:text>
        <xsl:value-of select="Hsp_align-len"/>
        <xsl:text>  </xsl:text>
        <xsl:value-of select="Hsp_gaps"/>
    <xsl:text>
</xsl:text>
    </xsl:for-each>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

Usage:

$ xsltproc --novalid stylesheet.xsl blast.xml

No definition line  Homo sapiens zinc finger CCCH-type containing 7B (ZC3H7B), mRNA 295 8
ADD COMMENT

Login before adding your answer.

Traffic: 2987 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