This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How i can extract the first hit's title from blast XML-s

Dear All!

i'm new to bioinformatics, and i'm working on an archeogenetics project. My first task, that in a genome part i should search the contaminating, non-human segments. It's a ~500 shotgun sequence.

I would have two questions: -How could i print out just the first hits from the XML. -How could i write a counter to each non-human genes with the number and the name of the organisms?

I work in biopython.

Thank you in advance!

biopython python

Thank you for the fast aswer! I wrote a short code, but my problem, that i don't know how to reach the hit_num part in the xml. My code is:

x=1
for record in NCBIXML.parse(open("full_result.xml")):
    if record.alignments:
        print("\n")
        print("query: %s" %record.query[:100])
        for align in record.alignments:
          if hit_num in hit.alignments == x :
           print("match:%s" %align.title[:100])

So basically i just want to print the query title and the first alignments title.

I can't help you much further, never used the parser. It helps to just print out everything or look what is inside record

So start with:

for record in NCBIXML.parse(open("full_result.xml")):
    print record

Or if you already know that hit_num is inside record.alignments:

for record in NCBIXML.parse(open("full_result.xml")):
    for x in record.alignments:
        print x

0 answers

No answers yet.

Log in to answer this question.