-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.py
176 lines (138 loc) · 6.03 KB
/
components.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
import os
from PyQt5 import QtCore
from PyQt5.QtGui import QTextOption
from PyQt5.QtWidgets import QFormLayout, QInputDialog, QLabel, QMainWindow, QHBoxLayout, QMessageBox, QSizePolicy, QTextEdit, QVBoxLayout, QWidget, QToolBar, QPushButton
# from PyQt5.QtCore import Qt
from .dna import DNA
class AbstractWindow(QMainWindow):
def __init__(self, parent=None):
"""Initializer."""
super().__init__()
styleFile = os.path.dirname(__file__) + "/style.css"
with open(styleFile,"r") as fh:
self.setStyleSheet(fh.read())
# self.setMinimumWidth(1500)
def setupMainLayout(self,sidebarLayout, mainLayout):
layout = QHBoxLayout()
left = QWidget()
left.setLayout(sidebarLayout)
right = QWidget()
right.setLayout(mainLayout)
layout.addWidget(left)
layout.addWidget(right)
layout.setStretch(0, 0)
layout.setStretch(1, 7)
self.centralwidget = QWidget()
self.setCentralWidget(self.centralwidget)
self.centralwidget.setLayout(layout)
def setMenuItems(self):
self.menu_fichier = self.menuBar().addMenu("Fichier")
self.menu_edit = self.menuBar().addMenu("Edit")
class SidebarLayout(QVBoxLayout):
def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)
self.setupButtons()
self.btn_creer_adn.clicked.connect(self.action_creer_adn)
self.btn_adn_vers_arn.clicked.connect(self.action_adn_vers_arn)
self.btn_arn_vers_proteine.clicked.connect(self.action_arn_vers_proteine)
self.btn_comp_inv_adn.clicked.connect(self.action_comp_inv_adn)
self.btn_taux_gc_adn.clicked.connect(self.action_taux_gc_adn)
self.btn_freq_codons_adn.clicked.connect(self.action_freq_codons_adn)
self.btn_masse_proteique.clicked.connect(self.action_masse_proteique)
def action_creer_adn(self):
n,result = QInputDialog.getInt(QWidget(), "Input Dialog", "Entrer la longueur:",min=1)
if result:
if n>0:
N=n
DNA.generate_dna(N)
MainLayout._instance.output_dna_chain.setText(DNA.dna_chain)
else:
msg = QMessageBox()
msg.setWindowTitle("create dna")
msg.setText("Vous devez donner un nombre positif")
msg.setIcon(QMessageBox.Critical)
x=msg.exec_()
def action_adn_vers_arn(self):
if DNA.dna_chain == "":
return
DNA.translate_to_rna()
MainLayout._instance.output_rna_chain.setText(DNA.rna_chain)
def action_arn_vers_proteine(self):
if DNA.rna_chain == "":
return
DNA.rna_to_prot()
MainLayout._instance.output_protein_chain.setText(DNA.protein_chain)
def action_comp_inv_adn(self):
if DNA.dna_chain == "":
return
DNA.get_dna_complement()
MainLayout._instance.output_dna_complement.setText(DNA.dna_complement)
def action_taux_gc_adn(self):
if DNA.dna_chain == "":
return
DNA.taux_gc()
MainLayout._instance.output_taux_gc.setText(str(DNA.gc_rate)+'%')
def action_freq_codons_adn(self):
if DNA.dna_chain == "":
return
DNA.taux_codons()
MainLayout._instance.output_codon_frequency.setText(str(DNA.codon_frequency))
def action_masse_proteique(self):
DNA.masse()
MainLayout._instance.output_protein_mass.setText(str(DNA.protein_mass))
pass
def setupButtons(self):
# setup buttons list
self.buttons = [
('Créer ADN','creer_adn'),
('ADN vers ARN','adn_vers_arn'),
('ARN vers Proteine','arn_vers_proteine'),
('Comp INV ADN','comp_inv_adn'),
('taux GC ADN','taux_gc_adn'),
('fréq codons ADN','freq_codons_adn'),
('Mutation','mutation'),
('Chercher Motif ADN','chercher_motif_adn'),
('ADN Consensus + profil','adn_consensus_profil'),
('Masse Proteïque','masse_proteique'),
('Epissage d\'ADN','epissage_adn'),
]
# create and assign buttons
for btn in self.buttons:
setattr(self,'btn_' + btn[1],QPushButton(btn[0]))
self.addWidget(getattr(self,'btn_' + btn[1]))
self.addStretch()
class MainLayout(QFormLayout):
_instance = None
def __init__(self, *args, **kwargs):
if MainLayout._instance != None:
return None
super().__init__(*args,**kwargs)
MainLayout._instance = self
chain_width = 50
elements = [
('ADN','dna_chain',chain_width),
('ARN','rna_chain',chain_width),
('Proteine','protein_chain',chain_width),
('Comp Inv','dna_complement',chain_width),
('Taux GC','taux_gc',4),
('Fréquence Codons','codon_frequency',40),
('Masse Protéique','protein_mass',10)
]
for element in elements:
label = QLabel(element[0])
textEdit = QTextEdit()
textEdit.setReadOnly(True)
textEdit.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
textEdit.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
textEdit.setLineWrapMode(QTextEdit.NoWrap)
singleWidth = textEdit.fontMetrics().boundingRect('A').width()
singleHeight = textEdit.fontMetrics().boundingRect('A').height()
textEdit.setFixedWidth(singleWidth*element[2])
textEdit.setFixedHeight(singleHeight*3)
setattr(self,'label_'+element[1], label)
setattr(self,'output_'+element[1],textEdit)
self.addRow(getattr(self,'label_'+element[1]),getattr(self,'output_'+element[1]))
class QPrimaryButton(QPushButton):
def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)
self.setStyleSheet("background-color: indigo;color:white;font-weight:bold;")