Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastMNN error when supplying SCE with dimnames and non-NULL use.dimred #2

Closed
PeteHaitch opened this issue May 22, 2019 · 4 comments
Closed

Comments

@PeteHaitch
Copy link

suppressPackageStartupMessages(library(batchelor))

B1 <- matrix(rnorm(10000), ncol = 40, dimnames = list(NULL, paste0("B1_", 1:40)))
B2 <- matrix(rnorm(10000), ncol = 40, dimnames = list(NULL, paste0("B2_", 1:40)))
batch <- c(rep(1, ncol(B1)), rep(2, ncol(B2)))
sce <- SingleCellExperiment(list(logcounts = cbind(B1, B2)))
assay(sce, "cosnormed") <- cosineNorm(logcounts(sce))
set.seed(666)
pcs <- multiBatchPCA(sce, batch = batch, assay.type = "cosnormed")
#> Warning in sweep(centered, 2, w, "/", check.margin = FALSE): 'check.margin' is ignored when 'x' is a DelayedArray object or
#>   derivative
reducedDim(sce, "PCA") <- do.call(rbind, pcs)

set.seed(666)
named_sce <- fastMNN(sce, batch = batch) # Works
#> Warning in sweep(centered, 2, w, "/", check.margin = FALSE): 'check.margin' is ignored when 'x' is a DelayedArray object or
#>   derivative
set.seed(666)
unnamed_sce <- fastMNN(unname(sce), batch = batch) # Works
#> Warning in sweep(centered, 2, w, "/", check.margin = FALSE): 'check.margin' is ignored when 'x' is a DelayedArray object or
#>   derivative
all.equal(reducedDim(named_sce), reducedDim(unnamed_sce), 
          check.attributes = FALSE) # Sanity check
#> [1] TRUE

unnamed_pca <- fastMNN(unname(sce), batch = batch, use.dimred = "PCA") # Works
all.equal(unnamed_pca$corrected, reducedDim(unnamed_sce)) # Sanity check
#> [1] TRUE
named_pca <- fastMNN(sce, batch = batch, use.dimred = "PCA") # Errors
#> Error in dimnames(x) <- dn: length of 'dimnames' [2] not equal to array extent

Created on 2019-05-22 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.0 (2019-04-26)
#>  os       Ubuntu 18.04.2 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en_AU:en                    
#>  collate  en_AU.UTF-8                 
#>  ctype    en_AU.UTF-8                 
#>  tz       Australia/Melbourne         
#>  date     2019-05-22                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package              * version   date       lib source        
#>  assertthat             0.2.1     2019-03-21 [3] CRAN (R 3.5.3)
#>  backports              1.1.4     2019-04-10 [3] CRAN (R 3.5.3)
#>  batchelor            * 1.0.0     2019-05-02 [1] Bioconductor  
#>  beeswarm               0.2.3     2016-04-25 [1] CRAN (R 3.6.0)
#>  Biobase              * 2.44.0    2019-05-02 [1] Bioconductor  
#>  BiocGenerics         * 0.30.0    2019-05-02 [1] Bioconductor  
#>  BiocNeighbors          1.2.0     2019-05-02 [1] Bioconductor  
#>  BiocParallel         * 1.18.0    2019-05-03 [1] Bioconductor  
#>  BiocSingular           1.0.0     2019-05-02 [1] Bioconductor  
#>  bitops                 1.0-6     2013-08-17 [3] CRAN (R 3.5.0)
#>  callr                  3.2.0     2019-03-15 [3] CRAN (R 3.5.3)
#>  cli                    1.1.0     2019-03-19 [3] CRAN (R 3.5.3)
#>  colorspace             1.4-1     2019-03-18 [3] CRAN (R 3.5.3)
#>  crayon                 1.3.4     2017-09-16 [3] CRAN (R 3.5.0)
#>  DelayedArray         * 0.10.0    2019-05-02 [1] Bioconductor  
#>  DelayedMatrixStats     1.6.0     2019-05-02 [1] Bioconductor  
#>  desc                   1.2.0     2018-05-01 [3] CRAN (R 3.5.0)
#>  devtools               2.0.2     2019-04-08 [1] CRAN (R 3.6.0)
#>  digest                 0.6.18    2018-10-10 [3] CRAN (R 3.5.1)
#>  dplyr                  0.8.0.1   2019-02-15 [3] CRAN (R 3.5.2)
#>  evaluate               0.13      2019-02-12 [3] CRAN (R 3.5.2)
#>  fs                     1.3.1     2019-05-06 [3] CRAN (R 3.6.0)
#>  GenomeInfoDb         * 1.20.0    2019-05-02 [1] Bioconductor  
#>  GenomeInfoDbData       1.2.1     2019-05-07 [1] Bioconductor  
#>  GenomicRanges        * 1.36.0    2019-05-02 [1] Bioconductor  
#>  ggbeeswarm             0.6.0     2017-08-07 [1] CRAN (R 3.6.0)
#>  ggplot2                3.1.1     2019-04-07 [3] CRAN (R 3.5.3)
#>  glue                   1.3.1     2019-03-12 [3] CRAN (R 3.5.3)
#>  gridExtra              2.3       2017-09-09 [1] CRAN (R 3.6.0)
#>  gtable                 0.3.0     2019-03-25 [3] CRAN (R 3.5.3)
#>  highr                  0.8       2019-03-20 [3] CRAN (R 3.5.3)
#>  htmltools              0.3.6     2017-04-28 [3] CRAN (R 3.5.0)
#>  IRanges              * 2.18.0    2019-05-02 [1] Bioconductor  
#>  irlba                  2.3.3     2019-02-05 [1] CRAN (R 3.6.0)
#>  knitr                  1.22      2019-03-08 [3] CRAN (R 3.5.2)
#>  lattice                0.20-38   2018-11-04 [4] CRAN (R 3.5.1)
#>  lazyeval               0.2.2     2019-03-15 [3] CRAN (R 3.5.3)
#>  magrittr               1.5       2014-11-22 [3] CRAN (R 3.5.0)
#>  Matrix                 1.2-17    2019-03-22 [4] CRAN (R 3.5.3)
#>  matrixStats          * 0.54.0    2018-07-23 [1] CRAN (R 3.6.0)
#>  memoise                1.1.0     2017-04-21 [1] CRAN (R 3.6.0)
#>  munsell                0.5.0     2018-06-12 [3] CRAN (R 3.5.0)
#>  pillar                 1.3.1     2018-12-15 [3] CRAN (R 3.5.2)
#>  pkgbuild               1.0.3     2019-03-20 [3] CRAN (R 3.5.3)
#>  pkgconfig              2.0.2     2018-08-16 [3] CRAN (R 3.5.1)
#>  pkgload                1.0.2     2018-10-29 [3] CRAN (R 3.5.1)
#>  plyr                   1.8.4     2016-06-08 [3] CRAN (R 3.5.0)
#>  prettyunits            1.0.2     2015-07-13 [3] CRAN (R 3.5.0)
#>  processx               3.3.1     2019-05-08 [3] CRAN (R 3.6.0)
#>  ps                     1.3.0     2018-12-21 [3] CRAN (R 3.5.2)
#>  purrr                  0.3.2     2019-03-15 [3] CRAN (R 3.5.3)
#>  R6                     2.4.0     2019-02-14 [3] CRAN (R 3.5.2)
#>  Rcpp                   1.0.1     2019-03-17 [3] CRAN (R 3.5.3)
#>  RCurl                  1.95-4.12 2019-03-04 [3] CRAN (R 3.5.2)
#>  remotes                2.0.4     2019-04-10 [1] CRAN (R 3.6.0)
#>  rlang                  0.3.4     2019-04-07 [3] CRAN (R 3.5.3)
#>  rmarkdown              1.12      2019-03-14 [3] CRAN (R 3.5.3)
#>  rprojroot              1.3-2     2018-01-03 [3] CRAN (R 3.5.3)
#>  rsvd                   1.0.0     2018-11-06 [1] CRAN (R 3.6.0)
#>  S4Vectors            * 0.22.0    2019-05-02 [1] Bioconductor  
#>  scales                 1.0.0     2018-08-09 [3] CRAN (R 3.5.1)
#>  scater                 1.12.1    2019-05-15 [1] Bioconductor  
#>  sessioninfo            1.1.1     2018-11-05 [1] CRAN (R 3.6.0)
#>  SingleCellExperiment * 1.6.0     2019-05-02 [1] Bioconductor  
#>  stringi                1.4.3     2019-03-12 [3] CRAN (R 3.5.3)
#>  stringr                1.4.0     2019-02-10 [3] CRAN (R 3.5.2)
#>  SummarizedExperiment * 1.14.0    2019-05-02 [1] Bioconductor  
#>  testthat               2.1.1     2019-04-23 [1] CRAN (R 3.6.0)
#>  tibble                 2.1.1     2019-03-16 [3] CRAN (R 3.5.3)
#>  tidyselect             0.2.5     2018-10-11 [3] CRAN (R 3.5.1)
#>  usethis                1.5.0     2019-04-07 [1] CRAN (R 3.6.0)
#>  vipor                  0.4.5     2017-03-22 [1] CRAN (R 3.6.0)
#>  viridis                0.5.1     2018-03-29 [1] CRAN (R 3.6.0)
#>  viridisLite            0.3.0     2018-02-01 [3] CRAN (R 3.5.0)
#>  withr                  2.1.2     2018-03-15 [3] CRAN (R 3.5.0)
#>  xfun                   0.6       2019-04-02 [3] CRAN (R 3.5.3)
#>  XVector                0.24.0    2019-05-02 [1] Bioconductor  
#>  yaml                   2.2.0     2018-07-25 [3] CRAN (R 3.5.1)
#>  zlibbioc               1.30.0    2019-05-02 [1] Bioconductor  
#> 
#> [1] /home/peter/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

The last line should work and all.equal(named_pca$corrected, reducedDim(named_sce) should be TRUE, right?
I got a bit lost in the traceback() trying to figure this one out.

@LTLA
Copy link
Owner

LTLA commented May 22, 2019

It's a recurring nightmare with the name handling. At some point, I was using withDimnames=FALSE in a misguided attempt to squeeze out some more efficiency. But this causes no end of problems when you try to add the names back in, because the diversity of sources (in SCE assays, in SCE reducedDims, as a raw matrix of expression values, as a matrix of PCs) makes it difficult to re-extract the names. In this case, the names were not properly extracted from the SCE reducedDims, hence the observed error.

The easiest solution is just for me to go in and remove withDimnames=FALSE, but the names are being lost somewhere else along the line. You can try to find it but otherwise I will deal with it tomorrow.

@PeteHaitch
Copy link
Author

I'm all too familiar with that nightmare.
Would you mind porting the fix to the release branch if the change is small enough?

@LTLA
Copy link
Owner

LTLA commented May 23, 2019

Fixed in 1.1.2 and 1.0.1.

@LTLA LTLA closed this as completed May 23, 2019
@PeteHaitch
Copy link
Author

Thanks, Aaron!

@getanid123 getanid123 mentioned this issue Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants