comparison plotly_blast_tool/plotlyblast.xml @ 1:6fbd48e9c950 draft

ready for beta testing?
author fubar
date Wed, 26 Jul 2023 06:35:18 +0000
parents 61cc57e069c0
children 47a7eeec4a19
comparison
equal deleted inserted replaced
0:61cc57e069c0 1:6fbd48e9c950
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--> 2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay-->
3 <!--Created by toolfactory@galaxy.org at 25/07/2023 14:13:15 using the Galaxy Tool Factory.--> 3 <!--Created by toolfactory@galaxy.org at 26/07/2023 15:45:12 using the Galaxy Tool Factory.-->
4 <description>Plotly plot generator</description> 4 <description>Plotly plot generator</description>
5 <requirements> 5 <requirements>
6 <requirement type="package" version="1.5.3">pandas</requirement> 6 <requirement type="package">pandas</requirement>
7 <requirement type="package" version="5.9.0">plotly</requirement> 7 <requirement type="package">plotly</requirement>
8 </requirements> 8 </requirements>
9 <stdio> 9 <stdio>
10 <exit_code range="1:" level="fatal"/> 10 <exit_code range="1:" level="fatal"/>
11 </stdio> 11 </stdio>
12 <version_command><![CDATA[echo "3.0"]]></version_command> 12 <version_command><![CDATA[echo "3.0"]]></version_command>
50 a('--hovercol',default='qseq') 50 a('--hovercol',default='qseq')
51 a('--title',default='test blast plot of mismatch by bitscore coloured by qaccver ') 51 a('--title',default='test blast plot of mismatch by bitscore coloured by qaccver ')
52 args = parser.parse_args() 52 args = parser.parse_args()
53 df = pd.read_csv(args.input_tab, sep='\t') 53 df = pd.read_csv(args.input_tab, sep='\t')
54 NCOLS = df.columns.size 54 NCOLS = df.columns.size
55 MAXLEN = 40 # tricky way to truncate long axis tickmarks 55 MAXLEN = 30 # tricky way to truncate long axis tickmarks
56 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] 56 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
57 if len(args.header.strip()) > 0: 57 if len(args.header.strip()) > 0:
58 newcols = args.header.split(',') 58 newcols = args.header.split(',')
59 if len(newcols) == NCOLS: 59 if len(newcols) == NCOLS:
60 df.columns = newcols 60 df.columns = newcols
61 else: 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)) 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 63 df.columns = defaultcols
64 else: 64 else:
65 df.columns = defaultcols 65 df.columns = defaultcols
66 df['evalue'] = [-math.log(x) for x in df['evalue']] # convert so large values reflect statistical surprise 66 df['evalue'] = [-math.log(x + 1e-308) for x in df['evalue']] # convert so large values reflect statistical surprise
67 if len(args.colourcol.strip()) == 0: 67 if len(args.colourcol.strip()) == 0:
68 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) 68 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
69 else: 69 else:
70 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) 70 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
71 if args.title: 71 if args.title:
72 ftitle=dict(text=args.title, font=dict(size=50)) 72 ftitle=dict(text=args.title, font=dict(size=40), automargin=True)
73 fig.update_layout(title=ftitle) 73 fig.update_layout(title=ftitle)
74 for scatter in fig.data: 74 for scatter in fig.data:
75 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']] 75 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']]
76 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']] 76 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']]
77 if len(args.colourcol.strip()) == 0:
78 sl = str(scatter['legendgroup'])
79 if len(sl) > MAXLEN:
80 scatter['legendgroup'] = sl[:MAXLEN]
77 fig.write_html(args.htmlout) 81 fig.write_html(args.htmlout)
82
78 83
79 #end raw]]></configfile> 84 #end raw]]></configfile>
80 </configfiles> 85 </configfiles>
81 <inputs> 86 <inputs>
82 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/> 87 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/>
83 <param name="xcol" type="text" value="mismatch" label="x axis for plat" help=""/> 88 <param name="xcol" type="text" value="qaccver" label="x axis for plat" help=""/>
84 <param name="ycol" type="text" value="bitscore" label="y axis for plot" help=""/> 89 <param name="ycol" type="text" value="bitscore" label="y axis for plot" help=""/>
85 <param name="colourcol" type="text" value="qaccver" label="column containing a groupable variable for colour. Default none." help="Adds a legend so choose wisely "/> 90 <param name="colourcol" type="text" value="piden" label="column containing a groupable variable for colour. Default none." help="Adds a legend so choose wisely "/>
86 <param name="hovercol" type="text" value="qseq" label="columname for hover string" help=""/> 91 <param name="hovercol" type="text" value="qseq" label="columname for hover string" help=""/>
87 <param name="title" type="text" value="Test title default" label="Title for the plot" help=""/> 92 <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"/>
88 <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__sq__s columns" help="Default for Galaxy blast outputs with 25 columns."/> 93 <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."/>
89 </inputs> 94 </inputs>
90 <outputs> 95 <outputs>
91 <data name="htmlout" format="html" label="htmlout" hidden="false"/> 96 <data name="htmlout" format="html" label="htmlout" hidden="false"/>
92 </outputs> 97 </outputs>
93 <tests> 98 <tests>
94 <test> 99 <test>
95 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/> 100 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/>
96 <param name="input_tab" value="input_tab_sample"/> 101 <param name="input_tab" value="input_tab_sample"/>
97 <param name="xcol" value="mismatch"/> 102 <param name="xcol" value="qaccver"/>
98 <param name="ycol" value="bitscore"/> 103 <param name="ycol" value="bitscore"/>
99 <param name="colourcol" value="qaccver"/> 104 <param name="colourcol" value="piden"/>
100 <param name="hovercol" value="qseq"/> 105 <param name="hovercol" value="qseq"/>
101 <param name="title" value="Test title default"/> 106 <param name="title" value="Qaccver by bitscore coloured by pident. Hover shows blast match."/>
102 <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"/> 107 <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"/>
103 </test> 108 </test>
104 </tests> 109 </tests>
105 <help><![CDATA[ 110 <help><![CDATA[
106 111
108 113
109 114
110 115
111 .. class:: warningmark 116 .. class:: warningmark
112 117
113 118 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.
114 119
115 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
116 121
117 The evalues WILL BE CONVERTED as -log10(evalue) so they are scaled in a way that doesn't confuse plotly.express with the tiny values. 122 .. class:: warningmark
123
124 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.
118 125
119 126
120 127
121 ---- 128 ----
122 129
123 130
124 131
125 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. 132 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.
126 133
127 134
128 135
129 Assumes you want a hover display for an interactive plot to be informative 136 Assumes you want a hover display for an interactive plot to be informative
130 137
147 154
148 155
149 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt 156 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt
150 157
151 158
159
160 .. image:: pbsample.png
161
162 :height: 400
163
164 :width: 400
165
166
152 167
153 ------ 168 ------
154 169
155 170
156 Script:: 171 Script::
174 a('--hovercol',default='qseq') 189 a('--hovercol',default='qseq')
175 a('--title',default='test blast plot of mismatch by bitscore coloured by qaccver ') 190 a('--title',default='test blast plot of mismatch by bitscore coloured by qaccver ')
176 args = parser.parse_args() 191 args = parser.parse_args()
177 df = pd.read_csv(args.input_tab, sep='\t') 192 df = pd.read_csv(args.input_tab, sep='\t')
178 NCOLS = df.columns.size 193 NCOLS = df.columns.size
179 MAXLEN = 40 # tricky way to truncate long axis tickmarks 194 MAXLEN = 30 # tricky way to truncate long axis tickmarks
180 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] 195 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
181 if len(args.header.strip()) > 0: 196 if len(args.header.strip()) > 0:
182 newcols = args.header.split(',') 197 newcols = args.header.split(',')
183 if len(newcols) == NCOLS: 198 if len(newcols) == NCOLS:
184 df.columns = newcols 199 df.columns = newcols
185 else: 200 else:
186 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)) 201 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))
187 df.columns = defaultcols 202 df.columns = defaultcols
188 else: 203 else:
189 df.columns = defaultcols 204 df.columns = defaultcols
190 df['evalue'] = [-math.log(x) for x in df['evalue']] # convert so large values reflect statistical surprise 205 df['evalue'] = [-math.log(x + 1e-308) for x in df['evalue']] # convert so large values reflect statistical surprise
191 if len(args.colourcol.strip()) == 0: 206 if len(args.colourcol.strip()) == 0:
192 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) 207 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
193 else: 208 else:
194 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) 209 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
195 if args.title: 210 if args.title:
196 ftitle=dict(text=args.title, font=dict(size=50), automargin=True) 211 ftitle=dict(text=args.title, font=dict(size=40), automargin=True)
197 fig.update_layout(title=ftitle) 212 fig.update_layout(title=ftitle)
198 for scatter in fig.data: 213 for scatter in fig.data:
199 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']] 214 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']]
200 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']] 215 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']]
216 if len(args.colourcol.strip()) == 0:
217 sl = str(scatter['legendgroup'])
218 if len(sl) > MAXLEN:
219 scatter['legendgroup'] = sl[:MAXLEN]
201 fig.write_html(args.htmlout) 220 fig.write_html(args.htmlout)
202 fig.show()
203 221
204 ]]></help> 222 ]]></help>
205 <citations> 223 <citations>
206 <citation type="doi">10.1093/bioinformatics/bts573</citation> 224 <citation type="doi">10.1093/bioinformatics/bts573</citation>
207 </citations> 225 </citations>