Bonjour,
J'ai cette erreur qui s'affiche et je ne l'a comprend pas.
Voila j'ai 2 QTableWidget, une contient les ID correspond aux séquences se trouvant dans l'autre Qtable.
Je veux quand je click sur un ID la séquence correpondant devient la séquence référence.
Car ensuite je compare cette séquence avec les autres pour les colorier.
Voici la classe msa_output où se trouve la fonction apelé lors du click: fonction click_ID_ref()
la classe controller apelé dans la fonction du dessus ;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 from PyQt4.QtGui import * from PyQt4.QtCore import * import controller_msa_output class Msa_output(QWidget): def __init__(self, layout_controller): super(Msa_output, self).__init__() self.table_aligt=QTableWidget(self) self.table_ID_seq=QTableWidget(self) self.id_msa=0 self.label_name_msa=QLabel() self.layout_V=QVBoxLayout() self.layout_H=QHBoxLayout() self.dic_msa_msa={} self.item_last=QTableWidgetItem() self.id_seq=0 self.control=layout_controller #Create the QTableWidget of alignment and for the ID def init_table(self, list_seq): self.para_table(self.table_aligt, len(list_seq), len(list_seq[0].seq)) self.table_aligt.resizeColumnsToContents() self.table_aligt.setMinimumSize(800,200) self.para_table(self.table_ID_seq, len(list_seq), 1) self.table_aligt.verticalScrollBar().valueChanged.connect(self.table_scrolled_aligt) self.table_ID_seq.verticalScrollBar().valueChanged.connect(self.table_scrolled_ID) #Define the parameter of table def para_table(self, table, nb_seq, len_seq): table.setRowCount(nb_seq) table.setColumnCount(len_seq) table.setShowGrid(False) table.verticalHeader().setVisible(False) table.horizontalHeader().setVisible(False) #Put the name in the label def set_label(self, name): self.label_name_msa.setText(name) self.layout_V.addWidget(self.label_name_msa) #Put the sequence of msa in the table_aligt def set_table(self, list_seq, tab_color): i=0 j=0 while i<len(list_seq): seq=list_seq[i].seq Id=list_seq[i].ID item_id=self.set_item(Id) self.table_ID_seq.setItem(i,0, item_id) while j<len(seq): item = self.set_item(seq[j]) self.table_aligt.setItem(i, j, item) if tab_color[i][j]==1: item.setBackgroundColor(QColor(30,144,255)) elif tab_color[i][j]==2: item.setBackgroundColor(QColor(238,44,44)) j=j+1 i=i+1 j=0 self.layout_H.addWidget(self.table_ID_seq) self.layout_H.addWidget(self.table_aligt) self.layout_V.addLayout(self.layout_H) self.setLayout(self.layout_V) #Put the sequence of msa in the table_aligt def set_table2(self, list_seq): i=0 j=0 while i<len(list_seq): seq=list_seq[i].seq Id=list_seq[i].ID item_id=self.set_item(Id) if i==0: item_id.setBackgroundColor(QColor(255,0,0)) self.table_ID_seq.setItem(i,0, item_id) while j<len(seq): item = self.set_item(seq[j]) self.table_aligt.setItem(i, j, item) j=j+1 i=i+1 j=0 self.layout_H.addWidget(self.table_ID_seq) self.layout_H.addWidget(self.table_aligt) self.layout_V.addLayout(self.layout_H) self.setLayout(self.layout_V) #Update of table item def set_item(self, text): item = QTableWidgetItem() item.setTextAlignment(Qt.AlignCenter) item.setText(text) item.setTextColor(QColor(0,0,0)) item.setBackgroundColor(QColor(255,255,255)) return item #Allows to associate the scroll bar vertical of table_aligt and table ID def table_scrolled_aligt(self, value): self.table_ID_seq.verticalScrollBar().setValue(value) def table_scrolled_ID(self, value): self.table_aligt.verticalScrollBar().setValue(value) def click_ID_ref(self, x, y): if self.id_msa==0: self.item_last.setBackgroundColor(QColor(255,255,255)) item = self.table_ID_seq.item(x,y) item.setBackgroundColor(QColor(255,0,0)) self.item_last=item self.id_seq=x self.control.update_output() #print item.text() #print x," ",y def click_msa(self,x, y): x=0 #print self.id_msa #print "x ",x," y ",y def read_tab(self, tab, pos): i=0 #print len(tab) while i<len(tab): dic_tab=tab[i] if len(dic_tab)!=0: if dic_tab.has_key(pos): tab1=dic_tab[pos] i=i+1 return tab1
la classe multi_msa_output;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 from PyQt4.QtGui import * from PyQt4.QtCore import * import multi_msa_input import multi_msa import multi_msa_output import sys import os class Layout_controller(): "Realize the event and action of the window view" def __init__(self,QWidget): self.MainWindow=QWidget self.multi_msa=multi_msa.Multi_msa() #allows the choose of file from of user home def choose_file(self): filename = QFileDialog.getOpenFileName(self.MainWindow, 'Open file', os.getenv("HOME")) fname = open(filename) self.filename=filename def update_widget(self, area, widget): self.area=area area.setWidget(widget) area.show() #create a tab with the object msa_input and call the function which allow to show the alignment def submit(self, msa_input, tab_new_msa): self.multi_msa.tab_msa=[] tab_new_msa.append(msa_input) msa_ref=tab_new_msa.pop() tab_new_msa.insert(0, msa_ref) self.multi_msa.set_msa(tab_new_msa) tab_new_msa.pop() self.multi_msa_output=multi_msa_output.Multi_msa_output(self) self.multi_msa_output.display_msa(self.multi_msa.tab_msa, self.multi_msa.msadiff.dic_msa_msa, self.multi_msa.matrix.mat_3D) self.multi_msa_output.scrollArea.show() def update_output(self): self.multi_msa_output.display_msa(self.multi_msa.tab_msa, self.multi_msa.msadiff.dic_msa_msa, self.multi_msa.matrix.mat_3D) if __name__ == '__main__': app=QApplication(sys.argv) vw=multi_msa_input.Multi_msa_input() v=vw.scrollArea v.show() app.exec_()
et enfin la class color_msa où devrait éffectué le changement de couleur!!!:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 from PyQt4.QtGui import * from PyQt4.QtCore import * import controller_msa_output import color_msa import msa_output class Multi_msa_output(QWidget): def __init__(self, layout_controller): super(Multi_msa_output, self).__init__() self.control=controller_msa_output.Controller_msa_output(layout_controller) self.layout=QVBoxLayout() self.msa_out=msa_output.Msa_output(layout_controller) #display the different alignment uploaded def display_msa(self, list_msa, dic_msa_msa, matrix): i=0 tab_color=[] while i<len(list_msa): if i==0: color_msa1=color_msa.Color_msa() color_msa1.set_tab_sub_column(matrix, i, list_msa[i].file.list_seq) self.msa_out=self.control.set_table(list_msa[i].file.list_seq, list_msa[i].msa_name.name_user, i, tab_color) self.msa_out.dic_msa_msa=dic_msa_msa self.msa_out.matrix=matrix self.layout.addWidget(self.msa_out) else : if dic_msa_msa.has_key("0_"+str(i)): color=color_msa.Color_msa() color.set_tab_sub_column(matrix, i, list_msa[i].file.list_seq) color.init_tab(list_msa[i].file.list_seq) tab_color=color.compare_sub_column(color_msa1.tab_sub_column,dic_msa_msa["0_"+str(i)], matrix, i, self.msa_out.id_seq) self.msa_out=self.control.set_table(list_msa[i].file.list_seq, list_msa[i].msa_name.name_user, i, tab_color) self.layout.addWidget(self.msa_out) self.msa_out.dic_msa_msa=dic_msa_msa self.msa_out.matrix=matrix i=i+1 self.setLayout(self.layout) self.scrollArea=QScrollArea() self.scrollArea.setWidget(self) if i>1: self.scrollArea.resize(1150,600) else : self.scrollArea.resize(1150,300) self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) i=0
J'espère que quelqu'un peut m'aidé;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import numpy as np import column class Color_msa: def __init__(self): self.tab=[[]] self.tab2=[[]] self.tab_sub_column=[] def set_tab_sub_column(self,matrix, id_msa, list_seq): i=0 while i<len(matrix[id_msa,0]): col=column.Column(len(list_seq)) tab_column=col.set_tab(matrix, i, id_msa) self.tab_sub_column.append(tab_column) i=i+1 def compare_sub_column(self, tab_column_msa_ref, tab_dic, matrix, id_msa, id_seq): dic=tab_dic[id_seq] i=0 j=0 while i<=len(dic): if dic.has_key(i): tab_res_res=dic[i] tab_seq_ref=tab_res_res[0] tab_seq_msa2=tab_res_res[1] column_ref=tab_column_msa_ref[tab_seq_ref[2]] column_msa2=self.tab_sub_column[tab_seq_msa2[2]] while j<len(column_ref): if len(tab_dic[j])!=0: dic2=tab_dic[j] if dic2.has_key(i): tab_res_res2=dic2[i] tab_seq_ref2=tab_res_res2[0] tab_seq_msa22=tab_res_res2[1] if column_ref[j]==column_msa2[tab_seq_msa22[1]]: self.tab2[tab_seq_msa22[1],tab_seq_msa2[2]]=1 else : self.tab2[tab_seq_msa22[1],tab_seq_msa2[2]]=2 j=j+1 i=i+1 j=0 return self.tab2 def init_tab(self, list): self.tab=np.zeros((len(list), len(list[0].seq))) self.tab2=np.zeros((len(list), len(list[0].seq)))
Alaninho
Partager