Skip to content

Commit

Permalink
Fix metabolite loading from database. Fixes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
JuBra committed Dec 13, 2017
1 parent 5753001 commit 517d949
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions GEMEditor/database/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import os
import sqlite3
import re
from GEMEditor.base.classes import Settings
from GEMEditor.database import database_path as DB_PATH
from GEMEditor.database.ui import Ui_MetaboliteEntryDisplayWidget, Ui_ReactionEntryDisplayWidget
from GEMEditor.model.classes.cobra import Metabolite, Reaction
from GEMEditor.model.classes.annotation import Annotation
from GEMEditor import formula_validator
from PyQt5 import QtCore, QtSql
from PyQt5.QtWidgets import QMessageBox, QWidget, QTableWidgetItem

Expand Down Expand Up @@ -240,8 +242,8 @@ def get_metabolite_from_id(self, identifier):

if metabolite_info:
metabolite = Metabolite(name=metabolite_info[0],
formula=metabolite_info[1],
charge=metabolite_info[2])
formula=valid_formula(metabolite_info[1]),
charge=valid_charge(metabolite_info[2]))
annotations = self.get_annotations_from_id(identifier, "Metabolite")
metabolite.annotation.update(annotations)
return metabolite
Expand Down Expand Up @@ -582,4 +584,15 @@ def pyqt_database_connection(database_path=None):
return db


def valid_formula(formula):
if isinstance(formula, str) and re.match(formula_validator, formula):
return formula
else:
return None


def valid_charge(charge):
try:
return int(charge)
except:
return None
2 changes: 1 addition & 1 deletion GEMEditor/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@ def check_model_closing(self):

def closeEvent(self, event):
if self.close_model():
LOGGER.debug("Update timer stopped.")
event.accept()
else:
event.ignore()

def __del__(self):
self.update_timer.stop()
LOGGER.debug("Update timer stopped.")

0 comments on commit 517d949

Please sign in to comment.