Source code for pyseg.protocols.protocol_import_starfile

# **************************************************************************
# *
# * Authors:     Estrella Fernandez Gimenez (me.fernandez@cnb.csic.es)
# *
# *  BCU, 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 pwem import UNIT_ANGSTROM_SYMBOL, dirname
from pyworkflow import BETA
from pyworkflow.protocol.params import PathParam, FloatParam, String
from pyworkflow.utils.path import copyFile, createAbsLink
from pwem.protocols import EMProtocol, basename
from tomo.protocols import ProtTomoBase
from ..convert import readStarFile, RELION_TOMO_LABELS, RELION_SUBTOMO_STAR


[docs]class ProtPySegImportSubtomos(EMProtocol, ProtTomoBase): """ This protocol imports subtomograms from a STAR file generated by PySeg""" _label = 'import star file PySeg' _devStatus = BETA warningMsg = None # -------------------------- DEFINE param functions ---------------------- def _defineParams(self, form): form.addSection(label='Input') form.addParam('starFile', PathParam, label="Star file:", help='Select star file generated by Relion/PySeg for linking metadata to the subtomograms that ' 'will be imported to Scipion.') form.addParam('samplingRate', FloatParam, label="Sampling rate: ") # --------------------------- STEPS functions ------------------------------ def _insertAllSteps(self): self._insertFunctionStep('importSubtomogramsStep') self._insertFunctionStep('createOutputStep') # --------------------------- STEPS functions -----------------------------
[docs] def importSubtomogramsStep(self): starFile = self.starFile.get() copyFile(starFile, self._getExtraPath('pyseg.star')) self.subtomoSet = self._createSetOfSubTomograms() self.subtomoSet.setSamplingRate(self.samplingRate.get()) warningMsg = readStarFile(self, self.subtomoSet, RELION_SUBTOMO_STAR) if warningMsg: self.warningMsg = String(warningMsg) self._store()
[docs] def createOutputStep(self): self._defineOutputs(outputSubTomograms=self.subtomoSet)
# --------------------------- INFO functions ----------------------------------- def _summary(self): summary = [] if hasattr(self, 'outputSubTomograms'): summary.append("Subtomograms imported from: *%s*\nSampling rate: *%0.2f %s/pix*" % (self.starFile.get(), self.samplingRate.get(), UNIT_ANGSTROM_SYMBOL)) else: summary.append("Output subtomograms not ready yet.") if self.warningMsg: summary.append(self.warningMsg.get()) return summary def _methods(self): methods = [] if not hasattr(self, 'outputSubTomograms'): methods.append("Output subtomograms not ready yet.") else: methods.append("*%s* subtomograms imported from file *%s* with a sampling rate *%0.2f %s/pix*" % (self.outputSubTomograms.getSize(), self.starFile.get(), self.samplingRate.get(), UNIT_ANGSTROM_SYMBOL)) return methods