saeyslab / multinichenetr

MultiNicheNet: a flexible framework for differential cell-cell communication analysis from multi-sample multi-condition single-cell transcriptomics data
GNU General Public License v3.0
112 stars 14 forks source link

Error in `auto_copy()`: Set `copy = TRUE` if `y` can be copied to the same source as `x` (may be slow). #12

Closed catsargent closed 1 year ago

catsargent commented 1 year ago

Hi,

when running MNN in step-by-step mode, I get the following error when calling get_DE_info:

Error in `auto_copy()`:
! `x` and `y` must share the same src.
ℹ `x` is a <tbl_df/tbl/data.frame> object.
ℹ `y` is `NULL`.
ℹ Set `copy = TRUE` if `y` can be copied to the same source as `x` (may be slow).
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `auto_copy()`:
! `x` and `y` must share the same src.
ℹ `x` is a <tbl_df/tbl/data.frame> object.
ℹ `y` is `NULL`.
ℹ Set `copy = TRUE` if `y` can be copied to the same source as `x` (may be slow).
---
Backtrace:
    ▆
 1. ├─multinichenetr::get_DE_info(...)
 2. │ └─... %>% ...
 3. ├─dplyr::select(., gene, cluster_id, logFC, p_val, p_adj, contrast)
 4. ├─dplyr::inner_join(., contrast_tbl, by = "group")
 5. └─dplyr:::inner_join.data.frame(., contrast_tbl, by = "group")
 6.   └─dplyr::auto_copy(x, y, copy = copy)
Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.
> rlang::last_trace(drop = FALSE)
<error/rlang_error>

It appears to be the last part of the following which is causing the issue:

celltype_de_findmarkers = celltypes %>% lapply(function(celltype_oi, sce){
      genes_expressed = rownames(sce) ## change later if necessary for having a more decent filtering
      sce_oi = sce[intersect(rownames(sce), genes_expressed), SummarizedExperiment::colData(sce)[,celltype_id] == celltype_oi]
      DE_tables_list = scran::findMarkers(sce_oi, test.type="t", groups = SummarizedExperiment::colData(sce_oi)[,group_id])
      conditions = names(DE_tables_list)
      DE_tables_df = conditions %>% lapply(function(condition_oi, DE_tables_list){
        DE_table_oi = DE_tables_list[[condition_oi]]
        DE_table_oi = DE_table_oi %>% data.frame() %>% tibble::rownames_to_column("gene") %>% tibble::as_tibble() %>% dplyr::mutate(cluster_id = celltype_oi, group = condition_oi) %>% dplyr::select(gene, p.value, FDR, summary.logFC, cluster_id, group)  
      }, DE_tables_list) %>% dplyr::bind_rows()
    }, **sce) %>% dplyr::bind_rows() %>% dplyr::rename(logFC = summary.logFC, p_val = p.value, p_adj = FDR) %>% dplyr::inner_join(contrast_tbl, by = "group") %>% dplyr::select(gene, cluster_id, logFC, p_val, p_adj, contrast**)

This is what contrast_tbl looks like (I believe it is set-up fine):

# A tibble: 3 × 2
  contrast                                                   group               
  <chr>                                                      <chr>               
1 Parotid.Gland-(Minor.Salivary.Gland+Submandibular.Gland)/2 Parotid.Gland       
2 Minor.Salivary.Gland-(Parotid.Gland+Submandibular.Gland)/2 Minor.Salivary.Gland
3 Submandibular.Gland-(Minor.Salivary.Gland+Parotid.Gland)/2 Submandibular.Gland 

Have you any ideas what the problem might be?

Thanks, Catherine

browaeysrobin commented 1 year ago

Hi @catsargent

Can you confirm whether you get this error if you use the default parameters get_DE_info(findMarkers = FALSE) since the code snippet you showed is only executed when using get_DE_info(findMarkers = TRUE)?

Note that using get_DE_info(findMarkers = TRUE) is not recommended, except maybe only if you would have 2/3 samples per group. (this option was added for us for internal testing, not to be used by the end users)