-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcombin_presto_function.R
More file actions
46 lines (44 loc) · 1.13 KB
/
combin_presto_function.R
File metadata and controls
46 lines (44 loc) · 1.13 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
suppressPackageStartupMessages({
library(qs)
library(Seurat)
library(presto)
library(msigdbr)
library(fgsea)
library(dplyr)
library(ggplot2)
library(tidyverse)
library(scran)
library(here)
library(tictoc)
})
combin_presto <- function(sc_obj) {
if ("curated_clusters" %in% names(sc_obj@meta.data) == FALSE)
{sc_obj$curated_clusters <- sc_obj$RNA_snn_res.0.5
curated_clusters <- sc_obj@meta.data$curated_clusters}
else
{curated_clusters <- sc_obj@meta.data$curated_clusters
}
combinations <-
combn(unique(curated_clusters),
m = 2,
simplify = F)
{
tic()
paired_results <- lapply(combinations, function(clus_comb) {
wilcoxauc(
sc_obj,
"curated_clusters",
groups_use = clus_comb,
assay = "data"
) %>%
mutate(groupA = clus_comb[1]) %>%
mutate(groupB = clus_comb[2]) %>%
mutate(pairs = paste0("Cl_", clus_comb[2], "vs", clus_comb[1])) %>%
subset(group == groupB) # Removing the doubled results of "A vs B" and "B vs A"
})
# Order of Cl_clus_comb[2] vs clus_comb[1] is
# validated by checking the expected expression comparisons for clusters
toc()
return(paired_results)
}
}