creating assay for seurat object
1
0
Entering edit mode
12 weeks ago
Sky ▴ 10

I have tried the below code to try and get an assay from one object and placing it into another:

adt.data <- GetAssayData(object = atac.object[['peaks']], slot = 'data')
rna.object[["peaks"]] <- CreateAssayObject(data = adt.data )

but I get the error:

Error in '[[<-': Cannot add new cells with [[<-
Backtrace:
1.methods (local) '[[<-'('*tmp*', "peaks", value = '<Assay[,5532]>')
2. SeuratObject (local) '[[<-'('*tmp*, "peaks", value= '<Assay[,5532]>')

I have also tried : rna.object[['peaks']] <- atac.object[['ATAC']] but I receive the same error.

Does anyone have any suggestions? I believe I understand the error message itself but I have ran similar lines of code before and it has worked

assay seurat • 538 views
ADD COMMENT
0
Entering edit mode
12 weeks ago
CJP-OHRI ▴ 30

This error is occurring because there are cells (cell barcodes) in your atac.object that aren't in the rna.object (to state the obvious). With the assumption that the atac.object and rna.object come from the same single cell (multiome?) data set and contain data from the same cells you could try the following approach.

# Confirm that the two objects contain the same cell barcodes
ncol(rna.object)
ncol(atac.object)
sum(colnames(rna.object) %in% colnames(atac.object))

Ideally you'll find that the atac.object has (a few) more cells than the rna.object and that all the cells in the rna.object are present in the atac.object (_i.e._ the first number is slightly smaller than the second, but the first and third numbers are equal). If this is the case you can proceed by adding an ATAC assay that contains only the cells present in the rna.object by subsetting the ATAC data set. I've used your example code for CreateAssayObject(), but in this instance I would probably use CreateChromatinAssay() instead.

# Create new assay, and subset to add to rna.assay
adt.data <- GetAssayData(object = atac.object[['peaks']], slot = 'data')
atac.assay <- CreateAssayObject(data = adt.data )
rna.object[["peaks"]] <- subset(atac.assay,cells=colnames(rna.assay))

Again, this is only a valid approach if the data are derived from the same cells - you could use this approach to combine two completely unrelated data sets if they happen to have the same cell barcodes, and any of the results derived would be meaningless.

ADD COMMENT

Login before adding your answer.

Traffic: 1793 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