comparison fsd.py @ 21:89ddbe5ae2aa draft

planemo upload for repository https://github.com/monikaheinzl/duplexanalysis_galaxy/tree/master/tools/fsd commit b8a2f7b7615b2bcd3b602027af31f4e677da94f6-dirty
author mheinzl
date Wed, 08 May 2019 07:21:18 -0400
parents 64f0362c974e
children 5e650e66e058
comparison
equal deleted inserted replaced
20:64f0362c974e 21:89ddbe5ae2aa
76 list_to_plot = [] 76 list_to_plot = []
77 label = [] 77 label = []
78 data_array_list = [] 78 data_array_list = []
79 list_to_plot_original = [] 79 list_to_plot_original = []
80 colors = [] 80 colors = []
81 bins = numpy.arange(1, 22) 81 bins = numpy.arange(1, 22)
82
83 with open(title_file, "w") as output_file, PdfPages(title_file2) as pdf: 82 with open(title_file, "w") as output_file, PdfPages(title_file2) as pdf:
84 fig = plt.figure() 83 fig = plt.figure()
85 fig.subplots_adjust(left=0.12, right=0.97, bottom=0.23, top=0.94, hspace=0) 84 fig.subplots_adjust(left=0.12, right=0.97, bottom=0.23, top=0.94, hspace=0)
86 fig2 = plt.figure() 85 fig2 = plt.figure()
87 fig2.subplots_adjust(left=0.12, right=0.97, bottom=0.23, top=0.94, hspace=0) 86 fig2.subplots_adjust(left=0.12, right=0.97, bottom=0.23, top=0.94, hspace=0)
281 ticks1 = map(str, ticks) 280 ticks1 = map(str, ticks)
282 if maximumX > 20: 281 if maximumX > 20:
283 ticks1[len(ticks1) - 1] = ">20" 282 ticks1[len(ticks1) - 1] = ">20"
284 283
285 if to_plot[l] == "Relative frequencies": 284 if to_plot[l] == "Relative frequencies":
286 counts_rel = ax.hist(list_to_plot2, bins=numpy.arange(minimumX, maximumX + 2), stacked=False, edgecolor="black", linewidth=1, label=label, align="left", alpha=1, rwidth=0.8, normed=True) 285 counts_rel = ax.hist(list_to_plot2, bins=numpy.arange(minimumX, maximumX + 2), stacked=False, edgecolor="black", linewidth=1, label=label, align="left", alpha=0.8, rwidth=0.8, normed=True)
287 else: 286 else:
288 counts = ax.hist(list_to_plot2, bins=numpy.arange(minimumX, maximumX + 2), stacked=False, edgecolor="black", linewidth=1, label=label, align="left", alpha=1, rwidth=0.8) 287 counts = ax.hist(list_to_plot2, bins=numpy.arange(minimumX, maximumX + 2), stacked=False, edgecolor="black", linewidth=1, label=label, align="left", alpha=0.8, rwidth=0.8)
289 ax.legend(loc='upper right', fontsize=14, frameon=True, bbox_to_anchor=(0.9, 1)) 288 ax.legend(loc='upper right', fontsize=14, frameon=True, bbox_to_anchor=(0.9, 1))
290 289
291 ax.set_xticks(numpy.array(ticks)) 290 ax.set_xticks(numpy.array(ticks))
292 ax.set_xticklabels(ticks1) 291 ax.set_xticklabels(ticks1)
293 292
314 313
315 for i in range(len(list_to_plot2)): 314 for i in range(len(list_to_plot2)):
316 unique, c = numpy.unique(list_to_plot2[i], return_counts=True) 315 unique, c = numpy.unique(list_to_plot2[i], return_counts=True)
317 new_c = [] 316 new_c = []
318 new_unique = [] 317 new_unique = []
319
320 for t in ticks: 318 for t in ticks:
321 if t not in unique: 319 if t not in unique:
322 new_c.append(0) # add zero count of not occuring 320 new_c.append(0) # add zero count of not occuring
323 new_unique.append(t) 321 new_unique.append(t)
324 else: 322 else:
325 c_idx = numpy.where(t == unique)[0] 323 c_idx = numpy.where(t == unique)[0]
326 new_c.append(c[c_idx]) 324 new_c.append(c[c_idx])
327 new_unique.append(unique[c_idx]) 325 new_unique.append(unique[c_idx])
328 print(new_unique)
329 print(new_c)
330 y = numpy.array(new_unique) * numpy.array(new_c) 326 y = numpy.array(new_unique) * numpy.array(new_c)
331 if len([list_to_plot_original > 20]) > 0: 327 if len([list_to_plot_original > 20]) > 0:
332 y[len(y) - 1] = sum(list_to_plot_original[i][list_to_plot_original[i] > 20]) 328 y[len(y) - 1] = sum(list_to_plot_original[i][list_to_plot_original[i] > 20])
333 reads.append(y) 329 reads.append(y)
334 reads_rel.append(list(numpy.float_(y)) / sum(y)) 330 reads_rel.append(list(numpy.float_(y)) / sum(y))
336 x = list(numpy.arange(numpy.amin(unique), numpy.amax(unique) + 1).astype(float)) 332 x = list(numpy.arange(numpy.amin(unique), numpy.amax(unique) + 1).astype(float))
337 x = [xi + barWidth for xi in x] 333 x = [xi + barWidth for xi in x]
338 334
339 if to_plot[l] == "Relative frequencies": 335 if to_plot[l] == "Relative frequencies":
340 counts2_rel = ax.bar(x, list(numpy.float_(y)) / sum(y), align="edge", width=1./(len(list_to_plot) + 1), 336 counts2_rel = ax.bar(x, list(numpy.float_(y)) / sum(y), align="edge", width=1./(len(list_to_plot) + 1),
341 edgecolor="black", label=label[i], alpha=1, linewidth=1, color=colors[i]) 337 edgecolor="black", label=label[i], alpha=0.8, linewidth=1, color=colors[i])
342 else: 338 else:
343 counts2 = ax.bar(x, y, align="edge", width=1./len(list_to_plot), edgecolor="black", label=label[i], 339 counts2 = ax.bar(x, y, align="edge", width=1./(len(list_to_plot) + 1), edgecolor="black", label=label[i],
344 alpha=1, linewidth=1, color=colors[i]) 340 alpha=0.8, linewidth=1, color=colors[i])
345 if i == len(list_to_plot2): 341 if i == len(list_to_plot2):
346 barWidth += 1. / (len(list_to_plot) + 1) + 1. / (len(list_to_plot) + 1) 342 barWidth += 1. / (len(list_to_plot) + 1) + 1. / (len(list_to_plot) + 1)
347 else: 343 else:
348 barWidth += 1. / (len(list_to_plot) + 1) 344 barWidth += 1. / (len(list_to_plot) + 1)
349 345