0
|
1 <tool name="plotlyblast" id="plotlyblast" version="3.0">
|
1
|
2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay-->
|
2
|
3 <!--Created by toolfactory@galaxy.org at 26/07/2023 17:31:09 using the Galaxy Tool Factory.-->
|
0
|
4 <description>Plotly plot generator</description>
|
|
5 <requirements>
|
2
|
6 <requirement type="package" version="1.5.3">pandas</requirement>
|
|
7 <requirement type="package" version="5.9.0">plotly</requirement>
|
0
|
8 </requirements>
|
|
9 <stdio>
|
|
10 <exit_code range="1:" level="fatal"/>
|
|
11 </stdio>
|
|
12 <version_command><![CDATA[echo "3.0"]]></version_command>
|
|
13 <command><![CDATA[python
|
|
14 $runme
|
|
15 --input_tab
|
|
16 $input_tab
|
|
17 --htmlout
|
|
18 $htmlout
|
|
19 --xcol
|
|
20 "$xcol"
|
|
21 --ycol
|
|
22 "$ycol"
|
|
23 --colourcol
|
|
24 "$colourcol"
|
|
25 --hovercol
|
|
26 "$hovercol"
|
|
27 --title
|
|
28 "$title"
|
|
29 --header
|
|
30 "$header"]]></command>
|
|
31 <configfiles>
|
|
32 <configfile name="runme"><![CDATA[#raw
|
|
33
|
|
34 import argparse
|
|
35 import sys
|
|
36 import math
|
|
37 import plotly.express as px
|
|
38 import pandas as pd
|
|
39 # Ross Lazarus July 2023
|
|
40 # based on various plotly tutorials
|
|
41 # Expects a blastn search result passed in as the first command line parameter.
|
|
42 parser = argparse.ArgumentParser()
|
|
43 a = parser.add_argument
|
|
44 a('--input_tab',default='')
|
|
45 a('--header',default='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')
|
|
46 a('--htmlout',default="test_run.html")
|
2
|
47 a('--xcol',default='')
|
|
48 a('--ycol',default='')
|
|
49 a('--colourcol',default='')
|
|
50 a('--hovercol',default='')
|
|
51 a('--title',default='test blast plot')
|
0
|
52 args = parser.parse_args()
|
|
53 df = pd.read_csv(args.input_tab, sep='\t')
|
|
54 NCOLS = df.columns.size
|
1
|
55 MAXLEN = 30 # tricky way to truncate long axis tickmarks
|
0
|
56 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
|
|
57 if len(args.header.strip()) > 0:
|
|
58 newcols = args.header.split(',')
|
|
59 if len(newcols) == NCOLS:
|
|
60 df.columns = newcols
|
|
61 else:
|
|
62 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))
|
|
63 df.columns = defaultcols
|
|
64 else:
|
|
65 df.columns = defaultcols
|
1
|
66 df['evalue'] = [-math.log(x + 1e-308) for x in df['evalue']] # convert so large values reflect statistical surprise
|
0
|
67 if len(args.colourcol.strip()) == 0:
|
|
68 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
|
|
69 else:
|
|
70 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
|
|
71 if args.title:
|
2
|
72 fig.update_layout(title=dict(text=args.title, font=dict(size=40)))
|
|
73
|
|
74
|
0
|
75 for scatter in fig.data:
|
|
76 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']]
|
1
|
78 if len(args.colourcol.strip()) == 0:
|
|
79 sl = str(scatter['legendgroup'])
|
|
80 if len(sl) > MAXLEN:
|
|
81 scatter['legendgroup'] = sl[:MAXLEN]
|
0
|
82 fig.write_html(args.htmlout)
|
|
83
|
1
|
84
|
0
|
85 #end raw]]></configfile>
|
|
86 </configfiles>
|
|
87 <inputs>
|
|
88 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/>
|
1
|
89 <param name="xcol" type="text" value="qaccver" label="x axis for plat" help=""/>
|
0
|
90 <param name="ycol" type="text" value="bitscore" label="y axis for plot" help=""/>
|
1
|
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 "/>
|
0
|
92 <param name="hovercol" type="text" value="qseq" label="columname for hover string" help=""/>
|
1
|
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"/>
|
|
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."/>
|
0
|
95 </inputs>
|
|
96 <outputs>
|
|
97 <data name="htmlout" format="html" label="htmlout" hidden="false"/>
|
|
98 </outputs>
|
|
99 <tests>
|
|
100 <test>
|
|
101 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/>
|
|
102 <param name="input_tab" value="input_tab_sample"/>
|
1
|
103 <param name="xcol" value="qaccver"/>
|
0
|
104 <param name="ycol" value="bitscore"/>
|
1
|
105 <param name="colourcol" value="piden"/>
|
0
|
106 <param name="hovercol" value="qseq"/>
|
1
|
107 <param name="title" value="Qaccver by bitscore coloured by pident. Hover shows blast match."/>
|
0
|
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"/>
|
|
109 </test>
|
|
110 </tests>
|
|
111 <help><![CDATA[
|
|
112
|
|
113 This is a specialised version of a generic tabular file plotter tool plotlytabular
|
|
114
|
|
115
|
|
116
|
|
117 .. class:: warningmark
|
|
118
|
1
|
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.
|
|
120
|
0
|
121
|
|
122
|
1
|
123 .. class:: warningmark
|
0
|
124
|
1
|
125 NOTE: Blast evalues WILL BE TRANSFORMED using -log10(evalue), so they are scaled in a way that doesn't confuse plotly.express with the tiny values.
|
0
|
126
|
|
127
|
|
128
|
|
129 ----
|
|
130
|
|
131
|
|
132
|
2
|
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.
|
0
|
134
|
|
135
|
|
136
|
|
137 Assumes you want a hover display for an interactive plot to be informative
|
|
138
|
|
139
|
|
140
|
|
141 Column names are auto-generated as col1,...coln unless a comma separated list of column names is supplied as the header parameter.
|
|
142
|
|
143
|
|
144
|
|
145 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.
|
|
146
|
|
147 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
|
|
148
|
|
149
|
|
150
|
|
151 When a header is supplied, the xcol and other column names must match one of those supplied column names.
|
|
152
|
|
153 So for example, xcol = "qaccver" for the blastn header example rather than xcol = "col1" when no header is supplied.
|
|
154
|
|
155
|
|
156
|
|
157 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt
|
|
158
|
|
159
|
|
160
|
1
|
161 .. image:: pbsample.png
|
|
162
|
|
163 :height: 400
|
|
164
|
|
165 :width: 400
|
|
166
|
2
|
167
|
1
|
168
|
0
|
169 ------
|
|
170
|
|
171
|
|
172 Script::
|
|
173
|
|
174 import argparse
|
|
175 import sys
|
|
176 import math
|
|
177 import plotly.express as px
|
|
178 import pandas as pd
|
|
179 # Ross Lazarus July 2023
|
|
180 # based on various plotly tutorials
|
|
181 # Expects a blastn search result passed in as the first command line parameter.
|
|
182 parser = argparse.ArgumentParser()
|
|
183 a = parser.add_argument
|
|
184 a('--input_tab',default='')
|
|
185 a('--header',default='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')
|
|
186 a('--htmlout',default="test_run.html")
|
2
|
187 a('--xcol',default='')
|
|
188 a('--ycol',default='')
|
|
189 a('--colourcol',default='')
|
|
190 a('--hovercol',default='')
|
|
191 a('--title',default='test blast plot')
|
0
|
192 args = parser.parse_args()
|
|
193 df = pd.read_csv(args.input_tab, sep='\t')
|
|
194 NCOLS = df.columns.size
|
1
|
195 MAXLEN = 30 # tricky way to truncate long axis tickmarks
|
0
|
196 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
|
|
197 if len(args.header.strip()) > 0:
|
|
198 newcols = args.header.split(',')
|
|
199 if len(newcols) == NCOLS:
|
|
200 df.columns = newcols
|
|
201 else:
|
|
202 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))
|
|
203 df.columns = defaultcols
|
|
204 else:
|
|
205 df.columns = defaultcols
|
1
|
206 df['evalue'] = [-math.log(x + 1e-308) for x in df['evalue']] # convert so large values reflect statistical surprise
|
0
|
207 if len(args.colourcol.strip()) == 0:
|
|
208 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
|
|
209 else:
|
|
210 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
|
|
211 if args.title:
|
1
|
212 ftitle=dict(text=args.title, font=dict(size=40), automargin=True)
|
0
|
213 fig.update_layout(title=ftitle)
|
|
214 for scatter in fig.data:
|
|
215 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']]
|
1
|
217 if len(args.colourcol.strip()) == 0:
|
|
218 sl = str(scatter['legendgroup'])
|
|
219 if len(sl) > MAXLEN:
|
|
220 scatter['legendgroup'] = sl[:MAXLEN]
|
0
|
221 fig.write_html(args.htmlout)
|
|
222
|
|
223 ]]></help>
|
|
224 <citations>
|
|
225 <citation type="doi">10.1093/bioinformatics/bts573</citation>
|
|
226 </citations>
|
|
227 </tool>
|
|
228
|