Mercurial > repos > galaxyp > msi_spectra_plot
comparison msi_spectra_plots.xml @ 4:dcf79af72c8f draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_spectra_plots commit 37da74ed68228b16efbdbde776e7c38cc06eb5d5
| author | galaxyp |
|---|---|
| date | Tue, 19 Jun 2018 18:06:46 -0400 |
| parents | 693a8efdfdeb |
| children | bc931322e4d6 |
comparison
equal
deleted
inserted
replaced
| 3:693a8efdfdeb | 4:dcf79af72c8f |
|---|---|
| 1 <tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.1"> | 1 <tool id="mass_spectrometry_imaging_mzplots" name="MSI plot spectra" version="1.10.0.2"> |
| 2 <description> | 2 <description> |
| 3 mass spectrometry imaging mass spectra plots | 3 mass spectrometry imaging mass spectra plots |
| 4 </description> | 4 </description> |
| 5 <requirements> | 5 <requirements> |
| 6 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement> | 6 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement> |
| 7 <requirement type="package" version="2.2.1">r-gridextra</requirement> | 7 <requirement type="package" version="2.2.1">r-gridextra</requirement> |
| 8 <requirement type="package" version="2.2.1">r-ggplot2</requirement> | |
| 9 <requirement type="package" version="0.5.0">r-scales</requirement> | |
| 8 </requirements> | 10 </requirements> |
| 9 <command detect_errors="exit_code"> | 11 <command detect_errors="exit_code"> |
| 10 <![CDATA[ | 12 <![CDATA[ |
| 11 #if $infile.ext == 'imzml' | 13 #if $infile.ext == 'imzml' |
| 12 ln -s '${infile.extra_files_path}/imzml' infile.imzML && | 14 ln -s '${infile.extra_files_path}/imzml' infile.imzML && |
| 27 | 29 |
| 28 ################################# load libraries and read file ################# | 30 ################################# load libraries and read file ################# |
| 29 | 31 |
| 30 library(Cardinal) | 32 library(Cardinal) |
| 31 library(gridExtra) | 33 library(gridExtra) |
| 32 | 34 library(ggplot2) |
| 33 ## Read MALDI Imaging dataset | 35 library(scales) |
| 34 | 36 |
| 35 #if $infile.ext == 'imzml' | 37 #if $infile.ext == 'imzml' |
| 36 msidata = readImzML('infile') | 38 msidata <- readImzML('infile', mass.accuracy=$accuracy, units.accuracy = "$units") |
| 37 #elif $infile.ext == 'analyze75' | 39 #elif $infile.ext == 'analyze75' |
| 38 msidata = readAnalyze('infile') | 40 msidata = readAnalyze('infile') |
| 39 #else | 41 #else |
| 40 load('infile.RData') | 42 load('infile.RData') |
| 41 #end if | 43 #end if |
| 69 TICs = colSums(spectra(msidata)[]) | 71 TICs = colSums(spectra(msidata)[]) |
| 70 NumemptyTIC = sum(TICs == 0) | 72 NumemptyTIC = sum(TICs == 0) |
| 71 | 73 |
| 72 ## Processing informations | 74 ## Processing informations |
| 73 processinginfo = processingData(msidata) | 75 processinginfo = processingData(msidata) |
| 74 centroidedinfo = processinginfo@centroided # TRUE or FALSE | 76 centroidedinfo = processinginfo@centroided |
| 75 | 77 |
| 76 ## if TRUE write processinginfo if no write FALSE | 78 ## if TRUE write processinginfo if FALSE write FALSE |
| 77 | 79 |
| 78 ## normalization | 80 ## normalization |
| 79 if (length(processinginfo@normalization) == 0) { | 81 if (length(processinginfo@normalization) == 0) { |
| 80 normalizationinfo='FALSE' | 82 normalizationinfo='FALSE' |
| 81 } else { | 83 } else { |
| 99 } else { | 101 } else { |
| 100 peakpickinginfo=processinginfo@peakPicking | 102 peakpickinginfo=processinginfo@peakPicking |
| 101 } | 103 } |
| 102 | 104 |
| 103 properties = c("Number of m/z features", | 105 properties = c("Number of m/z features", |
| 104 "Range of m/z values [Da]", | 106 "Range of m/z values", |
| 105 "Number of pixels", | 107 "Number of pixels", |
| 106 "Range of x coordinates", | 108 "Range of x coordinates", |
| 107 "Range of y coordinates", | 109 "Range of y coordinates", |
| 108 "Range of intensities", | 110 "Range of intensities", |
| 109 "Median of intensities", | 111 "Median of intensities", |
| 206 | 208 |
| 207 ############################# sample pixel ################################ | 209 ############################# sample pixel ################################ |
| 208 ########################################################################### | 210 ########################################################################### |
| 209 | 211 |
| 210 #elif str( $pixel_conditional.pixel_type) == 'sample_pixel': | 212 #elif str( $pixel_conditional.pixel_type) == 'sample_pixel': |
| 211 print("sample_pixel") | 213 print("sample pixels") |
| 212 | 214 |
| 213 ##################### I) Sample: plot full mass spectrum ############## | 215 ##################### I) Sample: plot full mass spectrum ############## |
| 214 | 216 |
| 215 plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$combined_sample, key=TRUE, col=c("blue", "orange", "green", "red", "yellow", "grey"), superpose=TRUE) | 217 ## coloured plot with mean over all spectra for combined_sample, otherwise only 1 black plot |
| 218 if (!is.null(levels(msidata\$combined_sample))){ | |
| 219 print("combined samples") | |
| 220 | |
| 221 ## overview plot over combined sample, in case more than 10 combined_samples legend has to be taken from this plot | |
| 222 number_combined = length(levels(msidata\$combined_sample)) | |
| 223 | |
| 224 ## the more combined_samples a file has the smaller will be the legend | |
| 225 if (number_combined<20){ | |
| 226 legend_size = 10 | |
| 227 }else if (number_combined>20 && number_combined<40){ | |
| 228 legend_size = 9 | |
| 229 }else if (number_combined>40 && number_combined<60){ | |
| 230 legend_size = 8 | |
| 231 }else if (number_combined>60 && number_combined<100){ | |
| 232 legend_size = 7 | |
| 233 }else{ | |
| 234 legend_size = 6 | |
| 235 } | |
| 236 | |
| 237 position_df = cbind(coord(msidata)[,1:2], msidata\$combined_sample) | |
| 238 colnames(position_df)[3] = "sample_name" | |
| 239 | |
| 240 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+ | |
| 241 geom_tile() + | |
| 242 coord_fixed()+ | |
| 243 ggtitle("Spatial orientation of combined data")+ | |
| 244 theme_bw()+ | |
| 245 theme(plot.title = element_text(hjust = 0.5))+ | |
| 246 theme(text=element_text(family="ArialMT", face="bold", size=12))+ | |
| 247 theme(legend.position="bottom",legend.direction="vertical")+ | |
| 248 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = legend_size))+ | |
| 249 guides(fill=guide_legend(ncol=5,byrow=TRUE)) | |
| 250 coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean) | |
| 251 coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$sample_name) | |
| 252 for(file_count in 1:nrow(coord_labels)) | |
| 253 {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"], | |
| 254 y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4]))} | |
| 255 | |
| 256 print(combine_plot) | |
| 257 | |
| 258 ## print legend only for less than 10 samples | |
| 259 if (length(levels(msidata\$combined_sample)) < 10){ | |
| 260 key_legend = TRUE | |
| 261 }else{key_legend = FALSE} | |
| 262 | |
| 263 plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$combined_sample, key=key_legend, col=hue_pal()(length(levels(msidata\$combined_sample))),superpose=TRUE) | |
| 264 }else{ | |
| 265 plot(msidata, pixel=1:ncol(msidata), key=TRUE)} | |
| 216 | 266 |
| 217 ##################### II) Sample: plot zoom-in mass spectrum ########## | 267 ##################### II) Sample: plot zoom-in mass spectrum ########## |
| 218 | 268 |
| 219 #if $pixel_conditional.zoomed_sample: | 269 #if $pixel_conditional.zoomed_sample: |
| 220 #for $token in $pixel_conditional.zoomed_sample: | 270 #for $token in $pixel_conditional.zoomed_sample: |
| 271 print("zoomed sample pixels") | |
| 221 | 272 |
| 222 minmasspixel = features(msidata, mz=$token.xlimmin) | 273 minmasspixel = features(msidata, mz=$token.xlimmin) |
| 223 maxmasspixel = features(msidata, mz=$token.xlimmax) | 274 maxmasspixel = features(msidata, mz=$token.xlimmax) |
| 224 | 275 |
| 225 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), | 276 ## coloured plot with mean over all spectra for combined_sample, otherwise only 1 black plot |
| 226 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$combined_sample, | 277 if (!is.null(levels(msidata\$combined_sample))){ |
| 227 key=TRUE,col=c("blue", "orange", "green", "red", "yellow", "grey"), superpose=TRUE) | 278 print("combined samples") |
| 279 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), | |
| 280 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$combined_sample, | |
| 281 key=key_legend,col=hue_pal()(length(levels(msidata\$combined_sample))), superpose=TRUE) | |
| 282 }else{ | |
| 283 plot(msidata[minmasspixel:maxmasspixel,], pixel=1:ncol(msidata), key=TRUE, xlim= c($token.xlimmin,$token.xlimmax))} | |
| 228 | 284 |
| 229 #end for | 285 #end for |
| 230 #end if | 286 #end if |
| 231 | 287 if (!is.null(levels(msidata\$combined_sample))){ |
| 232 pixeldf = data.frame(table(msidata\$combined_sample)) | 288 pixeldf = data.frame(table(msidata\$combined_sample)) |
| 289 }else{ | |
| 290 pixeldf = data.frame("$filename", ncol(msidata))} | |
| 233 colnames(pixeldf) = c("sample name", "number of pixels") | 291 colnames(pixeldf) = c("sample name", "number of pixels") |
| 234 | 292 |
| 235 #end if | 293 #end if |
| 236 | 294 |
| 295 ### overview table of pixels or samples: | |
| 237 plot(0,type='n',axes=FALSE,ann=FALSE) | 296 plot(0,type='n',axes=FALSE,ann=FALSE) |
| 238 title(main="Overview of chosen pixel:") | 297 title(main="Overview of chosen pixel:") |
| 239 grid.table(pixeldf, rows= NULL) | 298 |
| 299 ### for more than 20 combined samples print only 20 samples per page: | |
| 300 if (is.null(levels(msidata\$combined_sample))){ | |
| 301 grid.table(pixeldf, rows= NULL) | |
| 302 }else if (length(levels(msidata\$combined_sample)) <= 20){ | |
| 303 grid.table(pixeldf, rows= NULL) | |
| 304 }else{ | |
| 305 grid.table(pixeldf[1:20,], rows= NULL) | |
| 306 mincount = 21 | |
| 307 maxcount = 40 | |
| 308 for (count20 in 1:(ceiling(nrow(pixeldf)/20)-1)){ | |
| 309 plot(0,type='n',axes=FALSE,ann=FALSE) | |
| 310 if (maxcount <= nrow(pixeldf)){ | |
| 311 grid.table(pixeldf[mincount:maxcount,], rows= NULL) | |
| 312 mincount = mincount+20 | |
| 313 maxcount = maxcount+20 | |
| 314 }else{### stop last page with last sample otherwise NA in table | |
| 315 grid.table(pixeldf[mincount:nrow(pixeldf),], rows= NULL)} | |
| 316 } | |
| 317 } | |
| 240 | 318 |
| 241 dev.off() | 319 dev.off() |
| 242 | 320 |
| 243 }else{ | 321 }else{ |
| 244 print("Inputfile has no intensities > 0") | 322 print("Inputfile has no intensities > 0") |
| 247 ]]></configfile> | 325 ]]></configfile> |
| 248 </configfiles> | 326 </configfiles> |
| 249 <inputs> | 327 <inputs> |
| 250 <param name="infile" type="data" format="imzml,rdata,analyze75" label="Inputfile as imzML, Analyze7.5 or Cardinal MSImageSet saved as RData" | 328 <param name="infile" type="data" format="imzml,rdata,analyze75" label="Inputfile as imzML, Analyze7.5 or Cardinal MSImageSet saved as RData" |
| 251 help="Upload composite datatype imzml (ibd+imzML) or analyze75 (hdr+img+t2m) or regular upload .RData (Cardinal MSImageSet)"/> | 329 help="Upload composite datatype imzml (ibd+imzML) or analyze75 (hdr+img+t2m) or regular upload .RData (Cardinal MSImageSet)"/> |
| 330 <param name="accuracy" type="float" value="50" label="Only for processed imzML files: enter mass accuracy to which the m/z values will be binned" help="This should be set to the native accuracy of the mass spectrometer, if known"/> | |
| 331 <param name="units" display="radio" type="select" label="Only for processed imzML files: unit of the mass accuracy" help="either m/z or ppm"> | |
| 332 <option value="mz" >mz</option> | |
| 333 <option value="ppm" selected="True" >ppm</option> | |
| 334 </param> | |
| 252 <param name="filename" type="text" value="" label="Title" help="will appear in the pdf output. If nothing given it will take the dataset name"/> | 335 <param name="filename" type="text" value="" label="Title" help="will appear in the pdf output. If nothing given it will take the dataset name"/> |
| 253 <conditional name="pixel_conditional"> | 336 <conditional name="pixel_conditional"> |
| 254 <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"> | 337 <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"> |
| 255 <option value="single_pixel" selected="True">Single pixel</option> | 338 <option value="single_pixel" selected="True">Single pixel</option> |
| 256 <option value="sample_pixel">All pixels of a sample</option> | 339 <option value="sample_pixel">All pixels of a sample</option> |
| 351 <repeat name="repeatpixel"> | 434 <repeat name="repeatpixel"> |
| 352 <param name="plusminusinDalton" value="0.25"/> | 435 <param name="plusminusinDalton" value="0.25"/> |
| 353 <param name="inputx" value="2"/> | 436 <param name="inputx" value="2"/> |
| 354 <param name="inputy" value="2"/> | 437 <param name="inputy" value="2"/> |
| 355 </repeat> | 438 </repeat> |
| 356 </conditional> | 439 </conditional> |
| 357 <output name="plots" file="Plot_analyze75.pdf" compare="sim_size" delta="20000"/> | 440 <output name="plots" file="Plot_analyze75.pdf" compare="sim_size" delta="20000"/> |
| 441 </test> | |
| 442 <test> | |
| 443 <param name="infile" value="" ftype="analyze75"> | |
| 444 <composite_data value="Analyze75.hdr"/> | |
| 445 <composite_data value="Analyze75.img"/> | |
| 446 <composite_data value="Analyze75.t2m"/> | |
| 447 </param> | |
| 448 <conditional name="pixel_conditional"> | |
| 449 <param name="pixel_type" value="sample_pixel"/> | |
| 450 <repeat name="zoomed_sample"> | |
| 451 <param name="xlimmin" value="1250"/> | |
| 452 <param name="xlimmax" value="1270"/> | |
| 453 </repeat> | |
| 454 </conditional> | |
| 455 <output name="plots" file="Plot_analyze75_allpixels.pdf" compare="sim_size" delta="20000"/> | |
| 358 </test> | 456 </test> |
| 359 <test> | 457 <test> |
| 360 <param name="infile" value="123_combined.RData" ftype="rdata"/> | 458 <param name="infile" value="123_combined.RData" ftype="rdata"/> |
| 361 <conditional name="pixel_conditional"> | 459 <conditional name="pixel_conditional"> |
| 362 <param name="pixel_type" value="sample_pixel"/> | 460 <param name="pixel_type" value="sample_pixel"/> |
| 363 <repeat name="zoomed_sample"> | 461 <repeat name="zoomed_sample"> |
| 364 <param name="xlimmin" value="350"/> | 462 <param name="xlimmin" value="350"/> |
| 365 <param name="xlimmax" value="360"/> | 463 <param name="xlimmax" value="360"/> |
| 366 </repeat> | 464 </repeat> |
| 367 </conditional> | 465 </conditional> |
| 368 <output name="plots" file="Plot_rdata.pdf" compare="sim_size" delta="20000"/> | 466 <output name="plots" file="Plot_rdata.pdf" compare="sim_size" delta="20000"/> |
| 369 </test> | 467 </test> |
| 370 <test> | 468 <test> |
| 371 <param name="infile" value="empty_spectra.rdata" ftype="rdata"/> | 469 <param name="infile" value="empty_spectra.rdata" ftype="rdata"/> |
| 372 <param name="plusminusinDalton" value="0.1"/> | 470 <conditional name="pixel_conditional"> |
| 373 <param name="inputx" value="1"/> | 471 <param name="pixel_type" value="single_pixel"/> |
| 374 <param name="inputy" value="1"/> | 472 <repeat name="repeatpixel"> |
| 375 <repeat name="repeatpixel"> | 473 <param name="plusminusinDalton" value="0.1"/> |
| 376 <param name="plusminusinDalton" value="0.25"/> | 474 <param name="inputx" value="1"/> |
| 377 <param name="inputx" value="2"/> | 475 <param name="inputy" value="1"/> |
| 378 <param name="inputy" value="2"/> | 476 </repeat> |
| 379 <repeat name="zoomedplot"> | 477 </conditional> |
| 380 <param name="xlimmin" value="1000"/> | |
| 381 <param name="xlimmax" value="1050"/> | |
| 382 </repeat> | |
| 383 </repeat> | |
| 384 <output name="plots" file="Plot_empty_spectra.pdf" compare="sim_size" delta="20000"/> | 478 <output name="plots" file="Plot_empty_spectra.pdf" compare="sim_size" delta="20000"/> |
| 385 </test> | 479 </test> |
| 386 </tests> | 480 </tests> |
| 387 <help><