Mercurial > repos > galaxyp > cardinal_quality_report
comparison quality_report.xml @ 11:f396c176f366 draft
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit ca89f8e007c6b17f7c30066729e05b8686ab975a"
author | galaxyp |
---|---|
date | Sun, 27 Sep 2020 11:11:53 +0000 |
parents | f365bad862c9 |
children | ecaebe7c7b54 |
comparison
equal
deleted
inserted
replaced
10:f365bad862c9 | 11:f396c176f366 |
---|---|
58 msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y, c(1:ncol(msidata))) | 58 msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y, c(1:ncol(msidata))) |
59 colnames(msidata_coordinates) = c("x", "y", "pixel_index") | 59 colnames(msidata_coordinates) = c("x", "y", "pixel_index") |
60 merged_annotation = merge(msidata_coordinates, annotation_input, by=c("x", "y"), all.x=TRUE) | 60 merged_annotation = merge(msidata_coordinates, annotation_input, by=c("x", "y"), all.x=TRUE) |
61 merged_annotation[is.na(merged_annotation)] = "NA" | 61 merged_annotation[is.na(merged_annotation)] = "NA" |
62 merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),] | 62 merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),] |
63 msidata\$annotation = as.factor(merged_annotation[,4]) | 63 msidata\$annotation = as.character(merged_annotation[,4]) |
64 | 64 |
65 #end if | 65 #end if |
66 | 66 |
67 ###################### calculation of data properties ################################ | 67 ###################### calculation of data properties ################################ |
68 @DATA_PROPERTIES_INRAM@ | 68 @DATA_PROPERTIES_INRAM@ |
69 | 69 |
70 | |
70 ## Median intensities | 71 ## Median intensities |
71 medint = round(median(spectra(msidata), na.rm=TRUE), digits=2) | 72 medint = round(median(int_matrix), digits=2) |
72 ## Spectra multiplied with m/z (potential number of peaks) | 73 ## Spectra multiplied with m/z (potential number of peaks) |
73 numpeaks = ncol(msidata)*nrow(msidata) | 74 numpeaks = as.numeric(ncol(msidata)*nrow(msidata)) |
74 ## Percentage of intensities > 0 | 75 ## Percentage of intensities > 0 |
75 percpeaks = round(npeaks/numpeaks*100, digits=2) | 76 percpeaks = round(npeaks/numpeaks*100, digits=2) |
76 ## Number of empty TICs | 77 ## Number of empty TICs |
77 TICs = pixelApply(msidata, sum) | 78 TICs = pixelApply(msidata, sum, na.rm=TRUE) |
78 NumemptyTIC = sum(TICs == 0) | 79 NumemptyTIC = sum(TICs == 0) |
79 ## Median und sd TIC | 80 ## Median und sd TIC |
80 medTIC = round(median(TICs), digits=1) | 81 medTIC = round(median(TICs), digits=1) |
81 sdTIC = round(sd(TICs), digits=0) | 82 sdTIC = round(sd(TICs), digits=0) |
82 ## Median and sd # peaks per spectrum | 83 ## Median and sd # peaks per spectrum |
181 | 182 |
182 ################### 0) overview for combined data ########################### | 183 ################### 0) overview for combined data ########################### |
183 | 184 |
184 ### only for previously combined data, same plot as in combine QC pdf | 185 ### only for previously combined data, same plot as in combine QC pdf |
185 | 186 |
186 if (!is.null(levels(msidata\$annotation))){ | 187 if (!is.null(unique(msidata\$annotation))){ |
187 | 188 |
188 number_combined = length(levels(msidata\$annotation)) | 189 number_combined = length(unique(msidata\$annotation)) |
189 | 190 |
190 position_df = data.frame(coord(msidata)\$x, coord(msidata)\$y, msidata\$annotation) | 191 position_df = data.frame(coord(msidata)\$x, coord(msidata)\$y, msidata\$annotation) |
191 colnames(position_df) = c("x", "y","annotation") | 192 colnames(position_df) = c("x", "y","annotation") |
193 print(position_df) | |
192 | 194 |
193 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=annotation))+ | 195 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=annotation))+ |
194 geom_tile() + | 196 geom_tile() + |
195 coord_fixed()+ | 197 coord_fixed()+ |
196 ggtitle("Spatial orientation of pixel annotations")+ | 198 ggtitle("Spatial orientation of pixel annotations")+ |
412 rm(TICcoordarray) | 414 rm(TICcoordarray) |
413 gc() | 415 gc() |
414 | 416 |
415 ############################### 6b) median int image ############################### | 417 ############################### 6b) median int image ############################### |
416 | 418 |
417 median_int = pixelApply(msidata, median) | 419 median_int = pixelApply(msidata, median, na.rm=TRUE) |
418 | 420 |
419 median_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, median_int) | 421 median_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, median_int) |
420 colnames(median_coordarray) = c("x", "y", "median_int") | 422 colnames(median_coordarray) = c("x", "y", "median_int") |
421 print(ggplot(median_coordarray, aes(x=x, y=y, fill=median_int))+ | 423 print(ggplot(median_coordarray, aes(x=x, y=y, fill=median_int))+ |
422 geom_tile() + coord_fixed() + | 424 geom_tile() + coord_fixed() + |
431 rm(median_coordarray) | 433 rm(median_coordarray) |
432 gc() | 434 gc() |
433 | 435 |
434 ############################### 6c) max int image ############################### | 436 ############################### 6c) max int image ############################### |
435 | 437 |
436 max_int = pixelApply(msidata, max) | 438 max_int = pixelApply(msidata, max, na.rm=TRUE) |
437 | 439 |
438 max_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, max_int) | 440 max_coordarray=data.frame(coord(msidata)\$x, coord(msidata)\$y, max_int) |
439 colnames(max_coordarray) = c("x", "y", "max_int") | 441 colnames(max_coordarray) = c("x", "y", "max_int") |
440 print(ggplot(max_coordarray, aes(x=x, y=y, fill=max_int))+ | 442 print(ggplot(max_coordarray, aes(x=x, y=y, fill=max_int))+ |
441 geom_tile() + coord_fixed() + | 443 geom_tile() + coord_fixed() + |
493 print(image(pca, run="infile", col=c("black", "white"), strip=FALSE, ylim= c(maximumy+0.2*maximumy,minimumy-1), layout=FALSE)) | 495 print(image(pca, run="infile", col=c("black", "white"), strip=FALSE, ylim= c(maximumy+0.2*maximumy,minimumy-1), layout=FALSE)) |
494 | 496 |
495 par(oma=c(0,0,0,1))## margin for image legend | 497 par(oma=c(0,0,0,1))## margin for image legend |
496 print(image(pca, column = "PC1" , strip=FALSE, superpose = FALSE, main="PC1", col.regions = risk.colors(100), layout=c(2,1), ylim= c(maximumy+0.2*maximumy,minimumy-1))) | 498 print(image(pca, column = "PC1" , strip=FALSE, superpose = FALSE, main="PC1", col.regions = risk.colors(100), layout=c(2,1), ylim= c(maximumy+0.2*maximumy,minimumy-1))) |
497 print(image(pca, column = "PC2" , strip=FALSE, superpose = FALSE, main="PC2", col.regions = risk.colors(100), layout=FALSE, ylim= c(maximumy+0.2*maximumy,minimumy-1))) | 499 print(image(pca, column = "PC2" , strip=FALSE, superpose = FALSE, main="PC2", col.regions = risk.colors(100), layout=FALSE, ylim= c(maximumy+0.2*maximumy,minimumy-1))) |
498 ## remove pca to clean up RAM space | 500 ## remove pca to clean up space |
499 rm(pca) | 501 rm(pca) |
500 gc() | 502 gc() |
501 | 503 |
502 #end if | 504 #end if |
503 | 505 |
511 | 513 |
512 plot_colorByDensity(pixels(msidata), peaksperpixel, ylab = "", xlab = "", main="Number of peaks per spectrum") | 514 plot_colorByDensity(pixels(msidata), peaksperpixel, ylab = "", xlab = "", main="Number of peaks per spectrum") |
513 title(xlab="Spectra index", line=3) | 515 title(xlab="Spectra index", line=3) |
514 title(ylab="Number of peaks", line=4) | 516 title(ylab="Number of peaks", line=4) |
515 | 517 |
516 if (!is.null(levels(msidata\$annotation))){ | 518 if (!is.null(unique(msidata\$annotation))){ |
517 abline(v=abline_vector, lty = 3)} | 519 abline(v=abline_vector, lty = 3)} |
518 | 520 |
519 ## 9b) histogram | 521 ## 9b) histogram |
520 | 522 |
521 hist(peaksperpixel, main="", las=1, xlab = "Number of peaks per spectrum", ylab="") | 523 hist(peaksperpixel, main="", las=1, xlab = "Number of peaks per spectrum", ylab="") |
523 title(ylab="Frequency = # spectra", line=4) | 525 title(ylab="Frequency = # spectra", line=4) |
524 abline(v=median(peaksperpixel), col="blue") | 526 abline(v=median(peaksperpixel), col="blue") |
525 | 527 |
526 ## 9c) additional histogram to show contribution of annotation groups | 528 ## 9c) additional histogram to show contribution of annotation groups |
527 | 529 |
528 if (!is.null(levels(msidata\$annotation))){ | 530 if (!is.null(unique(msidata\$annotation))){ |
529 | 531 |
530 df_9 = data.frame(peaksperpixel, msidata\$annotation) | 532 df_9 = data.frame(peaksperpixel, msidata\$annotation) |
531 colnames(df_9) = c("Npeaks", "annotation") | 533 colnames(df_9) = c("Npeaks", "annotation") |
532 | 534 |
533 hist_9 = ggplot(df_9, aes(x=Npeaks, fill=annotation)) + | 535 hist_9 = ggplot(df_9, aes(x=Npeaks, fill=annotation)) + |
534 geom_histogram()+ theme_bw()+ | 536 geom_histogram()+ theme_bw()+ |
535 theme(text=element_text(family="ArialMT", face="bold", size=12))+ | 537 theme(text=element_text(family="ArialMT", face="bold", size=12))+ |
536 theme(plot.title = element_text(hjust = 0.5))+ | 538 theme(plot.title = element_text(hjust = 0.5))+ |
537 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 8))+ | 539 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 8))+ |
553 plot_colorByDensity(pixels(msidata), TICs, ylab = "", xlab = "", main="TIC per spectrum") | 555 plot_colorByDensity(pixels(msidata), TICs, ylab = "", xlab = "", main="TIC per spectrum") |
554 } | 556 } |
555 | 557 |
556 title(xlab="Spectra index", line=3) | 558 title(xlab="Spectra index", line=3) |
557 title(ylab = "Total ion current intensity", line=4) | 559 title(ylab = "Total ion current intensity", line=4) |
558 if (!is.null(levels(msidata\$annotation))){ | 560 if (!is.null(unique(msidata\$annotation))){ |
559 abline(v=abline_vector, lty = 3)} | 561 abline(v=abline_vector, lty = 3)} |
560 | 562 |
561 ## 10b) histogram | 563 ## 10b) histogram |
562 hist((TICs), main="", las=1, xlab = "TIC per spectrum", ylab="") | 564 hist(TICs, main="", las=1, xlab = "TIC per spectrum", ylab="") |
563 title(main= "TIC per spectrum", line=2) | 565 title(main= "TIC per spectrum", line=2) |
564 title(ylab="Frequency = # spectra", line=4) | 566 title(ylab="Frequency = # spectra", line=4) |
565 abline(v=median(TICs[TICs>0]), col="blue") | 567 abline(v=median(TICs[TICs>0]), col="blue") |
566 | 568 |
567 ## 10c) additional histogram to show annotation contributions | 569 ## 10c) additional histogram to show annotation contributions |
568 if (!is.null(levels(msidata\$annotation))){ | 570 if (!is.null(unique(msidata\$annotation))){ |
569 df_10 = data.frame((TICs), msidata\$annotation) | 571 df_10 = data.frame((TICs), msidata\$annotation) |
570 colnames(df_10) = c("TICs", "annotation") | 572 colnames(df_10) = c("TICs", "annotation") |
571 | 573 |
572 hist_10 = ggplot(df_10, aes(x=TICs, fill=annotation)) + | 574 hist_10 = ggplot(df_10, aes(x=TICs, fill=annotation)) + |
573 geom_histogram()+ theme_bw()+ | 575 geom_histogram()+ theme_bw()+ |
631 ########################## 14) Intensity distribution ###################### | 633 ########################## 14) Intensity distribution ###################### |
632 | 634 |
633 par(mfrow = c(2,1), mar=c(5,6,4,2)) | 635 par(mfrow = c(2,1), mar=c(5,6,4,2)) |
634 | 636 |
635 ## 14a) Median intensity over spectra | 637 ## 14a) Median intensity over spectra |
636 medianint_spectra = pixelApply(msidata, median) | 638 medianint_spectra = pixelApply(msidata, median, na.rm=TRUE) |
637 plot(medianint_spectra, main="Median intensity per spectrum",las=1, xlab="Spectra index", ylab="") | 639 plot(medianint_spectra, main="Median intensity per spectrum",las=1, xlab="Spectra index", ylab="") |
638 title(ylab="Median spectrum intensity", line=4) | 640 title(ylab="Median spectrum intensity", line=4) |
639 if (!is.null(levels(msidata\$annotation))){ | 641 if (!is.null(unique(msidata\$annotation))){ |
640 abline(v=abline_vector, lty = 3)} | 642 abline(v=abline_vector, lty = 3)} |
641 | 643 |
642 ## 14b) histogram: | 644 ## 14b) histogram: |
643 hist(as.matrix(spectra(msidata)), main="", xlab = "", ylab="", las=1) | 645 hist(int_matrix, main="", xlab = "", ylab="", las=1) |
644 title(main="Intensity histogram", line=2) | 646 title(main="Intensity histogram", line=2) |
645 title(xlab="intensities") | 647 title(xlab="intensities") |
646 title(ylab="Frequency", line=4) | 648 title(ylab="Frequency", line=4) |
647 abline(v=median(as.matrix(spectra(msidata))[(as.matrix(spectra(msidata))>0)], na.rm=TRUE), col="blue") | 649 abline(v=median(int_matrix)[(as.matrix(spectra(msidata))>0)], col="blue") |
648 | 650 |
649 | 651 |
650 ## 14c) histogram to show contribution of annotation groups | 652 ## 14c) histogram to show contribution of annotation groups |
651 | 653 |
652 if (!is.null(levels(msidata\$annotation))){ | 654 if (!is.null(unique(msidata\$annotation))){ |
653 | 655 |
654 df_13 = data.frame(matrix(,ncol=2, nrow=0)) | 656 df_13 = data.frame(matrix(,ncol=2, nrow=0)) |
655 for (subsample in levels(msidata\$annotation)){ | 657 for (subsample in unique(msidata\$annotation)){ |
656 log2_int_subsample = spectra(msidata)[,msidata\$annotation==subsample] | 658 log2_int_subsample = spectra(msidata)[,msidata\$annotation==subsample] |
657 df_subsample = data.frame(as.numeric(log2_int_subsample)) | 659 df_subsample = data.frame(as.numeric(log2_int_subsample)) |
658 df_subsample\$annotation = subsample | 660 df_subsample\$annotation = subsample |
659 df_13 = rbind(df_13, df_subsample)} | 661 df_13 = rbind(df_13, df_subsample)} |
660 df_13\$annotation = as.factor(df_13\$annotation) | 662 df_13\$annotation = as.factor(df_13\$annotation) |
666 labs(title="Intensities per sample", x="intensities", y = "Frequency") + | 668 labs(title="Intensities per sample", x="intensities", y = "Frequency") + |
667 theme(plot.title = element_text(hjust = 0.5))+ | 669 theme(plot.title = element_text(hjust = 0.5))+ |
668 theme(legend.position="bottom",legend.direction="vertical")+ | 670 theme(legend.position="bottom",legend.direction="vertical")+ |
669 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 8))+ | 671 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 8))+ |
670 guides(fill=guide_legend(ncol=5,byrow=TRUE))+ | 672 guides(fill=guide_legend(ncol=5,byrow=TRUE))+ |
671 geom_vline(xintercept = median(spectra(msidata)[(spectra(msidata)>0)]), size = 1, colour = "black",linetype = "dashed") | 673 geom_vline(xintercept = median(int_matrix)[(int_matrix>0)], size = 1, colour = "black",linetype = "dashed") |
672 print(hist_13) | 674 print(hist_13) |
673 | 675 |
674 ## 14d) boxplots to visualize in a different way the intensity distributions | 676 ## 14d) boxplots to visualize in a different way the intensity distributions |
675 par(mfrow = c(1,1), cex.axis=1.3, cex.lab=1.3, mar=c(13.1,4.1,5.1,2.1)) | 677 par(mfrow = c(1,1), cex.axis=1.3, cex.lab=1.3, mar=c(10,4.1,5.1,2.1)) |
676 | 678 |
677 mean_matrix = matrix(,ncol=0, nrow = nrow(msidata)) | 679 mean_matrix = matrix(,ncol=0, nrow = nrow(msidata)) |
678 for (subsample in levels(msidata\$annotation)){ | 680 for (subsample in unique(msidata\$annotation)){ |
679 mean_mz_sample = rowMeans(spectra(msidata)[,msidata\$annotation==subsample],na.rm=TRUE) | 681 mean_mz_sample = rowMeans(spectra(msidata)[,msidata\$annotation==subsample],na.rm=TRUE) |
680 mean_matrix = cbind(mean_matrix, mean_mz_sample)} | 682 mean_matrix = cbind(mean_matrix, mean_mz_sample)} |
681 | 683 |
682 boxplot(log10(mean_matrix), ylab = "Log10 mean intensity per m/z", main="Log10 mean m/z intensities per annotation group", xaxt = "n") | 684 boxplot(log10(as.data.frame(mean_matrix)), ylab = "Log10 mean intensity per m/z", main="Log10 mean m/z intensities per annotation group", xaxt = "n") |
683 (axis(1, at = c(1:number_combined), labels=levels(msidata\$annotation), las=2)) | 685 (axis(1, at = c(1:number_combined), cex.axis=0.9, labels=unique(msidata\$annotation), las=2)) |
684 | 686 |
685 ## 14e) Heatmap of mean intensities of annotation groups | 687 ## 14e) Heatmap of mean intensities of annotation groups |
686 | 688 |
687 colnames(mean_matrix) = levels(msidata\$annotation) | 689 colnames(mean_matrix) = unique(msidata\$annotation) |
688 mean_matrix[is.na(mean_matrix)] = 0 | 690 mean_matrix[is.na(mean_matrix)] = 0 |
689 heatmap.parameters <- list(mean_matrix, | 691 heatmap.parameters <- list(mean_matrix, |
690 show_rownames = T, show_colnames = T, | 692 show_rownames = T, show_colnames = T, |
691 main = "Heatmap of mean intensities per annotation group") | 693 main = "Heatmap of mean intensities per annotation group") |
692 par(oma=c(3,0,0,0)) | 694 par(oma=c(5,0,0,0)) |
693 print(heatmap(mean_matrix),margins = c(10, 10)) | 695 heatmap(mean_matrix) |
694 | 696 |
695 | 697 |
696 ## 14f) PCA of mean intensities of annotation groups | 698 ## 14f) PCA of mean intensities of annotation groups |
697 | 699 par(mar=c(4.1, 4.1, 4.1, 8.5)) |
698 ## define annotation by colour | 700 ## define annotation by colour |
699 annotation_colour = rainbow(length(levels(msidata\$annotation)))[as.factor(levels(msidata\$annotation))] | 701 annotation_colour = rainbow(length(unique(msidata\$annotation)))[as.factor(unique(msidata\$annotation))] |
700 ## transform and scale dataframe | 702 ## transform and scale dataframe |
701 pca = prcomp(t(mean_matrix),center=FALSE,scale.=FALSE) | 703 pca = prcomp(t(mean_matrix),center=FALSE,scale.=FALSE) |
702 ## plot single plot | 704 ## plot single plot |
703 plot(pca\$x[,c(1,2)],col=annotation_colour,pch=19) | 705 plot(pca\$x[,c(1,2)],col=annotation_colour,pch=19) |
706 legend("topright",xpd=TRUE, bty="n", inset=c(-0.3,0), cex=0.8, legend=unique(msidata\$annotation), col=rainbow(length(unique(msidata\$annotation))), pch=19) | |
704 ## plot pca with colours for max first 5 PCs | 707 ## plot pca with colours for max first 5 PCs |
705 pc_comp = ifelse(ncol(pca\$x)<5 , ncol(pca\$x), 5) | 708 pc_comp = ifelse(ncol(pca\$x)<5 , ncol(pca\$x), 5) |
706 pairs(pca\$x[,1:pc_comp],col=annotation_colour,pch=19) | 709 pairs(pca\$x[,1:pc_comp],col=annotation_colour,pch=19) |
707 legend("bottom", horiz = TRUE, legend=levels(msidata\$annotation), col=rainbow(length(levels(msidata\$annotation))), pch=19) | |
708 | 710 |
709 } | 711 } |
710 | 712 |
711 ################################## VI) Mass spectra and m/z accuracy ######################## | 713 ################################## VI) Mass spectra and m/z accuracy ######################## |
712 ############################################################################ | 714 ############################################################################ |
719 | 721 |
720 ## find three equal m/z ranges for the average mass spectra plots: | 722 ## find three equal m/z ranges for the average mass spectra plots: |
721 third_mz_range = round(nrow(msidata_no_NA)/3,0) | 723 third_mz_range = round(nrow(msidata_no_NA)/3,0) |
722 | 724 |
723 par(cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) | 725 par(cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) |
724 print(plot(msidata_no_NA, run="infile", layout=c(2,2), strip=FALSE, main= "Average spectrum")) | 726 print(plot(msidata_no_NA, run="infile", layout=c(2,2), strip=FALSE, main= "Average spectrum", col="black")) |
725 print(plot(msidata_no_NA[1:third_mz_range,], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum")) | 727 print(plot(msidata_no_NA[1:third_mz_range,], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black")) |
726 print(plot(msidata_no_NA[third_mz_range:(2*third_mz_range),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum")) | 728 print(plot(msidata_no_NA[third_mz_range:(2*third_mz_range),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum", col="black")) |
727 print(plot(msidata_no_NA[(2*third_mz_range):nrow(msidata_no_NA),], layout=FALSE, run="infile", strip=FALSE, main="Zoomed average spectrum")) | 729 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")) |
728 | 730 |
729 ## plot one average mass spectrum for each pixel annotation group | 731 ## plot one average mass spectrum for each pixel annotation group |
730 | 732 |
731 if (!is.null(levels(msidata\$annotation))){ | 733 if (!is.null(unique(msidata\$annotation))){ |
732 ## print legend only for less than 10 samples | 734 ## print legend only for less than 10 samples |
733 if (length(levels(msidata\$annotation)) < 10){ | 735 if (length(unique(msidata\$annotation)) < 10){ |
734 key_legend = TRUE | 736 key_legend = TRUE |
735 }else{key_legend = FALSE} | 737 }else{key_legend = FALSE} |
736 par(mfrow = c(1,1), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) | 738 par(mfrow = c(1,1), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) |
737 print(plot(msidata, run="infile", pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(levels(msidata\$annotation))),superpose=TRUE, main="Average mass spectra for annotation groups")) | 739 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")) |
738 } | 740 } |
739 | 741 |
740 ## plot 4 random mass spectra | 742 ## plot 4 random mass spectra |
741 ## find four random, not empty pixel to plot their spectra in the following plots: | 743 ## find four random, not empty pixel to plot their spectra in the following plots: |
742 pixel_vector = sample(which(TICs != 0),4) | 744 pixel_vector = sample(which(TICs != 0),4) |
743 | 745 |
744 par(mfrow = c(2, 2), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) | 746 par(mfrow = c(2, 2), cex.axis=1, cex.lab=1, mar=c(5.1,4.1,4.1,2.1)) |
745 print(plot(msidata_no_NA, pixel = pixel_vector)) | 747 print(plot(msidata_no_NA, pixel = pixel_vector, col="black")) |
746 | 748 |
747 | 749 |
748 ################### 16) Zoomed in mass spectra for calibrants ############## | 750 ################### 16) Zoomed in mass spectra for calibrants ############## |
749 | 751 |
750 count = 1 | 752 count = 1 |
788 | 790 |
789 ## plotting of 4 spectra in one page | 791 ## plotting of 4 spectra in one page |
790 par(oma=c(0,0,2,0)) | 792 par(oma=c(0,0,2,0)) |
791 ## average plot | 793 ## average plot |
792 | 794 |
793 print(plot(msidata_no_NA[minmasspixel1:maxmasspixel1,], run="infile", layout=c(2,2), strip=FALSE, main= "Average spectrum")) | 795 print(plot(msidata_no_NA[minmasspixel1:maxmasspixel1,], run="infile", layout=c(2,2), strip=FALSE, main= "Average spectrum", col="black")) |
794 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3)) | 796 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3)) |
795 abline(v=c(maxvalue), col="red", lty=2) | 797 abline(v=c(maxvalue), col="red", lty=2) |
796 abline(v=c(mzvalue), col="green2", lty=4) | 798 abline(v=c(mzvalue), col="green2", lty=4) |
797 ## average plot including points per data point | 799 ## average plot including points per data point |
798 print(plot(msidata_no_NA[minmasspixel1:maxmasspixel1,], run="infile", layout=FALSE, strip=FALSE, main="Average spectrum with data points")) | 800 print(plot(msidata_no_NA[minmasspixel1:maxmasspixel1,], run="infile", layout=FALSE, strip=FALSE, main="Average spectrum with data points", col="black")) |
799 points(mz(msidata_no_NA[minmasspixel1:maxmasspixel1,]), rowMeans(spectra(msidata_no_NA)[minmasspixel1:maxmasspixel1,,drop=FALSE]), col="blue", pch=20) | 801 points(mz(msidata_no_NA[minmasspixel1:maxmasspixel1,]), rowMeans(spectra(msidata_no_NA)[minmasspixel1:maxmasspixel1,,drop=FALSE]), col="blue", pch=20) |
800 ## plot of third average plot | 802 ## plot of third average plot |
801 print(plot(msidata_no_NA[minmasspixel2:maxmasspixel2,], run="infile", layout=FALSE, strip=FALSE, main= "Average spectrum")) | 803 print(plot(msidata_no_NA[minmasspixel2:maxmasspixel2,], run="infile", layout=FALSE, strip=FALSE, main= "Average spectrum", col="black")) |
802 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3)) | 804 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3)) |
803 abline(v=c(maxvalue), col="red", lty=2) | 805 abline(v=c(maxvalue), col="red", lty=2) |
804 abline(v=c(mzvalue), col="green2", lty=4) | 806 abline(v=c(mzvalue), col="green2", lty=4) |
805 ## plot of fourth average plot | 807 ## plot of fourth average plot |
806 print(plot(msidata_no_NA[minmasspixel3:maxmasspixel3,], run="infile", layout=FALSE, strip=FALSE, main= "Average spectrum")) | 808 print(plot(msidata_no_NA[minmasspixel3:maxmasspixel3,], run="infile", layout=FALSE, strip=FALSE, main= "Average spectrum", col="black")) |
807 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3)) | 809 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3)) |
808 abline(v=c(maxvalue), col="red", lty=2) | 810 abline(v=c(maxvalue), col="red", lty=2) |
809 abline(v=c(mzvalue), col="green2", lty=4) | 811 abline(v=c(mzvalue), col="green2", lty=4) |
810 title(paste0("theor. m/z: ", round(inputcalibrants[count,1], digits=4)), col.main="blue", outer=TRUE, line=0, adj=0.074) | 812 title(paste0("theor. m/z: ", round(inputcalibrants[count,1], digits=4)), col.main="blue", outer=TRUE, line=0, adj=0.074) |
811 title(paste0("most abundant m/z: ", round(maxvalue, digits=4)), col.main="red", outer=TRUE, line=0, adj=0.49) | 813 title(paste0("most abundant m/z: ", round(maxvalue, digits=4)), col.main="red", outer=TRUE, line=0, adj=0.49) |
812 title(paste0("closest m/z: ", round(mzvalue, digits=4)), col.main="green2", outer=TRUE, line=0, adj=0.93) | 814 title(paste0("closest m/z: ", round(mzvalue, digits=4)), col.main="green2", outer=TRUE, line=0, adj=0.93) |
813 | 815 |
814 ### 16b) one large extra plot with different colours for different pixel annotation groups | 816 ### 16b) one large extra plot with different colours for different pixel annotation groups |
815 | 817 |
816 if (!is.null(levels(msidata\$annotation))){ | 818 if (!is.null(unique(msidata\$annotation))){ |
817 if (number_combined < 10){ | 819 if (number_combined < 10){ |
818 key_zoomed = TRUE | 820 key_zoomed = TRUE |
819 }else{key_zoomed = FALSE} | 821 }else{key_zoomed = FALSE} |
820 par(mfrow = c(1, 1)) | 822 par(mfrow = c(1, 1)) |
821 print(plot(msidata_no_NA[minmasspixel1:maxmasspixel1,], run="infile", strip=FALSE,main="Average spectrum per annotation group", | 823 print(plot(msidata_no_NA[minmasspixel1:maxmasspixel1,], run="infile", strip=FALSE,main="Average spectrum per annotation group", |
908 | 910 |
909 plot(0,0,type="n", ylim=c(min(ppm_df, na.rm=TRUE),max(ppm_df, na.rm=TRUE)), xlim = c(1,ncol(filtered_data)),xlab = "Spectra index", ylab = "m/z difference in ppm", main="Difference m/z with max. average intensity vs. theor. m/z\n(per spectrum)") | 911 plot(0,0,type="n", ylim=c(min(ppm_df, na.rm=TRUE),max(ppm_df, na.rm=TRUE)), xlim = c(1,ncol(filtered_data)),xlab = "Spectra index", ylab = "m/z difference in ppm", main="Difference m/z with max. average intensity vs. theor. m/z\n(per spectrum)") |
910 for (each_cal in 1:ncol(ppm_df)){ | 912 for (each_cal in 1:ncol(ppm_df)){ |
911 lines(ppm_df[,each_cal], col=mycolours[each_cal], type="p")} | 913 lines(ppm_df[,each_cal], col=mycolours[each_cal], type="p")} |
912 legend("topright", inset=c(-0.2,0), xpd = TRUE, bty="n", cex=0.8,legend=inputcalibrantmasses, col=mycolours[1:ncol(ppm_df)],lty=1) | 914 legend("topright", inset=c(-0.2,0), xpd = TRUE, bty="n", cex=0.8,legend=inputcalibrantmasses, col=mycolours[1:ncol(ppm_df)],lty=1) |
913 if (!is.null(levels(msidata\$annotation))){ | 915 if (!is.null(unique(msidata\$annotation))){ |
914 abline(v=abline_vector, lty = 3)}} | 916 abline(v=abline_vector, lty = 3)}} |
915 | 917 |
916 ### make x-y-images for mz accuracy | 918 ### make x-y-images for mz accuracy |
917 | 919 |
918 ppm_dataframe = data.frame(coord(msidata)\$x, coord(msidata)\$y, ppm_df) | 920 ppm_dataframe = data.frame(coord(msidata)\$x, coord(msidata)\$y, ppm_df) |