-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathmetamorpheus_Process.R
More file actions
47 lines (40 loc) · 1.25 KB
/
metamorpheus_Process.R
File metadata and controls
47 lines (40 loc) · 1.25 KB
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
calculate_Metrics <- function(QuantData, protein_mappings, task_label, alpha = 0.05) {
comparison <- matrix(
c(-1,0,0,0,1, # E-A
-1,0,0,1,0, # D-A
-1,0,1,0,0, # C-A
-1,1,0,0,0), # B-A
nrow = 4, byrow = TRUE
)
rownames(comparison) <- c("E-A", "D-A", "C-A", "B-A")
groups <- levels(QuantData$ProteinLevelData$GROUP)
colnames(comparison) <- groups[order(as.numeric(groups))]
model <- groupComparison(
contrast.matrix = comparison,
data = QuantData,
use_log_file = FALSE
)
ecoli_ids <- protein_mappings %>%
filter(Organism == "Escherichia coli (strain K12)") %>%
pull(`Protein Groups`)
comp <- model$ComparisonResult %>%
mutate(ecoli = Protein %in% ecoli_ids) %>%
filter(is.na(issue))
labels <- unique(comp$Label)
result_rows <- lapply(labels, function(lbl) {
df <- comp %>% filter(Label == lbl)
sig <- df %>% filter(adj.pvalue < alpha)
tp <- sig %>% filter(ecoli) %>% nrow()
fp <- sig %>% filter(!ecoli) %>% nrow()
tot <- tp + fp
fdr <- if (tot > 0) fp / tot else NA_real_
data.frame(
Task = task_label,
Comparison = lbl,
FDR = fdr,
stringsAsFactors = FALSE
)
})
results <- do.call(rbind, result_rows)
return(results)
}