knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    crop = NULL ## Related to https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016656.html
)
## Bib setup
library("RefManageR")

## Write bibliography information
bib <- c(
    R = citation(),
    AnnotationHub = citation("AnnotationHub")[1],
    BiocFileCache = citation("BiocFileCache")[1],
    dplyr = citation("dplyr")[1],
    ExperimentHub = citation("ExperimentHub")[1],
    ggplot2 = citation("ggplot2")[1],
    graphics = citation("graphics")[1],
    grDevices = citation("grDevices")[1],
    matrixStats = citation("matrixStats")[1],
    methods = citation("methods")[1],
    purrr = citation("purrr")[1],
    rafalib = citation("rafalib")[1],
    RColorBrewer = citation("RColorBrewer")[1],
    reshape2 = citation("reshape2")[1],
    S4Vectors = citation("S4Vectors")[1],
    scran = citation("scran")[1],
    SingleCellExperiment = citation("SingleCellExperiment")[1],
    spatialLIBD = citation("spatialLIBD")[1],
    stats = citation("stats")[1],
    stringr = citation("stringr")[1],
    SummarizedExperiment = citation("SummarizedExperiment")[1],
    tibble = citation("tibble")[1],
    utils = citation("utils")[1],
    Biobase = citation("Biobase")[1],
    BiocStyle = citation("BiocStyle")[1],
    BisqueRNA = citation("BisqueRNA")[1],
    covr = citation("covr")[1],
    HDF5Array = citation("HDF5Array")[1],
    knitr = citation("knitr")[1],
    RefManageR = citation("RefManageR")[1],
    rmarkdown = citation("rmarkdown")[1],
    sessioninfo = citation("sessioninfo")[1],
    testthat = citation("testthat")[1],
    tidyr = citation("tidyr")[1],
    tidyverse = citation("tidyverse")[1],
    DeconvoBuddies = citation("DeconvoBuddies")[1],
    DeconvoBuddiespaper = citation("DeconvoBuddies")[2]
)

Introduction

DeconvoBuddies is an R package developed to assist in running bulk RNA-seq deconvolution. This package provides functions to access a data set designed to evaluate deconvolution method performance, find marker genes, and create plots useful in deconvolution.

This package is associated with "Benchmark of cellular deconvolution methods using a multi-assay reference dataset from postmortem human prefrontal cortex" from Huuki-Myers et al. (10.1101/2024.02.09.579665v2)[https://www.biorxiv.org/content/10.1101/2024.02.09.579665v2].

Basics

Install DeconvoBuddies

R is an open-source statistical environment which can be easily modified to enhance its functionality via packages. r Biocpkg("DeconvoBuddies") is a R package available via the Bioconductor repository for packages. R can be installed on any operating system from CRAN after which you can install r Biocpkg("DeconvoBuddies") by using the following commands in your R session:

if (!requireNamespace("BiocManager", quietly = TRUE)) {
    install.packages("BiocManager")
}

BiocManager::install("DeconvoBuddies")

## Check that you have a valid Bioconductor installation
BiocManager::valid()

Required knowledge

r Biocpkg("DeconvoBuddies") is based on many other packages and in particular in those that have implemented the infrastructure needed for dealing with snRNA-seq data. That is, packages like r Biocpkg("SingleCellExperiment").

If you are asking yourself the question "Where do I start using Bioconductor?" you might be interested in this blog post.

Asking for help

As package developers, we try to explain clearly how to use our packages and in which order to use the functions. But R and Bioconductor have a steep learning curve so it is critical to learn where to ask for help. The blog post quoted above mentions some but we would like to highlight the Bioconductor support site as the main resource for getting help: remember to use the DeconvoBuddies tag and check the older posts. Other alternatives are available such as creating GitHub issues and tweeting. However, please note that if you want to receive help you should adhere to the posting guidelines. It is particularly critical that you provide a small reproducible example and your session information so package developers can track down the source of the error.

Citing DeconvoBuddies

We hope that r Biocpkg("DeconvoBuddies") will be useful for your research. Please use the following information to cite the package and the overall approach. Thank you!

## Citation info
citation("DeconvoBuddies")

Quick start to using DeconvoBuddies

Let's load some packages we'll use in this vignette.

suppressMessages({
    library("DeconvoBuddies")
    library("SummarizedExperiment")
    library("dplyr")
    library("tidyr")
    library("tibble")
})

Access Data

Use fetch_deconvo_data to download RNA sequencing data from the Human DLPFC r Citep(bib[["DeconvoBuddiespaper"]]).

## Access and snRNA-seq example data
if (!exists("sce_DLPFC_example")) sce_DLPFC_example <- fetch_deconvo_data("sce_DLPFC_example")

## Explore snRNA-seq data in sce_DLPFC_example
sce_DLPFC_example

## Access Bulk RNA-seq data
if (!exists("rse_gene")) rse_gene <- fetch_deconvo_data("rse_gene")

## Explore bulk data in rse_gene
rse_gene

For more details on this dataset, and an example deconvolution run check out the Vignette: Deconvolution Benchmark in Human DLPFC.

Marker Finding

Using MeanRatio to Find Cell Type Markers

Accurate deconvolution requires highly specific marker genes for each cell type to be defined. To select genes specific for each cell type, you can evaluate the MeanRatio for each gene x each cell type, where MeanRatio = mean(Expression of target cell type) / mean(Expression of highest non-target cell type).

These values can be calculated for a single cell RNA-seq dataset using get_mean_ratio(). This can also work for spatially-resolved transcriptomics datasets. That is, get_mean_ratio() can also work with SpatialExperiment::SpatialExperiment() objects.

## find marker genes with get_mean_ratio
marker_stats <- get_mean_ratio(
    sce_DLPFC_example,
    cellType_col = "cellType_broad_hc",
    gene_name = "gene_name",
    gene_ensembl = "gene_id"
)

## explore tibble output, gene with high MeanRatio values are good marker genes
marker_stats

For more discussion of finding marker genes with DeconvoBuddies check out the Vignette: Finding Marker Genes with DeconvoBuddies.

Plotting Tools

Creating A Cell Type Color palette

As you work with single-cell data and deconvolution outputs, it is very useful to establish a consistent color palette to use across different plots. The function create_cell_colors() returns a named vector of hex values, corresponding to the names of cell types. This list is compatible with functions like ggplot2::scale_color_manual().

There are three palettes to choose from to generate colors or users can provide their own color palette:

test_cell_types <- c("cell_A", "cell_B", "cell_C", "cell_D", "cell_E")

## Preview "classic" colors
test_cell_colors_classic <- create_cell_colors(
    cell_types = test_cell_types,
    palette_name = "classic",
    preview = TRUE
)

## Preview "gg" colors
test_cell_colors_gg <- create_cell_colors(
    cell_types = test_cell_types,
    palette_name = "gg",
    preview = TRUE
)

## Preview "tableau" colors
test_cell_colors_tableau <- create_cell_colors(
    cell_types = test_cell_types,
    palette_name = "tableau",
    preview = TRUE
)

## Check the color hex codes for "tableau"
test_cell_colors_tableau

## Provide a palette from RColorBrewer
test_cell_colors_brew <- create_cell_colors(
    cell_types = test_cell_types,
    palette = RColorBrewer::brewer.pal(n = length(test_cell_types), name = "Dark2"),
    preview = TRUE
)

If there are sub-cell types with consistent delimiters, the split argument creates a scale of related colors. This helps expand on the maximum number of colors and makes your palette flexible when considering different 'resolutions' of cell types. This works by ignoring any prefixes after the split character. In this example below, Excit_01 and Excit_02 will just be considered as Excit since split = "_".

my_cell_types <- levels(sce_DLPFC_example$cellType_hc)
## Ignore any suffix after the "_" character by using the "split" argument
my_cell_colors <- create_cell_colors(
    cell_types = my_cell_types,
    palette_name = "classic",
    preview = TRUE,
    split = "_"
)

Plot Expression of Top Markers

The function plot_marker_express() helps quickly visualize expression of top marker genes, by ordering and annotating violin plots of expression over cell type. Here we'll plot the expression of the top 6 marker genes for Astrocytes.

# plot expression of the top 6 Astro marker genes
plot_marker_express(
    sce = sce_DLPFC_example,
    stats = marker_stats,
    cell_type = "Astro",
    n_genes = 6,
    cellType_col = "cellType_broad_hc",
    color_pal = my_cell_colors
)

The violin plots of gene expression confirm the cell type specificity of these marker genes, most of the nuclei with high expression of these six genes are astrocytes (Astro).

Plot Composition Bar Plot

The output of deconvolution are cell type estimates that sum to 1. A good visulization for these predictions is a stacked bar plot. The function plot_composition_bar() creates a stacked bar plot showing the cell type proportion for each sample, or the average proportion for a group of samples. In this example data, the RNum is a sample (donor) identifier and Dx is a group variable for the diagnosis status of the donors.

# load example data
data("rse_bulk_test")
data("est_prop")

# access the colData of a test rse dataset
pd <- colData(rse_bulk_test) |>
    as.data.frame()

## pivot data to long format and join with test estimated proportion data
est_prop_long <- est_prop |>
    rownames_to_column("RNum") |>
    pivot_longer(!RNum, names_to = "cell_type", values_to = "prop") |>
    left_join(pd)

## explore est_prop_long
est_prop_long

## the composition bar plot shows cell type composition for Sample
plot_composition_bar(est_prop_long,
    x_col = "RNum",
    add_text = FALSE
) +
    ggplot2::scale_fill_manual(values = test_cell_colors_classic)

## the composition bar plot shows the average cell type composition for each Dx
plot_composition_bar(est_prop_long, x_col = "Dx") +
    ggplot2::scale_fill_manual(values = test_cell_colors_classic)

We can see that the mean proportions of cell types A through E are very similar across the Dx groups (Case and Control). In this case, this is expected given that we are using simulated data. Although if you look across each donor with RNum we can see more variability across the simulated data.

Since you are now familiar with the basic overview of DeconvoBuddies, you are now ready to dive deeper into:

Reproducibility

The r Biocpkg("DeconvoBuddies") package r Citep(bib[["DeconvoBuddies"]]) was made possible thanks to:

This vignette was generated using r Biocpkg("BiocStyle") r Citep(bib[["BiocStyle"]]) with r CRANpkg("knitr") r Citep(bib[["knitr"]]) and r CRANpkg("rmarkdown") r Citep(bib[["rmarkdown"]]) running behind the scenes.

Citations made with r CRANpkg("RefManageR") r Citep(bib[["RefManageR"]]).

This package was developed using r BiocStyle::Biocpkg("biocthis").

R session information.

## Session info
library("sessioninfo")
options(width = 120)
session_info()

Bibliography

## Print bibliography
PrintBibliography(bib, .opts = list(hyperlink = "to.doc", style = "html"))


lahuuki/DeconvoBuddies documentation built on Feb. 26, 2025, 3:19 a.m.