knitr::opts_chunk$set(
    collapse=TRUE,
    comment="#>",
    message=FALSE,
    warning=FALSE
)

Introduction

This vignette describes the workflow for running r Githubpkg("montilab/K2Taxonomer") recursive partitioning on single-cell gene expression data [@reed_2020]. Note, that many of these steps are shared with that of bulk expression analyses. A vignette for running r Githubpkg("montilab/K2Taxonomer") on bulk expression data can be found here.

The single-cell expression workflow performs partitioning at the level of annotated cell clusters and/or cell types. Note, for recursive partitioning it is recommended to use the same data matrix from which clustering tasks were performed, such as an integrated data matrix generated prior to and used for clustering. For tasks downstream of partitioning, users can specify an alternative data matrix.

Requirements

Load packages

## K2Taxonomer package
library(K2Taxonomer)

## Seurat package
library(Seurat)

## For drawing dendrograms
library(ggdendro)

Read in single-cell RNAseq data

data("ifnb_small")

Read in gene sets for subgroup annotation

data("cellMarker2_genesets")

The IFNB Data

DimPlot(ifnb_small, label = TRUE, raster =TRUE,  pt.size = 3, alpha = 0.4) + NoLegend()

Running r Githubpkg("montilab/K2Taxonomer")

Get necessary data objects

## Integrated expression matrix used for clustering data
integrated_expression_matrix <- ifnb_small@assays$integrated$scale.data

## Normalized expression matrix to be used for downstream analyses
normalized_expression_matrix <- ifnb_small@assays$SCT$data

## Profile-level information
cell_data <- ifnb_small@meta.data

Initialize K2 object

The K2preproc() initializes the K2 object and runs pre-processing steps. Here, you can specify all arguments used throughout the analysis. Otherwise, you can specify these arguments within the specific functions for which they are implemented. See help pages for more information.

A description of arguments implemented in this vignette are

# Initialize `K2` object
K2res <- K2preproc(object = integrated_expression_matrix,
                   eMatDS = normalized_expression_matrix,
                   colData = cell_data,
                   cohorts="cell_type",
                   nBoots = 200,
                   clustFunc = "cKmeansDownsampleSqrt",
                   genesets = cellMarker2_genesets)

Run recursive partitioning algorithm

The r Githubpkg("montilab/K2Taxonomer") is run by K2tax(). At each recursion of the algorithm, the observations are partitioned into two sub-groups based on a compilation of repeated K=2 clustering on bootstrapped sampling of features.

K2res <- K2tax(K2res)

Generate dendrogram from r Githubpkg("montilab/K2Taxonomer") results

Static dendrogram

## Get dendrogram from K2Taxonomer
dendro <- K2dendro(K2res)

## Plot dendrogram
ggdendrogram(dendro)

Interactive dendrogram

K2visNetwork(K2res)

Annotate r Githubpkg("montilab/K2Taxonomer") results

Partition-level Differential Gene Expression Analysis

K2res <- runDGEmods(K2res)

Perform gene set based analyses

### Perform Fisher Exact Test based over-representation analysis
K2res <- runFISHERmods(K2res)

### Perform single-sample gene set scoring
K2res <- runScoreGeneSets(K2res)

### Perform partition-level differential gene set score analysis
K2res <- runDSSEmods(K2res)

Explore Annotation Results

Partition-level Differential Gene Expression Analysis

Create Static Table of DGE Results

DGEtable <- getDGETable(K2res)
head(DGEtable)

Create Interactive Table of DGE Results

getDGEInter(K2res, minDiff = 1, node = c("A"), pagelength = 10)

Create Plot of Gene Expression

plotGenePathway(K2res, feature = "FTL", node = "A")

Create Static Plot Gene Expression

plotGenePathway(K2res, feature = "FTL", node = "A", use_plotly = FALSE)

Partition-level Gene Set Enrichment Results

Create Static Table of Gene Set Results

ENRtable <- getEnrichmentTable(K2res)
head(ENRtable)

Create Interactive Table of Gene Set Results

getEnrichmentInter(K2res, nodes = c("A"), pagelength = 10)

Create Interactive Plot of Single-sample Scoring

plotGenePathway(K2res, feature = "Monocyte", node = "A", type = "gMat")

Create Static Plot of Single-sample Scoring

plotGenePathway(K2res, feature = "Monocyte", node = "A", type = "gMat", use_plotly = FALSE)

Create Dashboard

For more information about K2Taxonomer dashboards, read this vignette.

# Not run
K2dashboard(K2res, "K2results_ifnb_small")

Implementation Options

Parellel excecutation

Given their size, parts of the K2Taxonomer workflow can take a long time with single-cell data sets. Accordingly, it is generally recommended to run the workflow using parallel computing. This can be implemented easily by setting the useCors argument in K2preproc()

# Not run
K2res <- K2preproc(object = integrated_expression_matrix,
                   eMatDS = normalized_expression_matrix,
                   colData = cell_data,
                   cohorts="cell_type",
                   nBoots = 200,
                   useCors = 8, ## Runs K2Taxonomer in parellel with eight cores.
                   clustFunc = "cKmeansDownsampleSqrt",
                   genesets = cellMarker2_genesets)

Using Seurat object directly

In addition to expression matrices, Seurat objects may be input directly with the object argument. When implemented, colData isn't specified and this information is pulled from the meta data of the Seurat object. Two additional arguments may be set, each specifying the assay of the Seurat objects to pull expression data from.

K2res_seurat <- K2preproc(object = ifnb_small,
                   cohorts="cell_type",
                   seuAssay = "integrated",
                   seuAssayDS = "SCT",
                   nBoots = 200,
                   clustFunc = "cKmeansDownsampleSqrt",
                   genesets = cellMarker2_genesets)

## Run recursive partitioning algorithm
K2res_seurat <- K2tax(K2res_seurat)

## Get dendrogram from K2Taxonomer
dendro_seurat <- K2dendro(K2res_seurat)

## Plot dendrogram
ggdendrogram(dendro_seurat)

References



montilab/K2Taxonomer documentation built on April 5, 2025, 3:58 a.m.