Source code for ccpn.AnalysisScreen.pipes.PropagateFromReferences

#=========================================================================================
# 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__ = "$Date: 2021-05-19 16:26:00 +0100 (Wed, May 19, 2021) $"
__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: 2021-05-19 16:26:00 +0100 (Wed, May 19, 2021) $"
#=========================================================================================
# 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.CheckBox import CheckBox
from ccpn.ui.gui.widgets.DoubleSpinbox import DoubleSpinbox, ScientificDoubleSpinBox
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 = 'Propagate Peaks From References'
Propagate_ToSG = 'Propagate_To'
PeakListLabel = 'PeakList'
Last = 'Last'
New = 'New'
PlistOptions = [Last, New]
SnapNewPeak = 'Snap_Peaks'
Tolerance = 'Max_snap_distance_(ppm)'
SGVarNames = [Propagate_ToSG]
defaultPeakListIndice = -1
DefaultSnap = True
DefaultTolerance = 0.1 #ppm


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


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


[docs]class PropagatePeaksFromReferencesGuiPipe(GuiPipe): pipeName = PipeName def __init__(self, name=pipeName, parent=None, project=None, **kw): super(PropagatePeaksFromReferencesGuiPipe, self) GuiPipe.__init__(self, parent=parent, name=name, project=project, **kw) self.parent = parent row = 0 hw._addSGpulldowns(self, row, SGVarNames) row += len(SGVarNames) self.snapPeaksLabel = Label(self.pipeFrame, PeakListLabel, grid=(row, 0)) setattr(self, PeakListLabel, RadioButtons(self.pipeFrame, texts=PlistOptions, selectedInd=0, direction='v', callback=None, grid=(row, 1))) row += 1 self.snapPeaksLabel = Label(self.pipeFrame, SnapNewPeak, grid=(row, 0)) setattr(self, SnapNewPeak, CheckBox(self.pipeFrame, checked=DefaultSnap, callback=None, grid=(row, 1))) row += 1 self.ToleranceLabel = Label(self.pipeFrame, text=Tolerance, grid=(row, 0)) setattr(self, Tolerance, ScientificDoubleSpinBox(self.pipeFrame, value=DefaultTolerance, min=0.0001, step=0.01, decimals=3, grid=(row, 1))) self._updateWidgets() def _updateWidgets(self): self._setSpectrumGroupPullDowns(SGVarNames)
######################################################################################################################## ########################################## PIPE ############################################################# ########################################################################################################################
[docs]class PropagatePeaksFromReferencesPipe(SpectraPipe): """ Apply phasing to all the spectra in the pipeline """ guiPipe = PropagatePeaksFromReferencesGuiPipe pipeName = PipeName pipeCategory = PIPE_SCREEN _kwargs = { Propagate_ToSG: 'ControlSpectrumGroup.pid', #this will be replaced by the SG pid in the gui SnapNewPeak: DefaultSnap, Tolerance : DefaultSnap, PeakListLabel : Last, }
[docs] def runPipe(self, spectra): ''' :param spectra: inputData :return: spectra ''' # self.project.blankNotification() propagate_ToSG = self._getSpectrumGroup(self._kwargs[Propagate_ToSG]) createNewPL = True if self._kwargs[PeakListLabel] == New else False with undoBlockWithoutSideBar(): if self.project is not None: if propagate_ToSG is not None: for controlSpectrum in propagate_ToSG.spectra: allPeaks = [] references = _getReferencesFromSample(controlSpectrum) for spectrum in references: allPeaks += spectrum.peakLists[-1].peaks # create a newPeakList where to paste the references peaks if createNewPL: pl= controlSpectrum.newPeakList() else: pl = controlSpectrum.peakLists[-1] or controlSpectrum.newPeakList() # New PL if None avail for peak in allPeaks: peak.copyTo(pl) if self._kwargs[SnapNewPeak]: snap1DPeaksToExtrema(allPeaks, self._kwargs[Tolerance]) return spectra else: getLogger().warning('Spectra not present. Add spectra first') return spectra
PropagatePeaksFromReferencesPipe.register() # Registers the pipe in the pipeline