comparison msi_spectra_plots.xml @ 6:2e0368a6bfe8 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_spectra_plots commit 5bceedc3a11c950790692a4c64bbb83d46897bee
author galaxyp
date Tue, 24 Jul 2018 04:53:42 -0400
parents 4f13aec6d8ff
children 7d94faee0731
comparison
equal deleted inserted replaced
5:4f13aec6d8ff 6:2e0368a6bfe8
1 <tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.3"> 1 <tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.4">
2 <description> 2 <description>
3 mass spectrometry imaging mass spectra plots 3 mass spectrometry imaging mass spectra plots
4 </description> 4 </description>
5 <requirements> 5 <requirements>
6 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement> 6 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement>
150 pdf("mzplots.pdf", fonts = "Times", pointsize = 12) 150 pdf("mzplots.pdf", fonts = "Times", pointsize = 12)
151 plot(0,type='n',axes=FALSE,ann=FALSE) 151 plot(0,type='n',axes=FALSE,ann=FALSE)
152 #if not $filename: 152 #if not $filename:
153 #set $filename = $infile.display_name 153 #set $filename = $infile.display_name
154 #end if 154 #end if
155 title(main=paste0("Plotted mass spectra for file: \n\n","$filename")) 155 title(main=paste0("Mass spectra for file: \n\n","$filename"))
156 156
157 157
158 ############################# I) numbers ###################################### 158 ############################# I) numbers ######################################
159 ############################################################################### 159 ###############################################################################
160 160
217 ########################################################################### 217 ###########################################################################
218 218
219 #elif str( $pixel_conditional.pixel_type) == 'sample_pixel': 219 #elif str( $pixel_conditional.pixel_type) == 'sample_pixel':
220 print("sample pixels") 220 print("sample pixels")
221 221
222 ## optional annotation from tabular file to obtain pixel groups (otherwise all pixels are considered to be one sample)
223
224 #if str($pixel_conditional.tabular_annotation.load_annotation) == 'yes_annotation':
225
226 ## read and extract x,y,annotation information
227 input_tabular = read.delim("$pixel_conditional.tabular_annotation.annotation_file", header = $pixel_conditional.tabular_annotation.tabular_header, stringsAsFactors = FALSE)
228 annotation_input = input_tabular[,c($pixel_conditional.tabular_annotation.column_x, $pixel_conditional.tabular_annotation.column_y, $pixel_conditional.tabular_annotation.column_names)]
229 colnames(annotation_input) = c("x", "y", "annotation")
230
231 ## merge with coordinate information of msidata
232 msidata_coordinates = cbind(coord(msidata)[,1:2], c(1:ncol(msidata)))
233 colnames(msidata_coordinates)[3] = "pixel_index"
234 merged_annotation = merge(msidata_coordinates, annotation_input, by=c("x", "y"), all.x=TRUE)
235 merged_annotation[is.na(merged_annotation)] = "NA"
236 merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),]
237 msidata\$annotation = as.factor(merged_annotation[,4])
238
239 #end if
240
222 ##################### I) Sample: plot full mass spectrum ############## 241 ##################### I) Sample: plot full mass spectrum ##############
223 242
224 ## coloured plot with mean over all spectra for combined_sample, otherwise only 1 black plot 243 ## coloured plot with mean over all spectra with the same annotation, if no annotation is provided all pixels are considered as one sample
225 if (!is.null(levels(msidata\$combined_sample))){ 244
226 print("combined samples") 245 if (!is.null(levels(msidata\$annotation))){
227 246 print("annotated samples")
228 ## overview plot over combined sample, in case more than 10 combined_samples legend has to be taken from this plot 247
229 number_combined = length(levels(msidata\$combined_sample)) 248 ## overview plot over annotated samples
230 249 number_combined = length(levels(msidata\$annotation))
231 ## the more combined_samples a file has the smaller will be the legend 250
251 ## the more annotation groups a file has the smaller will be the legend
232 if (number_combined<20){ 252 if (number_combined<20){
233 legend_size = 10 253 legend_size = 10
234 }else if (number_combined>20 && number_combined<40){ 254 }else if (number_combined>20 && number_combined<40){
235 legend_size = 9 255 legend_size = 9
236 }else if (number_combined>40 && number_combined<60){ 256 }else if (number_combined>40 && number_combined<60){
239 legend_size = 7 259 legend_size = 7
240 }else{ 260 }else{
241 legend_size = 6 261 legend_size = 6
242 } 262 }
243 263
244 position_df = cbind(coord(msidata)[,1:2], msidata\$combined_sample) 264 position_df = cbind(coord(msidata)[,1:2], msidata\$annotation)
245 colnames(position_df)[3] = "sample_name" 265 colnames(position_df)[3] = "sample_name"
246 266
247 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+ 267 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+
248 geom_tile() + 268 geom_tile() +
249 coord_fixed()+ 269 coord_fixed()+
250 ggtitle("Spatial orientation of combined data")+ 270 ggtitle("Spatial orientation of annotated data")+
251 theme_bw()+ 271 theme_bw()+
252 theme(plot.title = element_text(hjust = 0.5))+ 272 theme(plot.title = element_text(hjust = 0.5))+
253 theme(text=element_text(family="ArialMT", face="bold", size=12))+ 273 theme(text=element_text(family="ArialMT", face="bold", size=12))+
254 theme(legend.position="bottom",legend.direction="vertical")+ 274 theme(legend.position="bottom",legend.direction="vertical")+
255 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = legend_size))+ 275 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = legend_size))+
256 guides(fill=guide_legend(ncol=5,byrow=TRUE)) 276 guides(fill=guide_legend(ncol=5,byrow=TRUE))
257 coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean)
258 coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$sample_name)
259 for(file_count in 1:nrow(coord_labels))
260 {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"],
261 y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4]))}
262 277
263 print(combine_plot) 278 print(combine_plot)
264 279
265 ## print legend only for less than 10 samples 280 ## print legend only for less than 10 samples
266 if (length(levels(msidata\$combined_sample)) < 10){ 281 if (length(levels(msidata\$annotation)) < 10){
267 key_legend = TRUE 282 key_legend = TRUE
268 }else{key_legend = FALSE} 283 }else{key_legend = FALSE}
269 284
270 spectra(msidata) = is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero 285 is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero
271 286 plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(levels(msidata\$annotation))),superpose=TRUE)
272 plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$combined_sample, key=key_legend, col=hue_pal()(length(levels(msidata\$combined_sample))),superpose=TRUE)
273 }else{ 287 }else{
274 spectra(msidata) = is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero 288 is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero
275 plot(msidata, pixel=1:ncol(msidata), key=TRUE)} 289 plot(msidata, pixel=1:ncol(msidata), key=TRUE)}
276 290
277 ##################### II) Sample: plot zoom-in mass spectrum ########## 291 ##################### II) Sample: plot zoom-in mass spectrum ##########
278 292
279 #if $pixel_conditional.zoomed_sample: 293 #if $pixel_conditional.zoomed_sample:
282 print("zoomed sample pixels") 296 print("zoomed sample pixels")
283 297
284 minmasspixel = features(msidata, mz=$token.xlimmin) 298 minmasspixel = features(msidata, mz=$token.xlimmin)
285 maxmasspixel = features(msidata, mz=$token.xlimmax) 299 maxmasspixel = features(msidata, mz=$token.xlimmax)
286 300
287 ## coloured plot with mean over all spectra for combined_sample, otherwise only 1 black plot 301 ## coloured plot with mean over all spectra for annotation group, otherwise only 1 black plot
288 if (!is.null(levels(msidata\$combined_sample))){ 302 if (!is.null(levels(msidata\$annotation))){
289 print("combined samples") 303 print("annotation samples")
290 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), 304 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata),
291 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$combined_sample, 305 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation,
292 key=key_legend,col=hue_pal()(length(levels(msidata\$combined_sample))), superpose=TRUE) 306 key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE)
293 }else{ 307 }else{
294 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))} 308 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))}
295 309
296 #end for 310 #end for
297 #end if 311 #end if
298 312
299 if (!is.null(levels(msidata\$combined_sample))){ 313 if (!is.null(levels(msidata\$annotation))){
300 pixeldf = data.frame(table(msidata\$combined_sample)) 314 pixeldf = data.frame(table(msidata\$annotation))
301 }else{ 315 }else{
302 pixeldf = data.frame("$filename", ncol(msidata))} 316 pixeldf = data.frame("$filename", ncol(msidata))}
303 colnames(pixeldf) = c("sample name", "number of pixels") 317 colnames(pixeldf) = c("sample name", "number of pixels")
304 318
305 #end if 319 #end if
311 325
312 ### overview table of pixels or samples: 326 ### overview table of pixels or samples:
313 plot(0,type='n',axes=FALSE,ann=FALSE) 327 plot(0,type='n',axes=FALSE,ann=FALSE)
314 title(main="Overview of chosen pixel:") 328 title(main="Overview of chosen pixel:")
315 329
316 ### for more than 20 combined samples print only 20 samples per page: 330 ### for more than 20 annotation groups print only 20 samples per page:
317 if (is.null(levels(msidata\$combined_sample))){ 331 if (is.null(levels(msidata\$annotation))){
318 grid.table(pixeldf, rows= NULL) 332 grid.table(pixeldf, rows= NULL)
319 }else if (length(levels(msidata\$combined_sample)) <= 20){ 333 }else if (length(levels(msidata\$annotation)) <= 20){
320 grid.table(pixeldf, rows= NULL) 334 grid.table(pixeldf, rows= NULL)
321 }else{ 335 }else{
322 grid.table(pixeldf[1:20,], rows= NULL) 336 grid.table(pixeldf[1:20,], rows= NULL)
323 mincount = 21 337 mincount = 21
324 maxcount = 40 338 maxcount = 40
366 </param> 380 </param>
367 <when value="single_pixel"> 381 <when value="single_pixel">
368 <repeat name="repeatpixel" title="Plot mass spectra for pixel of interest" min="1" max="20"> 382 <repeat name="repeatpixel" title="Plot mass spectra for pixel of interest" min="1" max="20">
369 <param name="inputx" type="integer" value="" label="x-coordinate of pixel of interest" help="x-value of the pixel of interest"/> 383 <param name="inputx" type="integer" value="" label="x-coordinate of pixel of interest" help="x-value of the pixel of interest"/>
370 <param name="inputy" type="integer" value="" label="y-coordinate of pixel of interest" help="y-value of the pixel of interest"/> 384 <param name="inputy" type="integer" value="" label="y-coordinate of pixel of interest" help="y-value of the pixel of interest"/>
371 <param name="inputmz" type="float" value="1296.7" label="Next parameters are to control heatmap image which will be plotted, here m/z in Dalton" help="m/z will be displayed as heatmap and the pixel of interest will be visualized by the intersection of two lines"/> 385 <param name="inputmz" type="float" value="1296.7" label="Next parameters are to control heatmap image which will be plotted, define m/z here" help="m/z will be displayed as heatmap and the pixel of interest will be visualized by the intersection of two lines"/>
372 <param name="plusminusinDalton" value="0.25" type="float" label="m/z range for this m/z value" help="plusminus m/z window in Dalton"/> 386 <param name="plusminusinDalton" value="0.25" type="float" label="m/z range for this m/z value" help="plusminus m/z window "/>
373 <param name="inputcolour" type="select" label="select the colour for the lines at x and y position"> 387 <param name="inputcolour" type="select" label="select the colour for the lines at x and y position">
374 <option value="white" selected="True">white</option> 388 <option value="white" selected="True">white</option>
375 <option value="black">black</option> 389 <option value="black">black</option>
376 <option value="grey">grey</option> 390 <option value="grey">grey</option>
377 <option value="blue">blue</option> 391 <option value="blue">blue</option>
384 <option value="dotted">dotted</option> 398 <option value="dotted">dotted</option>
385 <option value="longdash">longdash</option> 399 <option value="longdash">longdash</option>
386 </param> 400 </param>
387 <param name="inputwidth" type="integer" value="2" label="select the width of the lines at x and y position"/> 401 <param name="inputwidth" type="integer" value="2" label="select the width of the lines at x and y position"/>
388 <repeat name="zoomedplot" title="Zoomed in plots with m/z min and m/z max to define the plot window" min="0" max="50"> 402 <repeat name="zoomedplot" title="Zoomed in plots with m/z min and m/z max to define the plot window" min="0" max="50">
389 <param name="xlimmin" type="integer" value="" label="lower boundary in Dalton for plotting window" help="minimum m/z for zoomed in window"/> 403 <param name="xlimmin" type="integer" value="" label="lower m/z boundary for plotting window" help="minimum m/z for zoomed in window"/>
390 <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum m/z for zoomed in window"/> 404 <param name="xlimmax" type="integer" value="" label="upper m/z boundary for plotting window" help="maximum m/z for zoomed in window"/>
391 </repeat> 405 </repeat>
392 </repeat> 406 </repeat>
393 </when> 407 </when>
394 <when value="sample_pixel"> 408 <when value="sample_pixel">
409 <conditional name="tabular_annotation">
410 <param name="load_annotation" type="select" label="Use pixel annotation from tabular file for spectra plots">
411 <option value="no_annotation" selected="True">pixels belong into one group only</option>
412 <option value="yes_annotation">group pixels according to annotations</option>
413 </param>
414 <when value="yes_annotation">
415 <param name="annotation_file" type="data" format="tabular" label="Use annotations from tabular file"
416 help="Tabular file with three columns: x values, y values and pixel annotations"/>
417 <param name="column_x" data_ref="annotation_file" label="Column with x values" type="data_column"/>
418 <param name="column_y" data_ref="annotation_file" label="Column with y values" type="data_column"/>
419 <param name="column_names" data_ref="annotation_file" label="Column with pixel annotations" type="data_column"/>
420 <param name="tabular_header" type="boolean" label="Tabular file contains a header line" truevalue="TRUE" falsevalue="FALSE"/>
421 </when>
422 <when value="no_annotation"/>
423 </conditional>
395 <repeat name="zoomed_sample" title="Zoomed in plots with m/z min and m/z max to define the plot window" min="0" max="50"> 424 <repeat name="zoomed_sample" title="Zoomed in plots with m/z min and m/z max to define the plot window" min="0" max="50">
396 <param name="xlimmin" type="integer" value="" label="lower boundary in Dalton for plotting window" help="minimum m/z for zoomed in window"/> 425 <param name="xlimmin" type="integer" value="" label="lower m/z boundary for plotting window" help="minimum m/z for zoomed in window"/>
397 <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum m/z for zoomed in window"/> 426 <param name="xlimmax" type="integer" value="" label="upper m/z boundary for plotting window" help="maximum m/z for zoomed in window"/>
398 </repeat> 427 </repeat>
399 </when> 428 </when>
400 </conditional> 429 </conditional>
401 </inputs> 430 </inputs>
402 <outputs> 431 <outputs>
471 <composite_data value="Analyze75.img"/> 500 <composite_data value="Analyze75.img"/>
472 <composite_data value="Analyze75.t2m"/> 501 <composite_data value="Analyze75.t2m"/>
473 </param> 502 </param>
474 <conditional name="pixel_conditional"> 503 <conditional name="pixel_conditional">
475 <param name="pixel_type" value="sample_pixel"/> 504 <param name="pixel_type" value="sample_pixel"/>
476 <repeat name="zoomed_sample"> 505 <conditional name="tabular_annotation">
477 <param name="xlimmin" value="1250"/> 506 <param name="load_annotation" value="yes_annotation"/>
478 <param name="xlimmax" value="1270"/> 507 <param name="annotation_file" value="annotations.tabular" ftype="tabular"/>
479 </repeat> 508 <param name="column_x" value="1"/>
509 <param name="column_y" value="2"/>
510 <param name="column_names" value="4"/>
511 <param name="tabular_header" value="TRUE"/>
512 </conditional>
513 <repeat name="zoomed_sample">
514 <param name="xlimmin" value="1250"/>
515 <param name="xlimmax" value="1270"/>
516 </repeat>
480 </conditional> 517 </conditional>
481 <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size" delta="20000"/> 518 <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size" delta="20000"/>
482 </test> 519 </test>
483 <test> 520 <test>
484 <param name="infile" value="123_combined.RData" ftype="rdata"/> 521 <param name="infile" value="123_combined.RData" ftype="rdata"/>
521 - "single pixel": Returns a full mass spectrum plot for one pixel, which is defined by its x- and y-coordinates 558 - "single pixel": Returns a full mass spectrum plot for one pixel, which is defined by its x- and y-coordinates
522 559
523 - Enter the x and y coordinates of your pixel of interest 560 - Enter the x and y coordinates of your pixel of interest
524 - To have a visual control for the selected pixel, a heatmap of a m/z of interest will be drawn. Two intersecting lines will show the pixel location. This procedure requires an m/z of interest together with a m/z range and for the lines the colour and type. 561 - To have a visual control for the selected pixel, a heatmap of a m/z of interest will be drawn. Two intersecting lines will show the pixel location. This procedure requires an m/z of interest together with a m/z range and for the lines the colour and type.
525 - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot 562 - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot
526 - "All pixels of a sample": Returns a full average mass spectrum plot with different colours for the sample/each combined sample 563 - "All pixels of a sample": Returns a full average mass spectrum plot with different colours for each pixel annotation group, without annotations the average of all pixels is plotted
527
528 - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot 564 - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot
529 565
530 Output: 566 Output:
531 567
532 - Pdf with the selected mass spectra plots and additional control plots 568 - Pdf with the selected mass spectra plots and additional control plots