コード例 #1
0
def updateAnnotation(rosrs, rouri, resuri, bodypath, bodycontent):
    bodyuri = getResourceUri(rouri, bodypath)
    log.info("UpdateAnnotation:")
    log.info("-- resuri:  %s"%(resuri))
    log.info("-- rouri:   %s"%(rouri))
    log.info("-- bodyuri: %s"%(bodyuri))
    # If annotation is not aggregated in RO, add it
    (status, reason, headers, uri, data) = rosrs.getROResource(bodyuri, rouri)
    log.debug("Get annotation %s: %03d %s"%(bodyuri, status, reason))
    if status == 404:
        (status, reason, proxyuri, newbodyuri) = rosrs.aggregateResourceInt(
            rouri, bodypath, ctype="application/RDF+XML", body=ANNOTATION_EMPTY)
        assert status == 201, "Aggregating annotation body %s - status %03d %s"%(bodyuri, status, reason)
        assert newbodyuri == bodyuri, (
            "Aggregated annotation URI mismatch %s (expected %s)"%(newbodyuri, bodyuri))
        log.info("-- Created empty annotation body (%s)"%(bodyuri))
    # If annotation stub does not exist, create new
    bodyuris = list(rosrs.getROAnnotationBodyUris(rouri, resuri))
    log.debug("--- bodyuris:\n"+"\n".join([repr(u) for u in bodyuris]))
    if not bodyuri in bodyuris:
        (status, reason, annuri) = rosrs.createROAnnotationExt(rouri, resuri, bodyuri)
        assert status == 201, "Creating annotation stub for %s - status %03d %s"%(bodyuri, status, reason)
        log.info("-- Created annotation stub for resource (%s) with body (%s)"%(resuri, bodyuri))
    # Replace annotation body
    (status, reason, headers, data) = rosrs.doRequest(bodyuri,
        method="PUT", ctype="application/RDF+XML", body=bodycontent)
    assert status in [200,201], "Updating annotation body %s - status %03d %s"%(bodyuri, status, reason)
    log.info("-- Updated annotation body (%s)"%(bodyuri))
    return
コード例 #2
0
            <roterms:resource rdf:resource="&BUNDLE;workflow/Create_SNP_Set/in/Entrez_ID" />
          </rdf:Description>
        </roterms:inputValue>
        <roterms:inputValue>
          <rdf:Description>
            <roterms:portName>set_width</roterms:portName>
            <roterms:resource rdf:resource="&BUNDLE;workflow/Create_SNP_Set/in/set_width" />
          </rdf:Description>
        </roterms:inputValue>
        <roterms:inputValue>
          <rdf:Description>
            <roterms:portName>path_to_output_file</roterms:portName>
            <roterms:resource rdf:resource="&BUNDLE;workflow/Create_SNP_Set/in/path_to_output_file" />
          </rdf:Description>
        </roterms:inputValue>
      </rdf:Description>
    </rdf:RDF>
    """

# Main program script

if __name__ == "__main__":
    # Set up ROSRS session and key values
    rosrs   = ROSRS_Session(ROSRS_API_URI, accesskey=ROSRS_ACCESS_TOKEN)
    rouri   = getResourceUri(ROSRS_API_URI, RO_PATH)
    resuri  = getResourceUri(rouri, RES_PATH)
    # Add annotation
    updateAnnotation(rosrs, rouri, resuri, ANNOTATION_PATH, ANNOTATION_BODY)
    # Finish up
    rosrs.close()