Skip to content

Instantly share code, notes, and snippets.

@soh-i
Created February 24, 2022 02:50
Show Gist options
  • Save soh-i/49ba052d78c3adfc4e44312c2dc692e5 to your computer and use it in GitHub Desktop.
Save soh-i/49ba052d78c3adfc4e44312c2dc692e5 to your computer and use it in GitHub Desktop.
Generate dynamic rectangleGate object with flowCore and flowWorkspace
compute_dynamic_gate <- function(gs, inv.bins) {
df.stat <- data.frame()
for (min.cutoff in inv.bins) {
# Create dynamic FL1-A gate
rg_gfp <- flowCore::rectangleGate(
"FL1-A" = c(min.cutoff, Inf), "FSC-A" = c(-Inf, Inf),
filterId = "_dynamic"
)
gates <- flowWorkspace::gs_get_pop_paths(gs)
if ("/P1/_dynamic" %in% gates) {
flowWorkspace::gs_pop_remove("_dynamic", gs = gs)
flowWorkspace::gs_pop_add(gs, rg_gfp, parent = "P1")
flowWorkspace::recompute(gs)
} else {
flowWorkspace::gs_pop_add(gs, rg_gfp, parent = "P1")
flowWorkspace::recompute(gs)
}
stat <- flowWorkspace::gs_pop_get_stats(gs, "_dynamic", type = "percent") %>%
dplyr::mutate(percent, cutoff = inv.log.trans(min.cutoff))
df.stat <- rbind(df.stat, stat)
}
return(df.stat)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment