-
Notifications
You must be signed in to change notification settings - Fork 1
/
select.R
executable file
·64 lines (41 loc) · 1.6 KB
/
select.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
#!/usr/bin/env Rscript
'select
Usage:
select.R -b <id> -p <id> -r <list>
Options:
-h --help Show this screen.
-b <id> --batch_id=<id> Batch ID
-p <id> --plate_id=<id> Plate ID
-r <list> --filters=<list> Comma-separated list of filters' -> doc
suppressWarnings(suppressMessages(library(docopt)))
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(magrittr)))
opts <- docopt(doc)
batch_id <- opts[["batch_id"]]
plate_id <- opts[["plate_id"]]
filters <- opts[["filters"]]
filters <- stringr::str_split(filters, ",")[[1]]
# read features
variables_selected <-
lapply(filters,
function (filt) {
suppressMessages(readr::read_tsv(paste0("../../parameters/", batch_id, "/variable_selection/", filt, ".txt" )))
}) %>%
Reduce(function(df1, df2) dplyr::inner_join(df1, df2, by ="variable"), .) %>%
magrittr::extract2("variable")
backend_dir <- paste("../..", "backend", batch_id, plate_id, sep = "/")
profiles <- paste(backend_dir, paste0(plate_id, "_normalized.csv"), sep = "/")
profiles_variable_selected <- paste(backend_dir, paste0(plate_id, "_normalized_variable_selected.csv"), sep = "/")
df <- suppressMessages(readr::read_csv(profiles))
variables <-
colnames(df) %>%
stringr::str_subset("^Nuclei_|^Cells_|^Cytoplasm_")
metadata <-
colnames(df) %>%
stringr::str_subset("^Metadata_")
variables <- intersect(variables, variables_selected)
testthat::expect_gt(length(variables), 0)
df %<>%
select_(.dots = c(metadata, variables))
df %>%
readr::write_csv(profiles_variable_selected)