comparison plotly_tabular_tool/plotlytabular.xml @ 1:449c918bc4cd draft

Uploaded
author fubar
date Fri, 28 Jul 2023 03:44:26 +0000
parents 7c166107a2e2
children 08cc7a481af8
comparison
equal deleted inserted replaced
0:7c166107a2e2 1:449c918bc4cd
1 <tool name="plotlytabular" id="plotlytabular" version="3.0"> 1 <tool name="plotlytabular" id="plotlytabular" 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 27/07/2023 18:47:26 using the Galaxy Tool Factory.--> 3 <!--Created by toolfactory@galaxy.org at 28/07/2023 13:36:22 using the Galaxy Tool Factory.-->
4 <description>Plotly plot generator</description> 4 <description>Plotly plot generator</description>
5 <requirements> 5 <requirements>
6 <requirement version="1.5.3" type="package">pandas</requirement> 6 <requirement version="1.5.3" type="package">pandas</requirement>
7 <requirement version="5.9.0" type="package">plotly</requirement> 7 <requirement version="5.9.0" type="package">plotly</requirement>
8 </requirements> 8 </requirements>
47 a('--ycol',default='') 47 a('--ycol',default='')
48 a('--colourcol',default='') 48 a('--colourcol',default='')
49 a('--hovercol',default='') 49 a('--hovercol',default='')
50 a('--title',default='Default plot title') 50 a('--title',default='Default plot title')
51 args = parser.parse_args() 51 args = parser.parse_args()
52 isColour = False
53 isHover = False
54 if len(args.colourcol.strip()) > 0:
55 isColour = True
56 if len(args.hovercol.strip()) > 0:
57 isHover = True
52 df = pd.read_csv(args.input_tab, sep='\t') 58 df = pd.read_csv(args.input_tab, sep='\t')
53 MAXLEN=35 59 MAXLEN=35
54 NCOLS = df.columns.size 60 NCOLS = df.columns.size
55 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] 61 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
62 testcols = df.columns
56 if len(args.header.strip()) > 0: 63 if len(args.header.strip()) > 0:
57 newcols = args.header.split(',') 64 newcols = args.header.split(',')
58 if len(newcols) == NCOLS: 65 if len(newcols) == NCOLS:
59 df.columns = newcols 66 df.columns = newcols
60 else: 67 else:
61 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)) 68 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 df.columns = defaultcols 69 df.columns = defaultcols
63 else: 70 else: # no header supplied - check for a real one that matches the x and y axis column names
64 df.columns = defaultcols 71 colsok = (args.xcol in testcols) and (args.ycol in testcols) # if they match, probably ok...should use more code and logic..
72 if not colsok:
73 sys.stderr.write('replacing supplied header %s over existing %s' % (testcols, defaultcols))
74 df.columns = defaultcols
65 #df['col11'] = [-math.log(x) for x in df['col11']] # convert so large values reflect statistical surprise 75 #df['col11'] = [-math.log(x) for x in df['col11']] # convert so large values reflect statistical surprise
66 isColour = False
67 isHover = False
68 if len(args.colourcol.strip()) > 0:
69 isColour = True
70 if len(args.hovercol.strip()) > 0:
71 isHover = True
72 if isHover and isColour: 76 if isHover and isColour:
73 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) 77 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
74 elif isHover: 78 elif isHover:
75 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) 79 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
76 elif isColour: 80 elif isColour:
92 96
93 #end raw]]></configfile> 97 #end raw]]></configfile>
94 </configfiles> 98 </configfiles>
95 <inputs> 99 <inputs>
96 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/> 100 <param name="input_tab" type="data" optional="false" label="Tabular input file to plot" help="" format="tabular" multiple="false"/>
97 <param name="xcol" type="text" value="col1" label="x axis for plat" help=""/> 101 <param name="xcol" type="text" value="sepal_length" label="x axis for plot" help=""/>
98 <param name="ycol" type="text" value="col12" label="y axis for plot" help=""/> 102 <param name="ycol" type="text" value="sepal_width" label="y axis for plot" help=""/>
99 <param name="colourcol" type="text" value="col2" label="column containing a groupable variable for colour. Default none." help="Adds a legend so choose wisely "/> 103 <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 "/>
100 <param name="hovercol" type="text" value="col21" label="columname for hover string" help=""/> 104 <param name="hovercol" type="text" value="species_id" label="columname for hover string" help=""/>
101 <param name="title" type="text" value="default title" label="Title for the plot" help="Special characters will probably be escaped so do not use them"/> 105 <param name="title" type="text" value="Iris data sepal length by sepal width coloured by petal width with species_id as the hover column" label="Title for the plot" help="Special characters will probably be escaped so do not use them"/>
102 <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="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."/> 106 <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="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."/>
103 </inputs> 107 </inputs>
104 <outputs> 108 <outputs>
105 <data name="htmlout" format="html" label="htmlout" hidden="false"/> 109 <data name="htmlout" format="html" label="htmlout" hidden="false"/>
106 </outputs> 110 </outputs>
107 <tests> 111 <tests>
108 <test> 112 <test>
109 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/> 113 <output name="htmlout" value="htmlout_sample" compare="sim_size" delta="5000"/>
110 <param name="input_tab" value="input_tab_sample"/> 114 <param name="input_tab" value="input_tab_sample"/>
111 <param name="xcol" value="col1"/> 115 <param name="xcol" value="sepal_length"/>
112 <param name="ycol" value="col12"/> 116 <param name="ycol" value="sepal_width"/>
113 <param name="colourcol" value="col2"/> 117 <param name="colourcol" value="petal_width"/>
114 <param name="hovercol" value="col21"/> 118 <param name="hovercol" value="species_id"/>
115 <param name="title" value="default title"/> 119 <param name="title" value="Iris data sepal length by sepal width coloured by petal width with species_id as the hover column"/>
116 <param name="header" value=""/> 120 <param name="header" value=""/>
117 </test> 121 </test>
118 </tests> 122 </tests>
119 <help><![CDATA[ 123 <help><![CDATA[
120 124
195 a('--ycol',default='') 199 a('--ycol',default='')
196 a('--colourcol',default='') 200 a('--colourcol',default='')
197 a('--hovercol',default='') 201 a('--hovercol',default='')
198 a('--title',default='Default plot title') 202 a('--title',default='Default plot title')
199 args = parser.parse_args() 203 args = parser.parse_args()
204 isColour = False
205 isHover = False
206 if len(args.colourcol.strip()) > 0:
207 isColour = True
208 if len(args.hovercol.strip()) > 0:
209 isHover = True
200 df = pd.read_csv(args.input_tab, sep='\t') 210 df = pd.read_csv(args.input_tab, sep='\t')
201 MAXLEN=35 211 MAXLEN=35
202 NCOLS = df.columns.size 212 NCOLS = df.columns.size
203 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)] 213 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
214 testcols = df.columns
204 if len(args.header.strip()) > 0: 215 if len(args.header.strip()) > 0:
205 newcols = args.header.split(',') 216 newcols = args.header.split(',')
206 if len(newcols) == NCOLS: 217 if len(newcols) == NCOLS:
207 df.columns = newcols 218 df.columns = newcols
208 else: 219 else:
209 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)) 220 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))
210 df.columns = defaultcols 221 df.columns = defaultcols
211 else: 222 else: # no header supplied - check for a real one that matches the x and y axis column names
212 df.columns = defaultcols 223 colsok = (args.xcol in testcols) and (args.ycol in testcols) # if they match, probably ok...should use more code and logic..
224 if not colsok:
225 sys.stderr.write('replacing supplied header %s over existing %s' % (testcols, defaultcols))
226 df.columns = defaultcols
213 #df['col11'] = [-math.log(x) for x in df['col11']] # convert so large values reflect statistical surprise 227 #df['col11'] = [-math.log(x) for x in df['col11']] # convert so large values reflect statistical surprise
214 isColour = False
215 isHover = False
216 if len(args.colourcol.strip()) > 0:
217 isColour = True
218 if len(args.hovercol.strip()) > 0:
219 isHover = True
220 if isHover and isColour: 228 if isHover and isColour:
221 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol) 229 fig = px.scatter(df, x=args.xcol, y=args.ycol, color=args.colourcol, hover_name=args.hovercol)
222 elif isHover: 230 elif isHover:
223 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol) 231 fig = px.scatter(df, x=args.xcol, y=args.ycol, hover_name=args.hovercol)
224 elif isColour: 232 elif isColour: