knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    # dev.args = list(png = list(type = "cairo")),
    dpi = 900,
    out.width = "100%",
    message = FALSE,
    warning = FALSE
)

library(kableExtra)
library(xfun)

format_table <- function(mydf) {
    mydf %>%
        kableExtra::kbl() %>%
        kable_material() %>%
        scroll_box(width = "800px", height = "200px")
}

First step is to load seuratTools package and all other packages required

library(seuratTools)
library(Seurat)
library(tidyverse)
library(ggraph)

TLDR

seuratTools provides a single command to:

Run clustering on a single seurat object

By default clustering will be run at ten different resolutions between 0.2 and 2.0. Any resolution can be specified by providing the resolution argument as a numeric vector.

clustered_seu <- clustering_workflow(human_gene_transcript_seu,
    experiment_name = "seurat_hu_trans",
    organism = "human"
)

Clustering at 0.6

DimPlot(clustered_seu, group.by = "gene_snn_res.0.6")

Get a first look at a processed dataset using an interactive shiny app

minimalSeuratApp(clustered_seu)

Set up a seurat object

We start with a gene by cell matrix of count/UMI values and a table of cell metadata

human_count[1:5, 1:5]

head(human_meta)
human_count[1:10, 1:10] %>%
    format_table()
head(human_meta) %>%
    format_table()

Then using these 2 datasets we can create a Seurat object in the usual manner using the CreateSeuratObject function

myseu <- CreateSeuratObject(human_count, assay = "gene", meta.data = human_meta)
myseu

Preprocess the seurat object

seuratTools includes a handy function to preprocess the data that handles normalization and scaling required for downstream analysis. Preprocessing is performed using existing Seurat functions. If needed, parameters can be specified by the user.

myseu <- seurat_preprocess(myseu)

This single function includes sub-functions that normalizes, identifies highly variable features and scales the data:

preprocess_seu <- NormalizeData(myseu, verbose = FALSE)
preprocess_seu <- FindVariableFeatures(preprocess_seu,
    selection.method = "vst",
    verbose = FALSE
)
pre_process_seu <- ScaleData(preprocess_seu)

Perform dimension reduction

seuratTools also implements a standardized dimension reduction step to select variable features at a user-specified threshold and perform PCA, tSNE, and UMAP. The default assay the dimension reduction is being run on is "gene".

myseu <- seurat_reduce_dimensions(myseu, assay = "RNA")
DimPlot(myseu)

This function includes existing seurat functions which performs dimension reduction techniques.

Dim_Red_seu <- RunPCA(myseu,
    features = VariableFeatures(myseu),
    do.print = FALSE
)
Dim_Red_seu <- RunUMAP(Dim_Red_seu, dims = 1:30)

Community detection by clustering

Clustering analysis is performed via Louvain(default) or alternative algorithms available in Seurat. Clustering is performed at a range of resolutions with default value ranging from 0.2 to 2 and pca reduction

seu <- seurat_cluster(seu = Dim_Red_seu, resolution = seq(0.2, 2, by = 0.2))

This function produces clustering analysis via two steps performed using two different sub-functions



whtns/seuratTools documentation built on June 28, 2024, 8:30 p.m.