seurat v3.0 merge two objects with different number of features

Created on 12 Jun 2019  路  1Comment  路  Source: satijalab/seurat

hello,
Before I was trying to merge two seurat objects, I have already filtered cells and features during createseuratobject function,which means they have different number of features. After I use merge function to merge them toghter, I found that the new seurat object have more features than any of those two objects.
I guess that because the new object contains all unique features of the two objects, but I am not sure if it is OK to do so for my further analysis.
what did merge function operate when it merge objects with different rows?
Is there any another way I can merge two objects with filtered cells because I can not find a way to filter cells after I merge them?
I am a beginner at seurat, sorry if my question is so naive.
Here are my codes:
================= set up Object1 ================
Object1.data <- Read10X(data.dir = "/Users/m/N1",gene.column = 2, unique.features = TRUE)
Object1 <- CreateSeuratObject(counts = Object1.data, project = "P1_N1", min.cells = 3,min.features = 200)
Object1

An object of class Seurat

15720 features across 3091 samples within 1 assay

Active assay: RNA (15720 features)

================= set up M2 objects================
Object2.data <- Read10X(data.dir = "/Users/m/N2",gene.column = 2, unique.features = TRUE)
Object2<- CreateSeuratObject(counts = Object2.data, project = "P1_N2", min.cells = 3, min.features = 200)
Object1

An object of class Seurat

15499 features across 2531 samples within 1 assay

Active assay: RNA (15720 features)

================= merge two objects================
combined <- merge(Object1, y = Object2, add.cell.ids = c("N1", "N2"), project = "P1")
combined

An object of class Seurat

16190 features across 5625 samples within 1 assay

Active assay: RNA (15720 features)

Most helpful comment

Hi @ananl25,

Merging Seurat objects will add zero counts for features present in one object but not another. If you're worried about these zero counts, you can always subset your Seurat object to only those features present in both objects.

> # Split cells into two groups
> # This is only to show how I generate p1 and p2
> cc = split(colnames(pbmc_small), f = sample(c(TRUE, FALSE), size = ncol(pbmc_small), replace = TRUE))
> # Split features into two groups
> f1 <- sample(rownames(pbmc_small), size = 80, replace = FALSE)
> f2 <- sample(rownames(pbmc_small), size = 75, replace = FALSE)
> # Split pbmc_small into two objects of differing features and cells
> p1 <- pbmc_small[f1, cc[[1]]]
> p2 <- pbmc_small[f2, cc[[2]]]
> p1
An object of class Seurat 
80 features across 41 samples within 1 assay 
Active assay: RNA (80 features)
 2 dimensional reductions calculated: pca, tsne
> p2
An object of class Seurat 
75 features across 39 samples within 1 assay 
Active assay: RNA (75 features)
 2 dimensional reductions calculated: pca, tsne
> # Find common features between the two objects
> # This is where you'll start for your objects
> common.features <- intersect(rownames(p1), rownames(p2))
> length(x = common.features)
[1] 21
> # Merge p1 and p2 based on common features only
> merge(p1[common.features, ], p2[common.features, ])
An object of class Seurat 
21 features across 80 samples within 1 assay 
Active assay: RNA (21 features)

>All comments

Hi @ananl25,

Merging Seurat objects will add zero counts for features present in one object but not another. If you're worried about these zero counts, you can always subset your Seurat object to only those features present in both objects.

> # Split cells into two groups
> # This is only to show how I generate p1 and p2
> cc = split(colnames(pbmc_small), f = sample(c(TRUE, FALSE), size = ncol(pbmc_small), replace = TRUE))
> # Split features into two groups
> f1 <- sample(rownames(pbmc_small), size = 80, replace = FALSE)
> f2 <- sample(rownames(pbmc_small), size = 75, replace = FALSE)
> # Split pbmc_small into two objects of differing features and cells
> p1 <- pbmc_small[f1, cc[[1]]]
> p2 <- pbmc_small[f2, cc[[2]]]
> p1
An object of class Seurat 
80 features across 41 samples within 1 assay 
Active assay: RNA (80 features)
 2 dimensional reductions calculated: pca, tsne
> p2
An object of class Seurat 
75 features across 39 samples within 1 assay 
Active assay: RNA (75 features)
 2 dimensional reductions calculated: pca, tsne
> # Find common features between the two objects
> # This is where you'll start for your objects
> common.features <- intersect(rownames(p1), rownames(p2))
> length(x = common.features)
[1] 21
> # Merge p1 and p2 based on common features only
> merge(p1[common.features, ], p2[common.features, ])
An object of class Seurat 
21 features across 80 samples within 1 assay 
Active assay: RNA (21 features)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

htc502 picture htc502  路  3Comments

milanmlft picture milanmlft  路  3Comments

sarahwajid picture sarahwajid  路  3Comments

kathirij picture kathirij  路  3Comments

mvalenzuelav picture mvalenzuelav  路  3Comments