# HG changeset patch # User mzeidler # Date 1380105920 14400 # Node ID 9337c80d667272e7eda48ecb9e535584e043befc # Parent cbd4d7e3f155badd289c4de548cb67d16de25a2f Uploaded diff -r cbd4d7e3f155 -r 9337c80d6672 vhom_regionplot.py --- a/vhom_regionplot.py Wed Sep 25 06:45:02 2013 -0400 +++ b/vhom_regionplot.py Wed Sep 25 06:45:20 2013 -0400 @@ -6,6 +6,8 @@ from matplotlib import colors from matplotlib import cm +from matplotlib.patches import Rectangle + from vhom import RegionRunner from argparse import ArgumentParser @@ -122,12 +124,7 @@ rval.append( '' ) with open(file,'w') as file: file.write("\n".join( rval )) - -def generatePyPlot(stat_dict,output_file): - pp = PdfPages(output_file) - fig = plt.figure() - - n_samples=len(stat_dict) +def transformDict(stat_dict): dict={} position={} dict_label={} @@ -152,18 +149,41 @@ dict_label[sample][i].append(values[0][0]) i+=1 j+=1 + return dict,position,dict_label + +def customeLegend(color_map): + legend_map=[[],[]] + for label in color_map: + box=Rectangle((0,0),1,1,color=color_map[label],fill=True) + legend_map[0].append(box) + legend_map[1].append(label) + plt.figlegend(legend_map[0],legend_map[1],loc=8,ncol=len(color_map)) + + + + +def generatePyPlot(stat_dict,output_file): + pp = PdfPages(output_file) + fig = plt.figure() + + n_samples=len(stat_dict) + dict,position,dict_label=transformDict(stat_dict) i=0 for sample in dict.iterkeys(): fig = plt.figure() + fig.subplots_adjust(bottom=0.25,hspace=0.5) + r,g,b,a=cm.hsv(1.*i/n_samples) color_map=rgb_color_variants(r,g,b) + for sub in [0,1]: plt.subplot(1,2,sub+1) bottom={} for level,values in dict[sample][sub].iteritems(): colors=[color_map[r] for r in dict_label[sample][level]] + if level==0: plt.bar(position[sample][level],values,bottom=0, width=0.8 ,color=colors) @@ -181,12 +201,14 @@ pos=[x+0.4 for x in range(len(stat_dict[sample]))] plt.xticks(pos, stat_dict[sample].keys(), rotation='vertical') if(sub==0): - plt.ylabel("Reads") + plt.ylabel("Cumulative reads assigned to family") else: - plt.ylabel("Basepairs") + plt.ylabel("Cumulative basepairs assigned to family") plt.xlabel("") fig.subplots_adjust(bottom=0.25,wspace=0.5) remove_border() + + customeLegend(color_map) plt.suptitle(sample) pp.savefig(fig) i+=1