#!/usr/bin/python## Denes Turei, turei.denes@gmail.com#importpypathpa=pypath.PyPath()pa.load_omnipath()m=pa.mapperpa.graph.vs['entrez']=list(map(lambdav:m.map_name(v['name'],'uniprot','entrez',ncbi_tax_id=9606),pa.graph.vs))pa.load_all_pathways()# this loads pathway annotations from KEGG, Signor and SignaLink; NetPath is currently not included# here you already have everything loaded# and you can access the data by the attributes of the igraph object,# for example:header=['entrezA','entrezB','is_stimulation','is_inhibition','KEGG_pathways_A','SignaLink_pathways_A','Signor_pathways_A','KEGG_pathways_B','SignaLink_pathways_B','Signor_pathways_B']withopen('pathways.tab','w')asoutf:_=outf.write('%s\n'%'\t'.join(header))foreinpa.graph.es:uniprots={pa.graph.vs[e.source]['name']:e.source,pa.graph.vs[e.target]['name']:e.target}_dir=e['dirs']directions=_dir.which_dirs()directed=_dir.is_directed()ifnotlen(directions):directions.append(tuple(uniprots.keys()))fordindirections:positive=_dir.is_stimulation(d)negative=_dir.is_inhibition(d)unknown_effect=notpositiveandnotnegativesource=pa.graph.vs[uniprots[d[0]]]target=pa.graph.vs[uniprots[d[1]]]forentrez1insource['entrez']:forentrez2intarget['entrez']:_=outf.write('%s\n'% \
'\t'.join([entrez1,entrez2,str(int(positive)),str(int(negative)),';'.join(source['kegg_pathways']),';'.join(source['signalink_pathways']),';'.join(source['signor_pathways']),';'.join(target['kegg_pathways']),';'.join(target['signalink_pathways']),';'.join(target['signor_pathways'])# and add other attributes you wish to export]))
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.