예제 #1
0
    def createOutputStep(self):
        micSet = self.getInputMicrographs()
        ih = em.ImageHandler()
        coordSet = self._createSetOfCoordinates(micSet)
        if self.boxSize == 0:
            coordSet.setBoxSize(self.inputReferences.get().getDim()[0])
        else:
            coordSet.setBoxSize(self.boxSize.get())

        for mic in micSet:
            fnCoords = pwutils.replaceBaseExt(mic.getFileName(), 'txt')
            fn2parse = self._getExtraPath('pik_coord', fnCoords)
            print fn2parse
            xdim, _, _, _ = ih.getDimensions(mic)
            #xdim, ydim, _ = em.getDimensions(micSet)
            #print xdim, ydim
            with open(fn2parse, "r") as source:
                source.readline()  # Skip first line
                for line in source:
                    tokens = line.split()
                    coord = em.Coordinate()
                    coord.setPosition(xdim - int(tokens[3]), int(tokens[2]))
                    coord.setMicrograph(mic)
                    coordSet.append(coord)

        self._defineOutputs(outputCoordinates=coordSet)
        self._defineSourceRelation(micSet, coordSet)
예제 #2
0
def readCoordinates(mic, fileName, coordsSet):
    if os.path.exists(fileName):
        mdCoords = md.MetaData()
        mdCoords.readPlain(fileName, "xcoor ycoor xSize ySize")
        for row in md.iterRows(mdCoords):
            coord = em.Coordinate(
                x=row.getValue("xcoor") + row.getValue("xSize") / 2,
                y=row.getValue("ycoor") + row.getValue("ySize") / 2)
            coord.setMicrograph(mic)
            coordsSet.append(coord)
예제 #3
0
def rowToCoordinate(coordRow):
    """ Create a Coordinate from a row of a meta """
    # Check that all required labels are present in the row
    if coordRow.containsAll(COOR_DICT):
        coord = em.Coordinate()
        rowToObject(coordRow, coord, COOR_DICT)

        #FIXME: THE FOLLOWING IS NOT CLEAN
        try:
            coord.setMicId(int(coordRow.getValue(md.RLN_MICROGRAPH_NAME)))
        except Exception:
            pass
    else:
        coord = None

    return coord
예제 #4
0
def rowToCoordinate(coordRow):
    """ Create a Coordinate from a row of a meta """
    # Check that all required labels are present in the row
    if coordRow.containsAll(COOR_DICT):
        coord = em.Coordinate()
        rowToObject(coordRow, coord, COOR_DICT, extraLabels=COOR_EXTRA_LABELS)
        # Gautomatch starts _rlnClassNumber at 0, but relion at 1
        # so let's increment its value
        if coord.hasAttribute('_rlnClassNumber'):
            coord._rlnClassNumber.increment()

        # FIXME: THE FOLLOWING IS NOT CLEAN
        try:
            coord.setMicId(int(coordRow.getValue(md.RLN_MICROGRAPH_NAME)))
        except Exception:
            pass
    else:
        coord = None

    return coord
예제 #5
0
def rowToCoordinate(coordRow):
    """ Create a Coordinate from a row of a meta """
    # Check that all required labels are present in the row
    if coordRow.containsAll(COOR_DICT):
        coord = em.Coordinate()
        rowToObject(coordRow, coord, COOR_DICT, extraLabels=COOR_EXTRA_LABELS)

        micName = None

        if coordRow.hasLabel(md.RLN_MICROGRAPH_ID):
            micId = int(coordRow.getValue(md.RLN_MICROGRAPH_ID))
            coord.setMicId(micId)
            # If RLN_MICROGRAPH_NAME is not present, use the id as a name
            micName = micId

        if coordRow.hasLabel(md.RLN_MICROGRAPH_NAME):
            micName = coordRow.getValue(md.RLN_MICROGRAPH_NAME)

        coord.setMicName(micName)

    else:
        coord = None
        
    return coord