This repository was archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
386 lines (328 loc) · 15.4 KB
/
Copy pathstart.py
File metadata and controls
386 lines (328 loc) · 15.4 KB
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
import sys
import pandas as pd
import matplotlib.pyplot as plt
from PyQt5 import uic,QtWidgets
from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTableWidgetItem, QDialog, QHeaderView, QProgressDialog
import os
from CMlib.show_sampletable import showtable
from CMlib.show_grouptable import showtable as showgrouptable
from CMlib.show_result import showtable as showresult
from CMlib.show_fasta import showfasta
#from crisprmatch_running import showtable as crisprmatchrun
from crisprmatch_running import mainprogram
from subprocess import Popen
from subprocess import PIPE
# from CRISPRMatch import main as startrunning
path = os.getcwd()
qtCreatorFile = os.path.join(path,'CMlib/start.ui') # Aquí va el nombre de tu archivo
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.setWindowTitle('CRISPRMatch Start Page')
# Aquí van los botones
self.load1btn.clicked.connect(self.getsampleCSV)
self.load2btn.clicked.connect(self.getgenefa)
self.load3btn.clicked.connect(self.getgroupCSV)
self.Show1btn.clicked.connect(self.showsampletable)
self.Show2btn.clicked.connect(self.showgenefa)
self.Show3btn.clicked.connect(self.showgrouptable)
self.tbnin.clicked.connect(self.inputdir)
self.tbnout.clicked.connect(self.outputdir)
self.startButton.clicked.connect(self.startrun)
self.resultButton.clicked.connect(self.showresults)
self.prosstext = str() ###step information list
self.path1 = "" ###Check loading information
self.path2 = ""
self.path3 = ""
self.path1check = ""
self.path2check = ""
self.path3check = ""
self.outputdirpath = ""
self.inputdirpath = ""
self.resultcheck = ""
self.step = ""
##############get sampleCSV and show table#########
def getsampleCSV(self):
filePath1, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', path)
if filePath1 != "":
print("Direction", filePath1) # Opcional imprimir la dirección del archivo
self.dfsample = pd.read_csv(str(filePath1))
tmp = ' '.join(['load sample information table:',filePath1,';\n'])
self.prosstext +=tmp
self.processinfo.setText(self.prosstext)
self.path1=filePath1
def showsampletable(self):
if self.path1 !="":
self.ui = showtable() ##打开showtable新窗口
result = self.ui.setuptable(self.dfsample) ##传递倒入sample csv
tmp = ' '.join(['check sample table', ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
if result == "yes":
self.ui.show() ##显示窗
self.path1check = self.path1
else:
self.path1check = ""
else:
self.showMessageBox('Warning', 'Please load Sample information Table first')
self.path1=""
# ##################################################
# ##############get genefa and show fasta#########
def getgenefa(self):
filePath2, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', path)
if filePath2 != "":
print("Fasta Direction", filePath2)
p = open(filePath2,'r')
self.fafile = p.readlines()
tmp = ' '.join(['load gene file:', filePath2, ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
self.path2 = filePath2
def showgenefa(self):
if self.path2 != "":
self.ui = showfasta() ##打开showfasta新窗口
result=self.ui.setuptext(self.fafile) ##传递倒入fasta
tmp = ' '.join(['check gene sequence', ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
if result == "yes":
self.ui.show() ##显示窗
self.path2check = self.path2
else:
self.path2check = ""
else:
self.showMessageBox('Warning', 'Please load Gene fasta first')
self.path2=""
# ##################################################
# ##############get groupCSV and show table#########
def getgroupCSV(self):
filePath3, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', path)
if filePath3 != "":
print("Direction", filePath3) # Opcional imprimir la dirección del archivo
self.dfgroup = pd.read_csv(str(filePath3))
stripstr = lambda x: x.strip() if isinstance(x, str) else x ##去除前后空格
self.dfgroup = self.dfgroup.applymap(stripstr)
tmp = ' '.join(['load gene file:', filePath3, ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
self.path3 = filePath3
def showgrouptable(self):
if self.path3 != "":
self.ui = showgrouptable() ##打开showtable新窗口
result = self.ui.setuptable(self.dfgroup) ##传递倒入sample csv
tmp = ' '.join(['check group table', ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
###判断格式
if result == "yes":
self.ui.show() ##显示窗
self.path3check = self.path3
else:
self.path3check = ""
else:
self.showMessageBox('Warning', 'Please load Group information Table first')
self.path3 = ""
##################################################
# ##############set input and output file directory#########
def inputdir(self):
inputdirpath = QtWidgets.QFileDialog.getExistingDirectory(self,'open directory',path)
if inputdirpath !="":
print("Direction", inputdirpath)
self.inputdirpath = inputdirpath
self.lineEdit_input.setText(inputdirpath)
tmp = ' '.join(['input directory:', inputdirpath, ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
def outputdir(self):
outputdirpath = QtWidgets.QFileDialog.getExistingDirectory(self, 'open directory', path)
if outputdirpath != "":
print("Direction", outputdirpath)
self.outputdirpath = outputdirpath
self.lineEdit_output.setText(outputdirpath)
tmp = ' '.join(['output directory:', outputdirpath, ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
##################################################
# ############## warning message #########
def showMessageBox(self, title, message):
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setWindowTitle(title)
msgBox.setText(message)
msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
msgBox.exec_()
##################################################
# ############## start running ###################
def startrun(self):
if self.path1 != "" and self.path2 != "" and self.path3 != "":
if self.path1check !="" and self.path2check !="" and self.path3check !="":
sample = self.path1
gene = self.path2
group = self.path3
input = self.inputdirpath
self.output_tmp = self.outputdirpath + '/' + 'tmpfiles'
self.output_result = self.outputdirpath + '/' + 'result'
#self.ui.startrun(sample, gene, group, input, self.output_tmp, self.output_result)
mainprogram(sample, gene, group, input, self.output_tmp, self.output_result)
# x=startrunning(sample,gene,group,input,self.output_tmp,self.output_result)
# tmp = ' '.join([x, ';\n'])
# self.prosstext += tmp
# self.processinfo.setText(self.prosstext)
# self.step="done"
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowTitle("Information")
msgBox.setIcon(QtWidgets.QMessageBox.Information)
msgBox.setText("Project Done!")
msgBox.setDetailedText("The project has finished, please click ok to show result!")
msgBox.setStandardButtons(QtWidgets.QMessageBox.Open)
#msgBox.information(self,"Information","Project Done!")
# msgBox.addButton("Show Result",QtWidgets.QMessageBox.ActionRole)
# msgBox.clickedButton()
msgBox.exec_()
self.resultcheck = "done"
self.showresults()
else:
self.showMessageBox('Warning', 'Please click show buttons for information checking')
self.resultcheck = ""
else:
self.showMessageBox('Warning', 'Please load information first')
self.resultcheck = ""
##################################################
# ############## show results ###################
def showresults(self):
if self.path1 != "" and self.resultcheck =="done":
self.ui = showresult() ##打开showtable新窗口
self.ui.setuptable(self.dfsample,self.output_tmp,self.output_result,self.path2,self.dfgroup) ##传递倒入sample csv
tmp = ' '.join(['check sample table', ';\n'])
self.prosstext += tmp
self.processinfo.setText(self.prosstext)
self.ui.show() ##显示窗口
else:
self.showMessageBox('Warning', 'Please load Sample information Table first')
self.path1 = ""
# crispr = path + '/CRISPRMatch.py'
# cmd = ' '.join(['python',crispr, '-g', gene, '-i', sample, '-gi', group, '-s', output_tmp, '-r', output_result])
# print(cmd)
# cmd_run = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
# cmd_run.communicate()
##################################################
# ############## show bar ###################
def showbarprocess(self):
if self.step != "done":
num = int(100000)
progress = QProgressDialog(self)
progress.setWindowTitle("请稍等")
progress.setLabelText("正在操作...")
# progress.setCancelButtonText("取消")
progress.setMinimumDuration(5)
progress.setWindowModality(Qt.WindowModal)
progress.setRange(0, num)
for i in range(num):
progress.setValue(i)
if progress.wasCanceled():
QtWidgets.QMessageBox.warning(self, "提示", "操作失败")
break
else:
progress.setValue(num)
#QtWidgets.QMessageBox.information(self, "提示", "操作成功")
#self.showbarprocess()
else:
pass
# self.boton2.clicked.connect(self.plot)
# self.boton3.clicked.connect(self.showCSV)
# self.boton4.clicked.connect(self.show_table)
#
# self.tableWidget.setAlternatingRowColors(True) # 隔行改变颜色
# rown=self.tableWidget.rowCount() # 返回表格的行数
# coln=self.tableWidget.columnCount() # 返回表格的列数
# print(rown)
#
# #self.tableWidget.setHorizontalHeaderLabels('abcdef') # 设置表格表头数据
# # self.tableWidget.setColumnCount(5) # 设置表格的列数
# # self.tableWidget.setRowCount(3) # 设置表格的行数
# # self.tableWidget.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents) # 表格设置成大小随内容改变
# # self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
# self.tableWidget.setItem(3, 3, QTableWidgetItem("insert3,3")) # 设置表格内容为字符串"content"
# self.timeEdit = QtWidgets.QTimeEdit() # 创建一个timeEdit
# self.tableWidget.setCellWidget(0, 0, self.timeEdit) # 把timeedit添加进tableWidget内
# self.spinBox = QtWidgets.QSpinBox()
# self.spinBox.setValue(10)
# self.tableWidget.setCellWidget(2, 1, self.spinBox)
#
# ###set tableView
# self.model = QStandardItemModel(4,4)
# self.model.setHorizontalHeaderLabels(['标题1', '标题2', '标题3', '标题4'])
# #下面代码让表格100填满窗口
# self.tableView.horizontalHeader().setStretchLastSection(True)
# self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# for row in range(4):
# for column in range(4):
# item = QStandardItem("row %s, column %s" % (row, column))
# self.model.setItem(row, column, item)
# self.tableView.setModel(self.model)
# self.model.appendRow([
# QStandardItem("row %s, column %s" % (11, 11)),
# QStandardItem("row %s, column %s" % (11, 11)),
# QStandardItem("row %s, column %s" % (11, 11)),
# QStandardItem("row %s, column %s" % (11, 11)),
# ])
# # 取当前选中的所有行
# index = self.tableView.currentIndex()
# print(index.row())
# self.model.removeRow(index.row())
# ###########
#
#
#
#
# # Aquí van las nuevas funciones
# # Esta función abre el archivo CSV
# def getCSV(self):
# filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', '/Users/qyou/GitLab/pyQttest')
# if filePath != "":
# print("Dirección", filePath) # Opcional imprimir la dirección del archivo
# self.df = pd.read_csv(str(filePath))
#
# def plot(self):
# x=self.df['col1']
# y=self.df['col2']
# plt.plot(x,y)
# plt.show()
# estad_st="Estadisticas de col2: " +str(self.df['col2'].describe())
# self.resultado.setText(estad_st)
#
# def showCSV(self):
# ###set tableView
# rown=len(self.df.index)
# coln=len(self.df.columns)
# self.model = QStandardItemModel(rown,coln)
# labels = list(self.df.columns.values)
# #labels=['Index','Sample','Vector','Note','gRNA_PAM','start','end','Type','gene_name']
# self.model.setHorizontalHeaderLabels(labels)
# #下面代码让表格100填满窗口
# # self.tableView_csv.horizontalHeader().setStretchLastSection(True)
# # self.tableView_csv.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
#
# for row in range(rown):
# #print(self.df.loc[row].Sample)
# for column in range(len(labels)):
# item = QStandardItem(str(self.df.loc[row][labels[column]]))
# self.model.setItem(row, column, item)
# self.tableView_csv.setModel(self.model)
# estad_st=str(self.df)
# self.resultado.setText(estad_st)
# def show_table(self):
# #self.showtableWindow = QtWidgets.QDialog()
# self.ui = showtable() ##打开showtable新窗口
# self.ui.setuptable(self.df) ##传递倒入sample csv
# self.ui.show() ##显示窗口
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())