forked from wkumler/FalkorTargets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
figs_for_Laura.R
81 lines (74 loc) · 2.73 KB
/
figs_for_Laura.R
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
library(tidyverse)
library(data.table)
pmppm <- function(mass, ppm=4){
if(mass<200){
as.numeric(mass)+(c(-ppm, ppm)*200/1000000)
} else {
c(mass*(1-ppm/1000000), mass*(1+ppm/1000000))
}
}
all_stans <- read.csv("falkor_stans.csv") %>%
filter(polarity=="pos") %>% filter(!is.na(mix)) %>%
arrange(as.numeric(mz), as.numeric(rt)) %>%
mutate(mz=as.numeric(mz))
stan_MS1_data <- readRDS("stan_data.rds")
addiso_peaks <- read.csv("addiso_peaks.csv")
real_peaks <- read.csv("real_peaks.csv")
all_peaks <- real_peaks %>%
select(feature, mz, rt, into, file_name, M_area) %>%
rbind(addiso_peaks %>% select(feature, mz, rt, into, file_name, M_area)) %>%
arrange("feature", "file_name")
all_features <- all_peaks %>%
group_by(feature) %>%
summarise(mzmed=median(mz), rtmed=median(rt), avgarea=mean(M_area))
stan_annotations <- read.csv("stan_assignments.csv")
# Proline betaine peak
mz_i <- all_stans$mz[all_stans$compound_name=="Proline betaine"]
eic <- stan_MS1_data[mz%between%pmppm(mz_i)]
eic_zeroed <- split(eic, eic$fileid) %>%
lapply(function(x){
rbind(
data.frame(rt=min(x$rt), mz=median(x$mz), int=0, fileid=unique(x$fileid)),
x,
data.frame(rt=max(x$rt), mz=median(x$mz), int=0, fileid=unique(x$fileid))
)
}) %>%
do.call(what = rbind) %>%
mutate(fillcol=str_extract(fileid, "Blk|Smp|Std")) %>%
filter(fillcol=="Std") %>%
mutate(stdtype=str_extract(fileid, "Mix[1|2]|H2O"))
gp <- ggplot() +
geom_polygon(data = eic_zeroed, aes(x=rt, y=int, fill=stdtype)) +
geom_line(data = eic_zeroed, aes(x=rt, y=int, group=stdtype)) +
scale_y_continuous(oob = scales::rescale_none, limits = c(0, max(eic_zeroed$int)/5)) +
facet_wrap(~fileid) +
scale_fill_viridis_d(alpha = 0.7, option = "C") +
xlim(c(200, 700)) +
theme_bw() +
ggtitle("Proline betaine")
print(gp)
# Acetylcholine/TMAP
mz_i <- all_stans$mz[all_stans$compound_name=="Acetylcholine"]
eic <- stan_MS1_data[mz%between%pmppm(mz_i)]
eic_zeroed <- split(eic, eic$fileid) %>%
lapply(function(x){
rbind(
data.frame(rt=min(x$rt), mz=median(x$mz), int=0, fileid=unique(x$fileid)),
x,
data.frame(rt=max(x$rt), mz=median(x$mz), int=0, fileid=unique(x$fileid))
)
}) %>%
do.call(what = rbind) %>%
mutate(fillcol=str_extract(fileid, "Blk|Smp|Std")) %>%
filter(fillcol=="Std") %>%
mutate(stdtype=str_extract(fileid, "Mix[1|2]|H2O"))
gp <- ggplot() +
geom_polygon(data = eic_zeroed, aes(x=rt, y=int, fill=stdtype)) +
geom_line(data = eic_zeroed, aes(x=rt, y=int, group=stdtype)) +
scale_y_continuous(oob = scales::rescale_none, limits = c(0, max(eic_zeroed$int)/5)) +
facet_wrap(~fileid) +
scale_fill_viridis_d(alpha = 0.7, option = "C") +
xlim(c(400, 600)) +
theme_bw() +
ggtitle("Acetylcholine/3-carboxy")
print(gp)