annotate plotly_blast_tool/plotlyblast.xml @ 7:bb99f2c0e358 draft

Updated by regenerating with latest ToolFactory revision
author fubar
date Fri, 04 Aug 2023 01:52:13 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
1 <tool name="plotlyblast" id="plotlyblast" version="3.0">
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay-->
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
3 <!--Created by toolfactory@galaxy.org at 04/08/2023 10:36:02 using the Galaxy Tool Factory.-->
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
4 <description>Plotly plot generator specialised for 25 column Galaxy blast search result tabular files</description>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
5 <requirements>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
6 <requirement version="1.5.3" type="package">pandas</requirement>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
7 <requirement version="5.9.0" type="package">plotly</requirement>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
8 <requirement version="0.2.1" type="package">python-kaleido</requirement>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
9 </requirements>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
10 <stdio>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
11 <exit_code range="1:" level="fatal"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
12 </stdio>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
13 <version_command><![CDATA[echo "3.0"]]></version_command>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
14 <command><![CDATA[python
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
15 $runme
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
16 --input_tab
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
17 $input_tab
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
18 --htmlout
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
19 $htmlout
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
20 --xcol
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
21 "$xcol"
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
22 --ycol
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
23 "$ycol"
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
24 --colourcol
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
25 "$colourcol"
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
26 --hovercol
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
27 "$hovercol"
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
28 --title
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
29 "$title"
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
30 --header
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
31 "$header"
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
32 --image_type
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
33 "$outputimagetype"]]></command>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
34 <configfiles>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
35 <configfile name="runme"><![CDATA[#raw
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
36
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
37 import argparse
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
38 import shutil
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
39 import sys
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
40 import math
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
41 import plotly.express as px
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
42 import pandas as pd
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
43 # Ross Lazarus July 2023
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
44 # based on various plotly tutorials
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
45 # Expects a blastn search result passed in as the first command line parameter.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
46 parser = argparse.ArgumentParser()
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
47 a = parser.add_argument
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
48 a('--input_tab',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
49 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')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
50 a('--htmlout',default="test_run.html")
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
51 a('--xcol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
52 a('--ycol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
53 a('--colourcol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
54 a('--hovercol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
55 a('--title',default='test blast plot')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
56 a('--image_type',default='short_html')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
57 args = parser.parse_args()
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
58 df = pd.read_csv(args.input_tab, sep='\t')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
59 NCOLS = df.columns.size
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
60 MAXLEN = 30 # tricky way to truncate long axis tickmarks
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
61 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
62 if len(args.header.strip()) > 0:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
63 newcols = args.header.split(',')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
64 if len(newcols) == NCOLS:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
65 df.columns = newcols
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
66 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
67 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))
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
68 df.columns = defaultcols
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
69 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
70 df.columns = defaultcols
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
71 df['evalue'] = [-math.log(x + 1e-308) for x in df['evalue']] # convert so large values reflect statistical surprise
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
72 if len(args.colourcol.strip()) == 0:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
73 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
74 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
75 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
76 if args.title:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
77 ftitle=dict(text=args.title, font=dict(size=40))
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
78 fig.update_layout(title=ftitle)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
79 for scatter in fig.data:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
80 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
81 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
82 if len(args.colourcol.strip()) == 0:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
83 sl = str(scatter['legendgroup'])
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
84 if len(sl) > MAXLEN:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
85 scatter['legendgroup'] = sl[:MAXLEN]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
86 if args.image_type == "short_html":
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
87 fig.write_html(args.htmlout, full_html=False, include_plotlyjs='cdn')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
88 elif args.image_type == "long_html":
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
89 fig.write_html(args.htmlout)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
90 elif args.image_type == "small_png":
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
91 ht = 768
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
92 wdth = 1024
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
93 fig.write_image('plotly.png', height=ht, width=wdth)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
94 shutil.copyfile('plotly.png', args.htmlout)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
95 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
96 ht = 1200
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
97 wdth = 1920
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
98 fig.write_image('plotly.png', height=ht, width=wdth)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
99 shutil.copyfile('plotly.png', args.htmlout)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
100
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
101
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
102
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
103 #end raw]]></configfile>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
104 </configfiles>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
105 <inputs>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
106 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
107 <param name="xcol" type="text" value="qaccver" label="x axis for plot" help=""/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
108 <param name="ycol" type="text" value="bitscore" label="y axis for plot" help=""/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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 "/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
110 <param name="hovercol" type="text" value="qseq" label="columname for hover string" help=""/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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."/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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.">
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
114 <option value="short_html">Short HTML interactive - requires network connection to download 3MB javascript</option>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
115 <option value="long_html">Long HTML for stand-alone viewing where network access to libraries is not available.</option>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
116 <option value="large_png">Large (1920x1200) png image - not interactive so hover column ignored</option>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
117 <option value="small_png">Small (1024x768) png image - not interactive so hover column ignored</option>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
118 </param>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
119 </inputs>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
120 <outputs>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
121 <data name="htmlout" format="html" label="Plotlyblast $title on $input_tab.element_identifier" hidden="false">
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
122 <change_format>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
123 <when input="outputimagetype" format="png" value="small_png"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
124 <when input="outputimagetype" format="png" value="large_png"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
125 </change_format>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
126 </data>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
127 </outputs>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
128 <tests>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
129 <test>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
130 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
131 <param name="input_tab" value="input_tab_sample"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
132 <param name="xcol" value="qaccver"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
133 <param name="ycol" value="bitscore"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
134 <param name="colourcol" value="piden"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
135 <param name="hovercol" value="qseq"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
136 <param name="title" value="Qaccver by bitscore coloured by pident. Hover shows blast match."/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
138 <param name="outputimagetype" value="short_html"/>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
139 </test>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
140 </tests>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
141 <help><![CDATA[
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
142
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
143 This is a specialised version of a generic tabular file plotter tool plotlytabular
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
144
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
145 PNG image outputs are not interactive but best for very large numbers of data points. Hover column will be ignored.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
146
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
147 HTML interactive plots are best for a few thousand data points at most because
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
148
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
149 the hover information becomes uncontrollable with very dense points.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
150
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
151 Using the shorter format HTML relies on internet access when viewed, and saves 3MB of javascript being embedded.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
152
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
153 The long format is useful if potentially viewed offline.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
154
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
155
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
156
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
157 .. class:: warningmark
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
158
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
160
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
161
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
162
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
163 .. class:: warningmark
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
164
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
165 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.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
166
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
167
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
168
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
169 ----
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
170
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
171
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
172
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
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.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
174
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
175
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
176
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
177 Assumes you want a hover display for an interactive plot to be informative
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
178
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
179
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
180
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
181 Column names are auto-generated as col1,...coln unless a comma separated list of column names is supplied as the header parameter.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
182
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
183
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
184
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
185 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.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
186
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
187 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
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
188
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
189
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
190
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
191 When a header is supplied, the xcol and other column names must match one of those supplied column names.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
192
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
193 So for example, xcol = "qaccver" for the blastn header example rather than xcol = "col1" when no header is supplied.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
194
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
195
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
196
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
197 Relies on Plotly python code released under the MIT licence: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
198
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
199
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
200
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
201
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
202
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
203
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
204
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
205 ------
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
206
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
207
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
208 Script::
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
209
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
210 import argparse
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
211 import shutil
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
212 import sys
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
213 import math
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
214 import plotly.express as px
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
215 import pandas as pd
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
216 # Ross Lazarus July 2023
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
217 # based on various plotly tutorials
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
218 # Expects a blastn search result passed in as the first command line parameter.
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
219 parser = argparse.ArgumentParser()
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
220 a = parser.add_argument
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
221 a('--input_tab',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
222 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')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
223 a('--htmlout',default="test_run.html")
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
224 a('--xcol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
225 a('--ycol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
226 a('--colourcol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
227 a('--hovercol',default='')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
228 a('--title',default='test blast plot')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
229 a('--image_type',default='short_html')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
230 args = parser.parse_args()
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
231 df = pd.read_csv(args.input_tab, sep='\t')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
232 NCOLS = df.columns.size
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
233 MAXLEN = 30 # tricky way to truncate long axis tickmarks
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
234 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
235 if len(args.header.strip()) > 0:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
236 newcols = args.header.split(',')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
237 if len(newcols) == NCOLS:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
238 df.columns = newcols
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
239 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
240 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))
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
241 df.columns = defaultcols
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
242 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
243 df.columns = defaultcols
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
244 df['evalue'] = [-math.log(x + 1e-308) for x in df['evalue']] # convert so large values reflect statistical surprise
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
245 if len(args.colourcol.strip()) == 0:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
246 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
247 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
248 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
249 if args.title:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
250 ftitle=dict(text=args.title, font=dict(size=40))
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
251 fig.update_layout(title=ftitle)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
252 for scatter in fig.data:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
253 scatter['x'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['x']]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
254 scatter['y'] = [str(x)[:MAXLEN] + '..' if len(str(x)) > MAXLEN else x for x in scatter['y']]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
255 if len(args.colourcol.strip()) == 0:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
256 sl = str(scatter['legendgroup'])
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
257 if len(sl) > MAXLEN:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
258 scatter['legendgroup'] = sl[:MAXLEN]
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
259 if args.image_type == "short_html":
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
260 fig.write_html(args.htmlout, full_html=False, include_plotlyjs='cdn')
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
261 elif args.image_type == "long_html":
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
262 fig.write_html(args.htmlout)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
263 elif args.image_type == "small_png":
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
264 ht = 768
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
265 wdth = 1024
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
266 fig.write_image('plotly.png', height=ht, width=wdth)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
267 shutil.copyfile('plotly.png', args.htmlout)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
268 else:
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
269 ht = 1200
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
270 wdth = 1920
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
271 fig.write_image('plotly.png', height=ht, width=wdth)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
272 shutil.copyfile('plotly.png', args.htmlout)
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
273
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
274 ]]></help>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
275 <citations>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
276 <citation type="doi">10.1093/bioinformatics/bts573</citation>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
277 </citations>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
278 </tool>
bb99f2c0e358 Updated by regenerating with latest ToolFactory revision
fubar
parents:
diff changeset
279