Skip to content

Commit

Permalink
Merge pull request #29 from scipion-em/devel
Browse files Browse the repository at this point in the history
Release 3.1.1
  • Loading branch information
pconesa authored Nov 15, 2023
2 parents edefcff + 50bb905 commit 926509d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
v3.1.1:
- Installer updated: binaries are automatically downloaded now. Thanks to José Jesús Fernández.
v3.1.0:
- First plugin release
41 changes: 19 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
==============================
Scipion - TomoSegMemTV plugin
==============================
=====================================================
Scipion plugin for TomoSegMemTV and MembraneAnnotator
=====================================================

.. image:: https://img.shields.io/pypi/v/scipion-em-tomosegmemtv.svg
:target: https://pypi.python.org/pypi/scipion-em-tomosegmemtv
:alt: PyPI release

.. image:: https://img.shields.io/pypi/l/scipion-em-tomosegmemtv.svg
:target: https://pypi.python.org/pypi/scipion-em-tomosegmemtv
:alt: License

.. image:: https://img.shields.io/pypi/pyversions/scipion-em-tomosegmemtv.svg
:target: https://pypi.python.org/pypi/scipion-em-tomosegmemtv
:alt: Supported Python versions

.. image:: https://img.shields.io/pypi/dm/scipion-em-tomosegmemtv
:target: https://pypi.python.org/pypi/scipion-em-tomosegmemtv
:alt: Downloads

Scipion plugin for segmentation and annotation of membranes in tomograms (with TomoSegmenTV_ and memb-annotator_,
respectively)
Expand Down Expand Up @@ -30,25 +46,6 @@ The plugin can be installed in user (stable) or developer (latest, may be unstab
scipion3 installp -p local/path/to/scipion-em-tomosegmemtv --devel
=====================================
Getting the binaries for tomoSegmenTV
=====================================

TomoSegmenTV binaries must be downloaded from the following site
https://sites.google.com/site/3demimageprocessing/tomosegmemtv, where a form must be filled and submitted to get
instant download access. Download the standalone version (which will be a zip file), unzip it and move the binary file
to the directory SCIPION_HOME/software/em/TOMOSEGMEMB_DIRECTORY/tomoSegMemTV/bin/. It can be directly done executing
the following command on a terminal:

.. code-block::
cd DOWNLOADED_FILE_DIRECTORY
.. code-block::
unzip DOWNLOADED/FILE -d SCIPION_HOME/software/em/TOMOSEGMEM_DIRECTORY/tomoSegMemTV/bin/
=========
Protocols
=========
Expand Down
34 changes: 28 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,40 @@
setup(
name='scipion-em-tomosegmemtv', # Required
version=__version__, # Required
description='Scipion plugin tomosegmemtv.', # Required
description='Scipion plugin for softare packages tomosegmemTV and membraneAnnotator.', # Required
long_description=long_description, # Optional
url='https://github.com/scipion-em/scipion-em-tomosegmembtv', # Optional
author='you', # Optional
author_email='[email protected]', # Optional
url='https://github.com/scipion-em/scipion-em-tomosegmemtv', # Optional
author='I2PC', # Optional
author_email='[email protected]', # Optional
keywords='scipion cryoem cryoet imageprocessing scipion-3.0', # Optional
packages=find_packages(),
install_requires=[requirements],
entry_points={
'pyworkflow.plugin': 'tomosegmemtv = tomosegmemtv'
},
package_data={ # Optional
'tomosegmemtv': ['protocols.conf', 'icon.png'],
}
'tomosegmemtv': ['protocols.conf', 'icon.png'],
},
# For a list of valid classifiers, see
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[ # Optional
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: Production/Stable',

# Indicate who your project is intended for
# 'Intended Audience :: Users',

# Pick your license as you wish
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3',

# Specify Framework
'Framework :: Scipion :: 3'
],
)
35 changes: 21 additions & 14 deletions tomosegmemtv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
import pwem
import os

from pyworkflow.utils import Environ
from pyworkflow.utils import Environ, replaceExt

from tomosegmemtv.constants import TOMOSEGMEMTV_HOME, TOMOSEGMEMTV, TOMOSEGMEMTV_DEFAULT_VERSION, MEMBANNOTATOR, \
MEMBANNOTATOR_DEFAULT_VERSION, MEMBANNOTATOR_EM_DIR, TOMOSEGMEMTV_DIR, TOMOSEGMEMTV_EM_DIR, MEMBANNOTATOR_BIN

_references = ['MartinezSanchez2014']
__version__ = '3.1.0'
__version__ = '3.1.1'
_logo = "icon.png"


class Plugin(pwem.Plugin):

_homeVar = TOMOSEGMEMTV_HOME
_pathVars = [TOMOSEGMEMTV_HOME]
_url = "https://github.com/scipion-em/scipion-em-tomosegmemtv"
_url = "https://sites.google.com/site/3demimageprocessing/tomosegmemtv"

@classmethod
def _defineVariables(cls):
Expand Down Expand Up @@ -76,20 +76,27 @@ def defineBinaries(cls, env):
pluginHome = join(pwem.Config.EM_ROOT, TOMOSEGMEMTV_EM_DIR)
tomoSegmenTVHome = join(pluginHome, TOMOSEGMEMTV)
membraneAnnotatorHome = join(pluginHome, MEMBANNOTATOR_EM_DIR)
# membraneAnnotatorTar = join(pwem.Config.EM_ROOT, MEMBANNOTATOR_EM_DIR + '.tar.gz')

TOMOSEGMEMTV_INSTALLED = '%s_installed' % TOMOSEGMEMTV

# TomosegmenTV: only the directory will be generated, because the binaries must be downloaded manually from José
# Jesús website, filling a form
installationCmd = cls._genMembAnnCmd(membraneAnnotatorHome)
installationCmd += 'mkdir %s && ' % tomoSegmenTVHome
installationCmd += 'cd %s && ' % pluginHome
installationCmd += 'touch %s' % TOMOSEGMEMTV_INSTALLED # Flag installation finished
pattern = '%s_installed'
TOMOSEGMEMTV_INSTALLED = pattern % TOMOSEGMEMTV
MEMBRANE_ANN_INSTALLED = pattern % MEMBANNOTATOR

# Tomosegmemtv installation cmd
dlZipFileName = TOMOSEGMEMTV + '.zip'
tomosegmemtvInstallCmd = 'wget http://tiny.cc/vvu7vz -O %s && ' % dlZipFileName
tomosegmemtvInstallCmd += 'mkdir %s && ' % tomoSegmenTVHome
tomosegmemtvInstallCmd += 'unzip %s -d %s && ' % (dlZipFileName, tomoSegmenTVHome)
tomosegmemtvInstallCmd += 'touch %s' % TOMOSEGMEMTV_INSTALLED

# Membrane annotator installation cmd
membAnnInstallCmd = cls._genMembAnnCmd(membraneAnnotatorHome)
membAnnInstallCmd += 'cd %s && ' % pluginHome
membAnnInstallCmd += 'touch %s' % MEMBRANE_ANN_INSTALLED # Flag installation finished
env.addPackage(TOMOSEGMEMTV,
version=TOMOSEGMEMTV_DEFAULT_VERSION,
tar='void.tgz',
commands=[(installationCmd, TOMOSEGMEMTV_INSTALLED)],
commands=[(tomosegmemtvInstallCmd, TOMOSEGMEMTV_INSTALLED),
(membAnnInstallCmd, MEMBRANE_ANN_INSTALLED)],
neededProgs=["wget", "tar"],
default=True)

Expand All @@ -105,7 +112,7 @@ def getProgram(cls, program):
@classmethod
def runTomoSegmenTV(cls, protocol, program, args, cwd=None):
""" Run tomoSegmenTV command from a given protocol. """
protocol.runJob( cls.getProgram(program), args, cwd=cwd)
protocol.runJob(cls.getProgram(program), args, cwd=cwd)

@classmethod
def getMCRPath(cls):
Expand Down
2 changes: 0 additions & 2 deletions tomosegmemtv/protocols/protocol_annotate_membranes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from enum import Enum

from pwem.protocols import EMProtocol
from pyworkflow import BETA
from pyworkflow.object import Integer
from pyworkflow.protocol import PointerParam
from pyworkflow.utils import removeBaseExt
Expand All @@ -44,7 +43,6 @@ class ProtAnnotateMembranes(EMProtocol):
""" Manual annotation tool for segmented membranes
"""
_label = 'annotate segmented membranes'
_devStatus = BETA
_possibleOutputs = outputObjects

def __init__(self, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions tomosegmemtv/protocols/protocol_resize_tomomask.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import numpy as np
from pwem.emlib.image import ImageHandler
from pwem.protocols import EMProtocol
from pyworkflow import BETA
from pyworkflow.protocol import PointerParam
from pyworkflow.utils import Message, removeBaseExt, getExt, getParentFolder
from tomo.objects import SetOfTomoMasks, TomoMask
Expand All @@ -45,7 +44,6 @@ class ProtResizeSegmentedVolume(EMProtocol):
"""Resize segmented volumes or annotated (TomoMasks)."""

_label = 'Resize segmented or annotated volume'
_devStatus = BETA
_possibleOutputs = outputObjects
resizedFileList = []

Expand Down
29 changes: 18 additions & 11 deletions tomosegmemtv/protocols/protocol_tomosegmentv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from os import remove
from os.path import abspath
from pwem.protocols import EMProtocol
from pyworkflow import BETA
from pyworkflow.protocol import PointerParam, IntParam, GT, FloatParam, BooleanParam, LEVEL_ADVANCED
from pyworkflow.utils import Message, removeBaseExt, replaceBaseExt, createLink
from tomo.objects import SetOfTomoMasks, TomoMask
Expand Down Expand Up @@ -55,7 +54,6 @@ class ProtTomoSegmenTV(EMProtocol):
"""Segment membranes in tomograms"""

_label = 'tomogram segmentation'
_devStatus = BETA
_possibleOutputs = outputObjects
tomoMaskListDelineated = []

Expand Down Expand Up @@ -145,6 +143,8 @@ def _defineParams(self, form):
' - Saliency --> *filename%s.mrc*' % (S2, TV, SURF, TV2, FLT)
)

form.addParallelSection(threads=8, mpi =1)

def _insertAllSteps(self):
self._insertFunctionStep(self.convertInputStep)
for tomo in self.inTomograms.get():
Expand All @@ -162,22 +162,25 @@ def convertInputStep(self):
def runTomoSegmenTV(self, tomoFile):
tomoBaseName = removeBaseExt(tomoFile)
tomoFile = self._getExtraPath(tomoBaseName + '.mrc')

Nthreads = self.numberOfThreads.get()

# Scale space
s2OutputFile = self._getExtraPath(tomoBaseName + S2 + MRC)
Plugin.runTomoSegmenTV(self, SCALE_SPACE, self._getScaleSpaceCmd(tomoFile, s2OutputFile))
Plugin.runTomoSegmenTV(self, SCALE_SPACE, self._getScaleSpaceCmd(tomoFile, Nthreads, s2OutputFile))
# Tensor voting
tVOutputFile = self._getExtraPath(tomoBaseName + TV + MRC)
Plugin.runTomoSegmenTV(self, 'dtvoting', self._getTensorVotingCmd(s2OutputFile, tVOutputFile))
Plugin.runTomoSegmenTV(self, 'dtvoting', self._getTensorVotingCmd(s2OutputFile, tVOutputFile, Nthreads))
# Surfaceness
surfOutputFile = self._getExtraPath(tomoBaseName + SURF + MRC)
Plugin.runTomoSegmenTV(self, 'surfaceness', self._getSurfCmd(tVOutputFile, surfOutputFile))
Plugin.runTomoSegmenTV(self, 'surfaceness', self._getSurfCmd(tVOutputFile, surfOutputFile, Nthreads))
# Tensor voting - second round (to fill potential gaps and increase the robustness of the surfaceness map)
tV2OutputFile = self._getExtraPath(tomoBaseName + TV2 + MRC)
Plugin.runTomoSegmenTV(self, 'dtvoting',
self._getTensorVotingCmd(surfOutputFile, tV2OutputFile, isFirstRound=False))
self._getTensorVotingCmd(surfOutputFile, tV2OutputFile, Nthreads, isFirstRound=False))
# Saliency - second round (apply again the surfaceness program, but this time to produce the saliency)
salOutputFile = self._getExtraPath(tomoBaseName + FLT + MRC)
Plugin.runTomoSegmenTV(self, 'surfaceness', self._getSalCmd(tV2OutputFile, salOutputFile))
Plugin.runTomoSegmenTV(self, 'surfaceness', self._getSalCmd(tV2OutputFile, salOutputFile, Nthreads))
self.tomoMaskListDelineated.append(salOutputFile)
# Remove intermediate files if requested
if not self.keepAllFiles.get():
Expand Down Expand Up @@ -221,33 +224,37 @@ def _validate(self):

# --------------------------- UTIL functions -----------------------------------

def _getScaleSpaceCmd(self, inputFile, outputFile):
def _getScaleSpaceCmd(self, inputFile, Nthreads, outputFile):
outputCmd = '-s %s ' % self.mbThkPix.get()
outputCmd += '%s ' % inputFile
outputCmd += '%s ' % outputFile
outputCmd += ' -t %i' % Nthreads
return outputCmd

def _getTensorVotingCmd(self, inputFile, outputFile, isFirstRound=True):
def _getTensorVotingCmd(self, inputFile, outputFile, Nthreads, isFirstRound=True):
outputCmd = '-s %s ' % self.mbScaleFactor.get()
if isFirstRound and not self.blackOverWhite.get():
outputCmd += '-w '
elif not isFirstRound:
outputCmd += '-w ' # After the first tensor voting, the image will be always white over black
outputCmd += '%s ' % inputFile
outputCmd += '%s ' % outputFile
outputCmd += ' -t %i' % Nthreads
return outputCmd

def _getSurfCmd(self, inputFile, outputFile):
def _getSurfCmd(self, inputFile, outputFile, Nthreads):
outputCmd = '-m %s ' % self.mbStrengthTh.get()
outputCmd += '%s ' % inputFile
outputCmd += '%s ' % outputFile
outputCmd += ' -t %i' % Nthreads
return outputCmd

def _getSalCmd(self, inputFile, outputFile):
def _getSalCmd(self, inputFile, outputFile, Nthreads):
outputCmd = '-S '
outputCmd += '-s %s ' % self.sigmaS.get()
outputCmd += '-p %s ' % self.sigmaP.get()
outputCmd += '%s ' % inputFile
outputCmd += '%s ' % outputFile
outputCmd += ' -t %i' % Nthreads
return outputCmd

8 changes: 4 additions & 4 deletions tomosegmemtv/tests/test_resize_tomomask.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _importTomograms(self):
samplingRate=self.samplingRate
)
protImportTomo = self.launchProtocol(protImportTomo)
tomoSet = getattr(protImportTomo, 'outputTomograms', None)
tomoSet = protImportTomo.Tomograms

# Validate output tomograms
self.assertSetSize(tomoSet, size=self.setSize)
Expand All @@ -76,7 +76,7 @@ def _importTomograms(self):
def _normalizeTomo(self, protImportTomo):
print(magentaStr("\n==> Normalizing the tomograms to binning %i" % self.binning))
protNormalizeTomo = self.newProtocol(ProtImodTomoNormalization,
inputSetOfTomograms=getattr(protImportTomo, 'outputTomograms', None),
inputSetOfTomograms=protImportTomo.Tomograms,
binning=self.binning)

protNormalizeTomo = self.launchProtocol(protNormalizeTomo)
Expand Down Expand Up @@ -109,12 +109,12 @@ def _segmentMembranes(self, protNormalizeTomo):

return protTomosegmemTV

def _resizeTomoMask(self, protTomosegmemTV, protImportTomo):
def _resizeTomoMask(self, protTomosegmemTV, protImportTomo:ProtImportTomograms):
print(magentaStr("\n==> Resizing the tomomasks to the size of the imported tomograms"))
protResizeTomoMask = self.newProtocol(
ProtResizeSegmentedVolume,
inTomoMasks=getattr(protTomosegmemTV, outputObjects.tomoMasks.name, None),
inTomos=getattr(protImportTomo, 'outputTomograms', None)
inTomos=protImportTomo.Tomograms
)
protResizeTomoMask = self.launchProtocol(protResizeTomoMask)
tomoMaskSet = getattr(protResizeTomoMask, outputObjects.tomoMasks.name, None)
Expand Down
6 changes: 3 additions & 3 deletions tomosegmemtv/tests/test_tomosegmemtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _importTomograms(self):
samplingRate=self.samplingRate
)
protImportTomo = self.launchProtocol(protImportTomo)
tomoSet = getattr(protImportTomo, 'outputTomograms', None)
tomoSet = protImportTomo.Tomograms

# Validate output tomograms
self.assertSetSize(tomoSet, size=2)
Expand All @@ -68,11 +68,11 @@ def _importTomograms(self):

return protImportTomo

def _runTomosegmemTV(self, protImportTomo):
def _runTomosegmemTV(self, protImportTomo:ProtImportTomograms):
print(magentaStr("\n==> Segmenting the membranes:"))
protTomosegmemTV = self.newProtocol(
ProtTomoSegmenTV,
inTomograms=getattr(protImportTomo, 'outputTomograms', None),
inTomograms=protImportTomo.Tomograms,
mbThkPix=2,
mbScaleFactor=10,
blackOverWhite=False
Expand Down

0 comments on commit 926509d

Please sign in to comment.