Skip to content

Commit

Permalink
Merge pull request #166 from I2PC/fi_refactorTest
Browse files Browse the repository at this point in the history
Fi refactor test
  • Loading branch information
Vilax authored Oct 26, 2023
2 parents 79a21cc + f5a6324 commit 72989e8
Show file tree
Hide file tree
Showing 11 changed files with 852 additions and 569 deletions.
64 changes: 64 additions & 0 deletions xmipptomo/tests/test_protocols_apply_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# **************************************************************************
# *
# * 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 '[email protected]'
# *
# **************************************************************************


from pyworkflow.tests import BaseTest, setupTestProject
from tomo.tests import DataSet

from xmipptomo.protocols import XmippProtApplyTransformSubtomo, XmippProtPhantomSubtomo


class TestXmipptomoApplyTransf(BaseTest):
"""This class check if the protocol apply_alignment_subtomo works properly."""

@classmethod
def setUpClass(cls):
setupTestProject(cls)
cls.dataset = DataSet.getDataSet('tomo-em')

def _runPreviousProtocols(self):
protPhantom = self.newProtocol(XmippProtPhantomSubtomo, option=1, nsubtomos=5)
self.launchProtocol(protPhantom)
self.assertIsNotNone(protPhantom.outputSubtomograms,
"There was a problem with subtomograms output")
return protPhantom

def _applyAlignment(self):
protPhantom = self._runPreviousProtocols()
apply = self.newProtocol(XmippProtApplyTransformSubtomo,
inputSubtomograms=protPhantom.outputSubtomograms)
self.launchProtocol(apply)
self.assertIsNotNone(apply.outputSubtomograms,
"There was a problem with subtomograms output")
self.assertIsNotNone(apply.outputAverage,
"There was a problem with average output")
return apply

def test_applyAlignment(self):
align = self._applyAlignment()
self.assertTrue(getattr(align, 'outputSubtomograms'))
self.assertTrue(getattr(align, 'outputAverage'))
return align
108 changes: 108 additions & 0 deletions xmipptomo/tests/test_protocols_cc_to_roi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# **************************************************************************
# *
# * 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 '[email protected]'
# *
# **************************************************************************


from pwem.protocols import ProtUnionSet
from pyworkflow.tests import BaseTest, setupTestProject
from tomo.tests import DataSet
from tomo.protocols import (ProtImportCoordinates3D,
ProtImportTomograms,
TomoProtFitEllipsoid)

from xmipptomo.protocols import XmippProtCCroi


class TestXmipptomoProtCCtoROI(BaseTest):
""" This class check if the protocol connected components to ROIs works properly."""

@classmethod
def setUpClass(cls):
setupTestProject(cls)
cls.dataset = DataSet.getDataSet('tomo-em')
cls.tomogram = cls.dataset.getFile('tomo1')
cls.coords3D = cls.dataset.getFile('overview_wbp.txt')

def _runPreviousProtocols(self):
protImportTomogram = self.newProtocol(ProtImportTomograms,
filesPath=self.tomogram,
samplingRate=5)
self.launchProtocol(protImportTomogram)
self.assertIsNotNone(protImportTomogram.Tomograms,
"There was a problem with tomogram output")

protImportCoordinates3d = self.newProtocol(ProtImportCoordinates3D,
filesPath=self.coords3D,
importTomograms=protImportTomogram.Tomograms,
boxSize=32,
samplingRate=5)
self.launchProtocol(protImportCoordinates3d)
self.assertIsNotNone(protImportCoordinates3d.outputCoordinates,
"There was a problem with coordinates 3d output")

protImportCoordinates3dBis = self.newProtocol(ProtImportCoordinates3D,
filesPath=self.coords3D,
importTomograms=protImportTomogram.Tomograms,
boxSize=32,
samplingRate=5)
self.launchProtocol(protImportCoordinates3dBis)
self.assertIsNotNone(protImportCoordinates3dBis.outputCoordinates,
"There was a problem with coordinates 3d output 2")

protJoinCoordinates = self.newProtocol(ProtUnionSet,
inputSets=[protImportCoordinates3d.outputCoordinates,
protImportCoordinates3dBis.outputCoordinates])
self.launchProtocol(protJoinCoordinates)
self.assertIsNotNone(protJoinCoordinates.outputSet,
"There was a problem with join coordinates output")

protFitVesicles = self.newProtocol(TomoProtFitEllipsoid,
input=protJoinCoordinates.outputSet,
inputTomos=protImportTomogram.Tomograms)
self.launchProtocol(protFitVesicles)
self.assertIsNotNone(protFitVesicles.outputMeshes, "There was a problem with output vesicles (SetOfMeshes)")
return protFitVesicles, protJoinCoordinates

def test_CCtoROIs(self):
protFitVesicles, protJoinCoordinates = self._runPreviousProtocols()
protCCtoROI = self.newProtocol(XmippProtCCroi,
inputCoordinates=protJoinCoordinates.outputSet,
inputMeshes=protFitVesicles.outputMeshes)
self.launchProtocol(protCCtoROI)
self.assertIsNotNone(protCCtoROI.outputSet, "There was a problem with CCtoROIs output")
self.assertEqual(protCCtoROI.outputSet.getSize(), 10)
self.assertEqual(protCCtoROI.outputSet.getBoxSize(), 32)
return protCCtoROI

def test_CCtoROIsPoints(self):
protFitVesicles, protJoinCoordinates = self._runPreviousProtocols()
protCCtoROI = self.newProtocol(XmippProtCCroi,
inputCoordinates=protJoinCoordinates.outputSet,
inputMeshes=protFitVesicles.outputMeshes,
selection=1)
self.launchProtocol(protCCtoROI)
self.assertIsNotNone(protCCtoROI.outputSet, "There was a problem with CCtoROIs points output")
self.assertEqual(protCCtoROI.outputSet.getSize(), 10)
self.assertEqual(protCCtoROI.outputSet.getBoxSize(), 32)
61 changes: 61 additions & 0 deletions xmipptomo/tests/test_protocols_conected_components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# **************************************************************************
# *
# * 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 '[email protected]'
# *
# **************************************************************************


from pyworkflow.tests import BaseTest, setupTestProject

from tomo.tests import DataSet
from tomo.protocols import (ProtImportCoordinates3D,
ProtImportTomograms)


class TestXmipptomoProtCC(BaseTest):
""" This class check if the protocol to compute connected components works
properly."""

@classmethod
def setUpClass(cls):
setupTestProject(cls)
cls.dataset = DataSet.getDataSet('tomo-em')
cls.tomogram = cls.dataset.getFile('tomo1')
cls.coords3D = cls.dataset.getFile('overview_wbp.txt')

def _runPreviousProtocols(self):
protImportTomogram = self.newProtocol(ProtImportTomograms,
filesPath=self.tomogram,
samplingRate=5)
self.launchProtocol(protImportTomogram)
protImportCoordinates3d = self.newProtocol(ProtImportCoordinates3D,
filesPath=self.coords3D,
importTomograms=protImportTomogram.Tomograms,
boxSize=32,
samplingRate=5)
self.launchProtocol(protImportCoordinates3d)
self.assertIsNotNone(protImportTomogram.Tomograms,
"There was a problem with tomogram output")
self.assertIsNotNone(protImportCoordinates3d.outputCoordinates,
"There was a problem with coordinates 3d output")
return protImportCoordinates3d
65 changes: 65 additions & 0 deletions xmipptomo/tests/test_protocols_half_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# **************************************************************************
# *
# * 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 '[email protected]'
# *
# **************************************************************************


import numpy as np

from pwem.emlib.image import ImageHandler
from pyworkflow.tests import BaseTest, setupTestProject

from xmipptomo.protocols import XmippProtPhantomSubtomo, XmippProtHalfMapsSubtomo


class TestXmipptomoHalfMaps(BaseTest):
"""This class check if the protocol to create half maps from a SetOfSubtomograms
works properly"""

@classmethod
def setUpClass(cls):
setupTestProject(cls)

def _phantom(self):
phantom = self.newProtocol(XmippProtPhantomSubtomo, option=1)
self.launchProtocol(phantom)
self.assertIsNotNone(phantom.outputSubtomograms,
"There was a problem with subtomograms output")
return phantom

def _half_maps(self, subtomos):
halfMaps = self.newProtocol(XmippProtHalfMapsSubtomo, inputSubtomograms=subtomos)
self.launchProtocol(halfMaps)
self.assertIsNotNone(halfMaps.halfMaps,
"There was a problem with half maps output")
return halfMaps

def test_half_maps(self):
phantom = self._phantom()
halfMaps = self._half_maps(phantom.outputSubtomograms)
mapEven = np.squeeze(ImageHandler().read(halfMaps.halfMaps[1].getFileName()).getData())
mapOdd = np.squeeze(ImageHandler().read(halfMaps.halfMaps[2].getFileName()).getData())
error = np.sqrt(np.sum((mapEven - mapOdd) ** 2) / mapEven.size)
self.assertAlmostEqual(error, 0.0, delta=0.1, msg="Unexpected half maps")
return halfMaps
78 changes: 78 additions & 0 deletions xmipptomo/tests/test_protocols_mapback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# **************************************************************************
# *
# * 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 '[email protected]'
# *
# **************************************************************************


from pyworkflow.tests import BaseTest, setupTestProject

from tomo.tests import DataSet
from tomo.protocols import ProtImportTomograms

from xmipptomo.protocols import XmippProtSubtomoMapBack, XmippProtPhantomSubtomo


class TestXmipptomoMapback(BaseTest):
"""This class check if the protocol mapback works properly."""

@classmethod
def setUpClass(cls):
setupTestProject(cls)
cls.dataset = DataSet.getDataSet('tomo-em')
cls.tomogram = cls.dataset.getFile('tomo1')
cls.coords3D = cls.dataset.getFile('overview_wbp.txt')

def _runPreviousProtocols(self):
protImportTomogram = self.newProtocol(ProtImportTomograms,
filesPath=self.tomogram,
samplingRate=5)
self.launchProtocol(protImportTomogram)
self.assertIsNotNone(protImportTomogram.Tomograms,
"There was a problem with tomogram output")

protPhantom = self.newProtocol(XmippProtPhantomSubtomo,
option=1,
sampling=4,
nsubtomos=5,
coords=True,
tomos=protImportTomogram.Tomograms)
self.launchProtocol(protPhantom)
self.assertIsNotNone(protPhantom.outputSubtomograms,
"There was a problem with subtomograms output")

return protImportTomogram, protPhantom

def test_mapback(self):
_, protPhantom = self._runPreviousProtocols()
mapback = self.newProtocol(XmippProtSubtomoMapBack,
selection=1,
inputSubtomos=protPhantom.outputSubtomograms,
inputRef=protPhantom,
removeBackground=True)

mapback.inputRef.setExtended("outputSubtomograms.1")
self.launchProtocol(mapback)

self.assertSetSize(getattr(mapback, XmippProtSubtomoMapBack._possibleOutputs.tomograms.name), 1,
"There was a problem with tomograms output")
Loading

0 comments on commit 72989e8

Please sign in to comment.