Skip to content

Commit

Permalink
Merge pull request #1 from scipion-em/devel
Browse files Browse the repository at this point in the history
remove unused code, add summary
  • Loading branch information
azazellochg authored May 25, 2020
2 parents 85cee37 + a4f4c49 commit 9deba42
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
1.0.2 - remove unused code
1.0.0 - First plugin version

10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ SIDESPLITTER plugin

This plugin provide wrappers around `SIDESPLITTER <https://github.com/StructuralBiology-ICLMedicine/SIDESPLITTER>`_ program for mitigating local overfitting.

+------------------+------------------+
| stable: |stable| | devel: | |devel| |
+------------------+------------------+
+--------------+----------------+
| prod: |prod| | devel: |devel| |
+--------------+----------------+

.. |stable| image:: http://scipion-test.cnb.csic.es:9980/badges/sidesplitter_prod.svg
.. |devel| image:: http://scipion-test.cnb.csic.es:9980/badges/sidesplitter_sdevel.svg
.. |prod| image:: http://scipion-test.cnb.csic.es:9980/badges/cistem_prod.svg
.. |devel| image:: http://scipion-test.cnb.csic.es:9980/badges/cistem_devel.svg


Installation
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.0.1', # Required
version='1.0.2', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down
16 changes: 2 additions & 14 deletions sidesplitter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,26 @@
# *
# **************************************************************************

import os

import pyworkflow.utils as pwutils
from pwem.emlib.image import ImageHandler


def getImageLocation(location):
return ImageHandler.locationToXmipp(location)


def convertMask(img, outputPath, newDim=None):
def convertMask(img, outFn, newDim=None):
""" Convert binary mask to a format read by Relion and truncate the
values between 0-1 values, due to Relion only support masks with this
values (0-1).
Params:
img: input image to be converted.
outputPath: it can be either a directory or a file path.
If it is a directory, the output name will be inferred from input
and put into that directory. If it is not a directory,
it is assumed is the output filename.
outFn: output file path.
Return:
new file name of the mask.
"""

ih = ImageHandler()
imgFn = getImageLocation(img.getLocation())

if os.path.isdir(outputPath):
outFn = os.path.join(outputPath, pwutils.replaceBaseExt(imgFn, 'mrc'))
else:
outFn = outputPath

ih.truncateMask(imgFn, outFn, newDim=newDim)

return outFn
41 changes: 19 additions & 22 deletions sidesplitter/protocols/protocol_sidesplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pwem.objects import Volume
from pwem.emlib.image import ImageHandler

import sidesplitter
from sidesplitter import Plugin
from ..convert import convertMask


Expand All @@ -47,15 +47,8 @@ class ProtSideSplitter(ProtAnalysis3D):
def _getInputPath(self, *paths):
return self._getPath('input', *paths)

def _initialize(self):
""" This function is meant to be called after the
working dir for the protocol have been set.
(maybe after recovery from mapper)
"""
self._createFilenameTemplates()

def _createFilenameTemplates(self):
""" Centralize how files are called for iterations and references. """
""" Centralize how files are called. """
myDict = {'half1': self._getInputPath("half1_unfil.mrc"),
'half2': self._getInputPath("half2_unfil.mrc"),
'mask': self._getInputPath("mask.mrc"),
Expand Down Expand Up @@ -93,15 +86,14 @@ def _defineParams(self, form):
# --------------------------- INSERT steps functions ----------------------

def _insertAllSteps(self):
objId = self.protRefine.get().getObjId()
self._initialize()
self._insertFunctionStep('convertInputStep', objId)
self._createFilenameTemplates()
self._insertFunctionStep('convertInputStep')
self._insertFunctionStep('runSideSplitterStep')
self._insertFunctionStep('createOutputStep')

# --------------------------- STEPS functions -----------------------------

def convertInputStep(self, protId):
def convertInputStep(self):
""" Convert input half-maps to mrc as expected by SIDESPLITTER."""
pwutils.makePath(self._getInputPath())

Expand All @@ -121,11 +113,11 @@ def runSideSplitterStep(self):
""" Call SIDESPLITTER with the appropriate parameters. """
args = self._getArgs()
param = ' '.join(['%s %s' % (k, str(v)) for k, v in args.items()])
program = sidesplitter.Plugin.getProgram()
program = Plugin.getProgram()
cmd = 'export OMP_NUM_THREADS=%d; ' % self.numberOfThreads.get()
cmd += program

self.runJob(cmd, param, env=sidesplitter.Plugin.getEnviron(),
self.runJob(cmd, param, env=Plugin.getEnviron(),
cwd=self._getExtraPath(),
numberOfThreads=1)

Expand Down Expand Up @@ -154,6 +146,11 @@ def createOutputStep(self):
def _summary(self):
summary = []

if hasattr(self, 'outputVolume1'):
summary.append("Created locally filtered half-maps.")
else:
summary.append("Output is not ready")

return summary

def _validate(self):
Expand All @@ -165,17 +162,17 @@ def _validate(self):

def _getArgs(self):
""" Prepare the args dictionary."""
args = {'--v1': self._getPaths(self._getFileName('half1')),
'--v2': self._getPaths(self._getFileName('half2'))}
args = {'--v1': self._getRelPath(self._getFileName('half1')),
'--v2': self._getRelPath(self._getFileName('half2'))}

if self.mask.hasValue():
args.update({'--mask': self._getPaths(self._getFileName('mask'))})
args['--mask'] = self._getRelPath(self._getFileName('mask'))

if self.doSNRWeighting:
args.update({'--spectrum': ' '})
args['--spectrum'] = ' '

return args

def _getPaths(self, fn):
""" Return relative path to the input dir from cwd=extra. """
return pwutils.join("../input", os.path.basename(fn))
def _getRelPath(self, fn):
""" Return relative path from cwd=extra. """
return os.path.relpath(fn, self._getExtraPath())
2 changes: 1 addition & 1 deletion sidesplitter/tests/test_protocol_sidesplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ProtRelionRefine3D",
doRaise=True)
except ImportError as e:
print("Relion plugin not found! You need to install to be able to run this test.")
print("Relion plugin not found! You need to install it to be able to run this test.")


class TestSideSplitter(BaseTest):
Expand Down

0 comments on commit 9deba42

Please sign in to comment.