Created
December 19, 2013 10:35
-
-
Save heliy/8037311 to your computer and use it in GitHub Desktop.
#PPI中癌基因子图
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:UTF-8 | |
#!/usr/bin/python | |
import networkx as nx | |
import matplotlib.pyplot as plt | |
def cancergenes(filename="cancer_gene_census.tsv"): | |
doms,recs=[],[] | |
for line in open(filename,'r').read().split('\r'): | |
cons=line.split("\t") | |
if(cons[11]=="Dom"): | |
doms.append(cons[0]) | |
else: | |
recs.append(cons[0]) | |
return doms,recs | |
def ppihave(genes,ppifile="BINARY_PROTEIN_PROTEIN_INTERACTIONS.txt"): | |
ppis=[] | |
for line in open(ppifile,'r').readlines(): | |
subs=line.split('\t') | |
if subs[0] in genes and subs[3] in genes: | |
ppis.append((subs[0],subs[3])) | |
return ppis | |
def nxdraw(): | |
doms,res=cancergenes() | |
ppis=ppihave(res+doms) | |
G=nx.Graph() | |
G.add_nodes_from(res+doms) | |
G.add_edges_from(ppis) | |
colors=[1]*len(res)+[2]*len(doms) | |
pos=nx.spring_layout(G) | |
nx.draw_networkx_nodes(G,pos,node_size=30,node_color=colors) | |
nx.draw_networkx_edges(G,pos) | |
plt.axis('off') | |
plt.savefig("cancer_gene2ppi.png") | |
nxdraw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment