-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.R
More file actions
58 lines (43 loc) · 1.38 KB
/
main.R
File metadata and controls
58 lines (43 loc) · 1.38 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
48
49
50
51
52
53
54
55
56
57
58
suppressPackageStartupMessages({
library(tercen)
library(dplyr, warn.conflicts = FALSE)
library(tidyr)
library(flowCore)
})
source("./utils.R")
ctx = tercenCtx()
data <- ctx$as.matrix()
channels <- ctx$cselect() %>%
tidyr::unite(col = "new_name", sep = "_")
colnames(data) <- channels[["new_name"]]
annotation <- ctx$select(c(".ri", ctx$colors, ctx$labels)) %>%
distinct() %>%
mutate_at(unlist(ctx$labels), ~as.numeric(as.factor(.)))
data <- data %>%
as_tibble() %>%
mutate(.ri = 1:nrow(.) - 1L) %>%
left_join(annotation, by = ".ri")
grouping_factor <- unlist(ctx$colors)
if(is.null(grouping_factor)) {
grouping_factor <- "File"
data <- data %>% mutate(File = "File")
}
data <- data %>%
group_by(across(contains(grouping_factor)))
flow.frames <- data %>%
group_map(~matrix_to_flowFrame(as.matrix(.x)))
names(flow.frames) <- group_keys(data) %>%
tidyr::unite(col = "File", everything(), sep = " - ") %>%
unlist()
flow.set <- flow.frames %>%
flowCore::flowSet()
tmpdir <- paste0(tempdir(), "/fcs")
files <- write.flowSet(flow.set, outdir = tmpdir)
zipfile <- paste0(tmpdir, "/Tercen_FCS_Export.zip")
zip(zipfile = zipfile, files = files)
on.exit(unlink(c(zipfile, files)))
file_to_tercen(file_path = zipfile, filename = "Tercen_FCS_Export.zip") %>%
ctx$addNamespace() %>%
as_relation() %>%
as_join_operator(list(), list()) %>%
save_relation(ctx)