Mercurial > repos > pablocarb > synbiodesign
comparison rpviz/Test with Ecoli ntwk/E coli PPI network.py @ 16:fe78fd6b315a draft
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
author | pablocarb |
---|---|
date | Tue, 11 Jun 2019 11:42:40 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:785b6253af1f | 16:fe78fd6b315a |
---|---|
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 Created on Tue May 28 11:38:34 2019 | |
4 | |
5 @author: Anaelle | |
6 """ | |
7 | |
8 | |
9 import networkx as nx | |
10 import numpy as np | |
11 import matplotlib.pyplot as plt | |
12 import requests | |
13 | |
14 | |
15 tab=np.loadtxt('HT.PMID-15690043.EcoliNet.303gene.3446link.txt',dtype='str',delimiter='\t') #Network file | |
16 smartab=np.loadtxt('Copy_of_All_genes_of_E._coli_K-12_substr._MG1655.txt', dtype='str',delimiter='\t',usecols=(0,1)) #Smart table to assign a link to each node | |
17 | |
18 reseau=nx.Graph() | |
19 dic_links={} | |
20 for i in range(len(tab)): | |
21 reseau.add_edge(tab[i][0],tab[i][1],weight=tab[i][2]) #network construction | |
22 for nodes in range(len(list(reseau.nodes))): | |
23 for j in range(len(smartab)): | |
24 if smartab[j][1][1:-1]==list(reseau.nodes)[nodes]: | |
25 url=smartab[j][0][1:-1] | |
26 left, right = url.split(':') | |
27 url_new = ':'.join( [left, requests.utils.quote(right)] ) #to avoid encoding problems | |
28 dic_links[list(reseau.nodes)[nodes]]= url_new#each link is assigned to each node | |
29 | |
30 nx.set_node_attributes(reseau,name='link',values=dic_links) | |
31 nx.write_gml(reseau,'reseau.gml') |