flowCore issue: creating and applying new compensation matrix
2
0
Entering edit mode
rdlr • 0
@rdlr-21470
Last seen 2.2 years ago
Ger/Berlin/Deutsches Rheuma-Foirschungs…

Hi!

thank you very much for all the work on the flow packages; they are extremely helpful.

However, I did encounter a problem with creating and employing a new compensation object to a flowset or gatingset constructed after read.flowSet() with no prior compensation.

1) subset data to use for compensation

> tmp_data <- gating_set[which(pData(gating_set)$well_ID=="G10" & pData(fs)$plate==1)]
> tmp_data
A GatingSet with 1 samples
> getData(tmp_data)
A flowSet with 1 experiments.

  column names:
  HDR-T FSC-A FSC-H SSC-A SSC-H V1-A V2-A B1-A B2-A B3-A B4-A R1-A R2-A

2) make empty matrix and change some value

> tmp_chn <- getData(tmp_data[[1]])@parameters@data$name # get channels for compensation matrix
> tmp_chn <- tmp_chn[!grepl("[FS]SC|HDR-T",tmp_chn)]
> tmp_mat <- matrix(nrow=length(tmp_chn), ncol=length(tmp_chn), data=0)
> colnames(tmp_mat) <- rownames(tmp_mat) <- tmp_chn
> tmp_mat[2,4] <- 0.1 # make some arbitrary change
> tmp_mat
     V1-A V2-A B1-A B2-A B3-A B4-A R1-A R2-A
V1-A    0    0    0  0.0    0    0    0    0
V2-A    0    0    0  0.1    0    0    0    0
B1-A    0    0    0  0.0    0    0    0    0
B2-A    0    0    0  0.0    0    0    0    0
B3-A    0    0    0  0.0    0    0    0    0
B4-A    0    0    0  0.0    0    0    0    0
R1-A    0    0    0  0.0    0    0    0    0
R2-A    0    0    0  0.0    0    0    0    0

3) make compensation object and compensate flowset

> tmp_mat <- compensation(tmp_mat)
> tmp_mat
Compensation object 'defaultCompensation':
     V1-A V2-A B1-A B2-A B3-A B4-A R1-A R2-A
V1-A    0    0    0  0.0    0    0    0    0
V2-A    0    0    0  0.1    0    0    0    0
B1-A    0    0    0  0.0    0    0    0    0
B2-A    0    0    0  0.0    0    0    0    0
B3-A    0    0    0  0.0    0    0    0    0
B4-A    0    0    0  0.0    0    0    0    0
R1-A    0    0    0  0.0    0    0    0    0
R2-A    0    0    0  0.0    0    0    0    0
> tmp_comp <-compensate(tmp_data, tmp_mat)
Fehler in solve.default(spillover) : 
  Lapackroutine dgesv: System ist genau singulär: U[1,1] = 0
> tmp_comp <-compensate(getData(tmp_data), tmp_mat)
Fehler in solve.default(spillover) : 
  Lapackroutine dgesv: System ist genau singulär: U[1,1] = 0

> traceback()
16: solve.default(spillover)
15: solve(spillover)
14: .local(x, spillover, ...)
13: compensate(x, spillover@spillover)
12: compensate(x, spillover@spillover)
11: .local(x, spillover, ...)
10: FUN(if (use.exprs) exprs(y) else y, ...)
9: FUN(if (use.exprs) exprs(y) else y, ...)
8: FUN(X[[i]], ...)
7: lapply(sampleNames(x), function(n) {
       y <- x[[n]]
       FUN(if (use.exprs) 
           exprs(y)
       else y, ...)
   })
6: structure(lapply(sampleNames(x), function(n) {
       y <- x[[n]]
       FUN(if (use.exprs) 
           exprs(y)
       else y, ...)
   }), names = sampleNames(x))
5: fsApply(x, compensate, spillover)
4: fsApply(x, compensate, spillover)
3: .local(x, spillover, ...)
2: compensate(getData(tmp_data), tmp_mat)
1: compensate(getData(tmp_data), tmp_mat)

The error message translates (roughly) to:

Error in solve default solve.default(spillover) : 
      Lapackroutine dgesv: System is exactly singular: U[1,1] = 0

Any suggestions are highly appreciated! Thank you & keep up the good work!

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 19.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

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

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

other attached packages:
[1] ggthemes_4.2.0            ggcyto_1.12.0            
[3] ggplot2_3.2.0             openCyto_1.22.2          
[5] flowWorkspace_3.32.0      ncdfFlow_2.30.1          
[7] BH_1.69.0-1               RcppArmadillo_0.9.600.4.0
[9] flowCore_1.50.0          

loaded via a namespace (and not attached):
 [1] Biobase_2.44.0      splines_3.6.1       R.utils_2.9.0      
 [4] ellipse_0.4.1       gtools_3.8.1        RcppParallel_4.4.3 
 [7] assertthat_0.2.1    stats4_3.6.1        latticeExtra_0.6-28
[10] RBGL_1.60.0         robustbase_0.93-5   pillar_1.4.2       
[13] lattice_0.20-38     glue_1.3.1          digest_0.6.20      
[16] RColorBrewer_1.1-2  colorspace_1.4-1    Matrix_1.2-17      
[19] R.oo_1.22.0         plyr_1.8.4          pcaPP_1.9-73       
[22] pkgconfig_2.0.2     fda_2.4.8           zlibbioc_1.30.0    
[25] purrr_0.3.2         corpcor_1.6.9       mvtnorm_1.0-11     
[28] scales_1.0.0        flowStats_3.42.0    tibble_2.1.3       
[31] flowViz_1.48.0      withr_2.1.2         BiocGenerics_0.30.0
[34] hexbin_1.27.3       lazyeval_0.2.2      mnormt_1.5-5       
[37] magrittr_1.5        crayon_1.3.4        IDPmisc_1.1.19     
[40] mclust_5.4.5        ks_1.11.5           R.methodsS3_1.7.1  
[43] MASS_7.3-51.4       graph_1.62.0        tools_3.6.1        
[46] data.table_1.12.2   flowClust_3.22.0    matrixStats_0.54.0 
[49] stringr_1.4.0       munsell_0.5.0       cluster_2.1.0      
[52] compiler_3.6.1      rlang_0.4.0         grid_3.6.1         
[55] tcltk_3.6.1         labeling_0.3        gtable_0.3.0       
[58] rrcov_1.4-7         R6_2.4.0            gridExtra_2.3      
[61] dplyr_0.8.3         clue_0.3-57         KernSmooth_2.23-15 
[64] Rgraphviz_2.28.0    stringi_1.4.3       Rcpp_1.0.1         
[67] DEoptimR_1.0-8      tidyselect_0.2.5
compensate() flowCore • 422 views
ADD COMMENT
1
Entering edit mode
Jake Wagner ▴ 280
@jake-wagner-19995
Last seen 11 months ago

Hi @riedel. As the error message says, the matrix you are trying to use for compensation is not invertible (in other words, it's "singular"). The compensation calculation requires that the matrix be invertible, so the compensate method is appropriately failing.

In this case, starting with a zero-filled matrix and adjusting a single element's value will not generate a valid compensation matrix. If you plan on performing manual compensation, a better starting point would be the identity matrix, which would indicate no spillover between channels. However, flowCore supports automated calculation of the compensation matrix from a set of singly-stained compensation control samples in a flowSet using the spillover method. You can always manually adjust the matrix resulting from that if necessary.

ADD COMMENT
0
Entering edit mode
rdlr • 0
@rdlr-21470
Last seen 2.2 years ago
Ger/Berlin/Deutsches Rheuma-Foirschungs…

Hi Jake,

thank you very much for the quick fix! (In hindsight) that is as trivial as it should have been obvious

have a good day!

ADD COMMENT

Login before adding your answer.

Traffic: 216 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6