RGLab / openCyto

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

flowDensity wrapper error #215

Closed alexheubeck closed 4 years ago

alexheubeck commented 4 years ago

Hey @mikejiang and @jacobpwagner,

I'm attempting to use flowDensity to gate a highly variable Treg population, but I'm getting an add_pop error. I adapted your comments from Issue #104, here's what I tried so far.

flowDensity Wrapper:

.flowDensity <- function(fr, pp_res, channels = NA, ...){

  if(length(channels)==2)
    flowDensity:::.flowDensity.2d(fr, channels = channels, ...)
  else
    flowDensity:::.flowDensity.1d(fr, channel = channels, ...)

}

Gating Template Line:

alias pop parent dims gating_method gating_args collapseDataForGating groupBy preprocessing_method preprocessing_args
Treg + CD8-CD4+ CD127,CD25 flowDensity position=c(FALSE,TRUE)        

When I try gating with this gating template, this is the error I get back:

Gating for 'Treg'
Running in parallel mode with 8 cores.
Error in UseMethod("pop_add") : 
  no applicable method for 'pop_add' applied to an object of class "try-error"

Please let me know if you have any ideas, thanks!

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gridExtra_2.3             colorRamps_2.3            scales_1.1.1             
 [4] cytolib_2.1.7             CytoML_2.1.6              data.table_1.12.8        
 [7] flowDensity_1.22.0        ggcyto_1.17.0             ggplot2_3.3.2            
[10] ncdfFlow_2.35.1           BH_1.72.0-3               RcppArmadillo_0.9.900.2.0
[13] flowCore_2.1.0            flowWorkspace_4.1.4       openCyto_2.1.0           
jacobpwagner commented 4 years ago

Hey @alexheubeck , taking a look at this now. Can you give me the full traceback on top of final error?

jacobpwagner commented 4 years ago

I don't have your data so it's hard to infer what might be going wrong because of how general your error is. But this seems to work with flowWorkspace test data in my hands:

library(flowWorkspace)
library(openCyto)
library(flowDensity)

.flowDensity <- function(fr, pp_res, channels = NA, ...){

  if(length(channels)==2)
    flowDensity:::.flowDensity.2d(fr, channels = channels, ...)
  else
    flowDensity:::.flowDensity.1d(fr, channel = channels, ...)

}

register_plugins(fun = .flowDensity, methodName = "flowDensity", dep = "flowDensity", "gating")

gs <- load_gs(system.file("extdata", "gs_manual", package = "flowWorkspaceData"))

gs_add_gating_method(gs, 
                     alias = "flowDensity_pop",
                     pop = "+",
                     parent = "not debris",
                     dims = "CD4,CD8",
                     gating_method = "flowDensity",
                     gating_args = "position=c(FALSE,TRUE)")
jacobpwagner commented 4 years ago

I used gs_add_gating_method as a shortcut there, but I can also confirm that it works when pulled from a template csv. Attached as a txt because apparently GitHub doesn't like csv attachments:

library(flowWorkspace)
library(openCyto)
library(flowDensity)

.flowDensity <- function(fr, pp_res, channels = NA, ...){

  if(length(channels)==2)
    flowDensity:::.flowDensity.2d(fr, channels = channels, ...)
  else
    flowDensity:::.flowDensity.1d(fr, channel = channels, ...)

}

register_plugins(fun = .flowDensity, methodName = "flowDensity", dep = "flowDensity", "gating")
gs <- load_gs(system.file("extdata", "gs_manual", package = "flowWorkspaceData"))
gt <- gatingTemplate("template.csv")
gt_gating(gt, gs)

template.txt

alexheubeck commented 4 years ago

Oh shoot, I didn't have this line set correctly:

register_plugins(fun = .flowDensity, methodName = "flowDensity", dep = "flowDensity", "gating")

It's working now, thanks for your help!

jacobpwagner commented 4 years ago

Good to hear. I'm going to go ahead close this then but let me know if anything else comes up.