-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIhmFinal.py
executable file
·148 lines (118 loc) · 5.58 KB
/
IhmFinal.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
# -*- coding: UTF-8 -*-
##import filedialog
from tkinter import *
from GibbsFinalVersion import GibbsSampler,readFasta
class IhmGibbs:
#éléments graphiques
root=[] #c'est la fenetre
mainFrame=[] #c'est le cadran qui contient le champs text qui affiche les séquences
optionFrame=[] #c'est le cadran qui affiche les inputs/parametres de départ
resultText=[] #c'est la zone de texte qui va afficher les sequences
fileToLoadEntry=[] #le champ qui contient le fichier fasta à charger
nbOfRunsEntry=[] #le champ qui contient le nombre de runs
iterationsEntry=[] #le nombre d'itération par runs
motifWidthEntry=[] #champ qui contient la taille du motif
residuesChoice=[] #choix des résidus acides aminés ou nucléotides
#fin des éléments
sequences=[] #les sequences édités
residuesChoicesDic = {
1: "ARNDCQEGHILKMFPSTWYV",
2: "ACTG",
}
def __init__(self):
self.root=Tk()
self.root.geometry('1200x500')
title='GIBBS SAMPLING'
self.root.title(title)
self.optionFrame=Frame(self.root)
self.optionFrame.pack()
self.mainFrame=Frame(self.root)
self.mainFrame.pack()
#faire les scrollbars
xscrollbar = Scrollbar(self.mainFrame, orient=HORIZONTAL)
xscrollbar.grid(row=1, column=0, sticky=N+S+E+W)
yscrollbar = Scrollbar(self.mainFrame)
yscrollbar.grid(row=0, column=1, sticky=N+S+E+W)
#faire la textbox des résultats
self.resultText = Text(self.mainFrame, wrap=NONE,
xscrollcommand=xscrollbar.set,
yscrollcommand=yscrollbar.set,width=100)
self.resultText.grid(row=0, column=0)
xscrollbar.config(command=self.resultText.xview)
yscrollbar.config(command=self.resultText.yview)
#text d'introduction
self.resultText.insert(END, 'Hello this is a GIBBS sampling app')
#faire les box entry pour nom de fichiers
label = Label(self.optionFrame, text="Fasta file :")
label.pack(side=LEFT)
self.fileToLoadEntry = Entry( self.optionFrame)
self.fileToLoadEntry.insert(0, "hth.fst")
self.fileToLoadEntry.pack(side=LEFT)
#bouton pour prévisualiser le fichier fasta
b = Button(self.optionFrame, text ="Preview", command = self.readFastaFileAndShow )
b.pack(side=LEFT)
#bouton parcourir
button_brow= Button(self.optionFrame, text ="browse", command = self.browser)
button_brow.pack(side=LEFT)
#entry pour le nombre de runs
label = Label(self.optionFrame, text="Nb Runs :")
label.pack(side=LEFT)
self.nbOfRunsEntry = Entry( self.optionFrame)
self.nbOfRunsEntry.insert(0, "1")
self.nbOfRunsEntry.pack(side=LEFT)
label = Label(self.optionFrame, text="Iterations :")
label.pack(side=LEFT)
self.iterationsEntry = Entry( self.optionFrame)
self.iterationsEntry.insert(0, "200")
self.iterationsEntry.pack(side=LEFT)
label = Label(self.optionFrame, text="Width(W) :")
label.pack(side=LEFT)
self.motifWidthEntry = Entry( self.optionFrame)
self.motifWidthEntry.insert(0, "18")
self.motifWidthEntry.pack(side=LEFT)
label = Label(self.optionFrame, text="Residues :")
label.pack(side=LEFT)
#radio button pour selectionner les residues
self.residuesChoice=IntVar()
residueFrame=Frame(self.optionFrame)
residueFrame.pack(side=LEFT)
R1 = Radiobutton(residueFrame, text="Acides amines", variable=self.residuesChoice, value=1)
R1.pack()
R1.select()
R2 = Radiobutton(residueFrame, text="Nucleotides", variable=self.residuesChoice, value=2)
R2.pack()
b = Button(self.optionFrame, text ="RunGibbs", command = self.runGibbs)
b.pack(side=LEFT)
def run(self):
self.root.mainloop()
def runGibbs(self):
self.readFastaFileAndShow();
g=GibbsSampler(
self.sequences,
int(self.motifWidthEntry.get()),
self.residuesChoicesDic[self.residuesChoice.get()]
)
g.optimizeAlignment(int(self.iterationsEntry.get()), int(self.nbOfRunsEntry.get()))
self.resultText.delete(1.0, END)
self.resultText.insert(END,self.prettyPrintSequences(g.sequences,int(self.motifWidthEntry.get())))
def readFastaFileAndShow(self):
self.sequences=readFasta(self.fileToLoadEntry.get())
self.resultText.delete(1.0, END)
self.resultText.insert(END,self.prettyPrintSequences(self.sequences,int(self.motifWidthEntry.get())))
def prettyPrintSequences(self,sequences,w=18):
i=0
maxStart=max([k['start'] for k in sequences])
res=""
for seq in sequences:
startPos=seq['start']
endpos=seq['start']+w
res+= str(i).rjust(2,'0')+" "+seq['nom'][3:20] +" "+ seq['seq'][:startPos].rjust(maxStart,'-')+"["+seq['seq'][startPos:endpos]+"]"+seq['seq'][endpos:]+"\n"
i+=1
return res
def browser (self):
link= filedialog.askopenfilename(parent=self.optionFrame,title='Please select ')
self.fileToLoadEntry.delete(0,END)
self.fileToLoadEntry.insert(0,link)
#main
ihm=IhmGibbs()
ihm.run()