comparison msi_spectra_plots.xml @ 0:c93ae3463b30 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/msi_spectra_plot commit 6d271de132f364b1e16b0222ad2d6e315586f0dd
author galaxyp
date Mon, 27 Nov 2017 13:50:11 -0500
parents
children 7caaf84a8a51
comparison
equal deleted inserted replaced
-1:000000000000 0:c93ae3463b30
1 <tool id="mass_spectrometry_imaging_mzplots" name="MSI massspectra" version="1.7.0">
2 <description>
3 mass spectrometry imaging mass spectra plots
4 </description>
5 <requirements>
6 <requirement type="package" version="1.7.0">bioconductor-cardinal</requirement>
7 <requirement type="package" version="2.2.1">r-gridextra</requirement>
8 <requirement type="package" version="2.23-15">r-kernsmooth</requirement>
9 </requirements>
10 <command detect_errors="exit_code">
11 <![CDATA[
12 #if $infile.ext == 'imzml'
13 cp '${infile.extra_files_path}/imzml' infile.imzML &&
14 cp '${infile.extra_files_path}/ibd' infile.ibd &&
15 #elif $infile.ext == 'analyze75'
16 cp '${infile.extra_files_path}/hdr' infile.hdr &&
17 cp '${infile.extra_files_path}/img' infile.img &&
18 cp '${infile.extra_files_path}/t2m' infile.t2m &&
19 #else
20 ln -s $infile infile.RData &&
21 #end if
22 cat '${MSI_mzplots}' &&
23 Rscript '${MSI_mzplots}'
24 ]]>
25 </command>
26 <configfiles>
27 <configfile name="MSI_mzplots"><![CDATA[
28 ################################# load libraries and read file #########################
29
30 library(Cardinal)
31 library(gridExtra)
32 library(KernSmooth)
33
34 ## Read MALDI Imaging dataset
35
36 #if $infile.ext == 'imzml'
37 msidata <- readMSIData('infile.imzML')
38 #elif $infile.ext == 'analyze75'
39 msidata <- readMSIData('infile.hdr')
40 #else
41 load('infile.RData')
42 #end if
43
44 ###################################### file properties in numbers ######################
45
46 ## Number of features (mz)
47 maxfeatures = length(features(msidata))
48 ## Range mz
49 minmz = round(min(mz(msidata)), digits=2)
50 maxmz = round(max(mz(msidata)), digits=2)
51 ## Number of spectra (pixels)
52 pixelcount = length(pixels(msidata))
53 ## Range x coordinates
54 minimumx = min(coord(msidata)[,1])
55 maximumx = max(coord(msidata)[,1])
56 ## Range y coordinates
57 minimumy = min(coord(msidata)[,2])
58 maximumy = max(coord(msidata)[,2])
59 ## Range of intensities
60 minint = round(min(spectra(msidata)[]), digits=2)
61 maxint = round(max(spectra(msidata)[]), digits=2)
62 medint = round(median(spectra(msidata)[]), digits=2)
63 ## Number of intensities > 0
64 npeaks= sum(spectra(msidata)[]>0)
65 ## Spectra multiplied with mz (potential number of peaks)
66 numpeaks = ncol(spectra(msidata)[])*nrow(spectra(msidata)[])
67 ## Percentage of intensities > 0
68 percpeaks = round(npeaks/numpeaks*100, digits=2)
69 ## Number of empty TICs
70 TICs = colSums(spectra(msidata)[])
71 NumemptyTIC = sum(TICs == 0)
72
73 ## Processing informations
74 processinginfo = processingData(msidata)
75 centroidedinfo = processinginfo@centroided # TRUE or FALSE
76
77 ## if TRUE write processinginfo if no write FALSE
78
79 ## normalization
80 if (length(processinginfo@normalization) == 0) {
81 normalizationinfo='FALSE'
82 } else {
83 normalizationinfo=processinginfo@normalization
84 }
85 ## smoothing
86 if (length(processinginfo@smoothing) == 0) {
87 smoothinginfo='FALSE'
88 } else {
89 smoothinginfo=processinginfo@smoothing
90 }
91 ## baseline
92 if (length(processinginfo@baselineReduction) == 0) {
93 baselinereductioninfo='FALSE'
94 } else {
95 baselinereductioninfo=processinginfo@baselineReduction
96 }
97 ## peak picking
98 if (length(processinginfo@peakPicking) == 0) {
99 peakpickinginfo='FALSE'
100 } else {
101 peakpickinginfo=processinginfo@peakPicking
102 }
103
104 properties = c("Number of mz features",
105 "Range of mz values [Da]",
106 "Number of pixels",
107 "Range of x coordinates",
108 "Range of y coordinates",
109 "Range of intensities",
110 "Median of intensities",
111 "Intensities > 0",
112 "Number of zero TICs",
113 "Preprocessing",
114 "Normalization",
115 "Smoothing",
116 "Baseline reduction",
117 "Peak picking",
118 "Centroided")
119
120 values = c(paste0(maxfeatures),
121 paste0(minmz, " - ", maxmz),
122 paste0(pixelcount),
123 paste0(minimumx, " - ", maximumx),
124 paste0(minimumy, " - ", maximumy),
125 paste0(minint, " - ", maxint),
126 paste0(medint),
127 paste0(percpeaks, " %"),
128 paste0(NumemptyTIC),
129 paste0(" "),
130 paste0(normalizationinfo),
131 paste0(smoothinginfo),
132 paste0(baselinereductioninfo),
133 paste0(peakpickinginfo),
134 paste0(centroidedinfo))
135
136 property_df = data.frame(properties, values)
137
138
139 ######################################## PDF #############################################
140 ##########################################################################################
141 ##########################################################################################
142
143
144 pdf("mzplots.pdf", fonts = "Times", pointsize = 12)
145 plot(0,type='n',axes=FALSE,ann=FALSE)
146
147 title(main=paste0("Plotted mass spectra for file: \n\n", "$infile.display_name"))
148
149
150 ############################# I) numbers ####################################
151 #############################################################################
152 grid.table(property_df, rows= NULL)
153
154 counting = 2
155
156 outputmatrix = matrix(mz(msidata), ncol=1, byrow=TRUE)
157 colnames(outputmatrix) = "m/z"
158
159 if (npeaks > 0)
160 {
161 pixeldf = data.frame(matrix(ncol = 2, nrow=0))
162
163 #for $chosenpixel in $repeatpixel:
164
165
166 ### is x and y which was put in to define pixel valid coordinates?
167 pixelisvalid = as.character($chosenpixel.inputx %in% coord(msidata)\$x & $chosenpixel.inputy %in% coord(msidata)\$y)
168 pixelname = paste0("x=", $chosenpixel.inputx,", ", "y=", $chosenpixel.inputy)
169 pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid))
170
171
172 ############################# II) control image #############################
173 #############################################################################
174
175
176 if (pixelisvalid == "TRUE")
177 {
178
179
180 image(msidata, mz=$chosenpixel.inputmz,
181 ylim = c(maximumy+(0.2*maximumy),minimumy-1),colorkey=FALSE, plusminus = $chosenpixel.plusminusinDalton, contrast.enhance = "histogram",
182 main= paste0("x= ",$chosenpixel.inputx, ", y= ", $chosenpixel.inputy))
183
184 abline(v=$chosenpixel.inputx, col ="$chosenpixel.inputcolour", lty="$chosenpixel.inputtype", lwd=$chosenpixel.inputwidth)
185 abline(h=$chosenpixel.inputy, col ="$chosenpixel.inputcolour", lty="$chosenpixel.inputtype", lwd=$chosenpixel.inputwidth)
186
187
188 ##################### III) plot full mass spectrum ##########################
189 #############################################################################
190
191 plot(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy))
192
193
194
195 ##################### IV) plot zoom-in mass spectrum ##########################
196 #############################################################################
197
198 #if $chosenpixel.zoomedplot:
199 #for $token in $chosenpixel.zoomedplot:
200
201 minmasspixel = features(msidata, mz=$token.xlimmin)
202 maxmasspixel = features(msidata, mz=$token.xlimmax)
203
204 plot(msidata[minmasspixel:maxmasspixel,], coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy),
205 xlim= c($token.xlimmin,$token.xlimmax))
206
207 #end for
208 #end if
209
210 ##################### V) Output with mz and intensities #####################
211 #############################################################################
212
213
214 ### for each repeat a new intensity column for the new pixel is added
215 outputmatrix = cbind(outputmatrix, spectra(msidata)[,pixels(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy))])
216 colnames(outputmatrix)[counting] = paste0("x= ",$chosenpixel.inputx, ", y= ", $chosenpixel.inputy, " intensity")
217 counting = counting+1
218
219 }else{
220 print("These pixel coordinates did not correspond to a real pixel")}
221
222 #end for
223
224 colnames(pixeldf) = c("pixel coordinates", "coordinates were found in this file")
225 plot(0,type='n',axes=FALSE,ann=FALSE)
226 title(main=paste0("Overview of chosen pixel for file:\n", "$infile.display_name"))
227 grid.table(pixeldf, rows= NULL)
228
229 dev.off()
230
231 write.table(outputmatrix, file="$tabularmatrix", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
232 }else{
233 print("Inputfile has no intensities > 0")
234 dev.off()
235 }
236 ]]></configfile>
237 </configfiles>
238 <inputs>
239 <param name="infile" type="data" format="imzml,rdata,analyze75" label="Inputfile as imzML, Analyze7.5 or Cardinal MSImageSet saved as RData"
240 help="Upload composite datatype imzml (ibd+imzML) or analyze75 (hdr+img+t2m) or regular upload .RData (Cardinal MSImageSet)"/>
241 <repeat name="repeatpixel" title="Plot mass spectra for pixel of interest" min="1" max="20">
242 <param name="inputx" type="integer" value="" label="x-coordinate of pixel of interest" help="x-value of the pixel of interest"/>
243 <param name="inputy" type="integer" value="" label="y-coordinate of pixel of interest" help="y-value of the pixel of interest"/>
244 <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"/>
245 <param name="plusminusinDalton" value="0.25" type="float" label="mass range for this mz value" help="plusminus mass window in Dalton"/>
246 <param name="inputcolour" type="select" label="select the colour for the lines at x and y position">
247 <option value="white" selected="True">white</option>
248 <option value="black">black</option>
249 <option value="grey">grey</option>
250 <option value="blue">blue</option>
251 <option value="red">red</option>
252 <option value="green">green</option>
253 </param>
254 <param name="inputtype" type="select" label="select the line type for the lines at x and y position">
255 <option value="solid" selected="True">solid</option>
256 <option value="dashed">dashed</option>
257 <option value="dotted">dotted</option>
258 <option value="longdash">longdash</option>
259 </param>
260 <param name="inputwidth" type="integer" value="2" label="select the width of the lines at x and y position"/>
261 <repeat name="zoomedplot" title="Zoomed in plots with mz min and mz max to define the plot window" min="0" max="50">
262 <param name="xlimmin" type="integer" value="" label="lower boundary in Dalton for plotting window" help="minimum mz for zoomed in window"/>
263 <param name="xlimmax" type="integer" value="" label="upper boundary in Dalton for plotting window" help="maximum mz for zoomed in window"/>
264 </repeat>
265 </repeat>
266 </inputs>
267 <outputs>
268 <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label = "${tool.name} on $infile.display_name"/>
269 <data format="tabular" name="tabularmatrix" label="${tool.name} on $infile.display_name" />
270 </outputs>
271 <tests>
272 <test>
273 <param name="infile" value="" ftype="imzml">
274 <composite_data value="Example_Continuous.imzML"/>
275 <composite_data value="Example_Continuous.ibd"/>
276 </param>
277 <repeat name="repeatpixel">
278 <param name="plusminusinDalton" value="0.25"/>
279 <param name="inputx" value="3"/>
280 <param name="inputy" value="3"/>
281 <repeat name="zoomedplot">
282 <param name="xlimmin" value="550"/>
283 <param name="xlimmax" value="555"/>
284 </repeat>
285 <repeat name="zoomedplot">
286 <param name="xlimmin" value="750"/>
287 <param name="xlimmax" value="800"/>
288 </repeat>
289 <repeat name="zoomedplot">
290 <param name="xlimmin" value="400"/>
291 <param name="xlimmax" value="420"/>
292 </repeat>
293 </repeat>
294 <repeat name="repeatpixel">
295 <param name="plusminusinDalton" value="0.25"/>
296 <param name="inputx" value="2"/>
297 <param name="inputy" value="2"/>
298 </repeat>
299 <repeat name="repeatpixel">
300 <param name="plusminusinDalton" value="0.25"/>
301 <param name="inputx" value="1"/>
302 <param name="inputy" value="1"/>
303 </repeat>
304 <output name="plots" file="Plot_imzml.pdf" compare="sim_size" delta="20000"/>
305 <output name="tabularmatrix" file="Matrix_imzml.txt"/>
306 </test>
307
308 <test>
309 <param name="infile" value="" ftype="analyze75">
310 <composite_data value="Analyze75.hdr"/>
311 <composite_data value="Analyze75.img"/>
312 <composite_data value="Analyze75.t2m"/>
313 </param>
314 <repeat name="repeatpixel">
315 <param name="plusminusinDalton" value="0.25"/>
316 <param name="inputx" value="5"/>
317 <param name="inputy" value="2"/>
318 <repeat name="zoomedplot">
319 <param name="xlimmin" value="840"/>
320 <param name="xlimmax" value="850"/>
321 </repeat>
322 </repeat>
323 <repeat name="repeatpixel">
324 <param name="plusminusinDalton" value="0.25"/>
325 <param name="inputx" value="2"/>
326 <param name="inputy" value="2"/>
327 </repeat>
328 <output name="plots" file="Plot_analyze75.pdf" compare="sim_size" delta="20000"/>
329 <output name="tabularmatrix" file="Matrix_analyze75.txt"/>
330 </test>
331
332 <test>
333 <param name="infile" value="preprocessing_results1.RData" ftype="rdata"/>
334 <repeat name="repeatpixel">
335 <param name="plusminusinDalton" value="0.25"/>
336 <param name="inputx" value="2"/>
337 <param name="inputy" value="2"/>
338 <repeat name="zoomedplot">
339 <param name="xlimmin" value="222"/>
340 <param name="xlimmax" value="244"/>
341 </repeat>
342 </repeat>
343 <output name="plots" file="Plot_rdata.pdf" compare="sim_size" delta="20000"/>
344 <output name="tabularmatrix" file="Matrix_rdata.txt"/>
345 </test>
346 <test>
347 <param name="infile" value="LM8_file16.rdata" ftype="rdata"/>
348 <param name="plusminusinDalton" value="0.1"/>
349 <param name="inputx" value="1"/>
350 <param name="inputy" value="1"/>
351 <repeat name="repeatpixel">
352 <param name="plusminusinDalton" value="0.25"/>
353 <param name="inputx" value="2"/>
354 <param name="inputy" value="2"/>
355 <repeat name="zoomedplot">
356 <param name="xlimmin" value="1000"/>
357 <param name="xlimmax" value="1050"/>
358 </repeat>
359 </repeat>
360 <output name="plots" file="Plot_LM8_file16.pdf" compare="sim_size" delta="20000"/>
361 <output name="tabularmatrix" file="Matrix_LM8.txt"/>
362 </test>
363 </tests>
364 <help><![CDATA[
365
366 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.
367 Additionally zoom into mass-spectra plots is possible by providing the minimum and maximum mz value to define the limits of the plot.
368 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.
369
370 Input data: 3 types of input data can be used:
371
372 - imzml file (upload imzml and ibd file via the "composite" function) `Introduction to the imzml format <http://ms-imaging.org/wp/introduction/>`_
373 - Analyze7.5 (upload hdr, img and t2m file via the "composite" function)
374 - Cardinal "MSImageSet" data (with variable name "msidata", saved as .RData)
375
376 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.
377
378 ]]>
379 </help>
380 <citations>
381 <citation type="doi">10.1093/bioinformatics/btv146</citation>
382 </citations>
383 </tool>