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

Error with FindIntegrationAnchors #704

Closed
rpolicastro opened this issue Jul 7, 2021 · 4 comments
Closed

Error with FindIntegrationAnchors #704

rpolicastro opened this issue Jul 7, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@rpolicastro
Copy link

Hello,

I get the following error when trying to run FindIntegrationAnchors on a few scATAC-seq datasets run through Signac.

Error in names(cells) <- new.names[names(x = cells)] : 
  attempt to set an attribute on NULL
In addition: Warning message:
In CheckDuplicateCellNames(object.list = object.list) :
  Some cell names are duplicated across objects provided. Renaming to enforce unique cell names.

Here is the relevant code leading up to this error. seu is a list of scATAC-seq Seurat objects and frags is a list of Fragment Objects.

library("Signac")
library("Seurat")
library("tidyverse")

## Get unified (reduced) peaks.

unified_peaks <- UnifyPeaks(seu)

## For each sample get a new count matrix using the unified peaks.

mats <- map(frags, FeatureMatrix, unified_peaks)

# Filter out cells that aren't in the original seurat object.
mats <- map2(mats, seu, ~`[`(.x, , colnames(.x) %in% colnames(.y)))

## Create chromatin assays and seurat objects for unified peaks.

seu_unif <- mats %>%
  map2(frags, ~CreateChromatinAssay(.x, fragments=.y, annotation=anno)) %>%
  imap(~CreateSeuratObject(.x, project=.y, assay="ATAC"))

## Normalization.

seu_unif <- map(seu_unif, RunTFIDF)

## Find integration anchors.

anchors <- FindIntegrationAnchors(seu_unif, reduction="rlsi", dims=2:30)

Here is my session info.

R version 4.1.0 (2021-05-18)                                                                 
Platform: x86_64-conda-linux-gnu (64-bit)                                                    
Running under: Ubuntu 20.04.2 LTS                                                            
                                                                                             
Matrix products: default                                                                     
BLAS/LAPACK: /software/miniconda3/envs/singlecell/lib/libopenblasp-r0.3.15.so

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
 [1] GenomicFeatures_1.44.0      AnnotationDbi_1.54.0       
 [3] clustree_0.4.3              ggraph_2.0.5                
 [5] ggrastr_0.2.3               scDblFinder_1.6.0          
 [7] SingleCellExperiment_1.14.1 SummarizedExperiment_1.22.0
 [9] Biobase_2.52.0              MatrixGenerics_1.4.0       
[11] matrixStats_0.59.0          SeuratObject_4.0.2         
[13] Seurat_4.0.3                rtracklayer_1.52.0         
[15] GenomicRanges_1.44.0        GenomeInfoDb_1.28.0        
[17] IRanges_2.26.0              S4Vectors_0.30.0           
[19] BiocGenerics_0.38.0         future_1.21.0               
[21] patchwork_1.1.1             forcats_0.5.1               
[23] stringr_1.4.0               dplyr_1.0.7                 
[25] purrr_0.3.4                 readr_1.4.0
[27] tidyr_1.1.3                 tibble_3.1.2                
[29] ggplot2_3.3.5               tidyverse_1.3.1            
[31] Signac_1.2.1

loaded via a namespace (and not attached):
  [1] rappdirs_0.3.3            SnowballC_0.7.0          
  [3] scattermore_0.7           bit64_4.0.5               
  [5] irlba_2.3.3               DelayedArray_0.18.0      
  [7] data.table_1.14.0         rpart_4.1-15              
  [9] KEGGREST_1.32.0           RCurl_1.98-1.3            
 [11] generics_0.1.0            ScaledMatrix_1.0.0       
 [13] cowplot_1.1.1             RSQLite_2.2.5             
 [15] RANN_2.6.1                bit_4.0.4                 
 [17] spatstat.data_2.1-0       xml2_1.3.2                
 [19] lubridate_1.7.10          httpuv_1.6.1              
 [21] assertthat_0.2.1          viridis_0.6.1             
 [23] hms_1.1.0                 promises_1.2.0.1         
 [25] fansi_0.4.2               restfulr_0.0.13
[27] progress_1.2.2            dbplyr_2.1.1              
 [29] readxl_1.3.1              igraph_1.2.6              
 [31] DBI_1.1.1                 htmlwidgets_1.5.3        
 [33] sparsesvd_0.2             spatstat.geom_2.2-0      
 [35] ellipsis_0.3.2            backports_1.2.1          
 [37] biomaRt_2.48.0            deldir_0.2-10             
 [39] sparseMatrixStats_1.4.0   vctrs_0.3.8               
 [41] ROCR_1.0-11               abind_1.4-5               
 [43] cachem_1.0.5              withr_2.4.2               
 [45] ggforce_0.3.3             sctransform_0.3.2
[47] GenomicAlignments_1.28.0  prettyunits_1.1.1        
 [49] scran_1.20.1              goftest_1.2-2             
 [51] cluster_2.1.2             lazyeval_0.2.2            
 [53] crayon_1.4.1              edgeR_3.34.0              
 [55] pkgconfig_2.0.3           slam_0.1-48               
 [57] tweenr_1.0.2              nlme_3.1-152              
 [59] vipor_0.4.5               rlang_0.4.11              
 [61] globals_0.14.0            lifecycle_1.0.0          
 [63] miniUI_0.1.1.1            filelock_1.0.2            
 [65] BiocFileCache_2.0.0       modelr_0.1.8              
 [67] rsvd_1.0.5                cellranger_1.1.0         
 [69] polyclip_1.10-0           lmtest_0.9-38             
 [71] Matrix_1.3-4              ggseqlogo_0.1
[73] zoo_1.8-9                 reprex_2.0.0
[75] beeswarm_0.4.0            ggridges_0.5.3            
 [77] png_0.1-7                 viridisLite_0.4.0        
 [79] rjson_0.2.20              bitops_1.0-7              
 [81] KernSmooth_2.23-20        Biostrings_2.60.0        
 [83] blob_1.2.1                DelayedMatrixStats_1.14.0
 [85] parallelly_1.26.1         beachmat_2.8.0            
 [87] scales_1.1.1              memoise_2.0.0             
 [89] magrittr_2.0.1            plyr_1.8.6                
 [91] ica_1.0-2                 zlibbioc_1.38.0          
 [93] compiler_4.1.0            dqrng_0.3.0               
 [95] BiocIO_1.2.0              RColorBrewer_1.1-2       
 [97] fitdistrplus_1.1-5        Rsamtools_2.8.0
[99] cli_3.0.0                 XVector_0.32.0            
[101] listenv_0.8.0             pbapply_1.4-3             
[103] MASS_7.3-54               mgcv_1.8-36               
[105] tidyselect_1.1.1          stringi_1.6.2             
[107] yaml_2.2.1                BiocSingular_1.8.0       
[109] locfit_1.5-9.4            ggrepel_0.9.1             
[111] grid_4.1.0                fastmatch_1.1-0          
[113] tools_4.1.0               future.apply_1.7.0       
[115] rstudioapi_0.13           bluster_1.2.1             
[117] lsa_0.73.2                metapod_1.0.0             
[119] gridExtra_2.3             farver_2.1.0              
[121] Rtsne_0.15                digest_0.6.27
[123] shiny_1.6.0               qlcMatrix_0.9.7          
[125] Rcpp_1.0.7                broom_0.7.8               
[127] scuttle_1.2.0             later_1.2.0               
[129] RcppAnnoy_0.0.18          httr_1.4.2                
[131] colorspace_2.0-2          rvest_1.0.0               
[133] XML_3.99-0.6              fs_1.5.0                  
[135] tensor_1.5                reticulate_1.20          
[137] splines_4.1.0             uwot_0.1.10               
[139] RcppRoll_0.3.0            statmod_1.4.36            
[141] spatstat.utils_2.2-0      scater_1.20.0             
[143] graphlayouts_0.7.1        xgboost_1.4.0.1          
[145] plotly_4.9.4.1            xtable_1.8-4              
[147] jsonlite_1.7.2            tidygraph_1.2.0
[149] R6_2.5.0                  pillar_1.6.1              
[151] htmltools_0.5.1.1         mime_0.11                 
[153] glue_1.4.2                fastmap_1.1.0             
[155] BiocParallel_1.26.0       BiocNeighbors_1.10.0     
[157] codetools_0.2-18          utf8_1.2.1                
[159] lattice_0.20-44           spatstat.sparse_2.0-0    
[161] curl_4.3.2                ggbeeswarm_0.6.0         
[163] leiden_0.3.8              survival_3.2-11          
[165] limma_3.48.0              docopt_0.7.1              
[167] munsell_0.5.0             GenomeInfoDbData_1.2.6   
[169] haven_2.4.1               reshape2_1.4.4            
[171] gtable_0.3.0              spatstat.core_2.2-0 
@rpolicastro rpolicastro added the bug Something isn't working label Jul 7, 2021
@timoast
Copy link
Collaborator

timoast commented Jul 7, 2021

To use rlsi dimension reduction you need to first compute an LSI dimension reduction for each object to be integrated.

Do you still see this error when there is an lsi dimension reduction stored in each object?

If so, do you still see the error when running with more standard R code (without map, map2 %>%, etc)?

@rpolicastro
Copy link
Author

rpolicastro commented Jul 8, 2021

Thanks for taking a look at the error. I ran the below code to add lsi dimension reduction before the find anchors function, but unfortunately still got the same error.

## Find top features.

seu_unif <- map(seu_unif, FindTopFeatures)

## Dimension reduction.

seu_unif <- map(seu_unif, RunSVD)

Rerunning two of my samples without using magrittr or purrr functions didn't help either.

Here's a traceback.

> traceback()                                                                                                                                                                                                 
10: RenameCells.Fragment(object = slot(object = object, name = "fragments")[[i]],                                                                                                                             
        new.names = new.names)
9: RenameCells(object = slot(object = object, name = "fragments")[[i]],                                                                                                                               [0/1857]
       new.names = new.names)
8: RenameCells.ChromatinAssay(object = object[[assay]], new.names = new.cell.names)
7: RenameCells(object = object[[assay]], new.names = new.cell.names)
6: RenameCells.Seurat(object = object.list[[x]], new.names = paste0(Cells(x = object.list[[x]]), 
       "_", x))
5: RenameCells(object = object.list[[x]], new.names = paste0(Cells(x = object.list[[x]]), 
       "_", x))
4: FUN(X[[i]], ...)
3: lapply(X = 1:length(x = object.list), FUN = function(x) {
       return(RenameCells(object = object.list[[x]], new.names = paste0(Cells(x = object.list[[x]]), 
           "_", x)))
   })
2: CheckDuplicateCellNames(object.list = object.list)
1: FindIntegrationAnchors(seu_unif, reduction = "rlsi", dims = 2:30)

You can reproduce the error by just running Seurat:::CheckDuplicateCellNames on my list of Seurat objects. My guess right now is that it is looking for cell names in the fragment object slot, which right now there are none. I'll see if adding cells to the fragment file fixes the problem.

@rpolicastro
Copy link
Author

rpolicastro commented Jul 8, 2021

Adding cell names via the cells argument of CreateFragmentObject fixed the error. Because this wasn't specified at first the cell names in the fragment object were NULL which somehow caused the error when CheckDuplicateCellNames called RenameCells.

@timoast
Copy link
Collaborator

timoast commented Jul 9, 2021

Thanks for looking into this, I was able to reproduce the issue with RenameCells when no cell information is stored in a Fragment object.

We need to enforce that Fragment object always contain cell names when stored inside a ChromatinAssay, otherwise it's unclear what to do when attempting to rename cells. I have added a check in CreateChromatinAssay() that will set the cell name information for the fragment object to all the cells in the assay if it's not already set in the Fragment object itself.

This change is available on the develop branch, see installation instructions here

@timoast timoast closed this as completed Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants