-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemi_t_matrices_neg.Rmd
1654 lines (1390 loc) · 64.9 KB
/
semi_t_matrices_neg.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Differential abundance analysis, semi-targeted approach"
subtitle: "Negative polarity"
author: "Christa Malfertheiner, Johannes Rainer"
output:
BiocStyle::html_document:
toc: true
number_sections: false
toc_float: true
bibliography: references.bib
csl: biomed-central.csl
references:
- family: noname
given: noname
---
```{r setup, echo = FALSE, results = "asis", warning = FALSE}
library(BiocStyle)
BiocStyle::markdown()
knitr::opts_chunk$set(echo = TRUE, message = FALSE, dev = c("png", "pdf"))
```
```{r parameters, echo = FALSE, warning = FALSE}
## Set general parameters
polarity <- "NEG" # specify "POS" or "NEG"
p.cut <- 0.05 # cut-off for significance.
m.cut <- 0.7 # cut-off for log2 fold change
set.seed(123)
## Setting golden ratio to save images
phi <- (1+sqrt(5))/2
FILE_NAME <- "semi_t_matrices_neg"
## Define paths:
IMAGE_PATH <- paste0("images/", FILE_NAME, "/")
if (dir.exists(IMAGE_PATH)) unlink(IMAGE_PATH, recursive = TRUE, force = TRUE)
dir.create(IMAGE_PATH, recursive = TRUE, showWarnings = FALSE)
RDATA_PATH <- paste0("data/RData/", FILE_NAME, "/")
dir.create(RDATA_PATH, recursive = TRUE, showWarnings = FALSE)
RESULT_PATH <- paste0("data/results/", FILE_NAME, "/")
dir.create(RESULT_PATH, recursive = TRUE, showWarnings = FALSE)
FIG_PATH <- paste0(IMAGE_PATH, "FIG/")
dir.create(FIG_PATH, showWarnings = FALSE)
```
# Introduction
In this document we perform the differential abundance analysis of the features
previously identified for the *MitYOU* project, with the aim of identifying
significant sample source-related features. This task is performed by hypothesis
testing, where we try to identify which metabolites have the most different
concentrations between plasma samples, venous and capillary blood samples.
We follow a semi-targeted approach, where we look at concentrations of features
corresponding to lab-internal set of standards.
# Data import
First, we load the required packages and the data, after preprocessing and
normalization. The end result of these steps is a `SummarizedExperiment` that
contains aligned data, where features are grouped (after correspondence), and
that have undergone gap filling, normalization by the median, linear fitting and
per-feature between-batch normalization to remove any unwanted variability.
The `SummarizedExperiment` lets us store all the information regarding the
normalization steps in the form of `assays`, which we are still able to access
to proceed with the analysis.
```{r load-data, echo = FALSE, warning = FALSE}
library(xcms)
library(limma)
library(pheatmap)
library(writexl)
library(SummarizedExperiment)
library(RColorBrewer)
library(MsFeatures)
library(CompMetaboTools)
library(pander)
setMSnbaseFastLoad(FALSE)
load("data/RData/vams_normalization_neg/res_neg.RData")
res_neg$sample_pair <- paste0(res_neg$source, ".", res_neg$sample)
```
It is important now to remove the `POOL` samples from the dataset, because the
analysis has to be performed only on study samples; the `POOL` samples, though
are still required to evaluate the goodness of the detected features, therefore
they will be stored in a separate `SummarizedExperiment` object that can be
accessed when needed.
We also exclude the `RBC` samples from our analysis, as these samples showed
a noisy signal beforehand. We also store them separatedly in a
`SummarizedExperiment` object
We also assign the colours as seen before.
```{r split-qc, echo = TRUE}
res_qc <- res_neg[, res_neg$source == "all"]
res_rbc <- res_neg[, res_neg$source == "RBC"]
res_neg <- res_neg[, res_neg$source != "all"]
res_neg <- res_neg[, res_neg$source != "RBC"]
res_neg$source <- factor(as.character(res_neg$source))
res_neg$sex <- factor(as.character(res_neg$sex))
col_source <- brewer.pal(6, name = "Set1")[c(6, 2, 1)]
names(col_source) <- c("plasma", #' yellow
"venous", #' blue
"capillary") #' red
col_sex <- brewer.pal(4, name = "Set1") [c(1, 2, 3)]
names(col_sex) <- c("F", # red
"M", # blue
"POOL") # green
## Setting golden ratio to save images
phi <- (1+sqrt(5))/2
```
Next, we merge the technical replicates.
```{r}
#' Average
averageSE <- function(x, column = character(), mainAssay = character()) {
if (!column %in% colnames(colData(x)))
stop("Column '", "' not found in 'colData' of 'x'")
f <- factor(colData(x)[, column], levels = unique(colData(x)[, column]))
## new colData: take the first element for each replicate.
cd <- colData(x)[match(levels(f), f), ]
rownames(cd) <- cd[, column]
## loop over the assays and average them.
a <- lapply(assays(x), function(z) {
z <- split.data.frame(t(z), f = f)
z <- do.call(cbind, lapply(z, colMeans, na.rm = TRUE))
z[is.na(z)] <- NA
z
})
if (length(mainAssay)) {
tmp <- split.data.frame(t(assay(x, mainAssay)), f = f)
tmp <- do.call(cbind, lapply(tmp, function(y) {
apply(y, MARGIN = 2, FUN = sd, na.rm = TRUE)
}))
tmp[is.na(tmp)] <- NA
a[[paste0(mainAssay, "_sd")]] <- tmp
}
SummarizedExperiment(assays = a, rowData = rowData(x),
colData = cd, metadata = metadata(x))
}
## Average technical replicates:
res_neg <- averageSE(res_neg, column = "sample_pair",
mainAssay = "normalized_filled")
```
The samples used in this analysis are listed below.
```{r, echo = FALSE, results = "asis"}
tab <- colData(res_neg)[, c("source", "sex", "age")]
pandoc.table(as.data.frame(tab), style = "rmarkdown",
caption = "Samples used in this analysis")
```
# Semi-targeted analysis
First, we restrict the analysis to a set of known compounds, whose
mass-to-charge ratio and retention time have been previously measured from the
pure standards. To start, a table of standards is loaded, then
a search in the m/z and retention time dimensions is carried out to match the
features found before to these compounds. Subsequently, EICs for all the
assigned features are plotted and visually inspected: this step is necessary to
accurately pair the detected peaks to the standards. When the list of assigned
standards is complete, we perform a differential abundance analysis on the
subset of features.
First, we load the information on the standards, with the aim of identifying
features potentially matching these and plotting the EICs for all of these.
```{r known-cmps, message = FALSE, warning = FALSE}
## Extract known compunds
library("MetaboCoreUtils")
library(Rdisop)
std_info <- read.table(
"https://raw.githubusercontent.com/EuracBiomedicalResearch/lcms-standards/master/data/standards_dilution.txt",
sep = "\t", header = TRUE, as.is = TRUE)
std_info <- std_info[!is.na(std_info[, "NEG"]), ]
rownames(std_info) <- 1:nrow(std_info)
std_info$mzneut = NA
std_info$mz_ion = NA
for (i in seq(nrow(std_info))) {
if (grepl("C", std_info$formula[i])) {
std_info$mzneut[i] <- getMolecule(
as.character(std_info$formula[i]))$exactmass
} else {
std_info$mzneut[i] = as.numeric(std_info$formula[i])
}
## Calculate also the m/z
std_info$mz_ion[i] <- mass2mz(
std_info$mzneut[i], adduct = std_info[i, "NEG"])[1, 1]
}
std_info <- std_info[!is.na(std_info$mz_ion), ]
std_info <- std_info[order(std_info$name), ]
## Manually adding an additional row for Creatinine and Creatine
to_add <- std_info[std_info$name %in% c("Creatinine", "Creatine"), ]
to_add$name <- paste0(to_add$name, "-full")
std_info <- rbind(std_info, to_add)
dr <- paste0(IMAGE_PATH, "/standards/")
dir.create(dr, recursive = TRUE, showWarnings = FALSE)
##load data_neg
load("data/RData/vams_normalization_neg/data_neg_filled.RData")
## Subset to the samples we're currently analyzing.
tmp <- filterFile(data_neg, match(res_neg$mzML_file, data_neg$mzML_file),
keepFeatures = TRUE)
```
We next match features from our data set against m/z of the expected ions and
the retention times for the set of lab-internal standards, extract their ion
chromatogram and plot these.
```{r}
library(MetaboAnnotation)
## Match feature's m/z and rt values against expecte values for standards.
rowData(res_neg)$ft <- row.names(res_neg)
par <- MzRtParam(tolerance = 0, ppm = 20, toleranceRt = 30)
mo <- matchMz(res_neg, std_info, param = par, mzColname = c("mzmed", "mz_ion"),
rtColname = c("rtmed", "RT"))
## Subset to matching features.
mo <- mo[whichQuery(mo)]
mo <- pruneTarget(mo)
chrs <- featureChromatograms(tmp, features = mo$ft, expandRt = 7, filled = TRUE)
sample_colors <- col_source[tmp$source]
for (i in seq_len(length(mo$ft))) {
chr <- chrs[i, ]
pks <- chromPeaks(chr)
fl <- mo$target_name[i]
png(paste0(dr, fl, "-", mo$ft[i], ".png"),
width = 10, height = 8, units = "cm", res = 300, pointsize = 6)
plot(chr, col = "#00000040",
peakCol = paste0(sample_colors[pks[, "column"]], 50),
peakBg = paste0(sample_colors[pks[, "column"]], 10))
abline(v = mo$target_RT[i])
legend("topleft", legend = c(mo$ft[i], fl,
paste0("rt: ", mo$target_RT[i]),
paste0("mz: ", mo$target_mz_ion[i])))
dev.off()
}
```
The EICs have been manually inspected and the best matching feature has been
manually assigned to the corresponding standard. Some features found a better
match than others, such as xyz; in this case, in fact, there is a single
peak detected, with high intensity, that is well within the theoretical m/z
range and it is very close to the theoretical retention time.
```{r assign-feature-metabolite, echo = FALSE, warning = FALSE, message = FALSE}
## This is the tricky manual thing:
## - Got through all plots for all standards and if there is one feature
## that clearly matches (i.e. retention time close to the expected retention
## time and a single peak present in the wider rt range) assign it.
## The code below helps creating the assignment:
## tmp <- cbind(mo$ft, mo$target_name)
## rownames(tmp)
## tmp <- tmp[order(tmp[, 2]), ]
## tmp[, 2, drop = FALSE]
to_keep <- c(
FT00485 = "1-Methylhistidine",
FT00948 = "1,5-anhydro D-glucitol",
FT00066 = "2-Hydroxybutyric acid",
FT00060 = "2-Ketobutyric acid",
FT00066 = "3-Hydroxybutyric Acid",
FT00485 = "3-Methylhistidine",
FT01695 = "Acetyl-Glucosamine",
FT00723 = "Acetylmethionine",
FT00176 = "Acetylalanine",
FT02496 = "Acetylneuraminic Acid",
FT02569 = "Adenosine",
FT00377 = "Alanine",
FT00383 = "Allantoin",
FT00105 = "Alpha-ketoisovaleric acid",
FT04311 = "alpha-Lactose",
FT10805 = "AMP",
FT00537 = "Arginine",
FT00188 = "Asparagine",
FT00603 = "Aspirin",
FT01143 = "Carnosine",
FT04651 = "CDP",
FT07631 = "CDP-choline",
FT05599 = "CDP-ethanolamine",
FT00554 = "Citrulline",
FT01310 = "Cystine",
FT03173 = "Dihydroxyacetone phosphate",
FT00061 = "Dimethylglycine",
FT00604 = "Fructose",
FT00785 = "Gluconic Acid",
FT01139 = "Glucose",
FT00287 = "Glutamine",
FT00186 = "Glutaric acid", # new
FT09252 = "Glutathione Oxidized",
FT09252 = "Glutathione Reduced",
FT00071 = "Glyceric Acid",
FT02155 = "Glycero-phosphocholine",
FT00362 = "Histidine",
FT00628 = "homovanillic acid",
FT00177 = "Hydroxyproline",
FT00236 = "Hypoxanthine",
FT00905 = "Indolelactic acid",
FT01712 = "Inosine",
FT00737 = "Isocitric Acid",
FT00181 = "Isoleucine",
FT00172 = "Ketoleucine",
FT00195 = "L-Aspartic Acid",
FT00132 = "L-Cysteine",
FT00294 = "L-Glutamic Acid",
FT00181 = "Leucine",
FT00289 = "Lysine",
FT01139 = "Mannose",
FT00313 = "Methionine",
FT00439 = "Methioninesulfoxide",
FT01141 = "Myo-Inositol",
FT00176 = "N-Acetyl-beta-alanine",
FT00535 = "N-Acetylornithine",
FT10215 = "NAD",
FT00191 = "Ornithine",
FT00334 = "p-Hydroxyphenylacetic acid",
FT00247 = "PABA",
FT01063 = "Pantothenic Acid",
FT00442 = "Phenylalanine",
FT00433 = "Phenylpyruvic acid",
FT00474 = "Phosphoenolpyruvic Acid",
FT01944 = "Phosphorylethanolamine",
FT00028 = "Pyruvic Acid",
FT00464 = "Quinolinic acid", # new
FT00323 = "Ribose",
FT04217 = "SAH",
FT00253 = "Salicylic acid",
FT08606 = "Sedoheptulose-7-phosphate", # new
FT00067 = "Serine",
FT03307 = "Sphingosine",
FT04106 = "Sphingosine-1-phosphate",
FT00534 = "Suberic Acid",
FT00118 = "Succinic Acid",
FT00384 = "Succinylacetone",
FT04312 = "Sucrose",
FT00145 = "Taurine",
FT00236 = "Threonic Acid",
FT00123 = "Threonine",
FT00891 = "Tryptophan",
FT02088 = "Uridine",
FT00333 = "Xanthine"
)
## Missing from previous analysis:
## FT00612 = "Tyrosine"
## FT00629 = "Galactitol"
mo <- filterMatches(mo, queryValue = names(to_keep),
targetValue = to_keep,
queryColname = "ft",
targetColname = "target_name",
keep = TRUE)
mo <- mo[whichQuery(mo)]
## Handling duplicates.
md <- as.data.frame(matchedData(mo, c("ft", "target_name", "target_HMDB.code",
"target_formula", "target_RT",
"score", "score_rt")))
md <- split(md, md$ft)
md <- do.call(rbind, lapply(md, function(z) {
tmp <- data.frame(ft = z$ft[1L])
tmp$name <- paste0(unique(z$target_name), collapse = ";")
tmp$HMDB <- paste0(unique(z$target_HMDB.code), collapse = ";")
tmp$target_formula <- paste0(unique(z$target_formula), collapse = ";")
tmp$diff_mz <- paste0(unique(z$score), collapse = ";")
tmp$diff_rt <- paste0(unique(z$score_rt), collapse = ";")
tmp
}))
```
A total of `r sum(nrow(md))` standards have been identified. The features
identified and the corresponding metabolite are summarized in this table:
```{r result-table-ft-std, echo = FALSE, results = "asis"}
## Write result table
tab <- md[, c("name"), drop = FALSE]
pandoc.table(as.data.frame(tab), style = "rmarkdown",
caption = "Features assigned to known compounds")
```
Next, only the features assigned to the standards are taken into consideration
and are subsetted in the `std_res` object.
```{r std-subset, echo = FALSE}
std_res <- query(mo)
rowData(std_res) <- cbind(rowData(std_res),
md[rownames(std_res), ])
```
The subsetting reduced the number of features to `r length(std_res)`.
A PCA analysis is then performed on the subset to verify whether anything has
changed and if any similarities among the samples are visible or not.
```{r standards-pca-all, echo = FALSE}
pc <- prcomp(t(log2(assay(std_res, "normalized_filled_imputed"))),
center = TRUE, scale. = FALSE)
```
```{r standards-pca-plot, fig.path = IMAGE_PATH, fig.cap = "PCA of the samples based on intensities of known compounds.", fig.width = 7 * phi, fig.height = 7, echo = FALSE}
par(mfrow = c(1, 2))
plot_pca(pc, col = paste0(col_source[as.character(std_res$source)], 90),
pc_x = 1, pc_y = 2, labels = std_res$differentiation)
plot_pca(pc, col = paste0(col_source[as.character(std_res$source)], 90),
pc_x = 3, pc_y = 4)
legend("topleft", col = col_source, legend = names(col_source),
title = "phenotype", pch = 16, ncol = 2)
```
In the PC1 plot, we see a clear separation between the three matrices, which is
also seen in PC2.In PC3, some of the capillary samples do not cluster with the
rest of the samples, but it needs to be considered that the variance described
by this dimension is rather low.
## Heatmap
To visualize the intensity of all detected standards across the three matrices,
we created a heatmap of the known compounds we found in our samples.
```{r heatmap-source-semitargeted, fig.width = 15, fig.height = 13, fig.cap = "Heatmap of known compounds. Note that for better visibility, the color range has been restricted to -5 to 5, thus, differences larger than these values are assigned the extreme colors.", echo = FALSE, fig.path = IMAGE_PATH}
## Create heatmap
tmp <- log2(assay(
std_res, "normalized_filled_imputed")[rownames(std_res), , drop = FALSE])
tmp <- tmp - rowMeans(tmp, na.rm = TRUE)
rownames(tmp) <- rowData(std_res)$name
colnames(tmp) <- seq_len(ncol(tmp))
ann <- data.frame(matrix = colData(std_res)[, c("source")])
rownames(ann) <- colnames(tmp)
pm <- pheatmap(tmp, annotation_col = ann, labels_col = colnames(tmp),
breaks = seq(-5, 5, length.out = 101),
annotation_color = list(matrix = col_source),
show_colnames = FALSE)
```
```{r, echo = FALSE}
pheatmap(tmp, annotation_col = ann, labels_col = colnames(tmp),
breaks = seq(-5, 5, length.out = 101),
annotation_color = list(matrix = col_source),
show_colnames = FALSE,
filename = paste0(FIG_PATH, "FIG_3_NEG_heatmap_semitargeted.png"),
width = 10, height = 7.5)
```
In the heatmap we see two main cluster, one containing all plasma samples and
the other containing all venous and capillar< blood samples, which indicates
a higher similarity in the intensities of the lab internal standards. The
second cluster is then split up in two subclusters, containing all samples
from each matrix.
FT01310, **Cystine**, shows a high intensity in plasma samples, but has a low
intensity in capillary and venous samples. This was also seen in positive
polarity.
Two features, FT00377 which is **Alanine** and FT04651 which is **CDP** show a
high intensity in plasma an venous samples, but seem to be absent in capillary
blood.
There are 8 metabolites, that have a high intensity in venous and capillary
samples, but very low intensities in plasma samples. Another set of 7
metabolites have higher abundances in capillary samples and lower abundance in
the other matrices.
## Present and absent features
We then wanted to check if there are compounds that are only present in some of
the three matrices. For a metabolite to be *present* we require that a signal
was detected by the MS instrument for that metabolite in a large fraction of
samples of a certain sample matrix. We thus call a metabolite to be present, if
a chromatographic peak was detected in 2/3 or samples per matrix. Therefore, we
use below the `raw` data of our three sample sources (which only contains
intensity values for detected chromatographic peaks) and looked, which compounds
are present in more than 2/3 of the samples.
```{r Present and absent features}
plas <- assay(std_res, "raw")[, std_res$source == "plasma"]
plas_present <- moreAreValidThan(plas, prop = 1/3)
ven <- assay(std_res, "raw")[, std_res$source == "venous"]
ven_present <- moreAreValidThan(ven, prop = 1/3)
cap <- assay(std_res, "raw")[, std_res$source == "capillary"]
cap_present <- moreAreValidThan(cap, prop = 1/3)
```
We then create a plot an `UpSetR` plot to see the overlap of present features:
```{r present-feature-comparison-upset, fig.path = IMAGE_PATH, fig.cap = "Overlap of present features across the 3 sample matrices.", echo = FALSE, eval = TRUE}
library(UpSetR)
listInput <- list(capillary = which(cap_present, useNames = TRUE),
venous = which(ven_present, useNames = TRUE),
plasma = which(plas_present, useNames = TRUE))
upset(fromList(listInput), order.by = "freq")
```
```{r, echo = FALSE}
png(paste0(FIG_PATH, "FIG_4_NEG_upset_semitargeted.png"), width = 7, height = 7,
res = 600, pointsize = 4, units = "cm")
par(mfrow = c(1, 1), mar = c(4.2, 4.5, 1.5, 1), cex.lab = 1.5)
upset(fromList(listInput), keep.order = FALSE,
sets.bar.color = col_source[c("capillary", "venous", "plasma")],
order.by = "freq")
dev.off()
```
The majority of known compounds, 48 features, are present in all three sample
sources, whereas 17 features are only present in capillary and venous blood
samples and 5 features are only present in capillary blood samples. 3 features
are present in plasma and venous blood samples, but absent in capillary blood
samples and two features are only present in plasma samples, and lastly, one
feature is shared between plasma and capillary blood samples but absent in
venous blood.
We want to identify the features present in only some of the matrices, starting
with features that are only present in capillary blood samples:
```{r present-features_cap, echo = FALSE, results = "asis"}
#identify features present in only one or two matrices
only_cap <- rowData(std_res)[cap_present & !ven_present & !plas_present, ]
only_plas <- rowData(std_res)[plas_present & !ven_present & !cap_present, ]
only_ven <- rowData(std_res)[!plas_present & ven_present & !cap_present, ]
only_capven <- rowData(std_res)[cap_present & ven_present & !plas_present, ]
only_venplas <- rowData(std_res)[ven_present & plas_present & !cap_present, ]
only_capplas <- rowData(std_res)[!ven_present & plas_present & cap_present, ]
## Calculate average concentration per matrix
aname <- "normalized_filled_imputed"
std_res_avg = cbind(
capillary = rowMeans(assay(std_res, aname)[, std_res$source == "capillary"],
na.rm = TRUE),
venous = rowMeans(assay(std_res, aname)[, std_res$source == "venous"],
na.rm = TRUE),
plasma = rowMeans(assay(std_res, aname)[, std_res$source == "plasma"],
na.rm = TRUE)
)
## Write result table
tab <- data.frame(name = only_cap[, c("name")],
std_res_avg[rownames(only_cap), ])
pandoc.table(as.data.frame(tab), style = "rmarkdown",
caption = "Features only present in capillary blood samples")
```
Three of those features, **Methioninesulfoxide** , **Phosphorylethanolamine**
and **Carnosine** were also found to be only present in capillary blood samples
in the analysis of positive polarity.
So, we extract the (full) MS1 spectrum at the features' (peaks') apex position
for Methioninesulfoxide:
```{r extraction-MS1-spectrum-Methioninesulfoxide, echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Methioninesulfoxide"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Restrict to files for the present analysis
data <- filterFile(data_neg, match(res_neg$mzML_file, data_neg$mzML_file),
keepFeatures = TRUE)
library(Spectra)
library(MsCoreUtils)
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]
## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]
sp_ven <- ft_sps[pData(data)$source[ft_sps$fromFile] == "venous"][1L]
## Plot labeling peaks with intensity > 2000 with their m/z
label_fun <- function(x) {
ints <- unlist(intensity(x))
mzs <- format(unlist(mz(x)), digits = 4)
mzs[ints < 2000] <- ""
mzs
}
```
```{r MS1-EIC-Methioninesulfoxide, fig.path = IMAGE_PATH, fig.cap = "EIC of Methioninesulfoxide.", echo = FALSE, eval = TRUE}
plot_eic <- function(x) {
col_sample <- col_source[x$source]
col_peak <- col_sample[chromPeaks(x)[, "sample"]]
plot(x, col = paste0(col_sample, 80),
peakBg = paste0(col_peak, 10), peakCol = paste0(col_peak, 40))
legend("topright", col = col_source[c("plasma", "capillary", "venous")],
legend = c("plasma", "capillary", "venous"), pch = 15)
}
plot_eic(ft_chr)
```
```{r MS1-spectrum-Methioninesulfoxide, fig.path = IMAGE_PATH, fig.cap = "MS1 spectra of Methioninesulfoxide in a plasma sample (left), in a capillary blood sample (mid) and in a venous blood sample (right).", echo = FALSE, eval = TRUE}
plot_ms1_single_sample <- function() {
par(mfrow = c(2, 3), mar = c(3.5, 3.5, 1.5, 0.5))
plotSpectra(sp_plas, labels = label_fun, labelPos = 4, labelOffset = 0.2,
labelSrt = 30)
grid()
abline(v = ft_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", "plasma")
plotSpectra(sp_cap, labels = label_fun, labelPos = 4, labelOffset = 0.2,
labelSrt = 30)
grid()
abline(v = ft_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", "capillary")
plotSpectra(sp_ven, labels = label_fun, labelPos = 4, labelOffset = 0.2,
labelSrt = 30)
grid()
abline(v = ft_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", "venous")
## Focus on peak
plotSpectra(sp_plas, labels = label_fun, labelPos = 4, labelOffset = 0.2,
labelSrt = 30, xlim = ft_mz + c(-50, 50))
grid()
abline(v = ft_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", "plasma")
plotSpectra(sp_cap, labels = label_fun, labelPos = 4, labelOffset = 0.2,
labelSrt = 30, xlim = ft_mz + c(-50, 50))
grid()
abline(v = ft_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", "capillary")
plotSpectra(sp_ven, labels = label_fun, labelPos = 4, labelOffset = 0.2,
labelSrt = 30, xlim = ft_mz + c(-50, 50))
grid()
abline(v = ft_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", "venous")
}
plot_ms1_single_sample()
```
At the retention time around 180, where we expect Methioninesulfoxide, only
peaks in the mid spectrum, which derived from the capillary blood samples,
can be observed.
In addition to plotting a representative spectrum for each sample matrix we
aggregate the MS1 spectra per source matrix and compare those.
```{r MS1-spectrum-Methioninesulfoxide-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Methioninesulfoxide in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra <- function(x, target_mz, mzdiff = 3) {
x$source <- droplevels(
factor(pData(data)$source[x$fromFile],
levels = c("plasma", "capillary", "venous")))
## Aggregate spectra keeping only peaks present in 1/3 of samples
ft_sps_agg <- combineSpectra(x, f = x$source, p = x$source,
peaks = "intersect", minProp = 1/3, ppm = 10,
intensityFun = median, mzFun = median)
par(mfrow = c(2, length(ft_sps_agg)), mar = c(3.4, 3.5, 1.5, 0.5))
for (i in seq_along(ft_sps_agg)) {
plotSpectra(ft_sps_agg[i], labels = label_fun, labelPos = 4,
labelOffset = 0.2, labelSrt = 30)
grid()
abline(v = target_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", legend = ft_sps_agg$source[i])
}
ft_sps_agg <- filterMzRange(ft_sps_agg, mz = target_mz + c(-mzdiff, mzdiff))
for (i in seq_along(ft_sps_agg)) {
if (lengths(ft_sps_agg[i]) > 1)
plotSpectra(ft_sps_agg[i], labels = label_fun, labelPos = 4,
labelOffset = 0.2, labelSrt = 30)
else plotSpectra(ft_sps_agg[i])
grid()
abline(v = target_mz, lty = 3, col = "#ff000060", lwd = 2)
legend("topright", legend = ft_sps_agg$source[i])
}
}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz)
```
Again, only in capillary samples a peak with a signal well over the noise level
was identified.
Then, we extract the (full) MS1 spectrum at the features' (peaks') apex position
for Carnosine:
```{r extraction-MS1-spectrum-Carnosine, echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Carnosine"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]
## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]
sp_ven <- ft_sps[pData(data)$source[ft_sps$fromFile] == "venous"][1L]
```
```{r MS1-EIC-Carnosine, fig.path = IMAGE_PATH, fig.cap = "EIC of Carnosine.", echo = FALSE, eval = TRUE}
plot_eic(ft_chr)
```
Chromatographic peaks were detected mostly in capillary samples and also in some
venous samples.
```{r MS1-spectrum-Carnosine, fig.path = IMAGE_PATH, fig.cap = "MS1 spectra of Carnosine in a plasma sample (left), in a capillary blood sample (mid) and in a venous blood sample (right).", echo = FALSE, eval = TRUE}
plot_ms1_single_sample()
```
For Carnosine, we see a low intensity peak in the left spectrum deriving from
a plasma sample and a high intensity peak in the mid spectrum which was
obtained from a capillary blood sample. In the venous blood sample, we can't
observe a peak at rt 190, but right next to that a peak with really high
intensity was detected.
In addition to plotting a representative spectrum for each sample matrix we
aggregate the MS1 spectra per source matrix and compare those.
```{r MS1-spectrum-Carnosine-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Carnosine in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz, mzdiff = 1)
```
The Carnosine peak is right to a very close peak with a higher intensity.
Then, we extract the (full) MS1 spectrum at the features' (peaks') apex position
for Phosphorylethanolamine:
```{r extraction-MS1-spectrum-Phosphorylethanolamine, echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Phosphorylethanolamine"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]
## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]
sp_ven <- ft_sps[pData(data)$source[ft_sps$fromFile] == "venous"][1L]
```
```{r MS1-EIC-Phosphorylethanolamine, fig.path = IMAGE_PATH, fig.cap = "EIC of Phosphorylethanolamine.", echo = FALSE, eval = TRUE}
plot_eic(ft_chr)
```
```{r MS1-spectrum-Phosphorylethanolamine, fig.path = IMAGE_PATH, fig.cap = "MS1 spectra of Phosphorylethanolamine in a plasma sample (left), in a capillary blood sample (mid) and in a venous blood sample (right).", echo = FALSE, eval = TRUE}
plot_ms1_single_sample()
```
The MS1 spectra for Phosphorylethanolamine in plasma (left) and venous blood
(right) samples show no detected peak at a rt around 195, but really high
intensity peaks right next to it. In the sectra obtained from the capillary
blood sample (mid) a peak was detected for Phosphorylethanolamine, and also
a high intensity peak is observed like in the other two sample matrices.
In addition to plotting a representative spectrum for each sample matrix we
aggregate the MS1 spectra per source matrix and compare those.
```{r MS1-spectrum-Phosphorylethanolamine-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Phosphorylethanolamine in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz, mzdiff = 2)
```
A peak is present in all 3 matrices, but the signal in capillary samples is ~ 5
times larger.
Then, we extract the (full) MS1 spectrum at the features' (peaks') apex
position for Glycero-phosphocholine:
```{r extraction-MS1-spectrum-Glycero-phosphocholine, echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Glycero-phosphocholine"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
```
```{r MS1-EIC-Glycero-phosphocholine, fig.path = IMAGE_PATH, fig.cap = "EIC of Glycero-phosphocholine.", echo = FALSE, eval = TRUE}
plot_eic(ft_chr)
```
Only signal in capillary samples was detected.
```{r MS1-spectrum-Glycero-phosphocholine-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Glycero-phosphocholine in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz, mzdiff = 2)
```
In addition we extract also the MS1 spectrum closest to the average retention
time of this feature from all files (including plasma and venous samples).
```{r MS1-spectrum-Glycero-phosphocholine-aggregated-2, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Glycero-phosphocholine in the 3 sample matrices.", echo = FALSE, eval = TRUE}
sps <- Spectra(fileNames(data))
diff_rt <- abs(rtime(sps) - median(rtime(ft_sps)))
diff_rt <- data.frame(index = seq_along(diff_rt), diff = diff_rt,
fromFile = match(sps$dataOrigin, fileNames(data)))
res <- vapply(split(diff_rt, diff_rt$fromFile),
function(x) {
x$index[which.min(x$diff)]
}, integer(1))
sps_all <- sps[res]
sps_all$source <- data$source
sps_all$fromFile <- seq_along(sps_all)
plot_aggregated_spectra(sps_all, target_mz = ft_mz, mzdiff = 1)
```
It looks like the peak in plasma and venous samples is slightly off.
Lastly, we extract the (full) MS1 spectrum at the features' (peaks') apex
position for Adenosine :
```{r extraction-MS1-spectrum-Adenosine , echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Adenosine"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]
## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]
sp_ven <- ft_sps[pData(data)$source[ft_sps$fromFile] == "venous"][1L]
```
```{r MS1-EIC-Adenosine, fig.path = IMAGE_PATH, fig.cap = "EIC of Adenosine.", echo = FALSE, eval = TRUE}
plot_eic(ft_chr)
```
```{r MS1-spectrum-Adenosine , fig.path = IMAGE_PATH, fig.cap = "MS1 spectra of Adenosine in a plasma sample (left), in a capillary blood sample (mid) and in a venous blood sample (right).", echo = FALSE, eval = TRUE}
plot_ms1_single_sample()
```
In all three sample matrices we observe a high intensity peak right next to
the retention time Adenosine is expected at. Adenosine was only found to be
present in capillary blood samples using the MetaboAnnotation package.
In addition to plotting a representative spectrum for each sample matrix we
aggregate the MS1 spectra per source matrix and compare those.
```{r MS1-spectrum-Adenosine-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Adenosine in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz, mzdiff = 2)
```
Then we take a look at the features, which is only present in plasma samples:
```{r present-features_plas, echo = FALSE, results = "asis"}
tab <- data.frame(name = only_plas[, c("name")],
std_res_avg[rownames(only_plas), ])
pandoc.table(as.data.frame(tab), style = "rmarkdown",
caption = "Features only present in plasma samples")
```
**Cystine** was also found to be only present in plasma samples in
positive polarity.
Then, we extract the (full) MS1 spectrum at the features' (peaks') apex position
for Cystine:
```{r extraction-MS1-spectrum-Cystine, echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Cystine"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]
## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]
sp_ven <- ft_sps[pData(data)$source[ft_sps$fromFile] == "venous"][1L]
```
```{r MS1-EIC-Cystine, fig.path = IMAGE_PATH, fig.cap = "EIC of Cystine.", echo = FALSE, eval = TRUE}
plot_eic(ft_chr)
```
```{r MS1-spectrum-Cystine, fig.path = IMAGE_PATH, fig.cap = "MS1 spectra of Cystine in a plasma sample (left), in a capillary blood sample (mid) and in a venous blood sample (right).", echo = FALSE, eval = TRUE}
plot_ms1_single_sample()
```
A peak for Cystine was only detected in the MS1 spectrum on the left side,
which derives from a plasma sample. In venous and capillary blood no peak
was measured at a rt around 209. Also, interestingly, the large number of peaks
in the high m/z range seen in positive polarity is not detected here.
In addition to plotting a representative spectrum for each sample matrix we
aggregate the MS1 spectra per source matrix and compare those.
```{r MS1-spectrum-Cystine-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of Cystine in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz, mzdiff = 2)
```
Then, we extract the (full) MS1 spectrum at the features' (peaks') apex position
for 2-Ketobutyric acid:
```{r extraction-MS1-spectrum-2-Ketobutyric acid, echo = FALSE}
## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "2-Ketobutyric acid"]
ft_mz <- rowData(std_res)[ft, "mzmed"]
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
features = ft, method = "closest_rt",
skipFilled = FALSE)
## Extract also the EIC
ft_chr <- featureChromatograms(data, expandRt = 5, features = ft)
## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]
## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]
sp_ven <- ft_sps[pData(data)$source[ft_sps$fromFile] == "venous"][1L]
```
```{r MS1-EIC-2-Ketobutyric acid, fig.path = IMAGE_PATH, fig.cap = "EIC of 2-Ketobutyric acid.", echo = FALSE, eval = TRUE}
plot_eic(ft_chr)
```
```{r MS1-spectrum-2-Ketobutyric acid, fig.path = IMAGE_PATH, fig.cap = "MS1 spectra of 2-Ketobutyric acid in a plasma sample (left), in a capillary blood sample (mid) and in a venous blood sample (right).", echo = FALSE, eval = TRUE}
plot_ms1_single_sample()
```
2-Ketobutyric acid was detected as only "present" in plasma when using the
MetaboAnnotation package. In plasma and capillary blood samples, peaks with
high intensity are detected next to the rt of 2-Ketobutyric acid.
In addition to plotting a representative spectrum for each sample matrix we
aggregate the MS1 spectra per source matrix and compare those.
```{r MS1-spectrum-2-Ketobutyric acid-aggregated, fig.path = IMAGE_PATH, fig.cap = "Aggregated MS1 spectra of 2-Ketobutyric acid in the 3 sample matrices.", echo = FALSE, eval = TRUE}
plot_aggregated_spectra(ft_sps, target_mz = ft_mz, mzdiff = 2)
```
Next, we want to identify the features that are present in capillary and venous
blood samples, but absent in plasma samples:
```{r present-features_cap_ven, echo = FALSE, results = "asis"}
tab <- data.frame(name = only_capven[, c("name")],
std_res_avg[rownames(only_capven), ])
pandoc.table(as.data.frame(tab), style = "rmarkdown",
caption = "Features only present in capillary and venous blood
samples")
```
**SAH**, **AMP** and **L-Aspartic Acid** showed the same result in positive
polarity.
Next, we take a look at the features found in plasma and venous blood
samples, but not in capillary blood: