Comments (4)
Another option could be to export the graph from networkx into Cytoscape JSON and load the network in Cytoscape.
from genewalk.
Just for completeness below is the script to generate the GWN subgraph around 3 chosen genes of interest (see Figure 3B of our publication) also discussed here:
#28 (comment)
#!/usr/bin/env python
# coding: utf-8
# # GeneWalk network visualization
import os
import re
import copy
import pickle as pkl
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
plt.rcParams['pdf.fonttype'] = 42
# ### Load GeneWalk multigraph and results
path = '/home/genewalk/qki/'
filename = 'multi_graph.pkl'
with open(os.path.join(path,filename), 'rb') as f:
MG = pkl.load(f)
filename = 'genewalk_results.csv'
GW = pd.read_csv(os.path.join(path,filename))
# ## QKI subnetwork visualization
# Data preprocessing
# Choose genes of interest
GENES=['MAL','PLLP','PLP1']
labels = {}
for node in GENES:
labels[node] = node
#Genes and Neighors
#NB = neighbors
GENES_NB=copy.deepcopy(GENES)
for source in GENES:
GENES_NB.extend(list(MG.neighbors(source)))
print(source, len(GENES_NB))
GENES_NB=sorted(list(set(GENES_NB)))
#Subset of Neighbors that are genes
GENES_only_NB=copy.deepcopy(GENES_NB)
for gene in GENES_NB:
if re.search('GO:',gene):
GENES_only_NB.remove(gene)
#Enumerate GO annotations of Mal according to GeneWalk ranking
gene = 'MAL'
MAL_GO_NB = list(GW[GW['hgnc_symbol']==gene].sort_values(by='global_padj')['go_id'])
labels_MAL_GO_NB = dict()
for i in range(len(MAL_GO_NB)):
labels_MAL_GO_NB[MAL_GO_NB[i]] = str(i+1)
MAL_GO_NB_edges = [(gene,gonode) for gonode in MAL_GO_NB]
# ### Generate SubGraph (for plotting)
SG = MG.subgraph(GENES_NB)
SGplot = nx.OrderedGraph()
SGplot.add_nodes_from(GENES_NB)
SGplot.add_edges_from((u, v) for (u, v) in SG.edges() if u in SGplot if v in SGplot)
# ### Generate plot
plt.figure(figsize=(4,4))#units: inch
pos = nx.circular_layout(SGplot)
nx.draw(SGplot, pos=pos, node_color='white', with_labels=False, alpha=0.1, node_size=150)
nx.draw_networkx_nodes(SGplot, pos, nodelist=GENES_NB, node_size=150, node_color='#B82225', alpha=1)
nx.draw_networkx_nodes(SGplot, pos, nodelist=GENES_only_NB, node_size=150, node_color='#007EC3', alpha=1)
nx.draw_networkx_edges(SGplot, pos, edgelist=MAL_GO_NB_edges, width=2.0)#draw thick edges for Mal GO annotations
scale_factor = 1.05
posl = copy.deepcopy(pos)
for node in posl:
posl[node] = scale_factor * pos[node]
#Add labels to the nodes you require
lab = nx.draw_networkx_labels(SGplot, pos=posl, labels=labels, font_size=8,font_weight='bold')
lab = nx.draw_networkx_labels(SGplot, pos=pos, labels=labels_MAL_GO_NB, font_size=10,
font_color='white',font_weight='bold')
filename = 'subnetwork_circular'
plt.savefig(os.path.join(path, filename + '.pdf'),bbox_inches="tight",transparent=True)
plt.savefig(os.path.join(path, filename + '.png'),bbox_inches="tight",transparent=True)
from genewalk.
Hi @izu0421 ,
Thanks for your interest. You are right the GeneWalk Network is saved in multi_graph.pkl as a networkx.MultiGraph object. In general, the graph is too large to sensibly visualize as a whole given that it consists of over 40k nodes. Even if you only visualize all the genes and their interactions it will likely still just end up as a big hairball. I can give you a code snippet to visualize GWN subgraphs around certain genes of interest, similar to figure 3B of our publication. Let me know if that is of interest to you. If you do want to visualize the whole network, you could consider visualizing the vector representations of all the nodes using UMAP in a 2d embedding. Hope this helps.
Robert
from genewalk.
Hi @ri23,
Thanks a lot! Much appreciated.
Yizhou
from genewalk.
Related Issues (20)
- ensembl_id HOT 1
- ML HOT 1
- rdflib=4.2.2 and python 3 version conflict HOT 2
- Rat genome HOT 1
- Installation failed. HOT 6
- network source file HOT 4
- Install issue HOT 8
- AttributeError: type object 'object' has no attribute 'dtype' HOT 2
- Criteria for barplot output HOT 8
- IndexError: list index out of range HOT 2
- No regulators identified? HOT 4
- INDRA script generation HOT 2
- Trouble Using GeneWalk HOT 2
- GO Terms HOT 1
- Error when calling word2vec: unexpected keyword argument 'size' HOT 2
- Mouse ids are not working with genewalk? HOT 1
- Code for regulator/moonlighter plots HOT 4
- GO annotations file comment rows have changed HOT 1
- AttributeError: module 'typing' has no attribute 'NoReturn HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genewalk.