Mercurial > repos > galaxyp > cardinal_spectra_plots
comparison 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 |
comparison
equal
deleted
inserted
replaced
6:043f9c91f686 | 7:64ea4507e0bd |
---|---|
1 <tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.3"> | 1 <tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.0"> |
2 <description> | 2 <description> |
3 mass spectrometry imaging mass spectra plots | 3 mass spectrometry imaging mass spectra plots |
4 </description> | 4 </description> |
5 <macros> | 5 <macros> |
6 <import>macros.xml</import> | 6 <import>macros.xml</import> |
7 </macros> | 7 </macros> |
8 <expand macro="requirements"> | 8 <expand macro="requirements"> |
9 <requirement type="package" version="3.0">r-ggplot2</requirement> | 9 <requirement type="package" version="3.2.1">r-ggplot2</requirement> |
10 <requirement type="package" version="2.3">r-gridextra</requirement> | 10 <requirement type="package" version="2.3">r-gridextra</requirement> |
11 <requirement type="package" version="1.0.0">r-scales</requirement> | 11 <requirement type="package" version="1.0.0">r-scales</requirement> |
12 </expand> | 12 </expand> |
13 <command detect_errors="exit_code"> | 13 <command detect_errors="exit_code"> |
14 <![CDATA[ | 14 <![CDATA[ |
26 library(gridExtra) | 26 library(gridExtra) |
27 library(ggplot2) | 27 library(ggplot2) |
28 library(scales) | 28 library(scales) |
29 | 29 |
30 | 30 |
31 @READING_MSIDATA@ | 31 @READING_MSIDATA_FULLY_COMPATIBLE@ |
32 | 32 |
33 @DATA_PROPERTIES@ | 33 @DATA_PROPERTIES@ |
34 | 34 |
35 | 35 |
36 ######################################## PDF ################################### | 36 ######################################## PDF ################################### |
49 ############################# I) numbers ###################################### | 49 ############################# I) numbers ###################################### |
50 ############################################################################### | 50 ############################################################################### |
51 | 51 |
52 grid.table(property_df, rows= NULL) | 52 grid.table(property_df, rows= NULL) |
53 | 53 |
54 ## set NA to 0 otherwise plot function will not work | |
55 | |
56 #if str($processed_cond.processed_file) == "processed": | |
57 ##processed file needs to be converted into matrix to be able to replace NAs | |
58 iData(msidata) <- iData(msidata)[] | |
59 #end if | |
60 | |
61 spectra(msidata)[is.na(spectra(msidata))] = 0 | |
62 | |
63 ## run only if mz and pixels are > 0 | 54 ## run only if mz and pixels are > 0 |
64 | 55 |
65 if (ncol(msidata)>0 & nrow(msidata) >0){ | 56 if (ncol(msidata)>0 & nrow(msidata) >0){ |
66 | 57 |
67 pixeldf = data.frame(matrix(ncol = 2, nrow=0)) | 58 pixeldf = data.frame(matrix(ncol = 2, nrow=0)) |
68 | 59 |
69 ############################# single pixel ################################ | 60 ############################# single pixel ################################ |
70 ########################################################################### | 61 ########################################################################### |
71 | 62 |
72 #if str( $pixel_conditional.pixel_type) == 'single_pixel': | 63 #if str( $pixel_conditional.pixel_type) == 'tabular_pixel': |
73 print("single_pixel") | 64 print("tabular_pixel") |
74 | 65 |
75 #for $chosenpixel in $pixel_conditional.repeatpixel: | 66 ## read and extract x,y, optional annotation information |
76 | 67 spectra_tabular = read.delim("$pixel_conditional.pixel_file", header = $pixel_conditional.tabular_pixel_header, stringsAsFactors = FALSE) |
77 pixelname = paste0("x = ", $chosenpixel.inputx,", ", "y = ", $chosenpixel.inputy) | 68 |
78 | 69 #if $pixel_conditional.column_pixel_annotation: |
79 | 70 |
80 | 71 spectra_input = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y, $pixel_conditional.column_pixel_annotation)] |
81 input_pixels = paste($chosenpixel.inputx, $chosenpixel.inputy, sep="_") | 72 colnames(spectra_input) = c("x", "y", "annotation") |
82 dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_") | 73 |
83 | 74 input_pixels = paste(spectra_input[,1], spectra_input[,2], sep="_") |
84 pixelisvalid = as.character(input_pixels %in% dataset_pixels) | 75 dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_") |
85 | 76 pixelsofinterest = dataset_pixels %in% input_pixels |
86 | 77 msidata = msidata[,pixelsofinterest] |
87 | 78 |
88 pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid)) | 79 ## merge with coordinate information of msidata |
89 | 80 msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y, c(1:ncol(msidata))) |
90 ############################# II) control image #################### | 81 colnames(msidata_coordinates) = c("x", "y", "pixel_index") |
91 | 82 merged_annotation = merge(msidata_coordinates, spectra_input, by=c("x", "y"), all.x=TRUE) |
92 if (pixelisvalid == "TRUE"){ | 83 merged_annotation[is.na(merged_annotation)] = "NA" |
93 | 84 merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),] |
94 image(msidata, mz=$chosenpixel.inputmz, ylim = c(maximumy+(0.2*maximumy),minimumy-1), | 85 msidata\$annotation = as.factor(merged_annotation[,4]) |
95 colorkey=FALSE, plusminus = $chosenpixel.plusminusinDalton, | |
96 main= paste0("x= ",$chosenpixel.inputx, ", y= ", $chosenpixel.inputy)) | |
97 | |
98 abline(v=$chosenpixel.inputx, col ="$chosenpixel.inputcolour", lty="$chosenpixel.inputtype", lwd=$chosenpixel.inputwidth) | |
99 abline(h=$chosenpixel.inputy, col ="$chosenpixel.inputcolour", lty="$chosenpixel.inputtype", lwd=$chosenpixel.inputwidth) | |
100 | |
101 ##################### III) plot full mass spectrum ################# | |
102 | |
103 plot(msidata, coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy), main="Mass spectrum of full m/z range") | |
104 | |
105 ##################### IV) plot zoom-in mass spectrum ############### | |
106 | |
107 #if $chosenpixel.zoomedplot: | |
108 | |
109 #for $token in $chosenpixel.zoomedplot: | |
110 | |
111 minmasspixel = features(msidata, mz=$token.xlimmin) | |
112 maxmasspixel = features(msidata, mz=$token.xlimmax) | |
113 | |
114 plot(msidata[minmasspixel:maxmasspixel,], coord=list(x=$chosenpixel.inputx, y=$chosenpixel.inputy), | |
115 xlim= c($token.xlimmin,$token.xlimmax)) | |
116 | |
117 #end for | |
118 #end if | |
119 }else{ | |
120 print("The pixel coordinates did not correspond to a real pixel")} | |
121 #end for | |
122 | |
123 colnames(pixeldf) = c("pixel coordinates", "coordinates were found in this file") | |
124 | |
125 ############################# sample pixel ################################ | |
126 ########################################################################### | |
127 | |
128 #elif str( $pixel_conditional.pixel_type) == 'sample_pixel': | |
129 print("sample pixels") | |
130 | |
131 ## optional annotation from tabular file to obtain pixel groups (otherwise all pixels are considered to be one sample) | |
132 | |
133 #if str($pixel_conditional.tabular_annotation.load_annotation) == 'yes_annotation': | |
134 | |
135 ## read and extract x,y,annotation information | |
136 input_tabular = read.delim("$pixel_conditional.tabular_annotation.annotation_file", header = $pixel_conditional.tabular_annotation.tabular_header, stringsAsFactors = FALSE) | |
137 annotation_input = input_tabular[,c($pixel_conditional.tabular_annotation.column_x, $pixel_conditional.tabular_annotation.column_y, $pixel_conditional.tabular_annotation.column_names)] | |
138 colnames(annotation_input) = c("x", "y", "annotation") | |
139 | |
140 ## merge with coordinate information of msidata | |
141 msidata_coordinates = cbind(coord(msidata)[,1:2], c(1:ncol(msidata))) | |
142 colnames(msidata_coordinates)[3] = "pixel_index" | |
143 merged_annotation = merge(msidata_coordinates, annotation_input, by=c("x", "y"), all.x=TRUE) | |
144 merged_annotation[is.na(merged_annotation)] = "NA" | |
145 merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),] | |
146 msidata\$annotation = as.factor(merged_annotation[,4]) | |
147 | |
148 #end if | |
149 | |
150 ##################### I) Sample: plot full mass spectrum ############## | |
151 | |
152 ## coloured plot with mean over all spectra with the same annotation, if no annotation is provided all pixels are considered as one sample | |
153 | |
154 if (!is.null(levels(msidata\$annotation))){ | |
155 print("annotated samples") | |
156 | 86 |
157 ## overview plot over annotated samples | 87 ## overview plot over annotated samples |
158 number_combined = length(levels(msidata\$annotation)) | 88 number_combined = length(levels(msidata\$annotation)) |
159 | 89 |
160 ## the more annotation groups a file has the smaller will be the legend | 90 ## the more annotation groups a file has the smaller will be the legend |
168 legend_size = 7 | 98 legend_size = 7 |
169 }else{ | 99 }else{ |
170 legend_size = 6 | 100 legend_size = 6 |
171 } | 101 } |
172 | 102 |
173 position_df = cbind(coord(msidata)[,1:2], as.factor(msidata\$annotation)) | 103 position_df = data.frame(coord(msidata)\$x, coord(msidata)\$y, as.factor(msidata\$annotation)) |
174 colnames(position_df)[3] = "sample_name" | 104 colnames(position_df) = c("x", "y", "sample_name") |
175 | 105 |
176 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+ | 106 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+ |
177 geom_tile(height = 1, width=1)+ | 107 geom_tile(height = 1, width=1)+ |
178 coord_fixed()+ | 108 coord_fixed()+ |
179 ggtitle("Spatial orientation of pixel annotations")+ | 109 ggtitle("Spatial orientation of annotations")+ |
180 theme_bw()+ | 110 theme_bw()+ |
181 theme(plot.title = element_text(hjust = 0.5))+ | 111 theme(plot.title = element_text(hjust = 0.5))+ |
182 theme(text=element_text(family="ArialMT", face="bold", size=12))+ | 112 theme(text=element_text(family="ArialMT", face="bold", size=12))+ |
183 theme(legend.position="bottom",legend.direction="vertical")+ | 113 theme(legend.position="bottom",legend.direction="vertical")+ |
184 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 6))+ | 114 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 6))+ |
196 ## print legend only for less than 10 samples | 126 ## print legend only for less than 10 samples |
197 if (length(levels(msidata\$annotation)) < 10){ | 127 if (length(levels(msidata\$annotation)) < 10){ |
198 key_legend = TRUE | 128 key_legend = TRUE |
199 }else{key_legend = FALSE} | 129 }else{key_legend = FALSE} |
200 | 130 |
201 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") | 131 #if $fullmz: |
202 }else{ | 132 ## plot single tabular mz, average per annotation |
203 plot(msidata, pixel=1:ncol(msidata), key=TRUE, main="Average mass spectrum of full m/z range")} | 133 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") |
134 #end if | |
135 | |
136 pixeldf = data.frame(table(msidata\$annotation)) | |
137 colnames(pixeldf) = c("sample name", "number of pixels") | |
138 | |
139 | |
140 ##################### II) Sample: plot zoom-in mass spectrum ########## | |
141 | |
142 #if str($mz_range.mz_range_options) == "manual_mz": | |
143 | |
144 #for $token in $mz_range.zoomed_sample: | |
145 | |
146 | |
147 minmasspixel = tryCatch( | |
148 { | |
149 features(msidata, mz=$token.xlimmin) | |
150 }, | |
151 warning=function(cond) { | |
152 ## if xlimmin is outside mz range, use min mz value | |
153 return(features(msidata, mz=min(mz(msidata)))) | |
154 } | |
155 ) | |
156 | |
157 maxmasspixel = tryCatch( | |
158 { | |
159 features(msidata, mz=$token.xlimmax) | |
160 }, | |
161 warning=function(cond) { | |
162 ## if xlimax is outside mz range, use max mz value | |
163 return(features(msidata, mz=max(mz(msidata)))) | |
164 } | |
165 ) | |
166 | |
167 ## plot single tabular mz, average per annotation, manual zoom | |
168 print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE, | |
169 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable, | |
170 key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE, main="Average spectrum per group")) | |
171 #end for | |
172 | |
173 #elif str($mz_range.mz_range_options) == "tabular_mz": | |
174 | |
175 input_mz = read.delim("$mz_range.mz_file", header = $mz_range.tabular_header, stringsAsFactors = FALSE) | |
176 input_mz_features = input_mz[,c($mz_range.column_mz)] | |
177 for (feature_count in input_mz_features){ | |
178 | |
179 if (feature_count>min(mz(msidata))&feature_count<max(mz(msidata))){ | |
180 | |
181 xlimmin = feature_count-$mz_range.minus_mz_tab | |
182 xlimmax = feature_count+$mz_range.plus_mz_tab | |
183 | |
184 minmasspixel = features(msidata, mz=xlimmin) | |
185 maxmasspixel = features(msidata, mz=xlimmax) | |
186 | |
187 ## plot single tabular mz, average per annotation, tabular zoom | |
188 print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE, main="Average spectrum per group", | |
189 xlim= c(xlimmin,xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable, | |
190 key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE)) | |
191 } | |
192 } | |
193 | |
194 #end if | |
195 | |
196 #elif str($pixel_conditional.column_pixel_annotation)== "None": | |
197 | |
198 spectra_tabular = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y)] | |
199 colnames(spectra_tabular) = c("x", "y") | |
200 | |
201 dataset_pixels = data.frame(coord(msidata)\$x, coord(msidata)\$y) | |
202 colnames(dataset_pixels) = c("x", "y") | |
203 spectra_input = merge(dataset_pixels, spectra_tabular, by=c("x", "y")) | |
204 false_input = merge(spectra_tabular, spectra_input, by=c("x", "y")) | |
205 | |
206 ## for loop for every valid spectrum (pixel) | |
207 for (pixel_count in 1:nrow(spectra_input)){ | |
208 | |
209 x_coord = spectra_input[pixel_count,1] | |
210 y_coord = spectra_input[pixel_count,2] | |
211 | |
212 | |
213 ##################### I) Sample: plot full mass spectrum ############## | |
214 | |
215 #if $fullmz: | |
216 ## plot full mz for single tabular mz | |
217 print(plot(msidata, coord=list(x=x_coord, y=y_coord), key=TRUE, grid = $grid_variable)) | |
218 #end if | |
219 | |
220 pixelname = paste0("x = ", x_coord,", ", "y = ", y_coord) | |
221 | |
222 input_pixels = paste(x_coord, y_coord, sep="_") | |
223 dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_") | |
224 pixelisvalid = as.character(input_pixels %in% dataset_pixels) | |
225 | |
226 pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid)) | |
227 | |
228 | |
229 ##################### II) Sample: plot zoom-in mass spectrum ########## | |
230 | |
231 #if str($mz_range.mz_range_options) == "manual_mz": | |
232 #for $token in $mz_range.zoomed_sample: | |
233 | |
234 minmasspixel = tryCatch( | |
235 { | |
236 features(msidata, mz=$token.xlimmin) | |
237 }, | |
238 warning=function(cond) { | |
239 ## if xlimmin is outside mz range, use min mz value | |
240 return(features(msidata, mz=min(mz(msidata)))) | |
241 } | |
242 ) | |
243 | |
244 maxmasspixel = tryCatch( | |
245 { | |
246 features(msidata, mz=$token.xlimmax) | |
247 }, | |
248 warning=function(cond) { | |
249 ## if xlimax is outside mz range, use max mz value | |
250 return(features(msidata, mz=max(mz(msidata)))) | |
251 } | |
252 ) | |
253 | |
254 ## same min and max not possible for plot | |
255 if (minmasspixel == maxmasspixel){ | |
256 if (maxmasspixel == nrow(msidata)){ | |
257 minmasspixel = minmasspixel-1 | |
258 }else{ | |
259 maxmasspixel = maxmasspixel+1 | |
260 } | |
261 } | |
262 | |
263 ## print single tabular mz; manual zoom | |
264 print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, coord=list(x=x_coord, y=y_coord), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))) | |
265 | |
266 #end for | |
267 | |
268 #elif str($mz_range.mz_range_options) == "tabular_mz": | |
269 | |
270 input_mz = read.delim("$mz_range.mz_file", header = $mz_range.tabular_header, stringsAsFactors = FALSE) | |
271 input_mz_features = input_mz[,c($mz_range.column_mz)] | |
272 for (feature_count in input_mz_features){ | |
273 | |
274 if (feature_count>min(mz(msidata))&feature_count<max(mz(msidata))){ | |
275 | |
276 xlimmin = feature_count-$mz_range.minus_mz_tab | |
277 xlimmax = feature_count+$mz_range.plus_mz_tab | |
278 | |
279 minmasspixel = tryCatch( | |
280 { | |
281 features(msidata, mz=xlimmin) | |
282 }, | |
283 warning=function(cond) { | |
284 ## if xlimmin is outside mz range, use min mz value | |
285 return(features(msidata, mz=min(mz(msidata)))) | |
286 } | |
287 ) | |
288 | |
289 maxmasspixel = tryCatch( | |
290 { | |
291 maxmasspixel = features(msidata, mz=xlimmax) | |
292 }, | |
293 warning=function(cond) { | |
294 ## if xlimax is outside mz range, use max mz value | |
295 return(features(msidata, mz=max(mz(msidata)))) | |
296 } | |
297 ) | |
298 | |
299 ## same min and max not possible for plot | |
300 if (minmasspixel == maxmasspixel){ | |
301 if (maxmasspixel == nrow(msidata)){ | |
302 minmasspixel = minmasspixel-1 | |
303 }else{ | |
304 maxmasspixel = maxmasspixel+1 | |
305 } | |
306 } | |
307 | |
308 ## print single tabular mz; tabular zoom | |
309 print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, coord=list(x=x_coord, y=y_coord), key=TRUE, xlim= c(xlimmin,xlimmax))) | |
310 } | |
311 } | |
312 | |
313 #end if | |
314 | |
315 } | |
316 | |
317 colnames(pixeldf) = c("pixel coordinates", "coordinates were found in this file") | |
318 | |
319 #end if | |
320 | |
321 | |
322 ############################# all pixel ################################ | |
323 ########################################################################### | |
324 | |
325 #elif str( $pixel_conditional.pixel_type) == 'all_pixel': | |
326 print("all pixels") | |
327 | |
328 ##################### I) Sample: plot full mass spectrum ############## | |
329 | |
330 #if $fullmz: | |
331 | |
332 print(plot(msidata, run="infile", key=TRUE, strip=FALSE, main="Average spectrum", grid = $grid_variable)) | |
333 #end if | |
204 | 334 |
205 ##################### II) Sample: plot zoom-in mass spectrum ########## | 335 ##################### II) Sample: plot zoom-in mass spectrum ########## |
206 | 336 |
207 #if $pixel_conditional.zoomed_sample: | 337 #if str($mz_range.mz_range_options) == "manual_mz": |
208 #for $token in $pixel_conditional.zoomed_sample: | 338 #for $token in $mz_range.zoomed_sample: |
209 print("zoomed sample pixels") | 339 |
210 | 340 minmasspixel = tryCatch( |
211 minmasspixel = features(msidata, mz=$token.xlimmin) | 341 { |
212 maxmasspixel = features(msidata, mz=$token.xlimmax) | 342 features(msidata, mz=$token.xlimmin) |
213 | 343 }, |
214 ## coloured plot with mean over all spectra for annotation group, otherwise only 1 black plot | 344 warning=function(cond) { |
215 if (!is.null(levels(msidata\$annotation))){ | 345 ## if xlimmin is outside mz range, use min mz value |
216 print("annotation samples") | 346 return(features(msidata, mz=min(mz(msidata)))) |
217 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), | 347 } |
218 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation, | 348 ) |
219 key=key_legend,col=hue_pal()(length(levels(msidata\$annotation))), superpose=TRUE) | 349 |
220 }else{ | 350 maxmasspixel = tryCatch( |
221 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))} | 351 { |
352 features(msidata, mz=$token.xlimmax) | |
353 }, | |
354 warning=function(cond) { | |
355 ## if xlimax is outside mz range, use max mz value | |
356 return(features(msidata, mz=max(mz(msidata)))) | |
357 } | |
358 ) | |
359 | |
360 ## same min and max not possible for plot | |
361 if (minmasspixel == maxmasspixel){ | |
362 if (maxmasspixel == nrow(msidata)){ | |
363 minmasspixel = minmasspixel-1 | |
364 }else{ | |
365 maxmasspixel = maxmasspixel+1 | |
366 } | |
367 } | |
368 | |
369 print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, main="Average spectrum", run = "infile", strip=FALSE, key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))) | |
222 | 370 |
223 #end for | 371 #end for |
372 | |
373 #elif str($mz_range.mz_range_options) == "tabular_mz": | |
374 | |
375 input_mz = read.delim("$mz_range.mz_file", header = $mz_range.tabular_header, stringsAsFactors = FALSE) | |
376 input_mz_features = input_mz[,c($mz_range.column_mz)] | |
377 for (feature_count in input_mz_features){ | |
378 | |
379 if (feature_count>min(mz(msidata))&feature_count<max(mz(msidata))){ | |
380 | |
381 xlimmin = feature_count-$mz_range.minus_mz_tab | |
382 xlimmax = feature_count+$mz_range.plus_mz_tab | |
383 | |
384 minmasspixel = tryCatch( | |
385 { | |
386 features(msidata, mz=xlimmin) | |
387 }, | |
388 warning=function(cond) { | |
389 ## if xlimmin is outside mz range, use min mz value | |
390 return(features(msidata, mz=min(mz(msidata)))) | |
391 } | |
392 ) | |
393 | |
394 maxmasspixel = tryCatch( | |
395 { | |
396 maxmasspixel = features(msidata, mz=xlimmax) | |
397 }, | |
398 warning=function(cond) { | |
399 ## if xlimax is outside mz range, use max mz value | |
400 return(features(msidata, mz=max(mz(msidata)))) | |
401 } | |
402 ) | |
403 | |
404 print(plot(msidata[minmasspixel:maxmasspixel,], grid = $grid_variable, run="infile", key=TRUE, strip=FALSE, main="Average spectrum", xlim= c(xlimmin,xlimmax))) | |
405 } | |
406 } | |
407 | |
408 | |
224 #end if | 409 #end if |
225 | 410 |
226 if (!is.null(levels(msidata\$annotation))){ | 411 pixeldf = data.frame("$filename", ncol(msidata)) |
227 pixeldf = data.frame(table(msidata\$annotation)) | 412 colnames(pixeldf) = c("sample name", "number of pixels") |
228 }else{ | |
229 pixeldf = data.frame("$filename", ncol(msidata))} | |
230 colnames(pixeldf) = c("sample name", "number of pixels") | |
231 | 413 |
232 #end if | 414 #end if |
233 | 415 |
234 | 416 |
235 ############################# pixel table ###################################### | 417 ############################# pixel table ###################################### |
272 </configfiles> | 454 </configfiles> |
273 <inputs> | 455 <inputs> |
274 <expand macro="reading_msidata"/> | 456 <expand macro="reading_msidata"/> |
275 <expand macro="pdf_filename"/> | 457 <expand macro="pdf_filename"/> |
276 <conditional name="pixel_conditional"> | 458 <conditional name="pixel_conditional"> |
277 <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"> | 459 <param name="pixel_type" type="select" label="Choose spectra (pixel)"> |
278 <option value="single_pixel" selected="True">Single pixel</option> | 460 <option value="all_pixel" selected="True" >All spectra</option> |
279 <option value="sample_pixel">Average spectrum for each sample</option> | 461 <option value="tabular_pixel">Single spectra</option> |
280 </param> | 462 </param> |
281 <when value="single_pixel"> | 463 <when value="tabular_pixel"> |
282 <repeat name="repeatpixel" title="Plot mass spectra for pixel of interest" min="1" max="20"> | 464 <param name="pixel_file" type="data" format="tabular" label="Load tabular file with pixel coordinates" |
283 <param name="inputx" type="integer" value="" label="x-coordinate of pixel of interest" help="x-value of the pixel of interest"/> | 465 help="Two or three columns: x values, y values, optionally annotations"/> |
284 <param name="inputy" type="integer" value="" label="y-coordinate of pixel of interest" help="y-value of the pixel of interest"/> | 466 <param name="column_pixel_x" data_ref="pixel_file" label="Column with x values" type="data_column"/> |
285 <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"/> | 467 <param name="column_pixel_y" data_ref="pixel_file" label="Column with y values" type="data_column"/> |
286 <param name="plusminusinDalton" value="0.25" type="float" label="m/z range for this m/z value" help="plusminus m/z window "/> | 468 <param name="column_pixel_annotation" data_ref="pixel_file" optional="True" label="Column with annotations" type="data_column"/> |
287 <param name="inputcolour" type="select" label="Select the colour for the lines at x and y position"> | 469 <param name="tabular_pixel_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/> |
288 <option value="white" selected="True">white</option> | |
289 <option value="black">black</option> | |
290 <option value="grey">grey</option> | |
291 <option value="blue">blue</option> | |
292 <option value="red">red</option> | |
293 <option value="green">green</option> | |
294 </param> | |
295 <param name="inputtype" type="select" label="Select the line type for the lines at x and y position"> | |
296 <option value="solid" selected="True">solid</option> | |
297 <option value="dashed">dashed</option> | |
298 <option value="dotted">dotted</option> | |
299 <option value="longdash">longdash</option> | |
300 </param> | |
301 <param name="inputwidth" type="integer" value="2" label="Select the width of the lines at x and y position"/> | |
302 <repeat name="zoomedplot" title="Zoomed in plots with m/z min and m/z max to define the plot window" min="0" max="50"> | |
303 <param name="xlimmin" type="integer" value="" label="lower m/z boundary for plotting window" help="minimum m/z for zoomed in window"/> | |
304 <param name="xlimmax" type="integer" value="" label="upper m/z boundary for plotting window" help="maximum m/z for zoomed in window"/> | |
305 </repeat> | |
306 </repeat> | |
307 </when> | 470 </when> |
308 <when value="sample_pixel"> | 471 <when value="all_pixel"> |
309 <conditional name="tabular_annotation"> | 472 </when> |
310 <param name="load_annotation" type="select" label="Use pixel annotation from tabular file for spectra plots"> | 473 </conditional> |
311 <option value="no_annotation" selected="True">pixels belong into one group only</option> | 474 <param name="fullmz" type="boolean" label="Plot complete m/z range" checked="True" truevalue="TRUE" falsevalue="FALSE"/> |
312 <option value="yes_annotation">group pixels according to annotations</option> | 475 <conditional name="mz_range"> |
313 </param> | 476 <param name="mz_range_options" type="select" label="zoomed in m/z range"> |
314 <when value="yes_annotation"> | 477 <option value="none_mz" selected="True">no m/z range</option> |
315 <expand macro="reading_pixel_annotations"/> | 478 <option value="manual_mz" >Manual input</option> |
316 </when> | 479 <option value="tabular_mz">Tabular file</option> |
317 <when value="no_annotation"/> | 480 </param> |
318 </conditional> | 481 <when value="none_mz"/> |
319 <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"> | 482 <when value="tabular_mz"> |
320 <param name="xlimmin" type="integer" value="" label="lower m/z boundary for plotting window" help="minimum m/z for zoomed in window"/> | 483 <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"/> |
321 <param name="xlimmax" type="integer" value="" label="upper m/z boundary for plotting window" help="maximum m/z for zoomed in window"/> | 484 <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"/> |
485 <param name="mz_file" type="data" format="tabular" label="Load tabular file with m/z values"/> | |
486 <param name="column_mz" data_ref="mz_file" label="Column with mz values" type="data_column"/> | |
487 <param name="tabular_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/> | |
488 </when> | |
489 <when value="manual_mz"> | |
490 <repeat name="zoomed_sample" title="Define min m/z and max m/z for the plotting window" min="1"> | |
491 <param name="xlimmin" type="float" value="" label="lower m/z boundary for plotting window"/> | |
492 <param name="xlimmax" type="float" value="" label="upper m/z boundary for plotting window"/> | |
322 </repeat> | 493 </repeat> |
323 </when> | 494 </when> |
324 </conditional> | 495 </conditional> |
496 <param name="grid_variable" type="boolean" label="Add grid to plot" truevalue="TRUE" falsevalue="FALSE"/> | |
325 </inputs> | 497 </inputs> |
326 <outputs> | 498 <outputs> |
327 <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label="${tool.name} on ${on_string}:results"/> | 499 <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label="${tool.name} on ${on_string}:results"/> |
328 </outputs> | 500 </outputs> |
329 <tests> | 501 <tests> |
330 <test> | 502 <test> |
331 <expand macro="infile_imzml"/> | 503 <expand macro="infile_imzml"/> |
332 <conditional name="pixel_conditional"> | 504 <conditional name="pixel_conditional"> |
333 <param name="pixel_type" value="single_pixel"/> | 505 <param name="pixel_type" value="tabular_pixel"/> |
334 <repeat name="repeatpixel"> | 506 <param name="pixel_file" value="spectra_1_pixel.tabular"/> |
335 <param name="plusminusinDalton" value="0.25"/> | 507 <param name="column_pixel_x" value="1"/> |
336 <param name="inputx" value="3"/> | 508 <param name="column_pixel_y" value="2"/> |
337 <param name="inputy" value="3"/> | 509 <param name="tabular_pixel_header" value="FALSE"/> |
338 <repeat name="zoomedplot"> | 510 </conditional> |
339 <param name="xlimmin" value="310"/> | 511 <param name="fullmz" value="TRUE"/> |
340 <param name="xlimmax" value="320"/> | 512 <conditional name="mz_range"> |
341 </repeat> | 513 <param name="mz_range_options" value="manual_mz"/> |
342 <repeat name="zoomedplot"> | 514 <repeat name="zoomed_sample"> |
343 <param name="xlimmin" value="350"/> | 515 <param name="xlimmin" value="310"/> |
344 <param name="xlimmax" value="400"/> | 516 <param name="xlimmax" value="320"/> |
345 </repeat> | 517 </repeat> |
346 <repeat name="zoomedplot"> | 518 <repeat name="zoomed_sample"> |
347 <param name="xlimmin" value="400"/> | 519 <param name="xlimmin" value="350"/> |
348 <param name="xlimmax" value="420"/> | 520 <param name="xlimmax" value="400"/> |
349 </repeat> | 521 </repeat> |
350 </repeat> | 522 <repeat name="zoomed_sample"> |
351 <repeat name="repeatpixel"> | 523 <param name="xlimmin" value="360"/> |
352 <param name="plusminusinDalton" value="0.25"/> | 524 <param name="xlimmax" value="360.8"/> |
353 <param name="inputx" value="2"/> | |
354 <param name="inputy" value="2"/> | |
355 </repeat> | |
356 <repeat name="repeatpixel"> | |
357 <param name="plusminusinDalton" value="0.25"/> | |
358 <param name="inputx" value="1"/> | |
359 <param name="inputy" value="1"/> | |
360 </repeat> | 525 </repeat> |
361 </conditional> | 526 </conditional> |
527 <param name="grid_variable" value="TRUE"/> | |
362 <output name="plots" file="Plot_imzml.pdf" compare="sim_size"/> | 528 <output name="plots" file="Plot_imzml.pdf" compare="sim_size"/> |
363 </test> | 529 </test> |
364 <test> | 530 <test> |
365 <expand macro="infile_analyze75"/> | 531 <expand macro="infile_analyze75"/> |
366 <conditional name="pixel_conditional"> | 532 <conditional name="pixel_conditional"> |
367 <param name="pixel_type" value="single_pixel"/> | 533 <param name="pixel_type" value="tabular_pixel"/> |
368 <repeat name="repeatpixel"> | 534 <param name="pixel_file" value="spectra_1_pixel.tabular"/> |
369 <param name="plusminusinDalton" value="0.25"/> | 535 <param name="column_pixel_x" value="1"/> |
370 <param name="inputx" value="5"/> | 536 <param name="column_pixel_y" value="2"/> |
371 <param name="inputy" value="2"/> | 537 <param name="tabular_pixel_header" value="TRUE"/> |
372 <repeat name="zoomedplot"> | |
373 <param name="xlimmin" value="840"/> | |
374 <param name="xlimmax" value="850"/> | |
375 </repeat> | |
376 </repeat> | |
377 <repeat name="repeatpixel"> | |
378 <param name="plusminusinDalton" value="0.25"/> | |
379 <param name="inputx" value="2"/> | |
380 <param name="inputy" value="2"/> | |
381 </repeat> | |
382 </conditional> | 538 </conditional> |
539 <param name="fullmz" value="TRUE"/> | |
540 <conditional name="mz_range"> | |
541 <param name="mz_range_options" value="manual_mz"/> | |
542 <repeat name="zoomed_sample"> | |
543 <param name="xlimmin" value="840"/> | |
544 <param name="xlimmax" value="850"/> | |
545 </repeat> | |
546 </conditional> | |
547 <param name="grid_variable" value="FALSE"/> | |
383 <output name="plots" file="Plot_analyze75.pdf" compare="sim_size"/> | 548 <output name="plots" file="Plot_analyze75.pdf" compare="sim_size"/> |
384 </test> | 549 </test> |
385 <test> | 550 <test> |
386 <expand macro="infile_analyze75"/> | 551 <expand macro="infile_analyze75"/> |
387 <conditional name="pixel_conditional"> | 552 <conditional name="pixel_conditional"> |
388 <param name="pixel_type" value="sample_pixel"/> | 553 <param name="pixel_type" value="tabular_pixel"/> |
389 <conditional name="tabular_annotation"> | 554 <param name="pixel_file" value="annotations.tabular"/> |
390 | 555 <param name="column_pixel_x" value="1"/> |
391 <param name="load_annotation" value="yes_annotation"/> | 556 <param name="column_pixel_y" value="2"/> |
392 <param name="annotation_file" value="annotations.tabular" ftype="tabular"/> | 557 <param name="column_pixel_annotation" value="4"/> |
393 <param name="column_x" value="1"/> | 558 <param name="tabular_pixel_header" value="TRUE"/> |
394 <param name="column_y" value="2"/> | 559 </conditional> |
395 <param name="column_names" value="4"/> | 560 <param name="fullmz" value="FALSE"/> |
396 <param name="tabular_header" value="TRUE"/> | 561 <conditional name="mz_range"> |
397 | 562 <param name="mz_range_options" value="manual_mz"/> |
398 | 563 <repeat name="zoomed_sample"> |
399 | 564 <param name="xlimmin" value="1250"/> |
565 <param name="xlimmax" value="1270"/> | |
566 </repeat> | |
400 </conditional> | 567 </conditional> |
401 <repeat name="zoomed_sample"> | 568 <param name="grid_variable" value="FALSE"/> |
402 <param name="xlimmin" value="1250"/> | |
403 <param name="xlimmax" value="1270"/> | |
404 </repeat> | |
405 </conditional> | |
406 <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size"/> | 569 <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size"/> |
407 </test> | 570 </test> |
408 <test> | 571 <test> |
409 <param name="infile" value="3_files_combined.RData" ftype="rdata"/> | 572 <param name="infile" value="3_files_combined.RData" ftype="rdata"/> |
410 <conditional name="pixel_conditional"> | 573 <conditional name="pixel_conditional"> |
411 <param name="pixel_type" value="sample_pixel"/> | 574 <param name="pixel_type" value="all_pixel"/> |
412 <repeat name="zoomed_sample"> | |
413 <param name="xlimmin" value="350"/> | |
414 <param name="xlimmax" value="360"/> | |
415 </repeat> | |
416 </conditional> | 575 </conditional> |
576 <param name="fullmz" value="TRUE"/> | |
577 <conditional name="mz_range"> | |
578 <param name="mz_range_options" value="manual_mz"/> | |
579 <repeat name="zoomed_sample"> | |
580 <param name="xlimmin" value="350"/> | |
581 <param name="xlimmax" value="360"/> | |
582 </repeat> | |
583 </conditional> | |
584 <param name="grid_variable" value="FALSE"/> | |
417 <output name="plots" file="Plot_rdata.pdf" compare="sim_size"/> | 585 <output name="plots" file="Plot_rdata.pdf" compare="sim_size"/> |
418 </test> | 586 </test> |
419 <test> | 587 <test> |
420 <param name="infile" value="empty_spectra.rdata" ftype="rdata"/> | 588 <expand macro="processed_infile_imzml"/> |
589 <conditional name="processed_cond"> | |
590 <param name="processed_file" value="processed"/> | |
591 <param name="accuracy" value="50"/> | |
592 <param name="units" value="ppm"/> | |
593 </conditional> | |
421 <conditional name="pixel_conditional"> | 594 <conditional name="pixel_conditional"> |
422 <param name="pixel_type" value="single_pixel"/> | 595 <param name="pixel_type" value="all_pixel"/> |
423 <repeat name="repeatpixel"> | |
424 <param name="plusminusinDalton" value="0.1"/> | |
425 <param name="inputx" value="1"/> | |
426 <param name="inputy" value="1"/> | |
427 </repeat> | |
428 </conditional> | 596 </conditional> |
429 <output name="plots" file="Plot_empty_spectra.pdf" compare="sim_size"/> | 597 <param name="fullmz" value="FALSE"/> |
598 <conditional name="mz_range"> | |
599 <param name="mz_range_options" value="manual_mz"/> | |
600 <repeat name="zoomed_sample"> | |
601 <param name="xlimmin" value="350"/> | |
602 <param name="xlimmax" value="350.5"/> | |
603 </repeat> | |
604 <repeat name="zoomed_sample"> | |
605 <param name="xlimmin" value="600"/> | |
606 <param name="xlimmax" value="650"/> | |
607 </repeat> | |
608 </conditional> | |
609 <param name="grid_variable" value="TRUE"/> | |
610 <output name="plots" file="Plot_processed.pdf" compare="sim_size"/> | |
611 </test> | |
612 <test> | |
613 <param name="infile" value="" ftype="imzml"> | |
614 <composite_data value="preprocessing_results1.imzml"/> | |
615 <composite_data value="preprocessing_results1.ibd"/> | |
616 </param> | |
617 <param name="centroids" value="TRUE"/> | |
618 <conditional name="pixel_conditional"> | |
619 <param name="pixel_type" value="all_pixel"/> | |
620 </conditional> | |
621 <param name="fullmz" value="TRUE"/> | |
622 <conditional name="mz_range"> | |
623 <param name="mz_range_options" value="manual_mz"/> | |
624 <repeat name="zoomed_sample"> | |
625 <param name="xlimmin" value="328"/> | |
626 <param name="xlimmax" value="330"/> | |
627 </repeat> | |
628 <repeat name="zoomed_sample"> | |
629 <param name="xlimmin" value="335"/> | |
630 <param name="xlimmax" value="340"/> | |
631 </repeat> | |
632 </conditional> | |
633 <param name="grid_variable" value="TRUE"/> | |
634 <output name="plots" file="Plot_picked.pdf" compare="sim_size"/> | |
430 </test> | 635 </test> |
431 </tests> | 636 </tests> |
432 <help><![CDATA[ | 637 <help><![CDATA[ |
433 | 638 |
434 @CARDINAL_DESCRIPTION@ | 639 @CARDINAL_DESCRIPTION@ |
436 ----- | 641 ----- |
437 | 642 |
438 This tool uses the Cardinal plot function to generate (zoomed in) mass spectra plots of mass spectrometry imaging data. | 643 This tool uses the Cardinal plot function to generate (zoomed in) mass spectra plots of mass spectrometry imaging data. |
439 | 644 |
440 @MSIDATA_INPUT_DESCRIPTION@ | 645 @MSIDATA_INPUT_DESCRIPTION@ |
646 | |
441 @SPECTRA_TABULAR_INPUT_DESCRIPTION@ | 647 @SPECTRA_TABULAR_INPUT_DESCRIPTION@ |
442 | 648 |
649 @MZ_TABULAR_INPUT_DESCRIPTION@ | |
650 | |
443 **Options** | 651 **Options** |
444 | 652 |
445 - "single pixel": Returns a full mass spectrum plot for one pixel, which is defined by its x- and y-coordinates | 653 *Choosing spectra* |
446 | 654 |
447 - Enter the x and y coordinates of your pixel of interest | 655 - "All spectra": Plots average mass spectra (mean of all spectra) |
448 - 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. | 656 |
449 - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot | 657 - "Single spectra": Returns a full mass spectrum plot for each input spectrum, which is defined by its x- and y-coordinates |
450 | 658 |
451 - "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 | 659 - the annotation column is optional: |
452 | 660 - without annotation column: plots a separate mass spectrum for every input spectrum |
453 - Additionally zoom into mass spectra plots is possible by providing the minimum and maximum m/z value to define the limits of the plot | 661 - with annotation column: plots average mass spectra for each annotation group in different colours |
454 | 662 |
455 | 663 |
456 **Tip** | 664 *Choosing m/z axis* |
457 | 665 |
458 - 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 | 666 - "Plot complete m/z range": Full m/z range is plotted |
459 - 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 | 667 |
668 - "zoomed in m/z range": Only a customized m/z range is plotted | |
669 | |
670 | |
671 - "Manual input": Provide the minimum and maximum m/z value to define the m/z axis of the plot | |
672 | |
673 - "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 | |
460 | 674 |
461 | 675 |
462 **Output** | 676 **Output** |
463 | 677 |
464 - Pdf with the selected mass spectra plots and additional x-y grid plots | 678 - Single Pdf with all mass spectra plots |
465 | 679 |
466 | 680 |
467 ]]> | 681 ]]> |
468 </help> | 682 </help> |
469 <expand macro="citations"/> | 683 <expand macro="citations"/> |