annotate tools/venn_list/venn_list.py @ 11:679b6323db03 draft

v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
author peterjc
date Wed, 29 May 2019 04:45:19 -0400
parents 20d347feb882
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
1 #!/usr/bin/env python
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
2
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
3 """
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
4 Plot up to 3-way Venn Diagram.
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
5
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
6 It uses the Python libraries matplotlib and matplotlib_venn.
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
7
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
8 This script is copyright 2010-2017 by Peter Cock, The James Hutton Institute
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
9 (formerly SCRI), UK. All rights reserved.
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
10
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
11 See accompanying text file for licence details (MIT License).
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
12 """
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
13
10
20d347feb882 v0.0.11 (fixed script): Python 3 compatible print; capture script version
peterjc
parents: 8
diff changeset
14 from __future__ import print_function
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
15
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
16 import sys
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
17 from shutil import move
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
18
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
19 if "-v" in sys.argv or "--version" in sys.argv:
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
20 print("v0.1.0")
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
21 sys.exit(0)
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
22
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
23 try:
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
24 import matplotlib
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
25 except ImportError:
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
26 sys.exit("Requires the Python library matplotlib")
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
27
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
28 matplotlib.use("Agg")
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
29 from matplotlib import pyplot as plt
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
30
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
31 if len(sys.argv) - 1 not in [7, 10, 13]:
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
32 sys.exit(
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
33 "Expected 7, 10 or 13 arguments (for 1, 2 or 3 sets), not %i"
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
34 % (len(sys.argv) - 1)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
35 )
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
36
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
37 all_file, all_type, all_label = sys.argv[1:4]
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
38 set_data = []
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
39 if len(sys.argv) - 1 >= 7:
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
40 set_data.append(tuple(sys.argv[4:7]))
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
41 if len(sys.argv) - 1 >= 10:
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
42 set_data.append(tuple(sys.argv[7:10]))
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
43 if len(sys.argv) - 1 >= 13:
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
44 set_data.append(tuple(sys.argv[10:13]))
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
45 pdf_file = sys.argv[-1]
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
46 n = len(set_data)
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
47 print("Doing %i-way Venn Diagram" % n)
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
48
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
49
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
50 def load_ids(filename, filetype):
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
51 """Load ids from files."""
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
52 if filetype == "tabular":
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
53 for line in open(filename):
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
54 line = line.rstrip("\n")
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
55 if line and not line.startswith("#"):
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
56 yield line.split("\t", 1)[0]
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
57 elif filetype == "fasta":
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
58 for line in open(filename):
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
59 if line.startswith(">"):
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
60 yield line[1:].rstrip("\n").split(None, 1)[0]
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
61 elif filetype.startswith("fastq"):
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
62 # Use the Galaxy library not Biopython to cope with CS
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
63 from galaxy_utils.sequence.fastq import fastqReader
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
64
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
65 handle = open(filename, "rU")
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
66 for record in fastqReader(handle):
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
67 # The [1:] is because the fastaReader leaves the @ on the identifer.
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
68 yield record.identifier.split()[0][1:]
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
69 handle.close()
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
70 elif filetype == "sff":
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
71 try:
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
72 from Bio.SeqIO import index
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
73 except ImportError:
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
74 sys.exit("Require Biopython 1.54 or later (to read SFF files)")
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
75 # This will read the SFF index block if present (very fast)
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
76 for this_name in index(filename, "sff"):
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
77 yield this_name
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
78 else:
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
79 sys.exit("Unexpected file type %s" % filetype)
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
80
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
81
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
82 def load_ids_whitelist(filename, filetype, whitelist):
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
83 """Check if ids are in whitelist."""
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
84 for single_name in load_ids(filename, filetype):
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
85 if single_name in whitelist:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
86 yield single_name
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
87 else:
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
88 sys.exit(
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
89 "Unexpected ID %s in %s file %s" % (single_name, filetype, filename)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
90 )
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
91
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
92
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
93 if all_file in ["", "-", '""', '"-"']:
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
94 # Load without white list
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
95 sets = [set(load_ids(f, t)) for (f, t, c) in set_data]
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
96 # Take union
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
97 all_ids = set()
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
98 for s in sets:
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
99 all_ids.update(s)
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
100 print("Inferred total of %i IDs" % len(all_ids))
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
101 else:
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
102 all_ids = set(load_ids(all_file, all_type))
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
103 print("Total of %i IDs" % len(all_ids))
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
104 sets = [set(load_ids_whitelist(f, t, all_ids)) for (f, t, c) in set_data]
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
105
6
ea68a1a4c1d9 v0.0.10 explicit galaxy_sequence_utils dependency etc
peterjc
parents: 4
diff changeset
106 for s, (f, t, c) in zip(sets, set_data):
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
107 print("%i in %s" % (len(s), c))
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
108
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
109 names = [one_name for one_file, one_type, one_name in set_data]
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
110 lengths = [len(one_set) for one_set in sets]
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
111
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
112 if len(sets) == 3:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
113 try:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
114 from matplotlib_venn import venn3_unweighted
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
115 except ImportError:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
116 sys.exit("Requires the Python library matplotlib_venn")
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
117 venn3_unweighted(
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
118 sets,
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
119 [
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
120 "{} (Total {})".format(name, length)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
121 for (name, length) in zip(names, lengths)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
122 ],
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
123 )
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
124
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
125 if len(sets) == 2:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
126 try:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
127 from matplotlib_venn import venn2_unweighted
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
128 except ImportError:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
129 sys.exit("Requires the Python library matplotlib_venn")
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
130 venn2_unweighted(
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
131 sets,
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
132 [
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
133 "{} (Total {})".format(name, length)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
134 for (name, length) in zip(names, lengths)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
135 ],
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
136 )
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
137
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
138 # not sure what I am doing here,
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
139 # matplotlib_venn does not want to create a single Venn circle
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
140 # stick to the old behavior (rpy and Limma) as much as possible
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
141 if len(sets) == 1:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
142 try:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
143 from matplotlib_venn import venn2
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
144 except ImportError:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
145 sys.exit("Requires the Python library matplotlib_venn")
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
146 venn2((sets[0], set()), [set_data[0][2], ""])
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
147
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
148 plt.title(all_label)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
149 plt.savefig(pdf_file + ".pdf")
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
150
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
151 # Format "dat" is not supported.
4
991342eca214 Uploaded v0.0.8a, declare Biopython dependency via Tool Shed
peterjc
parents:
diff changeset
152 try:
11
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
153 move(pdf_file + ".pdf", pdf_file)
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
154 except (OSError, IOError) as error:
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
155 sys.exit("Fail to rename file {}".format(str(error)))
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
156
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
157 plt.close()
679b6323db03 v0.1.0 now using matplotlib_venn instead of limma R package via rpy. Contribution from Frederic Sapet.
peterjc
parents: 10
diff changeset
158
8
ee50d9ef9d69 v0.0.11 Python 3 compatible print; capture script version
peterjc
parents: 6
diff changeset
159 print("Done")