|
10 | 10 | from PyQt5 import QtCore, QtGui, QtWidgets
|
11 | 11 | from beams.qt import form
|
12 | 12 | import sqlite3
|
| 13 | +from collections import OrderedDict |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class BeamsApp(QtWidgets.QMainWindow, form.Ui_MainWindow):
|
@@ -51,7 +52,7 @@ def __init__(self, parent=None):
|
51 | 52 | self.checkBox_mz_digits.clicked.connect(self.create_summary)
|
52 | 53 | self.checkBox_convert_rt.clicked.connect(self.create_summary)
|
53 | 54 |
|
54 |
| - self.add_databases() |
| 55 | + self.db_names = self.add_databases() |
55 | 56 |
|
56 | 57 | self.pushButton_start.clicked.connect(self.run) # When the button is pressed
|
57 | 58 |
|
@@ -134,15 +135,15 @@ def source_peak_patterns(self):
|
134 | 135 | def source_compounds(self):
|
135 | 136 | if self.checkBox_filename_reference.isChecked():
|
136 | 137 | self.listWidget_databases.setEnabled(False)
|
137 |
| - self.listWidget_categories.setEnabled(False) |
| 138 | + # self.listWidget_categories.setEnabled(False) |
138 | 139 | self.label_databases.setEnabled(False)
|
139 | 140 | self.pushButton_filename_reference.setEnabled(True)
|
140 | 141 | self.lineEdit_filename_reference.setEnabled(True)
|
141 | 142 | else:
|
142 | 143 | self.label_databases.setEnabled(True)
|
143 | 144 | self.listWidget_databases.setEnabled(True)
|
144 |
| - self.label_categories.setEnabled(False) |
145 |
| - self.listWidget_categories.setEnabled(False) |
| 145 | + # self.label_categories.setEnabled(False) |
| 146 | + # self.listWidget_categories.setEnabled(False) |
146 | 147 | self.pushButton_filename_reference.setEnabled(False)
|
147 | 148 | self.lineEdit_filename_reference.setEnabled(False)
|
148 | 149 |
|
@@ -208,7 +209,7 @@ def annotate_molecular_formulae(self):
|
208 | 209 | def annotate_compounds(self):
|
209 | 210 | if not self.checkBox_annotate_compounds.isChecked():
|
210 | 211 | self.listWidget_databases.setEnabled(False)
|
211 |
| - self.listWidget_categories.setEnabled(False) |
| 212 | + # self.listWidget_categories.setEnabled(False) |
212 | 213 | self.label_databases.setEnabled(False)
|
213 | 214 | self.checkBox_filename_reference.setEnabled(False)
|
214 | 215 | self.pushButton_filename_reference.setEnabled(False)
|
@@ -249,21 +250,29 @@ def create_summary(self):
|
249 | 250 | self.spinBox_mz_digits.setEnabled(False)
|
250 | 251 |
|
251 | 252 | def add_databases(self):
|
252 |
| - path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') |
253 |
| - dbs = [fn for fn in os.listdir(path) if fn.endswith('.sqlite')] |
254 |
| - conn = sqlite3.connect(os.path.join(path, dbs[0])) |
| 253 | + |
| 254 | + path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'databases') |
| 255 | + |
| 256 | + list_databases = OrderedDict() |
| 257 | + with open(os.path.join(path, "compound_databases.txt"), "r") as inp: |
| 258 | + keys = inp.readline().strip().split("\t") |
| 259 | + for line in inp: |
| 260 | + line = line.split("\t") |
| 261 | + if os.path.isfile(os.path.join(path, line[keys.index("filename_sqlite")])): |
| 262 | + list_databases[line[keys.index("filename_sqlite")]] = line[keys.index("description")] |
| 263 | + conn = sqlite3.connect(os.path.join(path, list_databases.keys()[0])) |
255 | 264 | cursor = conn.cursor()
|
256 | 265 | cursor.execute("""SELECT name FROM sqlite_master where type='table'""")
|
257 | 266 | db_names = [str(name[0]) for name in cursor.fetchall()]
|
258 |
| - for i, db in enumerate(dbs[1:]): |
| 267 | + for i, db in enumerate(list_databases.keys()[1:]): |
259 | 268 | cursor.execute("ATTACH DATABASE ? AS db?", (os.path.join(path, dbs[i+1]), i, ))
|
260 | 269 | cursor.execute("""SELECT name FROM db?.sqlite_master where type='table'""", (i, ))
|
261 | 270 | db_names.extend([str(name[0]) for name in cursor.fetchall()])
|
262 | 271 | self.listWidget_databases.setSelectionMode(QtWidgets.QListWidget.MultiSelection)
|
263 |
| - for db_name in db_names: |
264 |
| - item = QtWidgets.QListWidgetItem(db_name) |
| 272 | + for description in list_databases.values(): |
| 273 | + item = QtWidgets.QListWidgetItem(description) |
265 | 274 | self.listWidget_databases.addItem(item)
|
266 |
| - return db_names |
| 275 | + return dict((v, k) for k, v in list_databases.iteritems()) |
267 | 276 |
|
268 | 277 | def run(self):
|
269 | 278 |
|
@@ -331,6 +340,7 @@ def run(self):
|
331 | 340 | QtWidgets.QMessageBox.critical(None, "Select file", "Provide a valid filename for adducts", QtWidgets.QMessageBox.Ok)
|
332 | 341 | else:
|
333 | 342 | QtWidgets.QMessageBox.critical(None, "Select file", "Provide a valid filename for adducts or 'Use default'", QtWidgets.QMessageBox.Ok)
|
| 343 | + |
334 | 344 | annotation.annotate_adducts(inp, db_out=self.lineEdit_sql_database.text(), ppm=self.doubleSpinBox_ppm_error.value(), lib=lib)
|
335 | 345 | print("Done")
|
336 | 346 |
|
@@ -435,13 +445,12 @@ def run(self):
|
435 | 445 | QtWidgets.QMessageBox.critical(None, "Select file", "Provide a valid filename for adducts", QtWidgets.QMessageBox.Ok)
|
436 | 446 |
|
437 | 447 | if self.checkBox_filename_reference.isChecked():
|
438 |
| - annotation.annotate_compounds(df, lib_adducts=lib, ppm=self.doubleSpinBox_ppm_error.value(), db_out=self.lineEdit_sql_database.text(), db_in=self.lineEdit_filename_reference.text(), db_name=None) |
| 448 | + annotation.annotate_compounds(df, lib_adducts=lib, ppm=self.doubleSpinBox_ppm_error.value(), |
| 449 | + db_out=self.lineEdit_sql_database.text(), db_name=None, db_in=self.lineEdit_filename_reference.text()) |
439 | 450 | else:
|
440 |
| - path = 'data/BEAMS_DB.sqlite' |
441 |
| - path_db = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) |
442 |
| - print(path_db) |
443 | 451 | for db_name in self.listWidget_databases.selectedItems():
|
444 |
| - annotation.annotate_compounds(df, lib_adducts=lib, ppm=self.doubleSpinBox_ppm_error.value(), db_out=self.lineEdit_sql_database.text(), db_in=path_db, db_name=db_name.text()) |
| 452 | + annotation.annotate_compounds(df, lib_adducts=lib, ppm=self.doubleSpinBox_ppm_error.value(), |
| 453 | + db_out=self.lineEdit_sql_database.text(), db_name=self.db_names[db_name.text()].strip(".sqlite")) |
445 | 454 | print("Done")
|
446 | 455 | print
|
447 | 456 |
|
|
0 commit comments