stuart-lab / signac

R toolkit for the analysis of single-cell chromatin data
https://stuartlab.org/signac/
Other
329 stars 88 forks source link

Error when trying to integrate merged atacseq obj with rnaseq obj #251

Closed alutservitz closed 4 years ago

alutservitz commented 4 years ago

Hi Tim,

I'm trying to integrate a merged snATACseq object with snRNAseq data, but I keep getting the following error with my own data.

Error in SetAssayData.ChromatinAssay(object = object, slot = "scale.data",  :
  Number of rows in provided matrix does not match
           the number of rows in the object
Calls: FindTransferAnchors ... ScaleData.Assay -> SetAssayData -> SetAssayData.ChromatinAssay
Execution halted

I recreated this error trying to integrate the merged pbmc object created following this vignette: https://satijalab.org/signac/articles/merging.html and the preprocessed scRNAseq pbmc object found here: https://www.dropbox.com/s/zn6khirjafoyyxl/pbmc_10k_v3.rds?dl=0. I am using the latest version of Signac (v 1.0.0).

Here is the chunk of my code where I am getting the error:

rna <- readRDS(path2rna_obj)
atac <- readRDS(path2atac_obj)

transfer.anchors <- FindTransferAnchors(
  reference = rna,
  query = atac,
  reduction = 'cca'
)

predicted.labels <- TransferData(
  anchorset = transfer.anchors,
  refdata = rna$celltype,
  weight.reduction = atac[['lsi']],
  dims = 2:30
)

atac <- AddMetaData(object = atac, metadata = predicted.labels)

What is the best way to set up the merged atacseq object to then integrate with rnaseq data? Thanks in advance!

timoast commented 4 years ago

I believe this is fixed on the develop branch (https://github.com/timoast/signac/commit/55611297a2a6ed96ee9cf587de16f4302bc12002). Can you install from the develop branch and see if you still have the same issue?

alutservitz commented 4 years ago

Hi Tim,

Thanks for the response! I tried again after installing from the develop branch and received this error:

Running CCA

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: Standardize(mat = object1, display_progress = FALSE)
 2: RunCCA.default(object1 = data1, object2 = data2, standardize = TRUE,     num.cc = num.cc, verbose = verbose, )
 3: RunCCA(object1 = data1, object2 = data2, standardize = TRUE,     num.cc = num.cc, verbose = verbose, )
 4: RunCCA.Seurat(object1 = reference, object2 = query, features = features,     num.cc = max(dims), renormalize = FALSE, rescale = FALSE,     verbose = verbose)
 5: RunCCA(object1 = reference, object2 = query, features = features,     num.cc = max(dims), renormalize = FALSE, rescale = FALSE,     verbose = verbose)
 6: FindTransferAnchors(reference = rna, query = atac, reduction = "cca")
An irrecoverable exception occurred. R is aborting now ...
/var/spool/uger-8.5.5/ugerbm-c003/job_scripts/20121416: line 24: 14790 Segmentation fault      (core dumped) 
alutservitz commented 4 years ago

Hi Tim,

We have it running now. The code below will solve the error seen in my previous post.

# load objects
rna <- readRDS(rnaPath)
atac <- readRDS(atacPath)

# extract gene annotations from EnsDb
annotations <- GetGRangesFromEnsDb(ensdb = EnsDb.Hsapiens.v75)

# change to UCSC style since the data was mapped to hg19
seqlevelsStyle(annotations) <- 'UCSC'
genome(annotations) <- "hg19"

# add the gene information to the object
Annotation(atac) <- annotations

gene.activities <- GeneActivity(atac)

# add the gene activity matrix to the Seurat object as a new assay and normalize it
atac[['RNA']] <- CreateAssayObject(counts = gene.activities)
atac <- NormalizeData(
  object = atac,
  assay = 'RNA',
  normalization.method = 'LogNormalize',
  scale.factor = median(atac$nCount_RNA)
)

DefaultAssay(atac) <- 'RNA'

transfer.anchors <- FindTransferAnchors(
  reference = rna,
  query = atac,
  reduction = 'cca'
)

predicted.labels <- TransferData(
  anchorset = transfer.anchors,
  refdata = rna$celltype,
  weight.reduction = atac[['lsi']],
  dims = 2:30
)

atac <- AddMetaData(object = atac, metadata = predicted.labels)