changeset 33:9337c80d6672 draft

Uploaded
author mzeidler
date Wed, 25 Sep 2013 06:45:20 -0400
parents cbd4d7e3f155
children d50aaf4471c1
files vhom_regionplot.py
diffstat 1 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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( '</body></html>' )
     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