-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_blastfolder2.py
109 lines (86 loc) · 2.94 KB
/
win_blastfolder2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import sys
import re
import glob
import subprocess
from Tkinter import *
from tkFileDialog import *
digits = re.compile(r'(\d+)')
def tokenize(filename):
return tuple(int(token) if match else token
for token, match in
((fragment, digits.search(fragment))
for fragment in digits.split(filename)))
# 'qseqid sseqid pident length qstart qend sstart send evalue bitscore'
def blastit(subj,fold,out,typ,top):
print "Starting.."
subj=subject.get()
print subj
fold=folder.get()
#fold="C:/python/"
print fold
out=outputfolder.get()
#out="C:/python/"
print out
typ=type.get()
print typ
#options=[subj,fold,out,typ,top]
filelist=glob.glob(fold+"/*")
filelist.sort(key=tokenize)
print filelist
for f in filelist:
outname = out+"\\"+f.split("\\")[-1]+".blast"
print outname
if typ == "blastp":
p1= subprocess.Popen('blastp -query %s -subject %s -out %s -outfmt "6 qseqid sseqid pident length slen qstart qend sstart send evalue bitscore" ' %(f,subj,outname), shell=True).wait()
if typ == "blastn":
p1= subprocess.Popen('blastn -task blastn -query %s -subject %s -out %s -outfmt "6 qseqid sseqid pident length slen qstart qend sstart send evalue bitscore" ' %(f,subj,outname), shell=True).wait()
print "Done.. blast again or ctrl-c to quit"
top=Tk()
top.wm_title("Blast a folder utility")
subject = StringVar()
subject.set("reference")
folder=StringVar()
folder.set("C:/python/")
outputfolder = StringVar()
outputfolder.set("C:/python/")
type = StringVar()
type.set("blastn")
offset=100
L1 = Label(top, text="Reference fasta file")
L1.grid(row=1, column=1, sticky=W)
E1 = Entry(top, textvariable=subject)
E1.grid(row=1, column=2)
B1=Button(top,text="Browse",command=lambda: subject.set(askopenfilename())).grid(row=1, column=3)
L2 = Label(top, text="Folder of fasta files to blast")
L2.grid(row=2, column=1, sticky=W)
E2 = Entry(top, textvariable=folder)
E2.grid(row=2, column=2)
B2 = Button(top,text="Browse",command=lambda: folder.set(askdirectory())).grid(row=2, column=3)
L3 = Label(top, text="Output folder")
L3.grid(row=3, column=1, sticky=W)
E3 = Entry(top, textvariable=outputfolder)
E3.grid(row=3, column=2)
B3 = Button(top,text="Browse",command=lambda: outputfolder.set(askdirectory())).grid(row=3, column=3)
L4 = Label(top, text="blast type: \nblastn, blastp, or blastx")
L4.grid(row=4, column=1, sticky=W)
E4 = Entry(top, textvariable=type)
E4.grid(row=4, column=2)
print "Starting.."
subj=subject.get()
print subj
fold=folder.get()
#fold="C://python//stx-phages"
print fold
out=outputfolder.get()
print out
typ=type.get()
print typ
options=[subj,fold,out,typ,top]
B4 = Button(top,text="Run Blast", command=lambda: blastit(*options)).grid(row=5, column=4)
'''
if subj and fold and out and typ:
B4.config(state='normal')
else:
B4.config(state='disabled')
'''
top.mainloop()