-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlap_plots.py
202 lines (164 loc) · 6.76 KB
/
overlap_plots.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# script for generating dsd-overlap plots and LaTex markup
# generates plots using routines from plotting.py, saves them,
# and generates the corresponding LaTeX markup
# LaTeX packages used: graphicx, float, subfig, geometry(margins set to .75in)
# run in command line with something like:
# python overlap_plots.py "PPIs and GO" "rat mouse" "tex.txt"
# these lines needed for working on ELF -- feel free to comment out
import sys
sys.path.append("/usr/lib64/python2.7/site-packages")
sys.path.append("/usr/lib/python2.7/site-packages/decorator-3.4.0-py2.7.egg")
sys.path.append("/usr/lib/python2.7/site-packages")
import plotting
import argparse
from matplotlib import pyplot as plt
import os
plt.rc('axes.formatter', use_mathtext=True)
parser = argparse.ArgumentParser()
# path to folder containing ppi and GO files
# organisms is a string of organisms we want to generate plots for, separated by spaces
parser.add_argument("directory")
parser.add_argument("organisms")
# file to write LaTeX code to
parser.add_argument("outfile")
options = parser.parse_args()
organisms = options.organisms.split(' ')
# ppi file extension
ppiExt = ".ppi"
# folder we want to put plots in
plotsDir = "plots"
# assume that any npy matrices will be in this folder
# if folder doesnt exist, create
npyDir = "NumPy files"
try:
os.makedirs(npyDir)
except OSError:
if not os.path.isdir(npyDir):
raise
# 3 plots currently: dsd against normalized overlap and pairs,
# pairs against summed overlap
# dsd against density
width = str(1.0/3)
# append, don't overwrite
with open(options.outfile, "a") as f:
figNum = 1
f.write("\\section{Plots based on (binary) function overlap}\n")
for organism in organisms:
# setup
print("generating plots for: " + organism)
infile = options.directory + "/" + organism + ppiExt
npyPath = npyDir + "/" + organism
f.write("\\subsection{" + organism + "}\n")
f.write("\\begin{figure}[H]\n\\caption{Plots based on original dataset}\n\\centerline{\n")
#################
# dsd : density #
#################
f.write("\\subfloat[DSD vs Density]{\n")
plt.figure(figNum)
plotting.dsd_density(infile, npyPath + "_dsd.npy", npyPath + "_overlap.npy")
# save plot
figFile = plotsDir + "/" + organism + "_dsd_density"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
########################
# dsd : pairs, overlap #
########################
f.write("\\subfloat[DSD vs Overlap, Pairs]{\n")
plt.figure(figNum)
plotting.dsd_overlap_pairs(infile, npyPath + "_dsd.npy", npyPath + "_overlap.npy")
# save plot
figFile = plotsDir + "/" + organism + "_dsd_overlap_pairs"
plt.savefig(figFile)
figFile += ".png"
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
##############################
# pairs : cumulative overlap #
##############################
f.write("\\subfloat[Pairs vs Cumulative Overlap]{\n")
plt.figure(figNum)
plotting.pairs_summed_overlap(infile, npyPath + "_dsd.npy", npyPath + "_overlap.npy")
# save plot
figFile = plotsDir + "/" + organism + "_pairs_overlap"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
f.write("}\n\\end{figure}\n\n")
# RANDOMIZE
f.write("\\begin{figure}[H]\n\\caption{Plots based on random permutation of label sets}\n\\centerline{\n")
#################
# dsd : density #
#################
f.write("\\subfloat[DSD vs Density]{\n")
plt.figure(figNum)
plotting.dsd_density(infile, npyPath + "_dsd.npy", npyPath + "_overlap.npy", randomize=True)
# save plot
figFile = plotsDir + "/" + organism + "_dsd_density_randomized"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
########################
# dsd : pairs, overlap #
########################
f.write("\\subfloat[DSD vs Overlap, Pairs]{\n")
plt.figure(figNum)
plotting.dsd_overlap_pairs(infile, npyPath + "_dsd.npy", npyPath + "_overlap.npy", randomize=True)
# save plot
figFile = plotsDir + "/" + organism + "_dsd_overlap_pairs_randomized"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
##############################
# pairs : cumulative overlap #
##############################
f.write("\\subfloat[Pairs vs Cumulative Overlap]{\n")
plt.figure(figNum)
plotting.pairs_summed_overlap(infile, npyPath + "_dsd.npy", npyPath + "_overlap.npy", randomize=True)
# save plot
figFile = plotsDir + "/" + organism + "_pairs_overlap_randomized"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
f.write("}\n\\end{figure}\n\n")
# SP COMPARISONS
f.write("\\begin{figure}[H]\n\\caption{Shortest-path distance (SPD) comparisons}\n\\centerline{\n")
#################
# spd : density #
#################
f.write("\\subfloat[SPD vs Density]{\n")
plt.figure(figNum)
plotting.dsd_density(infile, npyPath + "_spd.npy", npyPath + "_overlap.npy", sp=True)
# save plot
figFile = plotsDir + "/" + organism + "_spd_density"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
########################
# spd : pairs, overlap #
########################
f.write("\\subfloat[SPD vs Overlap, Pairs]{\n")
plt.figure(figNum)
plotting.dsd_overlap_pairs(infile, npyPath + "_spd.npy", npyPath + "_overlap.npy", sp=True)
# save plot
figFile = plotsDir + "/" + organism + "_spd_overlap_pairs"
figFile += ".png"
plt.savefig(figFile)
f.write("\\includegraphics[width=" + width + "\\textwidth]")
f.write("{" + figFile + "}\n}\n")
figNum += 1
f.write("}\n\\end{figure}\n\n")
print("done!")