annotate venn_diagram.py @ 7:98b7912a9ceb draft

planemo upload commit 89cd1b5f2ca7b135abfe2d9ed18bf2478a59e099-dirty
author proteore
date Tue, 05 Mar 2019 11:25:31 -0500
parents d1fd04dcb13a
children bca31ac678f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
1 #!/usr/bin/env python2.7
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
2
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
3 import os
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
4 import sys
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
5 import json
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
6 import operator
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
7 import argparse
6
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
8 import re, csv
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
9 from itertools import combinations
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
10
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
11 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
12
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
13 ##################################################################################################################################################
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
14 # FUNCTIONS
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
15 ##################################################################################################################################################
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
16
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
17 def isnumber(format, n):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
18 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
19 Check if an element is integer or float
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
20 """
3
145f347dc0e1 planemo upload commit b5beb4f7f3c60838b88a4cc32dfcb94c399d20ce-dirty
proteore
parents: 0
diff changeset
21 float_format = re.compile(r"^[-]?[1-9][0-9]*.?[0-9]+$")
145f347dc0e1 planemo upload commit b5beb4f7f3c60838b88a4cc32dfcb94c399d20ce-dirty
proteore
parents: 0
diff changeset
22 int_format = re.compile(r"^[-]?[1-9][0-9]*$")
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
23 test = ""
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
24 if format == "int":
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
25 test = re.match(int_format, n)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
26 elif format == "float":
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
27 test = re.match(float_format, n)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
28 if test:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
29 return True
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
30 else:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
31 return False
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
32
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
33 def input_to_dict(inputs):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
34 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
35 Parse input and return a dictionary of name and data of each lists/files
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
36 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
37 comp_dict = {}
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
38 title_dict = {}
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
39 c = ["A", "B", "C", "D", "E", "F"]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
40 for i in range(len(inputs)):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
41 input_file = inputs[i][0]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
42 name = inputs[i][1]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
43 input_type = inputs[i][2]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
44 title = c[i]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
45 title_dict[title] = name
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
46 ids = set()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
47 if input_type == "file":
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
48 header = inputs[i][3]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
49 ncol = inputs[i][4]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
50 file_content = open(input_file, "r").readlines()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
51
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
52 # Check if column number is in right form
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
53 if isnumber("int", ncol.replace("c", "")):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
54 if header == "true":
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
55 file_content = [x.strip() for x in [line.split("\t")[int(ncol.replace("c", ""))-1].split(";")[0] for line in file_content[1:]]] # take only first IDs
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
56 else:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
57 file_content = [x.strip() for x in [line.split("\t")[int(ncol.replace("c", ""))-1].split(";")[0] for line in file_content]] # take only first IDs
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
58 else:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
59 raise ValueError("Please fill in the right format of column number")
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
60 else:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
61 ids = set()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
62 file_content = inputs[i][0].split()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
63
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
64 ids.update(file_content)
6
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
65 if 'NA' in ids : ids.remove('NA')
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
66 comp_dict[title] = ids
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
67
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
68 return comp_dict, title_dict
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
69
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
70 def intersect(comp_dict):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
71 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
72 Calculate the intersections of input
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
73 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
74 names = set(comp_dict)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
75 for i in range(1, len(comp_dict) + 1):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
76 for group in combinations(sorted(comp_dict), i):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
77 others = set()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
78 [others.add(name) for name in names if name not in group]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
79 difference = []
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
80 intersected = set.intersection(*(comp_dict[k] for k in group))
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
81 if len(others) > 0:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
82 difference = intersected.difference(set.union(*(comp_dict[k] for k in others)))
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
83 yield group, list(intersected), list(difference)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
84
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
85 def diagram(comp_dict, title_dict):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
86 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
87 Create json string for jvenn diagram plot
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
88 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
89 result = {}
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
90 result["name"] = {}
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
91 for k in comp_dict.keys():
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
92 result["name"][k] = title_dict[k]
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
93
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
94 result["data"] = {}
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
95 result["values"] = {}
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
96 for group, intersected, difference in intersect(comp_dict):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
97 if len(group) == 1:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
98 result["data"]["".join(group)] = difference
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
99 result["values"]["".join(group)] = len(difference)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
100 elif len(group) > 1 and len(group) < len(comp_dict):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
101 result["data"]["".join(group)] = difference
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
102 result["values"]["".join(group)] = len(difference)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
103 elif len(group) == len(comp_dict):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
104 result["data"]["".join(group)] = intersected
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
105 result["values"]["".join(group)] = len(intersected)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
106
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
107 return result
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
108
6
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
109 #Write intersections of input to text output file
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
110 def write_text_venn(json_result):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
111 lines = []
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
112 result = dict((k, v) for k, v in json_result["data"].iteritems() if v != [])
6
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
113 for key in result :
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
114 if 'NA' in result[key] : result[key].remove("NA")
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
115 list_names = dict((k, v) for k, v in json_result["name"].iteritems() if v != [])
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
116 nb_lines_max = max(len(v) for v in result.values())
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
117
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
118 #get list names associated to each column
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
119 column_dict = {}
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
120 for key in result :
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
121 if key in list_names :
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
122 column_dict[key] = list_names[key]
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
123 else :
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
124 keys= list(key)
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
125 column_dict[key] = "_".join([list_names[k] for k in keys])
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
126
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
127 #construct tsv
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
128 for key in result :
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
129 line = [column_dict[key]]
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
130 line.extend(result[key])
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
131 if len(line) < nb_lines_max :
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
132 line.extend(['NA']*(nb_lines_max-len(line)))
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
133 lines.append(line)
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
134 #transpose tsv
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
135 lines=zip(*lines)
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
136
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
137 with open("venn_diagram_text_output.tsv", "w") as output:
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
138 tsv_output = csv.writer(output, delimiter='\t')
d1fd04dcb13a planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents: 3
diff changeset
139 tsv_output.writerows(lines)
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
140
3
145f347dc0e1 planemo upload commit b5beb4f7f3c60838b88a4cc32dfcb94c399d20ce-dirty
proteore
parents: 0
diff changeset
141 def write_summary(summary_file, inputs):
0
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
142 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
143 Paste json string into template file
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
144 """
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
145 a, b = input_to_dict(inputs)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
146 data = diagram(a, b)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
147 write_text_venn(data)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
148
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
149 to_replace = {
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
150 "series": [data],
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
151 "displayStat": "true",
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
152 "displaySwitch": "true",
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
153 "shortNumber": "true",
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
154 }
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
155
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
156 FH_summary_tpl = open(os.path.join(CURRENT_DIR, "jvenn_template.html"))
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
157 FH_summary_out = open(summary_file, "w" )
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
158 for line in FH_summary_tpl:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
159 if "###JVENN_DATA###" in line:
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
160 line = line.replace("###JVENN_DATA###", json.dumps(to_replace))
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
161 FH_summary_out.write(line)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
162
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
163 FH_summary_out.close()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
164 FH_summary_tpl.close()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
165
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
166 def process(args):
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
167 write_summary(args.summary, args.input)
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
168
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
169
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
170 ##################################################################################################################################################
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
171 # MAIN
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
172 ##################################################################################################################################################
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
173 if __name__ == '__main__':
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
174 # Parse parameters
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
175 parser = argparse.ArgumentParser(description='Filters an abundance file')
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
176 group_input = parser.add_argument_group( 'Inputs' )
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
177 group_input.add_argument('--input', nargs="+", action="append", required=True, help="The input tabular file.")
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
178 group_output = parser.add_argument_group( 'Outputs' )
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
179 group_output.add_argument('--summary', default="summary.html", help="The HTML file containing the graphs. [Default: %(default)s]")
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
180 args = parser.parse_args()
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
181
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
182 # Process
9d4f20618ab4 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
183 process( args )