Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this user
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
proost
/
LSTrAP
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
4
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
7944f8b
cluster
docs
helper
data
parsers
fasta_to_gtf.py
get_sra_ip.py
htseq_count_stats.py
matrix_heatmap.py
pca_powerlaw.py
plot_network.py
sra_to_fastq.py
tophat_stats.py
pipeline
scripts
utils
.gitignore
LICENSE.md
README.md
config.template.ini
data.template.ini
run.py
Breadcrumbs
LSTrAP
/
helper
/
plot_network.py
Blame
Blame
Latest commit
History
History
109 lines (74 loc) · 3.1 KB
Breadcrumbs
LSTrAP
/
helper
/
plot_network.py
Top
File metadata and controls
Code
Blame
109 lines (74 loc) · 3.1 KB
Raw
import argparse import sys from collections import defaultdict import networkx as nx import matplotlib.pyplot as plt DEBUG = True def plot_network(filename, gene, cutoff=0.7): """ Function to load a co-expression network from LSTrAP and plot the neighborhood for one gene. :param filename: PCC output to load :param gene: The gene whose neighborhood to visualize :param cutoff: PCC cutoff to use, default 0.7 """ print("Loading file %s ..." % filename, end='') network_full = defaultdict(dict) query = None # this will store the query gene with the right case once found with open(filename, "r") as fin: for i, line in enumerate(fin, start=1): try: g, network = line.strip().split(':') targets = network.strip().split() target_list = {} found_query = False if g.lower() == gene.lower(): found_query = True query = g for t in targets: target, score = t.strip(')').split('(') score = float(score) if score >= cutoff: target_list[target] = score if target.lower() == gene.lower(): found_query = True if found_query: network_full[g] = target_list except Exception as e: print("\nAn error occurred while reading line %d!" % i, file=sys.stderr) print(line, file=sys.stderr) print("Done!") print("Plotting graph for %s with PCC cutoff of %.2f" % (query, cutoff)) if DEBUG: print(network_full[query]) print(type(network_full[query])) valid_genes = [query] for k, _ in network_full[query].items(): valid_genes.append(k) if DEBUG: print(valid_genes) graph = nx.Graph() graph.add_nodes_from(valid_genes) for g, targets in network_full.items(): for target, score in targets.items(): if g in valid_genes and target in valid_genes: graph.add_edge(g, target, weight=score) # plot graph pos = nx.spring_layout(graph) nx.draw_networkx_nodes(graph, pos, node_color='#42bcf4', node_size=500, alpha=0.8) nx.draw_networkx_edges(graph, pos, width=3, alpha=0.5, edge_color='0.5') nx.draw_networkx_labels(graph, pos, {k: k for k in valid_genes}, font_size=16, alpha=0.5) plt.axis('off') plt.show() if __name__ == "__main__": parser = argparse.ArgumentParser(prog="./plot_network.py") parser.add_argument('filename', help='PCC output from LSTrAP') parser.add_argument('gene', help='Gene for which the networks will be drawn') parser.add_argument('--cutoff', help='PCC cutoff to use (default = 0.7)', default=0.7, type=float) parser.set_defaults(show_labels=True) # Parse arguments and start script args = parser.parse_args() plot_network(args.filename, args.gene, cutoff=args.cutoff)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
You can’t perform that action at this time.