Skip to content

Instantly share code, notes, and snippets.

@manrysh
Last active June 1, 2016 10:29
Show Gist options
  • Save manrysh/0f85ce834e36f68266b909132fb9056b to your computer and use it in GitHub Desktop.
Save manrysh/0f85ce834e36f68266b909132fb9056b to your computer and use it in GitHub Desktop.
Blast result processing
#Multiple alignment result of Blast
#query/alignment/identity/positive/coverage are collected
#Only for the best result
from Bio.Blast import NCBIStandalone
import os, sys
path='/.../.../...'
for i in os.listdir(path):
result_handle = open(str(i))
blast_parser = NCBIStandalone.BlastParser()
blast_iterator = NCBIStandalone.Iterator(result_handle, blast_parser)
#blast_record = blast_iterator.next()
f = open(str(i)+'.out','w')
for blast_record in blast_iterator:
query = "".join(blast_record.query.replace('\n',' '))
try:
blast_record.descriptions[0]!=''
for alignment in blast_record.alignments:
for hsp in alignment.hsps:
identity = round(100* float(hsp.identities[0])/float(hsp.identities[1]),1)
positive = round(100* float(hsp.positives[0])/float(hsp.positives[1]),1)
coverage = round(100* float(hsp.align_length)/float(blast_record.query_letters),1)
#if identity > 95 and identity < 100:
f.write(str(query)+' '+str(alignment.title)+' '+ str(identity)+' '+str(positive)+' '+str(coverage)+'\n')
break
break
except IndexError:
f.write(str(query)+' None 0 0 0'+'\n')
f.close()
result_handle.close()
@esrever10
Copy link

屌屌的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment