Source code for ccpn.AnalysisMetabolomics.ui.gui.modules.MetaboliteFinder

#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (http://www.ccpn.ac.uk) 2014 - 2021"
__credits__ = ("Ed Brooksbank, Joanna Fox, Victoria A Higman, Luca Mureddu, Eliza Płoskoń",
               "Timothy J Ragan, Brian O Smith, Gary S Thompson & Geerten W Vuister")
__licence__ = ("CCPN licence. See http://www.ccpn.ac.uk/v3-software/downloads/license")
__reference__ = ("Skinner, S.P., Fogh, R.H., Boucher, W., Ragan, T.J., Mureddu, L.G., & Vuister, G.W.",
                 "CcpNmr AnalysisAssign: a flexible platform for integrated NMR analysis",
                 "J.Biomol.Nmr (2016), 66, 111-124, http://doi.org/10.1007/s10858-016-0060-y")
#=========================================================================================
# Last code modification
#=========================================================================================
__modifiedBy__ = "$modifiedBy: Ed Brooksbank $"
__dateModified__ = "$dateModified: 2021-06-04 15:23:18 +0100 (Fri, June 04, 2021) $"
__version__ = "$Revision: 3.0.4 $"
#=========================================================================================
# Created
#=========================================================================================
__author__ = "$Author: CCPN $"
__date__ = "$Date: 2017-04-07 10:28:42 +0000 (Fri, April 07, 2017) $"
#=========================================================================================
# Start of code
#=========================================================================================

import pandas as pd
from PyQt5 import QtCore, QtGui, QtWidgets
from ccpn.ui.gui.modules.CcpnModule import CcpnModule
from ccpn.ui.gui.widgets.Label import Label
from ccpn.ui.gui.widgets.TextEditor import TextEditor
from ccpn.ui.gui.widgets.Button import Button
from ccpn.AnalysisMetabolomics.lib.BMRBquery import peaksToShifts1D, bmrbMultiShiftSearch
from ccpn.ui.gui.widgets.GuiTable import GuiTable


Qt = QtCore.Qt
Qkeys = QtGui.QKeySequence


[docs]class MetaboliteFinderModule(CcpnModule): includeSettingsWidget = False maxSettingsState = 2 settingsPosition = 'top' className = 'MetaboliteFinderModule' def __init__(self, mainWindow, name='BMRB Metabolite Finder', **kwds): super(MetaboliteFinderModule, self) CcpnModule.__init__(self, mainWindow=mainWindow, name=name) self.application = None self.project = None self.current = None self.preferences = None if mainWindow is not None: self.mainWindow = mainWindow self.project = self.mainWindow.project self.application = self.mainWindow.application self.moduleArea = self.mainWindow.moduleArea self.preferences = self.application.preferences self.current = self.application.current self._createWidgets() def _createWidgets(self): """ Add all widgets to the layout """ i = 0 self.chemicalShiftLabel = Label(self.mainWidget, 'Chemical Shifts', grid=(i, 0)) i += 1 self.chemicalShiftList = TextEditor(self.mainWidget, grid=(i, 0)) self.chemicalShiftList.setMaximumHeight(50) i += 1 self.copyFromCurrentButton = Button(self.mainWidget, 'Copy from current Peak(s)', grid=(i, 0)) i += 1 self.searchButton = Button(self.mainWidget, 'Search', callback=self._quearyBMRB, grid=(i, 0)) i += 1 self.metTable = GuiTable(self.mainWidget, mainWindow=self.mainWindow, selectionCallback=None, actionCallback=None, grid=(i, 0)) def _shiftsFromCurrentPeaks(self): if self.current: peaks = self.current.peaks shifts = peaksToShifts1D(peaks) self.chemicalShiftList.clear() text = '' for s in shifts: text += str(round(s, 3)) + ',' self.chemicalShiftList.setText(text) def _quearyBMRB(self): text = self.chemicalShiftList.get() lstStr = text.split(",") shifts = [float(i) for i in lstStr] df = bmrbMultiShiftSearch(shifts) print(df) self._setTable(df) def _setTable(self, dataframe): """Sets the table with a dataframe from bmrb website results.""" self.metTable.setData(dataframe) def _closeModule(self): """Re-implementation of closeModule function from CcpnModule to unregister notification""" self.metTable._close() super()._closeModule()
if __name__ == '__main__': from ccpn.ui.gui.widgets.Application import TestApplication from ccpn.ui.gui.widgets.CcpnModuleArea import CcpnModuleArea app = TestApplication() win = QtWidgets.QMainWindow() moduleArea = CcpnModuleArea(mainWindow=None, ) module = MetaboliteFinderModule(mainWindow=None) ala = ['3.771', '1.471'] data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']} df = pd.DataFrame.from_dict(data) # module._setTable(df) moduleArea.addModule(module) win.setCentralWidget(moduleArea) win.resize(1000, 500) win.setWindowTitle('Testing %s' % module.moduleName) win.show() app.start()