I'm trying to incorporate tmixFilter into a flowCore/flowWorkspace-based FACS data analysis. The primary problem I'm having is that I need to select multiple clusters the tmixFilter results and I can't find any examples a "flowCore"-y way of doing that.
Below is what I have been doing, but it's a complicated workflow that doesn't fit in well with the flowCore-family of workflows. For example, I'd like to incorporate this gating into a GatingWorkflow and be able to use the various plotting functions to visualize gating and backgating.
# 'fs' is a flowSet object
ssca_fsca_tmix <- flowCore::filter(fs, tmixFilter('SSCA_FSCA', c("FSC-A","SSC-A"), K=6, level=0.95))
# now I need to figure out which of the 6 clusters per flowFrame are the ones I need
# there are usually two
FSC_A.bounds <- c(70000,170000)
SSC_A.bounds <- c(10000,50000)
tmix_gate_summary <- tibble(i=seq_along(ssca_fsca_tmix)) %>%
# pull out the raw FSC-A and SSC-A data and combine it with the tmixFilter cluster assignment
mutate(raw.data = map(i, ~tibble(
`FSC-A`=fs[[.x]]@exprs[,"FSC-A"],
`SSC-A`=fs[[.x]]@exprs[,"SSC-A"],
cluster=ssca_fsca_tmix@.Data[[.x]]@subSet
))) %>%
# calculate median FSC-A and SSC-A values for each tmixFilter cluster
mutate(summary.data = map(raw.data, function(x){
x %>% dplyr::filter(!is.na(cluster)) %>%
group_by(cluster) %>%
summarize(`FSC-A`=median(`FSC-A`),`SSC-A`=median(`SSC-A`))
})) %>%
# identify the clusters with medians in the desired ranges
mutate(selected.clusters = map(summary.data, function(x){
x %>% dplyr::filter(
between(`FSC-A`, FSC_A.bounds[1], FSC_A.bounds[2]),
between(`SSC-A`, SSC_A.bounds[1], SSC_A.bounds[2])
) %>% pull(cluster)
}))
# use flowClust::split to pull out the desired clusters from each flowFrame
flowFrames <- lapply(seq_along(fs), function(j) {
cluster_numbers <- tmix_gate_summary %>%
dplyr::filter(i == j) %>%
pull(selected.clusters) %>%
unlist
split(fs[[j]], ssca_fsca_tmix[[j]], population=list(my_filter=cluster_numbers))
})
# combine these back into a new flowSet
fs_gated <- flowSet(lapply(flowFrames, function(x) x$my_filter ))
As an alternate workflow, I did come across cytoUtils::tmix2DGate. I can get the clusters out of that, and pull them out at as ellipse gates, but I can't figure out how to create gates which are the union of these multiple ellipse gates per flowFrame.
Thanks, Mike.
For a
tmixFilter
which returns multiple clusters, is there a way to turn an individual cluster (let's say cluster 4 out of k=6 clusters) as a gate? In the vignettes, I'm seeing gates accessed as "myGate+" or "myGate-", I haven't come across example code for something like "myGate #4".