satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.27k stars 910 forks source link

Combining two seurat objects by row cell id (not merge) #8184

Closed ruggerobelluomo closed 3 months ago

ruggerobelluomo commented 10 months ago

Hi everyone,

I am trying to create a Seurat object that contains the information spread across two Seurat objects. The tewo seurat object have matching cell IDs but in different order.

My two objects look like this:

head(alldata.integrated,2) orig.ident nCount_RNA nFeature_RNA condition sex batch percent.mt oc1_AAACCCAAGTCACGCC-1 B3MOC 697 533 OC M B3 0.7173601 oc1_AAACCCAAGTTCATGC-1 B3MOC 2576 1030 OC M B3 0.4270186

head(all_seurat_spliced_unspliced,2) orig.ident nCount_spliced nFeature_spliced nCount_unspliced oc1_AAACCCAAGTCACGCC-1 B3MOC 6262.219 2155 6262.219 oc1_AAACCCAAGTTCATGC-1 B3MOC 7154.890 2357 7154.890

The resulting object should be something like:

head(data.combined,2) orig.ident nCount_RNA nFeature_RNA condition sex batch percent.mt nCount_spliced nFeature_spliced oc1_AAACCCAAGTCACGCC-1 B3MOC 697 533 OC M B3 0.7173601 6262.219 2155
oc1_AAACCCAAGTTCATGC-1 B3MOC 2576 1030 OC M B3 0.4270186 7154.890 2357

How can I achieve this? The merge function doesnt add the columns instead creates new rows with new unique cell IDs which is not what I would like (even if I pass the merge.data=T still the same). Is it possible to just reorder the cells in object 2 as cells in object1?

Thanks for the help!

Info: platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 3.1
year 2023
month 06
day 16
svn rev 84548
language R
version.string R version 4.3.1 (2023-06-16 ucrt) nickname Beagle Scouts

for (package in (.packages())){

  • print(paste0(package, " ",packageVersion(package)))
  • } [1] "Seurat 5.0.1" [1] "SeuratObject 5.0.1" [1] "sp 2.1.2" [1] "dplyr 1.1.4" [1] "biomaRt 2.56.1" [1] "scater 1.28.0" [1] "ggplot2 3.4.4" [1] "scran 1.28.2" [1] "scuttle 1.10.3" [1] "data.table 1.14.8" [1] "reticulate 1.34.0" [1] "SingleCellExperiment 1.22.0" [1] "celldex 1.10.1" [1] "sctransform 0.4.1" [1] "SingleR 2.2.0" [1] "SummarizedExperiment 1.30.2" [1] "Biobase 2.60.0" [1] "GenomicRanges 1.52.0" [1] "GenomeInfoDb 1.36.3" [1] "IRanges 2.34.1" [1] "S4Vectors 0.38.1" [1] "BiocGenerics 0.46.0" [1] "stats4 4.3.1" [1] "MatrixGenerics 1.12.3" [1] "matrixStats 1.1.0" [1] "pheatmap 1.0.12" [1] "SeuratDisk 0.0.0.9020" [1] "SeuratWrappers 0.3.1" [1] "cowplot 1.1.1" [1] "stats 4.3.1" [1] "graphics 4.3.1" [1] "grDevices 4.3.1" [1] "utils 4.3.1" [1] "datasets 4.3.1" [1] "methods 4.3.1" [1] "base 4.3.1"
ruggerobelluomo commented 10 months ago

Maybe this helps as well to see the structure of the two objects

alldata.integrated An object of class Seurat 34285 features across 125586 samples within 2 assays Active assay: integrated (2000 features, 2000 variable features) 2 layers present: data, scale.data 1 other assay present: RNA 2 dimensional reductions calculated: pca, umap

all_seurat_spliced_unspliced An object of class Seurat 108896 features across 125586 samples within 2 assays Active assay: spliced (54448 features, 0 variable features) 16 layers present: counts.B2FYH, counts.B3MOC, counts.B3MYH, counts.B4FYH, counts.B5MOC, counts.B5MOH, counts.B5MYC, counts.B5MYH, counts.B6FOC, counts.B6FOH, counts.B6FYC, counts.B6FYC_2, counts.B7MOC, counts.B7MOH, counts.B7MYC, counts.B8FOH 1 other assay present: unspliced

samuel-marsh commented 10 months ago

Hi,

Not member of dev team but hopefully can be helpful. Can you explain why you want to merge cells with the same ids from 2 objects? Might help to understand goal better in order to help you.

Thanks, Sam

ruggerobelluomo commented 10 months ago

Hey @samuel-marsh,

thanks for your reply. I need to perform RNA velocity analysis and I do not have the information about spliced vs unspliced transcripts in my integrated object. So I counted spliced and unspliced transcripts with Salmon and I created a new objefct with spliced and unspliced assays. Now, I need to add this info to my integrated data to preform RNA velocity analysis in my clusters, hope it is clear enough...

igrabski commented 10 months ago

Hi Ruggero, the merge function is intended to combine Seurat objects containing two different sets of cells, which is why it is outputting an object that has renamed the cells uniquely. If these two objects represent information for the exact same cells and you just want to combine them into one object, I would recommend just adding the relevant metadata and assays from one of your objects to the other. For example, you can extract metadata and assays from one of the objects, and add it to the other using the AddMetaData and CreateAssayObject functions.

ruggerobelluomo commented 9 months ago

Hi @igrabski, I am using the CreateAssayObject as you suggested but in seurat v5 the data structure changed and I cannot find anymore where the data is. Before I could do: alldata.integrated[["unspliced"]] <- CreateAssayObject(data = renamed.assay@assays$unspliced@data)

but now I cannot find it anymore in the new Seurat version. Do you know where I can find it?

igrabski commented 9 months ago

Can you show the structure of your object containing the unspliced data (renamed.assay) and how you created it?

igrabski commented 3 months ago

Closing this since there has been no response -- please feel free to open a new issue if the problem persists!