コード例 #1
0
ファイル: jnomics_service.py プロジェクト: cbun/narrative
def fidstoextids(fids,retries=0):
    if retries > 10: return
    idc = IDServerAPI(OTHERURLS.ids)
    try:
        ext_ids = idc.kbase_ids_to_external_ids(fids)
    except:
        retries+=1
        fidstoextids(fids,retries)
    return ext_ids
コード例 #2
0
ファイル: jnomics_service.py プロジェクト: cbun/narrative
    def writeWS(client, previous_steps):
        previous_steps = previous_steps[-1]
        #previous_job_id = previous_step["output"].job_id
        #pattern =  re.compile("\[id=(.*?)]")
        #shockid = parselog(previous_job_id,pattern,auth)
        #sid = str(shockid).rstrip().split('=')[1].replace(']','')
        if 'output' in previous_steps and 'shock_id' in previous_steps['output']:
            shock_id = previous_steps['output']['shock_id']
        idc = IDServerAPI(OTHERURLS.ids)
        name = 'kb|variant.'+str(idc.allocate_id_range(WSTYPES.var_vcftype,1))
        obj = { "name": name,
               "type": "vcf",
               "created":strftime("%d %b %Y %H:%M:%S +0000", gmtime()),
               "shock_ref":{ "shock_id" : shock_id,
                             "shock_url" : OTHERURLS.shock+"/"+shock_id },
               "metadata" : meta
               }

        return ws_saveobject(name,obj, WSTYPES.var_vcftype,meth.workspace_id,meth.token)
コード例 #3
0
ファイル: plants_coex.py プロジェクト: ugswork/narrative
def go_anno_net(meth, net_obj_id=None):
    """Add Gene Ontology annotation to network gene nodes

    :param net_obj_id: Network object id
    :type net_obj_id: kbtypes.KBaseNetworks.Network
    :return: Workspace id
    :rtype: kbtypes.Unicode
    :output_widget: ValueListWidget
    """
    meth.stages = 5

    meth.advance("Prepare annotation service")
    #gc = GWAS(URLS.gwas, token=meth.token)

    # load from current or other workspace
    wsid = meth.workspace_id
    # save to current workspace
    ws_save_id = meth.workspace_id

    meth.advance("Load network object")
    wsd = Workspace2(token=meth.token, wsid=wsid)
    oc = Ontology(url=URLS.ontology)

    net_object = wsd.get(net_obj_id)
    nc = Node(net_object['nodes'], net_object['edges'])

    idc = IDServerAPI(URLS.ids)
    cdmic = CDMI_API(URLS.cdmi)
    cdmie = CDMI_EntityAPI(URLS.cdmi)
    #idm = IdMap(URLS.idmap)
    gids = [
        i for i in sorted(nc.ugids.keys()) if 'CDS' in i or 'locus' in i or (
            not 'clst' in i and not i.startswith('cluster') and 'ps.' not in i)
    ]

    meth.advance("Get relationships from central data model")
    #eids = idc.kbase_ids_to_external_ids(gids)
    eids = kb_id2ext_id(idc, gids, 100)
    gids2cds = ids2cds(gids)
    cgids = gids2cds.values()
    cds2l = cds2locus(cgids)
    #mrnas_l = cdmie.get_relationship_Encompasses(gids, [], ['to_link'], [])
    #mrnas = dict((i[1]['from_link'], i[1]['to_link']) for i in mrnas_l)
    #locus_l = cdmie.get_relationship_Encompasses(mrnas.values(), [], ['to_link'], [])
    #locus = dict((i[1]['from_link'], i[1]['to_link']) for i in locus_l)
    #lgids = [locus[mrnas[i]] for i in gids if i in mrnas.keys()]  # ignore original locus ids in gids
    lgids = cds2l.values()

    meth.advance("Annotate ({:d} nodes, {:d} edges)".format(
        len(net_object['nodes']), len(net_object['edges'])))
    #ots = oc.get_goidlist(lgids, ['biological_process'], ['IEA'])
    ots = oc.get_goidlist(cgids, [], [])
    oan = ()  #oc.get_go_annotation(lgids)
    funcs = cdmic.fids_to_functions(lgids)
    funcs_org = cdmic.fids_to_functions(cgids)
    annotate_nodes(net_object,
                   ots=ots,
                   oan=oan,
                   funcs=funcs,
                   funcs_org=funcs_org,
                   eids=eids,
                   gids2cds=gids2cds,
                   cds2l=cds2l)

    meth.advance("Save annotated object to workspace {}".format(ws_save_id))
    obj = {
        'type': 'KBaseNetworks.Network',
        'data': net_object,
        'name': net_obj_id + ".ano",
        'meta': {
            'original': net_obj_id
        }
    }
    wsd.save_objects({'workspace': ws_save_id, 'objects': [obj]})

    return _workspace_output(net_obj_id + ".ano")