annotate plotly_tabular_tool/plotlytabular.xml @ 3:51a0c2e0fbdf draft

Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
author fubar
date Fri, 04 Aug 2023 02:00:28 +0000
parents 08cc7a481af8
children e2d2b080bae3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
1 <tool name="plotlytabular" id="plotlytabular" version="3.0">
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay-->
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
3 <!--Created by toolfactory@galaxy.org at 04/08/2023 10:38:13 using the Galaxy Tool Factory.-->
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
4 <description>Plotly plot generator for Galaxy tabular data.</description>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
5 <requirements>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
6 <requirement version="1.5.3" type="package">pandas</requirement>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
7 <requirement version="5.9.0" type="package">plotly</requirement>
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
8 <requirement version="0.2.1" type="package">python-kaleido</requirement>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
9 </requirements>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
10 <stdio>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
11 <exit_code range="1:" level="fatal"/>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
12 </stdio>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
13 <version_command><![CDATA[echo "3.0"]]></version_command>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
14 <command><![CDATA[python
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
15 $runme
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
16 --input_tab
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
17 $input_tab
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
18 --htmlout
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
19 $htmlout
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
20 --xcol
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
21 "$xcol"
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
22 --ycol
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
23 "$ycol"
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
24 --colourcol
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
25 "$colourcol"
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
26 --hovercol
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
27 "$hovercol"
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
28 --title
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
29 "$title"
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
30 --header
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
31 "$header"
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
32 --image_type
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
33 "$outputimagetype"]]></command>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
34 <configfiles>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
35 <configfile name="runme"><![CDATA[#raw
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
36
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
37 import argparse
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
38 import shutil
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
39 import sys
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
40 import math
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
41 import plotly.express as px
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
42 import pandas as pd
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
43 # Ross Lazarus July 2023
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
44 # based on various plotly tutorials
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
45 parser = argparse.ArgumentParser()
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
46 a = parser.add_argument
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
47 a('--input_tab',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
48 a('--header',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
49 a('--htmlout',default="test_run.html")
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
50 a('--xcol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
51 a('--ycol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
52 a('--colourcol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
53 a('--hovercol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
54 a('--title',default='Default plot title')
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
55 a('--image_type',default='short_html')
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
56 args = parser.parse_args()
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
57 isColour = False
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
58 isHover = False
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
59 if len(args.colourcol.strip()) > 0:
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
60 isColour = True
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
61 if len(args.hovercol.strip()) > 0:
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
62 isHover = True
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
63 df = pd.read_csv(args.input_tab, sep='\t')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
64 MAXLEN=35
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
65 NCOLS = df.columns.size
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
66 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
67 testcols = df.columns
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
68 if len(args.header.strip()) > 0:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
69 newcols = args.header.split(',')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
70 if len(newcols) == NCOLS:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
71 df.columns = newcols
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
72 else:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
73 sys.stderr.write('#### Supplied header %s has %d comma delimited header names - does not match the input tabular file %d columns - using col1,...coln' % (args.header, len(newcols), NCOLS))
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
74 df.columns = defaultcols
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
75 else: # no header supplied - check for a real one that matches the x and y axis column names
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
76 colsok = (args.xcol in testcols) and (args.ycol in testcols) # if they match, probably ok...should use more code and logic..
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
77 if not colsok:
2
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
78 sys.stderr.write('replacing first row of data derived header %s with %s' % (testcols, defaultcols))
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
79 df.columns = defaultcols
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
80 #df['col11'] = [-math.log(x) for x in df['col11']] # convert so large values reflect statistical surprise
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
81 if isHover and isColour:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
82 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
83 elif isHover:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
84 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
85 elif isColour:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
86 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
87 else:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
88 fig = px.scatter(df, x=args.xcol, y=args.ycol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
89 if args.title:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
90 ftitle=dict(text=args.title, font=dict(size=50))
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
91 fig.update_layout(title=ftitle)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
92 for scatter in fig.data:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
93 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']]
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
94 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']]
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
95 if len(args.colourcol.strip()) == 0:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
96 sl = str(scatter['legendgroup'])
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
97 if len(sl) > MAXLEN:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
98 scatter['legendgroup'] = sl[:MAXLEN]
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
99 if args.image_type == "short_html":
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
100 fig.write_html(args.htmlout, full_html=False, include_plotlyjs='cdn')
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
101 elif args.image_type == "long_html":
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
102 fig.write_html(args.htmlout)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
103 elif args.image_type == "small_png":
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
104 ht = 768
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
105 wdth = 1024
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
106 fig.write_image('plotly.png', height=ht, width=wdth)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
107 shutil.copyfile('plotly.png', args.htmlout)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
108 else:
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
109 ht = 1200
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
110 wdth = 1920
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
111 fig.write_image('plotly.png', height=ht, width=wdth)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
112 shutil.copyfile('plotly.png', args.htmlout)
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
113
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
114
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
115 #end raw]]></configfile>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
116 </configfiles>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
117 <inputs>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
118 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/>
2
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
119 <param name="xcol" type="text" value="sepal_length" label="x axis for plot" help="Use a column name from the header if the file has one, or use one from the list supplied below, or use col1....colN otherwise to select the correct column"/>
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
120 <param name="ycol" type="text" value="sepal_width" label="y axis for plot" help="Use a column name from the header if the file has one, or use one from the list supplied below, or use col1....colN otherwise to select the correct column"/>
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
121 <param name="colourcol" type="text" value="petal_width" label="column containing a groupable variable for colour. Default none." help="Adds a legend so choose wisely "/>
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
122 <param name="hovercol" type="text" value="species" label="columname for hover string" help="Use a column name from the header if the file has one, or use one from the list supplied below, or use col1....colN otherwise to select the correct column"/>
2
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
123 <param name="title" type="text" value="Iris data" label="Title for the plot" help="Special characters will probably be escaped so do not use them"/>
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
124 <param name="header" type="text" value="" label="Use this comma delimited list of column header names for this tabular file. Default is None when col1...coln will be used" help="The column names supplied for xcol, ycol, hover and colour MUST match either this supplied list, or if none, col1...coln."/>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
125 <param name="outputimagetype" type="select" label="Select the output format for this plot image" help="Small and large png are not interactive but best for many (__gt__10k) points. Stand-alone HTML includes 3MB of javascript. Short form HTML gets it the usual way so can be cut and paste into documents.">
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
126 <option value="short_html">Short HTML interactive format</option>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
127 <option value="long_html">Long HTML for stand-alone viewing where network access to libraries is not available.</option>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
128 <option value="large_png">Large (1920x1200) png image - not interactive so hover column ignored</option>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
129 <option value="small_png">small (1024x768) png image - not interactive so hover column ignored</option>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
130 </param>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
131 </inputs>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
132 <outputs>
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
133 <data name="htmlout" format="html" label="Plotlytabular $title on $input_tab.element_identifier" hidden="false">
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
134 <change_format>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
135 <when input="outputimagetype" format="png" value="small_png"/>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
136 <when input="outputimagetype" format="png" value="large_png"/>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
137 </change_format>
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
138 </data>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
139 </outputs>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
140 <tests>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
141 <test>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
142 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
143 <param name="input_tab" value="input_tab_sample"/>
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
144 <param name="xcol" value="sepal_length"/>
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
145 <param name="ycol" value="sepal_width"/>
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
146 <param name="colourcol" value="petal_width"/>
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
147 <param name="hovercol" value="species"/>
2
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
148 <param name="title" value="Iris data"/>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
149 <param name="header" value=""/>
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
150 <param name="outputimagetype" value="short_html"/>
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
151 </test>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
152 </tests>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
153 <help><![CDATA[
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
154
2
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
155 This is a generic version of the plotlyblast specific blastn Galaxy search output file plotter.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
156
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
157 PNG images are not interactive but best for very large numbers of data points. Hover column will be ignored.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
158
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
159 HTML interactive plots are best for a few thousand data points at most because
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
160
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
161 the hover information becomes uncontrollable with very dense points.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
162
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
163 Using the shorter format HTML relies on internet access when viewed, and saves 3MB of javascript being embedded.
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
164
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
165 The long format is useful if potentially viewed offline.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
166
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
167
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
168
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
169 .. class:: warningmark
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
170
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
171 Long strings in x and y tickmarks WILL BE TRUNCATED if they are too long - ".." is added to indicate truncation - otherwise some plots are squished.
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
172
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
173
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
174
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
175 .. class:: warningmark
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
176
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
177 Columns with very small scientific notation floats will need to be pre-scaled in a way that doesn't confuse plotly.express with their values.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
178
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
179
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
180
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
181 ----
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
182
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
183
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
184
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
185 This tool can plot an interactive scatter plot with a hover text column specified, that appears when hovering over each data point, to supply useful additional information.
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
186
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
187 It is only useful with a relatively small number of points when they can be distinguished. If many thousands, the density makes them relatively useless so use png output and
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
188
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
189 forget the hover text.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
190
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
191
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
192
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
193 Column names are auto-generated as col1,...coln *unless* a comma separated list of column names is supplied as the header parameter, *or* pandas can
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
194
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
195 find the values supplied as parameters by the user in the first row of data. This sounds more complex than it is.
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
196
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
197
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
198
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
199 For example, using a Galaxy blastn output with 25 columns, the following comma delimited string supplied as the "header" parameter will match the names of each column.
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
200
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
201 qaccver,saccver,piden,length,mismatch,gapopen,qstart,qend,sstart,send,evalue,bitscore,sallseqid,score,nident,positive,gaps,ppos,qframe,sframe,qseq,sseq,qlen,slen,salltitles
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
202
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
203
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
204
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
205 When a header is supplied, the xcol and other column names must match one of those supplied column names.
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
206
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
207 So for example, xcol = "qaccver" for the blastn header example rather than xcol = "col1" when no header is supplied.
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
208
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
209
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
210
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
211 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
212
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
213
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
214
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
215
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
216
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
217 ------
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
218
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
219
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
220 Script::
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
221
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
222 import argparse
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
223 import shutil
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
224 import sys
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
225 import math
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
226 import plotly.express as px
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
227 import pandas as pd
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
228 # Ross Lazarus July 2023
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
229 # based on various plotly tutorials
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
230 parser = argparse.ArgumentParser()
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
231 a = parser.add_argument
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
232 a('--input_tab',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
233 a('--header',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
234 a('--htmlout',default="test_run.html")
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
235 a('--xcol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
236 a('--ycol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
237 a('--colourcol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
238 a('--hovercol',default='')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
239 a('--title',default='Default plot title')
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
240 a('--image_type',default='short_html')
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
241 args = parser.parse_args()
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
242 isColour = False
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
243 isHover = False
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
244 if len(args.colourcol.strip()) > 0:
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
245 isColour = True
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
246 if len(args.hovercol.strip()) > 0:
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
247 isHover = True
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
248 df = pd.read_csv(args.input_tab, sep='\t')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
249 MAXLEN=35
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
250 NCOLS = df.columns.size
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
251 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
252 testcols = df.columns
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
253 if len(args.header.strip()) > 0:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
254 newcols = args.header.split(',')
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
255 if len(newcols) == NCOLS:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
256 df.columns = newcols
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
257 else:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
258 sys.stderr.write('#### Supplied header %s has %d comma delimited header names - does not match the input tabular file %d columns - using col1,...coln' % (args.header, len(newcols), NCOLS))
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
259 df.columns = defaultcols
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
260 else: # no header supplied - check for a real one that matches the x and y axis column names
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
261 colsok = (args.xcol in testcols) and (args.ycol in testcols) # if they match, probably ok...should use more code and logic..
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
262 if not colsok:
2
08cc7a481af8 Uploaded
fubar
parents: 1
diff changeset
263 sys.stderr.write('replacing first row of data derived header %s with %s' % (testcols, defaultcols))
1
449c918bc4cd Uploaded
fubar
parents: 0
diff changeset
264 df.columns = defaultcols
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
265 #df['col11'] = [-math.log(x) for x in df['col11']] # convert so large values reflect statistical surprise
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
266 if isHover and isColour:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
267 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
268 elif isHover:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
269 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
270 elif isColour:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
271 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
272 else:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
273 fig = px.scatter(df, x=args.xcol, y=args.ycol)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
274 if args.title:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
275 ftitle=dict(text=args.title, font=dict(size=50))
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
276 fig.update_layout(title=ftitle)
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
277 for scatter in fig.data:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
278 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']]
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
279 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']]
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
280 if len(args.colourcol.strip()) == 0:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
281 sl = str(scatter['legendgroup'])
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
282 if len(sl) > MAXLEN:
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
283 scatter['legendgroup'] = sl[:MAXLEN]
3
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
284 if args.image_type == "short_html":
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
285 fig.write_html(args.htmlout, full_html=False, include_plotlyjs='cdn')
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
286 elif args.image_type == "long_html":
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
287 fig.write_html(args.htmlout)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
288 elif args.image_type == "small_png":
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
289 ht = 768
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
290 wdth = 1024
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
291 fig.write_image('plotly.png', height=ht, width=wdth)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
292 shutil.copyfile('plotly.png', args.htmlout)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
293 else:
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
294 ht = 1200
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
295 wdth = 1920
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
296 fig.write_image('plotly.png', height=ht, width=wdth)
51a0c2e0fbdf Updated with latest ToolFactory with change_format for outputs so can make a png or html and it has an informative label since on $foo can be used.
fubar
parents: 2
diff changeset
297 shutil.copyfile('plotly.png', args.htmlout)
0
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
298
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
299 ]]></help>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
300 <citations>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
301 <citation type="doi">10.1093/bioinformatics/bts573</citation>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
302 </citations>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
303 </tool>
7c166107a2e2 Uploaded
fubar
parents:
diff changeset
304