Source code for ccpn.AnalysisScreen.pipes.LinkSubstancesToSpectrum

#=========================================================================================
# 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 19:38:32 +0100 (Fri, June 04, 2021) $"
__version__ = "$Revision: 3.0.4 $"
#=========================================================================================
# Created
#=========================================================================================
__author__ = "$Author: Luca Mureddu $"
__date__ = "$Date: 2017-05-28 10:28:42 +0000 (Sun, May 28, 2017) $"
#=========================================================================================
# Start of code
#=========================================================================================


#### GUI IMPORTS
from ccpn.AnalysisScreen.gui.widgets import HitFinderWidgets as hw
from ccpn.ui.gui.widgets.PipelineWidgets import GuiPipe
from ccpn.ui.gui.widgets.Label import Label
from ccpn.ui.gui.widgets.RadioButtons import RadioButtons

#### NON GUI IMPORTS
from ccpn.framework.lib.pipeline.PipeBase import SpectraPipe, PIPE_SCREEN
from ccpn.core.lib.peakUtils import snap1DPeaksToExtrema
from ccpn.AnalysisScreen.lib.experimentAnalysis.Common import _getReferencesFromSample
from ccpn.util.Logging import getLogger
from ccpn.core.lib.ContextManagers import undoBlock, notificationEchoBlocking, \
    undoBlockWithoutSideBar, undoStackBlocking

########################################################################################################################
###   Attributes:
###   Used in setting the dictionary keys on _kwargs either in GuiPipe and Pipe
########################################################################################################################

PipeName = 'Link Substances To Spectrum'



########################################################################################################################
##########################################      ALGORITHM       ########################################################
########################################################################################################################


########################################################################################################################
##########################################     GUI PIPE    #############################################################
########################################################################################################################


[docs]class LinkSubstancesToSpectrumGuiPipe(GuiPipe): pipeName = PipeName def __init__(self, name=pipeName, parent=None, project=None, **kw): super(LinkSubstancesToSpectrumGuiPipe, self) GuiPipe.__init__(self, parent=parent, name=name, project=project, **kw) self.parent = parent
######################################################################################################################## ########################################## PIPE ############################################################# ########################################################################################################################
[docs]class LinkSubstancesToSpectrumPipe(SpectraPipe): """ Link substances to a spectrum recorded for a mixture of screening substances. Normally a substance has a link to the reference spectrum for one single compound. 1:1 link The spectrum recorded for a mixture is linked to sample. The sample is made by components linked to substances of same name. In this pipe all those substances will be directly linked to to the mixture spectrum MixtureSpectrum -> ReferenceSubstances = [Empty] MixtureSpectrum -> Sample -> SampleComponent -> Substance -> ReferenceSpectrum new link from this pipe: MixtureSpectrum -> ReferenceSubstances = [all substances in the MixtureSpectrum.sample] As a result, references don't need be loaded for screening Analysis. See Recurrent Screening Analyses Manual """ guiPipe = LinkSubstancesToSpectrumGuiPipe pipeName = PipeName pipeCategory = PIPE_SCREEN _kwargs = { }
[docs] def runPipe(self, spectra): ''' :param spectra: inputData :return: spectra ''' if not spectra: getLogger().warning('Spectra not present. Add spectra first') return spectra with undoBlockWithoutSideBar(): if self.project is not None: for sp in spectra: sa = sp.sample if not sa: getLogger().warning('No sample detected for spectrum %s. Skipping' %sp.pid) continue subs = [sc.substance for sc in sa.sampleComponents if sc.substance is not None] sp.referenceSubstances = subs return spectra
LinkSubstancesToSpectrumPipe.register() # Registers the pipe in the pipeline