def distancePlot(distance_to_start_count,distance_to_stop_count,pre_psite_dict,length_counter,outname):
length_set = set(distance_to_start_count.keys() + distance_to_stop_count.keys())
total_reads = sum(length_counter.values())
with PdfPages(outname + ".pdf") as pdf:
x = np.arange(-50,51,dtype=int)
colors = np.tile(["b","g","r"], 34)
for l in sorted(length_set):
#plt.figure(figsize=(5,3))
if l not in pre_psite_dict:
xticks = [-40,-20,0,20,40]
else:
xticks = sorted([-40,-20,0,20,40] + pre_psite_dict[l] -50)
perct = '{:.2%}'.format(length_counter[l] / total_reads)
fig,(ax1,ax2) = plt.subplots(nrows=2,ncols=1)
y1 = distance_to_start_count[l]
y2 = distance_to_stop_count[l]
ax1.vlines(x,ymin=np.zeros(101),ymax=y1,colors=colors[:-1])
ax1.tick_params(axis='x',which="both",top="off",direction='out')
ax1.set_xticks(xticks)
ax1.set_xlim((-50,50))
ax1.set_xlabel("Distance (nt)")
ax1.set_ylabel("Alignments")
ax1.set_title("({} nt reads,proportion:{})".format(l,perct) + "\n Distance 5'- start codons")
ax2.vlines(x,ymin=np.zeros(101),ymax=y2,colors=colors[:-1])
ax2.tick_params(axis='x',which="both",top="off",direction='out')
ax2.set_xticks(xticks)
ax2.set_xlim((-50,50))
ax2.set_xlabel("Distance (nt)")
ax2.set_ylabel("Alignments")
ax2.set_title("Distance 5'- stop codons")
fig.tight_layout()
pdf.savefig(fig)
plt.close()
return None
评论列表
文章目录