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

Overview

This vignette will walk through the exportation of a processed seurat object that is compatible with the cellcuratoR shiny visualization system. Compatible S4 Seurat input objects should be supplied by the user that have either (A) been processed with Seuart (version 3) or (B) been updated to a version 3 Seurat object with the function UpdateSeuratObject(). Further, within the meta.data of the Seurat object, the user should have columns corresponding to a final cluster designation, a library-id, and a cell type classification, as walked through in this tutorial.

We will walk through the exportation of a stimulated vs control pbmc dataset freely available from Seurat. We will use the ifnb data, in which peripheral blood mononuclear cells were divided into stimulated and control groups. For further details, see https://satijalab.org/seurat/v3.1/immune_alignment.html. First, we will download the ifnb dataset using the helpful SeuratData package.

library(cellcuratoR)
library(Seurat)
library(tidyverse)

if(!requireNamespace("SeuratData", quietly = TRUE)){
  stop("Package \"SeuratData\" needed for this vignette to work. Please install it.",
      call. = FALSE)
}

library(SeuratData)

InstallData("ifnb") 
data("ifnb")
head(ifnb@meta.data)

We will perform a basic integration and clustering analysis, as outlined by the Seurat team.

ifnb.list <- SplitObject(ifnb, split.by = "stim")

ifnb.list <- lapply(X = ifnb.list, FUN = function(x) {
    x <- NormalizeData(x)
    x <- FindVariableFeatures(x, selection.method = "vst", nfeatures = 2000)
})

immune.anchors <- FindIntegrationAnchors(object.list = ifnb.list, dims = 1:20)
immune.combined <- IntegrateData(anchorset = immune.anchors, dims = 1:20)
DefaultAssay(immune.combined) <- "integrated"

# Run the standard workflow for visualization and clustering
immune.combined <- ScaleData(immune.combined, verbose = FALSE)
immune.combined <- RunPCA(immune.combined, npcs = 30, verbose = FALSE)
# t-SNE and Clustering
immune.combined <- RunUMAP(immune.combined, reduction = "pca", dims = 1:20)
immune.combined <- FindNeighbors(immune.combined, reduction = "pca", dims = 1:20)
immune.combined <- FindClusters(immune.combined, resolution = 0.5)

# We map each cluster to a putative cell type
seurat_celltypes <- c("CD14 Mono", "CD4 Naive T", "CD4 Memory T", 
                      "CD16 Mono", "B", "CD8 T", "T activated", 
                      "NK", "DC", "B Activated", "Mk",  "pDC", "Eryth")
celltype <- plyr::mapvalues(x = immune.combined@meta.data$seurat_clusters, 
                                from = seq(from = 0, to = 12), 
                                to = seurat_celltypes)
immune.combined@meta.data$celltype <- celltype

# We add a treatment column to the seurat object so that differential expression can 
# be performed between unstimulated and stimulated samples. Treatment must be a binary factor. 
treatment <- as.factor(immune.combined@meta.data$orig.ident)
immune.combined@meta.data <- data.frame(immune.combined@meta.data, treatment)

Before interacting with the data, we must export the processed seurat object in a format interpretable by Shiny. First, we create a directory to organize all of our exported cellcuratoR objects:

## consider changing filepath to ~/Desktop or other directory that is easier to navigate to
my_filepath <- file.path(find.package("cellcuratoR"))
dir.create(file.path(my_filepath, "my_cellcuratoR_objects/"))

Next, we export our processed Seurat object into this newly created directory with the export_shiny_object() function.

export_shiny_object(seurat_object = immune.combined, 
                    final_cluster_column_name = "seurat_clusters",
                    library_id_column_name = "orig.ident",
                    classification_column_name = "celltype",
                    create_dendrogram = TRUE,
                    custom_cluster_colors = FALSE,
                    custom_library_colors = FALSE,
                    additional_metadata_cols = c("treatment"), # allows for dge between treatment groups
                    export_data_path = file.path(my_filepath, "my_cellcuratoR_objects/"))
## consider changing filepath to ~/Desktop or other directory that is easier to navigate to

The directory structure of the exported dataset is as follows:

|-- infb_shiny
|   |--seurat_obj.RData
|   |--seurat_obj_big.RData

Once exported, we can now launch the cellcuratoR app and interact with the dataset. Upon launching the cellcuratoR shiny interface, we click the "Select Seurat Object Directory" button and navigate to our newly created directory, "~/Desktop/my_cellcurator_objects/." Importantly, we do NOT navigate to the directory of the individual dataset (eg, do NOT navigate to "~/Desktop/my_cellcurator_objects/infb_shiny/"). Then, we can load our dataset with the "which dataset should be loaded?" dropdown and initiate exploratory data analysis.

print(paste0("exporting data to: ", my_filepath, "my_cellcuratoR_objects/"))
# Launch the app with the following command (commented out for R-markdown)
# cellcuratoR::launchApp()

# 1. Navigate to the our newly created directory printed above (or change to a more accesible directory for you)
# 2. Select the "infb_shiny" dataset from the "which dataset should be loaded?" dropdown
# 3. Interactively explore data!


drewvoigt10/cellcuratoR documentation built on May 22, 2023, 4:38 p.m.