Compiled date: r Sys.Date()
Last edited: 2018-03-08
License: r packageDescription("iSEE")[["License"]]
knitr::opts_chunk$set( collapse = TRUE, comment = "#>", error = FALSE, warning = FALSE, message = FALSE, crop = NULL ) stopifnot(requireNamespace("htmltools")) htmltools::tagList(rmarkdown::html_dependency_font_awesome()) sce <- readRDS('sce.rds')
SCREENSHOT <- function(x, ...) knitr::include_graphics(x, dpi = NA)
r Biocpkg("iSEE")
coordinates the coloration in every plot via the ExperimentColorMap
class [@kra2018iSEE].
Colors for samples or features are defined from column or row metadata or assay values using "colormaps".
Each colormap is a function that takes a single integer argument and returns that number of distinct colors.
The ExperimentColorMap
is a container that stores these functions for use within the iSEE()
function.
Users can define their own colormaps to customize coloration for specific assays or covariates.
For continuous variables, the function will be asked to generate a number of colors (21, by default).
Interpolation will then be performed internally to generate a color gradient.
Users can use existing color scales like viridis::viridis
or heat.colors
:
# Coloring for log-counts: logcounts_color_fun <- viridis::viridis
It is also possible to use a function that completely ignores any arguments, and simply returns a fixed number of interpolation points:
# Coloring for FPKMs: fpkm_color_fun <- function(n){ c("black","brown","red","orange","yellow") }
For categorical variables, the function should accept the number of levels and return a color per level. Colors are automatically assigned to factor levels in the specified order of the levels.
# Coloring for the 'driver' metadata variable. driver_color_fun <- function(n){ RColorBrewer::brewer.pal(n, "Set2") }
Alternatively, the function can ignore its arguments and simply return a named vector of colors if users want to specify the color for each level explicitly
It is the user's responsibility to ensure that all levels are accounted for^[Needless to say, these functions should not be used as shared or global colormaps.].
For instance, the following colormap function will only be compatible with factors of two levels, namely "Y"
and "N"
:
# Coloring for the QC metadata variable: qc_color_fun <- function(n){ qc_colors <- c("forestgreen", "firebrick1") names(qc_colors) <- c("Y", "N") qc_colors }
Colormaps can be defined by users at three different levels:
assays
, colData
, and rowData
slots, respectively, of the ExperimentColorMap
.
This can be useful to easily remember which assay is currently shown;
to apply different color scale limits to assays that vary on different ranges of values;
or display boolean information in an intuitive way, among many other scenarios.all_discrete
and all_continuous
slots of the ExperimentColorMap
, as lists of functions named assays
, colData
, and rowData
.global_discrete
and global_continuous
slots of the ExperimentColorMap
.When queried for a specific colormap of any type (assay, column data, or row data), the following process takes place:
ExperimentColorMap
.ExperimentColorMap
will revert to the default colormaps.By default, viridis
is used as the default continuous colormap, and hcl
is used as the default categorical colormap.
ExperimentColorMap
We store the set of colormap functions in an instance of the ExperimentColorMap
class.
Named functions passed as assays
, colData
, or rowData
arguments will be used for coloring data in those slots, respectively.
library(iSEE) ecm <- ExperimentColorMap( assays = list( counts = heat.colors, logcounts = logcounts_color_fun, cufflinks_fpkm = fpkm_color_fun ), colData = list( passes_qc_checks_s = qc_color_fun, driver_1_s = driver_color_fun ), all_continuous = list( assays = viridis::plasma ) ) ecm
Users can change the defaults for all assays or column data by modifying the shared colormaps. Similarly, users can modify the defaults for all continuous or categorical data by modifying the global colormaps. This is demonstrated below for the continuous variables:
ExperimentColorMap( all_continuous=list( # shared assays=viridis::plasma, colData=viridis::inferno ), global_continuous=viridis::magma # global )
The ExperimentColorMap
class offers the following major features:
colDataColorMap(colormap, "coldata_name")
and setters assayColorMap(colormap, "assay_name") <- colormap_function
assays
, colData
, rowData
), or shared globally between all categorical or continuous data scales.Detailed examples on the use of ExperimentColorMap
objects are available in the documentation ?ExperimentColorMap
, as well as below.
Here, we use the allen
single-cell RNA-seq data set to demonstrate the use of the ExperimentColorMap
class.
Using the sce
object that we created r Biocpkg("iSEE", vignette="basic.html", label="previously")
, we create an iSEE
app with the SingleCellExperiment
object and the colormap generated above.
app <- iSEE(sce, colormap = ecm)
We run this using runApp
to open the app on our browser.
shiny::runApp(app)
SCREENSHOT("screenshots/ecm-demo.png")
Now, choose to color cells by Column data
and select passes_qc_checks_s
.
We will see that all cells that passed QC (Y
) are colored "forestgreen", while the ones that didn’t pass are colored firebrick.
If we color any plot by gene expression, we see that use of counts follows the heat.colors
coloring scheme;
use of log-counts follows the viridis
coloring scheme;
and use of FPKMs follows the black-to-yellow scheme we defined in fpkm_color_fun
.
sessionInfo() # devtools::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.