Example #1
0
    def _createClasses(self, partSet):
        self._classesDict = {} # store classes info, indexed by class id
        pathDict = {}

        self.protocol.info('Loading classes info from: %s' % self._modelStarFile)
        modelMd = md.MetaData('model_classes@' + self._modelStarFile)
        for classNumber, objId in enumerate(modelMd):
            row = md.Row()
            row.readFromMd(modelMd, objId)
            index, fn = relionToLocation(row.getValue('rlnReferenceImage'))

            if fn in pathDict:
                newFn = pathDict.get(fn)
            else:
                clsPath = findRootFrom(self._modelStarFile, fn)
                if clsPath is None:
                    newFn = fn
                else:
                    newFn = self.protocol._getExtraPath(os.path.basename(fn))
                    self.copyOrLink(os.path.join(clsPath, fn), newFn)
                pathDict[fn] = newFn

            self._classesDict[classNumber+1] = (index, newFn, row)

        clsSet = self._classesFunc(partSet)
        clsSet.classifyItems(updateClassCallback=self._updateClass)

        self.protocol._defineOutputs(outputClasses=clsSet)
        self.protocol._defineSourceRelation(partSet, clsSet)
Example #2
0
    def _createClasses(self, partSet):
        self._classesDict = {}  # store classes info, indexed by class id
        pathDict = {}

        self.protocol.info('Loading classes info from: %s' %
                           self._modelStarFile)
        modelMd = md.MetaData('model_classes@' + self._modelStarFile)
        for classNumber, objId in enumerate(modelMd):
            row = md.Row()
            row.readFromMd(modelMd, objId)
            index, fn = relionToLocation(row.getValue('rlnReferenceImage'))

            if fn in pathDict:
                newFn = pathDict.get(fn)
            else:
                clsPath = findRootFrom(self._modelStarFile, fn)
                if clsPath is None:
                    newFn = fn
                else:
                    newFn = self.protocol._getExtraPath(os.path.basename(fn))
                    self.copyOrLink(os.path.join(clsPath, fn), newFn)
                pathDict[fn] = newFn

            self._classesDict[classNumber + 1] = (index, newFn, row)

        clsSet = self._classesFunc(partSet)
        clsSet.classifyItems(updateClassCallback=self._updateClass)

        self.protocol._defineOutputs(outputClasses=clsSet)
        self.protocol._defineSourceRelation(partSet, clsSet)
Example #3
0
    def _findPathAndCtf(self, label, warnings=True):
        """ Find the relative path from which the micrographs exists
        repect to the metadata location. Also check if it contains
        CTF information and their relative root.
        """
        row = md.getFirstRow(self._mdFile)

        if row is None:
            raise Exception("Can not import from an empty metadata: "
                            "%s" % self._mdFile)

        if not row.containsLabel(label):
            raise Exception("Label *%s* is missing in metadata: "
                            "%s" % (md.label2Str(label), self._mdFile))

        # take only the filename part after the @
        index, fn = xmippToLocation(row.getValue(label))
        self._imgPath = findRootFrom(self._mdFile, fn)

        if warnings and self._imgPath is None:
            self.protocol.warning("Binary data was not found from metadata: "
                                  "%s" % self._mdFile)

        if row.containsLabel(md.MDL_CTF_MODEL):
            self._ctfPath = findRootFrom(self._mdFile,
                                         row.getValue(md.MDL_CTF_MODEL))
        else:
            self._ctfPath = None  # means no CTF info from micrographs metadata

        if row.containsLabel(md.MDL_REF):
            self._classFunc = self.protocol._createSetOfClasses2D
        elif row.containsLabel(md.MDL_REF3D):
            self._classFunc = self.protocol._createSetOfClasses3D
        else:
            self._classLabel = None
            self._classFunc = None

        # Check if the MetaData contains either MDL_MICROGRAPH_ID
        # or MDL_MICROGRAPH, this will be used when imported
        # particles to keep track of the particle's micrograph
        self._micIdOrName = (row.containsLabel(md.MDL_MICROGRAPH_ID)
                             or row.containsLabel(md.MDL_MICROGRAPH))
        #init dictionary. It will be used in the preprocessing
        self.micDict = {}

        return row
Example #4
0
    def _findPathAndCtf(self, label, warnings=True):
        """ Find the relative path from which the micrographs exists
        repect to the metadata location. Also check if it contains
        CTF information and their relative root.
        """
        row = md.getFirstRow(self._mdFile)

        if row is None:
            raise Exception("Can not import from an empty metadata: "
                            "%s" % self._mdFile)

        if not row.containsLabel(label):
            raise Exception("Label *%s* is missing in metadata: "
                            "%s" % (md.label2Str(label), self._mdFile))

        # take only the filename part after the @
        index, fn = xmippToLocation(row.getValue(label))
        self._imgPath = findRootFrom(self._mdFile, fn)

        if warnings and self._imgPath is None:
            self.protocol.warning("Binary data was not found from metadata: "
                                  "%s" % self._mdFile)

        if row.containsLabel(md.MDL_CTF_MODEL):
            self._ctfPath = findRootFrom(self._mdFile,
                                         row.getValue(md.MDL_CTF_MODEL))
        else:
            self._ctfPath = None # means no CTF info from micrographs metadata

        if row.containsLabel(md.MDL_REF):
            self._classFunc = self.protocol._createSetOfClasses2D
        elif row.containsLabel(md.MDL_REF3D):
            self._classFunc = self.protocol._createSetOfClasses3D
        else:
            self._classLabel = None
            self._classFunc = None

        # Check if the MetaData contains either MDL_MICROGRAPH_ID
        # or MDL_MICROGRAPH, this will be used when imported
        # particles to keep track of the particle's micrograph
        self._micIdOrName = (row.containsLabel(md.MDL_MICROGRAPH_ID) or
                             row.containsLabel(md.MDL_MICROGRAPH))
        #init dictionary. It will be used in the preprocessing
        self.micDict = {}

        return row
Example #5
0
    def _findImagesPath(self, label, warnings=True):

        row = md.getFirstRow(self._starFile)

        if row is None:
            raise Exception("Can not import from an empty metadata: %s" %
                            self._starFile)

        if not row.containsLabel(label):
            raise Exception("Label *%s* is missing in metadata: %s" %
                            (md.label2Str(label), self._starFile))

        index, fn = relionToLocation(row.getValue(label))
        self._imgPath = findRootFrom(self._starFile, fn)

        if warnings and self._imgPath is None:
            self.protocol.warning(
                "Binary data was not found from metadata: %s" % self._starFile)

        if (self._starFile.endswith('_data.star')
                and self._getModelFile(self._starFile)):
            self._modelStarFile = self._getModelFile(self._starFile)
            modelRow = md.getFirstRow(self._modelStarFile)
            classDimensionality = modelRow.getValue(
                'rlnReferenceDimensionality')

            self._optimiserFile = self._starFile.replace(
                '_data.star', '_optimiser.star')
            if not exists(self._optimiserFile):
                raise Exception("Missing required optimiser star file: %s" %
                                self._optimiserFile)
            optimiserRow = md.getFirstRow(self._optimiserFile)
            autoRefine = optimiserRow.containsLabel('rlnModelStarFile2')

            self.alignType = ALIGN_PROJ

            if not autoRefine:
                if classDimensionality == 3:
                    self._classesFunc = self.protocol._createSetOfClasses3D
                else:
                    self._classesFunc = self.protocol._createSetOfClasses2D
                    self.alignType = ALIGN_2D
            else:
                self._classesFunc = None
        else:
            self.alignType = ALIGN_NONE
            self._classesFunc = None
            self._modelStarFile = None
            modelRow = None
        # Check if the MetaData contains either MDL_MICROGRAPH_ID
        # or MDL_MICROGRAPH, this will be used when imported
        # particles to keep track of the particle's micrograph
        self._micIdOrName = (row.containsLabel('rlnMicrographName')
                             or row.containsLabel('rlnMicrographId'))
        #init dictionary. It will be used in the preprocessing
        self.micDict = {}

        return row, modelRow
Example #6
0
 def _findImagesPath(self, inputSet):
     """ Find the relative path from which the images exists
     repect to the sqlite location. 
     """
     self._imgDict = {} # store which images stack have been linked/copied and the new path
     img = inputSet.getFirstItem()
     self._imgPath = findRootFrom(self._sqliteFile, img.getFileName())
     
     if self._imgPath is None:
         self.protocol.warning("Binary data was not found from sqlite: %s" % self._sqliteFile)
Example #7
0
    def _findImagesPath(self, label, warnings=True):

        row = md.getFirstRow(self._starFile)

        if row is None:
            raise Exception("Can not import from an empty metadata: %s" % self._starFile)

        if not row.containsLabel(label):
            raise Exception("Label *%s* is missing in metadata: %s" % (md.label2Str(label),
                                                                       self._starFile))

        index, fn = relionToLocation(row.getValue(label))
        self._imgPath = findRootFrom(self._starFile, fn)

        if warnings and self._imgPath is None:
            self.protocol.warning("Binary data was not found from metadata: %s" % self._starFile)


        if (self._starFile.endswith('_data.star') and 
            self._getModelFile(self._starFile)):
            self._modelStarFile = self._getModelFile(self._starFile)
            modelRow = md.getFirstRow(self._modelStarFile)
            classDimensionality = modelRow.getValue('rlnReferenceDimensionality')

            self._optimiserFile = self._starFile.replace('_data.star', '_optimiser.star')
            if not exists(self._optimiserFile):
                raise Exception("Missing required optimiser star file: %s" % self._optimiserFile)
            optimiserRow = md.getFirstRow(self._optimiserFile)
            autoRefine = optimiserRow.containsLabel('rlnModelStarFile2')

            self.alignType = ALIGN_PROJ

            if not autoRefine:
                if classDimensionality == 3:
                    self._classesFunc = self.protocol._createSetOfClasses3D
                else:
                    self._classesFunc = self.protocol._createSetOfClasses2D
                    self.alignType = ALIGN_2D
            else:
                self._classesFunc = None
        else:
            self.alignType = ALIGN_NONE
            self._classesFunc = None
            self._modelStarFile = None
            modelRow = None
        # Check if the MetaData contains either MDL_MICROGRAPH_ID
        # or MDL_MICROGRAPH, this will be used when imported
        # particles to keep track of the particle's micrograph
        self._micIdOrName = (row.containsLabel('rlnMicrographName') or
                             row.containsLabel('rlnMicrographId'))
        #init dictionary. It will be used in the preprocessing
        self.micDict = {}

        return row, modelRow
Example #8
0
    def _findImagesPath(self, inputSet):
        """ Find the relative path from which the images exists
        repect to the sqlite location. 
        """
        self._imgDict = {
        }  # store which images stack have been linked/copied and the new path
        img = inputSet.getFirstItem()
        self._imgPath = findRootFrom(self._sqliteFile, img.getFileName())

        if self._imgPath is None:
            self.protocol.warning("Binary data was not found from sqlite: %s" %
                                  self._sqliteFile)
Example #9
0
    def _findPathAndCtf(self, warnings=True):
        """ Find the relative path from which the micrographs exists
        repect to the metadata location. Also check if it contains
        CTF information and their relative root.
        """
        inputSet = SetOfParticles(filename=self._sqliteFile)
        inputSet.loadProperty('_alignment', ALIGN_NONE)
        inputSet.loadProperty('_hasCtf', False)
        
        particle = inputSet.getFirstItem()
        self._imgPath = findRootFrom(self._sqliteFile, particle.getFileName())
        
        if warnings and self._imgPath is None:
            self.protocol.warning("Binary data was not found from metadata: %s" % self._sqliteFile)

        return inputSet