Title: | Simplex Visualization of Cell Fate Similarity in Single-Cell Data |
---|---|
Description: | Create simplex plots to visualize the similarity between single-cells and selected clusters in a 1-/2-/3-simplex space. Velocity information can be added as an additional layer. See Liu J, Wang Y et al (2023) <doi:10.1101/2023.12.07.570655> for more details. |
Authors: | Yichen Wang [aut, cre] , Jialin Liu [aut] , Joshua Welch [cph] |
Maintainer: | Yichen Wang <[email protected]> |
License: | GPL-3 |
Version: | 0.1.99 |
Built: | 2024-12-17 05:15:41 UTC |
Source: | https://github.com/welch-lab/CytoSimplex |
Normalize each column of the input matrix by the column sum
colNormalize(x, scaleFactor = NULL, log = FALSE, ...) ## Default S3 method: colNormalize(x, scaleFactor = NULL, log = FALSE, ...) ## S3 method for class 'dgCMatrix' colNormalize(x, scaleFactor = NULL, log = FALSE, ...) ## S3 method for class 'Seurat' colNormalize( x, scaleFactor = NULL, log = FALSE, assay = NULL, layer = "counts", ... ) ## S3 method for class 'SingleCellExperiment' colNormalize(x, scaleFactor = NULL, log = FALSE, assay.type = "counts", ...)
colNormalize(x, scaleFactor = NULL, log = FALSE, ...) ## Default S3 method: colNormalize(x, scaleFactor = NULL, log = FALSE, ...) ## S3 method for class 'dgCMatrix' colNormalize(x, scaleFactor = NULL, log = FALSE, ...) ## S3 method for class 'Seurat' colNormalize( x, scaleFactor = NULL, log = FALSE, assay = NULL, layer = "counts", ... ) ## S3 method for class 'SingleCellExperiment' colNormalize(x, scaleFactor = NULL, log = FALSE, assay.type = "counts", ...)
x |
Feature by observation matrix. Alternatively, |
scaleFactor |
Multiplier on normalized data. Default |
log |
Logical. Whether to take log1p transformation after scaling.
Default |
... |
Additional arguments passed to methods |
assay |
For "Seurat" method, the specific assay to get data from.
Default |
layer |
For "Seurat" method, which layer of the assay to be used.
Default |
assay.type |
For "SingleCellExperiment" method, the assay type to get
data from. Default |
Normalized matrix of the same size
A Seurat object with normalized data in the specified slot of the specified assay.
A SingleCellExperiment object with normalized data in the specified
assay. "normcounts"
if log = FALSE
and "logcounts"
if
log = TRUE
.
rnaNorm <- colNormalize(rnaRaw) # Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) srt <- colNormalize(srt) # SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) sce <- colNormalize(sce)
rnaNorm <- colNormalize(rnaRaw) # Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) srt <- colNormalize(srt) # SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) sce <- colNormalize(sce)
Create binary plots that show similarity between single cells and two selected terminals in a barycentric coordinate. The two vertices are placed at the left and right of a 2D plot where x-axis measures the similarity. Y-axis is jittered for a clear view. A density (histogram) curve is added for indicating the distribution.
See plotTernary
manual for more details.
plotBinary(x, ...) ## Default S3 method: plotBinary( x, clusterVar, vertices, features = NULL, byCluster = NULL, processed = FALSE, method = c("euclidean", "cosine", "pearson", "spearman"), force = FALSE, sigma = 0.08, scale = TRUE, dotColor = "grey60", returnData = FALSE, ... ) ## S3 method for class 'Seurat' plotBinary( x, layer = "counts", assay = NULL, clusterVar = NULL, processed = FALSE, ... ) ## S3 method for class 'SingleCellExperiment' plotBinary(x, assay.type = "counts", clusterVar = NULL, processed = FALSE, ...) ## S3 method for class 'simMat' plotBinary( x, dotSize = 0.6, dotColor = "grey60", densLinewidth = 0.8, labelColors = c("#3B4992FF", "#EE0000FF"), title = NULL, ... )
plotBinary(x, ...) ## Default S3 method: plotBinary( x, clusterVar, vertices, features = NULL, byCluster = NULL, processed = FALSE, method = c("euclidean", "cosine", "pearson", "spearman"), force = FALSE, sigma = 0.08, scale = TRUE, dotColor = "grey60", returnData = FALSE, ... ) ## S3 method for class 'Seurat' plotBinary( x, layer = "counts", assay = NULL, clusterVar = NULL, processed = FALSE, ... ) ## S3 method for class 'SingleCellExperiment' plotBinary(x, assay.type = "counts", clusterVar = NULL, processed = FALSE, ...) ## S3 method for class 'simMat' plotBinary( x, dotSize = 0.6, dotColor = "grey60", densLinewidth = 0.8, labelColors = c("#3B4992FF", "#EE0000FF"), title = NULL, ... )
x |
Input data. Can be a |
... |
Arguments passed to other methods. |
clusterVar |
A vector/factor assigning the cluster variable to each
column of the matrix object. For "Seurat" method, |
vertices |
Vector of three unique cluster names that will be used for plotting. Or a named list that groups clusters as three terminal vertices. There must not be any overlap between groups. |
features |
Valid matrix row subsetting index to select features for
similarity calculation. Default |
byCluster |
Default |
processed |
Logical. Whether the input matrix is already processed.
|
method |
Similarity calculation method. Default |
force |
Whether to force calculate the similarity when more then 500
features are detected, which is generally not recommended. Default
|
sigma |
Gaussian kernel parameter that controls the effect of variance.
Only effective when using a distance metric (i.e. |
scale |
Whether to min-max scale the distance matrix by clusters.
Default |
returnData |
Logical. Whether to return similarity data instead of
generating plot. Default |
layer |
For "Seurat" method, which layer of the assay to be used.
Default |
assay |
For "Seurat" method, the specific assay to get data from.
Default |
assay.type |
For "SingleCellExperiment" methods. Which assay to use for
calculating the similarity. Default |
dotSize , dotColor
|
Dot aesthetics passed to
|
densLinewidth |
Density plot line aesthetic. Default |
labelColors |
Color of the axis lines and vertex labels. Default
|
title |
Title text of the plot. Default |
For 'simMat' method, a ggplot object. For other methods, a ggplot
object when splitCluster = FALSE
, or a list of ggplot objects when
splitCluster = TRUE
.
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("RE", "OS")) plotBinary(rnaRaw, rnaCluster, c("RE", "OS"), gene) # Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE")) plotBinary(srt, features = gene, vertices = c("OS", "RE")) # SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE")) plotBinary(sce, features = gene, vertices = c("OS", "RE"))
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("RE", "OS")) plotBinary(rnaRaw, rnaCluster, c("RE", "OS"), gene) # Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE")) plotBinary(srt, features = gene, vertices = c("OS", "RE")) # SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE")) plotBinary(sce, features = gene, vertices = c("OS", "RE"))
Create quaternary plots that show similarity between single cells and selected four terminals in a baricentric coordinate.
See plotTernary
for more details on methodologies.
A dynamic rotating view in a GIF image file can be created with
writeQuaternaryGIF
. Package magick
must be installed in
advance. Linux users may refer to this
installation guide.
plotQuaternary(x, ...) ## Default S3 method: plotQuaternary( x, clusterVar, vertices, features = NULL, veloGraph = NULL, byCluster = NULL, processed = FALSE, method = c("euclidean", "cosine", "pearson", "spearman"), force = FALSE, sigma = 0.05, scale = TRUE, dotColorBy = NULL, dotColor = NULL, palette = "D", direction = 1, breaks = NULL, legendTitle = NULL, returnData = FALSE, ... )
plotQuaternary(x, ...) ## Default S3 method: plotQuaternary( x, clusterVar, vertices, features = NULL, veloGraph = NULL, byCluster = NULL, processed = FALSE, method = c("euclidean", "cosine", "pearson", "spearman"), force = FALSE, sigma = 0.05, scale = TRUE, dotColorBy = NULL, dotColor = NULL, palette = "D", direction = 1, breaks = NULL, legendTitle = NULL, returnData = FALSE, ... )
x |
Input data. Can be a |
... |
Arguments passed on to
|
clusterVar |
A vector/factor assigning the cluster variable to each
column of the matrix object. For "Seurat" method, |
vertices |
Vector of three unique cluster names that will be used for plotting. Or a named list that groups clusters as three terminal vertices. There must not be any overlap between groups. |
features |
Valid matrix row subsetting index to select features for
similarity calculation. Default |
veloGraph |
Cell x cell |
byCluster |
Default |
processed |
Logical. Whether the input matrix is already processed.
|
method |
Similarity calculation method. Default |
force |
Whether to force calculate the similarity when more then 500
features are detected, which is generally not recommended. Default
|
sigma |
Gaussian kernel parameter that controls the effect of variance.
Only effective when using a distance metric (i.e. |
scale |
Whether to min-max scale the distance matrix by clusters.
Default |
dotColorBy |
A vector/factor for coloring dots, can be either categorical
(must be character or factor) or continuous. Default |
dotColor |
Character vector of color codes. When |
palette |
Color palette to use when |
direction |
Sets the order of colors in the scale. Default |
breaks |
Number of breaks for continuous color scale passed to
non-interactive "plot3D::scatter3D" call. Default |
legendTitle |
Title on the legend/colorbar. Default |
returnData |
Logical. Whether to return similarity and aggregated
velocity data if applicable instead of generating plot. Default |
By default, a "plotly" object. When interactive = FALSE
, a
"quatPlot" object when byCluster
is not specified, or a "list" of
"quatPlot" objects when byCluster
is specified. When
returnData = TRUE
, a list of similarity matrix and aggregated velocity
matrix is returned.
Other plotQuaternary:
plotQuaternary.Seurat()
,
plotQuaternary.SingleCellExperiment()
gene <- selectTopFeatures( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT") ) plotQuaternary( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT"), features = gene )
gene <- selectTopFeatures( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT") ) plotQuaternary( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT"), features = gene )
Create quaternary plots that show similarity between single cells and selected four terminals in a baricentric coordinate.
See plotTernary
for more details on methodologies.
A dynamic rotating view in a GIF image file can be created with
writeQuaternaryGIF
. Package magick
must be installed in
advance. Linux users may refer to this
installation guide.
## S3 method for class 'Seurat' plotQuaternary( x, layer = "counts", assay = NULL, clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
## S3 method for class 'Seurat' plotQuaternary( x, layer = "counts", assay = NULL, clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
x |
A Seurat object |
layer |
Layer in the specified assay to use. Default |
assay |
The assay to get data from. Default |
clusterVar |
A variable name in meta.data ( |
processed |
Logical. Whether the input matrix is already processed.
|
dotColorBy |
A vector/factor for coloring dots, can be either categorical
(must be character or factor) or continuous. Default |
legendTitle |
Title on the legend/colorbar. Default |
... |
Arguments passed on to
|
By default, a "plotly" object. When interactive = FALSE
, a
"quatPlot" object when byCluster
is not specified, or a "list" of
"quatPlot" objects when byCluster
is specified. When
returnData = TRUE
, a list of similarity matrix and aggregated velocity
matrix is returned.
Other plotQuaternary:
plotQuaternary()
,
plotQuaternary.SingleCellExperiment()
# Seurat example if (requireNamespace("Seurat", quietly = TRUE)) { require(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE", "CH", "ORT")) plotQuaternary(srt, features = gene, vertices = c("OS", "RE", "CH", "ORT")) }
# Seurat example if (requireNamespace("Seurat", quietly = TRUE)) { require(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE", "CH", "ORT")) plotQuaternary(srt, features = gene, vertices = c("OS", "RE", "CH", "ORT")) }
Create quaternary simplex plot with pre-calculated similarity matrix
## S3 method for class 'simMat' plotQuaternary( x, veloMat = NULL, nGrid = 10, radius = 0.2, dotSize = NULL, colorArg = NULL, labelColors = c("#3B4992FF", "#EE0000FF", "#008B45FF", "#631879FF"), arrowLinewidth = NULL, arrowAngle = 20, arrowLen = 0.1, vertexLabelSize = NULL, edgeLinewidth = 1, title = NULL, titleSize = 1, titleColor = "black", theta = 20, phi = 0, interactive = TRUE, ... )
## S3 method for class 'simMat' plotQuaternary( x, veloMat = NULL, nGrid = 10, radius = 0.2, dotSize = NULL, colorArg = NULL, labelColors = c("#3B4992FF", "#EE0000FF", "#008B45FF", "#631879FF"), arrowLinewidth = NULL, arrowAngle = 20, arrowLen = 0.1, vertexLabelSize = NULL, edgeLinewidth = 1, title = NULL, titleSize = 1, titleColor = "black", theta = 20, phi = 0, interactive = TRUE, ... )
x |
simMat object, n cells by 4 vertices, each row summing to 1. |
veloMat |
Aggregated velocity matrix. Output of |
nGrid |
Number of grids along the x-axis of the tetrahedron. Default
|
radius |
Arrow length of unit velocity. Lower this when arrows point
outside of the tetrahedron. Default |
dotSize |
Size of each dot. Default |
colorArg |
A "colorArg" object, internally prepared by
|
labelColors |
Colors of the vertex labels. Default
|
arrowLinewidth |
Arrow aesthetics. Default |
arrowAngle , arrowLen
|
Arrow aesthetics passed to TODOOOO
|
vertexLabelSize |
Numeric, size of vertex text label relative to default
size. Default |
edgeLinewidth |
Controls the linewidth of the edges of the tetrahedron.
Default |
title |
Title text of the plot. Default |
titleSize , titleColor
|
Setting on the main title text. Default |
theta , phi
|
Numeric scalar. The angles defining the viewing direction.
|
interactive |
Logical. Whether to display plotly interactive view.
Default |
... |
Not used |
A "quatPlot" object, can be displayed by printing.
Create quaternary plots that show similarity between single cells and selected four terminals in a baricentric coordinate.
See plotTernary
for more details on methodologies.
A dynamic rotating view in a GIF image file can be created with
writeQuaternaryGIF
. Package magick
must be installed in
advance. Linux users may refer to this
installation guide.
## S3 method for class 'SingleCellExperiment' plotQuaternary( x, assay.type = "counts", clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
## S3 method for class 'SingleCellExperiment' plotQuaternary( x, assay.type = "counts", clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
x |
A SingleCellExperiment object |
assay.type |
Assay to use for calculating the similarity. Default
|
clusterVar |
A variable name in |
processed |
Logical. Whether the input matrix is already processed.
|
dotColorBy |
A vector/factor for coloring dots, can be either categorical
(must be character or factor) or continuous. Default |
legendTitle |
Title on the legend/colorbar. Default |
... |
Arguments passed on to
|
By default, a "plotly" object. When interactive = FALSE
, a
"quatPlot" object when byCluster
is not specified, or a "list" of
"quatPlot" objects when byCluster
is specified. When
returnData = TRUE
, a list of similarity matrix and aggregated velocity
matrix is returned.
Other plotQuaternary:
plotQuaternary()
,
plotQuaternary.Seurat()
# SingleCellExperiment example if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { require(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE", "CH", "ORT")) plotQuaternary(sce, features = gene, vertices = c("OS", "RE", "CH", "ORT")) }
# SingleCellExperiment example if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { require(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE", "CH", "ORT")) plotQuaternary(sce, features = gene, vertices = c("OS", "RE", "CH", "ORT")) }
Create ternary plots that show similarity between single cells and selected three terminals in a ternary baricentric coordinate.
plotTernary(x, ...) ## Default S3 method: plotTernary( x, clusterVar, vertices, features = NULL, veloGraph = NULL, byCluster = NULL, processed = FALSE, method = c("euclidean", "cosine", "pearson", "spearman"), force = FALSE, sigma = 0.08, scale = TRUE, dotColorBy = NULL, dotColor = NULL, palette = "D", direction = 1, breaks = NULL, legendTitle = NULL, returnData = FALSE, ... )
plotTernary(x, ...) ## Default S3 method: plotTernary( x, clusterVar, vertices, features = NULL, veloGraph = NULL, byCluster = NULL, processed = FALSE, method = c("euclidean", "cosine", "pearson", "spearman"), force = FALSE, sigma = 0.08, scale = TRUE, dotColorBy = NULL, dotColor = NULL, palette = "D", direction = 1, breaks = NULL, legendTitle = NULL, returnData = FALSE, ... )
x |
Input data. Can be a |
... |
Arguments passed on to
|
clusterVar |
A vector/factor assigning the cluster variable to each
column of the matrix object. For "Seurat" method, |
vertices |
Vector of three unique cluster names that will be used for plotting. Or a named list that groups clusters as three terminal vertices. There must not be any overlap between groups. |
features |
Valid matrix row subsetting index to select features for
similarity calculation. Default |
veloGraph |
Cell x cell |
byCluster |
Default |
processed |
Logical. Whether the input matrix is already processed.
|
method |
Similarity calculation method. Default |
force |
Whether to force calculate the similarity when more then 500
features are detected, which is generally not recommended. Default
|
sigma |
Gaussian kernel parameter that controls the effect of variance.
Only effective when using a distance metric (i.e. |
scale |
Whether to min-max scale the distance matrix by clusters.
Default |
dotColorBy |
A vector/factor for coloring dots, can be either categorical
(must be character or factor) or continuous. Default |
dotColor |
Character vector of color codes. When |
palette |
Color palette to use when |
direction |
Sets the order of colors in the scale. Default |
breaks |
Number of breaks for continuous color scale passed to
non-interactive "plot3D::scatter3D" call. Default |
legendTitle |
Title on the legend/colorbar. Default |
returnData |
Logical. Whether to return similarity and aggregated
velocity data if applicable instead of generating plot. Default |
Argument inheritance - For matrix/dgCMatrix ("default" method), we first calculate the similarity matrix and obtain a "simMat" object. Then the "simMat" method is internally called. For data container objects (e.g. Seurat), we obtain the correct data matrix first and then call the "default" method. The arguments inherits as the flow described above.
The calculation of similarity matrix - The similarity is calculated either by converting a distance metric ("euclidean" or "cosine") with Gaussian kernel, or directly computed with correlation metrics ("pearson" or "spearman"). The centroid of each terminal is obtained first, and the specified metric from each cell to each terminal is calculated. The similarity matrix (n cells by v terminals) is lastly normalized to sum to 1 for each cell, so it becomes a baricentric coordinate.
By default, a "ggplot" object when byCluster
is not specified,
a list of "ggplot" object when byCluster
is specified. When
interactive = TRUE
, a "plotly" object is returned. When
returnData = TRUE
, a list of similarity matrix and aggregated velocity
matrix is returned.
Other plotTernary:
plotTernary.Seurat()
,
plotTernary.SingleCellExperiment()
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("OS", "RE", "CH")) plotTernary(rnaRaw, rnaCluster, c("OS", "RE", "CH"), gene)
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("OS", "RE", "CH")) plotTernary(rnaRaw, rnaCluster, c("OS", "RE", "CH"), gene)
Create ternary plots that show similarity between single cells and selected three terminals in a ternary baricentric coordinate.
## S3 method for class 'Seurat' plotTernary( x, layer = "counts", assay = NULL, clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
## S3 method for class 'Seurat' plotTernary( x, layer = "counts", assay = NULL, clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
x |
A Seurat object |
layer |
Layer in the specified assay to use. Default |
assay |
The assay to get data from. Default |
clusterVar |
A variable name in meta.data ( |
processed |
Logical. Whether the input matrix is already processed.
|
dotColorBy |
A vector/factor for coloring dots, can be either categorical
(must be character or factor) or continuous. Default |
legendTitle |
Title on the legend/colorbar. Default |
... |
Arguments passed on to
|
By default, a "ggplot" object when byCluster
is not specified,
a list of "ggplot" object when byCluster
is specified. When
interactive = TRUE
, a "plotly" object is returned. When
returnData = TRUE
, a list of similarity matrix and aggregated velocity
matrix is returned.
Other plotTernary:
plotTernary()
,
plotTernary.SingleCellExperiment()
# Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE", "CH")) plotTernary(srt, features = gene, vertices = c("OS", "RE", "CH"))
# Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE", "CH")) plotTernary(srt, features = gene, vertices = c("OS", "RE", "CH"))
Create quaternary simplex plot with pre-calculated similarity matrix
## S3 method for class 'simMat' plotTernary( x, title = NULL, veloMat = NULL, nGrid = 10, radius = 0.1, dotSize = NULL, dotShuffle = NULL, colorArg = NULL, labelColors = c("#3B4992FF", "#EE0000FF", "#008B45FF"), vertexLabelSize = NULL, vertexLabelDrift = 0.03, axisBreak = 5, axisTextShow = TRUE, axisTextSize = NULL, axisTextDrift = 0.01, gridLineAlpha = 0.6, arrowLinewidth = NULL, arrowAngle = 20, arrowLen = 0.2, titleSize = NULL, equilateral = TRUE, margin = 0.1, interactive = FALSE, ... )
## S3 method for class 'simMat' plotTernary( x, title = NULL, veloMat = NULL, nGrid = 10, radius = 0.1, dotSize = NULL, dotShuffle = NULL, colorArg = NULL, labelColors = c("#3B4992FF", "#EE0000FF", "#008B45FF"), vertexLabelSize = NULL, vertexLabelDrift = 0.03, axisBreak = 5, axisTextShow = TRUE, axisTextSize = NULL, axisTextDrift = 0.01, gridLineAlpha = 0.6, arrowLinewidth = NULL, arrowAngle = 20, arrowLen = 0.2, titleSize = NULL, equilateral = TRUE, margin = 0.1, interactive = FALSE, ... )
x |
simMat object, n cells by 4 vertices, each row summing to 1. |
title |
Title text of the plot. Default |
veloMat |
Aggregated velocity matrix. Output of |
nGrid |
Number of grids along the bottom side of the equilateral
triangle. Default |
radius |
Arrow length of unit velocity. Lower this when arrows point
outside of the coordinate. Default |
dotSize |
Dot aesthetics passed to |
dotShuffle |
Whether to shuffle the order of dots being added to the
plot, useful when categorical colors are used and mixing of categories is
expected. Default |
colorArg |
A "colorArg" object, internally prepared by
|
labelColors |
Colors of the axis lines and vertex labels.
Default |
vertexLabelSize |
Size of vertex labels. Default |
vertexLabelDrift |
Position adjustment of the vertex labels, only
applied to non-interactive view. Default |
axisBreak |
Number of breaks to be labeled along axis. Default
|
axisTextShow |
Logical, whether to show axis text. Default |
axisTextSize |
Size of text along each axis break. Default |
axisTextDrift |
Position adjustment of the axis text, only applied to
non-interactive view. Default |
gridLineAlpha |
Transparency of background grid lines. Default
|
arrowLinewidth |
Line width of the velocity arrows. Default |
arrowAngle |
Controls the angle of the arrowhead, only applied to
non-interactive view. Default |
arrowLen |
Control length in centimetre from arrow tip to arrow tail,
only applied to non-interactive view. Default |
titleSize |
Size of title text. Default |
equilateral |
Logical, whether to always display the triangle as
equilateral. Default |
margin |
Margin allowed around of the triangle plotting region when
|
interactive |
Logical. Whether to display plotly interactive view.
Default |
... |
Not used |
Create ternary plots that show similarity between single cells and selected three terminals in a ternary baricentric coordinate.
## S3 method for class 'SingleCellExperiment' plotTernary( x, assay.type = "counts", clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
## S3 method for class 'SingleCellExperiment' plotTernary( x, assay.type = "counts", clusterVar = NULL, processed = FALSE, dotColorBy = NULL, legendTitle = NULL, ... )
x |
A SingleCellExperiment object. |
assay.type |
Assay to use for calculating the similarity. Default
|
clusterVar |
A variable name in |
processed |
Logical. Whether the input matrix is already processed.
|
dotColorBy |
A vector/factor for coloring dots, can be either categorical
(must be character or factor) or continuous. Default |
legendTitle |
Title on the legend/colorbar. Default |
... |
Arguments passed on to
|
By default, a "ggplot" object when byCluster
is not specified,
a list of "ggplot" object when byCluster
is specified. When
interactive = TRUE
, a "plotly" object is returned. When
returnData = TRUE
, a list of similarity matrix and aggregated velocity
matrix is returned.
Other plotTernary:
plotTernary()
,
plotTernary.Seurat()
# SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE", "CH")) plotTernary(sce, features = gene, vertices = c("OS", "RE", "CH"))
# SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE", "CH")) plotTernary(sce, features = gene, vertices = c("OS", "RE", "CH"))
Show plist object produced with plot3D package
## S3 method for class 'quatPlot' print(x, ...)
## S3 method for class 'quatPlot' print(x, ...)
x |
quatPlot object, returned by |
... |
Graphic parameters passed to |
No return value. It displays the plot described in a 'plist' object
returned by plotQuaternary
, internally created by package
'plot3D'.
gene <- selectTopFeatures( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT") ) quat <- plotQuaternary( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT"), features = gene, interactive = FALSE ) quat; print(quat)
gene <- selectTopFeatures( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT") ) quat <- plotQuaternary( x = rnaRaw, clusterVar = rnaCluster, vertices = c("RE", "OS", "CH", "ORT"), features = gene, interactive = FALSE ) quat; print(quat)
It frequently happens that velocity analyses stored in H5AD files do not contain the full raw count data suggested for CytoSimplex visualization. Extracting the cell IDs (e.g. barcodes) helps matching the velocity data to raw count data imported from other sources.
readH5ADObsNames(filename)
readH5ADObsNames(filename)
filename |
File path to the H5AD file. |
A character vector of cell IDs.
Other H5AD-reader:
readH5ADObsVar()
,
readH5ADUnsSpMat()
,
readVelocytoLoom()
## Not run: h5adFile <- "path/to/analysis.h5ad" cellIDs <- readH5ADObsNames(h5adFile) ## End(Not run)
## Not run: h5adFile <- "path/to/analysis.h5ad" cellIDs <- readH5ADObsNames(h5adFile) ## End(Not run)
Primarily designed for fetching the annotation used for visualization.
readH5ADObsVar(filename, obsKey, named = TRUE, categoricalAsFactor = TRUE)
readH5ADObsVar(filename, obsKey, named = TRUE, categoricalAsFactor = TRUE)
filename |
File path to the H5AD file. |
obsKey |
The variable name to extract, must use only one character string. |
named |
Logical, whether to name the vector with cell IDs that came from
|
categoricalAsFactor |
Logical, whether to convert categorical variables
to factors. Default |
A vector of the extracted variable, or a factor if the variable is
encoded to be categorical and categoricalAsFactor = TRUE
.
Other H5AD-reader:
readH5ADObsNames()
,
readH5ADUnsSpMat()
,
readVelocytoLoom()
## Not run: h5adFile <- "path/to/analysis.h5ad" cluster <- readH5ADObsVar(h5adFile, "leiden") ## End(Not run)
## Not run: h5adFile <- "path/to/analysis.h5ad" cluster <- readH5ADObsVar(h5adFile, "leiden") ## End(Not run)
Primarily designed for fetching the velocity data presented as a cell-cell transition graph.
readH5ADUnsSpMat(filename, unsKey)
readH5ADUnsSpMat(filename, unsKey)
filename |
File path to the H5AD file. |
unsKey |
The |
A CSC-matrix of "dgCMatrix" class
Other H5AD-reader:
readH5ADObsNames()
,
readH5ADObsVar()
,
readVelocytoLoom()
## Not run: h5adFile <- "path/to/analysis.h5ad" velo <- readH5ADUnsSpMat(h5adFile, "velo_s_norm_graph") ## End(Not run)
## Not run: h5adFile <- "path/to/analysis.h5ad" velo <- readH5ADUnsSpMat(h5adFile, "velo_s_norm_graph") ## End(Not run)
This function is primarily designed for fetching the raw count data from a LOOM file, output by Velocyto. We by default use the spliced counts.
readVelocytoLoom( filename, matrixPath = "layers/spliced", cellID = "CellID", featureID = "Gene", chunkSize = 1000 )
readVelocytoLoom( filename, matrixPath = "layers/spliced", cellID = "CellID", featureID = "Gene", chunkSize = 1000 )
filename |
File path to the LOOM file. |
matrixPath |
A path in the LOOM file to the matrix to extract, following
the inner HDF5 structure. Default |
cellID |
The name of the cell ID column in the LOOM column-attributes.
The same thing as argument |
featureID |
The name of the feature ID column in the LOOM
row-attributes. The same thing as argument |
chunkSize |
The maximum size of the chunk to load the matrix. Default 1000. |
The velocyto output LOOM file is HDF5 based and is roughly organized as follows:
"matrix"
: The whole raw counts, which is the sum of spliced, unspliced
and ambiguous counts.
layers: A group like a folder
"layers/spliced"
: The spliced counts.
"layers/unspliced"
: The unspliced counts.
"layers/ambiguous"
: The ambiguous counts.
An AnnData object created with Scanpy by default loads the data with a
different structure, so that all the four matrices are accessible in
adata.layers
and set one of them (by default "layers/spliced"
)
to adata.X
.
A sparse matrix of class "dgCMatrix", with cells as columns and genes as rows.
Other H5AD-reader:
readH5ADObsNames()
,
readH5ADObsVar()
,
readH5ADUnsSpMat()
## Not run: loomFile <- "velocyto/out/analysis.loom" rawCounts <- readVelocytoLoom(loomFile) ## End(Not run)
## Not run: loomFile <- "velocyto/out/analysis.loom" rawCounts <- readVelocytoLoom(loomFile) ## End(Not run)
Major cell type annotation of the example mouse bone marrow data
rnaCluster
rnaCluster
factor
object
https://www.nature.com/articles/s41467-023-38034-2
Matsushita, Y., Liu, J., Chu, A.K.Y. et al. Bone marrow endosteal stem cells dictate active osteogenesis and aggressive tumorigenesis. Nat Commun 14, 2383 (2023).
Mouse bone marrow scRNAseq example data
rnaRaw
rnaRaw
dgCMatrix object
https://www.nature.com/articles/s41467-023-38034-2
Matsushita, Y., Liu, J., Chu, A.K.Y. et al. Bone marrow endosteal stem cells dictate active osteogenesis and aggressive tumorigenesis. Nat Commun 14, 2383 (2023).
Velocity graph of the example mouse bone marrow data
rnaVelo
rnaVelo
dgCMatrix object
https://www.nature.com/articles/s41467-023-38034-2
Matsushita, Y., Liu, J., Chu, A.K.Y. et al. Bone marrow endosteal stem cells dictate active osteogenesis and aggressive tumorigenesis. Nat Commun 14, 2383 (2023).
Performs wilcoxon rank-sum test on input matrix. While clusterVar
and
vertices
together defines the groups of cells to be set as terminals
of the simplex, this function will test each of these groups against the rest
of the cells. The U-Statistics (statistic
), p-value (pval
) and
adjusted p-value (padj
), together with average presence in group
(avgExpr
), log fold-change (logFC
), AUC (auc
),
percentage in group (pct_in
) and percentage out of group
(pct_out
) will be calculated. Set returnStats = TRUE
to return
the full statistics table.
Top features are selected by sorting primarily on adjusted p-value, and secondarily on log fold-change, after filtering for up-regulated features.
selectTopFeatures(x, clusterVar, vertices, ...) ## Default S3 method: selectTopFeatures( x, clusterVar, vertices, nTop = 30, processed = FALSE, lfcThresh = 0.1, returnStats = FALSE, ... ) ## S3 method for class 'Seurat' selectTopFeatures( x, clusterVar = NULL, vertices, assay = NULL, layer = "counts", processed = FALSE, ... ) ## S3 method for class 'SingleCellExperiment' selectTopFeatures( x, clusterVar = NULL, vertices, assay.type = "counts", processed = FALSE, ... )
selectTopFeatures(x, clusterVar, vertices, ...) ## Default S3 method: selectTopFeatures( x, clusterVar, vertices, nTop = 30, processed = FALSE, lfcThresh = 0.1, returnStats = FALSE, ... ) ## S3 method for class 'Seurat' selectTopFeatures( x, clusterVar = NULL, vertices, assay = NULL, layer = "counts", processed = FALSE, ... ) ## S3 method for class 'SingleCellExperiment' selectTopFeatures( x, clusterVar = NULL, vertices, assay.type = "counts", processed = FALSE, ... )
x |
Dense or sparse matrix, observation per column. Preferrably a raw
count matrix. Alternatively, a |
clusterVar |
A vector/factor assigning the cluster variable to each
column of the matrix object. For "Seurat" method, |
vertices |
Vector of cluster names that will be used for plotting. Or a named list that groups clusters as a terminal vertex. There must not be any overlap between groups. |
... |
Arguments passed to methods. |
nTop |
Number of top differentially presented features per terminal.
Default |
processed |
Logical. Whether the input matrix is already processed.
|
lfcThresh |
Threshold on log fold-change to identify up-regulated
features. Default |
returnStats |
Logical. Whether to return the full statistics table
rather then returning the selected genes. Default |
assay |
Assay name of the Seurat object to be used. Default |
layer |
For "Seurat" method, which layer of the assay to be used.
Default |
assay.type |
Assay name of the SingleCellExperiment object to be used.
Default |
When returnStats = FALSE
(default), a character vector of at
most length(unique(vertices))*nTop
feature names. When
returnStats = TRUE
, a data.frame of wilcoxon rank sum test statistics.
selectTopFeatures(rnaRaw, rnaCluster, c("OS", "RE")) # Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE")) # SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE"))
selectTopFeatures(rnaRaw, rnaCluster, c("OS", "RE")) # Seurat example library(Seurat) srt <- CreateSeuratObject(rnaRaw) Idents(srt) <- rnaCluster gene <- selectTopFeatures(srt, vertices = c("OS", "RE")) # SingleCellExperiment example library(SingleCellExperiment) sce <- SingleCellExperiment(assays = list(counts = rnaRaw)) colLabels(sce) <- rnaCluster gene <- selectTopFeatures(sce, vertices = c("OS", "RE"))
Create GIF image for dynamic rotating view of 3D quaternary simplex plot
writeQuaternaryGIF( x, ..., cluster = NULL, filename = NULL, fps = 10, degreePerFrame = 10, width = 5, height = 5, res = 100 )
writeQuaternaryGIF( x, ..., cluster = NULL, filename = NULL, fps = 10, degreePerFrame = 10, width = 5, height = 5, res = 100 )
x |
Input object that |
... |
All other arguments needed for |
cluster |
One cluster that exists in |
filename |
Output GIF image file path. Default |
fps |
Number of frame per second, must be a factor of 100. Default
|
degreePerFrame |
Number of degree that the tetrahedron is rotated per
frame. Default |
width , height , res
|
|
A object of class magick-image
that can be shown in the Viewer
panel in RStudio or equivalent display device. If filename
is
specified, the GIF image will be written to the file path.
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("RE", "OS", "CH", "ORT")) writeQuaternaryGIF(rnaRaw, clusterVar = rnaCluster, features = gene, vertices = c("RE", "OS", "CH", "ORT"), gifPath = tempfile(fileext = ".gif"))
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("RE", "OS", "CH", "ORT")) writeQuaternaryGIF(rnaRaw, clusterVar = rnaCluster, features = gene, vertices = c("RE", "OS", "CH", "ORT"), gifPath = tempfile(fileext = ".gif"))