-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStretchFinder.py
1266 lines (1058 loc) · 42.7 KB
/
StretchFinder.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
from tkinter import filedialog
from tkinter import *
import tkinter as tk
import tkinter as ttk
import os
import urllib.parse
import urllib.request
from os.path import join as pjoin
from tkinter import messagebox
from tkinter.ttk import *
from tkinter import *
import tkinter as tk
from tkinter import ttk
from Utilities.Functions import *
import webbrowser
import platform
class CreateToolTip(object):
"""
create a tooltip for a given widget
"""
def __init__(self, widget, text='widget info'):
self.waittime = 500 #miliseconds
self.wraplength = 1500 #pixels
self.widget = widget
self.text = text
self.widget.bind("<Enter>", self.enter)
self.widget.bind("<Leave>", self.leave)
self.widget.bind("<ButtonPress>", self.leave)
self.id = None
self.tw = None
def enter(self, event=None):
self.schedule()
def leave(self, event=None):
self.unschedule()
self.hidetip()
def schedule(self):
self.unschedule()
self.id = self.widget.after(self.waittime, self.showtip)
def unschedule(self):
id = self.id
self.id = None
if id:
self.widget.after_cancel(id)
def showtip(self, event=None):
x = y = 0
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_rootx() + 25
y += self.widget.winfo_rooty() + 20
# creates a toplevel window
self.tw = tk.Toplevel(self.widget)
# Leaves only the label and removes the app window
self.tw.wm_overrideredirect(True)
self.tw.wm_geometry("+%d+%d" % (x, y))
label = tk.Label(self.tw, text=self.text, justify='left',
background="#ffffff", relief='solid', borderwidth=1,
wraplength = self.wraplength)
label.pack(ipadx=1)
def hidetip(self):
tw = self.tw
self.tw= None
if tw:
tw.destroy()
LARGE_FONT= ("Verdana", 12)
NORM_FONT= ("Verdana", 10)
SMALL_FONT= ("Verdana", 8)
value=0
selected=None
global selccds
global selid
selid=False
selccds=False
if platform.system()=="Linux":
directori=os.getcwd()
directori=directori.replace("\\", "/")
else:
directori=os.getcwd()
directori=directori.replace("\\", "/")
print (directori)
def popupmsg(msg):
quote=msg
messagebox.showinfo('FASTA file Creator', quote)
inputRW=""
outRW=""
#read Codon txt
codons= open(directori+"/Utilities/conversionCodonstoR.txt", "r")
PtoR={} #el que tenim a python al ordre de R - per passar a codi
RtoP={} #de R a python - per marcar
for line in codons:
line=line.strip()
cod=line.split(";")
PtoR[int(cod[0])]=int(cod[1])
RtoP[int(cod[1])]=int(cod[0])
codons.close()
codons=open(directori+"/Utilities/allcodsAA.txt")
codonList=[]
for line in codons:
line=line.strip()
cod=line.split(" - ")
codonList.append(cod[1])
codons.close()
def runp():
def select_file(label):
global inputRW
filename = filedialog.askopenfilename(title="Select Fasta file")
label.configure(text=filename)
inputRW=filename
def select_dir(label):
global outRW
filename = filedialog.askdirectory(title="Select Output Directory")
label.configure(text=filename)
outRW=filename
def create_cbutsd(label):
root = Toplevel()
root.title("d Codons")
name=directori+"/Utilities/allCodsAA.txt"
f9000=open(name,'r')
listaa1=f9000.readlines()
cbuts_textd = listaa1
cbutsd = []
i=0
j=0
varis=[]
for index, item in enumerate(cbuts_textd):
var=IntVar()
cbutsd.append(Checkbutton(root, text = item, variable=var))
cbutsd[index].grid(column=i,row=j, padx=10)
j=j+1
if j==4:
i=i+1
j=0
varis.append(var)
def deselect_all():
for i in cbutsd:
i.deselect()
def select_dTAPS():
deselect_all()
listdTAPS=[37,38,40,21,22,24,5,6,8,53,54,56] #R format
for i in listdTAPS:
e=RtoP[i]
e=e-1
cbutsd[e].select()
def select_dLIVR_dTAPS():
deselect_all()
listdTAPSLIVR=[37,38,40,21,22,24,5,6,8,53,54,56,29,30,32,45,46,48,25,26,28,13,14,16]
for i in listdTAPSLIVR:
e=RtoP[i]
e=e-1
cbutsd[e].select()
def select_all():
for i in cbutsd:
i.select()
def okd():
yesno=[]
for i in varis:
yesno.append(i.get())
n=1
rlist=[]
for i in yesno:
if i:
rlist.append(n)
n=1+n
print(rlist)
rlist_R=[]
for i in rlist:
r=PtoR[i]
rlist_R.append(r)
awrite="dtCod=c("
for i in rlist_R:
awrite=awrite+str(i)+","
awrite=awrite[:-1]
awrite=awrite+")"
label.configure(text=awrite)
root.destroy()
nnba4=Button(root , text="I34 (TAPS)", command=select_dTAPS)
nnba4.grid(column=2,row=6)
nnba6=Button(root , text="I34", command=select_dLIVR_dTAPS)
nnba6.grid(column=1,row=6)
nnba7=Button(root, text="Unselect all", command=deselect_all)
nnba7.grid(column=4,row=6)
nnba9=Button(root, text="Select all", command=select_all)
nnba9.grid(column=3,row=6)
nnba8=Button(root, text="OK", command=okd)
nnba8.grid(column=5,row=6)
mainloop()
def create_cbutsa(label):
root = Toplevel()
root.title("a Codons")
name=directori+"/Utilities/allCodsAA.txt"
f900=open(name,'r')
listaa=f900.readlines()
cbuts_text = listaa
cbuts = []
i=0
j=0
varis=[]
for index, item in enumerate(cbuts_text):
var=IntVar()
cbuts.append(Checkbutton(root, text = item, variable=var))
cbuts[index].grid(column=i,row=j, padx=10)
j=j+1
if j==4:
i=i+1
j=0
varis.append(var)
def deselect_all():
for i in cbuts:
i.deselect()
def select_aTAPS():
deselect_all()
listaTAPS=[37,38,39,40,21,22,23,24,5,6,7,8,53,54,55,56]#format R
for i in listaTAPS:
e=RtoP[i]
e=e-1
cbuts[e].select()
def select_aLIVR_aTAPS():
deselect_all()
listaTAPSLIVR=[37,38,39,40,21,22,23,24,5,6,7,8,53,54,55,56,29,30,31,32,61,63,13,14,16,45,46,47,48,25,26,27,28,9,11] #format R
for i in listaTAPSLIVR:
e=RtoP[i]
e=e-1
cbuts[e].select()
def select_all():
for i in cbuts:
i.select()
def oka():
yesno=[]
for i in varis:
yesno.append(i.get())
n=1
rlist=[]
for i in yesno:
if i:
rlist.append(n)
n=1+n
print(rlist) #format P
rlist_R=[]
for i in rlist:
r=PtoR[i]
rlist_R.append(r)
print(rlist_R)
awrite="atCod=c("
for i in rlist_R:
awrite=awrite+str(i)+","
awrite=awrite[:-1]
awrite=awrite+")"
label.configure(text=awrite)
root.destroy()
nba4=Button(root , text="I34 (TAPS)", command=select_aTAPS)
nba4.grid(column=2,row=6)
nba6=Button(root , text="I34", command=select_aLIVR_aTAPS)
nba6.grid(column=1,row=6)
nba7=Button(root, text="Unselect all", command=deselect_all)
nba7.grid(column=4,row=6)
nba9=Button(root, text="Select all", command=select_all)
nba9.grid(column=3,row=6)
nba8=Button(root, text="OK", command=oka)
nba8.grid(column=5,row=6)
mainloop()
def test():
global inputRW
name=outRW+"/run.R"
run=open(name, "w")
run.write("rm(list=ls())"+"\n")
run.write("options(stringsAsFactors=FALSE)"+"\n"+ "options(warn=-1)\n")
if platform.system() !="Windows": #mirem quin OS es
run.write("setFunc <- '"+ directori+"/Utilities/scripts/functions/strLibrary.R'\n")
core=", core=8"
else:
run.write("setFunc <- '"+ directori+"/Utilities/scripts/functions/strLibrary.R'\n")
core=", core=1"
run.write("setwd('"+ directori+"/Utilities/scripts/functions')\n")
run.write("source(setFunc)"+"\n")
run.write("organ<-'humanCCDS'"+"\n")
thredef=spin.get()
wsdef=spin1.get()
if outRW=="":
messagebox.showerror("Error", "Please select an output directory!")
return None
if inputRW=="":
messagebox.showerror("Error", "Please select a Fasta File!")
return None
if wsdef == "0":
messagebox.showerror("Error", "Window Size cannot be 0")
return None
if thredef == "0":
messagebox.showerror("Error", "Threshold cannot be 0")
return None
if aw['text'] == "atCod=0":
messagebox.showerror("Error", "Please Select A Codons")
return None
if dw['text'] == "dtCod=0":
messagebox.showerror("Error", "Please Select D Codons")
return None
command="rw(\""+outRW+"\", "+wsdef+", "+thredef+", robust=T, organism=organ, "+ aw['text'] +"," + dw['text'] +", Ethr=" + str(Ethr.get())+core
command=command+", fasta=T, sourceFasta=\""+inputRW+"\""
command=command+", matrix=T"
command=command+", sum=T"
command=command+", info=T"
command=command+")"
run.write(command)
print(command)
run.close()
#We run the program - it can be that in windows it doesn't
os.system('R <' + name + ' --no-save')
def cb(vari):
x= ("variable is {0}".format(vari.get()))
spin = IntVar()
spin1 = IntVar()
rw = Toplevel()
rw.title("Running Windows Module")
rw.geometry('200x350')
mi=IntVar(rw)
mi.set(67)
spin = Spinbox(rw, from_=0, to=100, width=5, textvariable=mi)
spin.grid(column=2,row=3)
bThr=Label( rw , text="Select Threshold")
bThr.grid(column=0,row=3, pady=10)
Thr_Q = Label(rw, text=" ? ", relief="sunken")
Thr_Q.grid(column=4, row=3)
Thr_Q_ttp=CreateToolTip(Thr_Q, "The threshold is the minimum number of selected AA codons to appear in a window")
mi=IntVar(rw)
mi.set(80)
spin1 = Spinbox(rw, from_=0, to=100, width=5, textvariable=mi)
spin1.grid(column=2,row=4)
bWz=Label( rw , text="Select Windows Size")
bWz.grid(column=0,row=4)
Win_Q = Label(rw, text=" ? ", relief="sunken")
Win_Q.grid(column=4, row=4)
Win_Q_ttp=CreateToolTip(Win_Q, "The Window corresponds to a fragment of the sequence with fixed size that will be sliding")
baa1=Button( rw , text="Select AA Codons", command= lambda: create_cbutsa(aw))
baa1.grid(column=0,row=5, columnspan=3, padx=10, pady=10, sticky=W+E)
aw=Label(rw, text="atCod=0")
Cods_A_Q = Label(rw, text=" ? ", relief="sunken")
Cods_A_Q.grid(column=4, row=5)
Cods_A_Q_ttp=CreateToolTip(Cods_A_Q, "Codons from the AA that want to be studied")
baa1=Button( rw , text="Select Affected Codons", command= lambda: create_cbutsd(dw))
baa1.grid(column=0,row=6, columnspan=3, padx=10, pady=10, sticky=W+E)
dw=Label(rw, text="dtCod=0")
Cods_Q = Label(rw, text=" ? ", relief="sunken")
Cods_Q.grid(column=4, row=6)
Cods_Q_ttp=CreateToolTip(Cods_Q, "Codons Affected that want to be selected")
#FASTA DIR
rad2 = Button (rw,text='Select FASTA file',command=lambda: select_file(LFasta))
rad2.grid(column=0,row=1, columnspan=3, padx=10, pady=10, sticky=W+E)
Fasta_Q=Label(rw, text=" ? ", relief="sunken")
Fasta_Q_ttp=CreateToolTip(Fasta_Q, "Fasta file that has to be analized")
Fasta_Q.grid(row=1, column=4)
#OUTPUT DIR
LFasta=Label(rw, text="miau")
bdestiout=Button( rw, text="Select output directory", command= lambda: select_dir(LDir)) #ubiquem els botons
bdestiout.grid(column=0,row=2, columnspan=3, padx=10, pady=10, sticky=W+E)
LDir=Label(rw, text='miau2')
Dir_Q=Label(rw, text=" ? ", relief="sunken")
Dir_Q_ttp=CreateToolTip(Dir_Q, "Directory where all the outputs will be generated")
Dir_Q.grid(row=2, column=4)
LEthr=Label(rw, text="Enrichment Threshold")
LEthr.grid(column=0, row=7)
mi=IntVar(rw)
mi.set(0.8)
Ethr=Spinbox(rw, from_=0.01, to=1.00, width=5, textvariable=mi, increment=0.01, format="%.2f")
Ethr.grid(column=2, row=7)
Ethr_Q=Label(rw, text=" ? ", relief="sunken")
Ethr_Q_ttp=CreateToolTip(Ethr_Q, "Minimum ratio of affected codons that should appear in a window")
Ethr_Q.grid(row=7, column=4)
bok11=Button( rw , text="Accept and run", command=test)
bok11.grid(column=0,row=10, columnspan=3, padx=10, pady=30, sticky=W+E)
rw.mainloop()
path_desti=""
def fastacreator():
def select_IDfile():
global filenameid
global selid
selid=True
print(selid)
IDfile = filedialog.askopenfile( initialdir="C:/", title="select CCDS file", filetypes=(("text files", "*.fna"), ("all files", "*.*")))
filenameid=IDfile.name
popupmsg('ID FILE selected properly!\n')
def select_CCDSfile():
global filenameccds
selccds=True
CCDSfile = filedialog.askopenfile( initialdir="C:/", title="select CCDS file", filetypes=(("text files", "*.fna"), ("all files", "*.*")))
filenameccds=CCDSfile.name
popupmsg('CCDS FILE selected properly!\n')
def select_dir(label):
global path_desti
filename = filedialog.askdirectory(title="Select Output Directory")
label.configure(text=filename)
path_desti=filename
def creation_fastafile():
if path_desti == "":
messagebox.showerror("Error", "Please Select Output Directory")
return None
try:
path_to_file = pjoin(path_desti, 'bigFASTAfile.fa')
f3 = open(path_to_file, "r+")
f3.close()
os.remove('bigFASTAfile.fa')
path_to_file = pjoin(path_desti, 'bigFASTAfile.fa')
f3 = open(path_to_file, "w")
except:
path_to_file = pjoin(path_desti, 'bigFASTAfile.fa')
f3 = open(path_to_file, "w")
try:
path_to_file = pjoin(path_desti, 'smallFASTAfile.fa')
f35 = open(path_to_file, "r+")
f35.close()
os.remove('smallFASTAfile.fa')
path_to_file = pjoin(path_desti, 'smallFASTAfile.fa')
f35 = open(path_to_file, "w")
except:
path_to_file = pjoin(path_desti, 'smallFASTAfile.fa')
f35 = open(path_to_file, "w")
try:
print(selid)
if selid==True:
try:
f00 = open(filenameid, 'r')
except IOError:
messagebox.showerror("Error", "Cannot open ID List file!")
return None
for line in f00:
line=line.strip()
line=line+'\n'
text2.insert(tk.END, line)
t=text2.get(1.0,END)
#text1.insert(tk.END, "Creating Fasta file please wait...")
if selid==False:
t= text2.get(1.0,END)
if len(t) == 1:
messagebox.showerror("Error", "The Uniprot ID list cannot be empty")
return None
#t=t.lstrip()
if selccds==False:
try:
name=directori+"/Utilities/CCDS_nucleotide.current.fna"
tryopen=open(name, "r")
tryopen.close()
except IOError:
messagebox.showerror("Error", "Cannot open CCDS source file.")
return None
if selccds==True:
try:
miau = open(filenameccds, 'r')
miau.close()
except IOError:
messagebox.showerror("Error", "Cannot open CCDS source file.")
return None
f5 = open('IDuniprotCCDS', 'w+')
f6 = open('IDuniprotGeneName', 'w+')
#t=t.strip()
#print(t)
#API GOING TO FROM THE ID LIST TO CCDS CODE
url = "https://www.uniprot.org/uploadlists/"
params = {
"from": "ACC+ID",
"to": "CCDS_ID",
"format": "tab",
"query": t
}
data = urllib.parse.urlencode(params)
data = data.encode("utf-8")
req = urllib.request.Request(url, data)
with urllib.request.urlopen(req) as f:
response = f.read()
writee=(response.decode("utf-8"))
f5.write(writee)
url = "https://www.uniprot.org/uploadlists/"
params = {
"from": "ACC+ID",
"to": "GENENAME",
"format": "tab",
"query": t
}
data = urllib.parse.urlencode(params)
data = data.encode("utf-8")
req = urllib.request.Request(url, data)
with urllib.request.urlopen(req) as f:
response = f.read()
writee2=(response.decode("utf-8"))
f6.write(writee2)
f5.close()
f6.close()
#PUT IN CORRECT FORMAT FROM LIST TO LIST WITH THE | TO CAN MANIPULATE IT
f8 = open('IDuniprotCCDS', 'r')
f7 = open('IDuniprotGeneName', 'r')
f9 = open('IDuniprotCCDSbarra', 'w+')
f10 = open('IDuniprotGeneNamebarra', 'w+')
for line in f8:
line=line.strip()
a,b=line.split()
f9.write(a+"|"+b+"\n")
f8.close()
os.remove('IDuniprotCCDS')
for line in f7:
a,b=line.split()
f10.write(a+"|"+b+"\n")
f7.close()
os.remove('IDuniprotGeneName')
f9.close()
f10.close()
#CHOSE LARGEONE
f = open('IDuniprotCCDSbarra', 'r')
f1 = open('IDuniprotCCDSbarra', 'r')
f2 = open('IDuniprotCCDSbarra', 'r')
f30 = open('UnicIDCCDScode', 'w+')
lines=f.readlines()
f.close()
dictionary= {}
def FASTA_iterator(fasta_filename):
dicctionary1={}
"""A Generator Function that reads a Fasta file. In each iteration, the function must return a tuple with the following format: (identifier, sequence)."""
file = open(fasta_filename, "r")
sequence = ""
for my_line in file:
line = my_line.strip()
if line.startswith(">"):
if not sequence == "":
dicctionary1[name]=sequence
name = line[1:].split("|",1)[0]
sequence = ""
else:
sequence = sequence+"\n" + line
file.close()
dicctionary1[name]=sequence
return dicctionary1
if selccds==False:
try:
name=directori+"/Utilities/CCDS_nucleotide.current.fna"
tryopen=open(name, "r")
tryopen.close()
except IOError:
messagebox.showerror("Error", "Cannot open CCDS source file.")
return None
listccds=FASTA_iterator(name)
if selccds==True:
listccds=FASTA_iterator(filenameccds)
for line in f1:
a,b= line.split("|")
b=b.strip()
dictionary[a]=(b)
ID=0
w1=f2.readline()
f30.write(w1)
max=len(lines)
maxs=0
i=1
#####
while i < max:
a,b=lines[i].split("|")
b=b.strip()
ID=a
if ID in w1:
while ID in w1 and i < max :
ccds=listccds[b] #EL CCDS HA D'estar
canmaxseq=len(ccds)
if maxs<canmaxseq:
maxs=canmaxseq
idmax=ID
w1=f2.readline()
i=i+1
try:
a,b=lines[i].split("|")
b=b.strip()
ID=a
except:
break
idmax=idmax.strip()
w=idmax+dictionary[idmax]
else:
w=lines[i]
f30.write(w)
w1=f2.readline()
i=i+1
print("uwu")
f1.close()
f2.close()
f30.close()
#MARGE TWO LIST CCDS-IDUNIPROT-GENENAME
f9 = open('UnicIDCCDScode', 'r')
f10 = open('IDuniprotGeneNamebarra', 'r')
f11 = open('CCDSIDuniprotGenenamelarge', 'w+')
f12 = open('IDuniprotCCDSbarra', 'r')
f13 = open('CCDSIDuniprotGenename', 'w+')
i=0
dictionary = {}
add=0
gene=0
for line in f10:
if line != ('\n'):
a,b= line.split('|')
dictionary[a]=(b)
print("aqki")
for line in f9:
if line != ('\n'):
c,d=line.split('|')
c=c.strip()
key=c
if key in dictionary:
value=dictionary[key]
line=line.strip()
e,f=line.split('|')
f11.write(f+'|'+e+'|'+value)
else:
line=line.strip()
e,f=line.split('|')
f11.write(f+'|'+e+'|----'+'\n')
f10.close()
f10 = open('IDuniprotGeneNamebarra', 'r')
for line in f10:
if line != ('\n'):
a,b= line.split('|')
dictionary[a]=(b)
for line in f12:
if line != ('\n'):
c,d=line.split('|')
c=c.strip()
key=c
if key in dictionary:
value=dictionary[key]
line=line.strip()
e,f=line.split('|')
f13.write(f+'|'+e+'|'+value)
else:
line=line.strip()
e,f=line.split('|')
f13.write(f+'|'+e+'|----'+'\n')
f9.close()
f10.close()
f11.close()
f12.close()
f13.close()
print("Done")
os.remove('IDuniprotCCDSbarra')
os.remove('IDuniprotGeneNamebarra')
#FASTA FILE CREATION
if selccds==False:
name=directori+"/Utilities/CCDS_nucleotide.current.fna"
f2 = open(name, 'r')
if selccds==True:
f2 = open(filenameccds, 'r')
if selccds==False:
name=directori+"/Utilities/CCDS_nucleotide.current.fna"
listccds=FASTA_iterator(name)
if selccds==True:
listccds=FASTA_iterator(filenameccds)
i=0
dictionary3 = {}
add=0
gene=0
f4 = open('CCDSIDuniprotGenename', 'r')
f40 = open('CCDSIDuniprotGenenamelarge', 'r')
for line in f4:
if line != ("\n"):
a,b,c= line.split('|')
dictionary3[a]=(b,c)
for line in f2:
i=i+1
char=line[:1]
if char == ('>'):
gene=gene+1
key=line[1:].split('|',1)[0]
if line[1:].split("|",1)[0] in dictionary3:
values=dictionary3[key]
iduni=values[0]
genname=values[1]
line=line.strip()
f3.write(line+'|'+iduni+'|'+genname)
add=add+1
writee=listccds[key]
f3.write(writee+'\n')
if selccds==False:
name=directori+"/Utilities/CCDS_nucleotide.current.fna"
listccds=FASTA_iterator(name)
print("Done")
if selccds==True:
filenameccds
listccds=FASTA_iterator(filenameccds)
i=0
dictionary3 = {}
add1=0
gene=0
f2.close()
if selccds==False:
name=directori+"/Utilities/CCDS_nucleotide.current.fna"
f2 = open(name, 'r')
if selccds==True:
f2 = open(filenameccds, 'r')
for line in f40:
if line != ("\n"):
a,b,c= line.split('|')
dictionary3[a]=(b,c)
for line in f2:
i=i+1
char=line[:1]
if char == ('>'):
gene=gene+1
key=line[1:].split('|',1)[0]
if line[1:].split("|",1)[0] in dictionary3:
values=dictionary3[key]
iduni=values[0]
genname=values[1]
line=line.strip()
f35.write(line+'|'+iduni+'|'+genname)
add1=add1+1
writee=listccds[key]
f35.write(writee+'\n')
quote1=add
quote2=add1
if add==0:
text1.insert(tk.END, quote1, 'color')
text1.insert(tk.END, quote2, 'color')
text1.insert(tk.END, ' IDuniprot added in FASTA file created\n\n')
text1.insert(tk.END, 'Please check if the ID introd-uced are valids')
if add!= 0:
text1.insert(tk.END, '\n\nFASTA file created! \nPlease check in the directory selected previously \n\n\n')
text1.insert(tk.END, quote1, 'color')
text1.insert(tk.END, ' IDuniprot added in big FASTA file created\n')
text1.insert(tk.END, quote2, 'color')
text1.insert(tk.END, ' IDuniprot added in small FASTA file created')
f2.close()
f3.close()
f4.close()
f40.close()
os.remove('CCDSIDuniprotGenename')
os.remove('UnicIDCCDScode')
os.remove('IDuniprotCCDSbarra')
os.remove('CCDSIDuniprotGenenamelarge')
popupmsg('FASTA file created, please scroll down the left panel')
except:
popupmsg('Something is wrong!:(, please scroll down the left panel')
text1.insert(tk.END, '\n\nSomething is wrong!Suggestions:\n -Please check your internet connection\n-Please make sure the ID do not have any space at the end(is better to copy directly from excel file)\n')
window=Toplevel()
text1 = tk.Text(window, height=20, width=30)
scroll1 = tk.Scrollbar(window, command=text1.yview)
window.title ( "Retrieve CCDS Fasta Sequence Module")
text1.pack(side=tk.LEFT)
text1.insert(tk.END,'\nWelcome to Retrieve CCDS Fasta Sequence Module!\n', 'big')
quote = '\nPlease select first the direc-tory where you want FASTA file to be created using: \n''1.Select creating directory'' \nand then click \n''2. Ok'''
text1.insert(tk.END, quote, 'color')
text1.pack(side=tk.LEFT)
scroll1.pack(side=tk.LEFT, fill=tk.Y)
text1.configure(yscrollcommand=scroll1.set)
text2 = tk.Text(window, height=20, width=50)
scroll = tk.Scrollbar(window, command=text2.yview)
text2.configure(yscrollcommand=scroll.set)
text2.tag_configure('bold_italics', font=('Arial', 16, 'bold', 'italic'))
text2.tag_configure('big', font=('Verdana', 20, 'bold'))
text2.tag_configure('color',
foreground='#476042',
font=('Tempus Sans ITC', 16, 'bold'))
text2.pack(side=tk.LEFT)
scroll.pack(side=tk.RIGHT, fill=tk.Y)
#Escolli directoris font i desti
escollir = Frame (window) #cremm frame que contindra botons i labels per escollir els directoris i cercar
#Botons escollir
botons_escollir= Frame (escollir) # creem frame per als botons d'escollir directori
#Frame labels_escollir+cerca
labels_cerca_escollir= Frame (escollir) #crem frame que tindra el boto de cerca i els labels-frame que mostraran els directoris selecionats
fldesti= LabelFrame (labels_cerca_escollir)
ldesti= Label ( fldesti, bg="pink")
ldesti.pack(expand =TRUE, fill=X)
fldesti.pack( side = LEFT, expand =TRUE, fill=X)
botons_escollir.pack( side = LEFT, fill=X)
labels_cerca_escollir.pack(side =LEFT, expand=TRUE, fill=X)
escollir.pack(expand=TRUE, fill=X, anchor = NW)
bdesti=Button( botons_escollir , text="1. Select creation directory", command= lambda: select_dir(ldesti)) #ubiquem els botons
crear= Button (window, text = "Create FASTA file", command= creation_fastafile)
bccds=Button(window, text="Select CCDS file", command= select_CCDSfile)
bid=Button( window , text="Select UniprotID file", command= select_IDfile)
#run= Button ( root, text = "Run Str Program", command= runp)
#creem els botons asociats a la seva funcio
#bordenar.pack (side =BOTTOM, anchor=SW) #ubiquem els botons al lloc adcuat dins del frame botons_originals
bid.pack ( side = LEFT)
bccds.pack ( side = LEFT)
crear.pack ( side = LEFT)
#run.pack (side = LEFT)
bdesti.pack( fill=X)
bdesti.pack(side = LEFT, anchor = E)
def consecutive():
def select_dir(label):
filename = filedialog.askdirectory(title="Select Output Directory")
label.configure(text=filename)
def create_cbutsa(label):
root = Toplevel()
root.title("a Codons")
name=directori+"/Utilities/allCodsAA.txt"
f900=open(name,'r')
listaa=f900.readlines()
cbuts_text = listaa
cbuts = []
i=0
j=0
varis=[]
for index, item in enumerate(cbuts_text):
var=IntVar()
cbuts.append(Checkbutton(root, text = item, variable=var))
cbuts[index].grid(column=i,row=j, padx=10)
j=j+1
if j==4:
i=i+1
j=0
varis.append(var)
def deselect_all():
for i in cbuts:
i.deselect()
def select_aTAPS():
deselect_all()
listaTAPS=[37,38,39,40,21,22,23,24,5,6,7,8,53,54,55,56]#format R
for i in listaTAPS: #format P
e=RtoP[i]
e=e-1
cbuts[e].select()
def select_aLIVR_aTAPS():
deselect_all()
listaTAPSLIVR=[37,38,39,40,21,22,23,24,5,6,7,8,53,54,55,56,29,30,31,32,61,63,13,14,16,45,46,47,48,25,26,27,28,9,11] #format R
for i in listaTAPSLIVR:#format P
e=RtoP[i]
e=e-1
cbuts[e].select()
def select_all():
for i in cbuts:
i.select()
def oka():
yesno=[]
for i in varis:
yesno.append(i.get())
n=0
rlist=[]
for i in yesno:
if i:
rlist.append(n)
n=1+n
listcod=[]
for i in rlist:
listcod.append(codonList[i])
label.configure(text=listcod)
root.destroy()
nba4=Button(root , text="I34 (TAPS)", command=select_aTAPS)
nba4.grid(column=2,row=6)
nba6=Button(root , text="I34", command=select_aLIVR_aTAPS)
nba6.grid(column=1,row=6)
nba7=Button(root, text="Unselect all", command=deselect_all)
nba7.grid(column=4,row=6)
nba9=Button(root, text="Select all", command=select_all)
nba9.grid(column=3,row=6)
nba8=Button(root, text="OK", command=oka)
nba8.grid(column=5,row=6)
mainloop()
def Consecutive_ok():
# MIREM QUE ESTIGUIN TOTES LES COSES NECESARIES
if SelectCodons['text'] =="":
messagebox.showerror("Error", "Please select codon set!")
return None