-
Notifications
You must be signed in to change notification settings - Fork 1
/
ncbiRemoteblast.py
51 lines (44 loc) · 1.69 KB
/
ncbiRemoteblast.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
'''
@Description This script can be used to run blast through internet
@Author This script was developed by Ginsea Chen (ginseachen@hotmail.com) in CATAS
'''
from Bio.Blast import NCBIWWW
from Bio import SeqIO
from time import clock
import argparse
import os
def parse_args():
parser = argparse.ArgumentParser(usage="%(prog)s[options]")
parser.add_argument("--fasta",default="test.fa",help="Your fasta file")
parser.add_argument("--type",default="prot",help="Your seqs type: prot or nucl")
return parser.parse_args()
def create_dir():
try:
os.stat("split_xml")
except OSError:
os.mkdir("split_xml")
def run_blast(fasta,type):
if type == "prot":
for seqs in SeqIO.parse(fasta,"fasta"):
clock()
out = open("split_xml/%s.xml"%str(seqs.id),"w")
ncbi = NCBIWWW.qblast(program="blastp",database="nr",sequence=str(seqs.seq),format_type="XML",ncbi_gi=str(seqs.id), alignments=20,word_size=3)
out.write(ncbi.read())
print "%s\t%f"%(str(seqs.id),float(clock()))
elif type == "nucl":
for seqs in SeqIO.parse(fasta,"fasta"):
clock()
out = open("split_xml/%s.xml"%str(seqs.id),"w")
ncbi = NCBIWWW.qblast(program="blastp",database="nr",sequence=str(seqs.seq),format_type="XML",ncbi_gi=str(seqs.id), alignments=20,word_size=3)
out.write(ncbi.read())
print "%s\t%f"%(str(seqs.id),float(clock()))
def main():
argser = parse_args()
if argser.type not in ["prot","nucl"]:
print "You should type 'prot' or 'nucl'"
exit(1)
create_dir()
run_blast(argser.fasta,argser.type)
if __name__ == "__main__":
main()