Mercurial > repos > peterjc > venn_list
diff tools/venn_list/venn_list.py @ 8:ee50d9ef9d69 draft
v0.0.11 Python 3 compatible print; capture script version
author | peterjc |
---|---|
date | Thu, 11 May 2017 06:21:20 -0400 |
parents | ea68a1a4c1d9 |
children | 20d347feb882 |
line wrap: on
line diff
--- a/tools/venn_list/venn_list.py Thu Feb 02 11:45:35 2017 -0500 +++ b/tools/venn_list/venn_list.py Thu May 11 06:21:20 2017 -0400 @@ -1,16 +1,20 @@ #!/usr/bin/env python """Plot up to 3-way Venn Diagram using R limma vennDiagram (via rpy) -This script is copyright 2010 by Peter Cock, The James Hutton Institute +This script is copyright 2010-2017 by Peter Cock, The James Hutton Institute (formerly SCRI), UK. All rights reserved. -See accompanying text file for licence details (MIT/BSD style). -This is version 0.0.8 of the script. +See accompanying text file for licence details (MIT License). """ +from __futute__ import print_function import sys +if "-v" in sys.argv or "--version" in sys.argv: + print("v0.0.11") + sys.exit(0) + try: import rpy except ImportError: @@ -37,7 +41,7 @@ set_data.append(tuple(sys.argv[10:13])) pdf_file = sys.argv[-1] n = len(set_data) -print "Doing %i-way Venn Diagram" % n +print("Doing %i-way Venn Diagram" % n) def load_ids(filename, filetype): @@ -77,6 +81,7 @@ else: sys.exit("Unexpected ID %s in %s file %s" % (name, filetype, filename)) + if all_file in ["", "-", '""', '"-"']: # Load without white list sets = [set(load_ids(f, t)) for (f, t, c) in set_data] @@ -84,14 +89,14 @@ all_ids = set() for s in sets: all_ids.update(s) - print "Inferred total of %i IDs" % len(all_ids) + print("Inferred total of %i IDs" % len(all_ids)) else: all_ids = set(load_ids(all_file, all_type)) - print "Total of %i IDs" % len(all_ids) + print("Total of %i IDs" % len(all_ids)) sets = [set(load_ids_whitelist(f, t, all_ids)) for (f, t, c) in set_data] for s, (f, t, c) in zip(sets, set_data): - print "%i in %s" % (len(s), c) + print("%i in %s" % (len(s), c)) # Now call R library to draw simple Venn diagram try: @@ -102,7 +107,7 @@ rpy.r('vc <- vennCounts(groups)') # Populate the 2^n classes with real counts # Don't make any assumptions about the class order - # print rpy.r('vc') + # print(rpy.r('vc')) for index, row in enumerate(rpy.r('vc[,%s]' % cols)): if isinstance(row, int) or isinstance(row, float): # Hack for rpy being too clever for single element row @@ -114,7 +119,7 @@ else: names = names.difference(s) rpy.r('vc[%i,"Counts"] <- %i' % (index + 1, len(names))) - # print rpy.r('vc') + # print(rpy.r('vc')) if n == 1: # Single circle, don't need to add (Total XXX) line names = [c for (t, f, c) in set_data] @@ -131,4 +136,4 @@ except Exception, exc: sys.exit("%s" % str(exc)) rpy.r.quit(save="no") -print "Done" +print("Done")