dittoSeq: R Visualization Toolkit for RNA-sequencing Data

repository·devel·Indexed 42 days ago

https://github.com/dtm2451/dittoseq

An R package for the analysis and visualization of single-cell (scRNA-seq) and bulk RNA-sequencing data. It provides color-blind friendly plotting functions compatible with Seurat, SingleCellExperiment, DGEList, and SummarizedExperiment objects. Key features include universal helper functions for metadata and gene inspection, Demuxlet tools for Mux-seq applications, and the Simulate() function to preview plots for different types of colorblindness.

Tokens
3.1K
Snippets
9
Records
13
Agent score
3%

What's inside dittoSeq

  1. Overview of dittoSeq

    devel

    dittoSeq is an R package designed for the analysis and visualization of single-cell (scRNA-seq) and bulk RNA-sequencing data. It provides universal, color-blind friendly plotting and helper functions that work with common data structures from both Seurat and Bioconductor ecosystems.

    Supported Data Structures:

    • Single-cell:
      • Seurat (versions 2+) objects.
      • SingleCellExperiment objects (used by scran, scater, and other Bioconductor packages).
    • Bulk:
      • DGEList objects (used by edgeR).
      • SummarizedExperiment objects (used by DESeq2 and other Bioconductor packages).

    All plotting functions generate high-quality figures using ggplot2, plotly, or pheatmap/ComplexHeatmap. A key feature is the data.out = TRUE input, which allows users to easily access the underlying data used for plots, facilitating journal submissions or adding custom layers.

  2. Demuxlet tools in dittoSeq

    devel
    dittoSeq includes a set of functions to facilitate Mux-seq (multiplex sequencing) applications. These tools are designed to help manage experiments that generate side-by-side bulk and single-cell RNA-seq data.
  3. Color blindness compatibility in dittoSeq

    devel

    dittoSeq is designed to be color-blind friendly by default. It uses a 24-color vector adapted from Wong B, "Points of view: Color blindness" (Nature Methods, 2011).

    • Default Colors: All plotting functions use the colors stored in dittoColors() by default.
    • Simulation: You can use the Simulate() function to preview how your plots will appear to a color-blind individual.
  4. Install dittoSeq via GitHub

    devel

    If BiocManager prevents you from installing the pre-compiled version, you can install the package directly from the GitHub repository.

    # Example command for installing from GitHub if BiocManager fails
    remotes::install_github("dtm2451/dittoseq")
  5. Quick Start Guide: Loading and Plotting Data

    devel

    dittoSeq works natively with Seurat, SingleCellExperiment (SCE), and SummarizedExperiment (SE) objects. For non-SE bulk RNAseq data, import your data into a SingleCellExperiment structure using importDittoBulk() and add dimensionality reductions with addDimReduction().

    Basic Plotting Examples

    • dittoPlot: General purpose plotting (e.g., boxplots, ridgeplots).
    • dittoDimPlot: Dimensionality reduction plots (e.g., UMAP, t-SNE).
    • dittoBarPlot: Bar plots for counts or frequencies.
    • dittoHeatmap: Heatmaps for gene expression.
    • dittoScatterPlot: Scatter plots for feature relationships.
    library(dittoSeq)
    
    # Seurat
    seurat <- Seurat::pbmc_small
    dittoPlot(seurat, "CD14", group.by = "ident")
    
    # SingleCellExperiment
    sce <- Seurat::as.SingleCellExperiment(seurat)
    dittoDimPlot(sce, "CD3E")
    
    # SummarizedExperiment
    library(SummarizedExperiment)
    se <- as(as.SingleCellExperiment(Seurat::pbmc_small), "SummarizedExperiment")
    dittoBarPlot(sce, "ident", group.by = "RNA_snn_res.0.8")
    
    # Bulk RNAseq workflow
    myRNA <- example("importDittoBulk")
    myRNA <- addDimReduction(myRNA, embeddings, "pca")
    dittoDimPlot("gene1", myRNA, size = 3)
  6. Install dittoSeq

    devel

    Installation depends on your R version.

    For R 4.0 and newer:

    Use BiocManager to install the pre-compiled version.

    For R versions older than 4.0:

    BiocManager may not support pre-compiled versions for older R releases. In this case, install directly from GitHub using devtools.

    ### For R-4.0 users:
    if (!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
    
    BiocManager::install("dittoSeq")
    
    ### For users with older versions of R:
    if (!requireNamespace("devtools", quietly = TRUE))
        install.packages("devtools")
    
    devtools::install_github("dtm2451/dittoSeq")
  7. Customize dittoSeq plots

    devel

    Most dittoSeq functions support common parameters to adjust visual output:

    • Subsetting: Use cells.use to subset specific cells (e.g., cells.use = meta("ident", seurat) != 1).
    • Titles: Adjust main, sub, xlab, ylab, x.labels, and legend.title.
    • Colors:
      • For discrete colors: color.panel = c("red", "blue").
      • For continuous colors: min.color and max.color.
      • To change color order: colors = c(3, 1, 2).
    • Interactivity: Set do.hover = TRUE to enable plotly-based hovering.
    • Data Output: Set data.out = TRUE to return the underlying data used for the plot.
    # Adjust titles and labels
    dittoBarPlot(seurat, "ident", group.by = "RNA_snn_res.0.8",
        main = "Starters",
        sub = "By Type",
        xlab = NULL,
        ylab = "Generation 1",
        x.labels = c("Ash", "Misty"),
        legend.title = "Types",
        var.labels.rename = c("Fire", "Water", "Grass"),
        x.labels.rotate = FALSE)
    
    # Subset cells
    dittoBarPlot(seurat, "ident", group.by = "RNA_snn_res.0.8",
        cells.use = meta("ident", seurat) != 1)
    
    # Adjust colors
    dittoBarPlot(seurat, "ident", group.by = "RNA_snn_res.0.8",
        color.panel = c("red", "orange", "purple"))
    
    # Output data and interactivity
    dittoBarPlot(seurat, "ident", group.by = "RNA_snn_res.0.8",
        data.out = TRUE,
        do.hover = TRUE)
  8. Simulate colorblindness with Simulate()

    devel

    The Simulate() function allows you to preview how your dittoSeq plots will appear to individuals with different types of colorblindness. It works for all visualizations except dittoHeatmap.

    Parameters:

    • type: The type of colorblindness to simulate. Options: "deutan" (most common, red-green), "protan" (green-red), or "tritan" (blue deficiency).
    • plot.function: The dittoSeq function you want to visualize (e.g., dittoDimPlot). Note: If R adds parentheses, remove them.
    • ...: All additional arguments passed directly to the plot.function.
    # Original plot
    dittoDimPlot("CD3E", object = seurat, do.letter = F)
    
    # Simulated plot for a deuteranope
    Simulate(type = "deutan", plot.function = dittoDimPlot, "CD3E", object = seurat, do.letter = F)
  9. Use universal helper functions to inspect metadata and genes

    devel

    Use these helper functions to quickly determine available metadata columns, gene names, and dimensionality reductions in your object.

    • getMetas(object): Returns metadata column names.
    • isMeta(name, object): Checks if a metadata column exists.
    • getGenes(object): Returns gene names.
    • isGene(name, object): Checks if a gene exists.
    • getReductions(object): Returns available dimensionality reductions.
    • gene(name, object, ...): Accesses specific gene data.
    • meta(name, object): Accesses specific metadata.
    • metaLevels(name, object): Returns levels of a metadata factor.
    getMetas(seurat)
    isMeta("nCount_RNA", seurat)
    
    getGenes(myRNA)
    isGene("CD3E", myRNA)
    
    getReductions(sce)
    
    gene("CD3E", seurat, assay = "RNA", slot = "counts")
    meta("groups", seurat)
    metaLevels("groups", seurat)
  10. Use importDemux() to add Demuxlet info to Seurat or SCE objects

    devel

    The importDemux() function imports Demuxlet .best output files into an existing Seurat or SingleCellExperiment (SCE) object. This is useful for Mux-seq applications where side-by-side bulk and single-cell RNAseq data are generated.

    Required Arguments:

    • object: The target Seurat or SCE object.
    • demuxlet.best: The file path(s) to your Demuxlet .best output files.

    Metadata Created: Upon import, the following metadata columns are added to your object:

    • Lane: Represents separate droplet-generation lanes, pools, or sequencing lanes (guided by the lane.names input).
    • Sample: The sample call from the BEST column.
    • demux.doublet.call: Whether the cell was a singlet (SNG), doublet (DBL), or ambiguous (AMB).
    • demux.RD.TOTL: Total reads (RD.TOTL).
    • demux.RD.PASS: Passed reads (RD.PASS).
    • demux.RD.UNIQ: Unique reads (RD.UNIQ).
    • demux.N.SNP: Number of SNPs (N.SNP).
    • demux.PRB.DBL: Doublet probability (PRB.DBL).
    • demux.barcode.dup: Indicates if a cell's barcode referred to only one row of the .best file but multiple distinct cells in the dataset (indicates a technical issue).
    # Basic usage pattern
    object <- importDemux(object = my_seurat_obj, demuxlet.best = "path/to/demuxlet.best")
  11. Summarize Demuxlet calls with demux.calls.summary()

    devel

    Use demux.calls.summary(object) to create a plot showing the number of sample calls made per sample, separated by lane. This helps verify the accuracy of sample calls relative to specific lanes or sequencing runs.

    Options:

    • singlets.only = TRUE (default): Only shows Singlet calls.
    • singlets.only = FALSE: Includes one of the sample calls for any doublets in the plot.
    # Plotting only singlets
    demux.calls.summary(object)
    
    # Plotting singlets and doublets
    demux.calls.summary(object, singlets.only = FALSE)
  12. Check SNP counts per cell with demux.SNP.summary()

    devel

    The demux.SNP.summary(object) function creates a plot of the number of SNPs per cell, grouped by individual lane by default. This is useful for identifying cells with very low SNP counts.

    This function acts as a wrapper for dittoPlot() using var="demux.N.SNP" and defaults group.by and color.by to "Lane".

    demux.SNP.summary(object)