Repository navigation
Expand file tree
/
Copy path00_run_all.R
More file actions
82 lines (71 loc) · 2.88 KB
/
Copy path00_run_all.R
File metadata and controls
82 lines (71 loc) · 2.88 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Run scripts 01-05 in order, with checks and logging
# Set DATA_DIR to the folder holding the scripts and the data files before sourcing,
# or run from inside that folder.
if (!exists("DATA_DIR")) DATA_DIR <- "."
setwd(DATA_DIR)
needed <- c("tidyverse", "lme4", "lmerTest", "emmeans", "readxl")
missing <- needed[!sapply(needed, requireNamespace, quietly = TRUE)]
if (length(missing)) {
message("Installing: ", paste(missing, collapse = ", "))
install.packages(missing, repos = "https://cloud.r-project.org")
}
invisible(lapply(needed, \(p) suppressMessages(library(p, character.only = TRUE))))
inputs <- c(
"MASTER_kinetic_annotated.csv",
"MASTER_static_annotated.csv",
"MASTER_timeseries_annotated.csv",
"SC_RI_flow_cytometry_master.xlsx"
)
scripts <- c(
"01_design_and_identifiability.R",
"02_endpoint_OD.R",
"03_PvsC_paired.R",
"04_batch_effects.R",
"05_CoV_reproducibility.R"
)
missing_files <- c(inputs, scripts)[!file.exists(c(inputs, scripts))]
if (length(missing_files)) {
stop("Missing from ", DATA_DIR, ":\n - ",
paste(missing_files, collapse = "\n - "),
"\n\n(If a data file has a numeric prefix on it, strip the prefix.)")
}
cat("All", length(inputs), "data files and", length(scripts), "scripts found.\n\n")
log_file <- file.path(DATA_DIR, "analysis_log.txt")
con <- file(log_file, open = "wt")
sink(con, split = TRUE)
sink(con, type = "message")
cat("SHAKING REGIME ANALYSIS —", format(Sys.time()), "\n")
cat(R.version.string, "\n")
cat(strrep("=", 75), "\n")
results <- data.frame()
for (s in scripts) {
cat("\n\n", strrep("#", 75), "\n### RUNNING: ", s, "\n", strrep("#", 75), "\n", sep = "")
t0 <- Sys.time()
ok <- tryCatch({
env <- new.env(parent = globalenv())
source(s, local = env, echo = FALSE)
TRUE
}, error = function(e) {
cat("\n*** FAILED:", conditionMessage(e), "\n")
FALSE
})
results <- rbind(results, data.frame(
script = s, status = ifelse(ok, "OK", "FAILED"),
seconds = round(as.numeric(difftime(Sys.time(), t0, units = "secs")), 1)))
if (!ok) break
}
cat("\n\n", strrep("=", 75), "\nSUMMARY\n", strrep("=", 75), "\n", sep = "")
print(results, row.names = FALSE)
if (all(results$status == "OK")) {
cat("\nAll scripts completed. Result files written to:\n ", DATA_DIR, "\n")
cat("\nKey outputs to look at, in this order:\n")
cat(" 01_PvsC_route_comparison.csv <- why P-vs-C is not identifiable\n")
cat(" 02_endpoint_stats.csv <- Fig 4 stats (the solid contrasts)\n")
cat(" 03_FC_tests.csv <- Fig 5 flow cytometry (SC 1.25x, RI null)\n")
cat(" 04_batch_effects.csv <- Fig 3A (why P-vs-C had to go)\n")
cat(" 05_CoV_tests.csv <- Fig 3B: Pulsed 6/6 more reproducible\n")
} else {
cat("\nSTOPPED at the first failure. Fix it and re-run; nothing downstream ran.\n")
}
cat("\nFull transcript: ", log_file, "\n", sep = "")
sink(type = "message"); sink(); close(con)