-
Notifications
You must be signed in to change notification settings - Fork 15
/
run_FlowSOM_pre_stability.R
executable file
·77 lines (59 loc) · 2.08 KB
/
run_FlowSOM_pre_stability.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
#########################################################################################
# Stability analysis:
# Function to run and evaluate FlowSOM_pre once for each data set
#
# Lukas Weber, September 2016
#########################################################################################
run_FlowSOM_pre_stability <- function(data) {
# parameters
# grid sizes
grid_size <- list(
Levine_32dim = 10,
Mosmann_rare = 20
)
# extract true population labels
clus_truth <- vector("list", length(data))
names(clus_truth) <- names(data)
for (i in 1:length(clus_truth)) {
clus_truth[[i]] <- data[[i]][, "label"]
}
# subset data: protein marker columns only
marker_cols <- list(
Levine_32dim = 5:36,
Mosmann_rare = c(7:9, 11:21)
)
for (i in 1:length(data)) {
data[[i]] <- data[[i]][, marker_cols[[i]]]
}
# run once for each data set
# note: don't set any random seeds, since we want a different random seed each time
out <- vector("list", length(data))
names(out) <- names(data)
for (i in 1:length(out)) {
data_i <- flowCore::flowFrame(data[[i]]) ## input data must be flowFrame
fSOM <- FlowSOM::ReadInput(data_i, transform = FALSE, scale = FALSE)
fSOM <- FlowSOM::BuildSOM(fSOM,
colsToUse = NULL, ## use all columns since already subsetted
xdim = grid_size[[i]],
ydim = grid_size[[i]])
#fSOM <- FlowSOM::BuildMST(fSOM) ## not required
out[[i]] <- fSOM
}
# extract cluster labels
clus <- vector("list", length(data))
names(clus) <- names(data)
for (i in 1:length(clus)) {
clus[[i]] <- out[[i]]$map$mapping[, 1]
}
# calculate mean F1 scores / F1 scores
res <- vector("list", length(clus))
names(res) <- names(clus)
for (i in 1:length(clus)) {
if (!is_rare[i]) {
res[[i]] <- helper_match_evaluate_multiple(clus[[i]], clus_truth[[i]])
} else if (is_rare[i]) {
res[[i]] <- helper_match_evaluate_single(clus[[i]], clus_truth[[i]])
}
}
return(res)
}