import sys
import argparse
import re
-#import matplotlib_venn
+from matplotlib_venn import venn2
+from matplotlib import pyplot as plt
#----------------------------------------------------------------------------------------------------------------------
# globals
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) :
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
#----------------------------------------------------------------------------------------------------------------------
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
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
#----------------------------------------------------------------------------------------------------------------------