Skip to content

Custom transform doesn't invert with ggcyto::axis_x_inverse_trans() #396

@hrj21

Description

@hrj21

Hello!

I think this is probably my misunderstanding rather than a bug, but while I can successfully define a new transform that can be applied to a gatingSet, I cannot get ggcyto::axis_x_inverse_trans() to invert it (I think the issue is probably with how I have defined the transform rather than anything to do with ggcyto). Below is a reprex

# Load packages -----------------------------------------------------------
library(flowWorkspace) # for cytoset and gatingset classes
library(openCyto)      # for automated gating 
library(ggcyto)        # for ggplot wrappers
library(scales)        # for creating custom transformations

# Load data and create gatingSet ------------------------------------------
fcs_path  <- system.file("extdata", package = "flowWorkspaceData")
fcs_files <- list.files(pattern = "CytoTrol", fcs_path, full = TRUE)
cs        <- load_cytoset_from_fcs(fcs_files)
comp_mat  <- spillover(cs[[1]])$SPILL
compensate(cs, comp_mat)
gs <- GatingSet(cs)

# Define new trans object -------------------------------------------------
asinhTransform <- function(transformationId = "defaultAsinhTransform", cofactor = 5) {
  t <- new("transform", .Data = function(x) x <- asinh(x / cofactor)) 
  t@transformationId <- transformationId 
  t
}

sinhTransform <- function(transformationId = "defaultSinhTransform", cofactor = 5) {
  t <- new("transform", .Data = function(x) x <- sinh(x) * cofactor) 
  t@transformationId <- transformationId 
  t
}

simple_asinh <- function (...) {
  trans.obj <- asinhTransform(...)
  trans <- trans.obj@.Data
  inv <- sinhTransform(...)@.Data
  trans_new(name = "a_sinh", transform = trans, inverse = inv)
}

# Transform data ----------------------------------------------------------
trans        <- simple_asinh(cofactor = 500)
to_transform <- colnames(gs)[5:11]
trans_list   <- transformerList(to_transform, trans)
gs           <- transform(gs, trans_list)

ggcyto(gs[[1]], subset = "root", aes("B710-A", "R780-A")) +
  geom_hex(bins = 100) +
  axis_x_inverse_trans() +
  axis_y_inverse_trans()

As you can see, the axes still display the transformed values, not the original ones. What is it I've done wrong here?

image

Many thanks for your help and an excellent ecosystem of packages.
Hefin

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] scales_1.2.1             ggcyto_1.22.0            ncdfFlow_2.40.0         
[4] BH_1.81.0-1              RcppArmadillo_0.12.6.6.1 flowCore_2.6.0          
[7] ggplot2_3.4.4            openCyto_2.6.0           flowWorkspace_4.6.0     

loaded via a namespace (and not attached):
 [1] bitops_1.0-7        matrixStats_1.2.0   RColorBrewer_1.1-3  httr_1.4.7         
 [5] Rgraphviz_2.38.0    tools_4.1.0         utf8_1.2.4          R6_2.5.1           
 [9] KernSmooth_2.23-22  DBI_1.2.0           BiocGenerics_0.40.0 colorspace_2.1-0   
[13] withr_2.5.2         gridExtra_2.3       tidyselect_1.2.0    mnormt_2.1.1       
[17] curl_5.2.0          compiler_4.1.0      graph_1.72.0        cli_3.6.2          
[21] Biobase_2.54.0      flowClust_3.32.0    xml2_1.3.6          labeling_0.4.3     
[25] flowStats_4.6.0     DEoptimR_1.1-3      hexbin_1.28.3       mvtnorm_1.2-4      
[29] robustbase_0.99-1   RBGL_1.70.0         digest_0.6.33       rainbow_3.7        
[33] R.utils_2.12.3      rrcov_1.7-4         base64enc_0.1-3     jpeg_0.1-10        
[37] pkgconfig_2.0.3     rlang_1.1.2         rstudioapi_0.15.0   farver_2.1.1       
[41] generics_0.1.3      mclust_6.0.1        gtools_3.9.5        dplyr_1.1.4        
[45] R.oo_1.25.0         RCurl_1.98-1.12     magrittr_2.0.3      RProtoBufLib_2.6.0 
[49] interp_1.1-5        Matrix_1.6-4        Rcpp_1.0.11         munsell_0.5.0      
[53] S4Vectors_0.32.4    fansi_1.0.6         lifecycle_1.0.4     R.methodsS3_1.8.2  
[57] MASS_7.3-60         zlibbioc_1.40.0     plyr_1.8.9          grid_4.1.0         
[61] parallel_4.1.0      deldir_2.0-2        lattice_0.22-5      splines_4.1.0      
[65] pillar_1.9.0        fda_6.1.4           corpcor_1.6.10      stats4_4.1.0       
[69] XML_3.99-0.14       glue_1.6.2          latticeExtra_0.6-30 data.table_1.14.10 
[73] RcppParallel_5.1.7  deSolve_1.40        png_0.1-8           vctrs_0.6.5        
[77] gtable_0.3.4        aws.s3_0.3.21       clue_0.3-65         ks_1.14.1          
[81] fds_1.8             pracma_2.4.4        IDPmisc_1.1.20      pcaPP_2.0-4        
[85] tibble_3.2.1        cytolib_2.6.2       aws.signature_0.6.0 flowViz_1.58.0     
[89] ellipse_0.5.0       cluster_2.1.6       hdrcde_3.4     

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions