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"
)
## 06:22:17 UMAP embedding parameters a = 0.583 b = 1.334
## 06:22:17 Read 10250 rows and found 30 numeric columns
## 06:22:17 Using Annoy for neighbor search, n_neighbors = 30
## 06:22:17 Building Annoy index with metric = cosine, n_trees = 50
## 0%   10   20   30   40   50   60   70   80   90   100%
## [----|----|----|----|----|----|----|----|----|----|
## **************************************************|
## 06:22:18 Writing NN index file to temp file /tmp/Rtmp5J9pWv/file371b0548b0f22
## 06:22:18 Searching Annoy index using 64 threads, search_k = 3000
## 06:22:18 Annoy recall = 100%
## 06:22:20 Commencing smooth kNN distance calibration using 64 threads
## 06:22:21 Initializing from normalized Laplacian + noise
## 06:22:22 Commencing optimization for 200 epochs, with 469734 positive edges
## 06:22:27 Optimization finished
## 06:22:27 Creating temp model dir /tmp/Rtmp5J9pWv/dir371b0633323f2
## 06:22:27 Creating dir /tmp/Rtmp5J9pWv/dir371b0633323f2
## 06:22:29 Changing to /tmp/Rtmp5J9pWv/dir371b0633323f2
## 06:22:29 Creating /corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme1/Embeddings/Save-Uwot-UMAP-Params-Harmony-371b01a6b5f6d-Date-2022-12-23_Time-06-22-27.tar
p3 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAPHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b07f01f7ad-Date-2022-12-23_Time-06-22-29.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-371b07f01f7ad-Date-2022-12-23_Time-06-22-29.log
p4 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "UMAPHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b04203700a-Date-2022-12-23_Time-06-22-31.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-371b04203700a-Date-2022-12-23_Time-06-22-31.log
ggAlignPlots(p3, p4, type = "h")

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 5.31 seconds (sparsity = 0.013600)!
## Learning embedding...
## Iteration 50: error is 95.931305 (50 iterations in 5.05 seconds)
## Iteration 100: error is 86.055628 (50 iterations in 4.87 seconds)
## Iteration 150: error is 84.054710 (50 iterations in 4.62 seconds)
## Iteration 200: error is 83.784196 (50 iterations in 4.68 seconds)
## Iteration 250: error is 83.662431 (50 iterations in 4.69 seconds)
## Iteration 300: error is 3.466283 (50 iterations in 4.65 seconds)
## Iteration 350: error is 3.199987 (50 iterations in 4.37 seconds)
## Iteration 400: error is 3.061191 (50 iterations in 4.31 seconds)
## Iteration 450: error is 2.972080 (50 iterations in 4.32 seconds)
## Iteration 500: error is 2.909455 (50 iterations in 4.35 seconds)
## Iteration 550: error is 2.862018 (50 iterations in 4.35 seconds)
## Iteration 600: error is 2.826252 (50 iterations in 4.36 seconds)
## Iteration 650: error is 2.797812 (50 iterations in 4.36 seconds)
## Iteration 700: error is 2.774407 (50 iterations in 4.38 seconds)
## Iteration 750: error is 2.755503 (50 iterations in 4.39 seconds)
## Iteration 800: error is 2.739209 (50 iterations in 4.41 seconds)
## Iteration 850: error is 2.725232 (50 iterations in 4.40 seconds)
## Iteration 900: error is 2.714177 (50 iterations in 4.41 seconds)
## Iteration 950: error is 2.705204 (50 iterations in 4.39 seconds)
## Iteration 1000: error is 2.697724 (50 iterations in 4.41 seconds)
## Fitting performed in 89.76 seconds.
p3 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "TSNEHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b03b63fa86-Date-2022-12-23_Time-06-23-05.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-371b03b63fa86-Date-2022-12-23_Time-06-23-05.log
p4 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "TSNEHarmony")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b0458d939e-Date-2022-12-23_Time-06-23-07.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-371b0458d939e-Date-2022-12-23_Time-06-23-07.log
ggAlignPlots(p3, p4, type = "h")

To save an editable vectorized version of this plot, we use plotPDF().

plotPDF(p1,p2,p3,p4, name = "Plot-TSNE2Harmony-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
## Plotting Ggplot!
## Plotting Ggplot!
## Plotting Ggplot!
## Plotting Ggplot!