RGLab / openCyto

A package that provides data analysis pipeline for flow cytometry.
GNU Affero General Public License v3.0
75 stars 29 forks source link

pivot option to gate_mindensity and gate_mindensity2 is not honored #207

Closed jacobpwagner closed 3 years ago

jacobpwagner commented 4 years ago

In constraining the search for the gate boundary returned from gate_mindensity or gate_mindensity2, the min, max, and gate_range args work as expected. However, the pivot option does not. According to the docs:

"pivot | logical value. If TRUE, we choose as the two peaks the largest peak and its neighboring peak. See details."

(details from mindensity): "In the default case, the two peaks of interest are the two largest peaks obtained from the density function. However, if pivot is TRUE, we choose the largest peak and its neighboring peak as the two peaks of interest. In this case, the neighboring peak is the peak immediately to the left of the largest peak if positive is TRUE. Otherwise, the neighboring peak is selected as the peak to the right"

However, this does not seem to work at all and a quick glance at the source suggests that the option is never utilized. Demonstration:

library(flowCore)
library(flowWorkspace)
library(openCyto)
library(ggcyto)
gs <- load_gs(system.file("extdata", "gs_bcell_auto", package="flowWorkspaceData"))
fr <- gh_pop_get_data(gs[[1]])
autoplot(fr, getChannelMarker(fr, "CD38")$desc)

image

Here, I think it's just finding the global minimum:

gate <- gate_mindensity2(fr,
                         channel="CD38",
                         filterID="nonDebris",
                         pivot=TRUE,
                         plot=TRUE
)
gate
Rectangular gate '' with dimensions:
  CD38: (-335.765135027374,Inf)

image

The same call with pivot=FALSE results in the exact same result. Of course, using gate_range or min/max, we can get the desired boundary.

gate <- gate_mindensity2(fr,
                         channel="CD38",
                         filterID="nonDebris",
                         pivot=FALSE,
                         gate_range = c(800,3000),
                         plot=TRUE
)
gate
Rectangular gate '' with dimensions:
  CD38: (1497.26841196133,Inf)

image

I'm not sure if the option was just never implemented, but we should probably either implement it fully (it would be kind of handy in automated pipelines) or remove it from the args and docs.

gfinak commented 3 years ago

@jacobpwagner is this still an open issue? Just going through old stuff to see where to focus.

jacobpwagner commented 3 years ago

Yeah, I believe it is still open. It's probably a pretty quick fix, though. It must have just slipped through the cracks.

Pandapip1 commented 3 years ago

Here, I think it's just finding the global minimum:

This is still not fixed. It seems to still be gating around the global min, even on the latest github version: image

jacobpwagner commented 3 years ago

@Pandapip1 , rather than being fully implemented, the option was simply removed in 956808f71b5befa23688552351e2b25b091e7c82, so I think this is expected behavior.