diff msi_spectra_plots.xml @ 2:ea4f1c516368 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_spectra_plots commit 1c808d60243bb1eeda0cd26cb4b0a17ab05de2c0
author galaxyp
date Mon, 28 May 2018 12:39:59 -0400
parents 7caaf84a8a51
children fe28ca73548a
line wrap: on
line diff
--- a/msi_spectra_plots.xml	Mon Apr 23 17:20:15 2018 -0400
+++ b/msi_spectra_plots.xml	Mon May 28 12:39:59 2018 -0400
@@ -1,21 +1,20 @@
-<tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.7.0.1">
+<tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.0">
     <description>
         mass spectrometry imaging mass spectra plots
     </description>
     <requirements>
-        <requirement type="package" version="1.7.0">bioconductor-cardinal</requirement>
+        <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement>
         <requirement type="package" version="2.2.1">r-gridextra</requirement>
-        <requirement type="package" version="2.23-15">r-kernsmooth</requirement>
     </requirements>
     <command detect_errors="exit_code">
     <![CDATA[
         #if $infile.ext == 'imzml'
-            cp '${infile.extra_files_path}/imzml' infile.imzML &&
-            cp '${infile.extra_files_path}/ibd' infile.ibd &&
+            ln -s '${infile.extra_files_path}/imzml' infile.imzML &&
+            ln -s '${infile.extra_files_path}/ibd' infile.ibd &&
         #elif $infile.ext == 'analyze75'
-            cp '${infile.extra_files_path}/hdr' infile.hdr &&
-            cp '${infile.extra_files_path}/img' infile.img &&
-            cp '${infile.extra_files_path}/t2m' infile.t2m &&
+            ln -s '${infile.extra_files_path}/hdr' infile.hdr &&
+            ln -s '${infile.extra_files_path}/img' infile.img &&
+            ln -s '${infile.extra_files_path}/t2m' infile.t2m &&
         #else
             ln -s $infile infile.RData &&
         #end if
@@ -25,23 +24,22 @@
     </command>
     <configfiles>
         <configfile name="MSI_mzplots"><![CDATA[
-################################# load libraries and read file #########################
+################################# load libraries and read file #################
 
 library(Cardinal)
 library(gridExtra)
-library(KernSmooth)
 
 ## Read MALDI Imaging dataset
 
 #if $infile.ext == 'imzml'
-    msidata <- readMSIData('infile.imzML')
+    msidata = readImzML('infile')
 #elif $infile.ext == 'analyze75'
-    msidata <- readMSIData('infile.hdr')
+    msidata = readAnalyze('infile')
 #else
     load('infile.RData')
 #end if
 
-###################################### file properties in numbers ######################
+###################################### file properties in numbers ##############
 
 ## Number of features (mz)
 maxfeatures = length(features(msidata))
@@ -135,10 +133,11 @@
 
 property_df = data.frame(properties, values)
 
+print("before pdf")
 
-######################################## PDF #############################################
-##########################################################################################
-##########################################################################################
+######################################## PDF ###################################
+################################################################################
+################################################################################
 
 
 pdf("mzplots.pdf", fonts = "Times", pointsize = 12)
@@ -147,88 +146,108 @@
 title(main=paste0("Plotted mass spectra for file: \n\n", "$infile.display_name"))
 
 
-############################# I) numbers ####################################
-#############################################################################
+############################# I) numbers ######################################
+###############################################################################
+
+print("in pdf")
 grid.table(property_df, rows= NULL)
 
-counting = 2
 
-    outputmatrix = matrix(mz(msidata), ncol=1, byrow=TRUE)
-    colnames(outputmatrix) = "m/z"
 
 if (npeaks > 0)
 {
     pixeldf = data.frame(matrix(ncol = 2, nrow=0))
 
-    #for $chosenpixel in $repeatpixel: 
+
+    #if str( $pixel_conditional.pixel_type) == 'single_pixel':
+    print("single_pixel")
+
+        #for $chosenpixel in $pixel_conditional.repeatpixel: 
 
 
-        ### is x and y which was put in to define pixel valid coordinates? 
-        pixelisvalid = as.character($chosenpixel.inputx %in% coord(msidata)\$x & $chosenpixel.inputy %in% coord(msidata)\$y)
-        pixelname = paste0("x=", $chosenpixel.inputx,", ", "y=", $chosenpixel.inputy) 
-        pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid))
+            pixelisvalid = as.character($chosenpixel.inputx %in% coord(msidata)\$x & $chosenpixel.inputy %in% coord(msidata)\$y)
+            pixelname = paste0("x=", $chosenpixel.inputx,", ", "y=", $chosenpixel.inputy)
+            print(pixelname)
+            print(colnames(pixeldf))
+            print(colnames(cbind(pixelname, pixelisvalid)))
+            pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid))
+            print(colnames(pixeldf))
+
+            ############################# II) control image ####################
+            ####################################################################
 
 
-############################# II) control image #############################
-#############################################################################
+                if (pixelisvalid == "TRUE")
+                {
+
+                print(pixelisvalid)
 
 
-    if (pixelisvalid == "TRUE")
-    {
+                    image(msidata, mz=$chosenpixel.inputmz, 
+                          ylim = c(maximumy+(0.2*maximumy),minimumy-1),colorkey=FALSE, plusminus = $chosenpixel.plusminusinDalton, contrast.enhance = "histogram", 
+                          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)
 
 
-        image(msidata, mz=$chosenpixel.inputmz, 
-              ylim = c(maximumy+(0.2*maximumy),minimumy-1),colorkey=FALSE, plusminus = $chosenpixel.plusminusinDalton, contrast.enhance = "histogram", 
-              main= paste0("x= ",$chosenpixel.inputx, ", y= ", $chosenpixel.inputy))
+            ##################### III) plot full mass spectrum #################
+            ####################################################################
+
+                    plot(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy))
+
+            ##################### IV) plot zoom-in mass spectrum ###############
+            ####################################################################
 
-        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)
+                    #if $chosenpixel.zoomedplot:
+                        #for $token in $chosenpixel.zoomedplot:
 
+                            minmasspixel = features(msidata, mz=$token.xlimmin)
+                            maxmasspixel = features(msidata, mz=$token.xlimmax)
+
+                            plot(msidata[minmasspixel:maxmasspixel,], coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy), 
+                                 xlim= c($token.xlimmin,$token.xlimmax))
 
-        ##################### III) plot full mass spectrum ##########################
-        #############################################################################
+                        #end for
+                    #end if
 
-        plot(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy))
+                }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")
 
+    #elif str( $pixel_conditional.pixel_type) == 'sample_pixel':
+    print("sample_pixel")
 
-            ##################### IV) plot zoom-in mass spectrum ##########################
-            #############################################################################
+            ##################### I) Sample: plot full mass spectrum ###########
+        plot(msidata, pixel=1:ncol(msidata), pixel.groups=pData(msidata)\$sample, key=TRUE, col=c("blue", "orange", "green", "red", "yellow", "grey"), superpose=TRUE)
 
-        #if $chosenpixel.zoomedplot:
-            #for $token in $chosenpixel.zoomedplot:
+            ##################### II) Sample: plot zoom-in mass spectrum #######
+
+        #if $pixel_conditional.zoomed_sample:
+            #for $token in $pixel_conditional.zoomed_sample:
 
                 minmasspixel = features(msidata, mz=$token.xlimmin)
                 maxmasspixel = features(msidata, mz=$token.xlimmax)
-
-                plot(msidata[minmasspixel:maxmasspixel,], coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy), 
-                     xlim= c($token.xlimmin,$token.xlimmax))
+                plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata),  xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=pData(msidata)\$sample, key=TRUE,col=c("blue", "orange", "green", "red", "yellow", "grey"), superpose=TRUE)
 
             #end for
         #end if
 
-        ##################### V) Output with mz and intensities #####################
-        #############################################################################
-
-
-        ### for each repeat a new intensity column for the new pixel is added
-        outputmatrix = cbind(outputmatrix, spectra(msidata)[,pixels(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy))])
-        colnames(outputmatrix)[counting] = paste0("x= ",$chosenpixel.inputx, ", y= ", $chosenpixel.inputy, " intensity")
-        counting = counting+1
+        pixeldf = data.frame(table(pData(msidata)\$sample))
+        colnames(pixeldf) = c("sample name", "number of pixels")
 
-    }else{
-        print("These pixel coordinates did not correspond to a real pixel")}
+    #end if
 
-#end for
-
-    colnames(pixeldf) = c("pixel coordinates", "coordinates were found in this file")
     plot(0,type='n',axes=FALSE,ann=FALSE)
-    title(main=paste0("Overview of chosen pixel for file:\n", "$infile.display_name"))
+    title(main="Overview of chosen pixel:")
     grid.table(pixeldf, rows= NULL)
 
     dev.off()
 
-        write.table(outputmatrix, file="$tabularmatrix", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
+
 }else{
     print("Inputfile has no intensities > 0")
     dev.off()
@@ -238,35 +257,48 @@
     <inputs>
         <param name="infile" type="data" format="imzml,rdata,analyze75" label="Inputfile as imzML, Analyze7.5 or Cardinal MSImageSet saved as RData"
             help="Upload composite datatype imzml (ibd+imzML) or analyze75 (hdr+img+t2m) or regular upload .RData (Cardinal MSImageSet)"/>
-        <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 mz in Dalton" help="mz 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="mass range for this mz value" help="plusminus mass window in Dalton"/>
-            <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>
+        <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 of all pixels of a sample">
+                <option value="single_pixel" selected="True">Single pixel</option>
+                <option value="sample_pixel">All pixels of a sample</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 mz min and mz 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 mz for zoomed in window"/>
-                <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum mz for zoomed in window"/>
-            </repeat>
-        </repeat>
+            <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, here mz in Dalton" help="mz 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="mass range for this mz value" help="plusminus mass window in Dalton"/>
+                    <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 mz min and mz 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 mz for zoomed in window"/>
+                        <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum mz for zoomed in window"/>
+                    </repeat>
+                </repeat>
+            </when>
+            <when value="sample_pixel">
+                <repeat name="zoomed_sample" title="Zoomed in plots with mz min and mz 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 mz for zoomed in window"/>
+                    <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum mz for zoomed in window"/>
+                </repeat>
+            </when>
+        </conditional>
     </inputs>
     <outputs>
         <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label = "${tool.name} ${on_string}"/>
-        <data format="tabular" name="tabularmatrix" label="Mass spectrum ${on_string}" />
     </outputs>
     <tests>
         <test>
@@ -274,77 +306,76 @@
                 <composite_data value="Example_Continuous.imzML"/>
                 <composite_data value="Example_Continuous.ibd"/>
             </param>
-            <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="550"/>
-                    <param name="xlimmax" value="555"/>
-                </repeat>
-                <repeat name="zoomedplot">
-                    <param name="xlimmin" value="750"/>
-                    <param name="xlimmax" value="800"/>
-                </repeat>
-                <repeat name="zoomedplot">
-                    <param name="xlimmin" value="400"/>
-                    <param name="xlimmax" value="420"/>
-                </repeat>
-            </repeat>
-            <repeat name="repeatpixel">
-                <param name="plusminusinDalton" value="0.25"/>
-                <param name="inputx" value="2"/>
-                <param name="inputy" value="2"/>
-            </repeat>
-            <repeat name="repeatpixel">
-                <param name="plusminusinDalton" value="0.25"/>
-                <param name="inputx" value="1"/>
-                <param name="inputy" value="1"/>
-            </repeat>
+            <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="550"/>
+                            <param name="xlimmax" value="555"/>
+                        </repeat>
+                        <repeat name="zoomedplot">
+                            <param name="xlimmin" value="750"/>
+                            <param name="xlimmax" value="800"/>
+                        </repeat>
+                        <repeat name="zoomedplot">
+                            <param name="xlimmin" value="400"/>
+                            <param name="xlimmax" value="420"/>
+                        </repeat>
+                    </repeat>
+                    <repeat name="repeatpixel">
+                        <param name="plusminusinDalton" value="0.25"/>
+                        <param name="inputx" value="2"/>
+                        <param name="inputy" value="2"/>
+                    </repeat>
+                    <repeat name="repeatpixel">
+                        <param name="plusminusinDalton" value="0.25"/>
+                        <param name="inputx" value="1"/>
+                        <param name="inputy" value="1"/>
+                    </repeat>
+                </conditional>
             <output name="plots" file="Plot_imzml.pdf" compare="sim_size" delta="20000"/>
-            <output name="tabularmatrix" file="Matrix_imzml.txt"/>
         </test>
-
         <test>
             <param name="infile" value="" ftype="analyze75">
                 <composite_data value="Analyze75.hdr"/>
                 <composite_data value="Analyze75.img"/>
                 <composite_data value="Analyze75.t2m"/>
             </param>
-            <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>
-            </repeat>
-            <repeat name="repeatpixel">
-                <param name="plusminusinDalton" value="0.25"/>
-                <param name="inputx" value="2"/>
-                <param name="inputy" value="2"/>
-            </repeat>
+            <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>
+                    </repeat>
+                    <repeat name="repeatpixel">
+                        <param name="plusminusinDalton" value="0.25"/>
+                        <param name="inputx" value="2"/>
+                        <param name="inputy" value="2"/>
+                    </repeat>
+                </conditional>
             <output name="plots" file="Plot_analyze75.pdf" compare="sim_size" delta="20000"/>
-            <output name="tabularmatrix" file="Matrix_analyze75.txt"/>
-        </test>
-
-        <test>
-            <param name="infile" value="preprocessing_results1.RData" ftype="rdata"/>
-            <repeat name="repeatpixel">
-                <param name="plusminusinDalton" value="0.25"/>
-                <param name="inputx" value="2"/>
-                <param name="inputy" value="2"/>
-                <repeat name="zoomedplot">
-                     <param name="xlimmin" value="222"/>
-                     <param name="xlimmax" value="244"/>
-                 </repeat>
-            </repeat>
-            <output name="plots" file="Plot_rdata.pdf" compare="sim_size" delta="20000"/>
-            <output name="tabularmatrix" file="Matrix_rdata.txt"/>
         </test>
         <test>
-            <param name="infile" value="LM8_file16.rdata" ftype="rdata"/>
+            <param name="infile" value="123_combined.rdata" ftype="rdata"/>
+            <conditional name="pixel_conditional">
+                <param name="pixel_type" value="sample_pixel"/>
+                    <repeat name="zoomed_sample">
+                         <param name="xlimmin" value="350"/>
+                         <param name="xlimmax" value="360"/>
+                     </repeat>
+                </conditional>
+            <output name="plots" file="Plot_rdata.pdf" compare="sim_size" delta="20000"/>
+        </test>
+        <test>
+            <param name="infile" value="empty_spectra.rdata" ftype="rdata"/>
             <param name="plusminusinDalton" value="0.1"/>
             <param name="inputx" value="1"/>
             <param name="inputy" value="1"/>
@@ -357,23 +388,41 @@
                     <param name="xlimmax" value="1050"/>
                 </repeat>
             </repeat>
-            <output name="plots" file="Plot_LM8_file16.pdf" compare="sim_size" delta="20000"/>
-            <output name="tabularmatrix" file="Matrix_LM8.txt"/>
+            <output name="plots" file="Plot_empty_spectra.pdf" compare="sim_size" delta="20000"/>
         </test>
     </tests>
     <help><![CDATA[
 
-Returns a full mass-spectrum plot and peaklist output with masses and intensities for the chosen pixel. Input needs the x and the y coordinates of the pixel of interest. 
-Additionally zoom into mass-spectra plots is possible by providing the minimum and maximum mz value to define the limits of the plot.  
-To have a visual control that the right pixel was chosen, a heatmap of a mass in Dalton which can be specified will be plotted and two intersecting lines will show where the chosen pixel is located in the ion image. 
+Cardinal is an R package that implements statistical & computational tools for analyzing mass spectrometry imaging datasets. `More information on Cardinal <http://cardinalmsi.org//>`_
+
+This tool uses the Cardinal plot function to generate (zoomed in) mass spectra plots of mass-spectrometry imaging data.
 
 Input data: 3 types of input data can be used:
 
-- imzml file (upload imzml and ibd file via the "composite" function) `Introduction to the imzml format <http://ms-imaging.org/wp/introduction/>`_
+- imzml file (upload imzml and ibd file via the "composite" function) `Introduction to the imzml format <https://ms-imaging.org/wp/imzml/>`_
 - Analyze7.5 (upload hdr, img and t2m file via the "composite" function)
 - Cardinal "MSImageSet" data (with variable name "msidata", saved as .RData)
 
-The output of this tool contains a heatmap of the mass of interest with two lines intersecting at the pixel of interest. Then the full mass-spectrum plot is obtained and if chosen also several zoomed in mass spectra. A peaklist with masses and intensities for this pixel is exported as tabular file. 
+Options:
+
+- "single pixel": Returns a full mass-spectrum plot for one pixel, which is defined by its x- and y-coordinates
+
+    - Enter the x and y coordinates of your pixel of interest
+    - To have a visual control for the selected pixel, a heatmap of a mass of interest will be drawn. Two intersecting lines will show the pixel location. This procedure requires an mass of interest together with a mass range and for the lines the colour and type.
+    - Additionally zoom into mass-spectra plots is possible by providing the minimum and maximum mass value to define the limits of the plot
+- "All pixels of a sample": Returns a full average mass-spectrum plot with different colours for each subfile
+
+    - This option only works on files that have previosly been combined in the combine tool
+    - Additionally zoom into mass-spectra plots is possible by providing the minimum and maximum mass value to define the limits of the plot
+
+Output:
+
+- Pdf with the selected mass-spectra plots and additional control plots
+
+Tip: 
+
+- Corresponding peaklists with masses and their intensities can be obtained with the filtering tool option "ranges for x and y"
+
 
 ]]>
     </help>