comparison msi_qualitycontrol.xml @ 6:5c63fe03ed9e draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_qualitycontrol commit 06c2b45d8644b1d7fc01622a5c59dcbf8886d0f1
author galaxyp
date Mon, 23 Apr 2018 17:19:35 -0400
parents ac786240ef07
children b86a66dd1a16
comparison
equal deleted inserted replaced
5:ac786240ef07 6:5c63fe03ed9e
1 <tool id="mass_spectrometry_imaging_qc" name="MSI Qualitycontrol" version="1.7.0.4"> 1 <tool id="mass_spectrometry_imaging_qc" name="MSI Qualitycontrol" version="1.7.0.5">
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.7.0">bioconductor-cardinal</requirement> 6 <requirement type="package" version="1.7.0">bioconductor-cardinal</requirement>
241 ############################################################################ 241 ############################################################################
242 242
243 ## 1) Acquisition image 243 ## 1) Acquisition image
244 244
245 pixelnumber = 1:pixelcount 245 pixelnumber = 1:pixelcount
246 pixelxyarray=cbind(coord(msidata),pixelnumber) 246 pixelxyarray=cbind(coord(msidata)[,1:2],pixelnumber)
247 247
248 print(ggplot(pixelxyarray, aes(x=x, y=y, fill=pixelnumber)) 248 print(ggplot(pixelxyarray, aes(x=x, y=y, fill=pixelnumber))
249 + geom_tile() + coord_fixed() 249 + geom_tile() + coord_fixed()
250 + ggtitle("1) Order of Acquisition") 250 + ggtitle("Order of Acquisition")
251 +theme_bw() 251 +theme_bw()
252 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), 252 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"),
253 space = "Lab", na.value = "black", name = "Acq")) 253 space = "Lab", na.value = "black", name = "Acq"))
254 254
255 ## 2) Number of calibrants per spectrum 255 ## 2) Number of calibrants per spectrum
276 } 276 }
277 pixelmatrix = rbind(pixelmatrix, calibrantintensity) 277 pixelmatrix = rbind(pixelmatrix, calibrantintensity)
278 } 278 }
279 279
280 countvector= as.factor(colSums(pixelmatrix>0)) 280 countvector= as.factor(colSums(pixelmatrix>0))
281 countdf= cbind(coord(msidata), countvector) 281 countdf= cbind(coord(msidata)[,1:2], countvector)
282 mycolours = c("black","grey", "darkblue", "blue", "green" , "red", "yellow", "magenta", "olivedrab1", "lightseagreen") 282 mycolours = c("black","grey", "darkblue", "blue", "green" , "red", "yellow", "magenta", "olivedrab1", "lightseagreen")
283 283
284 print(ggplot(countdf, aes(x=x, y=y, fill=countvector)) 284 print(ggplot(countdf, aes(x=x, y=y, fill=countvector))
285 + geom_tile() + coord_fixed() 285 + geom_tile() + coord_fixed()
286 + ggtitle("2) Number of calibrants per pixel") 286 + ggtitle("Number of calibrants per pixel")
287 + theme_bw() 287 + theme_bw()
288 + theme(text=element_text(family="ArialMT", face="bold", size=12)) 288 + theme(text=element_text(family="ArialMT", face="bold", size=12))
289 + scale_fill_manual(values = mycolours[1:length(countvector)], 289 + scale_fill_manual(values = mycolours[1:length(countvector)],
290 na.value = "black", name = "# calibrants")) 290 na.value = "black", name = "# calibrants"))
291 }else{print("2) The inputcalibrant masses were not provided or outside the mass range")} 291 }else{print("2) The inputcalibrant masses were not provided or outside the mass range")}
350 350
351 mass1vector = spectra(msidata)[features(msidata, mz = maxmass1),] 351 mass1vector = spectra(msidata)[features(msidata, mz = maxmass1),]
352 mass2vector = spectra(msidata)[features(msidata, mz = maxmass2),] 352 mass2vector = spectra(msidata)[features(msidata, mz = maxmass2),]
353 foldchange = log2(mass1vector/mass2vector) 353 foldchange = log2(mass1vector/mass2vector)
354 354
355 ratiomatrix = cbind(foldchange, coord(msidata)) 355 ratiomatrix = cbind(foldchange, coord(msidata)[,1:2])
356 356
357 print(ggplot(ratiomatrix, aes(x=x, y=y, fill=foldchange), colour=colo) 357 print(ggplot(ratiomatrix, aes(x=x, y=y, fill=foldchange), colour=colo)
358 + geom_tile() + coord_fixed() 358 + geom_tile() + coord_fixed()
359 + ggtitle("$label") 359 + ggtitle("$label")
360 + theme_bw() 360 + theme_bw()
369 par(mfrow=c(1,1), mar=c(5.1, 4.1, 4.1, 2.1), mgp=c(3, 1, 0), las=0) 369 par(mfrow=c(1,1), mar=c(5.1, 4.1, 4.1, 2.1), mgp=c(3, 1, 0), las=0)
370 if (length(inputmasses) != 0) 370 if (length(inputmasses) != 0)
371 { for (mass in 1:length(inputmasses)) 371 { for (mass in 1:length(inputmasses))
372 { 372 {
373 image(msidata, mz=inputmasses[mass], plusminus=$plusminus_dalton, 373 image(msidata, mz=inputmasses[mass], plusminus=$plusminus_dalton,
374 main= paste0("3", LETTERS[mass], ") ", inputnames[mass], " (", round(inputmasses[mass], digits = 2)," ± ", $plusminus_dalton, " Da)"), 374 main= paste0(inputnames[mass], " (", round(inputmasses[mass], digits = 2)," ± ", $plusminus_dalton, " Da)"),
375 contrast.enhance = "histogram", ylim=c(maximumy+2, 0)) 375 contrast.enhance = "histogram", ylim=c(maximumy+2, 0))
376 } 376 }
377 } else {print("3) The inputpeptide masses were not provided or outside the mass range")} 377 } else {print("3) The inputpeptide masses were not provided or outside the mass range")}
378 378
379 379
380 ## 4) Number of peaks per pixel - image 380 ## 4) Number of peaks per pixel - image
381 381
382 peaksperpixel = colSums(spectra(msidata)[]> 0) 382 peaksperpixel = colSums(spectra(msidata)[]> 0)
383 peakscoordarray=cbind(coord(msidata), peaksperpixel) 383 peakscoordarray=cbind(coord(msidata)[,1:2], peaksperpixel)
384 384
385 print(ggplot(peakscoordarray, aes(x=x, y=y, fill=peaksperpixel), colour=colo) 385 print(ggplot(peakscoordarray, aes(x=x, y=y, fill=peaksperpixel), colour=colo)
386 + geom_tile() + coord_fixed() 386 + geom_tile() + coord_fixed()
387 + ggtitle("4) Number of peaks per pixel") 387 + ggtitle("Number of peaks per pixel")
388 + theme_bw() 388 + theme_bw()
389 + theme(text=element_text(family="ArialMT", face="bold", size=12)) 389 + theme(text=element_text(family="ArialMT", face="bold", size=12))
390 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange") 390 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange")
391 ,space = "Lab", na.value = "black", name = "# peaks")) 391 ,space = "Lab", na.value = "black", name = "# peaks"))
392 392
393 ## 5) TIC image 393 ## 5) TIC image
394 TICcoordarray=cbind(coord(msidata), TICs) 394 TICcoordarray=cbind(coord(msidata)[,1:2], TICs)
395 colo = colorRampPalette( 395 colo = colorRampPalette(
396 c("blue", "cyan", "green", "yellow","red")) 396 c("blue", "cyan", "green", "yellow","red"))
397 print(ggplot(TICcoordarray, aes(x=x, y=y, fill=TICs), colour=colo) 397 print(ggplot(TICcoordarray, aes(x=x, y=y, fill=TICs), colour=colo)
398 + geom_tile() + coord_fixed() 398 + geom_tile() + coord_fixed()
399 + ggtitle("5) Total Ion Chromatogram") 399 + ggtitle("Total Ion Chromatogram")
400 + theme_bw() 400 + theme_bw()
401 + theme(text=element_text(family="ArialMT", face="bold", size=12)) 401 + theme(text=element_text(family="ArialMT", face="bold", size=12))
402 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange") 402 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange")
403 ,space = "Lab", na.value = "black", name = "TIC")) 403 ,space = "Lab", na.value = "black", name = "TIC"))
404 404
405 ## 6) Most abundant mass image 405 ## 6) Most abundant mass image
406 406
407 highestmz = apply(spectra(msidata)[],2,which.max) 407 highestmz = apply(spectra(msidata)[],2,which.max)
408 highestmz_matrix = cbind(coord(msidata),mz(msidata)[highestmz]) 408 highestmz_matrix = cbind(coord(msidata)[,1:2],mz(msidata)[highestmz])
409 colnames(highestmz_matrix)[3] = "highestmzinDa" 409 colnames(highestmz_matrix)[3] = "highestmzinDa"
410 410
411 print(ggplot(highestmz_matrix, aes(x=x, y=y, fill=highestmzinDa)) 411 print(ggplot(highestmz_matrix, aes(x=x, y=y, fill=highestmzinDa))
412 + geom_tile() + coord_fixed() 412 + geom_tile() + coord_fixed()
413 + ggtitle("6) Most abundant m/z in each pixel") 413 + ggtitle("Most abundant m/z in each pixel")
414 + theme_bw() 414 + theme_bw()
415 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), space = "Lab", na.value = "black", name = "m/z", 415 + scale_fill_gradientn(colours = c("blue", "purple" , "red","orange"), space = "Lab", na.value = "black", name = "m/z",
416 labels = as.character(pretty(highestmz_matrix\$highestmzinDa)[c(1,3,5,7)]), 416 labels = as.character(pretty(highestmz_matrix\$highestmzinDa)[c(1,3,5,7)]),
417 breaks = pretty(highestmz_matrix\$highestmzinDa)[c(1,3,5,7)], limits=c(min(highestmz_matrix\$highestmzinDa), max(highestmz_matrix\$highestmzinDa))) 417 breaks = pretty(highestmz_matrix\$highestmzinDa)[c(1,3,5,7)], limits=c(min(highestmz_matrix\$highestmzinDa), max(highestmz_matrix\$highestmzinDa)))
418 + theme(text=element_text(family="ArialMT", face="bold", size=12))) 418 + theme(text=element_text(family="ArialMT", face="bold", size=12)))
425 secondhighestmz_pixel = which(round(highestmz_matrix\$highestmzinDa, digits=0) == secondhighestmz)[1] 425 secondhighestmz_pixel = which(round(highestmz_matrix\$highestmzinDa, digits=0) == secondhighestmz)[1]
426 426
427 ## 7) pca image for two components 427 ## 7) pca image for two components
428 pca = PCA(msidata, ncomp=2) 428 pca = PCA(msidata, ncomp=2)
429 par(mfrow = c(2,1)) 429 par(mfrow = c(2,1))
430 plot(pca, col=c("black", "darkgrey"), main="7) PCA for two components") 430 plot(pca, col=c("black", "darkgrey"), main="PCA for two components")
431 image(pca, col=c("black", "white"),ylim=c(maximumy+2, 0), strip=FALSE) 431 image(pca, col=c("black", "white"),ylim=c(maximumy+2, 0), strip=FALSE)
432 432
433 433
434 ############################# III) properties over acquisition (spectra index)########## 434 ############################# III) properties over acquisition (spectra index)##########
435 ############################################################################## 435 ##############################################################################
436 436
437 par(mfrow = c(2,1), mar=c(5,6,4,2)) 437 par(mfrow = c(2,1), mar=c(5,6,4,2))
438 438
439 ## 8a) number of peaks per spectrum - scatterplot 439 ## 8a) number of peaks per spectrum - scatterplot
440 plot_colorByDensity(pixels(msidata), peaksperpixel, ylab = "", xlab = "", main="8a) Number of peaks per spectrum") 440 plot_colorByDensity(pixels(msidata), peaksperpixel, ylab = "", xlab = "", main="Number of peaks per spectrum")
441 title(xlab="Spectra index \n (= Acquisition time)", line=3) 441 title(xlab="Spectra index \n (= Acquisition time)", line=3)
442 title(ylab="Number of peaks", line=4) 442 title(ylab="Number of peaks", line=4)
443 443
444 ## 8b) number of peaks per spectrum - histogram 444 ## 8b) number of peaks per spectrum - histogram
445 hist(peaksperpixel, main="", las=1, xlab = "Number of peaks per spectrum", ylab="") 445 hist(peaksperpixel, main="", las=1, xlab = "Number of peaks per spectrum", ylab="")
446 title(main="8b) Number of peaks per spectrum", line=2) 446 title(main="Number of peaks per spectrum", line=2)
447 title(ylab="Frequency = # spectra", line=4) 447 title(ylab="Frequency = # spectra", line=4)
448 abline(v=median(peaksperpixel), col="blue") 448 abline(v=median(peaksperpixel), col="blue")
449 449
450 ## 9a) TIC per spectrum - density scatterplot 450 ## 9a) TIC per spectrum - density scatterplot
451 zero=0 451 zero=0
452 par(mfrow = c(2,1), mar=c(5,6,4,2)) 452 par(mfrow = c(2,1), mar=c(5,6,4,2))
453 plot_colorByDensity(pixels(msidata), TICs, ylab = "", xlab = "", main="9a) TIC per pixel") 453 plot_colorByDensity(pixels(msidata), TICs, ylab = "", xlab = "", main="TIC per spectrum")
454 title(xlab="Spectra index \n (= Acquisition time)", line=3) 454 title(xlab="Spectra index \n (= Acquisition time)", line=3)
455 title(ylab = "Total ion chromatogram intensity", line=4) 455 title(ylab = "Total ion chromatogram intensity", line=4)
456 456
457 ## 9b) TIC per spectrum - histogram 457 ## 9b) TIC per spectrum - histogram
458 hist(log(TICs), main="", las=1, xlab = "log(TIC per spectrum)", ylab="") 458 hist(log(TICs), main="", las=1, xlab = "log(TIC per spectrum)", ylab="")
459 title(main= "9b) TIC per spectrum", line=2) 459 title(main= "TIC per spectrum", line=2)
460 title(ylab="Frequency = # spectra", line=4) 460 title(ylab="Frequency = # spectra", line=4)
461 abline(v=median(log(TICs[TICs>0])), col="blue") 461 abline(v=median(log(TICs[TICs>0])), col="blue")
462 462
463 463
464 ################################## IV) changes over mz ############################ 464 ################################## IV) changes over mz ############################
467 ## 11) Number of peaks per mz 467 ## 11) Number of peaks per mz
468 ## Number of peaks per mz - number across all pixel 468 ## Number of peaks per mz - number across all pixel
469 peakspermz = rowSums(spectra(msidata)[] > 0 ) 469 peakspermz = rowSums(spectra(msidata)[] > 0 )
470 470
471 par(mfrow = c(2,1), mar=c(5,6,4,4.5)) 471 par(mfrow = c(2,1), mar=c(5,6,4,4.5))
472 ## 11a) Number of peaks per mz - scatterplot 472 ## Number of peaks per mz - scatterplot
473 plot_colorByDensity(mz(msidata),peakspermz, main= "11a) Number of peaks for each mz", ylab ="") 473 plot_colorByDensity(mz(msidata),peakspermz, main= "Number of peaks per mz", ylab ="")
474 title(xlab="mz in Dalton", line=2.5) 474 title(xlab="mz in Dalton", line=2.5)
475 title(ylab = "Number of peaks", line=4) 475 title(ylab = "Number of peaks", line=4)
476 axis(4, at=pretty(peakspermz),labels=as.character(round((pretty(peakspermz)/pixelcount*100), digits=1)), las=1) 476 axis(4, at=pretty(peakspermz),labels=as.character(round((pretty(peakspermz)/pixelcount*100), digits=1)), las=1)
477 mtext("Coverage of spectra [%]", 4, line=3, adj=1) 477 mtext("Coverage of spectra [%]", 4, line=3, adj=1)
478 478
479 # make plot smaller to fit axis and labels, add second y axis with % 479 # make plot smaller to fit axis and labels, add second y axis with %
480 ## 11b) Number of peaks per mz - histogram 480 ## Number of peaks per mz - histogram
481 hist(peakspermz, main="", las=1, ylab="") 481 hist(peakspermz, main="", las=1, ylab="", xlab="")
482 title(ylab = "Frequency", line=4) 482 title(ylab = "Frequency", line=4)
483 title(main="11b) Number of peaks per mz", xlab = "Number of peaks per mz", line=2) 483 title(main="Number of peaks per mz", xlab = "Number of peaks per mz", line=2)
484 abline(v=median(peakspermz), col="blue") 484 abline(v=median(peakspermz), col="blue")
485 485
486 486
487 ## 12) Sum of intensities per mz 487 ## 12) Sum of intensities per mz
488 488
489 ## Sum of all intensities for each mz (like TIC, but for mz instead of pixel) 489 ## Sum of all intensities for each mz (like TIC, but for mz instead of pixel)
490 mzTIC = rowSums(spectra(msidata)[]) # calculate intensity sum for each mz 490 mzTIC = rowSums(spectra(msidata)[]) # calculate intensity sum for each mz
491 491
492 par(mfrow = c(2,1), mar=c(5,6,4,2)) 492 par(mfrow = c(2,1), mar=c(5,6,4,2))
493 # 12a) sum of intensities per mz - scatterplot 493 # 12a) sum of intensities per mz - scatterplot
494 plot_colorByDensity(mz(msidata),mzTIC, main= "12a) Sum of all peak intensities for each mz", ylab ="") 494 plot_colorByDensity(mz(msidata),mzTIC, main= "Sum of intensities per mz", ylab ="")
495 title(xlab="mz in Dalton", line=2.5) 495 title(xlab="mz in Dalton", line=2.5)
496 title(ylab="Intensity sum", line=4) 496 title(ylab="Intensity sum", line=4)
497 # 12b) sum of intensities per mz - histogram 497 # 12b) sum of intensities per mz - histogram
498 hist(log(mzTIC), main="", xlab = "", las=1, ylab="") 498 hist(log(mzTIC), main="", xlab = "", las=1, ylab="")
499 title(main="12b) Sum of intensities per mz", line=2, ylab="") 499 title(main="Sum of intensities per mz", line=2, ylab="")
500 title(xlab = "log (sum of intensities per mz)") 500 title(xlab = "log (sum of intensities per mz)")
501 title(ylab = "Frequency", line=4) 501 title(ylab = "Frequency", line=4)
502 abline(v=median(log(mzTIC[mzTIC>0])), col="blue") 502 abline(v=median(log(mzTIC[mzTIC>0])), col="blue")
503 503
504 ################################## V) general plots ############################ 504 ################################## V) general plots ############################
508 508
509 par(mfrow = c(2,1), mar=c(5,6,4,2)) 509 par(mfrow = c(2,1), mar=c(5,6,4,2))
510 510
511 ## 13a) Intensity histogram: 511 ## 13a) Intensity histogram:
512 hist(log2(spectra(msidata)[]), main="", xlab = "", ylab="", las=1) 512 hist(log2(spectra(msidata)[]), main="", xlab = "", ylab="", las=1)
513 title(main="13a) Log2-transformed intensities", line=2) 513 title(main="Log2-transformed intensities", line=2)
514 title(xlab="log2 intensities") 514 title(xlab="log2 intensities")
515 title(ylab="Frequency", line=4) 515 title(ylab="Frequency", line=4)
516 abline(v=median(log2(spectra(msidata)[(spectra(msidata)>0)])), col="blue") 516 abline(v=median(log2(spectra(msidata)[(spectra(msidata)>0)])), col="blue")
517 517
518 ## 13b) Median intensity over spectra 518 ## 13b) Median intensity over spectra
519 medianint_spectra = apply(spectra(msidata), 2, median) 519 medianint_spectra = apply(spectra(msidata), 2, median)
520 plot(medianint_spectra, main="13b) Median intensity per spectrum",las=1, xlab="Spectra index \n (= Acquisition time)", ylab="") 520 plot(medianint_spectra, main="Median intensity per spectrum",las=1, xlab="Spectra index \n (= Acquisition time)", ylab="")
521 title(ylab="Median spectrum intensity", line=4) 521 title(ylab="Median spectrum intensity", line=4)
522
523 ## 13c) Histogram on mz values
524 par(mfrow = c(1, 1))
525 hist(mz(msidata), xlab = "mz in Dalton", main="Histogram of mz values")
526
522 527
523 ## 14) Mass spectra 528 ## 14) Mass spectra
524 529
525 par(mfrow = c(2, 2)) 530 par(mfrow = c(2, 2))
526 plot(msidata, pixel = 1:length(pixelnumber), main= "Average spectrum") 531 plot(msidata, pixel = 1:length(pixelnumber), main= "Average spectrum")
527 plot(msidata, pixel =round(length(pixelnumber)/2, digits=0), main="Spectrum in middle of acquisition") 532 plot(msidata, pixel =round(length(pixelnumber)/2, digits=0), main="Spectrum in middle of acquisition")
528 plot(msidata, pixel = highestmz_pixel, main= paste0("Spectrum at ", rownames(coord(msidata)[highestmz_pixel,]))) 533 plot(msidata, pixel = highestmz_pixel, main= paste0("Spectrum at ", rownames(coord(msidata)[highestmz_pixel,1:2])))
529 plot(msidata, pixel = secondhighestmz_pixel, main= paste0("Spectrum at ", rownames(coord(msidata)[secondhighestmz_pixel,]))) 534 plot(msidata, pixel = secondhighestmz_pixel, main= paste0("Spectrum at ", rownames(coord(msidata)[secondhighestmz_pixel,1:2])))
530 535
531 ## 15) Zoomed in mass spectra for calibrants 536 ## 15) Zoomed in mass spectra for calibrants
532 plusminusvalue = $plusminus_dalton 537 plusminusvalue = $plusminus_dalton
533 x = 1 538 x = 1
534 if (length(inputcalibrantmasses) != 0) 539 if (length(inputcalibrantmasses) != 0)
541 par(mfrow = c(2, 2), oma=c(0,0,2,0)) 546 par(mfrow = c(2, 2), oma=c(0,0,2,0))
542 plot(msidata[minmasspixel:maxmasspixel,], pixel = 1:length(pixelnumber), main= "average spectrum") 547 plot(msidata[minmasspixel:maxmasspixel,], pixel = 1:length(pixelnumber), main= "average spectrum")
543 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3)) 548 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3))
544 plot(msidata[minmasspixel:maxmasspixel,], pixel =round(length(pixelnumber)/2, digits=0), main="pixel in middle of acquisition") 549 plot(msidata[minmasspixel:maxmasspixel,], pixel =round(length(pixelnumber)/2, digits=0), main="pixel in middle of acquisition")
545 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3)) 550 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3))
546 plot(msidata[minmasspixel:maxmasspixel,], pixel = highestmz_pixel,main= paste0("Spectrum at ", rownames(coord(msidata)[highestmz_pixel,]))) 551 plot(msidata[minmasspixel:maxmasspixel,], pixel = highestmz_pixel,main= paste0("Spectrum at ", rownames(coord(msidata)[highestmz_pixel,1:2])))
547 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3)) 552 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3))
548 plot(msidata[minmasspixel:maxmasspixel,], pixel = secondhighestmz_pixel, main= paste0("Spectrum at ", rownames(coord(msidata)[secondhighestmz_pixel,]))) 553 plot(msidata[minmasspixel:maxmasspixel,], pixel = secondhighestmz_pixel, main= paste0("Spectrum at ", rownames(coord(msidata)[secondhighestmz_pixel,1:2])))
549 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3)) 554 abline(v=c(calibrant-plusminusvalue, calibrant,calibrant+plusminusvalue), col="blue", lty=c(3,5,3))
550 title(paste0(inputcalibrants[x,1]), outer=TRUE) 555 title(paste0(inputcalibrants[x,1]), outer=TRUE)
551 x=x+1 556 x=x+1
552 } 557 }
553 558
554 }else{print("15) The inputcalibrant masses were not provided or outside the mass range")} 559 }else{print("15) The inputcalibrant masses were not provided or outside the mass range")}
555 560
561 ## 16) ppm accuracy measured vs. theoretical calibrant mass
562
563 if (length(inputcalibrantmasses) != 0)
564 {
565 par(mfrow = c(1, 1))
566
567 differencevector = vector()
568
569 for (mass in 1:length(inputcalibrantmasses))
570 {mznumber = features(msidata, mz = inputcalibrantmasses[mass]) ### this gives the featurenumber which is closest to given mz
571 mzvalue = mz(msidata)[mznumber] ### gives the mz in Da which is closest to the given mz (using the featurenumber)
572 mzdifference = inputcalibrantmasses[mass] - mzvalue ### difference in Da: theoretical value - closest mz value
573 ppmdifference = mzdifference/inputcalibrantmasses[mass]*1000000 ### calculate ppm for accuracy measurement
574 differencevector[mass] = ppmdifference }
575 differencevector = round(differencevector, digits=2)
576
577 ### plot the ppm difference theor. mz value to closest mz value:
578
579 calibrant_names = as.character(calibrant_list[,2])
580 diff_df = data.frame(differencevector, calibrant_names)
581 diff_plot<-ggplot(data=diff_df, aes(x=calibrant_names, y=differencevector)) + geom_col() + theme_minimal() +
582 labs(title="Theoretical calibrant mz vs. closest measured mz", x="calibrants", y = "Difference in ppm")+
583 geom_text(aes(label=differencevector), vjust=-0.3, size=3.5, col="blue")
584
585 print(diff_plot)
586
587 }else{print("16) The inputcalibrant masses were not provided or outside the mass range")}
588
589
556 dev.off() 590 dev.off()
591
557 }else{ 592 }else{
558 print("inputfile has no intensities > 0") 593 print("inputfile has no intensities > 0")
559 dev.off() 594 dev.off()
560 } 595 }
561 596
577 <param name="distance" value="0.25" type="float" label="Distance in Dalton" help="Distance in Da used to find peak maximum from input masses in both directions"/> 612 <param name="distance" value="0.25" type="float" label="Distance in Dalton" help="Distance in Da used to find peak maximum from input masses in both directions"/>
578 <param name="filenameratioplot" type="text" optional="true" label="Title" help="Optional title for fold change plot."/> 613 <param name="filenameratioplot" type="text" optional="true" label="Title" help="Optional title for fold change plot."/>
579 </repeat> 614 </repeat>
580 </inputs> 615 </inputs>
581 <outputs> 616 <outputs>
582 <data format="pdf" name="plots" from_work_dir="qualitycontrol.pdf" label = "${tool.name} on $infile.display_name"/> 617 <data format="pdf" name="plots" from_work_dir="qualitycontrol.pdf" label = "${tool.name} ${on_string}"/>
583 </outputs> 618 </outputs>
584 619
585 <tests> 620 <tests>
586 <test> 621 <test>
587 <param name="infile" value="" ftype="imzml"> 622 <param name="infile" value="" ftype="imzml">