コード例 #1
0
def populateProtTree(tree, obj):
    emProtocolsDict = em.getProtocols()

    for sub in obj:
        text = sub.text.get()
        value = sub.value.get(text)
        tag = sub.tag.get('')
        icon = sub.icon.get('')
        openItem = sub.openItem.get()
        item = TreeItem(text, tag, icon, openItem)
        tree.childs.append(item)
        # If have tag 'protocol_base', fill dynamically with protocol sub-classes
        protClassName = value.split('.')[-1]  # Take last part
        if sub.value.hasValue() and tag == 'protocol_base':
            prot = emProtocolsDict.get(protClassName, None)
            if prot is not None:
                for k, v in emProtocolsDict.iteritems():
                    if not v is prot and issubclass(v, prot):
                        protItem = TreeItem(k, 'protocol_class',
                                            'python_file.gif', None,
                                            protClassName, v)
                        item.childs.append(protItem)
        else:
            item.protClass = protClassName
            populateProtTree(item, sub)
コード例 #2
0
def loadProtocolProject(request, requestType=POST):
    """ Retrieve the project and protocol from this request.
    Return:
        (project, protocol) tuple

    Parameters
    ----------
    requestType
    request
    """
    requestDict = getattr(request, requestType)

    protId = requestDict.get("protocolId")
    protClass = requestDict.get("protocolClass")

    # Load the project
    project = loadProject(request)

    # Create the protocol object
    if protId and protId != 'None':  # Case of existing protocol
        protId = requestDict.get('protocolId', None)
        protocol = project.getProtocol(int(protId))

        # Remove this and create loadProtocol method in project class
        protocol.setProject(project)

        # Create a new protocol (added from the menu)
    else:
        protocolClass = em.getProtocols().get(protClass, None)
        protocol = project.newProtocol(protocolClass)
        loadProtocolConf(protocol)

    return project, protocol
コード例 #3
0
def loadProtocolProject(request, requestType='POST'):
    """ Retrieve the project and protocol from this request.
    Return:
        (project, protocol) tuple
    """
    requestDict = getattr(request, requestType)
    projectName = request.session['projectName']
    #print "projectName %s"%projectName
    protId = requestDict.get("protocolId")
    protClass = requestDict.get("protocolClass")

    # Load the project
    project = loadProject(request)

    # Create the protocol object
    if protId and protId != 'None':  # Case of new protocol
        protId = requestDict.get('protocolId', None)
        protocol = project.getProtocol(int(protId))

        # Remove this and create loadProtocol method in project class
        protocol.setProject(project)
    else:
        protocolClass = em.getProtocols().get(protClass, None)
        protocol = project.newProtocol(protocolClass)

    return (project, protocol)
コード例 #4
0
ファイル: views_util.py プロジェクト: coocoky/scipion
def loadProtocolProject(request, requestType='POST'):
    """ Retrieve the project and protocol from this request.
    Return:
        (project, protocol) tuple
    """
    requestDict = getattr(request, requestType)
    projectName = request.session['projectName']
    #print "projectName %s"%projectName
    protId = requestDict.get("protocolId")
    protClass = requestDict.get("protocolClass")
    
    # Load the project
    project = loadProject(request)
    
    # Create the protocol object
    if protId and protId != 'None':  # Case of new protocol
        protId = requestDict.get('protocolId', None)
        protocol = project.getProtocol(int(protId))
        
        # Remove this and create loadProtocol method in project class
        protocol.setProject(project) 
    else:
        protocolClass = em.getProtocols().get(protClass, None)
        protocol = project.newProtocol(protocolClass)
        
    return (project, protocol)
コード例 #5
0
ファイル: views_util.py プロジェクト: coocoky/scipion
def browse_protocol_class(request):
    if request.is_ajax():
        protClassName = request.GET.get('protClassName')
        from pyworkflow.em import findSubClasses, getProtocols
        objs = findSubClasses(getProtocols(), protClassName).keys()
        
        jsonStr = json.dumps({'objects' : objs},ensure_ascii=False)
        return HttpResponse(jsonStr, mimetype='application/javascript')
コード例 #6
0
def browse_protocol_class(request):
    if request.is_ajax():
        protClassName = request.GET.get('protClassName')
        from pyworkflow.em import findSubClasses, getProtocols
        objs = findSubClasses(getProtocols(), protClassName).keys()

        jsonStr = json.dumps({'objects': objs}, ensure_ascii=False)
        return HttpResponse(jsonStr, mimetype='application/javascript')
コード例 #7
0
ファイル: project.py プロジェクト: denisfortun/scipion
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     #TODO: REMOVE THE USE OF globals() here
     classesDict = dict(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     return SqliteMapper(sqliteFn, classesDict)
コード例 #8
0
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     #TODO: REMOVE THE USE OF globals() here
     classesDict = dict(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     return SqliteMapper(sqliteFn, classesDict)
コード例 #9
0
ファイル: project.py プロジェクト: kevinpetersavage/scipion
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     classesDict = pwobj.Dict(default=pwprot.LegacyProtocol)
     classesDict.update(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     return SqliteMapper(sqliteFn, classesDict)
コード例 #10
0
ファイル: project.py プロジェクト: EyeSeeTea/scipion-web
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     classesDict = dict(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     mapper = SqliteMapper(sqliteFn, classesDict)
     if not self.chdir:
         mapper.setWorkingDir(self.path)
     return mapper
コード例 #11
0
def get_protocols(request):
    search = request.GET.get('search', None)
    result = []
    emProtocolsDict = getProtocols()
    for key, prot in emProtocolsDict.iteritems():
        label = prot.getClassLabel()
        className = prot.__name__
        if search is None or search in label:
            result.append((label, className))

    jsonStr = json.dumps(result, ensure_ascii=False)
    return HttpResponse(jsonStr, mimetype='application/javascript')
コード例 #12
0
ファイル: views_project.py プロジェクト: I2PC/scipion
def get_protocols(request):
    search = request.GET.get('search', None)
    result = []
    emProtocolsDict = getProtocols()
    for key, prot in emProtocolsDict.iteritems():
        label = prot.getClassLabel()
        className = prot.__name__
        if  search is None or search in label:
            result.append((label, className))
    
    jsonStr = json.dumps(result, ensure_ascii=False)    
    return HttpResponse(jsonStr, mimetype='application/javascript')
コード例 #13
0
ファイル: config.py プロジェクト: totalcos/scipion
        def addItem(item):

            # If it is a protocol
            if item["tag"] == "protocol":
                # Get the class name and then if it is disabled
                protClassName = item["value"]
                protClass = em.getProtocols().get(protClassName)
                if protClass is None:
                    return False
                else:
                    return not protClass.isDisabled()
            else:
                return True
コード例 #14
0
ファイル: project.py プロジェクト: josegutab/scipion
 def loadProtocols(self, filename=None, jsonStr=None):
     """ Load protocols generated in the same format as self.exportProtocols.
     Params:
         filename: the path of the file where to read the workflow.
         jsonStr: read the protocols from a string instead of file.
     Note: either filename or jsonStr should be not None.
     """
     f = open(filename)
     protocolsList = json.load(f)
     
     emProtocols = em.getProtocols()
     newDict = {}
     
     # First iteration: create all protocols and setup parameters
     for protDict in protocolsList:
         protClassName = protDict['object.className']
         protId = protDict['object.id']
         protClass = emProtocols.get(protClassName, None)
         
         if protClass is None:
             print "ERROR: protocol class name '%s' not found" % protClassName
         else:
             prot = self.newProtocol(protClass, 
                                     objLabel=protDict.get('object.label', None),
                                     objComment=protDict.get('object.comment', None))
             newDict[protId] = prot
             for paramName, attr in prot.iterDefinitionAttributes():
                 if not attr.isPointer():
                     if paramName in protDict:
                         attr.set(protDict[paramName])
             self.saveProtocol(prot)
     # Second iteration: update pointers values
     for protDict in protocolsList:
         protId = protDict['object.id']
         
         if protId in newDict:
             prot = newDict[protId]
             for paramName, attr in prot.iterDefinitionAttributes():
                     if attr.isPointer() and paramName in protDict:
                         parts = protDict[paramName].split('.')
                         if parts[0] in newDict:
                             attr.set(newDict[parts[0]]) # set pointer to correct created protocol
                             if len(parts) > 1: # set extended attribute part
                                 attr._extended.set(parts[1])
                         else:
                             attr.set(None)
             self.mapper.store(prot)
         
     f.close()
     self.mapper.commit()
コード例 #15
0
def addAllProtocols(protocols):
    # Add all protocols
    from pyworkflow.em import getProtocols
    allProts = getProtocols()

    # Sort the dictionary
    allProtsSorted = OrderedDict(
        sorted(allProts.items(), key=lambda e: e[1].getClassLabel()))

    allProtMenu = ProtocolConfig("All")
    packages = {}
    # Group protocols by package name
    for k, v in allProtsSorted.iteritems():

        if isAFinalProtocol(v, k):

            packageName = v.getClassPackageName()

            # Get the package submenu
            packageMenu = packages.get(packageName)

            # If no package menu available
            if packageMenu is None:

                # Add it to the menu ...
                packageLine = {
                    "tag": "package",
                    "value": packageName,
                    "text": packageName
                }
                packageMenu = addToTree(allProtMenu, packageLine)

                # Store it in the dict
                packages[packageName] = packageMenu

            # Add the protocol
            protLine = {
                "tag": "protocol",
                "value": k,
                "text": v.getClassLabel(prependPackageName=False)
            }

            # If it's a new protocol
            if v.isNew():
                # add the new icon
                protLine["icon"] = "newProt.png"

            addToTree(packageMenu, protLine)

    protocols["All"] = allProtMenu
コード例 #16
0
ファイル: config.py プロジェクト: I2PC/scipion
def addAllProtocols(protocols):
    # Add all protocols
    from pyworkflow.em import getProtocols
    allProts = getProtocols()

    # Sort the dictionary
    allProtsSorted = OrderedDict(sorted(allProts.items(), key= lambda e: e[1].getClassLabel()))

    allProtMenu = ProtocolConfig(ALL_PROTOCOLS)
    packages = {}
    # Group protocols by package name
    for k, v in allProtsSorted.iteritems():

        if isAFinalProtocol(v, k):

            packageName = v.getClassPackageName()

            # Get the package submenu
            packageMenu = packages.get(packageName)

            # If no package menu available
            if packageMenu is None:

                # Add it to the menu ...
                packageLine = {"tag": "package", "value": packageName,
                               "text": packageName}
                packageMenu = addToTree(allProtMenu, packageLine)

                # Store it in the dict
                packages[packageName] = packageMenu

            # Add the protocol
            tag = getProtocolTag(v.isInstalled())

            protLine = {"tag": tag, "value": k,
                        "text": v.getClassLabel(prependPackageName=False)}

            # If it's a new protocol
            if v.isNew() and v.isInstalled():
                # add the new icon
                protLine["icon"] = "newProt.png"

            addToTree(packageMenu, protLine)

    protocols[ALL_PROTOCOLS] = allProtMenu
コード例 #17
0
    def handle(self):
        try:
            project = self.server.project
            window = self.server.window
            msg = self.request.recv(1024)
            tokens = shlex.split(msg)
            if msg.startswith('run protocol'):
                protocolName = tokens[2]
                from pyworkflow.em import getProtocols
                protocolClass = getProtocols()[protocolName]
                # Create the new protocol instance and set the input values
                protocol = project.newProtocol(protocolClass)

                for token in tokens[3:]:
                    #print token
                    param, value = token.split('=')
                    attr = getattr(protocol, param, None)
                    if param == 'label':
                        protocol.setObjLabel(value)
                    elif attr.isPointer():
                        obj = project.getObject(int(value))
                        attr.set(obj)
                    elif value:
                        attr.set(value)
                #project.launchProtocol(protocol)
                # We need to enqueue the action of execute a new protocol
                # to be run in the same GUI thread and avoid concurrent
                # access to the project sqlite database
                window.getViewWidget().executeProtocol(protocol)
            if msg.startswith('run function'):
                functionName = tokens[2]
                functionPointer = getattr(window, functionName)
                functionPointer(*tokens[3:])
            else:
                answer = 'no answer available'
                self.request.sendall(answer + '\n')
        except Exception as e:
            print e
            import traceback
            traceback.print_stack()
コード例 #18
0
ファイル: project.py プロジェクト: I2PC/scipion
    def handle(self):
        try:
            project = self.server.project
            window = self.server.window
            msg = self.request.recv(1024)
            tokens = shlex.split(msg)
            if msg.startswith('run protocol'):
                protocolName = tokens[2]
                from pyworkflow.em import getProtocols
                protocolClass = getProtocols()[protocolName]
                # Create the new protocol instance and set the input values
                protocol = project.newProtocol(protocolClass)

                for token in tokens[3:]:
                    #print token
                    param, value = token.split('=')
                    attr = getattr(protocol, param, None)
                    if param == 'label':
                        protocol.setObjLabel(value)
                    elif attr.isPointer():
                        obj = project.getObject(int(value))
                        attr.set(obj)
                    elif value:
                        attr.set(value)
                #project.launchProtocol(protocol)
                # We need to enqueue the action of execute a new protocol
                # to be run in the same GUI thread and avoid concurrent
                # access to the project sqlite database
                window.getViewWidget().executeProtocol(protocol)
            if msg.startswith('run function'):
                functionName = tokens[2]
                functionPointer = getattr(window, functionName)
                functionPointer(*tokens[3:])
            else:
                answer = 'no answer available'
                self.request.sendall(answer + '\n')
        except Exception as e:
            print e
            import traceback
            traceback.print_stack()
コード例 #19
0
ファイル: views_tree.py プロジェクト: I2PC/scipion
def populateProtTree(tree, obj):    
    emProtocolsDict = em.getProtocols()
    
    for sub in obj:
        text = sub.text.get()
        value = sub.value.get(text)
        tag = sub.tag.get('')
        icon = sub.icon.get('')
        openItem = sub.openItem.get()
        item = TreeItem(text, tag, icon, openItem)
        tree.childs.append(item)
        # If have tag 'protocol_base', fill dynamically with protocol sub-classes
        protClassName = value.split('.')[-1]  # Take last part
        if sub.value.hasValue() and tag == 'protocol_base':
            prot = emProtocolsDict.get(protClassName, None)
            if prot is not None:
                for k, v in emProtocolsDict.iteritems():
                    if not v is prot and issubclass(v, prot):
                        protItem = TreeItem(k, 'protocol_class', '/python_file.gif', None, protClassName, v)
                        item.childs.append(protItem)
        else:
            item.protClass = protClassName
            populateProtTree(item, sub)
コード例 #20
0
ファイル: project.py プロジェクト: kevinpetersavage/scipion
    def loadProtocols(self, filename=None, jsonStr=None):
        """ Load protocols generated in the same format as self.exportProtocols.
        Params:
            filename: the path of the file where to read the workflow.
            jsonStr: read the protocols from a string instead of file.
        Note: either filename or jsonStr should be not None.
        """
        f = open(filename)
        protocolsList = json.load(f)

        emProtocols = em.getProtocols()
        newDict = OrderedDict()

        # First iteration: create all protocols and setup parameters
        for protDict in protocolsList:
            protClassName = protDict['object.className']
            protId = protDict['object.id']
            protClass = emProtocols.get(protClassName, None)

            if protClass is None:
                print "ERROR: protocol class name '%s' not found" % protClassName
            else:
                prot = self.newProtocol(protClass,
                                        objLabel=protDict.get('object.label',
                                                              None),
                                        objComment=protDict.get(
                                            'object.comment', None))
                newDict[protId] = prot
                self.saveProtocol(prot)

        # Second iteration: update pointers values
        def _setPointer(pointer, value):
            # Properly setup the pointer value checking if the 
            # id is already present in the dictionary
            parts = value.split('.')
            target = newDict.get(parts[0], None)
            pointer.set(target)
            if not pointer.pointsNone():
                pointer.setExtendedParts(parts[1:])

        for protDict in protocolsList:
            protId = protDict['object.id']

            if protId in newDict:
                prot = newDict[protId]
                for paramName, attr in prot.iterDefinitionAttributes():
                    if paramName in protDict:
                        # If the attribute is a pointer, we should look
                        # if the id is already in the dictionary and 
                        # set the extended property
                        if attr.isPointer():
                            _setPointer(attr, protDict[paramName])
                        # This case is similar to Pointer, but the values
                        # is a list and we will setup a pointer for each value
                        elif isinstance(attr, pwobj.PointerList):
                            for value in protDict[paramName]:
                                p = pwobj.Pointer()
                                _setPointer(p, value)
                                attr.append(p)
                        # For "normal" parameters we just set the string value 
                        else:
                            attr.set(protDict[paramName])
                self.mapper.store(prot)

        f.close()
        self.mapper.commit()

        return newDict
コード例 #21
0
ファイル: pw_protocol_list.py プロジェクト: josegutab/scipion
# *  All comments concerning this program package may be sent to the
# *  e-mail address '*****@*****.**'
# *
# **************************************************************************
"""
List all existing protocols within Scipion
"""

import sys
from pyworkflow.em import getProtocols


if __name__ == '__main__':
    count = 0
    withDoc = '--with-doc' in sys.argv
    emProtocolsDict = getProtocols()
    
    protDict = {}
    
    # Group protocols by package name
    for k, v in emProtocolsDict.iteritems():
        packageName = v.getClassPackageName()
        
        if packageName not in protDict:
            protDict[packageName] = []
        
        protDict[packageName].append((k, v))
           
         
    for group, prots in protDict.iteritems():
        print "-" * 100
コード例 #22
0
def getFirstLine(doc):
    """ Get the first non empty line from doc. """
    if doc:
        for lines in doc.split('\n'):
            l = lines.strip()
            if l:
                return l
    return ''


if __name__ == '__main__':
    count = 0
    withDoc = '--with-doc' in sys.argv
    asciidoc = '--asciidoc' in sys.argv
    
    emProtocolsDict = em.getProtocols()
    
    emCategories = [('Imports', em.ProtImport, []),
                    ('Micrographs', em.ProtMicrographs, []),
                    ('Particles', em.ProtParticles, []),
                    ('2D', em.Prot2D, []),
                    ('3D', em.Prot3D, [])]
    
    protDict = {}
    
    # Group protocols by package name
    for k, v in emProtocolsDict.iteritems():
        packageName = v.getClassPackageName()
        
        if packageName not in protDict:
            protDict[packageName] = []
コード例 #23
0
ファイル: pw_protocol_list.py プロジェクト: I2PC/scipion
    numParents = len(classRef.__bases__)
    while numParents == 1 and classRef is not Protocol:
        classRef = classRef.__bases__[0]
        numParents = len(classRef.__bases__)
    if numParents > 1:
        return True
    else:
        return False

if __name__ == '__main__':
    count = 0
    withDoc  = '--with-doc' in sys.argv
    asciidoc = '--asciidoc' in sys.argv
    extended = '--extended' in sys.argv

    emProtocolsDict = em.getProtocols()
    emCategories = [('Imports', em.ProtImport, []),
                    ('Micrographs', em.ProtMicrographs, []),
                    ('Particles', em.ProtParticles, []),
                    ('2D', em.Prot2D, []),
                    ('3D', em.Prot3D, [])]
    protDict = {}

    # Group protocols by package name
    for k, v in emProtocolsDict.iteritems():
        packageName = v.getClassPackageName()

        if packageName not in protDict:
            protDict[packageName] = []

        if not issubclass(v, Viewer) and not v.isBase():