Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
added Venn generator
authorpreecej <preecej@localhost>
Fri, 11 Apr 2014 21:37:35 +0000 (21:37 +0000)
committerpreecej <preecej@localhost>
Fri, 11 Apr 2014 21:37:35 +0000 (21:37 +0000)
svn path=/; revision=571

Personnel/preecej/python_singletons/incomparanoid.py

index a573cc77b51039a3e704d2b31eaa94557033e95a..4ba98646267865a8cac0b978a2de43aa7518ff23 100755 (executable)
@@ -10,7 +10,8 @@ import os
 import sys
 import argparse
 import re
-#import matplotlib_venn
+from matplotlib_venn import venn2
+from matplotlib import pyplot as plt
 
 #----------------------------------------------------------------------------------------------------------------------
 # globals
@@ -257,6 +258,7 @@ def compare_maps(dict_cmp_map, dict_inp_map, comparison_file_path, compara_outpu
         CMP_OUT_FILE.close()
         CMP_FLAT_OUT_FILE.close()
 
+    return [set_inp_ref_loci, set_cmp_ref_loci]
 
 #----------------------------------------------------------------------------------------------------------------------
 def write_reactome_files(dict_map, reactome_gene_protein_path, reactome_projection_path, projection_prefix) :
@@ -278,6 +280,50 @@ def write_reactome_files(dict_map, reactome_gene_protein_path, reactome_projecti
     REACTOME_GENE_PROTEIN_OUT_FILE.close()
     REACTOME_PROJECTION_OUT_FILE.close()
 
+
+#----------------------------------------------------------------------------------------------------------------------
+def generate_venn(venn_data) :
+#----------------------------------------------------------------------------------------------------------------------
+    """build and display Venn diagrams representing reference loci overlap"""
+
+    intersection_ref_loci = len(venn_data[0] & venn_data[1])
+    union_ref_loci = len(venn_data[0] | venn_data[1])
+    inp_exc_ref_loci = len(venn_data[0] - venn_data[1])
+    cmp_exc_ref_loci = len(venn_data[1] - venn_data[0])
+
+    v = venn2(venn_data, ('Inparanoid', 'Compara'))
+    
+    v.get_patch_by_id('10').set_alpha(0.5)
+    v.get_patch_by_id('10').set_color('red')
+    
+    v.get_patch_by_id('01').set_alpha(0.5)
+    v.get_patch_by_id('01').set_color('yellow')
+    
+    v.get_patch_by_id('11').set_alpha(0.75)
+    v.get_patch_by_id('11').set_color('orange')
+    
+    v.get_label_by_id('10').set_text(str(inp_exc_ref_loci))
+    v.get_label_by_id('01').set_text(str(cmp_exc_ref_loci))
+    v.get_label_by_id('11').set_text(str(intersection_ref_loci))
+    
+    v.get_label_by_id('A').set_text('')
+    v.get_label_by_id('B').set_text('')
+    
+    #v.get_label_by_id('A').set_size(20)
+    #v.get_label_by_id('B').set_size(20)
+    
+    plt.annotate('Inparanoid', xy = v.get_label_by_id('10').get_position(), xytext = (-30,-70), size = 'x-large',
+                ha = 'center', textcoords = 'offset points', bbox = dict(boxstyle = 'round, pad=0.5', fc = '#cc88ff', alpha = 0.3))
+     
+    plt.annotate('Compara', xy = v.get_label_by_id('01').get_position(), xytext = (30,-70), size = 'x-large',
+                ha = 'center', textcoords = 'offset points', bbox = dict(boxstyle = 'round, pad = 0.5', fc = 'lime', alpha = 0.3))
+    
+    #plt.annotate('Reference Loci (' + str(union_ref_loci) + ' total)', xy = v.get_label_by_id('11').get_position(), xytext = (0,0), size = 'xx-large',
+     #           ha = 'center', textcoords = 'offset points', bbox = dict(boxstyle = 'round, pad=0.5', fc = 'black', alpha = 0.0))
+    
+    plt.show()
+
+
 #----------------------------------------------------------------------------------------------------------------------
 # main
 #----------------------------------------------------------------------------------------------------------------------
@@ -303,6 +349,7 @@ parser.add_argument('-I', '--inparanoid_output_path', help='output file containi
 parser.add_argument('-g', '--generate_reactome_output', help='produce ortho_pair files required by Reactome projection inference script for specified projection source', choices=['ensembl', 'inparanoid'])
 parser.add_argument('-R', '--reactome_gene_protein_path', help='output file containing gene::protein mappings for Reactome projection inference') # e.g. 'zmay_gene_protein_mapping.txt'
 parser.add_argument('-P', '--reactome_projection_path', help='output file containing reference::projection protein mappings for Reactome inference') # e.g. 'osat_zmay_mapping.txt'
+parser.add_argument('-V', '--venn_diagram', help='generate Venn diagram', action='store_true')
 
 args = parser.parse_args()
 #print args
@@ -316,13 +363,17 @@ dict_inp_map = create_inp_map(args.inparanoid_input_path, dict_uniprot_map)
 dict_ens_map = create_ens_map(args.filtering_loci_path, args.ensembl_input_path, args.rap_map_path, args.reciprocal_id, dict_uniprot_map, 1 if args.confidence_high else 0)
 
 # generate stats and output them
-compare_maps(dict_ens_map, dict_inp_map, args.comparison_file_path, args.ensembl_output_path, args.inparanoid_output_path)
+venn_data = compare_maps(dict_ens_map, dict_inp_map, args.comparison_file_path, args.ensembl_output_path, args.inparanoid_output_path)
 
 if args.generate_reactome_output == 'ensembl' :
     write_reactome_files(dict_ens_map, args.reactome_gene_protein_path, args.reactome_projection_path, args.projection_prefix)
 if args.generate_reactome_output == 'inparanoid' :
     write_reactome_files(dict_inp_map, args.reactome_gene_protein_path, args.reactome_projection_path, args.projection_prefix)
 
+# NOTE: requires local matplotlib backend configuration
+if args.venn_diagram :
+    generate_venn(venn_data)
+
 #----------------------------------------------------------------------------------------------------------------------
 # end
 #----------------------------------------------------------------------------------------------------------------------