-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
102 lines (84 loc) · 3.5 KB
/
plot.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
"""Summary
Provides the genPlot function to create and save feature plots.
"""
import matplotlib.pyplot as plt
import numpy as np
# Unclustered edition
def genPlotUn(result, fname, dirName, udStream, numFeatures, computeRatio):
"""Summary
Creates a plot of features using numpy and matplotlib for unclustered
Args:
result (list): The result to plot
fname (str): File name to be used as the plot title
dirName (str): Directory to output to within Outputs/
udStream (int): Distance between chromosomes.
numFeatures (int): The number of features (utilized in the plot title)
computeRatio (boolean): Whether to compute the ratio of two files (true) or plot a single file's coverage (false)
"""
print("Generating Unclustered plot")
y = np.array(result)
x = np.arange(len(y))
# plot
fig, ax = plt.subplots()
ax.set(xlim=(0, len(result)), xticks=np.arange(0, len(result)),
ylim=(0, max(result)), yticks=np.arange(0, max(result) + 10)) # result[1]
ax.set_xlabel('Distance')
if computeRatio:
ax.set_ylabel('log2-ratio')
else:
ax.set_ylabel('Coverage')
plt.figure(figsize=(15, 10))
plt.plot(x[(len(x) - udStream - 1):len(x) - 1],
y[(len(x) - udStream - 1):len(x) - 1], linestyle='-.', color='red')
plt.plot(x[0:udStream - 1], y[0:udStream - 1], linestyle='-.', color='red')
plt.plot(x[udStream - 1:(len(x) - udStream - 1)],
y[udStream - 1:(len(x) - udStream - 1)], color='black')
plt.title(fname)
plt.xlabel('Distance')
if computeRatio:
plt.ylabel('log2-ratio')
else:
plt.ylabel('Coverage')
path = fname + ".png" # in case of single plot
if dirName != None:
path = 'Outputs/' + dirName + '/' + path
plt.savefig(path, dpi=75)
def genPlot(result, fname, dirName, udStream, numFeatures, computeRatio):
"""Summary
Creates a plot of features using numpy and matplotlib.
Args:
result (list): The result to plot
fname (str): File name to be used as the plot title
dirName (str): Directory to output to within Outputs/
udStream (int): Distance between chromosomes.
numFeatures (int): The number of features (utilized in the plot title)
computeRatio (boolean): Whether to compute the ratio of two files (true) or plot a single file's coverage (false)
"""
print("Generating clustered plot")
y = np.array(result)
x = np.arange(len(y))
# plot
fig, ax = plt.subplots()
ax.set(xlim=(0, len(result)), xticks=np.arange(0, len(result)),
ylim=(0, max(result)), yticks=np.arange(0, max(result) + 10)) # result[1]
ax.set_xlabel('Distance')
if computeRatio:
ax.set_ylabel('log2-ratio')
else:
ax.set_ylabel('Coverage')
plt.figure(figsize=(15, 10))
plt.plot(x[(len(x) - udStream - 1):len(x) - 1],
y[(len(x) - udStream - 1):len(x) - 1], linestyle='-.', color='red')
plt.plot(x[0:udStream - 1], y[0:udStream - 1], linestyle='-.', color='red')
plt.plot(x[udStream - 1:(len(x) - udStream - 1)],
y[udStream - 1:(len(x) - udStream - 1)], color='black')
plt.title(fname + ' (' + str(numFeatures) + ')')
plt.xlabel('Distance')
if computeRatio:
plt.ylabel('log2-ratio')
else:
plt.ylabel('Coverage')
path = fname + ".png" # in case of single plot
if dirName != None:
path = 'Outputs/' + dirName + '/' + path
plt.savefig(path, dpi=75)