-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequelyzer.py
199 lines (182 loc) · 9.36 KB
/
Sequelyzer.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
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Sequence_Analyzer.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from ast import Expression
from Bio import SeqIO
import re
import sys
import fnmatch
DNA = 'ATCG'
RNA = 'AUCG'
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(566, 692)
MainWindow.setMaximumSize(QtCore.QSize(566, 692))
MainWindow.setMouseTracking(True)
MainWindow.setFocusPolicy(QtCore.Qt.ClickFocus)
MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.Sequence_Input = QtWidgets.QTextEdit(self.centralwidget)
self.Sequence_Input.setGeometry(QtCore.QRect(50, 60, 461, 291))
self.Sequence_Input.setMinimumSize(QtCore.QSize(50, 50))
self.Sequence_Input.setSizeIncrement(QtCore.QSize(0, 0))
self.Sequence_Input.setFocusPolicy(QtCore.Qt.WheelFocus)
self.Sequence_Input.setStatusTip("")
self.Sequence_Input.setStyleSheet("border-radius: 10px;\n"
"background-color: rgb(255, 255, 255);\n"
" border: 1px solid #9d9d9d;\n")
self.Sequence_Input.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Sequence_Input.setFrameShadow(QtWidgets.QFrame.Sunken)
self.Sequence_Input.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
self.Sequence_Input.setObjectName("Sequence_Input")
self.btn_Proportion = QtWidgets.QPushButton(self.centralwidget)
self.btn_Proportion.setGeometry(QtCore.QRect(200, 360, 75, 23))
self.btn_Proportion.setStyleSheet("background-color: rgb(83, 255, 161);\n"
"border-radius: 5px;")
self.btn_Proportion.setObjectName("btn_Proportion")
self.btn_Browse = QtWidgets.QToolButton(self.centralwidget)
self.btn_Browse.setGeometry(QtCore.QRect(50, 40, 61, 19))
self.btn_Browse.setStyleSheet("")
self.btn_Browse.setObjectName("btn_Browse")
self.label_Result = QtWidgets.QLabel(self.centralwidget)
self.label_Result.setGeometry(QtCore.QRect(90, 410, 381, 30))
self.label_Result.setMinimumSize(QtCore.QSize(30, 30))
self.label_Result.setStyleSheet("background-color: rgb(0, 85, 127);\n"
"color: rgb(255, 255, 255);\n"
"border-top-left-radius:5px;\n"
"border-top-right-radius:5px;")
self.label_Result.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label_Result.setLineWidth(6)
self.label_Result.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_Result.setIndent(5)
self.label_Result.setObjectName("label_Result")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(90, 440, 381, 151))
self.textEdit.setStyleSheet("background-color: rgb(255, 255, 255);\n"
"border-bottom-right-radius:5px;\n"
"border-bottom-left-radius:5px;\n"
"border: 1px solid #9d9d9d;")
self.textEdit.setObjectName("textEdit")
self.btn_Complement = QtWidgets.QPushButton(self.centralwidget)
self.btn_Complement.setGeometry(QtCore.QRect(280, 360, 75, 23))
self.btn_Complement.setStyleSheet("background-color: rgb(79, 239, 239);\n"
"border-radius: 5px;")
self.btn_Complement.setObjectName("btn_Complement")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 566, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.btn_Proportion.setText(_translate("MainWindow", "Proportion"))
self.btn_Browse.setText(_translate("MainWindow", "Browse..."))
self.label_Result.setText(_translate("MainWindow", "Result"))
self.btn_Complement.setText(_translate("MainWindow", "Complement"))
self.btn_Browse.clicked.connect(self.seq_input)
self.btn_Proportion.clicked.connect(self.seq_output)
self.btn_Complement.clicked.connect(self.seq_output_r)
# My Functions:
def seq_input(self):
SeqFile, _ = QtWidgets.QFileDialog.getOpenFileName(None, 'Single File', QtCore.QDir.currentPath(), '*.fasta *.txt *.gb')
if fnmatch.fnmatch(SeqFile, '*.txt'):
read_file = open(SeqFile).read()
self.Sequence_Input.setText(read_file)
elif fnmatch.fnmatch(SeqFile, '*.fasta'):
for seq_record in SeqIO.parse(SeqFile, "fasta"):
seqq = str(seq_record.seq)
self.Sequence_Input.setText(seqq)
elif fnmatch.fnmatch(SeqFile, '*.gb'):
for seq_record in SeqIO.parse(SeqFile, "genbank"):
seqq = str(seq_record.seq)
self.Sequence_Input.setText(seqq)
else:
pass
def seq_output(self):
if self.Sequence_Input.toPlainText() == "":
self.textEdit.setPlainText(str("Empty Value Not Allowed"))
pass
else:
while True:
Text = self.Sequence_Input.toPlainText()
A = len(re.findall("A", Text))
T = len(re.findall("T", Text))
U = len(re.findall("U", Text))
C = len(re.findall("C", Text))
G = len(re.findall("G", Text))
Text_length = len(Text)
A_p = (A/Text_length)*100
T_p = (T/Text_length)*100
U_p = (U/Text_length)*100
C_p = (C/Text_length)*100
G_p = (G/Text_length)*100
CG_p = C_p + G_p
if all(char in DNA for char in Text):
result = "A= ", round(A_p, 2), "%", "\n\n","T= ", round(T_p, 2),"%", "\n\n", "C= ", round(C_p, 2),"%", "\n\n", "G= ", round(G_p, 2),"%", "\n\n", "CG= ", round(CG_p, 2),"%"
result_1 = ''.join(map(str, result))
self.textEdit.setPlainText(result_1)
break
elif all(char in RNA for char in Text):
result = "A= ", round(A_p, 2), "%", "\n\n","U= ", round(U_p, 2),"%", "\n\n", "C= ", round(C_p, 2),"%", "\n\n", "G= ", round(G_p, 2),"%", "\n\n", "CG= ", round(CG_p, 2),"%"
result_1 = ''.join(map(str, result))
self.textEdit.setPlainText(result_1)
break
else:
Invalid = "Invalid Sequence"
self.textEdit.setPlainText(str(Invalid))
break
def seq_output_r(self):
if self.Sequence_Input.toPlainText() == "":
self.textEdit.setPlainText(str("Empty Value Not Allowed"))
pass
else:
while True:
Text = self.Sequence_Input.toPlainText()
comp = []
for base in Text:
if base == "A":
comp.append("T")
elif base == "G":
comp.append("C")
elif base == "T":
comp.append("A")
elif base == "U":
comp.append("A")
elif base == "C":
comp.append("G")
if all(char in DNA for char in Text):
comp_rev = comp[::-1]
comp_reverse = ''.join(comp_rev)
self.textEdit.setPlainText(comp_reverse)
break
elif all(char in RNA for char in Text):
comp_rev = comp[::-1]
comp_reverse = ''.join(comp_rev)
self.textEdit.setPlainText(comp_reverse)
break
else:
Invalid = "Invalid Sequence"
self.textEdit.setPlainText(str(Invalid))
break
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())