changeset 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
files msi_spectra_plots.xml test-data/Plot_analyze75.pdf test-data/Plot_analyze75_allpixels.pdf test-data/Plot_empty_spectra.pdf test-data/Plot_imzml.pdf test-data/Plot_rdata.pdf test-data/annotations.tabular
diffstat 7 files changed, 88 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/msi_spectra_plots.xml	Fri Jul 06 14:14:41 2018 -0400
+++ b/msi_spectra_plots.xml	Tue Jul 24 04:53:42 2018 -0400
@@ -1,4 +1,4 @@
-<tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.3">
+<tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.4">
     <description>
         mass spectrometry imaging mass spectra plots
     </description>
@@ -152,7 +152,7 @@
 #if not $filename:
     #set $filename = $infile.display_name
 #end if
-title(main=paste0("Plotted mass spectra for file: \n\n","$filename"))
+title(main=paste0("Mass spectra for file: \n\n","$filename"))
 
 
 ############################# I) numbers ######################################
@@ -219,16 +219,36 @@
     #elif str( $pixel_conditional.pixel_type) == 'sample_pixel':
         print("sample pixels")
 
+        ## optional annotation from tabular file to obtain pixel groups (otherwise all pixels are considered to be one sample)
+
+        #if str($pixel_conditional.tabular_annotation.load_annotation) == 'yes_annotation':
+
+            ## read and extract x,y,annotation information
+            input_tabular = read.delim("$pixel_conditional.tabular_annotation.annotation_file", header = $pixel_conditional.tabular_annotation.tabular_header, stringsAsFactors = FALSE)
+            annotation_input = input_tabular[,c($pixel_conditional.tabular_annotation.column_x, $pixel_conditional.tabular_annotation.column_y, $pixel_conditional.tabular_annotation.column_names)]
+            colnames(annotation_input) = c("x", "y", "annotation")
+
+            ## merge with coordinate information of msidata
+            msidata_coordinates = cbind(coord(msidata)[,1:2], c(1:ncol(msidata)))
+            colnames(msidata_coordinates)[3] = "pixel_index"
+            merged_annotation = merge(msidata_coordinates, annotation_input, by=c("x", "y"), all.x=TRUE)
+            merged_annotation[is.na(merged_annotation)] = "NA"
+            merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),]
+            msidata\$annotation = as.factor(merged_annotation[,4])
+
+        #end if
+
         ##################### I) Sample: plot full mass spectrum ##############
 
-        ## coloured plot with mean over all spectra for combined_sample, otherwise only 1 black plot
-        if (!is.null(levels(msidata\$combined_sample))){
-            print("combined samples")
+        ## coloured plot with mean over all spectra with the same annotation, if no annotation is provided all pixels are considered as one sample
+
+        if (!is.null(levels(msidata\$annotation))){
+            print("annotated samples")
 
-                    ## overview plot over combined sample, in case more than 10 combined_samples legend has to be taken from this plot
-                    number_combined = length(levels(msidata\$combined_sample))
+                    ## overview plot over annotated samples
+                    number_combined = length(levels(msidata\$annotation))
 
-                    ## the more combined_samples a file has the smaller will be the legend
+                    ## the more annotation groups a file has the smaller will be the legend
                     if (number_combined<20){
                         legend_size = 10
                     }else if (number_combined>20 && number_combined<40){
@@ -241,37 +261,31 @@
                         legend_size = 6
                     }
 
-                    position_df = cbind(coord(msidata)[,1:2], msidata\$combined_sample)
+                    position_df = cbind(coord(msidata)[,1:2], msidata\$annotation)
                     colnames(position_df)[3] = "sample_name"
 
                     combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+
                            geom_tile() +
                            coord_fixed()+
-                           ggtitle("Spatial orientation of combined data")+
+                           ggtitle("Spatial orientation of annotated data")+
                            theme_bw()+
                            theme(plot.title = element_text(hjust = 0.5))+
                            theme(text=element_text(family="ArialMT", face="bold", size=12))+
                            theme(legend.position="bottom",legend.direction="vertical")+
                            theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = legend_size))+
                            guides(fill=guide_legend(ncol=5,byrow=TRUE))
-                    coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean)
-                    coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$sample_name)
-                    for(file_count in 1:nrow(coord_labels))
-                        {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"],
-                        y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4]))}
 
                     print(combine_plot)
 
                     ## print legend only for less than 10 samples
-                    if (length(levels(msidata\$combined_sample)) < 10){
+                    if (length(levels(msidata\$annotation)) < 10){
                         key_legend = TRUE
                     }else{key_legend = FALSE}
 
-            spectra(msidata) = is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero
-
-            plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$combined_sample, key=key_legend, col=hue_pal()(length(levels(msidata\$combined_sample))),superpose=TRUE)
+            is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero
+            plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(levels(msidata\$annotation))),superpose=TRUE)
         }else{
-            spectra(msidata) = is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero
+            is.na(spectra(msidata)[]) == 0 ## in case of NA values they will be set to zero
             plot(msidata, pixel=1:ncol(msidata), key=TRUE)}
 
         ##################### II) Sample: plot zoom-in mass spectrum ##########
@@ -284,20 +298,20 @@
                 minmasspixel = features(msidata, mz=$token.xlimmin)
                 maxmasspixel = features(msidata, mz=$token.xlimmax)
 
-                ## coloured plot with mean over all spectra for combined_sample, otherwise only 1 black plot
-                if (!is.null(levels(msidata\$combined_sample))){
-                    print("combined samples")
+                ## coloured plot with mean over all spectra for annotation group, otherwise only 1 black plot
+                if (!is.null(levels(msidata\$annotation))){
+                    print("annotation samples")
                     plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata),
-                    xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$combined_sample,
-                    key=key_legend,col=hue_pal()(length(levels(msidata\$combined_sample))), superpose=TRUE)
+                    xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation,
+                    key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE)
                 }else{
                     plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))}
 
             #end for
         #end if
 
-        if (!is.null(levels(msidata\$combined_sample))){
-            pixeldf = data.frame(table(msidata\$combined_sample))
+        if (!is.null(levels(msidata\$annotation))){
+            pixeldf = data.frame(table(msidata\$annotation))
         }else{
             pixeldf = data.frame("$filename", ncol(msidata))}
         colnames(pixeldf) = c("sample name", "number of pixels")
@@ -313,10 +327,10 @@
     plot(0,type='n',axes=FALSE,ann=FALSE)
     title(main="Overview of chosen pixel:")
 
-    ### for more than 20 combined samples print only 20 samples per page:
-    if (is.null(levels(msidata\$combined_sample))){
+    ### for more than 20 annotation groups print only 20 samples per page:
+    if (is.null(levels(msidata\$annotation))){
         grid.table(pixeldf, rows= NULL)
-    }else if (length(levels(msidata\$combined_sample)) <= 20){
+    }else if (length(levels(msidata\$annotation)) <= 20){
         grid.table(pixeldf, rows= NULL)
     }else{
         grid.table(pixeldf[1:20,], rows= NULL)
@@ -368,8 +382,8 @@
                 <repeat name="repeatpixel" title="Plot mass spectra for pixel of interest" min="1" max="20">
                     <param name="inputx" type="integer" value="" label="x-coordinate of pixel of interest" help="x-value of the pixel of interest"/>
                     <param name="inputy" type="integer" value="" label="y-coordinate of pixel of interest" help="y-value of the pixel of interest"/>
-                    <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"/>
-                    <param name="plusminusinDalton" value="0.25" type="float" label="m/z range for this m/z value" help="plusminus m/z window in Dalton"/>
+                    <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"/>
+                    <param name="plusminusinDalton" value="0.25" type="float" label="m/z range for this m/z value" help="plusminus m/z window "/>
                     <param name="inputcolour" type="select" label="select the colour for the lines at x and y position">
                         <option value="white" selected="True">white</option>
                         <option value="black">black</option>
@@ -386,15 +400,30 @@
                     </param>
                     <param name="inputwidth" type="integer" value="2" label="select the width of the lines at x and y position"/>
                     <repeat name="zoomedplot" title="Zoomed in plots with m/z min and m/z max to define the plot window" min="0" max="50">
-                        <param name="xlimmin" type="integer" value="" label="lower boundary in Dalton for plotting window" help="minimum m/z for zoomed in window"/>
-                        <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum m/z for zoomed in window"/>
+                        <param name="xlimmin" type="integer" value="" label="lower m/z boundary for plotting window" help="minimum m/z for zoomed in window"/>
+                        <param name="xlimmax" type="integer" value="" label="upper m/z boundary for plotting window" help="maximum m/z for zoomed in window"/>
                     </repeat>
                 </repeat>
             </when>
             <when value="sample_pixel">
+            <conditional name="tabular_annotation">
+                <param name="load_annotation" type="select" label="Use pixel annotation from tabular file for spectra plots">
+                    <option value="no_annotation" selected="True">pixels belong into one group only</option>
+                    <option value="yes_annotation">group pixels according to annotations</option>
+                </param>
+                    <when value="yes_annotation">
+                        <param name="annotation_file" type="data" format="tabular" label="Use annotations from tabular file"
+                        help="Tabular file with three columns: x values, y values and pixel annotations"/>
+                            <param name="column_x" data_ref="annotation_file" label="Column with x values" type="data_column"/>
+                            <param name="column_y" data_ref="annotation_file" label="Column with y values" type="data_column"/>
+                            <param name="column_names" data_ref="annotation_file" label="Column with pixel annotations" type="data_column"/>
+                            <param name="tabular_header" type="boolean" label="Tabular file contains a header line" truevalue="TRUE" falsevalue="FALSE"/>
+                    </when>
+                    <when value="no_annotation"/>
+            </conditional>
                 <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">
-                    <param name="xlimmin" type="integer" value="" label="lower boundary in Dalton for plotting window" help="minimum m/z for zoomed in window"/>
-                    <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum m/z for zoomed in window"/>
+                    <param name="xlimmin" type="integer" value="" label="lower m/z boundary for plotting window" help="minimum m/z for zoomed in window"/>
+                    <param name="xlimmax" type="integer" value="" label="upper m/z boundary for plotting window" help="maximum m/z for zoomed in window"/>
                 </repeat>
             </when>
         </conditional>
@@ -473,10 +502,18 @@
             </param>
             <conditional name="pixel_conditional">
                 <param name="pixel_type" value="sample_pixel"/>
-                    <repeat name="zoomed_sample">
-                         <param name="xlimmin" value="1250"/>
-                         <param name="xlimmax" value="1270"/>
-                     </repeat>
+                <conditional name="tabular_annotation">
+                    <param name="load_annotation" value="yes_annotation"/>
+                    <param name="annotation_file" value="annotations.tabular" ftype="tabular"/>
+                    <param name="column_x" value="1"/>
+                    <param name="column_y" value="2"/>
+                    <param name="column_names" value="4"/>
+                    <param name="tabular_header" value="TRUE"/>
+                </conditional>
+                <repeat name="zoomed_sample">
+                     <param name="xlimmin" value="1250"/>
+                     <param name="xlimmax" value="1270"/>
+                 </repeat>
             </conditional>
             <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size" delta="20000"/>
         </test>
@@ -523,8 +560,7 @@
     - Enter the x and y coordinates of your pixel of interest
     - 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.
     - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot
-- "All pixels of a sample": Returns a full average mass spectrum plot with different colours for the sample/each combined sample
-
+- "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
     - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot
 
 Output:
Binary file test-data/Plot_analyze75.pdf has changed
Binary file test-data/Plot_analyze75_allpixels.pdf has changed
Binary file test-data/Plot_empty_spectra.pdf has changed
Binary file test-data/Plot_imzml.pdf has changed
Binary file test-data/Plot_rdata.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/annotations.tabular	Tue Jul 24 04:53:42 2018 -0400
@@ -0,0 +1,10 @@
+X	Y	file_name	column_name
+1	1	file_one	col1
+1	2	file_one	col1
+1	3	file_one	col1
+2	1	file_one	col2
+2	2	file_one	col2
+2	3	file_one	col2
+3	1	file_one	col3
+3	2	file_one	col3
+3	3	file_one	col3