comparison msi_qualitycontrol.xml @ 13:88e12d270e35 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_qualitycontrol commit 8087490eb4dcaf4ead0f03eae4126780d21e5503
author galaxyp
date Fri, 06 Jul 2018 14:14:09 -0400
parents c43a7821c030
children 7c7c39b9ec4a
comparison
equal deleted inserted replaced
12:c43a7821c030 13:88e12d270e35
1 <tool id="mass_spectrometry_imaging_qc" name="MSI Qualitycontrol" version="1.10.0.3"> 1 <tool id="mass_spectrometry_imaging_qc" name="MSI Qualitycontrol" version="1.10.0.4">
2 <description> 2 <description>
3 mass spectrometry imaging QC 3 mass spectrometry imaging QC
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>
52 #end if 52 #end if
53 53
54 ## create full matrix to make processed imzML files compatible with segmentation 54 ## create full matrix to make processed imzML files compatible with segmentation
55 iData(msidata) <- iData(msidata)[] 55 iData(msidata) <- iData(msidata)[]
56 56
57 ## remove duplicated coordinates
58 print(paste0(sum(duplicated(coord(msidata))), " duplicated coordinates were removed"))
59 msidata <- msidata[,!duplicated(coord(msidata))]
60
57 ###################################### file properties in numbers ###################### 61 ###################################### file properties in numbers ######################
58 62
59 ## Number of features (m/z) 63 ## Number of features (m/z)
60 maxfeatures = length(features(msidata)) 64 maxfeatures = length(features(msidata))
61 ## Range m/z 65 ## Range m/z
68 maximumx = max(coord(msidata)[,1]) 72 maximumx = max(coord(msidata)[,1])
69 ## Range y coordinates 73 ## Range y coordinates
70 minimumy = min(coord(msidata)[,2]) 74 minimumy = min(coord(msidata)[,2])
71 maximumy = max(coord(msidata)[,2]) 75 maximumy = max(coord(msidata)[,2])
72 ## Range of intensities 76 ## Range of intensities
73 minint = round(min(spectra(msidata)[]), digits=2) 77 minint = round(min(spectra(msidata)[], na.rm=TRUE), digits=2)
74 maxint = round(max(spectra(msidata)[]), digits=2) 78 maxint = round(max(spectra(msidata)[], na.rm=TRUE), digits=2)
75 medint = round(median(spectra(msidata)[]), digits=2) 79 medint = round(median(spectra(msidata)[], na.rm=TRUE), digits=2)
76 ## Number of intensities > 0 80 ## Number of intensities > 0
77 npeaks= sum(spectra(msidata)[]>0) 81 npeaks= sum(spectra(msidata)[]>0, na.rm=TRUE)
78 ## Spectra multiplied with m/z (potential number of peaks) 82 ## Spectra multiplied with m/z (potential number of peaks)
79 numpeaks = ncol(spectra(msidata)[])*nrow(spectra(msidata)[]) 83 numpeaks = ncol(spectra(msidata)[])*nrow(spectra(msidata)[])
80 ## Percentage of intensities > 0 84 ## Percentage of intensities > 0
81 percpeaks = round(npeaks/numpeaks*100, digits=2) 85 percpeaks = round(npeaks/numpeaks*100, digits=2)
82 ## Number of empty TICs 86 ## Number of empty TICs
83 TICs = colSums(spectra(msidata)[]) 87 TICs = colSums(spectra(msidata)[], na.rm=TRUE)
84 NumemptyTIC = sum(TICs == 0) 88 NumemptyTIC = sum(TICs == 0)
85 ## Median TIC 89 ## Median TIC
86 medTIC = round(median(TICs), digits=2) 90 medTIC = round(median(TICs), digits=2)
87 ## Median peaks per spectrum 91 ## Median peaks per spectrum
88 medpeaks = median(colSums(spectra(msidata)[]>0)) 92 medpeaks = median(colSums(spectra(msidata)[]>0, na.rm=TRUE), na.rm=TRUE)
89 print(cor(TICs,colSums(spectra(msidata)[]>0), method="pearson")) 93 print(cor(TICs,colSums(spectra(msidata)[]>0), method="pearson"))
90 94
91 ## Processing informations 95 ## Processing informations
92 processinginfo = processingData(msidata) 96 processinginfo = processingData(msidata)
93 centroidedinfo = processinginfo@centroided 97 centroidedinfo = processinginfo@centroided
209 213
210 ####################### II) x-y images ####################################### 214 ####################### II) x-y images #######################################
211 ############################################################################## 215 ##############################################################################
212 print("x-y images") 216 print("x-y images")
213 217
218 ## only do plots for file with intensity peaks
214 if (npeaks > 0){ 219 if (npeaks > 0){
215 ## function for density plots 220 ## function for density plots
216 plot_colorByDensity = function(x1,x2, 221 plot_colorByDensity = function(x1,x2,
217 ylim=c(min(x2),max(x2)), 222 ylim=c(min(x2),max(x2)),
218 xlim=c(min(x1),max(x1)), 223 xlim=c(min(x1),max(x1)),
313 ## filter for m/z window of each calibrant and calculate if sum of peak intensities > 0 318 ## filter for m/z window of each calibrant and calculate if sum of peak intensities > 0
314 for (mass in 1:length(inputcalibrantmasses)){ 319 for (mass in 1:length(inputcalibrantmasses)){
315 320
316 filtered_data = msidata[mz(msidata) >= inputcalibrantmasses[mass]-plusminusvalues[mass] & mz(msidata) <= inputcalibrantmasses[mass]+plusminusvalues[mass],] 321 filtered_data = msidata[mz(msidata) >= inputcalibrantmasses[mass]-plusminusvalues[mass] & mz(msidata) <= inputcalibrantmasses[mass]+plusminusvalues[mass],]
317 322
318 if (nrow(filtered_data) > 1 & sum(spectra(filtered_data)) > 0){ 323 if (nrow(filtered_data) > 1 & sum(spectra(filtered_data)[],na.rm=TRUE) > 0){
319 324
320 ## intensity of all m/z > 0 325 ## intensity of all m/z > 0
321 intensity_sum = colSums(spectra(filtered_data)) > 0 326 intensity_sum = colSums(spectra(filtered_data)[], na.rm=TRUE) > 0
322 }else if(nrow(filtered_data) == 1 & sum(spectra(filtered_data)) > 0){ 327
328 }else if(nrow(filtered_data) == 1 & sum(spectra(filtered_data)[], na.rm=TRUE) > 0){
323 329
324 ## intensity of only m/z > 0 330 ## intensity of only m/z > 0
325 intensity_sum = spectra(filtered_data) > 0 331 intensity_sum = spectra(filtered_data)[] > 0
332
326 }else{ 333 }else{
327 intensity_sum = rep(FALSE, ncol(filtered_data))} 334 intensity_sum = rep(FALSE, ncol(filtered_data))}
328 335
329 ## for each pixel add sum of intensity in the given m/z range 336 ## for each pixel add sum of intensity in the given m/z range
330 pixelmatrix = rbind(pixelmatrix, intensity_sum) 337 pixelmatrix = rbind(pixelmatrix, intensity_sum)
331 } 338 }
332 339
333 ## for each pixel count TRUE (each calibrant m/z range with intensity > 0 is TRUE) 340 ## for each pixel count TRUE (each calibrant m/z range with intensity > 0 is TRUE)
334 countvector= as.factor(colSums(pixelmatrix)) 341 countvector= as.factor(colSums(pixelmatrix, na.rm=TRUE))
335 countdf= cbind(coord(msidata)[,1:2], countvector) ## add pixel coordinates to counts 342 countdf= cbind(coord(msidata)[,1:2], countvector) ## add pixel coordinates to counts
336 mycolours = c("black","grey", "darkblue", "blue", "green" , "red", "yellow", "magenta", "olivedrab1", "lightseagreen") 343 mycolours = c("black","grey", "darkblue", "blue", "green" , "red", "yellow", "magenta", "olivedrab1", "lightseagreen")
337 344
338 print(ggplot(countdf, aes(x=x, y=y, fill=countvector))+ 345 print(ggplot(countdf, aes(x=x, y=y, fill=countvector))+
339 geom_tile() + coord_fixed() + 346 geom_tile() + coord_fixed() +
370 filtered_data1 = msidata[mz(msidata) >= mass1-distance & mz(msidata) <= mass1+distance,] 377 filtered_data1 = msidata[mz(msidata) >= mass1-distance & mz(msidata) <= mass1+distance,]
371 filtered_data2 = msidata[mz(msidata) >= mass2-distance & mz(msidata) <= mass2+distance,] 378 filtered_data2 = msidata[mz(msidata) >= mass2-distance & mz(msidata) <= mass2+distance,]
372 379
373 ### find m/z in the two given ranges with the highest mean intensity 380 ### find m/z in the two given ranges with the highest mean intensity
374 ### this two m/z will be used to calculate the fold change (red line in plot) 381 ### this two m/z will be used to calculate the fold change (red line in plot)
375 maxmassrow1 = rowMeans(spectra(filtered_data1)) 382 maxmassrow1 = rowMeans(spectra(filtered_data1), na.rm=TRUE)
376 maxmass1 = mz(filtered_data1)[which.max(maxmassrow1)] 383 maxmass1 = mz(filtered_data1)[which.max(maxmassrow1)]
377 maxmassrow2 = rowMeans(spectra(filtered_data2)) 384 maxmassrow2 = rowMeans(spectra(filtered_data2), na.rm=TRUE)
378 maxmass2 = mz(filtered_data2)[which.max(maxmassrow2)] 385 maxmass2 = mz(filtered_data2)[which.max(maxmassrow2)]
379 386
380 ### plot legend: chosen value in blue, distance in blue, max m/z in red 387 ### plot legend: chosen value in blue, distance in blue, max m/z in red
381 ### m/z range for each plot (fixed range of 5 Da) 388 ### m/z range for each plot (fixed range of 5 Da)
382 ### xlim does not work because it does not adjust for the max. intensities within the range 389 ### xlim does not work because it does not adjust for the max. intensities within the range
415 theme(text=element_text(family="ArialMT", face="bold", size=12))+ 422 theme(text=element_text(family="ArialMT", face="bold", size=12))+
416 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange") 423 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange")
417 ,space = "Lab", na.value = "black", name ="FC")) 424 ,space = "Lab", na.value = "black", name ="FC"))
418 }else{ 425 }else{
419 plot(0,type='n',axes=FALSE,ann=FALSE) 426 plot(0,type='n',axes=FALSE,ann=FALSE)
420 title(main=paste("At least one m/z range did not contain any intensity value > 0,\n therefore no foldchange plot could be drawn"))} 427 title(main=paste("At least one m/z range did not contain any intensity > 0,\n therefore no foldchange plot could be drawn"))}
421 428
422 #end for 429 #end for
423 #end if 430 #end if
424 431
425 #################### 4) m/z heatmaps ####################################### 432 #################### 4) m/z heatmaps #######################################
436 } else {print("4) The input peptide and calibrant m/z were not provided or outside the m/z range")} 443 } else {print("4) The input peptide and calibrant m/z were not provided or outside the m/z range")}
437 444
438 #################### 5) Number of peaks per pixel - image ################## 445 #################### 5) Number of peaks per pixel - image ##################
439 446
440 ## here every intensity value > 0 counts as pixel 447 ## here every intensity value > 0 counts as pixel
441 peaksperpixel = colSums(spectra(msidata)[]> 0) 448 peaksperpixel = colSums(spectra(msidata)[]> 0, na.rm=TRUE)
442 peakscoordarray=cbind(coord(msidata)[,1:2], peaksperpixel) 449 peakscoordarray=cbind(coord(msidata)[,1:2], peaksperpixel)
443 450
444 print(ggplot(peakscoordarray, aes(x=x, y=y, fill=peaksperpixel), colour=colo)+ 451 print(ggplot(peakscoordarray, aes(x=x, y=y, fill=peaksperpixel), colour=colo)+
445 geom_tile() + coord_fixed() + 452 geom_tile() + coord_fixed() +
446 ggtitle("Number of peaks per spectrum")+ 453 ggtitle("Number of peaks per spectrum")+
484 geom_tile() + coord_fixed() + 491 geom_tile() + coord_fixed() +
485 ggtitle("Most abundant m/z in each spectrum")+ 492 ggtitle("Most abundant m/z in each spectrum")+
486 theme_bw() + 493 theme_bw() +
487 theme(plot.title = element_text(hjust = 0.5))+ 494 theme(plot.title = element_text(hjust = 0.5))+
488 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), space = "Lab", na.value = "black", name = "m/z", 495 scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), space = "Lab", na.value = "black", name = "m/z",
489 labels = as.character(pretty(highestmz_matrix\$highestmzinDa)[c(1,3,5,7)]), 496 limits=c(min(highestmz_matrix\$highestmzinDa), max(highestmz_matrix\$highestmzinDa)))+
490 breaks = pretty(highestmz_matrix\$highestmzinDa)[c(1,3,5,7)], limits=c(min(highestmz_matrix\$highestmzinDa), max(highestmz_matrix\$highestmzinDa)))+
491 theme(text=element_text(family="ArialMT", face="bold", size=12))) 497 theme(text=element_text(family="ArialMT", face="bold", size=12)))
492
493 ## which m/z are highest
494 highestmz_peptides = names(sort(table(round(highestmz_matrix\$highestmzinDa, digits=0)), decreasing=TRUE)[1])
495 highestmz_pixel = which(round(highestmz_matrix\$highestmzinDa, digits=0) == highestmz_peptides)[1]
496
497 secondhighestmz = names(sort(table(round(highestmz_matrix\$highestmzinDa, digits=0)), decreasing=TRUE)[2])
498 secondhighestmz_pixel = which(round(highestmz_matrix\$highestmzinDa, digits=0) == secondhighestmz)[1]
499 498
500 ## append list for optional tabular output with spectrum values 499 ## append list for optional tabular output with spectrum values
501 colnames(highestmz_matrix)[3] = "Most abundant m/z" 500 colnames(highestmz_matrix)[3] = "Most abundant m/z"
502 spectrum_list[[list_count]] = highestmz_matrix 501 spectrum_list[[list_count]] = highestmz_matrix
503 502
504 ########################## 8) pca image for two components ################# 503 ## tabular output of spectra values
504
505 #if $pixel_output:
506 print("pixel list")
507 pixel_df = Reduce(function(...) merge(..., by=c("x", "y"), all=T), spectrum_list)
508 write.table(pixel_df, file="$pixel_tabular_output", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
509 #end if
510
511 ########################## 8) optional pca image for two components #################
512
513 #if $do_pca:
505 514
506 pca = PCA(msidata, ncomp=2) 515 pca = PCA(msidata, ncomp=2)
507 par(mfrow = c(2,1)) 516 par(mfrow = c(2,1))
508 plot(pca, col=c("black", "darkgrey"), main="PCA for two components") 517 plot(pca, col=c("black", "darkgrey"), main="PCA for two components")
509 image(pca, col=c("black", "white"), strip=FALSE, ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy)) 518 image(pca, col=c("black", "white"), strip=FALSE, ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy))
519
520 #end if
510 521
511 ################## III) properties over spectra index ########## 522 ################## III) properties over spectra index ##########
512 ############################################################################## 523 ##############################################################################
513 print("properties over pixels") 524 print("properties over pixels")
514 par(mfrow = c(2,1), mar=c(5,6,4,2)) 525 par(mfrow = c(2,1), mar=c(5,6,4,2))
689 plot(msidata, pixel = 1:length(pixelnumber), main= "Average spectrum") 700 plot(msidata, pixel = 1:length(pixelnumber), main= "Average spectrum")
690 plot(msidata, pixel = pixels_for_plot[1], main=paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[1],1:2]))) 701 plot(msidata, pixel = pixels_for_plot[1], main=paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[1],1:2])))
691 plot(msidata, pixel = pixels_for_plot[2], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[2],1:2]))) 702 plot(msidata, pixel = pixels_for_plot[2], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[2],1:2])))
692 plot(msidata, pixel = pixels_for_plot[3], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[3],1:2]))) 703 plot(msidata, pixel = pixels_for_plot[3], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[3],1:2])))
693 704
694 #################### 16) Zoomed in mass spectra for calibrants############## 705 ################### 16) Zoomed in mass spectra for calibrants ##############
695 706
696 count = 1 707 count = 1
697 differencevector = numeric() 708 differencevector = numeric()
698 differencevector2 = vector() 709 differencevector2 = vector()
699 710
700 if (length(inputcalibrantmasses) != 0){ 711 if (length(inputcalibrantmasses) != 0){
701 712
702 ### calculate plusminus values in m/z for each calibrant, this is used for all following plots 713 ### calculate plusminus values in m/z for each calibrant, this is used for all following plots
703 plusminusvalues = rep($plusminus_ppm/1000000, length(inputcalibrantmasses))*inputcalibrantmasses 714 plusminusvalues = rep($plusminus_ppm/1000000, length(inputcalibrantmasses)) * inputcalibrantmasses
704 715
705 for (mass in 1:length(inputcalibrantmasses)){ 716 for (mass in 1:length(inputcalibrantmasses)){
706 717
707 ### define the plot window with xmin und xmax 718 ### define the plot window with xmin und xmax
708 minmasspixel = features(msidata, mz=inputcalibrantmasses[mass]-1) 719 minmasspixel = features(msidata, mz=inputcalibrantmasses[mass]-1)
709 maxmasspixel = features(msidata, mz=inputcalibrantmasses[mass]+3) 720 maxmasspixel = features(msidata, mz=inputcalibrantmasses[mass]+3)
710 721
711 ### find m/z with the highest mean intensity in m/z range (red line in plot 16) and calculate ppm difference for plot 17 722 ### find m/z with the highest mean intensity in m/z range (red line in plot 16) and calculate ppm difference for plot 17
712 filtered_data = msidata[mz(msidata) >= inputcalibrantmasses[mass]-plusminusvalues[mass] & mz(msidata) <= inputcalibrantmasses[mass]+plusminusvalues[mass],] 723 filtered_data = msidata[mz(msidata) >= inputcalibrantmasses[mass]-plusminusvalues[mass] & mz(msidata) <= inputcalibrantmasses[mass]+plusminusvalues[mass],]
724
713 if (nrow(filtered_data) > 0 & sum(spectra(filtered_data)) > 0){ 725 if (nrow(filtered_data) > 0 & sum(spectra(filtered_data)) > 0){
714 maxmassrow = rowMeans(spectra(filtered_data)) ## for each m/z average intensity is calculated 726 maxmassrow = rowMeans(spectra(filtered_data)) ## for each m/z average intensity is calculated
715 maxvalue = mz(filtered_data)[which.max(maxmassrow)] ### m/z with highest average intensity in m/z range 727 maxvalue = mz(filtered_data)[which.max(maxmassrow)] ### m/z with highest average intensity in m/z range
716 mzdifference = maxvalue - inputcalibrantmasses[mass] ### difference: theoretical value - closest m/z value 728 mzdifference = maxvalue - inputcalibrantmasses[mass] ### difference: theoretical value - closest m/z value
717 ppmdifference = mzdifference/inputcalibrantmasses[mass]*1000000 ### calculate ppm for accuracy measurement 729 ppmdifference = mzdifference/inputcalibrantmasses[mass]*1000000 ### calculate ppm for accuracy measurement
727 ppmdifference2 = mzdifference2/inputcalibrantmasses[mass]*1000000 739 ppmdifference2 = mzdifference2/inputcalibrantmasses[mass]*1000000
728 differencevector2[mass] = round(ppmdifference2, digits=2) 740 differencevector2[mass] = round(ppmdifference2, digits=2)
729 741
730 par(mfrow = c(2, 2), oma=c(0,0,2,0)) 742 par(mfrow = c(2, 2), oma=c(0,0,2,0))
731 plot(msidata[minmasspixel:maxmasspixel,], pixel = 1:length(pixelnumber), main= "average spectrum") 743 plot(msidata[minmasspixel:maxmasspixel,], pixel = 1:length(pixelnumber), main= "average spectrum")
732 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,1,3)) 744 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3))
733 abline(v=c(maxvalue), col="red", lty=2) 745 abline(v=c(maxvalue), col="red", lty=2)
734 abline(v=c(mzvalue), col="green2", lty=4) 746 abline(v=c(mzvalue), col="green2", lty=4)
735 plot(msidata[minmasspixel:maxmasspixel,], pixel = pixels_for_plot[1], main=paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[1],1:2]))) 747 plot(msidata[minmasspixel:maxmasspixel,], pixel = pixels_for_plot[1], main=paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[1],1:2])))
736 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,1,3)) 748 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3))
737 abline(v=c(maxvalue), col="red", lty=2) 749 abline(v=c(maxvalue), col="red", lty=2)
738 abline(v=c(mzvalue), col="green2", lty=4) 750 abline(v=c(mzvalue), col="green2", lty=4)
739 plot(msidata[minmasspixel:maxmasspixel,], pixel = pixels_for_plot[2], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[2],1:2]))) 751 plot(msidata[minmasspixel:maxmasspixel,], pixel = pixels_for_plot[2], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[2],1:2])))
740 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,1,3)) 752 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3))
741 abline(v=c(maxvalue), col="red", lty=2) 753 abline(v=c(maxvalue), col="red", lty=2)
742 abline(v=c(mzvalue), col="green2", lty=4) 754 abline(v=c(mzvalue), col="green2", lty=4)
743 plot(msidata[minmasspixel:maxmasspixel,], pixel = pixels_for_plot[3], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[3],1:2]))) 755 plot(msidata[minmasspixel:maxmasspixel,], pixel = pixels_for_plot[3], main= paste0("Spectrum at ", rownames(coord(msidata)[pixels_for_plot[3],1:2])))
744 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,1,3)) 756 abline(v=c(inputcalibrantmasses[mass] -plusminusvalues[count], inputcalibrantmasses[mass] ,inputcalibrantmasses[mass] +plusminusvalues[count]), col="blue", lty=c(3,5,3))
745 abline(v=c(maxvalue), col="red", lty=2) 757 abline(v=c(maxvalue), col="red", lty=2)
746 abline(v=c(mzvalue), col="green2", lty=4) 758 abline(v=c(mzvalue), col="green2", lty=4)
747 title(paste0("theor. m/z: ", inputcalibrants[count,1]), col.main="blue", outer=TRUE, line=0, adj=0.074) 759 title(paste0("theor. m/z: ", inputcalibrants[count,1]), col.main="blue", outer=TRUE, line=0, adj=0.074)
748 title(paste0("most abundant m/z: ", round(maxvalue, digits=4)), col.main="red", outer=TRUE, line=0, adj=0.49) 760 title(paste0("most abundant m/z: ", round(maxvalue, digits=4)), col.main="red", outer=TRUE, line=0, adj=0.49)
749 title(paste0("closest m/z: ", round(mzvalue, digits=4)), col.main="green2", outer=TRUE, line=0, adj=0.93) 761 title(paste0("closest m/z: ", round(mzvalue, digits=4)), col.main="green2", outer=TRUE, line=0, adj=0.93)
762 count=count+1 774 count=count+1
763 } 775 }
764 776
765 ######### 17) ppm difference input calibrant m/z and m/z with max intensity in given m/z range######### 777 ######### 17) ppm difference input calibrant m/z and m/z with max intensity in given m/z range#########
766 778
767 par(mfrow = c(1, 1))
768
769 ### plot the ppm difference calculated above: theor. m/z value to highest m/z value: 779 ### plot the ppm difference calculated above: theor. m/z value to highest m/z value:
770 780
771 calibrant_names = as.character(inputcalibrants[,2]) 781 calibrant_names = as.character(inputcalibrants[,2])
772 diff_df = data.frame(differencevector, calibrant_names) 782 diff_df = data.frame(differencevector, calibrant_names)
773 783
774 if (sum(is.na(diff_df[,1])) == nrow(diff_df)){ 784 if (sum(is.na(diff_df[,1])) == nrow(diff_df)){
775 print("plot 17: no peaks in the chosen region, repeat with higher ppm range") 785 plot(0,type='n',axes=FALSE,ann=FALSE)
786 title(main=paste("plot 17: no peaks in the chosen region, repeat with higher ppm range")) ## here klammer weggenommen...
776 }else{ 787 }else{
777 788
778 diff_plot=ggplot(data=diff_df, aes(x=calibrant_names, y=differencevector)) + geom_bar(stat="identity", fill = "darkgray") + theme_minimal() + 789 diff_plot1=ggplot(data=diff_df, aes(x=calibrant_names, y=differencevector)) + geom_bar(stat="identity", fill = "darkgray") + theme_minimal() +
779 labs(title="Difference m/z with max. average intensity vs. theor. calibrant m/z", x="calibrants", y = "Difference in ppm")+ 790 labs(title="Average m/z error (max. average intensity vs. theor. calibrant m/z)", x="calibrants", y = "Average m/z error in ppm")+
780 theme(plot.title = element_text(hjust = 0.5))+theme(text=element_text(family="ArialMT", face="bold", size=12))+ 791 theme(plot.title = element_text(hjust = 0.5, size=14))+theme(text=element_text(family="ArialMT", face="bold", size=16))+
781 geom_text(aes(label=differencevector), vjust=-0.3, size=3.5, col="blue") 792 geom_text(aes(label=differencevector), vjust=-0.3, size=5.5, col="blue") +
782 793 theme(axis.text.x = element_text(angle = 90, hjust = 1, size=16))
783 print(diff_plot)} 794
795 print(diff_plot1)
796 }
784 797
785 ######### 18) ppm difference input calibrant m/z and closest m/z ########### 798 ######### 18) ppm difference input calibrant m/z and closest m/z ###########
786 799
787 ### plot the ppm difference calculated above theor. m/z value to closest m/z value: 800 ### plot the ppm difference calculated above theor. m/z value to closest m/z value:
788 801
789 differencevector2 = round(differencevector2, digits=2) 802 differencevector2 = round(differencevector2, digits=2)
790 calibrant_names = as.character(inputcalibrants[,2]) 803 calibrant_names = as.character(inputcalibrants[,2])
791 diff_df = data.frame(differencevector2, calibrant_names) 804 diff_df = data.frame(differencevector2, calibrant_names)
792 805
793 diff_plot=ggplot(data=diff_df, aes(x=calibrant_names, y=differencevector2)) + geom_bar(stat="identity", fill = "darkgray") + theme_minimal() + 806 diff_plot2=ggplot(data=diff_df, aes(x=calibrant_names, y=differencevector2)) + geom_bar(stat="identity", fill = "darkgray") + theme_minimal() +
794 labs(title="Difference closest measured m/z vs. theor. calibrant m/z", x="calibrants", y = "Difference in ppm")+ 807 labs(title="Average m/z error (closest measured m/z vs. theor. calibrant m/z)", x="calibrants", y = "Average m/z error in ppm")+
795 theme(plot.title = element_text(hjust = 0.5))+theme(text=element_text(family="ArialMT", face="bold", size=12))+ 808 theme(plot.title = element_text(hjust = 0.5, size=16))+theme(text=element_text(family="ArialMT", face="bold", size=16))+
796 geom_text(aes(label=differencevector2), vjust=-0.3, size=3.5, col="blue") 809 geom_text(aes(label=differencevector2), vjust=-0.3, size=5.5, col="blue")+
797 810 theme(axis.text.x = element_text(angle = 90, hjust = 1, size=16))
798 print(diff_plot) 811
812 print(diff_plot2)
813
799 814
800 #################### 19) ppm difference over pixels ##################### 815 #################### 19) ppm difference over pixels #####################
801 816
817 par(mfrow = c(1,1))
802 mycolours = c("darkgrey", "darkblue", "blue", "green" , "red", "orange", "yellow", "magenta", "olivedrab1", "lightseagreen") 818 mycolours = c("darkgrey", "darkblue", "blue", "green" , "red", "orange", "yellow", "magenta", "olivedrab1", "lightseagreen")
803 count = 1 819 count = 1
804 ppm_df = as.data.frame(matrix(,ncol=0, nrow = ncol(msidata))) 820 ppm_df = as.data.frame(matrix(,ncol=0, nrow = ncol(msidata)))
805 for (calibrant in inputcalibrantmasses){ 821 for (calibrant in inputcalibrantmasses){
806 ### find m/z with the highest mean intensity in m/z range, if no m/z in the range, all ppm differences will be NA 822 ### find m/z with the highest mean intensity in m/z range, if no m/z in the range, all ppm differences will be NA
823 839
824 ppm_df = cbind(ppm_df, ppm_vector) 840 ppm_df = cbind(ppm_df, ppm_vector)
825 count=count+1} 841 count=count+1}
826 842
827 if (sum(is.na(ppm_df)) == ncol(ppm_df)*nrow(ppm_df)){ 843 if (sum(is.na(ppm_df)) == ncol(ppm_df)*nrow(ppm_df)){
828 print("plot 19: no peaks in the chosen region, repeat with higher ppm range") 844 plot(0,type='n',axes=FALSE,ann=FALSE)
845 title(main=paste("plot 19: no peaks in the chosen region, repeat with higher ppm range"))
829 }else{ 846 }else{
830 847
831 ### plot ppm differences over pixels (spectra index) 848 ### plot ppm differences over pixels (spectra index)
832 849
833 par(mar=c(4.1, 4.1, 4.1, 7.5)) 850 par(mar=c(4.1, 4.1, 4.1, 7.5))
834 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)") 851 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)")
835 852
836 for (each_cal in 1:ncol(ppm_df)){ 853 for (each_cal in 1:ncol(ppm_df)){
837 lines(ppm_df[,each_cal], col=mycolours[each_cal], type="p")} 854 lines(ppm_df[,each_cal], col=mycolours[each_cal], type="p")}
838 legend("topright", inset=c(-0.25,0), xpd = TRUE, bty="n", legend=inputcalibrantmasses, col=mycolours[1:ncol(ppm_df)],lty=1) 855 legend("topright", inset=c(-0.25,0), xpd = TRUE, bty="n", legend=inputcalibrantmasses, col=mycolours[1:ncol(ppm_df)],lty=1)
839 abline(v=abline_vector, lty = 3)} 856 abline(v=abline_vector, lty = 3)}
840 857
841 }else{print("16+17+18+19) The inputcalibrant m/z were not provided or outside the m/z range")} 858 }else{print("plot 16+17+18+19) The inputcalibrant m/z were not provided or outside the m/z range")}
842
843 dev.off()
844
845 }else{ 859 }else{
846 print("inputfile has no intensities > 0") 860 print("inputfile has no intensities > 0")
861 }
847 dev.off() 862 dev.off()
848 }
849
850 ## tabular output of spectra values
851
852 #if $pixel_output:
853 print("pixel list")
854 pixel_df = Reduce(function(...) merge(..., by=c("x", "y"), all=T), spectrum_list)
855 write.table(pixel_df, file="$pixel_tabular_output", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t")
856 #end if
857 863
858 864
859 865
860 ]]></configfile> 866 ]]></configfile>
861 </configfiles> 867 </configfiles>
878 </conditional> 884 </conditional>
879 <param name="filename" type="text" value="" optional="true" label="Title" help="will appear as header in the quality report, if nothing given input dataset name is used"/> 885 <param name="filename" type="text" value="" optional="true" label="Title" help="will appear as header in the quality report, if nothing given input dataset name is used"/>
880 <param name="calibrant_file" type="data" optional="true" format="tabular" 886 <param name="calibrant_file" type="data" optional="true" format="tabular"
881 label="File with internal calibrants" help="first column: m/z, second column: name (optional), tabular file"/> 887 label="File with internal calibrants" help="first column: m/z, second column: name (optional), tabular file"/>
882 <param name="plusminus_ppm" value="50" type="float" label="ppm range" help="Will be added in both directions to input calibrant m/z"/> 888 <param name="plusminus_ppm" value="50" type="float" label="ppm range" help="Will be added in both directions to input calibrant m/z"/>
889 <param name="do_pca" type="boolean" display="radio" label="PCA with 2 components"/>
883 <repeat name="calibrantratio" title="Plot fold change of two m/z" min="0" max="10"> 890 <repeat name="calibrantratio" title="Plot fold change of two m/z" min="0" max="10">
884 <param name="mass1" value="1111" type="float" label="M/z 1" help="First m/z"/> 891 <param name="mass1" value="1111" type="float" label="M/z 1" help="First m/z"/>
885 <param name="mass2" value="2222" type="float" label="M/z 2" help="Second m/z"/> 892 <param name="mass2" value="2222" type="float" label="M/z 2" help="Second m/z"/>
886 <param name="distance" value="0.25" type="float" label="M/z range" help="Plusminus m/z window added to input m/z. In both m/z ranges the maximum intensity is used to calculate the fold change"/> 893 <param name="distance" value="0.25" type="float" label="M/z range" help="Plusminus m/z window added to input m/z. In both m/z ranges the maximum intensity is used to calculate the fold change"/>
887 <param name="filenameratioplot" type="text" optional="true" label="Title" help="Optional title for fold change plot."/> 894 <param name="filenameratioplot" type="text" optional="true" label="Title" help="Optional title for fold change plot."/>
906 <param name="units" value="ppm"/> 913 <param name="units" value="ppm"/>
907 </conditional> 914 </conditional>
908 <param name="calibrant_file" value="inputcalibrantfile1.txt"/> 915 <param name="calibrant_file" value="inputcalibrantfile1.txt"/>
909 <param name="plusminus_ppm" value="100"/> 916 <param name="plusminus_ppm" value="100"/>
910 <param name="filename" value="Testfile_imzml"/> 917 <param name="filename" value="Testfile_imzml"/>
918 <param name="do_pca" value="True"/>
911 <repeat name="calibrantratio"> 919 <repeat name="calibrantratio">
912 <param name="mass1" value="328.9"/> 920 <param name="mass1" value="328.9"/>
913 <param name="mass2" value="398.8"/> 921 <param name="mass2" value="398.8"/>
914 <param name="distance" value="0.25"/> 922 <param name="distance" value="0.25"/>
915 <param name="filenameratioplot" value = "Ratio of mass1 (328.9) / mass2 (398.8)"/> 923 <param name="filenameratioplot" value = "Ratio of mass1 (328.9) / mass2 (398.8)"/>
924 <composite_data value="Analyze75.img"/> 932 <composite_data value="Analyze75.img"/>
925 <composite_data value="Analyze75.t2m"/> 933 <composite_data value="Analyze75.t2m"/>
926 </param> 934 </param>
927 <param name="calibrant_file" value="inputcalibrantfile2.txt"/> 935 <param name="calibrant_file" value="inputcalibrantfile2.txt"/>
928 <param name="filename" value="Testfile_analyze75"/> 936 <param name="filename" value="Testfile_analyze75"/>
937 <param name="do_pca" value="True"/>
929 <output name="plots" file="QC_analyze75.pdf" compare="sim_size" delta="20000"/> 938 <output name="plots" file="QC_analyze75.pdf" compare="sim_size" delta="20000"/>
930 </test> 939 </test>
931 <test expect_num_outputs="2"> 940 <test expect_num_outputs="2">
932 <param name="infile" value="123_combined.RData" ftype="rdata"/> 941 <param name="infile" value="123_combined.RData" ftype="rdata"/>
933 <param name="filename" value="Testfile_rdata"/> 942 <param name="filename" value="Testfile_rdata"/>
943 <param name="do_pca" value="True"/>
934 <param name="pixel_output" value="True"/> 944 <param name="pixel_output" value="True"/>
935 <output name="pixel_tabular_output" file="spectra_info_123_combi.txt"/> 945 <output name="pixel_tabular_output" file="spectra_info_123_combi.txt"/>
936 <output name="plots" file="QC_rdata.pdf" compare="sim_size" delta="20000"/> 946 <output name="plots" file="QC_rdata.pdf" compare="sim_size" delta="20000"/>
937 </test> 947 </test>
938 <test expect_num_outputs="1"> 948 <test expect_num_outputs="1">
939 <param name="infile" value="empty_spectra.rdata" ftype="rdata"/> 949 <param name="infile" value="empty_spectra.rdata" ftype="rdata"/>
940 <param name="calibrant_file" value="inputcalibrantfile2.txt"/> 950 <param name="calibrant_file" value="inputcalibrantfile2.txt"/>
941 <param name="filename" value="Testfile_rdata"/> 951 <param name="filename" value="Testfile_rdata"/>
952 <param name="do_pca" value="False"/>
942 <output name="plots" file="QC_empty_spectra.pdf" compare="sim_size" delta="20000"/> 953 <output name="plots" file="QC_empty_spectra.pdf" compare="sim_size" delta="20000"/>
943 </test> 954 </test>
944 </tests> 955 </tests>
945 <help> 956 <help>
946 <![CDATA[ 957 <![CDATA[