annotate paracords_plot.py @ 1:7b21a9b5922f draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
author bgruening
date Wed, 10 Oct 2018 02:29:28 -0400
parents 7b2455348edf
children 9958188c6195
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
1 import sys
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
2 import argparse
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
3 import plotly
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
4 import plotly.graph_objs as go
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
5 import pandas as pd
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
6
1
7b21a9b5922f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
bgruening
parents: 0
diff changeset
7 def main(infile, col_dimensions, categorized, col_color):
0
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
8 """
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
9 Produce an interactive paracords plotting html
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
10 Args:
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
11 infile: str, tabular file
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
12 col_dimensions: str, comma separated index numbers. For example: "3,4,5"
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
13 col_color: str, index number
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
14 """
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
15 df = pd.read_csv(infile, sep='\t', parse_dates=True)
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
16
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
17 dimensions = []
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
18 col_dimensions = [int(x)-1 for x in col_dimensions.split(',')]
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
19 for col in col_dimensions:
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
20 values = df[df.columns[col]]
1
7b21a9b5922f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
bgruening
parents: 0
diff changeset
21 if categorized == 'boolfalse' and all(type(e) is int for e in values ):
0
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
22 dimensions.append(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
23 dict( values = values,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
24 tickformat = ",.2r",
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
25 label = df.columns[col])
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
26 )
1
7b21a9b5922f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
bgruening
parents: 0
diff changeset
27 elif categorized == 'boolfalse' and all(type(e) is float for e in values ):
0
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
28 dimensions.append(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
29 dict( values = values,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
30 tickformat = "g",
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
31 label = df.columns[col])
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
32 )
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
33 else:
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
34 unique_values = list(set(values))
1
7b21a9b5922f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
bgruening
parents: 0
diff changeset
35 unique_values.sort()
0
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
36 dimensions.append(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
37 dict( range = [0, len(unique_values)-1],
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
38 tickvals = list(range(len(unique_values))),
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
39 ticktext = [str(e) for e in unique_values],
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
40 values = list(map(lambda e: unique_values.index(e), values )),
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
41 label = df.columns[col])
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
42 )
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
43
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
44 col_color = int(col_color) - 1
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
45 colors = df[df.columns[col_color]]
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
46 if all(type(e) is int for e in colors ):
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
47 tickformat = ",.2r"
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
48 elif all(type(e) is float for e in colors ):
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
49 tickformat = "g"
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
50 else:
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
51 sys.exit("Error: the column for coloring must contain all numerical values!")
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
52
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
53 dimensions.append(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
54 dict(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
55 values = colors,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
56 tickformat = tickformat,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
57 label = df.columns[col_color]
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
58 )
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
59 )
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
60
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
61 line = dict(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
62 color = colors,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
63 colorscale = 'Jet',
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
64 showscale = True,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
65 reversescale = True
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
66 )
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
67
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
68 data = [
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
69 go.Parcoords(
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
70 line = line,
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
71 dimensions = dimensions
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
72 )
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
73 ]
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
74
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
75 plotly.offline.plot(data, filename = "output.html", auto_open=False)
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
76
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
77 if __name__ == "__main__":
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
78 aparser = argparse.ArgumentParser()
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
79 aparser.add_argument( "-i", "--input", dest="infile", required=True)
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
80 aparser.add_argument( "-d", "--col_dimensions", dest="col_dimensions")
1
7b21a9b5922f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
bgruening
parents: 0
diff changeset
81 aparser.add_argument( "-t", "--categorized_datatype", dest="categorized")
0
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
82 aparser.add_argument( "-c", "--col_color", dest="col_color")
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
83 args = aparser.parse_args()
7b2455348edf planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 93fcfe0fa6a64246d13e0fb7e35a357985b02465
bgruening
parents:
diff changeset
84
1
7b21a9b5922f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_parallel_coordinates_plot commit 7ba5d8f0e920dccbc82588e4f4a7b9039dc3ea36
bgruening
parents: 0
diff changeset
85 main(args.infile, args.col_dimensions, args.categorized, args.col_color)