diff spectra_plots.xml @ 7:64ea4507e0bd draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit f986c51abe33c7f622d429a3c4a79ee24b33c1f3"
author galaxyp
date Thu, 23 Apr 2020 08:05:19 -0400
parents 9b6b86e771c2
children 0b7e00e5b9d2
line wrap: on
line diff
--- a/spectra_plots.xml	Wed Mar 25 05:53:20 2020 -0400
+++ b/spectra_plots.xml	Thu Apr 23 08:05:19 2020 -0400
@@ -1,4 +1,4 @@
-<tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.3">
+<tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.0">
     <description>
         mass spectrometry imaging mass spectra plots
     </description>
@@ -6,7 +6,7 @@
         <import>macros.xml</import>
     </macros>
     <expand macro="requirements">
-        <requirement type="package" version="3.0">r-ggplot2</requirement>
+        <requirement type="package" version="3.2.1">r-ggplot2</requirement>
         <requirement type="package" version="2.3">r-gridextra</requirement>
         <requirement type="package" version="1.0.0">r-scales</requirement>
     </expand>
@@ -28,7 +28,7 @@
 library(scales)
 
 
-@READING_MSIDATA@
+@READING_MSIDATA_FULLY_COMPATIBLE@
 
 @DATA_PROPERTIES@
 
@@ -51,15 +51,6 @@
 
 grid.table(property_df, rows= NULL)
 
-## set NA to 0 otherwise plot function will not work
-
-    #if str($processed_cond.processed_file) == "processed":
-        ##processed file needs to be converted into matrix to be able to replace NAs
-        iData(msidata) <- iData(msidata)[]
-    #end if
-
-    spectra(msidata)[is.na(spectra(msidata))] = 0
-
 ## run only if mz and pixels are > 0
 
 if (ncol(msidata)>0 & nrow(msidata) >0){
@@ -69,90 +60,29 @@
     ############################# single pixel ################################
     ###########################################################################
 
-    #if str( $pixel_conditional.pixel_type) == 'single_pixel':
-        print("single_pixel")
-
-        #for $chosenpixel in $pixel_conditional.repeatpixel: 
-
-            pixelname = paste0("x = ", $chosenpixel.inputx,", ", "y = ", $chosenpixel.inputy)
-
-
-
-        input_pixels = paste($chosenpixel.inputx, $chosenpixel.inputy, sep="_")
-        dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_")
-
-        pixelisvalid = as.character(input_pixels %in% dataset_pixels)
-
-
-
-            pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid))
-
-            ############################# II) control image ####################
+    #if str( $pixel_conditional.pixel_type) == 'tabular_pixel':
+        print("tabular_pixel")
 
-                if (pixelisvalid == "TRUE"){
-
-                    image(msidata, mz=$chosenpixel.inputmz, ylim = c(maximumy+(0.2*maximumy),minimumy-1),
-                    colorkey=FALSE, plusminus = $chosenpixel.plusminusinDalton,
-                    main= paste0("x= ",$chosenpixel.inputx, ", y= ", $chosenpixel.inputy))
-
-                    abline(v=$chosenpixel.inputx, col ="$chosenpixel.inputcolour", lty="$chosenpixel.inputtype", lwd=$chosenpixel.inputwidth)
-                    abline(h=$chosenpixel.inputy, col ="$chosenpixel.inputcolour", lty="$chosenpixel.inputtype", lwd=$chosenpixel.inputwidth)
-
-            ##################### III) plot full mass spectrum #################
+        ## read and extract x,y, optional annotation information
+        spectra_tabular = read.delim("$pixel_conditional.pixel_file", header = $pixel_conditional.tabular_pixel_header, stringsAsFactors = FALSE)
 
-                    plot(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy), main="Mass spectrum of full m/z range")
-
-            ##################### IV) plot zoom-in mass spectrum ###############
+        #if $pixel_conditional.column_pixel_annotation:
 
-                    #if $chosenpixel.zoomedplot:
-
-                        #for $token in $chosenpixel.zoomedplot:
-
-                            minmasspixel = features(msidata, mz=$token.xlimmin)
-                            maxmasspixel = features(msidata, mz=$token.xlimmax)
+                spectra_input = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y, $pixel_conditional.column_pixel_annotation)]
+                colnames(spectra_input) = c("x", "y", "annotation")
 
-                            plot(msidata[minmasspixel:maxmasspixel,], coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy), 
-                                 xlim= c($token.xlimmin,$token.xlimmax))
-
-                        #end for
-                    #end if
-                }else{
-                    print("The pixel coordinates did not correspond to a real pixel")}
-        #end for
-
-    colnames(pixeldf) = c("pixel coordinates", "coordinates were found in this file")
-
-    ############################# sample pixel ################################
-    ###########################################################################
-
-    #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':
+                input_pixels = paste(spectra_input[,1], spectra_input[,2], sep="_")
+                dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_")
+                pixelsofinterest = dataset_pixels %in% input_pixels
+                msidata = msidata[,pixelsofinterest]
 
-            ## 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 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")
+                ## merge with coordinate information of msidata
+                msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y, c(1:ncol(msidata)))
+                colnames(msidata_coordinates) = c("x", "y", "pixel_index")
+                merged_annotation = merge(msidata_coordinates, spectra_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])
 
                     ## overview plot over annotated samples
                     number_combined = length(levels(msidata\$annotation))
@@ -170,13 +100,13 @@
                         legend_size = 6
                     }
 
-                    position_df = cbind(coord(msidata)[,1:2], as.factor(msidata\$annotation))
-                    colnames(position_df)[3] = "sample_name"
+                    position_df = data.frame(coord(msidata)\$x, coord(msidata)\$y, as.factor(msidata\$annotation))
+                    colnames(position_df) = c("x", "y", "sample_name")
 
                     combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+
                            geom_tile(height = 1, width=1)+
                            coord_fixed()+
-                           ggtitle("Spatial orientation of pixel annotations")+
+                           ggtitle("Spatial orientation of annotations")+
                            theme_bw()+
                            theme(plot.title = element_text(hjust = 0.5))+
                            theme(text=element_text(family="ArialMT", face="bold", size=12))+
@@ -198,36 +128,288 @@
                         key_legend = TRUE
                     }else{key_legend = FALSE}
 
-            plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(levels(msidata\$annotation))),superpose=TRUE, main="Average mass spectrum of full m/z range")
-        }else{
-            plot(msidata, pixel=1:ncol(msidata), key=TRUE, main="Average mass spectrum of full m/z range")}
+                #if $fullmz:
+                ## plot single tabular mz, average per annotation
+                    print(plot(msidata, run="infile", pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(levels(msidata\$annotation))),superpose=TRUE, strip=FALSE, grid=$grid_variable), main="Average spectrum per group")
+                #end if
+
+                    pixeldf = data.frame(table(msidata\$annotation))
+                    colnames(pixeldf) = c("sample name", "number of pixels")
+
+
+            ##################### II) Sample: plot zoom-in mass spectrum ##########
+
+                #if str($mz_range.mz_range_options) == "manual_mz":
+
+                    #for $token in $mz_range.zoomed_sample:
+
+
+                minmasspixel = tryCatch(
+                        {
+                        features(msidata, mz=$token.xlimmin)
+                        },
+                        warning=function(cond) {
+                        ## if xlimmin is outside mz range, use min mz value
+                        return(features(msidata, mz=min(mz(msidata))))
+                        }
+                    )    
+
+                maxmasspixel = tryCatch(
+                        {
+                        features(msidata, mz=$token.xlimmax)
+                        },
+                        warning=function(cond) {
+                        ## if xlimax is outside mz range, use max mz value
+                        return(features(msidata, mz=max(mz(msidata))))
+                        }
+                    )   
+
+                        ## plot single tabular mz, average per annotation, manual zoom
+                        print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE,
+                        xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable,
+                        key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE, main="Average spectrum per group"))
+                    #end for
+
+                #elif str($mz_range.mz_range_options) == "tabular_mz":
+
+                    input_mz = read.delim("$mz_range.mz_file", header = $mz_range.tabular_header, stringsAsFactors = FALSE)
+                    input_mz_features = input_mz[,c($mz_range.column_mz)]
+                    for (feature_count in input_mz_features){
+
+                        if (feature_count>min(mz(msidata))&feature_count<max(mz(msidata))){
+
+                            xlimmin = feature_count-$mz_range.minus_mz_tab
+                            xlimmax = feature_count+$mz_range.plus_mz_tab
+
+                            minmasspixel = features(msidata, mz=xlimmin)
+                            maxmasspixel = features(msidata, mz=xlimmax)
+
+                            ## plot single tabular mz, average per annotation, tabular zoom
+                            print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE, main="Average spectrum per group",
+                            xlim= c(xlimmin,xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable,
+                            key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE))
+                        }
+                    }
+
+                #end if
+
+        #elif str($pixel_conditional.column_pixel_annotation)== "None":
+
+                spectra_tabular = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y)]
+                colnames(spectra_tabular) = c("x", "y")
+
+            dataset_pixels = data.frame(coord(msidata)\$x, coord(msidata)\$y)
+            colnames(dataset_pixels) = c("x", "y")
+            spectra_input = merge(dataset_pixels, spectra_tabular, by=c("x", "y"))
+            false_input = merge(spectra_tabular, spectra_input, by=c("x", "y"))
+
+                ## for loop for every valid spectrum (pixel)
+                for (pixel_count in 1:nrow(spectra_input)){
+
+                    x_coord = spectra_input[pixel_count,1]
+                    y_coord = spectra_input[pixel_count,2]
+
+
+            ##################### I) Sample: plot full mass spectrum ##############
+
+                    #if $fullmz:
+                    ## plot full mz for single tabular mz
+                        print(plot(msidata, coord=list(x=x_coord, y=y_coord), key=TRUE, grid = $grid_variable))
+                    #end if
+
+                    pixelname = paste0("x = ", x_coord,", ", "y = ", y_coord)
+
+                    input_pixels = paste(x_coord, y_coord, sep="_")
+                    dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_")
+                    pixelisvalid = as.character(input_pixels %in% dataset_pixels)
+
+                    pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid))
+
+
+            ##################### II) Sample: plot zoom-in mass spectrum ##########
+
+            #if str($mz_range.mz_range_options) == "manual_mz":
+                #for $token in $mz_range.zoomed_sample:
+
+                minmasspixel = tryCatch(
+                        {
+                        features(msidata, mz=$token.xlimmin)
+                        },
+                        warning=function(cond) {
+                        ## if xlimmin is outside mz range, use min mz value
+                        return(features(msidata, mz=min(mz(msidata))))
+                        }
+                    )    
+
+                maxmasspixel = tryCatch(
+                        {
+                        features(msidata, mz=$token.xlimmax)
+                        },
+                        warning=function(cond) {
+                        ## if xlimax is outside mz range, use max mz value
+                        return(features(msidata, mz=max(mz(msidata))))
+                        }
+                    )   
+
+                ## same min and max not possible for plot
+                if (minmasspixel == maxmasspixel){
+                    if (maxmasspixel == nrow(msidata)){
+                        minmasspixel = minmasspixel-1
+                        }else{
+                            maxmasspixel = maxmasspixel+1
+                        }
+                }
+
+                    ## print single tabular mz; manual zoom
+                    print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, coord=list(x=x_coord, y=y_coord), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax)))
+
+                #end for
+
+                #elif str($mz_range.mz_range_options) == "tabular_mz":
+
+                    input_mz = read.delim("$mz_range.mz_file", header = $mz_range.tabular_header, stringsAsFactors = FALSE)
+                    input_mz_features = input_mz[,c($mz_range.column_mz)]
+                    for (feature_count in input_mz_features){
+
+                        if (feature_count>min(mz(msidata))&feature_count<max(mz(msidata))){
+
+                            xlimmin = feature_count-$mz_range.minus_mz_tab
+                            xlimmax = feature_count+$mz_range.plus_mz_tab
+
+                            minmasspixel = tryCatch(
+                                    {
+                                    features(msidata, mz=xlimmin)
+                                    },
+                                    warning=function(cond) {
+                                    ## if xlimmin is outside mz range, use min mz value
+                                    return(features(msidata, mz=min(mz(msidata))))
+                                    }
+                                )    
+
+                            maxmasspixel = tryCatch(
+                                    {
+                                    maxmasspixel = features(msidata, mz=xlimmax)
+                                    },
+                                    warning=function(cond) {
+                                    ## if xlimax is outside mz range, use max mz value
+                                    return(features(msidata, mz=max(mz(msidata))))
+                                    }
+                                )   
+
+                            ## same min and max not possible for plot
+                            if (minmasspixel == maxmasspixel){
+                                if (maxmasspixel == nrow(msidata)){
+                                    minmasspixel = minmasspixel-1
+                                    }else{
+                                        maxmasspixel = maxmasspixel+1
+                                    }
+                            }
+
+                                ## print single tabular mz; tabular zoom
+                                print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, coord=list(x=x_coord, y=y_coord), key=TRUE, xlim= c(xlimmin,xlimmax)))
+                            }
+                        }
+
+                #end if
+
+            }
+
+                    colnames(pixeldf) = c("pixel coordinates", "coordinates were found in this file")
+
+        #end if
+
+
+    ############################# all pixel ################################
+    ###########################################################################
+
+    #elif str( $pixel_conditional.pixel_type) == 'all_pixel':
+        print("all pixels")
+
+        ##################### I) Sample: plot full mass spectrum ##############
+
+                    #if $fullmz:
+
+                        print(plot(msidata, run="infile", key=TRUE, strip=FALSE, main="Average spectrum", grid = $grid_variable))
+                    #end if
 
         ##################### II) Sample: plot zoom-in mass spectrum ##########
 
-        #if $pixel_conditional.zoomed_sample:
-            #for $token in $pixel_conditional.zoomed_sample:
-                print("zoomed sample pixels")
+        #if str($mz_range.mz_range_options) == "manual_mz":
+            #for $token in $mz_range.zoomed_sample:
 
-                minmasspixel = features(msidata, mz=$token.xlimmin)
-                maxmasspixel = features(msidata, mz=$token.xlimmax)
+                minmasspixel = tryCatch(
+                        {
+                        features(msidata, mz=$token.xlimmin)
+                        },
+                        warning=function(cond) {
+                        ## if xlimmin is outside mz range, use min mz value
+                        return(features(msidata, mz=min(mz(msidata))))
+                        }
+                    )    
 
-                ## 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\$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))}
+                maxmasspixel = tryCatch(
+                        {
+                        features(msidata, mz=$token.xlimmax)
+                        },
+                        warning=function(cond) {
+                        ## if xlimax is outside mz range, use max mz value
+                        return(features(msidata, mz=max(mz(msidata))))
+                        }
+                    )   
+
+                ## same min and max not possible for plot
+                if (minmasspixel == maxmasspixel){
+                    if (maxmasspixel == nrow(msidata)){
+                        minmasspixel = minmasspixel-1
+                        }else{
+                            maxmasspixel = maxmasspixel+1
+                        }
+                }
+
+                    print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, main="Average spectrum", run = "infile", strip=FALSE, key=TRUE, xlim= c($token.xlimmin,$token.xlimmax)))
 
             #end for
+
+        #elif str($mz_range.mz_range_options) == "tabular_mz":
+
+            input_mz = read.delim("$mz_range.mz_file", header = $mz_range.tabular_header, stringsAsFactors = FALSE)
+            input_mz_features = input_mz[,c($mz_range.column_mz)]
+            for (feature_count in input_mz_features){
+
+                if (feature_count>min(mz(msidata))&feature_count<max(mz(msidata))){
+
+                    xlimmin = feature_count-$mz_range.minus_mz_tab
+                    xlimmax = feature_count+$mz_range.plus_mz_tab
+
+                            minmasspixel = tryCatch(
+                                    {
+                                    features(msidata, mz=xlimmin)
+                                    },
+                                    warning=function(cond) {
+                                    ## if xlimmin is outside mz range, use min mz value
+                                    return(features(msidata, mz=min(mz(msidata))))
+                                    }
+                                )    
+
+                            maxmasspixel = tryCatch(
+                                    {
+                                    maxmasspixel = features(msidata, mz=xlimmax)
+                                    },
+                                    warning=function(cond) {
+                                    ## if xlimax is outside mz range, use max mz value
+                                    return(features(msidata, mz=max(mz(msidata))))
+                                    }
+                                )   
+
+                        print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, run="infile", key=TRUE, strip=FALSE, main="Average spectrum", xlim= c(xlimmin,xlimmax)))
+                }
+            }
+
+
         #end if
 
-        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")
+            pixeldf = data.frame("$filename", ncol(msidata))
+            colnames(pixeldf) = c("sample name", "number of pixels")
 
     #end if
 
@@ -274,54 +456,44 @@
         <expand macro="reading_msidata"/>
         <expand macro="pdf_filename"/>
         <conditional name="pixel_conditional">
-            <param name="pixel_type" type="select" label="Select if you want to plot the mass spectrum of a single pixel or the average spectrum of all pixels of a sample">
-                <option value="single_pixel" selected="True">Single pixel</option>
-                <option value="sample_pixel">Average spectrum for each sample</option>
+            <param name="pixel_type" type="select" label="Choose spectra (pixel)">
+                <option value="all_pixel" selected="True" >All spectra</option>
+                <option value="tabular_pixel">Single spectra</option>
             </param>
-            <when value="single_pixel">
-                <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, 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>
-                        <option value="grey">grey</option>
-                        <option value="blue">blue</option>
-                        <option value="red">red</option>
-                        <option value="green">green</option>
-                    </param>
-                    <param name="inputtype" type="select" label="Select the line type for the lines at x and y position">
-                        <option value="solid" selected="True">solid</option>
-                        <option value="dashed">dashed</option>
-                        <option value="dotted">dotted</option>
-                        <option value="longdash">longdash</option>
-                    </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 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 value="tabular_pixel">
+                <param name="pixel_file" type="data" format="tabular" label="Load tabular file with pixel coordinates"
+                help="Two or three columns: x values, y values, optionally annotations"/>
+                <param name="column_pixel_x" data_ref="pixel_file" label="Column with x values" type="data_column"/>
+                <param name="column_pixel_y" data_ref="pixel_file" label="Column with y values" type="data_column"/>
+                <param name="column_pixel_annotation" data_ref="pixel_file" optional="True" label="Column with annotations" type="data_column"/>
+                <param name="tabular_pixel_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/>
+            </when>
+            <when value="all_pixel">
             </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">
-                        <expand macro="reading_pixel_annotations"/>
-                    </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 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"/>
+        </conditional>
+        <param name="fullmz" type="boolean" label="Plot complete m/z range" checked="True" truevalue="TRUE" falsevalue="FALSE"/>
+        <conditional name="mz_range">
+            <param name="mz_range_options" type="select" label="zoomed in m/z range">
+                <option value="none_mz" selected="True">no m/z range</option>
+                <option value="manual_mz" >Manual input</option>
+                <option value="tabular_mz">Tabular file</option>
+            </param>
+            <when value="none_mz"/>
+            <when value="tabular_mz">
+                <param name="minus_mz_tab" type="float" value="" label="m/z value to subtract from m/z values in tabular file = lower m/z boundary"/>
+                <param name="plus_mz_tab" type="float" value="" label="m/z value to add to m/z values in tabular file = upper m/z boundary"/>
+                <param name="mz_file" type="data" format="tabular" label="Load tabular file with m/z values"/>
+                <param name="column_mz" data_ref="mz_file" label="Column with mz values" type="data_column"/>
+                <param name="tabular_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/>
+            </when>
+            <when value="manual_mz">
+                <repeat name="zoomed_sample" title="Define min m/z and max m/z for the plotting window" min="1">
+                    <param name="xlimmin" type="float" value="" label="lower m/z boundary for plotting window"/>
+                    <param name="xlimmax" type="float" value="" label="upper m/z boundary for plotting window"/>
                 </repeat>
             </when>
         </conditional>
+        <param name="grid_variable" type="boolean" label="Add grid to plot" truevalue="TRUE" falsevalue="FALSE"/>
     </inputs>
     <outputs>
         <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label="${tool.name} on ${on_string}:results"/>
@@ -330,103 +502,136 @@
         <test>
             <expand macro="infile_imzml"/>
             <conditional name="pixel_conditional">
-                <param name="pixel_type" value="single_pixel"/>
-                    <repeat name="repeatpixel">
-                        <param name="plusminusinDalton" value="0.25"/>
-                        <param name="inputx" value="3"/>
-                        <param name="inputy" value="3"/>
-                        <repeat name="zoomedplot">
-                            <param name="xlimmin" value="310"/>
-                            <param name="xlimmax" value="320"/>
-                        </repeat>
-                        <repeat name="zoomedplot">
-                            <param name="xlimmin" value="350"/>
-                            <param name="xlimmax" value="400"/>
-                        </repeat>
-                        <repeat name="zoomedplot">
-                            <param name="xlimmin" value="400"/>
-                            <param name="xlimmax" value="420"/>
-                        </repeat>
+                <param name="pixel_type" value="tabular_pixel"/>
+                <param name="pixel_file" value="spectra_1_pixel.tabular"/>
+                <param name="column_pixel_x" value="1"/>
+                <param name="column_pixel_y" value="2"/>
+                <param name="tabular_pixel_header" value="FALSE"/>
+            </conditional>
+                <param name="fullmz" value="TRUE"/>
+                <conditional name="mz_range">
+                    <param name="mz_range_options" value="manual_mz"/>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="310"/>
+                        <param name="xlimmax" value="320"/>
                     </repeat>
-                    <repeat name="repeatpixel">
-                        <param name="plusminusinDalton" value="0.25"/>
-                        <param name="inputx" value="2"/>
-                        <param name="inputy" value="2"/>
+                   <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="350"/>
+                        <param name="xlimmax" value="400"/>
                     </repeat>
-                    <repeat name="repeatpixel">
-                        <param name="plusminusinDalton" value="0.25"/>
-                        <param name="inputx" value="1"/>
-                        <param name="inputy" value="1"/>
+                   <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="360"/>
+                        <param name="xlimmax" value="360.8"/>
                     </repeat>
                 </conditional>
+                <param name="grid_variable" value="TRUE"/>
             <output name="plots" file="Plot_imzml.pdf" compare="sim_size"/>
         </test>
         <test>
             <expand macro="infile_analyze75"/>
             <conditional name="pixel_conditional">
-                <param name="pixel_type" value="single_pixel"/>
-                    <repeat name="repeatpixel">
-                        <param name="plusminusinDalton" value="0.25"/>
-                        <param name="inputx" value="5"/>
-                        <param name="inputy" value="2"/>
-                        <repeat name="zoomedplot">
-                            <param name="xlimmin" value="840"/>
-                            <param name="xlimmax" value="850"/>
-                        </repeat>
+                <param name="pixel_type" value="tabular_pixel"/>
+                <param name="pixel_file" value="spectra_1_pixel.tabular"/>
+                <param name="column_pixel_x" value="1"/>
+                <param name="column_pixel_y" value="2"/>
+                <param name="tabular_pixel_header" value="TRUE"/>
+            </conditional>
+                <param name="fullmz" value="TRUE"/>
+                <conditional name="mz_range">
+                    <param name="mz_range_options" value="manual_mz"/>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="840"/>
+                        <param name="xlimmax" value="850"/>
                     </repeat>
-                    <repeat name="repeatpixel">
-                        <param name="plusminusinDalton" value="0.25"/>
-                        <param name="inputx" value="2"/>
-                        <param name="inputy" value="2"/>
-                    </repeat>
-            </conditional>
+                </conditional>
+                <param name="grid_variable" value="FALSE"/>
             <output name="plots" file="Plot_analyze75.pdf" compare="sim_size"/>
         </test>
         <test>
             <expand macro="infile_analyze75"/>
             <conditional name="pixel_conditional">
-                <param name="pixel_type" value="sample_pixel"/>
-                <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"/>
-
-
-
+                <param name="pixel_type" value="tabular_pixel"/>
+                <param name="pixel_file" value="annotations.tabular"/>
+                <param name="column_pixel_x" value="1"/>
+                <param name="column_pixel_y" value="2"/>
+                <param name="column_pixel_annotation" value="4"/>
+                <param name="tabular_pixel_header" value="TRUE"/>
+            </conditional>
+                <param name="fullmz" value="FALSE"/>
+                <conditional name="mz_range">
+                    <param name="mz_range_options" value="manual_mz"/>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="1250"/>
+                        <param name="xlimmax" value="1270"/>
+                    </repeat>
                 </conditional>
-                <repeat name="zoomed_sample">
-                     <param name="xlimmin" value="1250"/>
-                     <param name="xlimmax" value="1270"/>
-                 </repeat>
-            </conditional>
+                <param name="grid_variable" value="FALSE"/>
             <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size"/>
         </test>
         <test>
             <param name="infile" value="3_files_combined.RData" ftype="rdata"/>
             <conditional name="pixel_conditional">
-                <param name="pixel_type" value="sample_pixel"/>
+                <param name="pixel_type" value="all_pixel"/>
+            </conditional>
+                <param name="fullmz" value="TRUE"/>
+                <conditional name="mz_range">
+                    <param name="mz_range_options" value="manual_mz"/>
                     <repeat name="zoomed_sample">
-                         <param name="xlimmin" value="350"/>
-                         <param name="xlimmax" value="360"/>
-                     </repeat>
-            </conditional>
+                        <param name="xlimmin" value="350"/>
+                        <param name="xlimmax" value="360"/>
+                    </repeat>
+                </conditional>
+                <param name="grid_variable" value="FALSE"/>
             <output name="plots" file="Plot_rdata.pdf" compare="sim_size"/>
         </test>
         <test>
-            <param name="infile" value="empty_spectra.rdata" ftype="rdata"/>
+            <expand macro="processed_infile_imzml"/>
+            <conditional name="processed_cond">
+                <param name="processed_file" value="processed"/>
+                <param name="accuracy" value="50"/>
+                <param name="units" value="ppm"/>
+            </conditional>
             <conditional name="pixel_conditional">
-                <param name="pixel_type" value="single_pixel"/>
-                    <repeat name="repeatpixel">
-                        <param name="plusminusinDalton" value="0.1"/>
-                        <param name="inputx" value="1"/>
-                        <param name="inputy" value="1"/>
+                <param name="pixel_type" value="all_pixel"/>
+            </conditional>
+                <param name="fullmz" value="FALSE"/>
+                <conditional name="mz_range">
+                    <param name="mz_range_options" value="manual_mz"/>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="350"/>
+                        <param name="xlimmax" value="350.5"/>
+                    </repeat>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="600"/>
+                        <param name="xlimmax" value="650"/>
                     </repeat>
+                </conditional>
+                <param name="grid_variable" value="TRUE"/>
+            <output name="plots" file="Plot_processed.pdf" compare="sim_size"/>
+        </test>
+        <test>
+        <param name="infile" value="" ftype="imzml">
+            <composite_data value="preprocessing_results1.imzml"/>
+            <composite_data value="preprocessing_results1.ibd"/>
+        </param>
+        <param name="centroids" value="TRUE"/>
+            <conditional name="pixel_conditional">
+                <param name="pixel_type" value="all_pixel"/>
             </conditional>
-            <output name="plots" file="Plot_empty_spectra.pdf" compare="sim_size"/>
+                <param name="fullmz" value="TRUE"/>
+                <conditional name="mz_range">
+                    <param name="mz_range_options" value="manual_mz"/>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="328"/>
+                        <param name="xlimmax" value="330"/>
+                    </repeat>
+                    <repeat name="zoomed_sample">
+                        <param name="xlimmin" value="335"/>
+                        <param name="xlimmax" value="340"/>
+                    </repeat>
+                </conditional>
+            <param name="grid_variable" value="TRUE"/>
+            <output name="plots" file="Plot_picked.pdf" compare="sim_size"/>
         </test>
     </tests>
     <help><![CDATA[
@@ -438,30 +643,39 @@
 This tool uses the Cardinal plot function to generate (zoomed in) mass spectra plots of mass spectrometry imaging data.
 
 @MSIDATA_INPUT_DESCRIPTION@
+
 @SPECTRA_TABULAR_INPUT_DESCRIPTION@
 
+@MZ_TABULAR_INPUT_DESCRIPTION@
+
 **Options**
 
-- "single pixel": Returns a full mass spectrum plot for one pixel, which is defined by its x- and y-coordinates
+*Choosing spectra*
+
+- "All spectra": Plots average mass spectra (mean of all spectra)
 
-    - 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
+- "Single spectra": Returns a full mass spectrum plot for each input spectrum, which is defined by its x- and y-coordinates
 
-- "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
+    - the annotation column is optional: 
+    - without annotation column: plots a separate mass spectrum for every input spectrum
+    - with annotation column: plots average mass spectra for each annotation group in different colours
 
 
-**Tip** 
+*Choosing m/z axis*
+
+- "Plot complete m/z range": Full m/z range is plotted
 
-- Corresponding m/z intensity pairs for single spectra can be obtained with the filtering tool option "ranges for x and y" and afterwards using the imzml tabular exporter tool
-- Plots will only be drawn for pixels that exist in the MSI data, pixel that are outside the dataset will be "False" in the overview table on the last page of the pdf
+- "zoomed in m/z range": Only a customized m/z range is plotted
+
+
+    - "Manual input": Provide the minimum and maximum m/z value to define the m/z axis of the plot
+
+    - "Tabular input": File with m/z values of interest. Needs manual choice of m/z values to subtract and add from the input m/z values to generate the m/z axis of the plot
 
 
 **Output**
 
-- Pdf with the selected mass spectra plots and additional x-y grid plots
+- Single Pdf with all mass spectra plots
 
 
 ]]>