annotate clustergrammerIPG.py @ 0:fee56ee2f7ac draft

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
author azomics
date Fri, 31 Jul 2020 19:06:45 -0400
parents
children c90127c2a1ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
1 #!/usr/bin/env python
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
2
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
3 ######################################################################
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
4 # Copyright (c) 2016 Northrop Grumman.
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
5 # All rights reserved.
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
6 ######################################################################
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
7
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
8 # version 1.1 -- August 2017
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
9 # added checks for consistency between input files
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
10 # and upper limit on nb of cluster to look at
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
11 # version 1.2 -- June 2018
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
12 # added clustergrammer clustering parameters and normalization options
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
13
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
14
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
15 from __future__ import print_function
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
16 import sys
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
17 import os
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
18
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
19 from jinja2 import Environment, FileSystemLoader
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
20 import pandas as pd
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
21 from clustergrammer import Network
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
22
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
23
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
24 def is_integer(s):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
25 try:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
26 int(s)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
27 return True
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
28 except ValueError:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
29 return False
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
30
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
31
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
32 def get_indices(input_text):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
33 output_list = []
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
34 default_value = ['i.e.:1,2,5', 'i.e.:3,6,7']
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
35 if input_text in default_value:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
36 sys.exit(2)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
37 else:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
38 tmp_col = input_text.split(",")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
39 if len(tmp_col) == 1:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
40 if not tmp_col[0].strip():
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
41 sys.exit(2)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
42 elif not is_integer(tmp_col[0].strip()):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
43 sys.exit(3)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
44 else:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
45 output_list.append(int(tmp_col[0].strip()) - 1)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
46 else:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
47 for c in range(0, len(tmp_col)):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
48 if not is_integer(tmp_col[c].strip()):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
49 sys.exit(3)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
50 else:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
51 output_list.append(int(tmp_col[c].strip()) - 1)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
52 return(output_list)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
53
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
54
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
55 def prepare_heatmap(matrix_input, html_file, html_dir, tools_dir, categories, distance, linkage):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
56 # prepare directory and html
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
57 os.mkdir(html_dir)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
58
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
59 env = Environment(loader=FileSystemLoader(tools_dir + "/templates"))
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
60 template = env.get_template("clustergrammer.template")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
61 overview = template.render()
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
62 with open(html_file, "w") as outf:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
63 outf.write(overview)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
64
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
65 json_output = html_dir + "/mult_view.json"
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
66
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
67 net = Network()
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
68 net.load_file(matrix_input)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
69 if (categories['row']):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
70 net.add_cats('row', categories['row'])
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
71 if (categories['col']):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
72 net.add_cats('col', categories['col'])
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
73 net.cluster(dist_type=distance, linkage_type=linkage)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
74 net.write_json_to_file('viz', json_output)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
75
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
76
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
77 if __name__ == "__main__":
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
78
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
79 args = sys.argv
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
80 categories = {
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
81 'row': [],
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
82 'col': []
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
83 }
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
84 norm = {}
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
85
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
86 if (len(args) > 7):
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
87 df = pd.read_table(args[1])
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
88 names = {
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
89 'row': df.iloc[:, 0],
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
90 'col': df.columns[1:]
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
91 }
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
92
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
93 tmp_string = "-=-".join(args[8:])
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
94 print (tmp_string + "\n")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
95 # get categories
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
96 cats = tmp_string.split("-=-new_cat-=-")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
97 for cat in cats:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
98 tmp_cat = cat.split("-=-")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
99 group = {
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
100 "title": tmp_cat[1],
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
101 "cats": {}
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
102 }
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
103 stg_groups = "--".join(tmp_cat[2:])
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
104 groups = stg_groups.split("--new_label--")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
105 cat_indices = []
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
106 for g in groups:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
107 print(g + "\n")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
108 elem = g.split("--")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
109 index_list = get_indices(elem[1])
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
110 index_names = []
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
111 for i in index_list:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
112 if i in cat_indices:
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
113 sys.exit(4)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
114 index_names.append(str(names[tmp_cat[0]][i]))
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
115 cat_indices = cat_indices + index_list
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
116 print(index_names, elem[0], sep="\t")
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
117 group["cats"][elem[0]] = index_names
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
118 categories[tmp_cat[0]].append(group)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
119 print(categories)
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
120
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
121
fee56ee2f7ac "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/clustergrammer_flow commit b11dfcf10d287c1da91ffb1d5d0148c7f8f61356"
azomics
parents:
diff changeset
122 prepare_heatmap(args[1], args[2], args[3], args[4], categories, args[5], args[6])