-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccoverlap.R
61 lines (53 loc) · 2.55 KB
/
ccoverlap.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
#' @export
#Overlaps between condition markers and cluster markers - NOT intracluster
CCOverlap <- function(seuratObj, clusterMarkers, selectionMarkers, RownamesCML, typeNames, nItems, isLog = T){
clusters <- c()
pvalues <- c()
selections <- c()
nGenes <- length(rownames(seuratObj))
for (i in 1:length(levels(seuratObj$seurat_clusters)))
{
message(str_c("Calculating overlaps with cluster ", i - 1, "."))
for (j in 1:length(RownamesCML)){
message(str_c("Calculating overlaps with condition ", RownamesCML[j], "."))
clusters <- c(clusters, typeNames[i])
selections <- c(selections, RownamesCML[j])
pvalues <- c(pvalues, TwoLogs(clusterMarkers[[i]], selectionMarkers[[j]], nItems, isLog))
}
}
df <- data.frame(Cluster = clusters, Grouping = selections, pvalue = pvalues)
return(BYCorrectDF(df))
}
CCPathwaysOverlap <- function(seuratObj, clusterDescriptions, selectionDescriptions, RownamesCML, typeNames, nItems)
return(CCOverlap(seuratObj, clusterDescriptions, selectionDescriptions, RownamesCML, typeNames, nItems, isLog = F))
#Three way overlaps
ThreeWayCCOverlap <- function(thirdSet, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N, ThreeFun){
clusters <- c()
pvalues <- c()
selections <- c()
for (i in 1:length(clusterMarkers))
{
message(str_c("Calculating overlaps with cluster ", i - 1, "."))
for (j in 1:length(RownamesCML)){
message(str_c("Calculating overlaps with condition ", RownamesCML[j], "."))
clusters <- c(clusters, typeNames[i])
selections <- c(selections, RownamesCML[j])
pvalues <- c(pvalues, ThreeFun(thirdSet, clusterMarkers[[i]], selectionMarkers[[j]], N))
}
}
df <- data.frame(Cluster = clusters, Grouping = selections, pvalue = pvalues)
return(BYCorrectDF(df))
}
LitCCOverlap <- function(thirdSet, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N)
return(ThreeWayCCOverlap(thirdSet, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N, OneLitTwoLogs))
LogCCOverlap <- function(thirdSet, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N)
return(ThreeWayCCOverlap(thirdSet, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N, ThreeLogs))
AllLitCCOverlap <- function(allLit, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N){
return(lapply(allLit, function(x) LitCCOverlap(x, clusterMarkers, selectionMarkers, RownamesCML, typeNames, N)))
}
PrintAllLitCCOverlap <- function(CC, LitNames){
invisible(lapply(1:length(LitNames), function(x){
print(LitNames[x])
PrintOverlapCC(CC[[x]])
}))
}