ncborcherding / scRepertoire

A toolkit for single-cell immune profiling
https://www.borch.dev/uploads/screpertoire/
MIT License
301 stars 49 forks source link

combineExpression Error: all cells in assays must be present in the Seurat object #251

Closed kkearns13 closed 1 year ago

kkearns13 commented 1 year ago

I've been trying to look for a similar error online but haven't found anything so far... Apologies if I've missed something!

I am trying to use scRepertoire with a Seurat v5 object and have been having issues with the combineExpression function. I am running into this error:

gd.seurat <- combineExpression(gd_dat, seurat,
                               cloneCall="gene",
                               group.by = "sample",
                               proportion = FALSE,
                               cloneTypes=c(Single=1, Small=5, Medium=20,
                                            Large=100, Hyperexpanded=500))
Error in validObject(object = x) : 
  invalid class “Seurat” object: 1: all cells in assays must be present in the Seurat object
invalid class “Seurat” object: 2: all cells in assays must be present in the Seurat object
invalid class “Seurat” object: 3: all cells in assays must be present in the Seurat object
invalid class “Seurat” object: 4: All cells in reductions must be present in the Seurat object
invalid class “Seurat” object: 5: All cells in reductions must be present in the Seurat object
invalid class “Seurat” object: 6: All cells in reductions must be present in the Seurat object
invalid class “Seurat” object: 7: All cells in reductions must be present in the Seurat object
invalid class “Seurat” object: 8: all cells in graphs must be present in the Seurat object
invalid class “Seurat” object: 9: all cells in graphs must be present in the Seurat object

I followed essentially what I did previously (which worked, albeit with an older version of Seurat) with a different dataset - I've reconstructed a TCR repertoire with TRUST4, added the correct suffixes for the barcodes so they match those in the Seurat object, ran createHTOContigList on the integrated object (with barcodes fixed). All barcodes in gd_dat are found in seurat@meta.data, and all of the Seurat assays have the same number of cells. This is what the Seurat object looks like:

> seurat
An object of class Seurat 
44712 features across 142054 samples within 3 assays 
Active assay: SCT (19700 features, 5872 variable features)
 3 layers present: scale.data, data, counts
 2 other assays present: RNA, HTO
 4 dimensional reductions calculated: pca, umap, integrated.rpca, umap.rpca

Any advice would be much appreciated!

ncborcherding commented 1 year ago

Hey Kendall,

scRepertoire has not yet been updated for v5 Seurat. Based on the error, my guess is that the structure of a Seurat Object has changed subtly that breaks the final addition of the contig information to the meta data. I will mark this as a feature request.

In the mean time, a hack to get the data to work would be:

combined.df <- dplyr::bind_rows(combined)
seuratObj <- AddMetaData(combined, combined.df)

The major drawback of this approach would be there is no leveling for "hyperexpanded", "large", etc.

Nick

ncborcherding commented 1 year ago

Hey Kendell,

I tested v5 today with the example data and can't replicate the error - could you provide the data set you are using to help troubleshoot (you can email me a link. If not I will keep trying from my end.

Nick

kkearns13 commented 1 year ago

Hi Nick,

Thank you for working on this over the weekend! I spent some time trying to troubleshoot using the code you shared above and tried some more things but finally I tried using the cell barcodes from the Seurat object as is (ex: AAACCTGAGATCGGGT-1_1, GACGTGCCAGACGCCT-1_6). This ended up working!

I realized the way I was renaming the cell barcodes wasn't working with the code. I originally was using gsub to remove the 1_ from each of the barcodes directly, but using RenameCells instead or leaving the barcodes as is worked. Not sure why I decided to do it that way, but hopefully this helps someone with a similar issue.

Thanks again for your help!