Ignacio Arroyo

PErsistencia para graficar lista

...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
3 import os 3 import os
4 import matplotlib.pyplot as plt 4 import matplotlib.pyplot as plt
5 from numpy import log10 5 from numpy import log10
6 - 6 +from pdb import set_trace as st
7 7
8 def analyze_pair(group_anlized, gropus_dir, rev, eigenvectors, fo): 8 def analyze_pair(group_anlized, gropus_dir, rev, eigenvectors, fo):
9 dic_part = {} 9 dic_part = {}
...@@ -72,6 +72,9 @@ def get_cmap(n, name='hsv'): ...@@ -72,6 +72,9 @@ def get_cmap(n, name='hsv'):
72 return plt.cm.get_cmap(name, n) 72 return plt.cm.get_cmap(name, n)
73 73
74 74
75 +plotting = False
76 +out_file = "persistence.csv"
77 +log = False
75 rev = 120 78 rev = 120
76 ff = "report_persistence_.csv" 79 ff = "report_persistence_.csv"
77 eigenvectors = "one-by-one/eigen_vectors/eigenBOs_120-eigens.txt" 80 eigenvectors = "one-by-one/eigen_vectors/eigenBOs_120-eigens.txt"
...@@ -95,10 +98,11 @@ for g in groups_analyzed: ...@@ -95,10 +98,11 @@ for g in groups_analyzed:
95 rev=rev, eigenvectors=eigenvectors, fo=ff) 98 rev=rev, eigenvectors=eigenvectors, fo=ff)
96 plots.append(partition) 99 plots.append(partition)
97 100
98 -fig = plt.figure() 101 +if plotting:
99 -ax1 = fig.add_subplot(111) 102 + fig = plt.figure()
103 + ax1 = fig.add_subplot(111)
100 104
101 -for i, p in enumerate(plots): 105 + for i, p in enumerate(plots):
102 if " ".join(p['tfs'][0]) == marked: 106 if " ".join(p['tfs'][0]) == marked:
103 width = 6 107 width = 6
104 mark = "D" 108 mark = "D"
...@@ -106,11 +110,25 @@ for i, p in enumerate(plots): ...@@ -106,11 +110,25 @@ for i, p in enumerate(plots):
106 width = 2 110 width = 2
107 mark = "" 111 mark = ""
108 112
109 - ax1.plot(p['part'], log10(p['n_tfs']), c=cmap(i), linewidth=width, 113 + ax1.plot(p['part'], log10(p['n_tfs']) if log else p['n_tfs'],
110 - marker=mark, label=" ".join(p['tfs'][0])) 114 + c=cmap(i), linewidth=width, marker=mark,
111 - 115 + label=" ".join(p['tfs'][0]))
112 -plt.legend(loc='upper right') 116 +
113 -plt.title("TF pair persistence through partitions of model resolution") 117 + plt.legend(loc='upper right')
114 -plt.xlabel("Partition") 118 + plt.title("TF pair persistence through partitions of model resolution")
115 -plt.ylabel("Number of TFs (log_10)") 119 + plt.xlabel("Partition")
116 -plt.show() 120 + plt.ylabel("Number of TFs (log_10)")
121 + plt.show()
122 +else:
123 + import csv
124 +
125 + lists = []
126 + pn = [' '] + list(plots[0]['part'])
127 + lists.append(pn)
128 + for p in plots:
129 + lists.append([p['tfs'][0]] + list(p['n_tfs']))
130 + lists.append([p['tfs'][0]] + list(p['tfs']))
131 +
132 + with open(out_file, 'w') as f:
133 + writer = csv.writer(f, delimiter='\t')
134 + writer.writerows(zip(*lists))
......
This diff could not be displayed because it is too large.