Skip to content

Commit b9241c1

Browse files
committed
1 parent ea1f7ea commit b9241c1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

audit.R

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'audit
44
55
Usage:
6-
audit.R -b <id> -m <id> -o <file> [-a <int>] [-l <file>] [-s <query>] [-p <var>] [-f <str>] [-r <op>] [-t <dir>]
6+
audit.R -b <id> -m <id> -o <file> [-a <int>] [-l <file>] [-s <query>] [-p <var>] [-f <str>] [-r <op>] [-t <dir>] [-q <var>]
77
88
Options:
99
-h --help Show this screen.
@@ -16,7 +16,8 @@ Options:
1616
-f <str> --suffix=<str> Suffix to append to barcode to select a profile file [default: _normalized_variable_selected.csv].
1717
-p <var> --group_by=<var> Group by column [default: Metadata_Well].
1818
-r <op> --operation=<op> Audit operation [default: replicate_quality].
19-
-t <dir> --tmpdir=<dir> Temporary directory [default: /tmp]. ' -> doc
19+
-t <dir> --tmpdir=<dir> Temporary directory [default: /tmp].
20+
-q <var> --null_quantile=<var> Quantile of null distribution to extract [default: 0.95]' -> doc
2021

2122
suppressWarnings(suppressMessages(library(docopt)))
2223

@@ -46,6 +47,8 @@ group_by <- stringr::str_split(opts[["group_by"]], ",")[[1]]
4647

4748
operation <- opts[["operation"]]
4849

50+
null_quantile <- as.numeric(paste(opts[["null_quantile"]]))
51+
4952
backend_dir <- paste("../..", "backend", batch_id, sep = "/")
5053

5154
metadata_dir <- paste("../..", "metadata", batch_id, sep = "/")
@@ -56,15 +59,15 @@ filelist <- barcode_platemap %>%
5659
filter(Plate_Map_Name == plate_map_name) %>%
5760
mutate(filename = normalizePath(paste0(backend_dir, "/", Assay_Plate_Barcode, "/", Assay_Plate_Barcode, suffix)))
5861

59-
df <- filelist$filename %>%
62+
df <- filelist$filename %>%
6063
map_df(
6164
function(filename) {
6265
if (file.exists(filename)) {
6366
suppressMessages(readr::read_csv(filename))
64-
67+
6568
} else {
6669
tibble::data_frame()
67-
70+
6871
}
6972
}
7073
)
@@ -101,22 +104,23 @@ set.seed(24)
101104
correlations <- df %>%
102105
median_pairwise_correlation(variables, group_by)
103106

104-
null_threshold <-
105-
1:iterations %>%
107+
null_threshold <-
108+
1:iterations %>%
106109
map_df(function(i) {
107110
df %>%
108111
tidyr::unite_("group_by", group_by) %>%
109112
mutate(group_by = sample(group_by)) %>%
110113
median_pairwise_correlation(variables, "group_by")
111114
}) %>%
112115
magrittr::extract2("correlation") %>%
113-
quantile(0.95, na.rm = TRUE)
116+
quantile(null_quantile, na.rm = TRUE)
114117

115118
result <-
116119
tibble::data_frame(
117120
plate_map_name = plate_map_name,
118121
null_threshold = null_threshold,
119-
fraction_strong = (sum(correlations$correlation > null_threshold) / nrow(correlations))
122+
fraction_strong = (sum(correlations$correlation > null_threshold) / nrow(correlations)),
123+
null_quantile = null_quantile
120124
)
121125

122126
knitr::kable(result)

0 commit comments

Comments
 (0)