8.3 Dimensionality Reduction After Harmony
In a previous chapter, we performed batch correction using Harmony via the addHarmony()
function, creating a reducedDims
object named “Harmony”. We can assess the effects of Harmony by visualizing the embedding using UMAP or t-SNE and comparing this to the embeddings visualized in the previous sections for iterative LSI.
Repeating the UMAP embedding with the same parameters but for the “Harmony” reducedDims
object:
projHeme2 <- addUMAP(
ArchRProj = projHeme2,
reducedDims = "Harmony",
name = "UMAPHarmony",
nNeighbors = 30,
minDist = 0.5,
metric = "cosine"
)
## 01:07:36 UMAP embedding parameters a = 0.583 b = 1.334
## 01:07:36 Read 10250 rows and found 30 numeric columns
## 01:07:36 Using Annoy for neighbor search, n_neighbors = 30
## 01:07:36 Building Annoy index with metric = cosine, n_trees = 50
## 0% 10 20 30 40 50 60 70 80 90 100%
## [----|----|----|----|----|----|----|----|----|----|
## **************************************************|
## 01:07:36 Writing NN index file to temp file /tmp/RtmpCdKDaq/file923d7b457
## 01:07:36 Searching Annoy index using 12 threads, search_k = 3000
## 01:07:37 Annoy recall = 100%
## 01:07:38 Commencing smooth kNN distance calibration using 12 threads with target n_neighbors = 30
## 01:07:40 Initializing from normalized Laplacian + noise (using RSpectra)
## 01:07:40 Commencing optimization for 200 epochs, with 470210 positive edges
## 01:07:44 Optimization finished
## 01:07:44 Creating temp model dir /tmp/RtmpCdKDaq/dir9102aa005
## 01:07:44 Creating dir /tmp/RtmpCdKDaq/dir9102aa005
## 01:07:56 Changing to /tmp/RtmpCdKDaq/dir9102aa005
## 01:07:56 Creating /workspace/ArchR/ArchR_Website_Testing/bookdown/Save-ProjHeme1/Embeddings/Save-Uwot-UMAP-Params-Harmony-944036e93-Date-2025-02-06_Time-01-07-44.721748.tar
p3 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAPHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-9a577cc-Date-2025-02-06_Time-01-07-58.776653.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-9a577cc-Date-2025-02-06_Time-01-07-58.776653.log
p4 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "UMAPHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-9667e5148-Date-2025-02-06_Time-01-08-00.101279.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-9667e5148-Date-2025-02-06_Time-01-08-00.101279.log
To save an editable vectorized version of this plot, we use plotPDF()
.
plotPDF(p1,p2,p3,p4, name = "Plot-UMAP2Harmony-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
## Plotting Ggplot!
## Plotting Ggplot!
## Plotting Ggplot!
## Plotting Ggplot!
And the same for t-SNE:
projHeme2 <- addTSNE(
ArchRProj = projHeme2,
reducedDims = "Harmony",
name = "TSNEHarmony",
perplexity = 30
)
## Read the 10250 x 30 data matrix successfully!
## OpenMP is working. 8 threads.
## Using no_dims = 2, perplexity = 30.000000, and theta = 0.500000
## Computing input similarities...
## Building tree...
## - point 10000 of 10250
## Done in 3.96 seconds (sparsity = 0.013643)!
## Learning embedding...
## Iteration 50: error is 95.902970 (50 iterations in 2.25 seconds)
## Iteration 100: error is 87.051912 (50 iterations in 2.35 seconds)
## Iteration 150: error is 84.526702 (50 iterations in 2.27 seconds)
## Iteration 200: error is 84.307969 (50 iterations in 2.23 seconds)
## Iteration 250: error is 84.304736 (50 iterations in 2.19 seconds)
## Iteration 300: error is 3.461251 (50 iterations in 2.22 seconds)
## Iteration 350: error is 3.197965 (50 iterations in 2.14 seconds)
## Iteration 400: error is 3.059166 (50 iterations in 2.13 seconds)
## Iteration 450: error is 2.969836 (50 iterations in 2.13 seconds)
## Iteration 500: error is 2.906957 (50 iterations in 2.10 seconds)
## Iteration 550: error is 2.861397 (50 iterations in 2.12 seconds)
## Iteration 600: error is 2.825782 (50 iterations in 2.14 seconds)
## Iteration 650: error is 2.797092 (50 iterations in 2.13 seconds)
## Iteration 700: error is 2.773688 (50 iterations in 2.10 seconds)
## Iteration 750: error is 2.754990 (50 iterations in 2.09 seconds)
## Iteration 800: error is 2.739997 (50 iterations in 2.11 seconds)
## Iteration 850: error is 2.728881 (50 iterations in 2.14 seconds)
## Iteration 900: error is 2.720387 (50 iterations in 2.09 seconds)
## Iteration 950: error is 2.713294 (50 iterations in 2.11 seconds)
## Iteration 1000: error is 2.708060 (50 iterations in 2.08 seconds)
## Fitting performed in 43.13 seconds.
p3 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "TSNEHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-9e59fa7-Date-2025-02-06_Time-01-08-17.156208.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-9e59fa7-Date-2025-02-06_Time-01-08-17.156208.log
p4 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "TSNEHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-96198d9ca-Date-2025-02-06_Time-01-08-18.406349.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-96198d9ca-Date-2025-02-06_Time-01-08-18.406349.log
To save an editable vectorized version of this plot, we use plotPDF()
.