comparison quality_report.xml @ 15:23d0394b5908 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit c8d3adac445b4e08e2724e22d7201bfc38bbf40f"
author galaxyp
date Sun, 29 Aug 2021 07:30:21 +0000
parents ecaebe7c7b54
children d426a9107a6c
comparison
equal deleted inserted replaced
14:5a35e3a8d013 15:23d0394b5908
1 <tool id="cardinal_quality_report" name="MSI Qualitycontrol" version="@VERSION@.1"> 1 <tool id="cardinal_quality_report" name="MSI Qualitycontrol" version="@VERSION@.0">
2 <description> 2 <description>
3 mass spectrometry imaging QC 3 mass spectrometry imaging QC
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="2.3">r-gridextra</requirement> 9 <requirement type="package" version="2.3">r-gridextra</requirement>
10 <requirement type="package" version="3.3.2">r-ggplot2</requirement> 10 <requirement type="package" version="3.3.5">r-ggplot2</requirement>
11 <requirement type="package" version="1.1_2">r-rcolorbrewer</requirement> 11 <requirement type="package" version="1.1_2">r-rcolorbrewer</requirement>
12 <requirement type="package" version="2.23_17">r-kernsmooth</requirement> 12 <requirement type="package" version="2.23_20">r-kernsmooth</requirement>
13 <requirement type="package" version="1.1.1">r-scales</requirement> 13 <requirement type="package" version="1.1.1">r-scales</requirement>
14 <requirement type="package" version="1.0.12">r-pheatmap</requirement> 14 <requirement type="package" version="1.0.12">r-pheatmap</requirement>
15 </expand> 15 </expand>
16 <command detect_errors="exit_code"> 16 <command detect_errors="exit_code">
17 <![CDATA[ 17 <![CDATA[
357 357
358 #end for 358 #end for
359 #end if 359 #end if
360 360
361 #################### 4) m/z heatmaps ####################################### 361 #################### 4) m/z heatmaps #######################################
362 par(mfrow=c(1,1), mar=c(5.1, 4.1, 4.1, 2.1), mgp=c(3, 1, 0), las=0) 362
363 if (length(inputcalibrants[,1]) != 0){ 363 #if $report_depth:
364 for (mass in 1:length(inputcalibrants[,1])){ 364
365 par(oma=c(0,0,0,1))## margin for image legend 365 par(mfrow=c(1,1), mar=c(5.1, 4.1, 4.1, 2.1), mgp=c(3, 1, 0), las=0)
366 366 if (length(inputcalibrants[,1]) != 0){
367 tryCatch( 367 for (mass in 1:length(inputcalibrants[,1])){
368 { 368 par(oma=c(0,0,0,1))## margin for image legend
369 print(image(msidata, mz=inputcalibrants[,1][mass], plusminus=plusminusvalues[mass], 369
370 main= paste0(inputcalibrants[,2][mass], ": ", round(inputcalibrants[,1][mass], digits = 2)," (±",$plusminus_ppm, " ppm)"), 370 tryCatch(
371 contrast.enhance = "histogram", strip=FALSE, ylim= c(maximumy,minimumy))) 371 {
372 }, 372 print(image(msidata, mz=inputcalibrants[,1][mass], plusminus=plusminusvalues[mass],
373 error=function(cond) { 373 main= paste0(inputcalibrants[,2][mass], ": ", round(inputcalibrants[,1][mass], digits = 2)," (±",$plusminus_ppm, " ppm)"),
374 ## if there are not enough intensities in the mz range skip creating an image 374 contrast.enhance = "histogram", strip=FALSE, ylim= c(maximumy,minimumy)))
375 print(paste0("Not enough intensities > 0 for m/z ", inputcalibrants[,1][mass])) 375 },
376 } 376 error=function(cond) {
377 ) 377 ## if there are not enough intensities in the mz range skip creating an image
378 } 378 print(paste0("Not enough intensities > 0 for m/z ", inputcalibrants[,1][mass]))
379 } else {print("4) The input peptide and calibrant m/z were not provided or outside the m/z range")} 379 }
380 )
381 }
382 } else {print("4) The input peptide and calibrant m/z were not provided or outside the m/z range")}
383
384 #end if
380 385
381 #################### 5) Number of peaks per pixel - image ################## 386 #################### 5) Number of peaks per pixel - image ##################
382 387
383 ## here every intensity value > 0 counts as peak 388 ## here every intensity value > 0 counts as peak
384 peaksperpixel = colSums(spectra(msidata)> 0, na.rm=TRUE) 389 peaksperpixel = colSums(spectra(msidata)> 0, na.rm=TRUE)
417 rm(TICcoordarray) 422 rm(TICcoordarray)
418 gc() 423 gc()
419 424
420 ############################### 6b) median int image ############################### 425 ############################### 6b) median int image ###############################
421 426
422 median_int = pixelApply(msidata, median, na.rm=TRUE) 427 #if $report_depth:
423 428
424 median_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, median_int) 429 median_int = pixelApply(msidata, median, na.rm=TRUE)
425 colnames(median_coordarray) = c("x", "y", "median_int") 430
426 print(ggplot(median_coordarray, aes(x=x, y=y, fill=median_int))+ 431 median_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, median_int)
427 geom_tile() + coord_fixed() + 432 colnames(median_coordarray) = c("x", "y", "median_int")
428 ggtitle("Median intensity per spectrum")+ 433 print(ggplot(median_coordarray, aes(x=x, y=y, fill=median_int))+
429 theme_bw() + 434 geom_tile() + coord_fixed() +
430 theme(plot.title = element_text(hjust = 0.5))+ 435 ggtitle("Median intensity per spectrum")+
431 theme(text=element_text(family="ArialMT", face="bold", size=12))+ 436 theme_bw() +
432 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange") 437 theme(plot.title = element_text(hjust = 0.5))+
433 ,space = "Lab", na.value = "black", name = "median\nintensity")) 438 theme(text=element_text(family="ArialMT", face="bold", size=12))+
434 439 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange")
435 ## remove median_coordarray to clean up RAM space 440 ,space = "Lab", na.value = "black", name = "median\nintensity"))
436 rm(median_coordarray) 441
437 gc() 442 ## remove median_coordarray to clean up RAM space
438 443 rm(median_coordarray)
439 ############################### 6c) max int image ############################### 444 gc()
440 445
441 max_int = pixelApply(msidata, max, na.rm=TRUE) 446 ############################### 6c) max int image ###############################
442 447
443 max_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, max_int) 448 max_int = pixelApply(msidata, max, na.rm=TRUE)
444 colnames(max_coordarray) = c("x", "y", "max_int") 449
445 print(ggplot(max_coordarray, aes(x=x, y=y, fill=max_int))+ 450 max_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, max_int)
446 geom_tile() + coord_fixed() + 451 colnames(max_coordarray) = c("x", "y", "max_int")
447 ggtitle("Maximum intensity per spectrum")+ 452 print(ggplot(max_coordarray, aes(x=x, y=y, fill=max_int))+
448 theme_bw() + 453 geom_tile() + coord_fixed() +
449 theme(plot.title = element_text(hjust = 0.5))+ 454 ggtitle("Maximum intensity per spectrum")+
450 theme(text=element_text(family="ArialMT", face="bold", size=12))+ 455 theme_bw() +
451 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange") 456 theme(plot.title = element_text(hjust = 0.5))+
452 ,space = "Lab", na.value = "black", name = "max\nintensity")) 457 theme(text=element_text(family="ArialMT", face="bold", size=12))+
453 458 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange")
454 ## remove median_coordarray to clean up RAM space 459 ,space = "Lab", na.value = "black", name = "max\nintensity"))
455 rm(max_coordarray) 460
456 gc() 461 ## remove median_coordarray to clean up RAM space
457 462 rm(max_coordarray)
458 ############################### 7) Most abundant m/z image ################# 463 gc()
459 464
460 ## for each spectrum find the row (m/z) with the highest intensity 465 ############################### 7) Most abundant m/z image #################
461 highestmz = pixelApply(msidata, which.max) 466
462 467 ## for each spectrum find the row (m/z) with the highest intensity
463 ## in case for some spectra max returns integer(0), highestmz is a list and integer(0) have to be replaced with NA and unlisted 468 highestmz = pixelApply(msidata, which.max)
464 if (class(highestmz) == "list"){ 469
465 ##find zero-length values 470 ## in case for some spectra max returns integer(0), highestmz is a list and integer(0) have to be replaced with NA and unlisted
466 zero_entry <- !(sapply(highestmz, length)) 471 if (class(highestmz) == "list"){
467 ### replace these values with NA 472 ##find zero-length values
468 highestmz[zero_entry] <- NA 473 zero_entry <- !(sapply(highestmz, length))
469 ### unlist list to get a vector 474 ### replace these values with NA
470 highestmz = unlist(highestmz)} 475 highestmz[zero_entry] <- NA
471 476 ### unlist list to get a vector
472 highestmz_matrix = data.frame(coord(msidata)\$x, coord(msidata)\$y,mz(msidata)[highestmz]) 477 highestmz = unlist(highestmz)}
473 colnames(highestmz_matrix) = c("x", "y", "highestmzinDa") 478
474 479 highestmz_matrix = data.frame(coord(msidata)\$x, coord(msidata)\$y,mz(msidata)[highestmz])
475 print(ggplot(highestmz_matrix, aes(x=x, y=y, fill=highestmzinDa))+ 480 colnames(highestmz_matrix) = c("x", "y", "highestmzinDa")
476 geom_tile() + coord_fixed() + 481
477 ggtitle("Most abundant m/z in each spectrum")+ 482 print(ggplot(highestmz_matrix, aes(x=x, y=y, fill=highestmzinDa))+
478 theme_bw() + 483 geom_tile() + coord_fixed() +
479 theme(plot.title = element_text(hjust = 0.5))+ 484 ggtitle("Most abundant m/z in each spectrum")+
480 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), space = "Lab", na.value = "black", name = "m/z", 485 theme_bw() +
481 limits=c(min(highestmz_matrix\$highestmzinDa), max(highestmz_matrix\$highestmzinDa)))+ 486 theme(plot.title = element_text(hjust = 0.5))+
482 theme(text=element_text(family="ArialMT", face="bold", size=12))) 487 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), space = "Lab", na.value = "black", name = "m/z",
483 488 limits=c(min(highestmz_matrix\$highestmzinDa), max(highestmz_matrix\$highestmzinDa)))+
484 ## remove highestmz_matrix to clean up RAM space 489 theme(text=element_text(family="ArialMT", face="bold", size=12)))
485 rm(highestmz_matrix) 490
486 gc() 491 ## remove highestmz_matrix to clean up RAM space
487 492 rm(highestmz_matrix)
493 gc()
494
495 #end if
488 496
489 ########################## 8) optional pca image for two components ################# 497 ########################## 8) optional pca image for two components #################
490 498
491 #if $do_pca: 499 #if $do_pca:
492 500
511 print("properties over pixels") 519 print("properties over pixels")
512 par(mfrow = c(2,1), mar=c(5,6,4,2)) 520 par(mfrow = c(2,1), mar=c(5,6,4,2))
513 521
514 ########################## 9) number of peaks per spectrum ################# 522 ########################## 9) number of peaks per spectrum #################
515 ## 9a) scatterplot 523 ## 9a) scatterplot
516 524
517 plot_colorByDensity(pixels(msidata), peaksperpixel, ylab = "", xlab = "", main="Number of peaks per spectrum") 525 #if $report_depth:
518 title(xlab="Spectra index", line=3) 526
519 title(ylab="Number of peaks", line=4) 527 plot_colorByDensity(pixels(msidata), peaksperpixel, ylab = "", xlab = "", main="Number of peaks per spectrum")
520 528 title(xlab="Spectra index", line=3)
521 if (!is.null(unique(msidata\$annotation))){ 529 title(ylab="Number of peaks", line=4)
522 abline(v=abline_vector, lty = 3)} 530
523 531 if (!is.null(unique(msidata\$annotation))){
524 ## 9b) histogram 532 abline(v=abline_vector, lty = 3)}
525 533
526 hist(peaksperpixel, main="", las=1, xlab = "Number of peaks per spectrum", ylab="") 534 ## 9b) histogram
527 title(main="Number of peaks per spectrum", line=2) 535
528 title(ylab="Frequency = # spectra", line=4) 536
529 abline(v=median(peaksperpixel), col="blue") 537
530 538 hist(peaksperpixel, main="", las=1, xlab = "Number of peaks per spectrum", ylab="")
531 ## 9c) additional histogram to show contribution of annotation groups 539 title(main="Number of peaks per spectrum", line=2)
532 540 title(ylab="Frequency = # spectra", line=4)
533 if (!is.null(unique(msidata\$annotation))){ 541 abline(v=median(peaksperpixel), col="blue")
534 542
535 df_9 = data.frame(peaksperpixel, msidata\$annotation) 543 ## 9c) additional histogram to show contribution of annotation groups
536 colnames(df_9) = c("Npeaks", "annotation") 544
537 545 if (!is.null(unique(msidata\$annotation))){
538 hist_9 = ggplot(df_9, aes(x=Npeaks, fill=annotation)) + 546
539 geom_histogram()+ theme_bw()+ 547 df_9 = data.frame(peaksperpixel, msidata\$annotation)
540 theme(text=element_text(family="ArialMT", face="bold", size=12))+ 548 colnames(df_9) = c("Npeaks", "annotation")
541 theme(plot.title = element_text(hjust = 0.5))+ 549
542 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 8))+ 550 hist_9 = ggplot(df_9, aes(x=Npeaks, fill=annotation)) +
543 theme(legend.position="bottom",legend.direction="vertical")+ 551 geom_histogram()+ theme_bw()+
544 labs(title="Number of peaks per spectrum and annotation group", x="Number of peaks per spectrum", y = "Frequency = # spectra") + 552 theme(text=element_text(family="ArialMT", face="bold", size=12))+
545 guides(fill=guide_legend(ncol=5,byrow=TRUE))+ 553 theme(plot.title = element_text(hjust = 0.5))+
546 geom_vline(xintercept = median(peaksperpixel), size = 1, colour = "black",linetype = "dashed") 554 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 8))+
547 print(hist_9)} 555 theme(legend.position="bottom",legend.direction="vertical")+
556 labs(title="Number of peaks per spectrum and annotation group", x="Number of peaks per spectrum", y = "Frequency = # spectra") +
557 guides(fill=guide_legend(ncol=5,byrow=TRUE))+
558 geom_vline(xintercept = median(peaksperpixel), size = 1, colour = "black",linetype = "dashed")
559 print(hist_9)}
560
561 #end if
548 562
549 ########################## 10) TIC per spectrum ########################### 563 ########################## 10) TIC per spectrum ###########################
550 564
551 ## 10a)density scatterplot 565 ## 10a)density scatterplot
552 par(mfrow = c(2,1), mar=c(5,6,4,2)) 566 par(mfrow = c(2,1), mar=c(5,6,4,2))
594 par(mfrow = c(1, 1), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) 608 par(mfrow = c(1, 1), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1))
595 hist(mz(msidata), xlab = "m/z", main="Histogram of m/z values") 609 hist(mz(msidata), xlab = "m/z", main="Histogram of m/z values")
596 610
597 ########################## 12) Number of peaks per m/z ##################### 611 ########################## 12) Number of peaks per m/z #####################
598 612
599 peakspermz = rowSums(spectra(msidata) > 0, na.rm=TRUE) 613 #if $report_depth:
600 614
601 par(mfrow = c(2,1), mar=c(5,6,4,4.5)) 615 peakspermz = rowSums(spectra(msidata) > 0, na.rm=TRUE)
602 ## 12a) scatterplot 616
603 plot_colorByDensity(mz(msidata),peakspermz, main= "Number of peaks per m/z", ylab ="") 617 par(mfrow = c(2,1), mar=c(5,6,4,4.5))
604 title(xlab="m/z", line=2.5) 618 ## 12a) scatterplot
605 title(ylab = "Number of peaks", line=4) 619 plot_colorByDensity(mz(msidata),peakspermz, main= "Number of peaks per m/z", ylab ="")
606 axis(4, at=pretty(peakspermz),labels=as.character(round((pretty(peakspermz)/pixelcount*100), digits=1)), las=1) 620 title(xlab="m/z", line=2.5)
607 mtext("Coverage of spectra [%]", 4, line=3, adj=1) 621 title(ylab = "Number of peaks", line=4)
608 622 axis(4, at=pretty(peakspermz),labels=as.character(round((pretty(peakspermz)/pixelcount*100), digits=1)), las=1)
609 ## 12b) histogram 623 mtext("Coverage of spectra [%]", 4, line=3, adj=1)
610 hist(peakspermz, main="", las=1, ylab="", xlab="") 624
611 title(ylab = "Frequency", line=4) 625 ## 12b) histogram
612 title(main="Number of peaks per m/z", xlab = "Number of peaks per m/z", line=2) 626 hist(peakspermz, main="", las=1, ylab="", xlab="")
613 abline(v=median(peakspermz), col="blue") 627 title(ylab = "Frequency", line=4)
614 628 title(main="Number of peaks per m/z", xlab = "Number of peaks per m/z", line=2)
615 ########################## 13) Sum of intensities per m/z ################## 629 abline(v=median(peakspermz), col="blue")
616 630
617 ## Sum of all intensities for each m/z (like TIC, but for m/z instead of pixel) 631 ########################## 13) Sum of intensities per m/z ##################
618 mzTIC = featureApply(msidata, sum, na.rm=TRUE) ## calculate intensity sum for each m/z 632
619 633 ## Sum of all intensities for each m/z (like TIC, but for m/z instead of pixel)
620 par(mfrow = c(2,1), mar=c(5,6,4,2)) 634 mzTIC = featureApply(msidata, sum, na.rm=TRUE) ## calculate intensity sum for each m/z
621 ## 13a) scatterplot 635
622 plot_colorByDensity(mz(msidata),mzTIC, main= "Sum of intensities per m/z", ylab ="") 636 par(mfrow = c(2,1), mar=c(5,6,4,2))
623 title(xlab="m/z", line=2.5) 637 ## 13a) scatterplot
624 title(ylab="Intensity sum", line=4) 638 plot_colorByDensity(mz(msidata),mzTIC, main= "Sum of intensities per m/z", ylab ="")
625 639 title(xlab="m/z", line=2.5)
626 ## 13b) histogram 640 title(ylab="Intensity sum", line=4)
627 hist(mzTIC, main="", xlab = "", las=1, ylab="") 641
628 title(main="Sum of intensities per m/z", line=2, ylab="") 642 ## 13b) histogram
629 title(xlab = "sum of intensities per m/z") 643 hist(mzTIC, main="", xlab = "", las=1, ylab="")
630 title(ylab = "Frequency", line=4) 644 title(main="Sum of intensities per m/z", line=2, ylab="")
631 abline(v=median(mzTIC[mzTIC>0]), col="blue") 645 title(xlab = "sum of intensities per m/z")
632 646 title(ylab = "Frequency", line=4)
633 ################################## V) intensity plots ######################## 647 abline(v=median(mzTIC[mzTIC>0]), col="blue")
634 ############################################################################ 648
635 print("intensity plots") 649 ################################## V) intensity plots ########################
636 ########################## 14) Intensity distribution ###################### 650 ############################################################################
637 651 print("intensity plots")
638 par(mfrow = c(2,1), mar=c(5,6,4,2)) 652 ########################## 14) Intensity distribution ######################
639 653
640 ## 14a) Median intensity over spectra 654 par(mfrow = c(2,1), mar=c(5,6,4,2))
641 medianint_spectra = pixelApply(msidata, median, na.rm=TRUE) 655
642 plot(medianint_spectra, main="Median intensity per spectrum",las=1, xlab="Spectra index", ylab="") 656 ## 14a) Median intensity over spectra
643 title(ylab="Median spectrum intensity", line=4) 657 medianint_spectra = pixelApply(msidata, median, na.rm=TRUE)
644 if (!is.null(unique(msidata\$annotation))){ 658 plot(medianint_spectra, main="Median intensity per spectrum",las=1, xlab="Spectra index", ylab="")
645 abline(v=abline_vector, lty = 3)} 659 title(ylab="Median spectrum intensity", line=4)
646 660 if (!is.null(unique(msidata\$annotation))){
647 ## 14b) histogram: 661 abline(v=abline_vector, lty = 3)}
648 hist(int_matrix, main="", xlab = "", ylab="", las=1) 662
649 title(main="Intensity histogram", line=2) 663 ## 14b) histogram:
650 title(xlab="intensities") 664 hist(int_matrix, main="", xlab = "", ylab="", las=1)
651 title(ylab="Frequency", line=4) 665 title(main="Intensity histogram", line=2)
652 abline(v=median(int_matrix)[(as.matrix(spectra(msidata))>0)], col="blue") 666 title(xlab="intensities")
653 667 title(ylab="Frequency", line=4)
668 abline(v=median(int_matrix)[(as.matrix(spectra(msidata))>0)], col="blue")
669
670 #end if
654 671
655 ## 14c) histogram to show contribution of annotation groups 672 ## 14c) histogram to show contribution of annotation groups
656 673
657 if (!is.null(unique(msidata\$annotation))){ 674 if (!is.null(unique(msidata\$annotation))){
658 675
717 ############################################################################ 734 ############################################################################
718 print("Mass spectra and m/z accuracy") 735 print("Mass spectra and m/z accuracy")
719 736
720 ############################ 15) Mass spectra ############################## 737 ############################ 15) Mass spectra ##############################
721 738
739
722 ## replace any NA with 0, otherwise plot function will not work at all 740 ## replace any NA with 0, otherwise plot function will not work at all
723 msidata_no_NA = msidata 741 msidata_no_NA = msidata
724 742
725 ## find three equal m/z ranges for the average mass spectra plots: 743 #if $report_depth:
726 third_mz_range = round(nrow(msidata_no_NA)/3,0) 744
727 745 ## find three equal m/z ranges for the average mass spectra plots:
728 par(cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) 746 third_mz_range = round(nrow(msidata_no_NA)/3,0)
729 print(plot(msidata_no_NA, run="infile", layout=c(2,2), strip=FALSE, main= "Average spectrum", col="black")) 747
730 print(plot(msidata_no_NA[1:third_mz_range,], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black")) 748 par(cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1))
731 print(plot(msidata_no_NA[third_mz_range:(2*third_mz_range),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black")) 749 print(plot(msidata_no_NA, run="infile", layout=c(2,2), strip=FALSE, main= "Average spectrum", col="black"))
732 print(plot(msidata_no_NA[(2*third_mz_range):nrow(msidata_no_NA),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black")) 750 print(plot(msidata_no_NA[1:third_mz_range,], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black"))
733 751 print(plot(msidata_no_NA[third_mz_range:(2*third_mz_range),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black"))
734 ## plot one average mass spectrum for each pixel annotation group 752 print(plot(msidata_no_NA[(2*third_mz_range):nrow(msidata_no_NA),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black"))
735 753
736 if (!is.null(unique(msidata\$annotation))){ 754 ## plot one average mass spectrum for each pixel annotation group
737 ## print legend only for less than 10 samples 755
738 if (length(unique(msidata\$annotation)) < 10){ 756 if (!is.null(unique(msidata\$annotation))){
739 key_legend = TRUE 757 ## print legend only for less than 10 samples
740 }else{key_legend = FALSE} 758 if (length(unique(msidata\$annotation)) < 10){
741 par(mfrow = c(1,1), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) 759 key_legend = TRUE
742 print(plot(msidata, run="infile", pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(unique(msidata\$annotation))),superpose=TRUE, main="Average mass spectra for annotation groups")) 760 }else{key_legend = FALSE}
743 } 761 par(mfrow = c(1,1), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1))
744 762 print(plot(msidata, run="infile", pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(unique(msidata\$annotation))),superpose=TRUE, main="Average mass spectra for annotation groups"))
745 ## plot 4 random mass spectra 763 }
746 ## find four random, not empty pixel to plot their spectra in the following plots: 764
747 pixel_vector = sample(which(TICs != 0),4) 765 ## plot 4 random mass spectra
748 766 ## find four random, not empty pixel to plot their spectra in the following plots:
749 par(mfrow = c(2, 2), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) 767 pixel_vector = sample(which(TICs != 0),4)
750 print(plot(msidata_no_NA, pixel = pixel_vector, col="black")) 768
751 769 par(mfrow = c(2, 2), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1))
770 print(plot(msidata_no_NA, pixel = pixel_vector, col="black"))
771
772 #end if
752 773
753 ################### 16) Zoomed in mass spectra for calibrants ############## 774 ################### 16) Zoomed in mass spectra for calibrants ##############
754 775
755 count = 1 776 count = 1
756 differencevector = numeric() 777 differencevector = numeric()
846 rm(msidata_no_NA) 867 rm(msidata_no_NA)
847 gc() 868 gc()
848 869
849 ######### 17) ppm difference input calibrant m/z and m/z with max intensity in given m/z range######### 870 ######### 17) ppm difference input calibrant m/z and m/z with max intensity in given m/z range#########
850 871
872 #if $report_depth:
873
851 par(mfrow = c(1,1)) 874 par(mfrow = c(1,1))
852 ### plot the ppm difference calculated above: theor. m/z value to highest m/z value: 875 ### plot the ppm difference calculated above: theor. m/z value to highest m/z value:
853 876
854 calibrant_names = as.character(inputcalibrants[,2]) 877 calibrant_names = as.character(inputcalibrants[,2])
855 878
883 theme(plot.title = element_text(hjust = 0.5, size=14))+theme(text=element_text(family="ArialMT", face="bold", size=14))+ 906 theme(plot.title = element_text(hjust = 0.5, size=14))+theme(text=element_text(family="ArialMT", face="bold", size=14))+
884 geom_text(aes(label=differencevector2), vjust=-0.3, size=5.5, col="blue")+ 907 geom_text(aes(label=differencevector2), vjust=-0.3, size=5.5, col="blue")+
885 theme(axis.text.x = element_text(angle = 90, hjust = 1, size=14)) 908 theme(axis.text.x = element_text(angle = 90, hjust = 1, size=14))
886 909
887 print(diff_plot2) 910 print(diff_plot2)
911
912 #end if
888 913
889 #################### 19) ppm difference over pixels ##################### 914 #################### 19) ppm difference over pixels #####################
890 915
891 par(mfrow = c(1,1)) 916 par(mfrow = c(1,1))
892 count = 1 917 count = 1
932 if (!is.null(unique(msidata\$annotation))){ 957 if (!is.null(unique(msidata\$annotation))){
933 abline(v=abline_vector, lty = 3)}} 958 abline(v=abline_vector, lty = 3)}}
934 959
935 ### make x-y-images for mz accuracy 960 ### make x-y-images for mz accuracy
936 961
962 #if $report_depth:
937 ppm_dataframe = data.frame(coord(msidata)\$x, coord(msidata)\$y, ppm_df) 963 ppm_dataframe = data.frame(coord(msidata)\$x, coord(msidata)\$y, ppm_df)
938 colnames(ppm_dataframe) = c("x", "y", "ppm_df") 964 colnames(ppm_dataframe) = c("x", "y", "ppm_df")
939 965
940 for (each_cal in 1:ncol(ppm_df)){ 966 for (each_cal in 1:ncol(ppm_df)){
941 tmp_ppm = ppm_dataframe[,c(1,2,each_cal+2)] 967 tmp_ppm = ppm_dataframe[,c(1,2,each_cal+2)]
948 theme_bw() + 974 theme_bw() +
949 theme(plot.title = element_text(hjust = 0.5))+ 975 theme(plot.title = element_text(hjust = 0.5))+
950 theme(text=element_text(family="ArialMT", face="bold", size=12))+ 976 theme(text=element_text(family="ArialMT", face="bold", size=12))+
951 scale_fill_gradient2(low = "navy", mid = "grey", high = "red", midpoint = 0 ,space = "Lab", na.value = "black", name = "ppm\nerror"))} 977 scale_fill_gradient2(low = "navy", mid = "grey", high = "red", midpoint = 0 ,space = "Lab", na.value = "black", name = "ppm\nerror"))}
952 978
979 #end if
953 980
954 }else{print("plot 16+17+18+19) The inputcalibrant m/z were not provided or outside the m/z range")} 981 }else{print("plot 16+17+18+19) The inputcalibrant m/z were not provided or outside the m/z range")}
955 }else{ 982 }else{
956 print("inputfile has no intensities > 0") 983 print("inputfile has no intensities > 0")
957 } 984 }
974 </conditional> 1001 </conditional>
975 <expand macro="pdf_filename"/> 1002 <expand macro="pdf_filename"/>
976 <expand macro="reading_2_column_mz_tabular" optional="true"/> 1003 <expand macro="reading_2_column_mz_tabular" optional="true"/>
977 <param name="plusminus_ppm" value="200" type="float" label="ppm range" help="Will be added in both directions to input calibrant m/z"/> 1004 <param name="plusminus_ppm" value="200" type="float" label="ppm range" help="Will be added in both directions to input calibrant m/z"/>
978 <param name="do_pca" type="boolean" label="PCA with 2 components"/> 1005 <param name="do_pca" type="boolean" label="PCA with 2 components"/>
1006 <param name="report_depth" type="boolean" label="Generate full QC report" truevalue="TRUE" falsevalue="FALSE" checked="True" help="No: does not generate all plots but only the most informatives"/>
979 <repeat name="calibrantratio" title="Plot fold change of two m/z" min="0" max="10"> 1007 <repeat name="calibrantratio" title="Plot fold change of two m/z" min="0" max="10">
980 <param name="mass1" value="1111" type="float" label="M/z 1" help="First m/z"/> 1008 <param name="mass1" value="1111" type="float" label="M/z 1" help="First m/z"/>
981 <param name="mass2" value="2222" type="float" label="M/z 2" help="Second m/z"/> 1009 <param name="mass2" value="2222" type="float" label="M/z 2" help="Second m/z"/>
982 <param name="distance" value="200" type="float" label="ppm range" help="Will be added in both directions to input calibrant m/z and intensities will be averaged in this range."/> 1010 <param name="distance" value="200" type="float" label="ppm range" help="Will be added in both directions to input calibrant m/z and intensities will be averaged in this range."/>
983 <param name="filenameratioplot" type="text" optional="true" label="Title" help="Optional title for fold change plot."> 1011 <param name="filenameratioplot" type="text" optional="true" label="Title" help="Optional title for fold change plot.">
1019 <param name="distance" value="500"/> 1047 <param name="distance" value="500"/>
1020 <param name="filenameratioplot" value = "Ratio of mz 328.9 and mz 398.8"/> 1048 <param name="filenameratioplot" value = "Ratio of mz 328.9 and mz 398.8"/>
1021 </repeat> 1049 </repeat>
1022 <output name="QC_report" file="QC_imzml.pdf" compare="sim_size"/> 1050 <output name="QC_report" file="QC_imzml.pdf" compare="sim_size"/>
1023 </test> 1051 </test>
1024
1025 <test> 1052 <test>
1026 <expand macro="infile_analyze75"/> 1053 <expand macro="infile_analyze75"/>
1027 <conditional name="tabular_annotation"> 1054 <conditional name="tabular_annotation">
1028 <param name="load_annotation" value="no_annotation"/> 1055 <param name="load_annotation" value="no_annotation"/>
1029 </conditional> 1056 </conditional>
1030 <param name="filename" value="Testfile_analyze75"/> 1057 <param name="filename" value="Testfile_analyze75"/>
1031 <param name="do_pca" value="True"/> 1058 <param name="do_pca" value="True"/>
1032 <output name="QC_report" file="QC_analyze75.pdf" compare="sim_size"/> 1059 <output name="QC_report" file="QC_analyze75.pdf" compare="sim_size"/>
1033 </test> 1060 </test>
1034
1035 <test> 1061 <test>
1036 <param name="infile" value="3_files_combined.RData" ftype="rdata"/> 1062 <param name="infile" value="3_files_combined.RData" ftype="rdata"/>
1037 <conditional name="tabular_annotation"> 1063 <conditional name="tabular_annotation">
1038 <param name="load_annotation" value="yes_annotation"/> 1064 <param name="load_annotation" value="yes_annotation"/>
1039 <param name="annotation_file" value="annotations_rdata.tabular"/> 1065 <param name="annotation_file" value="annotations_rdata.tabular"/>
1060 <param name="name_column" value="2"/> 1086 <param name="name_column" value="2"/>
1061 <param name="filename" value="Testfile_rdata"/> 1087 <param name="filename" value="Testfile_rdata"/>
1062 <param name="do_pca" value="False"/> 1088 <param name="do_pca" value="False"/>
1063 <output name="QC_report" file="QC_empty_spectra.pdf" compare="sim_size"/> 1089 <output name="QC_report" file="QC_empty_spectra.pdf" compare="sim_size"/>
1064 </test> 1090 </test>
1091 <test>
1092 <param name="infile" value="" ftype="imzml">
1093 <composite_data value="Example_Processed.imzML"/>
1094 <composite_data value="Example_Processed.ibd"/>
1095 </param>
1096 <conditional name="processed_cond">
1097 <param name="processed_file" value="processed"/>
1098 <param name="accuracy" value="200"/>
1099 <param name="units" value="ppm"/>
1100 </conditional>
1101 <conditional name="tabular_annotation">
1102 <param name="load_annotation" value="no_annotation"/>
1103 </conditional>
1104 <param name="calibrant_file" value="inputcalibrantfile1.tabular" ftype="tabular"/>
1105 <param name="mz_column" value="1"/>
1106 <param name="name_column" value="1"/>
1107 <param name="report_depth" value="False"/>
1108 <output name="QC_report" file="QC_imzml_shortreport.pdf" compare="sim_size"/>
1109 </test>
1065 </tests> 1110 </tests>
1066 <help> 1111 <help>
1067 <![CDATA[ 1112 <![CDATA[
1068 @CARDINAL_DESCRIPTION@ 1113 @CARDINAL_DESCRIPTION@
1069 1114