-
Notifications
You must be signed in to change notification settings - Fork 0
/
blast_handler.py
35 lines (26 loc) · 1.11 KB
/
blast_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
from Bio.Blast import NCBIWWW, NCBIXML
from Bio.Blast.Applications import NcbiblastpCommandline
def blast_local(query, output="/home/jasper/Thesis/blast/blast_results.xml"):
# path to local blast binary
blastp_path = "/home/jasper/Thesis/blast/ncbi-blast-2.15.0+/bin/blastp"
# path to local blast database
database_path = "/home/jasper/Thesis/blast/database/swissprot"
# create a blast query command
blastp_cline = NcbiblastpCommandline(cmd=blastp_path, query=query, db=database_path, evalue=0.01, outfmt=5, out=output)
# execute the command
stdout, stderr = blastp_cline()
# parse the XML output
result_handle = open(output)
return result_handle
def blast_parse(record, local=True):
try:
if local:
result_handle = blast_local(record.seq)
else:
result_handle = NCBIWWW.qblast("blastp", "swissprot", record.seq, expect=0.01, filter=True, word_size=6)
#parse the result
blast_record = NCBIXML.read(result_handle)
return blast_record
except Exception as e:
logging.error(f"Error: {e}")