Chapter 13 Second Round Clustering Based on Peak Matrix

library(ArchR)
library(magrittr)
library(tidyverse)
set.seed(1)

13.1 Description

Second round clustering based on the union peak set merged from first-round-cluster peaks: * generate pseudo-bulk replicates per cluster * call peaks per cluster and merge peaks * iterative LSI and clustering based on peak matrix

PS: due to the down-sampling, the demo dataset has limited cell number, so the numbers of cells per pseudo-bulk replicates are small

13.2 Set env and load arrow project

## Section: set default para
##################################################
addArchRThreads(threads = 16) # setting default number of parallel threads


## Section: load object
##################################################
proj <- loadArchRProject(path = "data/ArchR/ArrowProject/Merged/")

13.3 Call peaks

## create pseudo-bulk replicates
proj <- addGroupCoverages(
  ArchRProj = proj,
  groupBy = "Clusters",
  minCells = 15,
  maxCells = 700, 
  force = TRUE
)

## call peaks
proj <- addReproduciblePeakSet(
  ArchRProj = proj,
  groupBy = "Clusters",
  genomeSize = 2.7e09,
  pathToMacs2 = "/lustre/user/liclab/liuyt/software/anaconda2/bin/macs2",
  force = TRUE
)

## calculate peak matrix
proj <- addPeakMatrix(proj, binarize = TRUE, force = TRUE)

13.4 Iterative LSI

## Section: LSI on peaks
##################################################
proj <- addIterativeLSI(
  ArchRProj = proj,
  useMatrix = "PeakMatrix",
  name = "IterativeLSI_peak",
  varFeatures = 25000,
  force = TRUE
)

13.5 Add embedding

## Section: umap
##################################################
proj <- addUMAP(
    ArchRProj = proj,
    reducedDims = "IterativeLSI_peak",
    name = "UMAP_peak",
    nNeighbors = 30,
    force = TRUE
  )

13.6 Add clusters based on different resolutions

proj <- addClusters(input = proj, reducedDims = "IterativeLSI_peak", name = "Cluster_peak_res.0.8", resolution = 0.8)
proj <- addClusters(input = proj, reducedDims = "IterativeLSI_peak", name = "Cluster_peak_res.0.6", resolution = 0.6)
proj <- addClusters(input = proj, reducedDims = "IterativeLSI_peak", name = "Cluster_peak_res.0.4", resolution = 0.4)

13.7 Save arrow project

saveArchRProject(ArchRProj = proj)