• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.id_of函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中synapseclient.utils.id_of函数的典型用法代码示例。如果您正苦于以下问题:Python id_of函数的具体用法?Python id_of怎么用?Python id_of使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了id_of函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: archive

def archive(evaluation, destination=None, name=None, query=None):
    """
    Archive the submissions for the given evaluation queue and store them in the destination synapse folder.

    :param evaluation: a synapse evaluation queue or its ID
    :param destination: a synapse folder or its ID
    :param query: a query that will return the desired submissions. At least the ID must be returned.
                  defaults to _select * from evaluation_[EVAL_ID] where status=="SCORED"_.
    """
    challenge = {'5877348':'FusionDetection','5952651':'IsoformQuantification'}
    if not query:
        query = 'select * from evaluation_%s where status=="VALIDATED"' % utils.id_of(evaluation)
    path = challenge[utils.id_of(evaluation)]
    ## for each submission, download it's associated file and write a line of metadata
    results = Query(query=query)
    if 'objectId' not in results.headers:
        raise ValueError("Can't find the required field \"objectId\" in the results of the query: \"{0}\"".format(query))
    for result in results:
        #Check if the folder has already been created in synapse 
        #(This is used as a tool to check submissions that have already been cached)
        submissionId = result[results.headers.index('objectId')]
        check = syn.query('select id,name from folder where parentId == "%s" and name == "%s"' % (destination,submissionId))
        if check['totalNumberOfResults']==0:
            os.mkdir(submissionId)
            submission_parent = syn.store(Folder(submissionId,parent=destination))
            submission = syn.getSubmission(submissionId, downloadLocation=submissionId)
            newFilePath = submission.filePath.replace(' ', '_')
            shutil.move(submission.filePath,newFilePath)
            #Store CWL file in bucket
            os.system('gsutil cp -R %s gs://smc-rna-cache/%s' % (submissionId,path))
            with open(newFilePath,"r") as cwlfile:
                docs = yaml.load(cwlfile)
                merged = docs['$graph']
                docker = []
                for tools in merged:
                    if tools['class'] == 'CommandLineTool':
                        if tools.get('requirements',None) is not None:
                            for i in tools['requirements']:
                                if i.get('dockerPull',None) is not None:
                                    docker.append(i['dockerPull'])
                    if tools['class'] == 'Workflow':
                        hints = tools.get("hints",None)
                        if hints is not None:
                            for i in tools['hints']:
                                if os.path.basename(i['class']) == "synData":
                                    temp = syn.get(i['entity'])
                                    #Store index files
                                    os.system('gsutil cp %s gs://smc-rna-cache/%s/%s' % (temp.path,path,submissionId))
            os.system('rm -rf ~/.synapseCache/*')
            #Pull, save, and store docker containers
            docker = set(docker)
            for i in docker:
                os.system('sudo docker pull %s' % i)
                os.system('sudo docker save %s' % i)
                os.system('sudo docker save -o %s.tar %s' %(os.path.basename(i),i))
                os.system('sudo chmod a+r %s.tar' % os.path.basename(i))
                os.system('gsutil cp %s.tar gs://smc-rna-cache/%s/%s' % (os.path.basename(i),path,submissionId))
                os.remove("%s.tar" % os.path.basename(i))
            os.system('rm -rf %s' % submissionId)
开发者ID:brianjohnhaas,项目名称:SMC-RNA-Challenge,代码行数:59,代码来源:challenge.py


示例2: tableUpdateWhere

def tableUpdateWhere(tableSchema, whereClause, setDict):
    """ The UPDATE statement is used to update existing rows in a table.
    """
    from synapseclient.table import Table
    from synapseclient.utils import id_of
    import tempfile
    id = id_of(tableSchema)
    query = 'select %s from %s where %s' % (','.join(setDict.keys()), id, whereClause)
    df = syn.tableQuery(query).asDataFrame()
    for key, value in setDict.items():
        df[key] = value
    print(df)
    # df.to_csv('skit.csv')
    return syn.store(Table(id_of(tableSchema), 'skit.csv'))
开发者ID:larssono,项目名称:Analysis_helpers,代码行数:14,代码来源:synapseHelpers.py


示例3: archive

def archive(evaluation, destination=None, name=None, query=None):
    """
    Archive the submissions for the given evaluation queue and store them in the destination synapse folder.

    :param evaluation: a synapse evaluation queue or its ID
    :param destination: a synapse folder or its ID
    :param query: a query that will return the desired submissions. At least the ID must be returned.
                  defaults to _select * from evaluation_[EVAL_ID] where status=="SCORED"_.
    """
    tempdir = tempfile.mkdtemp()
    archive_dirname = 'submissions_%s' % utils.id_of(evaluation)

    if not query:
        query = 'select * from evaluation_%s where status=="SCORED"' % utils.id_of(evaluation)

    ## for each submission, download it's associated file and write a line of metadata
    results = Query(query=query)
    if not name:
        name = 'submissions_%s.tgz' % utils.id_of(evaluation)
    tar_path = os.path.join(tempdir, name)
    metadata_file_path = os.path.join(tempdir, 'submission_metadata.csv')
    print "creating tar at:", tar_path

    ## for each submission, we add a file to the tar and a row
    ## to the metadata .csv file
    with tarfile.open(tar_path, mode='w:gz') as archive:
        with open(metadata_file_path, 'w') as f:

            ## write header row to .csv file
            header = ','.join(results.headers)
            print header
            f.write(header + '\n')

            ## add submissions to archive and write rows to .csv file 
            for result in results:
                ## retrieve file into cache and copy it to destination
                submission = syn.getSubmission(result[results.headers.index('objectId')])
                archive.add(submission.filePath, arcname=os.path.join(archive_dirname, submission.id + "_" + os.path.basename(submission.filePath)))
                line = (','.join(unicode(item) for item in result)).encode('utf-8')
                print line
                f.write(line + '\n')

        ## add metadata .csv file to the tar
        archive.add(
            name=metadata_file_path,
            arcname=os.path.join(archive_dirname, 'submission_metadata.csv'))

    entity = syn.store(File(tar_path, parent=destination), evaluation_id=utils.id_of(evaluation))
    print "created:", entity.id, entity.name
    return entity.id
开发者ID:Sage-Bionetworks,项目名称:SMC-Het-Challenge,代码行数:50,代码来源:challenge.py


示例4: test_id_of

def test_id_of():
    assert utils.id_of(1) == '1'
    assert utils.id_of('syn12345') == 'syn12345'
    assert utils.id_of({'foo':1, 'id':123}) == 123
    assert_raises(ValueError, utils.id_of, {'foo':1, 'idzz':123})
    assert utils.id_of({'properties':{'id':123}}) == 123
    assert_raises(ValueError, utils.id_of, {'properties':{'qq':123}})
    assert_raises(ValueError, utils.id_of, object())

    class Foo:
        def __init__(self, id):
            self.properties = {'id':id}

    foo = Foo(123)
    assert utils.id_of(foo) == 123
开发者ID:kimyen,项目名称:synapsePythonClient,代码行数:15,代码来源:unit_tests.py


示例5: test_id_of

def test_id_of():
    assert utils.id_of(1) == "1"
    assert utils.id_of("syn12345") == "syn12345"
    assert utils.id_of({"foo": 1, "id": 123}) == 123
    assert_raises(ValueError, utils.id_of, {"foo": 1, "idzz": 123})
    assert utils.id_of({"properties": {"id": 123}}) == 123
    assert_raises(ValueError, utils.id_of, {"properties": {"qq": 123}})
    assert_raises(ValueError, utils.id_of, object())

    class Foo:
        def __init__(self, id):
            self.properties = {"id": id}

    foo = Foo(123)
    assert utils.id_of(foo) == 123
开发者ID:thomasyu888,项目名称:synapsePythonClient,代码行数:15,代码来源:unit_tests.py


示例6: list_evaluations

def list_evaluations(project):
    print '\n\nEvaluations for project: ', utils.id_of(project)
    print '-' * 60

    evaluations = syn.getEvaluationByContentSource(project)
    for evaluation in evaluations:
        print "Evaluation: %s" % evaluation.id, evaluation.name.encode('utf-8')
开发者ID:Sage-Bionetworks,项目名称:ISMB-AKES-challenge,代码行数:7,代码来源:challenge.py


示例7: test_id_of

def test_id_of():
    assert_equals(utils.id_of(1), '1')
    assert_equals(utils.id_of('syn12345'), 'syn12345')
    assert_equals(utils.id_of({'foo': 1, 'id': 123}), '123')
    assert_raises(ValueError, utils.id_of, {'foo': 1, 'idzz': 123})
    assert_equals(utils.id_of({'properties': {'id': 123}}), '123')
    assert_raises(ValueError, utils.id_of, {'properties': {'qq': 123}})
    assert_raises(ValueError, utils.id_of, object())

    class Foo:
        def __init__(self, id_attr_name, id):
            self.properties = {id_attr_name: id}

    id_attr_names = ['id', 'ownerId', 'tableId']

    for attr_name in id_attr_names:
        foo = Foo(attr_name, 123)
        assert_equals(utils.id_of(foo), '123')
开发者ID:Sage-Bionetworks,项目名称:synapsePythonClient,代码行数:18,代码来源:unit_tests.py


示例8: __init__

    def __init__(self, **kwargs):
        #Verify that the parameters are correct
        if not 'owner' in kwargs:
            sys.stderr.write('Wiki constructor must have an owner specified')
            raise ValueError

        super(Wiki, self).__init__(kwargs)
        self.ownerType=guess_object_type(self.owner)
        self.ownerId=id_of(self.owner)
        del self['owner']
开发者ID:xschildw,项目名称:synapsePythonClient,代码行数:10,代码来源:wiki.py


示例9: removeColumn

 def removeColumn(self, column):
     """
     :param column: a column object or its ID
     """
     if isinstance(column, basestring) or isinstance(column, int) or hasattr(column, 'id'):
         self.properties.columnIds.remove(utils.id_of(column))
     elif isinstance(column, Column) and self.columns_to_store:
         self.columns_to_store.remove(column)
     else:
         ValueError("Can't remove column %s" + unicode(column))
开发者ID:xindiguo,项目名称:synapsePythonClient,代码行数:10,代码来源:table.py


示例10: archive

def archive(evaluation, destination=None, name=None, query=None):
    """
    Archive the submissions for the given evaluation queue and store them in the destination synapse folder.

    :param evaluation: a synapse evaluation queue or its ID
    :param destination: a synapse folder or its ID
    :param query: a query that will return the desired submissions. At least the ID must be returned.
                  defaults to _select * from evaluation_[EVAL_ID] where status=="SCORED"_.
    """
    tempdir = tempfile.mkdtemp()
    archive_dirname = "submissions_%s" % utils.id_of(evaluation)

    if not query:
        query = 'select * from evaluation_%s where status=="SCORED"' % utils.id_of(evaluation)

    ## for each submission, download it's associated file and write a line of metadata
    results = Query(query=query)
    if "objectId" not in results.headers:
        raise ValueError('Can\'t find the required field "objectId" in the results of the query: "{0}"'.format(query))
    if not name:
        name = "submissions_%s.tgz" % utils.id_of(evaluation)
    tar_path = os.path.join(tempdir, name)
    print "creating tar at:", tar_path
    print results.headers
    with tarfile.open(tar_path, mode="w:gz") as archive:
        with open(os.path.join(tempdir, "submission_metadata.csv"), "w") as f:
            f.write((",".join(hdr for hdr in (results.headers + ["filename"])) + "\n").encode("utf-8"))
            for result in results:
                ## retrieve file into cache and copy it to destination
                submission = syn.getSubmission(result[results.headers.index("objectId")])
                prefixed_filename = submission.id + "_" + os.path.basename(submission.filePath)
                archive.add(submission.filePath, arcname=os.path.join(archive_dirname, prefixed_filename))
                line = (",".join(unicode(item) for item in (result + [prefixed_filename]))).encode("utf-8")
                print line
                f.write(line + "\n")
        archive.add(
            name=os.path.join(tempdir, "submission_metadata.csv"),
            arcname=os.path.join(archive_dirname, "submission_metadata.csv"),
        )

    entity = syn.store(File(tar_path, parent=destination), evaluation_id=utils.id_of(evaluation))
    print "created:", entity.id, entity.name
    return entity.id
开发者ID:thomasyu888,项目名称:SynapseChallengeTemplates,代码行数:43,代码来源:docker_challenge.py


示例11: __init__

    def __init__(self, properties=None, annotations=None, local_state=None, parent=None, **kwargs):

        if properties:
            if isinstance(properties, collections.Mapping):
                if "annotations" in properties and isinstance(properties["annotations"], collections.Mapping):
                    annotations.update(properties["annotations"])
                    del properties["annotations"]
                self.__dict__["properties"].update(properties)
            else:
                raise SynapseMalformedEntityError("Unknown argument type: properties is a %s" % str(type(properties)))

        if annotations:
            if isinstance(annotations, collections.Mapping):
                self.__dict__["annotations"].update(annotations)
            elif isinstance(annotations, str):
                self.properties["annotations"] = annotations
            else:
                raise SynapseMalformedEntityError("Unknown argument type: annotations is a %s" % str(type(annotations)))

        if local_state:
            if isinstance(local_state, collections.Mapping):
                self.local_state(local_state)
            else:
                raise SynapseMalformedEntityError("Unknown argument type: local_state is a %s" % str(type(local_state)))

        for key in self.__class__._local_keys:
            if key not in self.__dict__:
                self.__dict__[key] = None

        # Extract parentId from parent
        if "parentId" not in kwargs:
            if parent:
                try:
                    kwargs["parentId"] = id_of(parent)
                except Exception:
                    if isinstance(parent, Entity) and "id" not in parent:
                        raise SynapseMalformedEntityError(
                            "Couldn't find 'id' of parent.  Has it been stored in Synapse?"
                        )
                    else:
                        raise SynapseMalformedEntityError("Couldn't find 'id' of parent.")

        # Note: that this will work properly if derived classes declare their
        # internal state variable *before* invoking super(...).__init__(...)
        for key, value in six.iteritems(kwargs):
            self.__setitem__(key, value)

        if "concreteType" not in self:
            self["concreteType"] = self.__class__._synapse_entity_type

        ## Only project can be top-level. All other entity types require parentId
        ## don't enforce this for generic Entity
        if "parentId" not in self and not isinstance(self, Project) and not type(self) == Entity:
            raise SynapseMalformedEntityError("Entities of type %s must have a parentId." % type(self))
开发者ID:Sage-Bionetworks,项目名称:synapsePythonClient,代码行数:54,代码来源:entity.py


示例12: addColumn

 def addColumn(self, column):
     """
     :param column: a column object or its ID
     """
     if isinstance(column, basestring) or isinstance(column, int) or hasattr(column, 'id'):
         self.properties.columnIds.append(utils.id_of(column))
     elif isinstance(column, Column):
         if not self.__dict__.get('columns_to_store', None):
             self.__dict__['columns_to_store'] = []
         self.__dict__['columns_to_store'].append(column)
     else:
         raise ValueError("Not a column? %s" % unicode(column))
开发者ID:xindiguo,项目名称:synapsePythonClient,代码行数:12,代码来源:table.py


示例13: syncFromSynapse

def syncFromSynapse(syn, entity, path=None, ifcollision='overwrite.local', allFiles = None):
    """Synchronizes all the files in a folder (including subfolders) from Synapse.

    :param syn:    A synapse object as obtained with syn = synapseclient.login()

    :param entity:  A Synapse ID, a Synapse Entity object of type folder or project.

    :param path: An optional path where the file hierarchy will be
                 reproduced.  If not specified the files will by default
                 be placed in the synapseCache.

    :param ifcollision:   Determines how to handle file collisions.
                          May be "overwrite.local", "keep.local", or "keep.both".
                          Defaults to "overwrite.local".


    :returns: list of entities (files, tables, links)

    This function will crawl all subfolders of the project/folder
    specified by `id` and download all files that have not already
    been downloaded.  If there are newer files in Synapse (or a local
    file has been edited outside of the cache) since the last download
    then local the file will be replaced by the new file unless
    ifcollision is changed.

    Example::
    Download and print the paths of all downloaded files::

        entities = syncFromSynapse(syn, "syn1234")
        for f in entities:
            print(f.path)
    """
    if allFiles is None: allFiles = list()
    id = id_of(entity)
    results = syn.chunkedQuery("select id, name, nodeType from entity where entity.parentId=='%s'" %id)
    for result in results:
        if is_container(result):
            if path is not None:  #If we are downloading outside cache create directory.
                new_path = os.path.join(path, result['entity.name'])
                try:
                    os.mkdir(new_path)
                except OSError as err:
                    if err.errno!=errno.EEXIST:
                        raise
                print('making dir', new_path)
            else:
                new_path = None
            syncFromSynapse(syn, result['entity.id'], new_path, ifcollision, allFiles)
        else:
            ent = syn.get(result['entity.id'], downloadLocation = path, ifcollision = ifcollision)
            allFiles.append(ent)
    return allFiles
开发者ID:kkdang,项目名称:synapsePythonClient,代码行数:52,代码来源:sync.py


示例14: __init__

 def __init__(self, name=None, columns=None, parent=None, properties=None, annotations=None, local_state=None, **kwargs):
     self.properties.setdefault('columnIds',[])
     if name: kwargs['name'] = name
     if columns:
         for column in columns:
             if isinstance(column, basestring) or isinstance(column, int) or hasattr(column, 'id'):
                 kwargs.setdefault('columnIds',[]).append(utils.id_of(column))
             elif isinstance(column, Column):
                 kwargs.setdefault('columns_to_store',[]).append(column)
             else:
                 raise ValueError("Not a column? %s" % unicode(column))
     super(Schema, self).__init__(concreteType=Schema._synapse_entity_type, properties=properties, 
                                annotations=annotations, local_state=local_state, parent=parent, **kwargs)
开发者ID:xindiguo,项目名称:synapsePythonClient,代码行数:13,代码来源:table.py


示例15: setup

    def setup(self):
        self.eval_id = '9090'
        self.contributors = None
        self.entity = {
            'versionNumber': 7,
            'id': 'syn1009',
            'etag': 'etag',
            'name': 'entity name'
        }
        self.eval = {
            'contentSource': self.entity['id'],
            'createdOn': '2013-11-06T06:04:26.789Z',
            'etag': '86485ea1-8c89-4f24-a0a4-2f63bc011091',
            'id': self.eval_id,
            'name': 'test evaluation',
            'ownerId': '1560252',
            'status': 'OPEN',
            'submissionReceiptMessage': 'Your submission has been received.!'
        }
        self.team = {
            'id': 5,
            'name': 'Team Blue'
        }
        self.submission = {
            'id': 123,
            'evaluationId': self.eval_id,
            'name': self.entity['name'],
            'entityId': self.entity['id'],
            'versionNumber': self.entity['versionNumber'],
            'teamId': id_of(self.team['id']),
            'contributors': self.contributors,
            'submitterAlias': self.team['name']
        }
        self.eligibility_hash = 23

        self.patch_private_submit = patch.object(syn, "_submit", return_value=self.submission)
        self.patch_getEvaluation = patch.object(syn, "getEvaluation", return_value=self.eval)
        self.patch_get = patch.object(syn, "get", return_value=self.entity)
        self.patch_getTeam = patch.object(syn, "getTeam", return_value= self.team)
        self.patch_get_contributors = patch.object(syn, "_get_contributors",
                                                   return_value=(self.contributors, self.eligibility_hash))

        self.mock_private_submit = self.patch_private_submit.start()
        self.mock_getEvaluation = self.patch_getEvaluation.start()
        self.mock_get = self.patch_get.start()
        self.mock_getTeam = self.patch_getTeam.start()
        self.mock_get_contributors = self.patch_get_contributors.start()
开发者ID:Sage-Bionetworks,项目名称:synapsePythonClient,代码行数:47,代码来源:unit_test_client.py


示例16: __init__

    def __init__(self, properties=None, annotations=None, local_state=None, parent=None, **kwargs):

        if properties:
            if isinstance(properties, collections.Mapping):
                if 'annotations' in properties and isinstance(properties['annotations'], collections.Mapping):
                    annotations.update(properties['annotations'])
                    del properties['annotations']
                self.__dict__['properties'].update(properties)
            else:
                raise SynapseMalformedEntityError('Unknown argument type: properties is a %s' % str(type(properties)))

        if annotations:
            if isinstance(annotations, collections.Mapping):
                self.__dict__['annotations'].update(annotations)
            elif isinstance(annotations, basestring):
                self.properties['annotations'] = annotations
            else:
                raise SynapseMalformedEntityError('Unknown argument type: annotations is a %s' % str(type(annotations)))

        if local_state:
            if isinstance(local_state, collections.Mapping):
                self.local_state(local_state)
            else:
                raise SynapseMalformedEntityError('Unknown argument type: local_state is a %s' % str(type(local_state)))

        for key in self.__class__._local_keys:
            if key not in self.__dict__:
                self.__dict__[key] = None

        # Extract parentId from parent
        if 'parentId' not in kwargs:
            try:
                if parent: kwargs['parentId'] = id_of(parent)
            except Exception:
                if parent and isinstance(parent, Entity) and 'id' not in parent:
                    raise SynapseMalformedEntityError("Couldn't find 'id' of parent.  Has it been stored in Synapse?")
                else:
                    raise SynapseMalformedEntityError("Couldn't find 'id' of parent.")

        # Note: that this will work properly if derived classes declare their
        # internal state variable *before* invoking super(...).__init__(...)
        for key, value in kwargs.items():
            self.__setitem__(key, value)

        if 'concreteType' not in self:
            self['concreteType'] = self.__class__._synapse_entity_type
开发者ID:apratap,项目名称:synapsePythonClient,代码行数:46,代码来源:entity.py


示例17: __init__

    def __init__(self, **kwargs):
        # Verify that the parameters are correct
        if not 'owner' in kwargs:
            raise ValueError('Wiki constructor must have an owner specified')

        # Initialize the file handle list to be an empty list
        if 'attachmentFileHandleIds' not in kwargs:
            kwargs['attachmentFileHandleIds'] = []
            
        # Move the 'fileHandles' into the proper (wordier) bucket
        if 'fileHandles' in kwargs:
            for handle in kwargs['fileHandles']:
                kwargs['attachmentFileHandleIds'].append(handle)
            del kwargs['fileHandles']
        
        super(Wiki, self).__init__(kwargs)
        self.ownerId = id_of(self.owner)
        del self['owner']
开发者ID:brucehoff,项目名称:synapsePythonClient,代码行数:18,代码来源:wiki.py


示例18: usedEntity

 def usedEntity(self, target, targetVersion=None, wasExecuted=False):
     """
     TODO_Sphinx
     
     :param target:        either a synapse entity or entity id (as a string)
     :param targetVersion: optionally specify the version of the entity
     :param wasExecuted:   boolean indicating whether the entity represents code that was executed to produce the result
     """
     
     reference = {'targetId':id_of(target)}
     if targetVersion:
         reference['targetVersionNumber'] = int(targetVersion)
     else:
         try:
             # If we have an Entity, get it's version number
             reference['targetVersionNumber'] = target['versionNumber']
         except (KeyError, TypeError):
             # Count on platform to get the current version of the entity from Synapse
             pass
     self['used'].append({'reference':reference, 'wasExecuted':wasExecuted, 'concreteType':'org.sagebionetworks.repo.model.provenance.UsedEntity'})
开发者ID:xschildw,项目名称:synapsePythonClient,代码行数:20,代码来源:activity.py


示例19: validate

def validate(evaluation,
             send_messages=False,
             notifications=False,
             dry_run=False):
    """
    It may be convenient to validate submissions in one pass before scoring
    them, especially if scoring takes a long time.
    """
    print "\n\nValidating", utils.id_of(evaluation)
    print "-" * 60
    for submission, status in syn.getSubmissionBundles(evaluation, status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        submission = syn.getSubmission(submission)

        is_valid, validation_message = validate_submission(submission.filePath)
        print submission.id, validation_message
        if is_valid:
            status.status = "VALIDATED"
        else:
            status.status = "INVALID"

        if not dry_run:
            status = syn.store(status)

        ## send message AFTER storing status to ensure we don't get repeat messages
        if not is_valid and send_messages:
            profile = syn.getUserProfile(submission.userId)

            message = VALIDATION_TEMPLATE.format(
                username=profile.get('firstName', profile.get('userName', profile['ownerId'])),
                submission_id=submission.id,
                submission_name=submission.name,
                message=validation_message)

            response = syn.sendMessage(
                userIds=[submission.userId],
                messageSubject="Error validating Submission to "+CHALLENGE_NAME,
                messageBody=message)
            print "sent validation error message: ", unicode(response).encode('utf-8')
开发者ID:cbare,项目名称:ISMB-AKES-challenge,代码行数:41,代码来源:challenge_template.py


示例20: archive

def archive(evaluation, destination=None, token=None, name=None, query=None):
    """
    Archive the submissions for the given evaluation queue and store them in the destination synapse folder.

    :param evaluation: a synapse evaluation queue or its ID
    :param destination: a synapse folder or its ID
    :param query: a query that will return the desired submissions. At least the ID must be returned.
                  defaults to _select * from evaluation_[EVAL_ID] where status=="SCORED"_.
    """
    challenge = {'5877348':'FusionDetection','5952651':'IsoformQuantification'}
    if not query:
        query = 'select * from evaluation_%s where status=="SCORED"' % utils.id_of(evaluation)
    path = challenge[utils.id_of(evaluation)]
    ## for each submission, download it's associated file and write a line of metadata
    results = Query(query=query)
    if 'objectId' not in results.headers:
        raise ValueError("Can't find the required field \"objectId\" in the results of the query: \"{0}\"".format(query))
    for result in results:
        #Check if the folder has already been created in synapse 
        #(This is used as a tool to check submissions that have already been cached)
        new_map = []
        mapping = syn.get("syn7348150")
        submissionId = result[results.headers.index('objectId')]
        check = syn.query('select id,name from folder where parentId == "%s" and name == "%s"' % (destination,submissionId))
        if check['totalNumberOfResults']==0:
            os.mkdir(submissionId)
            submission = syn.getSubmission(submissionId, downloadFile=False)
            if submission.entity.externalURL is None:
                submission = syn.getSubmission(submissionId, downloadLocation=submissionId)
                newFilePath = submission.filePath.replace(' ', '_')
                shutil.move(submission.filePath,newFilePath)
                #Store CWL file in bucket
                os.system('gsutil cp -R %s gs://smc-rna-eval/entries/%s' % (submissionId,path))
                with open(newFilePath,"r") as cwlfile:
                    docs = yaml.load(cwlfile)
                    merged = docs['$graph']
                    docker = []
                    for tools in merged:
                        if tools['class'] == 'CommandLineTool':
                            if tools.get('requirements',None) is not None:
                                for i in tools['requirements']:
                                    if i.get('dockerPull',None) is not None:
                                        docker.append(i['dockerPull'])
                            if tools.get('hints', None) is not None:
                                for i in tools['hints']:
                                    if i.get('dockerPull',None) is not None:
                                        docker.append(i['dockerPull']) 
                        if tools['class'] == 'Workflow':
                            hints = tools.get("hints",None)
                            if hints is not None:
                                for i in tools['hints']:
                                    if os.path.basename(i['class']) == "synData":
                                        temp = syn.get(i['entity'])
                                        #create synid and index mapping
                                        new_map.append([temp.id,"gs://smc-rna-eval/entries/%s/%s/%s" %(path,submissionId,temp.name)])
                                        #Store index files
                                        os.system('gsutil cp %s gs://smc-rna-eval/entries/%s/%s' % (temp.path,path,submissionId))
                os.system('rm -rf ~/.synapseCache/*')
            else:
                if submission.entity.externalURL.endswith("/"):
                    submission.entity.externalURL = submission.entity.externalURL[:-1]
                taskId = submission.entity.externalURL.split("/")[-1]
                test = subprocess.check_call(["python", os.path.join(os.path.dirname(__file__),"../../SMC-RNA-Eval/sbg-download.py"), "--token", token, taskId, submissionId])
                os.system('gsutil cp -R %s gs://smc-rna-eval/entries/%s' % (submissionId,path))
                #Pull down docker containers
                with open("%s/submission.cwl" % submissionId,"r") as cwlfile:
                    docs = yaml.load(cwlfile)
                    # merged = docs['steps']
                    # docker = []
                    # for tools in merged:
                    #     for hint in tools['run']['hints']:
                    #         if hint['class'] == 'DockerRequirement':
                    #             docker.append(hint['dockerPull'])
                    #     for require in tools['run']['requirements']:
                    #         if require.get('requirements') is not None:
                    #             for i in require.get('requirements'):
                    #                 if i['class'] == 'DockerRequirement':
                    #                     docker.append(i['dockerPull'])
                    docker = []
                    for tools in docs['hints']:
                        if tools['class'] == "DockerRequirement":
                            docker.append(tools['dockerPull'])
            os.system('rm -rf %s' % submissionId)
            if len(new_map) > 0:
                table = syn.store(Table(mapping, new_map))
            #Pull, save, and store docker containers
            docker = set(docker)
            for i in docker:
                fileName = os.path.basename(i).replace(":","_")
                os.system('sudo -i docker pull %s' % i)
                #os.system('sudo -i docker save %s' % i)
                os.system('sudo docker save -o %s.tar %s' %(fileName,i))
                os.system('sudo chmod a+r %s.tar' % fileName)
                os.system('gsutil cp %s.tar gs://smc-rna-eval/entries/%s/%s' % (fileName,path,submissionId))
                os.remove("%s.tar" % fileName)
            submission_parent = syn.store(Folder(submissionId,parent=destination))
开发者ID:Sage-Bionetworks,项目名称:SMC-RNA-Challenge,代码行数:96,代码来源:challenge.py



注:本文中的synapseclient.utils.id_of函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.make_bogus_binary_file函数代码示例发布时间:2022-05-27
下一篇:
Python synapseclient.File类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap