Created
February 24, 2022 02:50
-
-
Save soh-i/49ba052d78c3adfc4e44312c2dc692e5 to your computer and use it in GitHub Desktop.
Generate dynamic rectangleGate object with flowCore and flowWorkspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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