seurat icon indicating copy to clipboard operation
seurat copied to clipboard

Got different harmony integration results

Open lindawillli opened this issue 10 months ago • 3 comments

I performed harmony integration on the same dataset twice in the same environment with the same parameters, but got different results.

The first time I ran the following code.

combined <- readRDS("v5_PCA.rds") combined <- FindNeighbors(combined, dims = 1:30, reduction = "pca") combined <- FindClusters(combined, resolution = 0.5, cluster.name = "unintegrated_clusters") combined <- RunUMAP(combined, dims = 1:30, reduction = "pca", reduction.name = "umap.unintegrated") sample <- c("A","B","C") combined$platform <- ifelse(combined$orig.ident %in% sample,'one','two') #Harmony combined <- IntegrateLayers(object = combined, method = HarmonyIntegration, orig.reduction = "pca", new.reduction = "harmony") combined <- FindNeighbors(combined, reduction = "harmony", dims = 1:30) combined <- FindClusters(combined, resolution = 0.5, cluster.name = "harmony_clusters") saveRDS(combined, file = "v5_mincell3_harmony05_merge44.rds")

This time Harmony converged after 5 iterations, and I got 32 clusters.

The second time I ran the following code.

combined <- readRDS("v5_PCA.rds") # This is the file after pca combined <- FindNeighbors(combined, dims = 1:30, reduction = "pca") combined <- FindClusters(combined, resolution = c(0.3,0.5,1,1.5), cluster.name = c("unintegrated_clusters_03","unintegrated_clusters_05","unintegrated_clusters_1","unintegrated_clusters_15")) sample <- c("A","B","C") combined$platform <- ifelse(combined$orig.ident %in% sample,'one','two') High <- c("A","D") combined$stage <- ifelse(combined$orig.ident %in% High,'H','L')

cluster_name = c("unintegrated_clusters_03","unintegrated_clusters_05","unintegrated_clusters_1","unintegrated_clusters_15") for (i in cluster_name) { Idents(object = combined) <- i combined <- RunUMAP(combined, dims = 1:30, reduction = "pca", reduction.name = paste("umap",i,sep = "_")) }

CCA

combined <- IntegrateLayers(object = combined, method = CCAIntegration, orig.reduction = "pca", new.reduction = "integrated.cca")

Harmony

combined <- IntegrateLayers(object = combined, method = HarmonyIntegration, orig.reduction = "pca", new.reduction = "harmony")

RPCA

combined <- IntegrateLayers(object = combined, method = RPCAIntegration, orig.reduction = "pca", new.reduction = "integrated.rpca")

combined <- FindNeighbors(combined, reduction = "integrated.cca", dims = 1:30) combined <- FindClusters(combined, resolution = c(0.3,0.5,1,1.5), cluster.name = c("cca_clusters_03","cca_clusters_05","cca_clusters_1","cca_clusters_15"))

combined <- FindNeighbors(combined, reduction = "integrated.rpca", dims = 1:30) combined <- FindClusters(combined, resolution = c(0.3,0.5,1,1.5), cluster.name = c("rpca_clusters_03","rpca_clusters_05","rpca_clusters_1","rpca_clusters_15"))

combined <- FindNeighbors(combined, reduction = "harmony", dims = 1:30) combined <- FindClusters(combined, resolution = c(0.3,0.5,1,1.5), cluster.name = c("harmony_clusters_03","harmony_clusters_05","harmony_clusters_1","harmony_clusters_15"))

saveRDS(combined, file = "v5_mincell3_merge44_06_Integrated.rds")

This time Harmony converged after 4 iterations, and I got 29 clusters (resolution = 0.5).

I wondered why I got different results. I would appreciate it if you could help me find the problem.

lindawillli avatar Apr 10 '24 13:04 lindawillli

Hi - none of the steps you additionally perform in method 2 should be altering results beyond what is expected from the stochastic nature of the algorithm; have you checked in the UMAP how the clusters have changed?

zskylarli avatar Apr 19 '24 20:04 zskylarli

Many thanks for your reply! I have checked the UMAPs I got after the harmony procedure. They are similar. image So, it is the stochastic nature of the algorithm that caused these differences, and setting seed before running harmony may help me get the same result. Is this accurate?

lindawillli avatar May 07 '24 10:05 lindawillli

I am experiencing the same issue. Running IntegrateLayers(method = HarmonyIntegration) leads to different results each time I run it. I also noticed that Seurat doesn't log the parameters used for IntegrateLayer in the commands slot, it would be really nice to have it saved there.

massisnascimento avatar Jun 13 '24 22:06 massisnascimento