Contents

library(COTAN)
library(zeallot)
library(rlang)
library(data.table)
library(Rtsne)
library(qpdf)
library(GEOquery)

options(parallelly.fork.enable = TRUE)

0.1 Introduction

This tutorial contains the same functionalities as the first release of the COTAN tutorial but done using the new and updated functions.

0.2 Get the data-set

Download the data-set for "mouse cortex E17.5".

dataDir <- tempdir()

GEO <- "GSM2861514"
fName <- "GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz"

dataSetFile <- file.path(dataDir, GEO, fName)

dir.create(file.path(dataDir, GEO), showWarnings = FALSE)

if (!file.exists(dataSetFile)) {
  getGEOSuppFiles(GEO, makeDirectory = TRUE,
                  baseDir = dataDir, fetch_files = TRUE,
                  filter_regex = fName)
}
#>                                                                              size
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz 1509523
#>                                                                           isdir
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz FALSE
#>                                                                           mode
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz  644
#>                                                                                         mtime
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz 2024-06-17 16:59:08
#>                                                                                         ctime
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz 2024-06-17 16:59:08
#>                                                                                         atime
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz 2024-06-17 16:59:08
#>                                                                            uid
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz 1002
#>                                                                            gid
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz 1002
#>                                                                               uname
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz biocbuild
#>                                                                              grname
#> /tmp/RtmpSvLaxC/GSM2861514/GSM2861514_E175_Only_Cortical_Cells_DGE.txt.gz biocbuild

sample.dataset <- read.csv(dataSetFile, sep = "\t", row.names = 1L)

Define a directory where the output will be stored.

outDir <- dataDir

# Log-level 2 was chosen to showcase better how the package works
# In normal usage a level of 0 or 1 is more appropriate
setLoggingLevel(2L)
#> Setting new log level to 2

# This file will contain all the logs produced by the package
# as if at the highest logging level
setLoggingFile(file.path(outDir, "vignette_v2.log"))
#> Setting log file to be: /tmp/RtmpSvLaxC/vignette_v2.log

message("COTAN uses the `torch` library when asked to `optimizeForSpeed`")
#> COTAN uses the `torch` library when asked to `optimizeForSpeed`
message("Run the command 'options(COTAN.UseTorch = FALSE)'",
        " in your session to disable `torch` completely!")
#> Run the command 'options(COTAN.UseTorch = FALSE)' in your session to disable `torch` completely!

# this command does check whether the torch library is properly installed
c(useTorch, deviceStr) %<-% COTAN:::canUseTorch(TRUE, "cuda")
#> While trying to load the `torch` library Error in doTryCatch(return(expr), name, parentenv, handler): The `torch` library is installed but the required additional libraries are not avalable yet
#> Warning in value[[3L]](cond): The `torch` library is installed, but might
#> require further initialization
#> Warning in value[[3L]](cond): Please look at the `torch` package installation
#> guide to complete the installation
#> Warning in COTAN:::canUseTorch(TRUE, "cuda"): Falling back to legacy
#> [non-torch] code.
if (useTorch) {
  message("The `torch` library is availble and ready to use")
  if (deviceStr == "cuda") {
    message("The `torch` library can use the `CUDA` GPU")
  } else {
    message("The `torch` library can only use the CPU")
    message("Please ensure you have the `OpenBLAS` libraries",
            " installed on the system")
  }
}

rm(useTorch, deviceStr)

1 Analytical pipeline

Initialize the COTAN object with the row count table and the metadata for the experiment.

cond <- "mouse_cortex_E17.5"

obj <- COTAN(raw = sample.dataset)
obj <- initializeMetaDataset(obj,
                             GEO = GEO,
                             sequencingMethod = "Drop_seq",
                             sampleCondition = cond)
#> Initializing `COTAN` meta-data

logThis(paste0("Condition ", getMetadataElement(obj, datasetTags()[["cond"]])),
        logLevel = 1L)
#> Condition mouse_cortex_E17.5

Before we proceed to the analysis, we need to clean the data. The analysis will use a matrix of raw UMI counts as the input. To obtain this matrix, we have to remove any potential cell doublets or multiplets, as well as any low quality or dying cells.

1.1 Data cleaning

We can check the library size (UMI number) with an empirical cumulative distribution function

ECDPlot(obj, yCut = 700L)

cellSizePlot(obj)
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_point()`).

genesSizePlot(obj)
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_point()`).

scatterPlot(obj)

During the cleaning, every time we want to remove cells or genes we can use the dropGenesCells()function.

Drop cells with too many reads as they are probably doublets or multiplets

cellsSizeThr <- 6000L
obj <- addElementToMetaDataset(obj, "Cells size threshold", cellsSizeThr)

cells_to_rem <- getCells(obj)[getCellsSize(obj) > cellsSizeThr]
obj <- dropGenesCells(obj, cells = cells_to_rem)

cellSizePlot(obj)
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_point()`).

To drop cells by gene number: high genes count might also indicate doublets…

genesSizeHighThr <- 3000L
obj <- addElementToMetaDataset(obj, "Num genes high threshold", genesSizeHighThr)

cells_to_rem <- getCells(obj)[getNumExpressedGenes(obj) > genesSizeHighThr]
obj <- dropGenesCells(obj, cells = cells_to_rem)

genesSizePlot(obj)

Drop cells with too low genes expression as they are probably dead

genesSizeLowThr <- 500L
obj <- addElementToMetaDataset(obj, "Num genes low threshold", genesSizeLowThr)

cells_to_rem <- getCells(obj)[getNumExpressedGenes(obj) < genesSizeLowThr]
obj <- dropGenesCells(obj, cells = cells_to_rem)

genesSizePlot(obj)

Cells with a too high percentage of mitochondrial genes are likely dead (or at the last problematic) cells. So we drop them!

c(mitPlot, mitSizes) %<-% mitochondrialPercentagePlot(obj, genePrefix = "^Mt")

mitPlot

mitPercThr <- 1.0
obj <- addElementToMetaDataset(obj, "Mitoc. perc. threshold", mitPercThr)

cells_to_rem <- rownames(mitSizes)[mitSizes[["mit.percentage"]] > mitPercThr]
obj <- dropGenesCells(obj, cells = cells_to_rem)

c(mitPlot, mitSizes) %<-% mitochondrialPercentagePlot(obj, genePrefix = "^Mt")

plot(mitPlot)

If we do not want to consider the mitochondrial genes we can remove them before starting the analysis.

genes_to_rem <- getGenes(obj)[grep("^Mt", getGenes(obj))]
cells_to_rem <- getCells(obj)[which(getCellsSize(obj) == 0L)]

obj <- dropGenesCells(obj, genes_to_rem, cells_to_rem)

We want also to log the current status.

logThis(paste("n cells", getNumCells(obj)), logLevel = 1L)
#> n cells 859

The clean() function estimates all the parameters for the data. Therefore, we have to run it again every time we remove any genes or cells from the data.

obj <- addElementToMetaDataset(obj, "Num drop B group", 0)

obj <- clean(obj)
#> Genes/cells selection done: dropped [4787] genes and [0] cells
#> Working on [12235] genes and [859] cells

c(pcaCellsPlot, pcaCellsData, genesPlot,
  UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(obj)
#> PCA: START
#> PCA: DONE
#> Hierarchical clustering: START
#> Hierarchical clustering: DONE

pcaCellsPlot

genesPlot

We can observe here that the red cells are really enriched in hemoglobin genes so we prefer to remove them. They can be extracted from the pcaCellsData object and removed.

cells_to_rem <- rownames(pcaCellsData)[pcaCellsData[["groups"]] == "B"]
obj <- dropGenesCells(obj, cells = cells_to_rem)

obj <- addElementToMetaDataset(obj, "Num drop B group", 1)

obj <- clean(obj)
#> Genes/cells selection done: dropped [5] genes and [0] cells
#> Working on [12230] genes and [855] cells

c(pcaCellsPlot, pcaCellsData, genesPlot,
  UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(obj)
#> PCA: START
#> PCA: DONE
#> Hierarchical clustering: START
#> Hierarchical clustering: DONE

pcaCellsPlot

To color the PCA based on nu (so the cells’ efficiency)

UDEPlot

UDE (color) should not correlate with principal components! This is very important.

The next part is used to remove the cells with efficiency too low.

plot(nuPlot)

We can zoom on the smallest values and, if COTAN detects a clear elbow, we can decide to remove the cells.

plot(zoomedNuPlot)

We also save the defined threshold in the metadata and re-run the estimation

UDELowThr <- 0.30
obj <- addElementToMetaDataset(obj, "Low UDE cells' threshold", UDELowThr)

obj <- addElementToMetaDataset(obj, "Num drop B group", 2)

cells_to_rem <- getCells(obj)[getNu(obj) < UDELowThr]
obj <- dropGenesCells(obj, cells = cells_to_rem)

Repeat the estimation after the cells are removed

obj <- clean(obj)
#> Genes/cells selection done: dropped [3] genes and [0] cells
#> Working on [12227] genes and [852] cells

c(pcaCellsPlot, pcaCellsData, genesPlot,
  UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(obj)
#> PCA: START
#> PCA: DONE
#> Hierarchical clustering: START
#> Hierarchical clustering: DONE

plot(pcaCellsPlot)

scatterPlot(obj)

logThis(paste("n cells", getNumCells(obj)), logLevel = 1L)
#> n cells 852

1.2 COTAN analysis

In this part, all the contingency tables are computed and used to get the statistics necessary to COEX evaluation and storing

obj <- proceedToCoex(obj, calcCoex = TRUE,
                     optimizeForSpeed = TRUE, cores = 6L,
                     saveObj = TRUE, outDir = outDir)
#> Cotan analysis functions started
#> Genes/cells selection done: dropped [0] genes and [0] cells
#> Working on [12227] genes and [852] cells
#> PCA: START
#> PCA: DONE
#> Hierarchical clustering: START
#> Hierarchical clustering: DONE
#> Estimate dispersion: START
#> Estimate dispersion: DONE
#> dispersion | min: -0.056854248046875 | max: 372.75 | % negative: 19.5469043919195
#> Cotan genes' coex estimation started
#> While trying to load the `torch` library Error in doTryCatch(return(expr), name, parentenv, handler): The `torch` library is installed but the required additional libraries are not avalable yet
#> Warning in canUseTorch(optimizeForSpeed, deviceStr): Falling back to legacy
#> [non-torch] code.
#> Calculate genes' coex (legacy): START
#> Warning in asMethod(object): sparse->dense coercion: allocating vector of size
#> 1.1 GiB
#> Total calculations elapsed time: 161.684590339661
#> Calculate genes' coex (legacy): DONE
#> Saving elaborated data locally at: /tmp/RtmpSvLaxC/mouse_cortex_E17.5.cotan.RDS

Since saveObj = TRUE, this step can be skipped as the COTAN object has already been saved in the outDir.

# saving the structure
saveRDS(obj, file = file.path(outDir, paste0(cond, ".cotan.RDS")))

1.3 Automatic run

It is also possible to run directly a single function if we don’t want to clean anything.

obj2 <- automaticCOTANObjectCreation(
  raw = sample.dataset,
  GEO = GEO,
  sequencingMethod = "Drop_seq",
  sampleCondition = cond,
  calcCoex = TRUE, cores = 6L, optimizeForSpeed = TRUE,
  saveObj = TRUE, outDir = outDir)

2 Analysis of the elaborated data

2.1 GDI

To calculate the GDI we can run:

quantP <- calculateGDI(obj)
#> Calculate GDI dataframe: START
#> Calculate GDI dataframe: DONE

head(quantP)
#>               sum.raw.norm      GDI exp.cells
#> 0610007N19Rik     3.332671 1.626640  2.230047
#> 0610007P14Rik     5.279001 1.349530 18.779343
#> 0610009B22Rik     4.733316 1.281530 11.619718
#> 0610009D07Rik     6.313149 1.364269 43.427230
#> 0610009E02Rik     2.590242 1.016320  1.173709
#> 0610009L18Rik     3.509489 1.256757  3.051643

obj <- storeGDI(obj, genesGDI = getColumnFromDF(quantP, "GDI"))

The next function can either plot the GDI for the dataset directly or use the pre-computed dataframe. It marks a 1.43 threshold (in red) and the two highest quantiles (in blue) by default. We can also specify some gene sets (three in this case) that we want to label explicitly in the GDI plot.

genesList <- list(
  "NPGs" = c("Nes", "Vim", "Sox2", "Sox1", "Notch1", "Hes1", "Hes5", "Pax6"),
  "PNGs" = c("Map2", "Tubb3", "Neurod1", "Nefm", "Nefl", "Dcx", "Tbr1"),
  "hk"   = c("Calm1", "Cox6b1", "Ppia", "Rpl18", "Cox7c", "Erh", "H3f3a",
             "Taf1", "Taf2", "Gapdh", "Actb", "Golph3", "Zfr", "Sub1",
             "Tars", "Amacr")
)

# needs to be recalculated after the changes in nu/dispersion above
#obj <- calculateCoex(obj, actOnCells = FALSE)

GDIPlot(obj, GDIIn = quantP, cond = cond,
        genes = genesList, GDIThreshold = 1.43)
#> GDI plot
#> Removed 0 low GDI genes (such as the fully-expressed) in GDI plot

The percentage of cells expressing the gene in the third column of this data-frame is reported.

2.2 Heatmaps

To perform the Gene Pair Analysis, we can plot a heatmap of the COEX values between two gene sets. We have to define the different gene sets (list.genes) in a list. Then we can choose which sets to use in the function parameter sets (for example, from 1 to 3). We also have to provide an array of the file name prefixes for each condition (for example, “mouse_cortex_E17.5”). In fact, this function can plot genes relationships across many different conditions to get a complete overview.

print(cond)
#> [1] "mouse_cortex_E17.5"
heatmapPlot(genesLists = genesList, sets = (1L:3L),
            conditions = c(cond), dir = outDir)
#> heatmap plot: START
#> calculating PValues: START
#> Get p-values on a set of genes on columns and on a set of genes on rows
#> calculating PValues: DONE
#> min coex: -0.475089564305104 max coex: 0.456662313361164

We can also plot a general heatmap of COEX values based on some markers like the following one.

genesHeatmapPlot(obj, primaryMarkers = c("Satb2", "Bcl11b", "Vim", "Hes1"),
                 pValueThreshold = 0.001, symmetric = TRUE)
#> calculating PValues: START
#> Get p-values genome wide on columns and genome wide on rows
#> calculating PValues: DONE

genesHeatmapPlot(obj, primaryMarkers = c("Satb2", "Bcl11b", "Fezf2"),
                 secondaryMarkers = c("Gabra3", "Meg3", "Cux1", "Neurod6"),
                 pValueThreshold = 0.001, symmetric = FALSE)

2.3 Get data tables

Sometimes we can also be interested in the numbers present directly in the contingency tables for two specific genes. To get them we can use two functions:

contingencyTables() to produce the observed and expected data

c(observedCT, expectedCT) %<-% contingencyTables(obj, g1 = "Satb2",
                                                      g2 = "Bcl11b")
print("Observed CT")
#> [1] "Observed CT"
observedCT
#>            Satb2.yes Satb2.no
#> Bcl11b.yes        47      149
#> Bcl11b.no        287      369
print("Expected CT")
#> [1] "Expected CT"
expectedCT
#>            Satb2.yes Satb2.no
#> Bcl11b.yes  82.78537 113.2154
#> Bcl11b.no  251.21413 404.7851
print("Coex")
#> [1] "Coex"
getGenesCoex(obj)["Satb2", "Bcl11b"]
#> [1] -0.2028008

Another useful function is getGenesCoex(). This can be used to extract the whole or a partial COEX matrix from a COTAN object.

# For the whole matrix
coex <- getGenesCoex(obj, zeroDiagonal = FALSE)
coex[1000L:1005L, 1000L:1005L]
#> 6 x 6 Matrix of class "dspMatrix"
#>             Ap3s1       Ap3s2        Ap4b1       Ap4e1       Ap4m1        Ap4s1
#> Ap3s1  0.91872636 -0.02997150  0.028065790 -0.02865879  0.01372465 -0.032402737
#> Ap3s2 -0.02997150  0.91460404 -0.045830195 -0.03058359 -0.05045147  0.095316128
#> Ap4b1  0.02806579 -0.04583020  0.907981121 -0.03650627  0.02944754  0.009052527
#> Ap4e1 -0.02865879 -0.03058359 -0.036506269  0.82865653 -0.04320115 -0.025651002
#> Ap4m1  0.01372465 -0.05045147  0.029447542 -0.04320115  0.91486865  0.047203683
#> Ap4s1 -0.03240274  0.09531613  0.009052527 -0.02565100  0.04720368  0.908152183
# For a partial matrix
coex <- getGenesCoex(obj, genes = c("Satb2", "Bcl11b", "Fezf2"))
coex[1000L:1005L, ]
#> 6 x 3 Matrix of class "dgeMatrix"
#>            Bcl11b        Fezf2       Satb2
#> Ap3s1 -0.04615274 -0.003499993  0.01372725
#> Ap3s2  0.01281042  0.026728977  0.01784518
#> Ap4b1  0.04062971  0.010720802 -0.03173374
#> Ap4e1 -0.05290965 -0.015074415 -0.03450185
#> Ap4m1  0.05811928  0.020840815 -0.03963970
#> Ap4s1 -0.06858325  0.006087159 -0.01587705

2.4 Establishing genes’ clusters

COTAN provides a way to establish genes’ clusters given some lists of markers

layersGenes <- list(
  "L1"   = c("Reln",   "Lhx5"),
  "L2/3" = c("Satb2",  "Cux1"),
  "L4"   = c("Rorb",   "Sox5"),
  "L5/6" = c("Bcl11b", "Fezf2"),
  "Prog" = c("Vim",    "Hes1")
)
c(gSpace, eigPlot, pcaGenesClDF, treePlot) %<-%
  establishGenesClusters(obj, groupMarkers = layersGenes,
                         numGenesPerMarker = 25L, kCuts = 5L)
#> Establishing gene clusters - START
#> Calculating gene co-expression space - START
#> calculating PValues: START
#> Get p-values on a set of genes on columns and genome wide on rows
#> calculating PValues: DONE
#> Number of selected secondary markers: 184
#> Calculating gene co-expression space - DONE
#> Establishing gene clusters - DONE

plot(eigPlot)

plot(treePlot)

genesUmapPl <- UMAPPlot(pcaGenesClDF[, sapply(pcaGenesClDF, is.numeric)],
                        clusters = getColumnFromDF(pcaGenesClDF, "hclust"),
                        elements = layersGenes,
                        title = "Genes' clusters UMAP Plot",
                        numNeighbors = 32, minPointsDist = 0.25)
#> UMAP plot
#> [2024-06-17 17:05:10.451636]  starting umap
#> [2024-06-17 17:05:10.499679]  creating graph of nearest neighbors
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by 'spam'
#> [2024-06-17 17:05:12.749471]  creating initial embedding
#> [2024-06-17 17:05:12.989942]  optimizing embedding
#> [2024-06-17 17:05:17.259892]  done

plot(genesUmapPl)

2.5 Uniform Clustering

It is possible to obtain a cell clusterization based on the concept of uniformity of expression of the genes across the cells. That is the cluster satisfies the null hypothesis of the COTAN model: the genes expression is not dependent on the cell in consideration.

There are two functions involved into obtaining a proper clusterization: the first is cellsUniformClustering that uses standard tools clusterization methods, but then discards and re-clusters any non-uniform cluster. Please not that the most important parameter for the users is the GDIThreshold: it defines how strict is the uniformity check, good values are between 1.42 (more strict) and 1.43 (less strict).

c(splitClusters, splitCoexDF) %<-%
  cellsUniformClustering(obj, GDIThreshold = 1.43, initialResolution = 0.8,
                         optimizeForSpeed = TRUE, cores = 6L,
                         saveObj = TRUE, outDir = outDir)
obj <- addClusterization(obj, clName = "split",
                         clusters = splitClusters, coexDF = splitCoexDF)

In the case one already has an existing clusterization, it is possible to calculate the DEA data.frame and add it to the COTAN object.

data("vignette.split.clusters", package = "COTAN")
splitClusters <- vignette.split.clusters[getCells(obj)]

splitCoexDF <- DEAOnClusters(obj, clusters = splitClusters)
#> Differential Expression Analysis - START
#> *********
#> Differential Expression Analysis - DONE

obj <- addClusterization(obj, clName = "split",
                         clusters = splitClusters, coexDF = splitCoexDF)

However since the algorithm that creates the clusters is not geared directly to achieve cluster uniformity, there might be clusters that can be merged back together and still be uniform. This is the purpose of the function mergeUniformCellsClusters that takes a clusterization and tries to merge cluster pairs after checking that together the pair forms a uniform cluster. In order to avoid the massive possible checks the function relies on a related distance the find the cluster pairs that will be most likely merged. Again the most important parameter for the users is the GDIThreshold, it is supposed to be the same as the one used to generate the clusterization in the first place, but if needed it can be slightly relaxed in order to reduce the number of clusters.

c(mergeClusters, mergeCoexDF) %<-%
  mergeUniformCellsClusters(obj, clusters = splitClusters, GDIThreshold = 1.43,
                            optimizeForSpeed = TRUE, cores = 6L,
                            saveObj = TRUE, outDir = outDir)

# merges are:
#  1 <- '-1' + 1 + 4
#  2 <- 2 + 3 + 8
#  3 <- 5
#  4 <- 6
#  5 <- 7

obj <- addClusterization(obj, clName = "merge",
                         clusters = mergeClusters, coexDF = mergeCoexDF)

In the case one already has an existing clusterization, it is possible to calculate the DEA data.frame and add it to the COTAN object.

data("vignette.merge.clusters", package = "COTAN")
mergeClusters <- vignette.merge.clusters[getCells(obj)]

mergeCoexDF <- DEAOnClusters(obj, clusters = mergeClusters)
#> Differential Expression Analysis - START
#> *****
#> Differential Expression Analysis - DONE

obj <- addClusterization(obj, clName = "merge",
                         clusters = mergeClusters, coexDF = mergeCoexDF)

It is possible to plot the clusterization on a UMAP plot

c(umapPlot, cellsPCA) %<-% cellsUMAPPlot(obj, clName = "merge",
                                         method = "LogNormalized",
                                         genesSel = "HGDI",
                                         colors = NULL, numNeighbors = 25,
                                         minPointsDist = 0.1)
#> Selected 1805 genes using HGDI selector
#> UMAP plot
#> [2024-06-17 17:05:22.010304]  starting umap
#> [2024-06-17 17:05:22.054156]  creating graph of nearest neighbors
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by 'spam'
#> [2024-06-17 17:05:23.306886]  creating initial embedding
#> [2024-06-17 17:05:23.432438]  optimizing embedding
#> [2024-06-17 17:05:26.478665]  done

plot(umapPlot)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.

In the following graph, it is possible to check that the found clusters align very well to the expression of the layers’ genes defined above…

c(.,scoreDF) %<-% clustersMarkersHeatmapPlot(obj, groupMarkers = layersGenes,
                                             clName = "split", kCuts = 5L)
#> clustersDeltaExpression - START
#> clustersDeltaExpression - DONE

c(.,scoreDF) %<-% clustersMarkersHeatmapPlot(obj, groupMarkers = layersGenes,
                                             clName = "merge", kCuts = 5L)
#> clustersDeltaExpression - START
#> clustersDeltaExpression - DONE

2.6 Vignette clean-up stage

The next few lines are just to clean.

if (file.exists(file.path(outDir, paste0(cond, ".cotan.RDS")))) {
  #Delete file if it exists
  file.remove(file.path(outDir, paste0(cond, ".cotan.RDS")))
}
#> [1] TRUE
if (file.exists(file.path(outDir, paste0(cond, "_times.csv")))) {
  #Delete file if it exists
  file.remove(file.path(outDir, paste0(cond, "_times.csv")))
}
#> [1] TRUE
if (dir.exists(file.path(outDir, cond))) {
  unlink(file.path(outDir, cond), recursive = TRUE)
}
if (dir.exists(file.path(outDir, GEO))) {
  unlink(file.path(outDir, GEO), recursive = TRUE)
}

# stop logging to file
setLoggingFile("")
#> Closing previous log file - Setting log file to be:
file.remove(file.path(outDir, "vignette_v2.log"))
#> [1] TRUE

options(parallelly.fork.enable = FALSE)

sessionInfo()
#> R version 4.4.0 RC (2024-04-16 r86468)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.20-bioc/R/lib/libRblas.so 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] GEOquery_2.73.0     Biobase_2.65.0      BiocGenerics_0.51.0
#>  [4] qpdf_1.3.3          Rtsne_0.17          data.table_1.15.4  
#>  [7] rlang_1.1.4         zeallot_0.1.0       COTAN_2.5.4        
#> [10] BiocStyle_2.33.1   
#> 
#> loaded via a namespace (and not attached):
#>   [1] RcppAnnoy_0.0.22          splines_4.4.0            
#>   [3] later_1.3.2               tibble_3.2.1             
#>   [5] polyclip_1.10-6           fastDummies_1.7.3        
#>   [7] lifecycle_1.0.4           doParallel_1.0.17        
#>   [9] processx_3.8.4            globals_0.16.3           
#>  [11] lattice_0.22-6            MASS_7.3-61              
#>  [13] dendextend_1.17.1         magrittr_2.0.3           
#>  [15] limma_3.61.2              plotly_4.10.4            
#>  [17] sass_0.4.9                rmarkdown_2.27           
#>  [19] jquerylib_0.1.4           yaml_2.3.8               
#>  [21] httpuv_1.6.15             Seurat_5.1.0             
#>  [23] sctransform_0.4.1         askpass_1.2.0            
#>  [25] spam_2.10-0               sp_2.1-4                 
#>  [27] spatstat.sparse_3.0-3     reticulate_1.37.0        
#>  [29] cowplot_1.1.3             pbapply_1.7-2            
#>  [31] RColorBrewer_1.1-3        abind_1.4-5              
#>  [33] zlibbioc_1.51.1           purrr_1.0.2              
#>  [35] coro_1.0.4                torch_0.13.0             
#>  [37] circlize_0.4.16           IRanges_2.39.0           
#>  [39] S4Vectors_0.43.0          ggrepel_0.9.5            
#>  [41] irlba_2.3.5.1             listenv_0.9.1            
#>  [43] spatstat.utils_3.0-5      umap_0.2.10.0            
#>  [45] goftest_1.2-3             RSpectra_0.16-1          
#>  [47] spatstat.random_3.2-3     dqrng_0.4.1              
#>  [49] fitdistrplus_1.1-11       parallelly_1.37.1        
#>  [51] DelayedMatrixStats_1.27.1 leiden_0.4.3.1           
#>  [53] codetools_0.2-20          DelayedArray_0.31.1      
#>  [55] xml2_1.3.6                tidyselect_1.2.1         
#>  [57] shape_1.4.6.1             farver_2.1.2             
#>  [59] ScaledMatrix_1.13.0       viridis_0.6.5            
#>  [61] matrixStats_1.3.0         stats4_4.4.0             
#>  [63] spatstat.explore_3.2-7    jsonlite_1.8.8           
#>  [65] GetoptLong_1.0.5          progressr_0.14.0         
#>  [67] ggridges_0.5.6            survival_3.7-0           
#>  [69] iterators_1.0.14          foreach_1.5.2            
#>  [71] tools_4.4.0               ica_1.0-3                
#>  [73] Rcpp_1.0.12               glue_1.7.0               
#>  [75] gridExtra_2.3             SparseArray_1.5.8        
#>  [77] xfun_0.45                 MatrixGenerics_1.17.0    
#>  [79] ggthemes_5.1.0            dplyr_1.1.4              
#>  [81] withr_3.0.0               BiocManager_1.30.23      
#>  [83] fastmap_1.2.0             fansi_1.0.6              
#>  [85] openssl_2.2.0             callr_3.7.6              
#>  [87] digest_0.6.35             rsvd_1.0.5               
#>  [89] parallelDist_0.2.6        R6_2.5.1                 
#>  [91] mime_0.12                 colorspace_2.1-0         
#>  [93] Cairo_1.6-2               scattermore_1.2          
#>  [95] tensor_1.5                spatstat.data_3.0-4      
#>  [97] utf8_1.2.4                tidyr_1.3.1              
#>  [99] generics_0.1.3            httr_1.4.7               
#> [101] htmlwidgets_1.6.4         S4Arrays_1.5.1           
#> [103] uwot_0.2.2                pkgconfig_2.0.3          
#> [105] gtable_0.3.5              ComplexHeatmap_2.21.0    
#> [107] lmtest_0.9-40             XVector_0.45.0           
#> [109] htmltools_0.5.8.1         dotCall64_1.1-1          
#> [111] bookdown_0.39             clue_0.3-65              
#> [113] SeuratObject_5.0.2        scales_1.3.0             
#> [115] png_0.1-8                 knitr_1.47               
#> [117] tzdb_0.4.0                reshape2_1.4.4           
#> [119] rjson_0.2.21              curl_5.2.1               
#> [121] nlme_3.1-165              cachem_1.1.0             
#> [123] zoo_1.8-12                GlobalOptions_0.1.2      
#> [125] stringr_1.5.1             KernSmooth_2.23-24       
#> [127] parallel_4.4.0            miniUI_0.1.1.1           
#> [129] RcppZiggurat_0.1.6        pillar_1.9.0             
#> [131] grid_4.4.0                vctrs_0.6.5              
#> [133] RANN_2.6.1                promises_1.3.0           
#> [135] BiocSingular_1.21.1       beachmat_2.21.3          
#> [137] xtable_1.8-4              cluster_2.1.6            
#> [139] evaluate_0.24.0           magick_2.8.3             
#> [141] tinytex_0.51              readr_2.1.5              
#> [143] cli_3.6.2                 compiler_4.4.0           
#> [145] crayon_1.5.2              future.apply_1.11.2      
#> [147] labeling_0.4.3            ps_1.7.6                 
#> [149] plyr_1.8.9                stringi_1.8.4            
#> [151] viridisLite_0.4.2         deldir_2.0-4             
#> [153] BiocParallel_1.39.0       assertthat_0.2.1         
#> [155] munsell_0.5.1             lazyeval_0.2.2           
#> [157] spatstat.geom_3.2-9       PCAtools_2.17.0          
#> [159] Matrix_1.7-0              RcppHNSW_0.6.0           
#> [161] hms_1.1.3                 patchwork_1.2.0          
#> [163] bit64_4.0.5               sparseMatrixStats_1.17.2 
#> [165] future_1.33.2             ggplot2_3.5.1            
#> [167] statmod_1.5.0             shiny_1.8.1.1            
#> [169] highr_0.11                ROCR_1.0-11              
#> [171] Rfast_2.1.0               igraph_2.0.3             
#> [173] RcppParallel_5.1.7        bslib_0.7.0              
#> [175] bit_4.0.5