-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblast.py
More file actions
53 lines (39 loc) · 1.59 KB
/
blast.py
File metadata and controls
53 lines (39 loc) · 1.59 KB
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
52
53
import subprocess
def create_blast_database(fasta_str, save_path):
"""
:param fasta_str:
:param save_path:
:return:
"""
with open(save_path + 'fasta.txt', 'w') as f:
f.write(fasta_str)
f.close()
database_filename = save_path + '_database'
# creation of the makeblastdb command line
makeblastdb_cline = subprocess.Popen(['/ncbi-blast-2.7.1+/bin/makeblastdb.exe',
'-in', save_path + 'db_fasta.txt', '-parse_seqids', '-dbtype', 'nucl', '-out',
database_filename], stdout=subprocess.PIPE)
# calls the makeblastdb command line and cleans up unnecessary files
makeblastdb_cline.communicate()
return database_filename
def blast_n(fasta_str, save_path, database_filename):
"""
:param fasta_str:
:param save_path:
:param database_filename:
:return:
"""
with open(save_path, 'w') as f:
f.write(fasta_str)
f.close()
# generate unique filename for query
blast_output_file_path = save_path[:-4] + '.xml'
print(blast_output_file_path)
print(save_path)
# creation of the blast command line
blastp_cline = subprocess.Popen(['ncbi-blast-2.7.1+/bin/blastn.exe', '-task',
'blastn-short', '-out', blast_output_file_path, '-outfmt', '5', '-query',
save_path, '-db', database_filename], stdout=subprocess.PIPE)
# calling of the blast command line and cleans up unnecessary files
blastp_cline.communicate()
return blast_output_file_path