Mercurial > repos > fubar > plotly_blast_plot
comparison plotly_blast_tool/plotlyblast.xml @ 3:82bcfcb60f97 draft default tip
Updated by re-generating with latest ToolFactory so png or html outputs can be requested. Output labels are informative too.
author | fubar |
---|---|
date | Fri, 04 Aug 2023 01:55:07 +0000 |
parents | 47a7eeec4a19 |
children |
comparison
equal
deleted
inserted
replaced
2:47a7eeec4a19 | 3:82bcfcb60f97 |
---|---|
1 <tool name="plotlyblast" id="plotlyblast" version="3.0"> | 1 <tool name="plotlyblast" id="plotlyblast" version="3.0"> |
2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay--> | 2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay--> |
3 <!--Created by toolfactory@galaxy.org at 26/07/2023 17:31:09 using the Galaxy Tool Factory.--> | 3 <!--Created by toolfactory@galaxy.org at 04/08/2023 10:36:02 using the Galaxy Tool Factory.--> |
4 <description>Plotly plot generator</description> | 4 <description>Plotly plot generator specialised for 25 column Galaxy blast search result tabular files</description> |
5 <requirements> | 5 <requirements> |
6 <requirement type="package" version="1.5.3">pandas</requirement> | 6 <requirement version="1.5.3" type="package">pandas</requirement> |
7 <requirement type="package" version="5.9.0">plotly</requirement> | 7 <requirement version="5.9.0" type="package">plotly</requirement> |
8 <requirement version="0.2.1" type="package">python-kaleido</requirement> | |
8 </requirements> | 9 </requirements> |
9 <stdio> | 10 <stdio> |
10 <exit_code range="1:" level="fatal"/> | 11 <exit_code range="1:" level="fatal"/> |
11 </stdio> | 12 </stdio> |
12 <version_command><![CDATA[echo "3.0"]]></version_command> | 13 <version_command><![CDATA[echo "3.0"]]></version_command> |
25 --hovercol | 26 --hovercol |
26 "$hovercol" | 27 "$hovercol" |
27 --title | 28 --title |
28 "$title" | 29 "$title" |
29 --header | 30 --header |
30 "$header"]]></command> | 31 "$header" |
32 --image_type | |
33 "$outputimagetype"]]></command> | |
31 <configfiles> | 34 <configfiles> |
32 <configfile name="runme"><![CDATA[#raw | 35 <configfile name="runme"><![CDATA[#raw |
33 | 36 |
34 import argparse | 37 import argparse |
38 import shutil | |
35 import sys | 39 import sys |
36 import math | 40 import math |
37 import plotly.express as px | 41 import plotly.express as px |
38 import pandas as pd | 42 import pandas as pd |
39 # Ross Lazarus July 2023 | 43 # Ross Lazarus July 2023 |
47 a('--xcol',default='') | 51 a('--xcol',default='') |
48 a('--ycol',default='') | 52 a('--ycol',default='') |
49 a('--colourcol',default='') | 53 a('--colourcol',default='') |
50 a('--hovercol',default='') | 54 a('--hovercol',default='') |
51 a('--title',default='test blast plot') | 55 a('--title',default='test blast plot') |
56 a('--image_type',default='short_html') | |
52 args = parser.parse_args() | 57 args = parser.parse_args() |
53 df = pd.read_csv(args.input_tab, sep='\t') | 58 df = pd.read_csv(args.input_tab, sep='\t') |
54 NCOLS = df.columns.size | 59 NCOLS = df.columns.size |
55 MAXLEN = 30 # tricky way to truncate long axis tickmarks | 60 MAXLEN = 30 # tricky way to truncate long axis tickmarks |
56 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] | 61 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] |
67 if len(args.colourcol.strip()) == 0: | 72 if len(args.colourcol.strip()) == 0: |
68 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) | 73 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) |
69 else: | 74 else: |
70 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) | 75 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) |
71 if args.title: | 76 if args.title: |
72 fig.update_layout(title=dict(text=args.title, font=dict(size=40))) | 77 ftitle=dict(text=args.title, font=dict(size=40)) |
73 | 78 fig.update_layout(title=ftitle) |
74 | |
75 for scatter in fig.data: | 79 for scatter in fig.data: |
76 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']] | 80 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']] |
77 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']] | 81 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']] |
78 if len(args.colourcol.strip()) == 0: | 82 if len(args.colourcol.strip()) == 0: |
79 sl = str(scatter['legendgroup']) | 83 sl = str(scatter['legendgroup']) |
80 if len(sl) > MAXLEN: | 84 if len(sl) > MAXLEN: |
81 scatter['legendgroup'] = sl[:MAXLEN] | 85 scatter['legendgroup'] = sl[:MAXLEN] |
82 fig.write_html(args.htmlout) | 86 if args.image_type == "short_html": |
87 fig.write_html(args.htmlout, full_html=False, include_plotlyjs='cdn') | |
88 elif args.image_type == "long_html": | |
89 fig.write_html(args.htmlout) | |
90 elif args.image_type == "small_png": | |
91 ht = 768 | |
92 wdth = 1024 | |
93 fig.write_image('plotly.png', height=ht, width=wdth) | |
94 shutil.copyfile('plotly.png', args.htmlout) | |
95 else: | |
96 ht = 1200 | |
97 wdth = 1920 | |
98 fig.write_image('plotly.png', height=ht, width=wdth) | |
99 shutil.copyfile('plotly.png', args.htmlout) | |
100 | |
83 | 101 |
84 | 102 |
85 #end raw]]></configfile> | 103 #end raw]]></configfile> |
86 </configfiles> | 104 </configfiles> |
87 <inputs> | 105 <inputs> |
88 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/> | 106 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/> |
89 <param name="xcol" type="text" value="qaccver" label="x axis for plat" help=""/> | 107 <param name="xcol" type="text" value="qaccver" label="x axis for plot" help=""/> |
90 <param name="ycol" type="text" value="bitscore" label="y axis for plot" help=""/> | 108 <param name="ycol" type="text" value="bitscore" label="y axis for plot" help=""/> |
91 <param name="colourcol" type="text" value="piden" label="column containing a groupable variable for colour. Default none." help="Adds a legend so choose wisely "/> | 109 <param name="colourcol" type="text" value="piden" label="column containing a groupable variable for colour. Default none." help="Adds a legend so choose wisely "/> |
92 <param name="hovercol" type="text" value="qseq" label="columname for hover string" help=""/> | 110 <param name="hovercol" type="text" value="qseq" label="columname for hover string" help=""/> |
93 <param name="title" type="text" value="Qaccver by bitscore coloured by pident. Hover shows blast match." label="Title for the plot" help="Special characters will probably be escaped so do not use them"/> | 111 <param name="title" type="text" value="Qaccver by bitscore coloured by pident. Hover shows blast match." label="Title for the plot" help="Special characters will probably be escaped so do not use them"/> |
94 <param name="header" type="text" value="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" label="Use this comma delimited list of column header names for this tabular file. Default is None when col1...coln will be used" help="Default for Galaxy blast outputs with 25 columns. The column names supplied for xcol, ycol, hover and colour MUST match either the supplied list, or if none, col1...coln."/> | 112 <param name="header" type="text" value="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" label="Use this comma delimited list of column header names for this tabular file. Default is None when col1...coln will be used" help="Default for Galaxy blast outputs with 25 columns. The column names supplied for xcol, ycol, hover and colour MUST match either the supplied list, or if none, col1...coln."/> |
113 <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."> | |
114 <option value="short_html">Short HTML interactive - requires network connection to download 3MB javascript</option> | |
115 <option value="long_html">Long HTML for stand-alone viewing where network access to libraries is not available.</option> | |
116 <option value="large_png">Large (1920x1200) png image - not interactive so hover column ignored</option> | |
117 <option value="small_png">Small (1024x768) png image - not interactive so hover column ignored</option> | |
118 </param> | |
95 </inputs> | 119 </inputs> |
96 <outputs> | 120 <outputs> |
97 <data name="htmlout" format="html" label="htmlout" hidden="false"/> | 121 <data name="htmlout" format="html" label="Plotlyblast $title on $input_tab.element_identifier" hidden="false"> |
122 <change_format> | |
123 <when input="outputimagetype" format="png" value="small_png"/> | |
124 <when input="outputimagetype" format="png" value="large_png"/> | |
125 </change_format> | |
126 </data> | |
98 </outputs> | 127 </outputs> |
99 <tests> | 128 <tests> |
100 <test> | 129 <test> |
101 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/> | 130 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/> |
102 <param name="input_tab" value="input_tab_sample"/> | 131 <param name="input_tab" value="input_tab_sample"/> |
104 <param name="ycol" value="bitscore"/> | 133 <param name="ycol" value="bitscore"/> |
105 <param name="colourcol" value="piden"/> | 134 <param name="colourcol" value="piden"/> |
106 <param name="hovercol" value="qseq"/> | 135 <param name="hovercol" value="qseq"/> |
107 <param name="title" value="Qaccver by bitscore coloured by pident. Hover shows blast match."/> | 136 <param name="title" value="Qaccver by bitscore coloured by pident. Hover shows blast match."/> |
108 <param name="header" value="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"/> | 137 <param name="header" value="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"/> |
138 <param name="outputimagetype" value="short_html"/> | |
109 </test> | 139 </test> |
110 </tests> | 140 </tests> |
111 <help><![CDATA[ | 141 <help><![CDATA[ |
112 | 142 |
113 This is a specialised version of a generic tabular file plotter tool plotlytabular | 143 This is a specialised version of a generic tabular file plotter tool plotlytabular |
114 | 144 |
145 PNG image outputs are not interactive but best for very large numbers of data points. Hover column will be ignored. | |
146 | |
147 HTML interactive plots are best for a few thousand data points at most because | |
148 | |
149 the hover information becomes uncontrollable with very dense points. | |
150 | |
151 Using the shorter format HTML relies on internet access when viewed, and saves 3MB of javascript being embedded. | |
152 | |
153 The long format is useful if potentially viewed offline. | |
154 | |
115 | 155 |
116 | 156 |
117 .. class:: warningmark | 157 .. class:: warningmark |
118 | 158 |
119 NOTE: 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. | 159 NOTE: 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. |
128 | 168 |
129 ---- | 169 ---- |
130 | 170 |
131 | 171 |
132 | 172 |
133 The main reason to run this tool is to have an interactive hover text specified so it appears when hovering over each data point to supply useful information. | 173 The main reason to run this tool is to have an interactive hover text specified so it appears when hovering over each data point to supply useful information. |
134 | 174 |
135 | 175 |
136 | 176 |
137 Assumes you want a hover display for an interactive plot to be informative | 177 Assumes you want a hover display for an interactive plot to be informative |
138 | 178 |
156 | 196 |
157 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt | 197 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt |
158 | 198 |
159 | 199 |
160 | 200 |
161 .. image:: pbsample.png | 201 |
162 | 202 |
163 :height: 400 | 203 |
164 | |
165 :width: 400 | |
166 | |
167 | |
168 | 204 |
169 ------ | 205 ------ |
170 | 206 |
171 | 207 |
172 Script:: | 208 Script:: |
173 | 209 |
174 import argparse | 210 import argparse |
211 import shutil | |
175 import sys | 212 import sys |
176 import math | 213 import math |
177 import plotly.express as px | 214 import plotly.express as px |
178 import pandas as pd | 215 import pandas as pd |
179 # Ross Lazarus July 2023 | 216 # Ross Lazarus July 2023 |
187 a('--xcol',default='') | 224 a('--xcol',default='') |
188 a('--ycol',default='') | 225 a('--ycol',default='') |
189 a('--colourcol',default='') | 226 a('--colourcol',default='') |
190 a('--hovercol',default='') | 227 a('--hovercol',default='') |
191 a('--title',default='test blast plot') | 228 a('--title',default='test blast plot') |
229 a('--image_type',default='short_html') | |
192 args = parser.parse_args() | 230 args = parser.parse_args() |
193 df = pd.read_csv(args.input_tab, sep='\t') | 231 df = pd.read_csv(args.input_tab, sep='\t') |
194 NCOLS = df.columns.size | 232 NCOLS = df.columns.size |
195 MAXLEN = 30 # tricky way to truncate long axis tickmarks | 233 MAXLEN = 30 # tricky way to truncate long axis tickmarks |
196 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] | 234 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] |
207 if len(args.colourcol.strip()) == 0: | 245 if len(args.colourcol.strip()) == 0: |
208 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) | 246 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) |
209 else: | 247 else: |
210 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) | 248 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) |
211 if args.title: | 249 if args.title: |
212 ftitle=dict(text=args.title, font=dict(size=40), automargin=True) | 250 ftitle=dict(text=args.title, font=dict(size=40)) |
213 fig.update_layout(title=ftitle) | 251 fig.update_layout(title=ftitle) |
214 for scatter in fig.data: | 252 for scatter in fig.data: |
215 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']] | 253 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']] |
216 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']] | 254 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']] |
217 if len(args.colourcol.strip()) == 0: | 255 if len(args.colourcol.strip()) == 0: |
218 sl = str(scatter['legendgroup']) | 256 sl = str(scatter['legendgroup']) |
219 if len(sl) > MAXLEN: | 257 if len(sl) > MAXLEN: |
220 scatter['legendgroup'] = sl[:MAXLEN] | 258 scatter['legendgroup'] = sl[:MAXLEN] |
221 fig.write_html(args.htmlout) | 259 if args.image_type == "short_html": |
260 fig.write_html(args.htmlout, full_html=False, include_plotlyjs='cdn') | |
261 elif args.image_type == "long_html": | |
262 fig.write_html(args.htmlout) | |
263 elif args.image_type == "small_png": | |
264 ht = 768 | |
265 wdth = 1024 | |
266 fig.write_image('plotly.png', height=ht, width=wdth) | |
267 shutil.copyfile('plotly.png', args.htmlout) | |
268 else: | |
269 ht = 1200 | |
270 wdth = 1920 | |
271 fig.write_image('plotly.png', height=ht, width=wdth) | |
272 shutil.copyfile('plotly.png', args.htmlout) | |
222 | 273 |
223 ]]></help> | 274 ]]></help> |
224 <citations> | 275 <citations> |
225 <citation type="doi">10.1093/bioinformatics/bts573</citation> | 276 <citation type="doi">10.1093/bioinformatics/bts573</citation> |
226 </citations> | 277 </citations> |