From c4ff6e32bbe9c60c1ec55fea01b740a765b783ba Mon Sep 17 00:00:00 2001 From: Vilax Date: Wed, 22 May 2024 17:31:12 +0200 Subject: [PATCH 1/4] adding protocols to legacy --- xmipptomo/protocols/__init__.py | 2 -- .../protocols/{ => legacy}/protocol_denoising_confidence.py | 0 xmipptomo/protocols/{ => legacy}/protocol_score_transform.py | 0 3 files changed, 2 deletions(-) rename xmipptomo/protocols/{ => legacy}/protocol_denoising_confidence.py (100%) rename xmipptomo/protocols/{ => legacy}/protocol_score_transform.py (100%) diff --git a/xmipptomo/protocols/__init__.py b/xmipptomo/protocols/__init__.py index 3fe53a6a..5b62c29b 100644 --- a/xmipptomo/protocols/__init__.py +++ b/xmipptomo/protocols/__init__.py @@ -35,7 +35,6 @@ from .protocol_dose_filter import XmippProtDoseFilter from .protocol_filter_coordinates_by_map import XmippProtFilterCoordinatesByMap from .protocol_crop_tomograms import XmippProtCropTomograms -from .protocol_denoising_confidence import XmippProtConfTomo from .protocol_extract_particlestacks import XmippProtExtractParticleStacks from .protocol_extract_subtomos import XmippProtExtractSubtomos from .protocol_flexalign import XmippProtTsFlexAlign @@ -49,7 +48,6 @@ from .protocol_resolution_local_monotomo import XmippProtMonoTomo from .protocol_roiIJ import XmippProtRoiIJ from .protocol_score_coordinates import XmippProtScoreCoordinates -from .protocol_score_transform import XmippProtScoreTransform from .protocol_splitTS import XmippProtSplitTiltSeries from .protocol_subtraction_subtomo import XmippProtSubtractionSubtomo from .protocol_subtomo_map_back import XmippProtSubtomoMapBack diff --git a/xmipptomo/protocols/protocol_denoising_confidence.py b/xmipptomo/protocols/legacy/protocol_denoising_confidence.py similarity index 100% rename from xmipptomo/protocols/protocol_denoising_confidence.py rename to xmipptomo/protocols/legacy/protocol_denoising_confidence.py diff --git a/xmipptomo/protocols/protocol_score_transform.py b/xmipptomo/protocols/legacy/protocol_score_transform.py similarity index 100% rename from xmipptomo/protocols/protocol_score_transform.py rename to xmipptomo/protocols/legacy/protocol_score_transform.py From b262edafc6dc5bbd14bd4fe770055cf0d4498ab7 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Thu, 23 May 2024 07:16:04 +0200 Subject: [PATCH 2/4] refactoring folders, adding test to legacy --- .../protocol_denoising_confidence.py | 0 .../protocols}/protocol_score_transform.py | 0 .../tests/test_protocol_score_transform.py | 71 +++++++++++++++++++ 3 files changed, 71 insertions(+) rename xmipptomo/{protocols/legacy => legacy/protocols}/protocol_denoising_confidence.py (100%) rename xmipptomo/{protocols/legacy => legacy/protocols}/protocol_score_transform.py (100%) create mode 100644 xmipptomo/legacy/tests/test_protocol_score_transform.py diff --git a/xmipptomo/protocols/legacy/protocol_denoising_confidence.py b/xmipptomo/legacy/protocols/protocol_denoising_confidence.py similarity index 100% rename from xmipptomo/protocols/legacy/protocol_denoising_confidence.py rename to xmipptomo/legacy/protocols/protocol_denoising_confidence.py diff --git a/xmipptomo/protocols/legacy/protocol_score_transform.py b/xmipptomo/legacy/protocols/protocol_score_transform.py similarity index 100% rename from xmipptomo/protocols/legacy/protocol_score_transform.py rename to xmipptomo/legacy/protocols/protocol_score_transform.py diff --git a/xmipptomo/legacy/tests/test_protocol_score_transform.py b/xmipptomo/legacy/tests/test_protocol_score_transform.py new file mode 100644 index 00000000..fbfff5fb --- /dev/null +++ b/xmipptomo/legacy/tests/test_protocol_score_transform.py @@ -0,0 +1,71 @@ +# ************************************************************************** +# * +# * Authors: Federico P. de Isidro-Gomez +# * +# * [1] Centro Nacional de Biotecnologia, CSIC, Spain +# * +# * This program is free software; you can redistribute it and/or modify +# * it under the terms of the GNU General Public License as published by +# * the Free Software Foundation; either version 2 of the License, or +# * (at your option) any later version. +# * +# * This program is distributed in the hope that it will be useful, +# * but WITHOUT ANY WARRANTY; without even the implied warranty of +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# * GNU General Public License for more details. +# * +# * You should have received a copy of the GNU General Public License +# * along with this program; if not, write to the Free Software +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +# * 02111-1307 USA +# * +# * All comments concerning this program package may be sent to the +# * e-mail address 'scipion@cnb.csic.es' +# * +# ************************************************************************** +import numpy as np +from pyworkflow.tests import BaseTest, setupTestProject +from tomo.tests import DataSet + +from xmipptomo.protocols import XmippProtScoreTransform +from tomo.protocols import ProtImportSubTomograms + +class TestXmippTomoScoreTransform(BaseTest): + """This class check if the protocol score_transform works properly.""" + + @classmethod + def setUpClass(cls): + setupTestProject(cls) + cls.dataset = DataSet.getDataSet('tomo-em') + cls.setOfSubtomograms = cls.dataset.getFile('basename.hdf') + + def _runImportSubtomos(self, label): + protImport = self.newProtocol(ProtImportSubTomograms, + filesPath=self.setOfSubtomograms, + samplingRate=5, + label=label) + self.launchProtocol(protImport) + self.assertIsNotNone(protImport.outputSubTomograms, + "There was a problem with import subtomograms output") + return protImport.outputSubTomograms + + def _scoreTransformations(self, firstSubtomos, secondSubtomos): + scoredTr = self.newProtocol(XmippProtScoreTransform, + firstSubtomos=firstSubtomos, + secondSubtomos=secondSubtomos, + label='Score Subtomogram Transformations') + self.launchProtocol(scoredTr) + self.assertIsNotNone(scoredTr.outputSetOfSubtomogram, + "There was a problem with score subtomograms output") + return scoredTr.outputSetOfSubtomogram + + def test_scoreTransformations(self): + firstSubtomos = self._runImportSubtomos('First Subtomograms') + secondSubtomos = self._runImportSubtomos('Second Subtomograms') + scoredSubtomos = self._scoreTransformations(firstSubtomos, secondSubtomos) + self.assertTrue(scoredSubtomos.getSize() == 4) + dist = scoredSubtomos.aggregate(["MAX"], "distanceScore", ["distanceScore"]) + dist = np.asarray([d["distanceScore"] for d in dist]) + meanDist = np.mean(dist) + self.assertTrue(meanDist == 0) + return scoredSubtomos From 946c9f3e2691c9aba214e23173c96d8080197652 Mon Sep 17 00:00:00 2001 From: Vilax Date: Thu, 23 May 2024 12:17:12 +0200 Subject: [PATCH 3/4] removing viewer --- xmipptomo/viewers/__init__.py | 1 - xmipptomo/viewers/viewer_score_subtomos.py | 73 ---------------------- 2 files changed, 74 deletions(-) delete mode 100644 xmipptomo/viewers/viewer_score_subtomos.py diff --git a/xmipptomo/viewers/__init__.py b/xmipptomo/viewers/__init__.py index 64a586c8..4b362cc8 100644 --- a/xmipptomo/viewers/__init__.py +++ b/xmipptomo/viewers/__init__.py @@ -27,5 +27,4 @@ from .viewer_cltomo import XmippCLTomoViewer, XmippProtTsFlexAlignViewer from .viewer_resolution_local_monotomo import XmippMonoTomoViewer from .viewer_phantom_create import XmippPhantomSubtomoViewer -from .viewer_score_subtomos import XmippTomoScoreSubtomoViewer diff --git a/xmipptomo/viewers/viewer_score_subtomos.py b/xmipptomo/viewers/viewer_score_subtomos.py deleted file mode 100644 index 52a501f3..00000000 --- a/xmipptomo/viewers/viewer_score_subtomos.py +++ /dev/null @@ -1,73 +0,0 @@ -# ************************************************************************** -# * -# * Authors: Pablo Conesa (pconesa@cnb.csic.es), -# * -# * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC -# * -# * This program is free software; you can redistribute it and/or modify -# * it under the terms of the GNU General Public License as published by -# * the Free Software Foundation; either version 2 of the License, or -# * (at your option) any later version. -# * -# * This program is distributed in the hope that it will be useful, -# * but WITHOUT ANY WARRANTY; without even the implied warranty of -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# * GNU General Public License for more details. -# * -# * You should have received a copy of the GNU General Public License -# * along with this program; if not, write to the Free Software -# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# * 02111-1307 USA -# * -# * All comments concerning this program package may be sent to the -# * e-mail address 'scipion@cnb.csic.es' -# * -# ************************************************************************** -from tomo.objects import SetOfSubTomograms -from xmipptomo.protocols.protocol_score_transform import ScoreTransformOutputs -from pyworkflow.viewer import Viewer - -from xmipptomo.protocols import XmippProtScoreTransform -from pwem.viewers.plotter import EmPlotter, plt - - -class XmippTomoScoreSubtomoViewer(Viewer): - """ Visualize the output of protocol reconstruct swarm """ - _label = 'Score transformation viewer' - _targets = [XmippProtScoreTransform] - - def _visualize(self, scoreProtocol: XmippProtScoreTransform, **kwargs): - # Keep input object in case we need to launch - # a new protocol and set dependencies - - views =[] - subtomos = getattr(scoreProtocol, ScoreTransformOutputs.Subtomograms.name) - - views.append(self.plotScoreHistogram(subtomos, **kwargs)) - - views.append(self.plotAngularDistibution(subtomos,**kwargs)) - - return views - - def plotAngularDistibution(self, subtomos:SetOfSubTomograms, **kwargs): - - plotter = EmPlotter(x=1, y=1, windowTitle='Angular distribution') - - plotter.plotAngularDistributionFromSet(subtomos, "Angular distribution", weightAttr=XmippProtScoreTransform.SCORE_ATTR) - - return plotter - - def plotScoreHistogram(self, subtomos:SetOfSubTomograms, **kwargs): - - plotter = EmPlotter(x=1, y=1, windowTitle='Angular distance histogram') - - - results = subtomos.getUniqueValues(["id", XmippProtScoreTransform.SCORE_ATTR]) - - scores = results[XmippProtScoreTransform.SCORE_ATTR] - - plotter.createSubPlot("Angular distance histogram", "angle", "count") - - plotter.plotHist(scores, 30) - - return plotter From 28b33356f1a9e2ae078ab56757d5a846e9e42c2d Mon Sep 17 00:00:00 2001 From: Vilax Date: Thu, 23 May 2024 13:08:46 +0200 Subject: [PATCH 4/4] legacy viewer --- .../legacy/viewers/viewer_score_subtomos.py | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 xmipptomo/legacy/viewers/viewer_score_subtomos.py diff --git a/xmipptomo/legacy/viewers/viewer_score_subtomos.py b/xmipptomo/legacy/viewers/viewer_score_subtomos.py new file mode 100644 index 00000000..52a501f3 --- /dev/null +++ b/xmipptomo/legacy/viewers/viewer_score_subtomos.py @@ -0,0 +1,73 @@ +# ************************************************************************** +# * +# * Authors: Pablo Conesa (pconesa@cnb.csic.es), +# * +# * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC +# * +# * This program is free software; you can redistribute it and/or modify +# * it under the terms of the GNU General Public License as published by +# * the Free Software Foundation; either version 2 of the License, or +# * (at your option) any later version. +# * +# * This program is distributed in the hope that it will be useful, +# * but WITHOUT ANY WARRANTY; without even the implied warranty of +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# * GNU General Public License for more details. +# * +# * You should have received a copy of the GNU General Public License +# * along with this program; if not, write to the Free Software +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +# * 02111-1307 USA +# * +# * All comments concerning this program package may be sent to the +# * e-mail address 'scipion@cnb.csic.es' +# * +# ************************************************************************** +from tomo.objects import SetOfSubTomograms +from xmipptomo.protocols.protocol_score_transform import ScoreTransformOutputs +from pyworkflow.viewer import Viewer + +from xmipptomo.protocols import XmippProtScoreTransform +from pwem.viewers.plotter import EmPlotter, plt + + +class XmippTomoScoreSubtomoViewer(Viewer): + """ Visualize the output of protocol reconstruct swarm """ + _label = 'Score transformation viewer' + _targets = [XmippProtScoreTransform] + + def _visualize(self, scoreProtocol: XmippProtScoreTransform, **kwargs): + # Keep input object in case we need to launch + # a new protocol and set dependencies + + views =[] + subtomos = getattr(scoreProtocol, ScoreTransformOutputs.Subtomograms.name) + + views.append(self.plotScoreHistogram(subtomos, **kwargs)) + + views.append(self.plotAngularDistibution(subtomos,**kwargs)) + + return views + + def plotAngularDistibution(self, subtomos:SetOfSubTomograms, **kwargs): + + plotter = EmPlotter(x=1, y=1, windowTitle='Angular distribution') + + plotter.plotAngularDistributionFromSet(subtomos, "Angular distribution", weightAttr=XmippProtScoreTransform.SCORE_ATTR) + + return plotter + + def plotScoreHistogram(self, subtomos:SetOfSubTomograms, **kwargs): + + plotter = EmPlotter(x=1, y=1, windowTitle='Angular distance histogram') + + + results = subtomos.getUniqueValues(["id", XmippProtScoreTransform.SCORE_ATTR]) + + scores = results[XmippProtScoreTransform.SCORE_ATTR] + + plotter.createSubPlot("Angular distance histogram", "angle", "count") + + plotter.plotHist(scores, 30) + + return plotter