Mercurial > repos > galaxyp > cardinal_mz_images
view mz_images.xml @ 2:27a4c660bbca draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit f127be2141cf22e269c85282d226eb16fe14a9c1
author | galaxyp |
---|---|
date | Fri, 15 Feb 2019 10:20:01 -0500 |
parents | 4d5f798a7a18 |
children | 773a24b240e1 |
line wrap: on
line source
<tool id="cardinal_mz_images" name="MSI mz images" version="@VERSION@.2"> <description> mass spectrometry imaging m/z heatmaps </description> <macros> <import>macros.xml</import> </macros> <expand macro="requirements"> <requirement type="package" version="2.3">r-gridextra</requirement> <requirement type="package" version="0.20_35">r-lattice</requirement> </expand> <command detect_errors="aggressive"> <![CDATA[ @INPUT_LINKING@ cat '${MSI_heatmaps}' && Rscript '${MSI_heatmaps}' ]]> </command> <configfiles> <configfile name="MSI_heatmaps"><![CDATA[ ################################# load libraries and read file ################# library(Cardinal) library(gridExtra) library(lattice) @READING_MSIDATA@ @DATA_PROPERTIES@ ##################################### read and filter input m/z ############## input_list = read.delim("$calibrant_file", header = $calibrant_header, stringsAsFactors = FALSE) input_list = input_list[,c($mz_column, $name_column)] ### calculate how many input m/z are valid: inputmasses = input_list[input_list[,1]>minmz & input_list[,1]<maxmz,] inputmz = as.numeric(inputmasses[,1]) inputnames = as.character(inputmasses[,2]) ############################## PDF ############################################# ################################################################################ pdf("heatmaps.pdf", fonts = "Times", pointsize = 12) plot(0,type='n',axes=FALSE,ann=FALSE) #if not $filename: #set $filename = $infile.display_name #end if title(main=paste("\nHeatmap images\n\n", "Filename:\n", "$filename")) new_row = data.frame(paste0("# valid m/z in \n", "$calibrant_file.display_name"), paste0(length(inputmz), "/", length(input_list[,1]))) colnames(new_row) = c("properties", "values") property_df = rbind(property_df, new_row) grid.table(property_df, rows= NULL) ############################# II) images #################################### ### only plot images when file has features and pixels: if (ncol(msidata)>0 & nrow(msidata) >0){ if (length(inputmz) != 0){ for (mass in 1:length(inputmz)){ ###standard image #if str($image_type) == "standard_image": print("standard image") print(image(msidata, mz=inputmz[mass],plusminus = $plusminus_dalton, contrast.enhance = "$image_contrast", smooth.image = "$image_smoothing", strip=$strip, colorkey=$colorkey,ylim= c(maximumy+0.2*maximumy,minimumy-1), main= paste0(inputnames[mass], " (", round(inputmz[mass], digits = 2)," ± ", $plusminus_dalton, " Da)")))} ###lattice image #elif str($image_type) == "lattice_image": print("lattice image") #if str($strip) =="TRUE": print(image(msidata, mz=inputmz[mass], strip = strip.custom(bg="lightgrey", par.strip.text=list(col="black", cex=.9)), lattice=TRUE, plusminus = $plusminus_dalton, contrast.enhance = "$image_contrast", smooth.image = "$image_smoothing", colorkey=$colorkey,ylim=c(maximumy+0.2*maximumy,minimumy-1), main= paste0(inputnames[mass], " (", round(inputmz[mass], digits = 2)," ± ", $plusminus_dalton, " Da)")))} #elif str($strip) =="FALSE": print(image(msidata, mz=inputmz[mass], strip = $strip, lattice=TRUE, plusminus = $plusminus_dalton, contrast.enhance = "$image_contrast", smooth.image = "$image_smoothing", colorkey=$colorkey, main= paste0(inputnames[mass], " (", round(inputmz[mass], digits = 2)," ± ", $plusminus_dalton, " Da)")))} #end if #end if ## optional svg output with original coordinates #if $svg_pixelimage: print("svg pixel image") ## reverse y axis for svg output = correct order and nice svg image coord(msidata)\$y <- max(coord(msidata)\$y) - coord(msidata)\$y + 1 svg(file="svg_pixel_output.svg") par(mar=c(0,0,0,0)) image(msidata, mz = inputmz[1],strip=FALSE, plusminus = $plusminus_dalton,colorkey = FALSE,axes=FALSE, xlab=NA, ylab=NA,contrast.enhance = "$image_contrast", smooth.image = "$image_smoothing") dev.off() #end if ## optional overlay all input m/z in one image #if str($overlay_cond.overlay_selection) == "yes_overlay": #set $color_string = ','.join(['"%s"' % $color.feature_color for $color in $overlay_cond.colours]) colourvector = c($color_string) image(msidata, mz=inputmz, plusminus = $plusminus_dalton, col=colourvector, contrast.enhance = "$image_contrast", normalize.image="linear", smooth.image = "$image_smoothing", superpose=TRUE, main="overlay of all m/z", ylim= c(maximumy+0.2*maximumy,minimumy-1)) legend("topright", fill=colourvector, legend=as.numeric(sort(as.character(inputmz)))) #end if } else {print("The input m/z were invalid")} dev.off() }else{ print("input file has no features or pixels left") dev.off() } ]]></configfile> </configfiles> <inputs> <expand macro="reading_msidata"/> <expand macro="pdf_filename"/> <expand macro="reading_2_column_mz_tabular"/> <param name="image_contrast" type="select" label="Select a contrast enhancement function for the heatmap images" help="The 'histogram' equalization method flatterns the distribution of intensities. The hotspot 'suppression' method uses thresholding to reduce the intensities of hotspots"> <option value="none" selected="True">none</option> <option value="suppression">suppression</option> <option value="histogram">histogram</option> </param> <param name="image_smoothing" type="select" label="Select an image smoothing function for the heatmap images" help="The 'gaussian' smoothing method smooths images with a simple gaussian kernel. The 'adaptive' method uses bilateral filtering to preserve edges"> <option value="none" selected="True">none</option> <option value="gaussian">gaussian</option> <option value="adaptive">adaptive</option> </param> <param name="plusminus_dalton" value="0.25" type="float" label="M/z range" help="plusminus m/z window"/> <param name="strip" type="boolean" checked="True" truevalue="TRUE" falsevalue="FALSE" label="Display m/z value in plot"/> <param name="colorkey" type="boolean" checked="True" truevalue="TRUE" falsevalue="FALSE" label="Display colorkey in plot"/> <param name="image_type" type="boolean" checked="True" truevalue="standard_image" falsevalue="lattice_image" label="Standard image" help="No: lattice function is used to display image"/> <param name="svg_pixelimage" type="boolean" label="Export first valid m/z from tabular file as SVG"/> <conditional name="overlay_cond"> <param name="overlay_selection" type="select" label="Overlay image"> <option value="no_overlay" selected="True">no</option> <option value="yes_overlay">yes</option> </param> <when value="no_overlay"/> <when value="yes_overlay"> <repeat name="colours" title="Colours for the plots" min="1" max="50"> <param name="feature_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of m/z in tabular file"> <sanitizer> <valid initial="string.letters,string.digits"> <add value="#" /> </valid> </sanitizer> </param> </repeat> </when> </conditional> </inputs> <outputs> <data format="pdf" name="plots" from_work_dir="heatmaps.pdf" label="${tool.name} on ${on_string}: results"/> <data format="svg" name="svg_output" from_work_dir="svg_pixel_output.svg" label="${tool.name} on ${on_string}: image.svg"> <filter>svg_pixelimage</filter> </data> </outputs> <tests> <test> <expand macro="infile_imzml"/> <param name="calibrant_file" value="inputpeptides.tabular" ftype="tabular"/> <param name="mz_column" value="1"/> <param name="name_column" value="2"/> <param name="plusminus_dalton" value="0.25"/> <param name="filename" value="Testfile_imzml"/> <param name="image_contrast" value="histogram"/> <param name="strip" value="True"/> <param name="colorkey" value="True"/> <param name="image_type" value="lattice_image"/> <output name="plots" file="Heatmaps_imzml.pdf" ftype="pdf" compare="sim_size"/> </test> <test> <expand macro="infile_analyze75"/> <param name="calibrant_file" value="inputpeptides2.tabular" ftype="tabular"/> <param name="mz_column" value="1"/> <param name="name_column" value="1"/> <param name="plusminus_dalton" value="0.5"/> <param name="filename" value="Testfile_analyze75"/> <param name="image_smoothing" value="gaussian"/> <param name="strip" value="False"/> <param name="colorkey" value="True"/> <param name="svg_pixelimage" value="True"/> <output name="plots" file="Heatmaps_analyze75.pdf" ftype="pdf" compare="sim_size"/> <output name="svg_output" file="analyze75.svg" ftype="svg" compare="sim_size"/> </test> <test> <param name="infile" value="preprocessed.RData" ftype="rdata"/> <param name="calibrant_file" value="inputpeptides.tabular" ftype="tabular"/> <param name="mz_column" value="1"/> <param name="name_column" value="2"/> <param name="plusminus_dalton" value="0.5"/> <param name="strip" value="True"/> <param name="colorkey" value="True"/> <param name="image_type" value="lattice_image"/> <param name="filename" value="Testfile_rdata"/> <output name="plots" file="Heatmaps_rdata.pdf" ftype="pdf" compare="sim_size"/> </test> <test> <param name="infile" value="empty_spectra.rdata" ftype="rdata"/> <param name="calibrant_file" value="inputpeptides2.tabular" ftype="tabular"/> <param name="mz_column" value="1"/> <param name="name_column" value="1"/> <param name="plusminus_dalton" value="0.5"/> <param name="strip" value="True"/> <param name="colorkey" value="False"/> <param name="filename" value="Testfile_rdata"/> <output name="plots" file="Heatmaps_LM8_file16.pdf" ftype="pdf" compare="sim_size"/> </test> </tests> <help><![CDATA[ @CARDINAL_DESCRIPTION@ ----- This tool uses the Cardinal image function to plot the intensity distribution of m/z feature of mass spectrometry imaging data. @MSIDATA_INPUT_DESCRIPTION@ @MZ_2COLS_TABULAR_INPUT_DESCRIPTION@ **Tips** - In case tabular file cannot be selected in drop-down menu: Datatype in Galaxy must be tabular otherwise file will not appear in selection window (if Galaxy auto-detection was wrong, datatype can be changed by pressing the pen button (edit attributes)) - No heatmaps are plotted when the input mass spectrometry imaging file has no intensities > 0 or all chosen m/z features are not present in the MSI dataset - The contrast enhance and image smoothing functions require a certain number (about 2%) of m/z features with intensities > 0 across all spectra - The standard image function should work for all files while the lattice function works not perfectly on every file **Output** - Pdf with the heatmap images - optional: svg file with the heatmap of the first valid m/z in the tabular file ]]> </help> <expand macro="citations"/> </tool>