示例#1
0
    def extractStep(self):
        listIds = {}
        smallMolID = "none"
        for item in self.inputListID.get():
            if hasattr(item, "_iteractsWithPDBId"):
                tokens = item._iteractsWithPDBId.get().split(";")
                for token in tokens:
                    pdbId = token.strip()
                    if not pdbId in listIds:
                        listIds[pdbId] = []
                    chemId = item.getDbId()
                    if hasattr(item, "_PDBChemId"):
                        chemId = item._PDBChemId.get()
                        smallMolID = "pdbchem"
                    listIds[pdbId].append(chemId)

        outputDatabaseID = SetOfDatabaseID().create(path=self._getPath(),
                                                    suffix='PDBs')
        for pdbId in listIds:
            pdb = DatabaseID()
            pdb.setDatabase("pdb")
            pdb.setDbId(pdbId)
            pdb._pdbId = pwobj.String(pdbId)
            pdb._PDBLink = pwobj.String("https://www.rcsb.org/structure/%s" %
                                        pdbId)
            aux = " ; ".join(listIds[pdbId])
            if smallMolID == "none":
                pdb._interactsWithChemId = pwobj.String(aux)
            elif smallMolID == "pdbchem":
                pdb._interactsWithPDBChemId = pwobj.String(aux)
            outputDatabaseID.append(pdb)
        self._defineOutputs(outputPDBs=outputDatabaseID)
        self._defineSourceRelation(self.inputListID, outputDatabaseID)
    def importStep(self):
        if not self.multiple.get():
            copyFile(self.filePath.get(),self._getPath(os.path.split(self.filePath.get())[1]))
            fh = open(self.filePath.get())
            for line in fh.readlines():
                tokens = line.split(',')
                if len(tokens)==2:
                    fhSmile = open(self._getExtraPath(tokens[0].strip()+".smi"),'w')
                    fhSmile.write(tokens[1].strip()+"\n")
                    fhSmile.close()
        else:
            for filename in glob.glob(os.path.join(self.filesPath.get(), self.filesPattern.get())):
                fnSmall = self._getExtraPath(os.path.split(filename)[1])
                copyFile(filename, fnSmall)

        outputSmallMolecules = SetOfSmallMolecules().create(path=self._getPath(),suffix='SmallMols')
        for fnSmall in glob.glob(self._getExtraPath("*")):
            smallMolecule = SmallMolecule(smallMolFilename=fnSmall)

            if not fnSmall.endswith('.mae') and not fnSmall.endswith('.maegz'):
                fnRoot = os.path.splitext(os.path.split(fnSmall)[1])[0]
                fnOut = self._getExtraPath("%s.png" % fnRoot)
                args = Plugin.getPluginHome('utils/rdkitUtils.py') + " draw %s %s" % (fnSmall, fnOut)
                try:
                    Plugin.runRDKit(self, "python3", args)
                    smallMolecule._PDBLigandImage = pwobj.String(fnOut)
                except:
                    smallMolecule._PDBLigandImage = pwobj.String("Not available")

            outputSmallMolecules.append(smallMolecule)
        self._defineOutputs(outputSmallMols=outputSmallMolecules)
示例#3
0
文件: config.py 项目: liz18/scipion
 def __init__(self, confs={}, **kwargs):
     pwobj.OrderedObject.__init__(self, **kwargs)
     self.config = ProjectConfig()
     # Store the current view selected by the user
     self.currentProtocolsView = pwobj.String()
     # Store the color mode: 0= Status, 1=Labels, ...
     self.colorMode = pwobj.Integer(ProjectSettings.COLOR_MODE_STATUS)
     self.nodeList = NodeConfigList(
     )  # Store graph nodes positions and other info
     self.labelsList = LabelsList()  # Label list
     self.mapper = None  # This should be set when load, or write
     self.runsView = pwobj.Integer(1)  # by default the graph view
     self.readOnly = pwobj.Boolean(False)
     self.runSelection = pwobj.CsvList(int)  # Store selected runs
     self.dataSelection = pwobj.CsvList(int)  # Store selected runs
     # Some extra settings stored, now mainly used
     # from the webtools
     # Time when the project was created
     self.creationTime = pwobj.String(dt.datetime.now())
     # Number of days that this project is active
     # if None, the project will not expire
     # This is used in webtools where a limited time
     # is allowed for each project
     self.lifeTime = pwobj.Integer()
     # Set a disk quota for the project (in Gb)
     # if None, quota is unlimited
     self.diskQuota = pwobj.Integer()
    def __init__(self, **kwargs):
        Volume.__init__(self, **kwargs)
        self._acquisition = None
        self._tsId = pwobj.String(kwargs.get('tsId', None))

        self._tomoPointer = pwobj.Pointer(objDoStore=False)
        self._tomoId = pwobj.Integer()
        self._tomoName = pwobj.String()
    def createOutput(self):
        smallDict = {}
        for small in self.inputLibrary.get():
            fnSmall = small.getFileName()
            fnBase = os.path.splitext(os.path.split(fnSmall)[1])[0]
            if not fnBase in smallDict:
                smallDict[fnBase]=fnSmall

        grid = self.inputGrid.get()
        fnStruct = grid.structureFile.get()
        if hasattr(grid,"bindingSiteScore"):
            bindingSiteScore = grid.bindingSiteScore.get()
        else:
            bindingSiteScore = None
        if hasattr(grid,"bindingSiteDScore"):
            bindingSiteDScore = grid.bindingSiteDScore.get()
        else:
            bindingSiteDScore = None
        smallList = []
        posesDir = self._getExtraPath('poses')
        makePath(posesDir)
        fhCsv = open(self._getPath('job_pv.csv'))
        fnPv = self._getPath('job_pv.maegz')
        i = 0
        for line in fhCsv.readlines():
            if i>1:
                tokens = line.split(',')
                small = SmallMolecule(smallMolFilename=smallDict[tokens[0]])
                small.dockingScore = pwobj.Float(tokens[1])
                small.ligandEfficiency = pwobj.Float(tokens[2])
                small.ligandEfficiencySA = pwobj.Float(tokens[3])
                small.ligandEfficiencyLn = pwobj.Float(tokens[4])
                small.poseFile = pwobj.String("%d@%s"%(i,fnPv))
                small.structFile = pwobj.String(fnStruct)
                if bindingSiteScore:
                    small.bindingSiteScore = pwobj.Float(bindingSiteScore)
                if bindingSiteDScore:
                    small.bindingSiteDScore = pwobj.Float(bindingSiteDScore)
                smallList.append(small)
            i+=1
        fhCsv.close()

        idxSorted=sortDockingResults(smallList)

        outputSet = SetOfSmallMolecules().create(path=self._getPath())
        for idx in idxSorted:
            small=smallList[idx]
            outputSet.append(small)

        self._defineOutputs(outputSmallMolecules=outputSet)
        self._defineSourceRelation(self.inputGrid, outputSet)
        self._defineSourceRelation(self.inputLibrary, outputSet)

        mae = SchrodingerPoses(filename=fnPv)
        self._defineOutputs(outputPoses=mae)
        self._defineSourceRelation(self.inputGrid, mae)
        self._defineSourceRelation(self.inputLibrary, mae)
示例#6
0
    def __init__(self, location=None, **kwargs):
        """
         Params:
        :param location: Could be a valid location: (index, filename)
        or  filename
        """
        EdBaseObject.__init__(self, **kwargs)
        # Image location is composed by an index and a filename
        self._index = pwobj.Integer(0)
        self._filename = pwobj.String()

        # Detector distance of this image
        self._distance = pwobj.Float()

        # Where oscillation starts and its range
        self._oscStart = pwobj.Float()
        self._oscRange = pwobj.Float()

        # Beam center (in pixels)
        self._beamCenterX = pwobj.Float()
        self._beamCenterY = pwobj.Float()

        # Exposure time (in seconds)
        self._exposureTime = pwobj.Float()

        # TwoTheta
        self._twoTheta = pwobj.Float()

        # Pixel size of the image (in millimeters)
        self._pixelSizeX = pwobj.Float()
        self._pixelSizeY = pwobj.Float()

        # Dimensions of images in this set (number of pixels)
        self._dimX = pwobj.Integer()
        self._dimY = pwobj.Integer()

        # Wavelength
        self._wavelength = pwobj.Float()

        # Detector type
        self._detector = Detector()

        # Experiment time
        self._collectionTime = pwobj.String()

        # Add parameter to state if the image should be ignored in processing
        self._ignore = pwobj.Boolean()

        # Add information about goniometer rotation axis relative to image
        self._rotX = pwobj.Float()
        self._rotY = pwobj.Float()
        self._rotZ = pwobj.Float()

        if location:
            self.setLocation(location)
示例#7
0
    def __init__(self,
                 filename=None,
                 poses=None,
                 ctfs=None,
                 dim=None,
                 samplingRate=None,
                 **kwargs):
        EMObject.__init__(self, **kwargs)

        self.filename = pwobj.String(filename)
        self.poses = pwobj.String(poses)
        self.ctfs = pwobj.String(ctfs)
        self.samplingRate = pwobj.Float(samplingRate)
        self.dim = pwobj.Integer(dim)
示例#8
0
 def __init__(self, text=None, value=None, icon=None, tag=None, **kwargs):
     """Constructor for the Menu config item.
     Arguments:
       text: text to be displayed
       value: internal value associated with the item.
       icon: display an icon with the item
       tag: put some tags to items
     **args: pass other options to base class.
     """
     self.text = pwobj.String(text)
     self.value = pwobj.String(value)
     self.icon = pwobj.String(icon)
     self.tag = pwobj.String(tag)
     self.childs = pwobj.List()
     self.openItem = pwobj.Boolean(kwargs.get('openItem', False))
示例#9
0
 def __init__(self, **kwargs):
     MockObject.__init__(self, **kwargs)
     self._micrographPointer = pwobj.Pointer(objDoStore=False)
     self._x = pwobj.Integer(kwargs.get('x', None))
     self._y = pwobj.Integer(kwargs.get('y', None))
     self._micId = pwobj.Integer()
     self._micName = pwobj.String()
示例#10
0
 def _storeCreationTime(self, creationTime):
     """ Store the creation time in the project db. """
     # Store creation time
     creation = pwobj.String(objName=PROJECT_CREATION_TIME)
     creation.set(creationTime)
     self.mapper.insert(creation)
     self.mapper.commit()
示例#11
0
    def create(self, runsView=1, readOnly=False, hostsConf=None,
               protocolsConf=None):
        """Prepare all required paths and files to create a new project.
        Params:
         hosts: a list of configuration hosts associated to this projects (class ExecutionHostConfig)
        """
        # Create project path if not exists
        pwutils.path.makePath(self.path)
        os.chdir(self.path)  # Before doing nothing go to project dir
        self._cleanData()
        print "Creating project at: ", os.path.abspath(self.dbPath)
        # Create db through the mapper
        self.mapper = self.createMapper(self.dbPath)
        creation = pwobj.String(objName='CreationTime')  # Store creation time
        creation.set(dt.datetime.now())
        self.mapper.insert(creation)
        self.mapper.commit()
        # Load settings from .conf files and write .sqlite
        self.settings = pwconfig.ProjectSettings()
        self.settings.setRunsView(runsView)
        self.settings.setReadOnly(readOnly)
        self.settings.write(self.settingsPath)
        # Create other paths inside project
        for p in self.pathList:
            pwutils.path.makePath(p)

        self._loadHosts(hostsConf)

        self._loadProtocols(protocolsConf)
    def searchStep(self):
        outputDatabaseID = SetOfDatabaseID().create(path=self._getPath())
        for item in self.inputListID.get():
            newItem = DatabaseID()
            newItem.copy(item)
            newItem._uniprotId = pwobj.String("Not available")
            newItem._uniprotLink = pwobj.String("Not available")

            pdbId = item._pdbId.get()
            print("Processing %s" % pdbId)

            urlId = "https://www.rcsb.org/pdb/rest/das/pdb_uniprot_mapping/alignment?query=%s" % pdbId
            if hasattr(item, "_chain"):
                urlId += "." + item._chain.get().upper()

            fnXml = self._getExtraPath("%s.xml" % pdbId)
            if not os.path.exists(fnXml):
                print("Fetching uniprot: %s" % urlId)
                for i in range(3):
                    try:
                        urllib.request.urlretrieve(urlId, fnXml)
                        break
                    except:  # The library raises an exception when the web is not found
                        pass
            if os.path.exists(fnXml):
                try:
                    tree = ET.parse(fnXml)
                    # print(ET.tostring(tree, pretty_print=True))

                    uniprotId = None
                    for child in tree.getroot().iter():
                        if child.tag.endswith("alignObject"):
                            if child.attrib['dbSource'] == "UniProt":
                                uniprotId = child.attrib['dbAccessionId']
                                break
                    if uniprotId:
                        newItem._uniprotId = pwobj.String(uniprotId)
                        newItem._uniprotLink = pwobj.String(
                            "https://www.uniprot.org/uniprot/%s" % uniprotId)
                except:
                    print("    Cannot parse the Uniprot XML: %s" % fnXml)

                outputDatabaseID.append(newItem)

        self._defineOutputs(outputUniprot=outputDatabaseID)
        self._defineSourceRelation(self.inputListID, outputDatabaseID)
    def searchStep(self):
        outputDatabaseID = SetOfDatabaseID().create(path=self._getPath())
        fnList = []
        for item in self.inputListID.get():
            newItem = DatabaseID()
            newItem.copy(item)
            newItem._uniprotFile = pwobj.String("Not available")
            newItem._unitprotSeqLength = pwobj.Integer(-1)

            uniprotId = item._uniprotId.get()
            print("Processing %s" % uniprotId)

            urlId = "https://www.uniprot.org/uniprot/%s.fasta" % uniprotId

            fnFasta = self._getExtraPath("%s.fasta" % uniprotId)
            if not os.path.exists(fnFasta):
                print("Fetching uniprot: %s" % urlId)
                for i in range(3):
                    try:
                        urllib.request.urlretrieve(urlId, fnFasta)
                        if not fnFasta in fnList:
                            fnList.append(fnFasta)
                        break
                    except:  # The library raises an exception when the web is not found
                        pass
            if os.path.exists(fnFasta):
                newItem._uniprotFile = pwobj.String(fnFasta)
                newItem._unitprotSeqLength = pwobj.Integer(
                    sequenceLength(fnFasta))

            outputDatabaseID.append(newItem)

        fnAll = self._getPath("sequences.fasta")
        with open(fnAll, 'w') as outfile:
            for fname in fnList:
                with open(fname) as infile:
                    for line in infile:
                        outfile.write(line)
                    outfile.write('\n\n')
        seqFile = ProteinSequenceFile()
        seqFile.setFileName(fnAll)

        self._defineOutputs(outputUniprot=outputDatabaseID)
        self._defineSourceRelation(self.inputListID, outputDatabaseID)
        self._defineOutputs(outputSequence=seqFile)
        self._defineSourceRelation(self.inputListID, seqFile)
示例#14
0
    def show(self, form, *params):
        attrsList = self.getInputAttributes(form)
        finalAttrsList = []
        for i in attrsList:
            finalAttrsList.append(pwobj.String(i))
        provider = ListTreeProviderString(finalAttrsList)

        dlg = dialog.ListDialog(form.root, "Filter set", provider,
                                "Select one of the attributes")
        form.setVar('rankingField', dlg.values[0].get())
    def test_String(self):
        value = 'thisisastring'
        s = pwobj.String(value)
        self.assertEqual(value, s.get())
        self.assertEqual(s.hasValue(), True)
        
        s2 = pwobj.String()
        # None value is considered empty
        self.assertTrue(s2.empty(), "s2 string should be empty if None")
        s2.set(' ')
        # Only spaces is also empty
        self.assertTrue(s2.empty(), "s2 string should be empty if only spaces")
        s2.set('something')
        # No empty after some value
        self.assertFalse(s2.empty(),
                         "s2 string should not be empty after value")

        now = dt.datetime.now()
        s.set(now)
        self.assertEqual(now, s.datetime())
 def _createOutputMovie(self, movie):
     """ Overwrite this function to store the Relion's specific
     Motion model coefficients.
     """
     m = ProtAlignMovies._createOutputMovie(self, movie)
     # Load local motion values only if the patches are more than one
     if self.patchX.get() * self.patchY.get() > 1:
         table = md.Table(fileName=self._getMovieExtraFn(movie, '.star'),
                          tableName='local_motion_model')
         coeffs = [row.rlnMotionModelCoeff for row in table]
         m._rlnMotionModelCoeff = pwobj.String(json.dumps(coeffs))
     return m
示例#17
0
 def __init__(self, **kwargs):
     pwobj.OrderedObject.__init__(self, **kwargs)
     
     self.fullName = pwobj.String(kwargs.get('fullName', None))
     self.organization = pwobj.String(kwargs.get('organization', None))
     self.email = pwobj.String(kwargs.get('email', None))
     self.subscription = pwobj.String(kwargs.get('subscription', None))
     self.country = pwobj.String(kwargs.get('country', None))
     self.version = pwobj.String(kwargs.get('version', None))
     self.platform = pwobj.String(kwargs.get('platform', None))
    def constructOutput(self, fnTxt):
        fnDir, fnResults = os.path.split(fnTxt)
        tokens = fnResults.split('-')
        if len(tokens) > 1:
            subset = tokens[1].split('.')[0]
        else:
            subset = ""

        outputSet = SetOfDatabaseID.create(path=self._getPath(), suffix=subset)
        for line in open(fnTxt, "r"):
            line = line.strip()
            if line == "":
                continue
            elif line.startswith("# Structural equivalences"):
                break
            elif line.startswith("#"):
                continue
            else:
                tokens = line.split()
                pdbId = DatabaseID()
                tokens2 = tokens[1].split('-')
                pdbId.setDatabase("pdb")
                pdbId.setDbId(tokens[1])
                pdbId._pdbId = pwobj.String(tokens2[0])
                if len(tokens2) > 1:
                    pdbId._chain = pwobj.String(tokens2[1])
                pdbId._PDBLink = pwobj.String(
                    "https://www.rcsb.org/structure/%s" % tokens2[0])
                pdbId._DaliZscore = pwobj.Float(float(tokens[2]))
                pdbId._DaliRMSD = pwobj.Float(float(tokens[3]))
                pdbId._DaliSuperpositionLength = pwobj.Integer(int(tokens[4]))
                pdbId._DaliSeqLength = pwobj.Integer(int(tokens[5]))
                pdbId._DaliSeqIdentity = pwobj.Float(float(tokens[6]))
                pdbId._DaliDescription = pwobj.String(" ".join(tokens[7:]))
                outputSet.append(pdbId)
        outputDict = {'outputDatabaseIds%s' % subset: outputSet}
        self.protocol._defineOutputs(**outputDict)
        self.protocol._defineSourceRelation(self.protocol.inputStructure,
                                            outputSet)
示例#19
0
 def __init__(self, location=None, **kwargs):
     """
      Params:
     :param location: Could be a valid location: (index, filename)
     or  filename
     """
     MockObject.__init__(self, **kwargs)
     # Image location is composed by an index and a filename
     self._index = pwobj.Integer(0)
     self._filename = pwobj.String()
     self._samplingRate = pwobj.Float()
     self._ctfModel = None
     self._acquisition = None
     if location:
         self.setLocation(location)
    def _loadInputCoords(self, micDict):
        """ Load coordinates from the input streaming.
        """
        # TODO: this takes for ever if you are NOT
        # doing streaming and have several thousands of mics
        # so I add a counter to keep the user entertained
        import sys
        a = datetime.now()
        counter = 1

        coordsFn = self.getCoords().getFileName()
        self.debug("Loading input db: %s" % coordsFn)
        coordSet = emobj.SetOfCoordinates(filename=coordsFn)
        # FIXME: Temporary to avoid loadAllPropertiesFail
        coordSet._xmippMd = pwobj.String()
        coordSet.loadAllProperties()

        micList = dict()  # To store a dictionary with mics with coordinates

        for micKey, mic in micDict.items():
            if counter % 50 == 0:
                b = datetime.now()
                print(b - a, 'reading coordinates for mic number',
                      "%06d" % counter)
                sys.stdout.flush()  # force buffer to print
            counter += 1

            micId = mic.getObjId()
            coordList = []

            self.debug("Loading coords for mic: %s (%s)" % (micId, micKey))
            for coord in coordSet.iterItems(where='_micId=%s' % micId):
                # TODO: Check performance penalty of using this clone
                coordList.append(coord.clone())
            self.debug("Coords found: %s" % len(coordList))

            if coordList:
                self.coordDict[micId] = coordList
                micList[micKey] = mic

        self.coordsClosed = coordSet.isStreamClosed()
        coordSet.close()
        self.debug("Coords are closed? %s" % self.coordsClosed)
        self.debug("Closed db.")

        return micList
示例#21
0
    def createOutput(self):
        def parseEvalLog(fnLog):
            fh = open(fnLog)
            state = 0
            for line in fh.readlines():
                if state == 0 and line.startswith("SiteScore"):
                    state = 1
                elif state == 1:
                    # SiteScore size   Dscore  volume  exposure enclosure contact  phobic   philic   balance  don/acc
                    tokens = [float(x) for x in line.split()]
                    return tokens
            return None

        fnBinding = self._getPath("job_out.maegz")
        fnStructure = self.inputStructure.get().getFileName()
        if os.path.exists(fnBinding):
            setOfBindings = SetOfBindingSites().create(path=self._getPath())
            for fn in glob.glob(self._getPath("job_site_*_eval.log")):
                score, size, dscore, volume, exposure, enclosure, contact, phobic, philic, balance, donacc = parseEvalLog(
                    fn)
                n = fn.split("job_site_")[1].replace("_eval.log", "")
                bindingSite = BindingSite(bindingSiteFilename="%s@%s" %
                                          (n, fnBinding))
                bindingSite.score = pwobj.Float(score)
                bindingSite.size = pwobj.Float(size)
                bindingSite.dscore = pwobj.Float(dscore)
                bindingSite.volume = pwobj.Float(volume)
                bindingSite.exposure = pwobj.Float(exposure)
                bindingSite.enclosure = pwobj.Float(enclosure)
                bindingSite.contact = pwobj.Float(contact)
                bindingSite.phobic = pwobj.Float(phobic)
                bindingSite.phobic = pwobj.Float(phobic)
                bindingSite.philic = pwobj.Float(philic)
                bindingSite.balance = pwobj.Float(balance)
                bindingSite.donacc = pwobj.Float(donacc)
                bindingSite.structureFile = pwobj.String(fnStructure)

                setOfBindings.append(bindingSite)

            self._defineOutputs(outputSetBindingSites=setOfBindings)
            self._defineSourceRelation(self.inputStructure, setOfBindings)

            mae = SchrodingerBindingSites(filename=fnBinding)
            self._defineOutputs(outputBindingSites=mae)
            self._defineSourceRelation(self.inputStructure, mae)
 def _createOutputMovie(self, movie):
     """ Overwrite this function to store the Relion's specific
     Motion model coefficients.
     """
     m = ProtAlignMovies._createOutputMovie(self, movie)
     # Load local motion values only if the patches are more than one
     if self.patchX.get() > 2 and self.patchY.get() > 2:
         try:
             table = md.Table(fileName=self._getMovieExtraFn(
                 movie, '.star'),
                              tableName='local_motion_model')
             coeffs = [row.rlnMotionModelCoeff for row in table]
         except:
             print("Failed to parse local motion from: %s" %
                   os.path.abspath(self._getMovieExtraFn(movie, '.star')))
             coeffs = []  # Failed to parse the local motion
         m._rlnMotionModelCoeff = pwobj.String(json.dumps(coeffs))
     return m
示例#23
0
    def show(self, form, *params):
        protocol = form.protocol
        try:
            listOfChains, listOfResidues = self.getModelsChainsStep(protocol)
        except Exception as e:
            print("ERROR: ", e)
            return

        self.editionListOfChains(listOfChains)
        finalChainList = []
        for i in self.chainList:
            finalChainList.append(pwobj.String(i))
        provider = ListTreeProviderString(finalChainList)
        dlg = dialog.ListDialog(
            form.root, "Model chains", provider,
            "Select one of the chains (model, chain, "
            "number of chain residues)")
        form.setVar('inputStructureChain', dlg.values[0].get())
示例#24
0
    def __init__(self, **kwargs):
        pwobj.Object.__init__(self, **kwargs)

        self.micId = pwobj.Integer(kwargs.get('micId', None))
        self.micName = pwobj.String(kwargs.get('micName', None))

        # list particle x coordinate
        def _floatList(key):
            fl = pwobj.CsvList(pType=float)
            fl.set(kwargs.get(key, []))
            return fl

        self.x = _floatList('xCoord')
        # list particle y coordinate
        self.y = _floatList('yCoord')
        # list particle defocus
        self.defocus = _floatList('defocus')
        # list particle defocus difference
        self.defocusDiff = _floatList('defocusDiff')

        self.stdev = pwobj.Float()  # defocus stdev
        self.n = pwobj.Integer()  # number particles in the micrograph
示例#25
0
 def __init__(self, train_data_dir=None, patch_size=None, **kwargs):
     EMObject.__init__(self, **kwargs)
     self._train_data_dir = pwobj.String(train_data_dir)
     self._patch_size = pwobj.Integer(patch_size)
示例#26
0
 def __init__(self, basedir=None, train_data_dir=None, **kwargs):
     EMObject.__init__(self, **kwargs)
     self._basedir = pwobj.String(basedir)
     self._train_data_dir = pwobj.String(train_data_dir)
示例#27
0
文件: config.py 项目: liz18/scipion
 def __init__(self, **args):
     pwobj.OrderedObject.__init__(self, **args)
     self.logo = pwobj.String('scipion_logo_small.png')
     # Do not store this object, unless we implement some kind of
     # icon customization
     self._objDoStore = False
示例#28
0
    def processMovieStep(self, movieDict, hasAlignment):
        movie = emobj.Movie()
        movie.setAcquisition(emobj.Acquisition())

        if hasAlignment:
            movie.setAlignment(emobj.MovieAlignment())

        movie.setAttributesFromDict(movieDict,
                                    setBasic=True,
                                    ignoreMissing=True)

        movieFolder = self._getOutputMovieFolder(movie)
        movieFn = movie.getFileName()
        movieName = basename(movieFn)
        movieDoneFn = self._getMovieDone(movie)

        if self.isContinued() and os.path.exists(movieDoneFn):
            self.info("Skipping movie: %s, seems to be done" % movieFn)
            return

        # Clean old finished files
        pwutils.cleanPath(movieDoneFn)

        if self._filterMovie(movie):
            pwutils.makePath(movieFolder)
            pwutils.createLink(movieFn, join(movieFolder, movieName))

            if movieName.endswith('bz2'):
                newMovieName = movieName.replace('.bz2', '')
                # We assume that if compressed the name ends with .mrc.bz2
                if not exists(newMovieName):
                    self.runJob('bzip2',
                                '-d -f %s' % movieName,
                                cwd=movieFolder)

            elif movieName.endswith('tbz'):
                newMovieName = movieName.replace('.tbz', '.mrc')
                # We assume that if compressed the name ends with .tbz
                if not exists(newMovieName):
                    self.runJob('tar', 'jxf %s' % movieName, cwd=movieFolder)

            elif movieName.endswith('.txt'):
                # Support a list of frame as a simple .txt file containing
                # all the frames in a raw list, we could use a xmd as well,
                # but a plain text was choose to simply its generation
                movieTxt = os.path.join(movieFolder, movieName)
                with open(movieTxt) as f:
                    movieOrigin = os.path.basename(os.readlink(movieFn))
                    newMovieName = movieName.replace('.txt', '.mrcs')
                    ih = emlib.image.ImageHandler()
                    for i, line in enumerate(f):
                        if line.strip():
                            inputFrame = os.path.join(movieOrigin,
                                                      line.strip())
                            ih.convert(
                                inputFrame,
                                (i + 1, os.path.join(movieFolder,
                                                     newMovieName)))
            else:
                newMovieName = movieName

            convertExt = self._getConvertExtension(newMovieName)
            correctGain = self._doCorrectGain()

            if convertExt or correctGain:
                inputMovieFn = os.path.join(movieFolder, newMovieName)
                if inputMovieFn.endswith('.em'):
                    inputMovieFn += ":ems"

                if convertExt:
                    newMovieName = pwutils.replaceExt(newMovieName, convertExt)
                else:
                    newMovieName = '%s_corrected.%s' % os.path.splitext(
                        newMovieName)

                outputMovieFn = os.path.join(movieFolder, newMovieName)

                # If the protocols wants Scipion to apply the gain, then
                # there is no reason to convert, since we can produce the
                # output in the format expected by the program. In some cases,
                # the alignment programs can directly deal with gain and dark
                # correction images, so we don't need to apply it
                if self._doCorrectGain():
                    self.info("Correcting gain and dark '%s' -> '%s'" %
                              (inputMovieFn, outputMovieFn))
                    gain, dark = self.getGainAndDark()
                    self.correctGain(inputMovieFn,
                                     outputMovieFn,
                                     gainFn=gain,
                                     darkFn=dark)
                else:
                    self.info("Converting movie '%s' -> '%s'" %
                              (inputMovieFn, outputMovieFn))

                    emlib.image.ImageHandler().convertStack(
                        inputMovieFn, outputMovieFn)

            # Just store the original name in case it is needed in _processMovie
            movie._originalFileName = pwobj.String(objDoStore=False)
            movie._originalFileName.set(movie.getFileName())
            # Now set the new filename (either linked or converted)
            movie.setFileName(os.path.join(movieFolder, newMovieName))
            self.info("Processing movie: %s" % movie.getFileName())

            self._processMovie(movie)

            if self._doMovieFolderCleanUp():
                self._cleanMovieFolder(movieFolder)

        # Mark this movie as finished
        open(movieDoneFn, 'w').close()
    def operateStep(self):
        outputSet = self.inputSet.get().create(self._getPath())
        for oldEntry in self.inputSet.get():
            fnSmall = oldEntry.smallMoleculeFile.get()
            fnBase = os.path.splitext(os.path.split(fnSmall)[1])[0]
            fnName = self._getExtraPath(fnBase+".txt")
            cid = None
            if not os.path.exists(fnName):
                if fnSmall.endswith('.smi'):
                    fhSmile = open(fnSmall)
                    smile = fhSmile.readlines()[0].split()[0].strip() # Only first line
                    fhSmile.close()
                    url = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/%s/cids/TXT"%smile
                    print(url)

                pubChemName = ""
                try:
                    with contextlib.closing(urllib.request.urlopen(url)) as fp:
                        mybytes = fp.read()
                        cid = mybytes.decode("utf8").split()[0]
                        fp.close()

                    if cid!="0":
                        url = "https://pubchem.ncbi.nlm.nih.gov/rest/pug_view/data/compound/%s/XML/?response_type=save&response_basename=compound_CID_%s"%(cid,cid)
                        print(url)
                        fnXml = self._getTmpPath("compound.xml")
                        urllib.request.urlretrieve(url, fnXml)
                        if os.path.exists(fnXml):
                            tree = ET.parse(fnXml)

                        pubChemName = ""
                        for child in tree.getroot().iter():
                            if "RecordTitle" in child.tag:
                                pubChemName = child.text
                                print(pubChemName)
                                fh = open(fnName,'w')
                                fh.write(pubChemName+" ;; %s"%cid)
                                fh.close()
                                break
                except Exception as e:
                    print(e)
                    print("  Could not be retrieved")
            else:
                fh = open(fnName)
                tokens = fh.readline().split(';;')
                pubChemName = tokens[0].strip()
                cid = tokens[1].strip()
                fh.close()

            newEntry = self.inputSet.get().ITEM_TYPE()
            newEntry.copy(oldEntry)
            newEntry.pubChemName = pwobj.String(pubChemName)
            if cid is not None and cid!="0":
                url = "https://pubchem.ncbi.nlm.nih.gov/compound/%s"%cid
            else:
                url = ""
            newEntry.pubChemURL = pwobj.String(url)
            outputSet.append(newEntry)

        if len(outputSet)>0:
            self._defineOutputs(output=outputSet)
            self._defineSourceRelation(self.inputSet, outputSet)
示例#30
0
 def __init__(self, **args):
     pwprot.Protocol.__init__(self, **args)
     self.name = pwobj.String(args.get('name', None))