RGLab / flowCore

Core flow cytometry infrastructure
43 stars 25 forks source link

How to set the output scale for estimateLogicle? #224

Closed saheedb closed 2 years ago

saheedb commented 2 years ago

Describe the bug Not a bug, but I'd like to know how to get estimateLogicle to log-transform and produce an output scale with n log decades. It seems to only produce a linear scale of 1-5. The file appears to have the appropriate keywords ($PnE), but I'm not certain if this is sufficient

To Reproduce

library(flowCore)

ff <- read.FCS(system.file("extdata", "0877408774.B08", package = "flowCore"), 
               transformation = FALSE)
ff_est <- estimateLogicle(ff, "FL1-H")
ff_t <- flowCore::transform(ff, ff_est)

Expected behavior Output data which is log-transformed and rescaled to 4 decades as defined in the keywords, where $P3E = "4,1"

Screenshots

library(ggcyto)

autoplot(ff_t, "FL1-H")

linear_scale

sessionInfo():

R version 4.0.3 (2020-10-10) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux Server 7.7 (Maipo)

Matrix products: default BLAS: /data/apps/R/4.0.3/lib64/R/lib/libRblas.so LAPACK: /data/apps/R/4.0.3/lib64/R/lib/libRlapack.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] flowTrans_1.42.0 flowClust_3.28.0 flowViz_1.54.0
[4] lattice_0.20-41 dplyr_1.0.2 tidyr_1.1.2
[7] scales_1.1.1 ggcyto_1.18.0 ncdfFlow_2.36.0
[10] BH_1.75.0-0 RcppArmadillo_0.10.1.2.0 ggplot2_3.3.3
[13] pdftools_2.3.1 ggridges_0.5.2 ggthemes_4.2.0
[16] flowCore_2.5.0 gridExtra_2.3 flowDensity_1.24.0
[19] flowWorkspace_4.5.3

loaded via a namespace (and not attached): [1] colorspace_2.0-0 ellipsis_0.3.1 rio_0.5.16
[4] cytolib_2.5.3 corpcor_1.6.9 base64enc_0.1-3
[7] clue_0.3-58 rstudioapi_0.13 farver_2.0.3
[10] hexbin_1.28.1 IDPmisc_1.1.20 DT_0.16
[13] fansi_0.4.1 xml2_1.3.2 mnormt_2.0.2
[16] knitr_1.30 spam_2.6-0 cluster_2.1.0
[19] png_0.1-7 RPMG_2.2-3 rgeos_0.5-5
[22] graph_1.68.0 compiler_4.0.3 httr_1.4.2
[25] fastmap_1.1.0 assertthat_0.2.1 cli_2.2.0
[28] htmltools_0.5.2 tools_4.0.3 dotCall64_1.0-0
[31] gtable_0.3.0 glue_1.4.2 Rwave_2.4-8
[34] reshape2_1.4.4 maps_3.3.0 Rcpp_1.0.5
[37] carData_3.0-4 Biobase_2.50.0 jquerylib_0.1.4
[40] cellranger_1.1.0 vctrs_0.3.6 RFOC_3.4-6
[43] changepoint_2.2.2 xfun_0.28 stringr_1.4.0
[46] openxlsx_4.2.3 lifecycle_0.2.0 gtools_3.8.2
[49] XML_3.99-0.5 zoo_1.8-8 zlibbioc_1.36.0
[52] MASS_7.3-53 RProtoBufLib_2.5.1 hms_0.5.3
[55] parallel_4.0.3 RColorBrewer_1.1-2 fields_11.6
[58] yaml_2.2.1 curl_4.3.2 aws.signature_0.6.0
[61] MBA_0.0-9 latticeExtra_0.6-29 stringi_1.5.3
[64] S4Vectors_0.28.1 flowAI_1.20.1 caTools_1.18.0
[67] BiocGenerics_0.36.1 zip_2.1.1 rlang_0.4.10
[70] pkgconfig_2.0.3 matrixStats_0.61.0-9001 bitops_1.0-6
[73] evaluate_0.14 purrr_0.3.4 htmlwidgets_1.5.3.9000 [76] labeling_0.4.2 tidyselect_1.1.0 plyr_1.8.6
[79] magrittr_2.0.1 R6_2.5.0 gplots_3.1.1
[82] generics_0.1.0 pillar_1.4.7 haven_2.3.1
[85] foreign_0.8-80 withr_2.3.0 abind_1.4-5
[88] sp_1.4-4 tibble_3.0.4 crayon_1.3.4
[91] car_3.0-10 GEOmap_2.4-4 KernSmooth_2.23-17
[94] ellipse_0.4.2 tmvnsim_1.0-2 rmarkdown_2.11
[97] aws.s3_0.3.21 jpeg_0.1-8.1 readxl_1.3.1
[100] data.table_1.13.6 qpdf_1.1 Rgraphviz_2.34.0
[103] forcats_0.5.0 splancs_2.01-40 digest_0.6.28
[106] RcppParallel_5.0.2 stats4_4.0.3 munsell_0.5.0
[109] shinyjs_2.0.0 RSEIS_3.9-3 askpass_1.1

Additional context Add any other context about the problem here.

gfinak commented 2 years ago

The logicle is not a log transform. If you want log transformed data define a log transform and use that. EstimateLogicle will apply a log-linear biexponential transform. See the docs for details.

Greg Finak

On Tue, Jan 4, 2022, 11:33 saheedb @.***> wrote:

Describe the bug Not a bug, but I'd like to know how to get estimateLogicle to log-transform and produce an output scale with n log decades. It seems to only produce a linear scale of 1-5. The file appears to have the appropriate keywords ($PnE), but I'm not certain if this is sufficient

To Reproduce ` library(flowCore)

ff <- read.FCS(system.file("extdata", "0877408774.B08", package = "flowCore"), transformation = FALSE) ff_est <- estimateLogicle(ff, "FL1-H") ff_t <- flowCore::transform(ff, ff_est) `

Expected behavior Output data which is log-transformed and rescaled to 4 decades as defined in the keywords, where $P3E = "4,1"

Screenshots library(ggcyto) autoplot(ff_t, "FL1-H") [image: linear_scale] https://user-images.githubusercontent.com/10297379/148112372-45e8c270-b45e-4f32-ae56-2f108931535e.png

sessionInfo():

R version 4.0.3 (2020-10-10) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux Server 7.7 (Maipo)

Matrix products: default BLAS: /data/apps/R/4.0.3/lib64/R/lib/libRblas.so LAPACK: /data/apps/R/4.0.3/lib64/R/lib/libRlapack.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] flowTrans_1.42.0 flowClust_3.28.0 flowViz_1.54.0 [4] lattice_0.20-41 dplyr_1.0.2 tidyr_1.1.2 [7] scales_1.1.1 ggcyto_1.18.0 ncdfFlow_2.36.0 [10] BH_1.75.0-0 RcppArmadillo_0.10.1.2.0 ggplot2_3.3.3 [13] pdftools_2.3.1 ggridges_0.5.2 ggthemes_4.2.0 [16] flowCore_2.5.0 gridExtra_2.3 flowDensity_1.24.0 [19] flowWorkspace_4.5.3

loaded via a namespace (and not attached): [1] colorspace_2.0-0 ellipsis_0.3.1 rio_0.5.16 [4] cytolib_2.5.3 corpcor_1.6.9 base64enc_0.1-3 [7] clue_0.3-58 rstudioapi_0.13 farver_2.0.3 [10] hexbin_1.28.1 IDPmisc_1.1.20 DT_0.16 [13] fansi_0.4.1 xml2_1.3.2 mnormt_2.0.2 [16] knitr_1.30 spam_2.6-0 cluster_2.1.0 [19] png_0.1-7 RPMG_2.2-3 rgeos_0.5-5 [22] graph_1.68.0 compiler_4.0.3 httr_1.4.2 [25] fastmap_1.1.0 assertthat_0.2.1 cli_2.2.0 [28] htmltools_0.5.2 tools_4.0.3 dotCall64_1.0-0 [31] gtable_0.3.0 glue_1.4.2 Rwave_2.4-8 [34] reshape2_1.4.4 maps_3.3.0 Rcpp_1.0.5 [37] carData_3.0-4 Biobase_2.50.0 jquerylib_0.1.4 [40] cellranger_1.1.0 vctrs_0.3.6 RFOC_3.4-6 [43] changepoint_2.2.2 xfun_0.28 stringr_1.4.0 [46] openxlsx_4.2.3 lifecycle_0.2.0 gtools_3.8.2 [49] XML_3.99-0.5 zoo_1.8-8 zlibbioc_1.36.0 [52] MASS_7.3-53 RProtoBufLib_2.5.1 hms_0.5.3 [55] parallel_4.0.3 RColorBrewer_1.1-2 fields_11.6 [58] yaml_2.2.1 curl_4.3.2 aws.signature_0.6.0 [61] MBA_0.0-9 latticeExtra_0.6-29 stringi_1.5.3 [64] S4Vectors_0.28.1 flowAI_1.20.1 caTools_1.18.0 [67] BiocGenerics_0.36.1 zip_2.1.1 rlang_0.4.10 [70] pkgconfig_2.0.3 matrixStats_0.61.0-9001 bitops_1.0-6 [73] evaluate_0.14 purrr_0.3.4 htmlwidgets_1.5.3.9000 [76] labeling_0.4.2 tidyselect_1.1.0 plyr_1.8.6 [79] magrittr_2.0.1 R6_2.5.0 gplots_3.1.1 [82] generics_0.1.0 pillar_1.4.7 haven_2.3.1 [85] foreign_0.8-80 withr_2.3.0 abind_1.4-5 [88] sp_1.4-4 tibble_3.0.4 crayon_1.3.4 [91] car_3.0-10 GEOmap_2.4-4 KernSmooth_2.23-17 [94] ellipse_0.4.2 tmvnsim_1.0-2 rmarkdown_2.11 [97] aws.s3_0.3.21 jpeg_0.1-8.1 readxl_1.3.1 [100] data.table_1.13.6 qpdf_1.1 Rgraphviz_2.34.0 [103] forcats_0.5.0 splancs_2.01-40 digest_0.6.28 [106] RcppParallel_5.0.2 stats4_4.0.3 munsell_0.5.0 [109] shinyjs_2.0.0 RSEIS_3.9-3 askpass_1.1

Additional context Add any other context about the problem here.

— Reply to this email directly, view it on GitHub https://github.com/RGLab/flowCore/issues/224, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKSI6P4UH2MXHVZWSU6O4DUUNDRTANCNFSM5LIGOKTQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

mikejiang commented 2 years ago

is this what you are trying to do?

autoplot(ff, "FL1-H")+scale_x_logicle()

image

saheedb commented 2 years ago

Sorry. I might not be asking the correct question. I'm interested in transforming the data so that the output looks as it does in flowjo (4 - 5 decades). I'm aware autoplot(ff, "FL1-H")+scale_x_logicle() will do it, but since this is just for the display, I'm looking for a a way to transform the data itself. flowWorkspace::flowjo_biexp() appears to be able to do this, but I'm having some difficulty automatically calculating the parameters which is why I started looking at estimateLogicle(), but perhaps you might be able to help me with flowjo_biexp(). I'm not too clear on what each parameter is supposed to represent:

pos: the full width of the transformed display in asymptotic decades So this should be 4 or 4.5 I gather?

channelRange: the maximum value of transformed data What would this be? Haven't I already specified the maximum with pos? i.e 10000 for a 4 decades? Is this equivalent to t in flowCore::logicleTransform?

maxValue: the maximum value of input data Seems self-explanatory. Is there a number high enough that will break it? Like I have outlier values of 1e7? I ask because I'm getting this error: Error in .getSplineCoefs(channelRange = channelRange, maxValue = maxValue, : invalid zeroChan -2147483648

widthBasis Is this meant to be calculated the same way as w in logicleTransform()? : w=(m-log10(t/abs(r)))/2 So m = pos? and t = channelRange? and r = my most negative value (after compensation)? Also, same question as above regarding extremely outliers at the bottom end--will it break?

I think I'm doing something wrong here:

ff <- read.FCS(system.file("extdata", "0877408774.B08", package = "flowCore"), 
               transformation = FALSE)

t = 262144
m = 4
a = 0
r = min(ff@exprs[, "FL1-H"]) ## with my data this would be < -1e6
max = max(ff@exprs[, "FL1-H"])
w = (m-log10(t/abs(r)))/2
lt <- flowjo_biexp(widthBasis = w, maxValue = max, pos = m)
lgcl <- transformList("FL1-H", lt)

fft    <- flowCore::transform(ff, lgcl)
autoplot(fft, "FL1-H")

fj_biex

saheedb commented 2 years ago

Thanks for the input. I need to explore this further myself before seeking help.