knitr::opts_chunk$set( collapse = TRUE, comment = "#>", crop = NULL ## Related to https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016656.html )
## Track time spent on making the vignette startTime <- Sys.time() ## Bib setup library("RefManageR") ## Write bibliography information bib <- c( R = citation(), BiocStyle = citation("BiocStyle")[1], knitr = citation("knitr")[1], RefManageR = citation("RefManageR")[1], rmarkdown = citation("rmarkdown")[1], sessioninfo = citation("sessioninfo")[1], testthat = citation("testthat")[1], DeconvoBuddies = citation("DeconvoBuddies")[1], DeconvoBuddiespaper = citation("DeconvoBuddies")[2] )
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()
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.
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.
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")
DeconvoBuddies
Let's load some packages we'll use in this vignette.
suppressMessages({ library("DeconvoBuddies") library("SummarizedExperiment") library("dplyr") library("tidyr") library("tibble") })
Use fetch_deconvo_data
Download RNA sequencing data from the Human
DLPFC r Citep(bib[["DeconvoBuddiespaper"]])
.
rse_gene
: 110 samples of bulk RNA-seq. [110 bulk RNA-seq samples x
21k genes] (41 MB).
sce
: snRNA-seq data from the Human DLPFC. [77k nuclei x 36k
genes] (172 MB)
sce_DLPFC_example
: Sub-set of sce
useful for testing. [10k
nuclei x 557 genes] (49 MB)
## 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.
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_ratio2()
.
## 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.
As you work with single-cell data and deconovoltion outputs, it is very
useful to establish a consistent color pallet 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 pallets to choose from to generate colors:
"classic" (default): Set1 from RColorBrewer
- max 9 colors
"gg": Equi-distant hues, same process for selecting colors as
ggplot
- no maximum number
"tableau": tableau20 color set - max 20 colors
test_cell_types <- c("cell_A", "cell_B", "cell_C", "cell_D", "cell_E") test_cell_colors_classic <- create_cell_colors(cell_types = test_cell_types, pallet = "classic", preview = TRUE) test_cell_colors_gg <- create_cell_colors(cell_types = test_cell_types, pallet = "gg", preview = TRUE) test_cell_colors_tableau <- create_cell_colors(cell_types = test_cell_types, pallet = "tableau", preview = TRUE) test_cell_colors_tableau
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 pallet flexible when considering
different 'resolutions' of cell types.
my_cell_types <- levels(sce_DLPFC_example$cellType_hc) my_cell_colors <- create_cell_colors( cell_types = my_cell_types, pallet = "classic", preview = TRUE, split = "_" )
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 nueli with high expression of these six genes are Astro.
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.
# 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)
The r Biocpkg("DeconvoBuddies")
package
r Citep(bib[["DeconvoBuddies"]])
was made possible thanks to:
r Citep(bib[["R"]])
r Biocpkg("BiocStyle")
r Citep(bib[["BiocStyle"]])
r CRANpkg("knitr")
r Citep(bib[["knitr"]])
r CRANpkg("RefManageR")
r Citep(bib[["RefManageR"]])
r CRANpkg("rmarkdown")
r Citep(bib[["rmarkdown"]])
r CRANpkg("sessioninfo")
r Citep(bib[["sessioninfo"]])
r CRANpkg("testthat")
r Citep(bib[["testthat"]])
This package was developed using r BiocStyle::Biocpkg("biocthis")
.
Code for creating the vignette
## Create the vignette library("rmarkdown") system.time(render("DeconvoBuddies.Rmd", "BiocStyle::html_document")) ## Extract the R code library("knitr") knit("DeconvoBuddies.Rmd", tangle = TRUE)
Date the vignette was generated.
## Date the vignette was generated Sys.time()
Wallclock time spent generating the vignette.
## Processing time in seconds totalTime <- diff(c(startTime, Sys.time())) round(totalTime, digits = 3)
R
session information.
## Session info library("sessioninfo") options(width = 120) session_info()
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"]])
.
## Print bibliography PrintBibliography(bib, .opts = list(hyperlink = "to.doc", style = "html"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.