| CRMetrics | R Documentation |
Functions to analyze Cell Ranger count data. To initialize a new object, 'data.path' or 'cms' is needed. 'metadata' is also recommended, but not required.
metadatadata.frame or character Path to metadata file or name of metadata data.frame object. Metadata must contain a column named 'sample' containing sample names that must match folder names in 'data.path' (default = NULL)
data.pathcharacter Path(s) to Cell Ranger count data, one directory per sample. If multiple paths, do c("path1","path2") (default = NULL)
cmslist List with count matrices (default = NULL)
cms.preprocessedlist List with preprocessed count matrices after $doPreprocessing() (default = NULL)
cms.rawlist List with raw, unfiltered count matrices, i.e., including all CBs detected also empty droplets (default = NULL)
summary.metricsdata.frame Summary metrics from Cell Ranger (default = NULL)
detailed.metricsdata.frame Detailed metrics, i.e., no. genes and UMIs per cell (default = NULL)
comp.groupcharacter A group present in the metadata to compare the metrics by, can be added with addComparison (default = NULL)
verboselogical Print messages or not (default = TRUE)
themeggplot2 theme (default: theme_bw())
palPlotting palette (default = NULL)
n.coresnumeric Number of cores for calculations (default = 1) Initialize a CRMetrics object
new()To initialize new object, 'data.path' or 'cms' is needed. 'metadata' is also recommended, but not required.
CRMetrics$new( data.path = NULL, metadata = NULL, cms = NULL, samples = NULL, unique.names = TRUE, sep.cells = "!!", comp.group = NULL, verbose = TRUE, theme = theme_bw(), n.cores = 1, sep.meta = ",", raw.meta = FALSE, pal = NULL )
data.pathcharacter Path to directory with Cell Ranger count data, one directory per sample (default = NULL).
metadatadata.frame or character Path to metadata file (comma-separated) or name of metadata dataframe object. Metadata must contain a column named 'sample' containing sample names that must match folder names in 'data.path' (default = NULL)
cmslist List with count matrices (default = NULL)
samplescharacter Sample names. Only relevant is cms is provided (default = NULL)
unique.nameslogical Create unique cell names. Only relevant if cms is provided (default = TRUE)
sep.cellscharacter Sample-cell separator. Only relevant if cms is provided and unique.names=TRUE (default = "!!")
comp.groupcharacter A group present in the metadata to compare the metrics by, can be added with addComparison (default = NULL)
verboselogical Print messages or not (default = TRUE)
themeggplot2 theme (default: theme_bw())
n.coresinteger Number of cores for the calculations (default = self$n.cores)
sep.metacharacter Separator for metadata file (default = ",")
raw.metalogical Keep metadata in its raw format. If FALSE, classes will be converted using "type.convert" (default = FALSE)
palcharacter Plotting palette (default = NULL)
CRMetrics object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
}
addDetailedMetrics()Function to read in detailed metrics. This is not done upon initialization for speed.
CRMetrics$addDetailedMetrics( cms = self$cms, min.transcripts.per.cell = 100, n.cores = self$n.cores, verbose = self$verbose )
cmslist List of (sparse) count matrices (default = self$cms)
min.transcripts.per.cellnumeric Minimal number of transcripts per cell (default = 100)
n.coresinteger Number of cores for the calculations (default = self$n.cores).
verboselogical Print messages or not (default = self$verbose).
Count matrices
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Run function
crm$addDetailedMetrics()
addComparison()Add comparison group for statistical testing.
CRMetrics$addComparison(comp.group, metadata = self$metadata)
comp.groupcharacter Comparison metric (default = self$comp.group).
metadatadata.frame Metadata for samples (default = self$metadata).
Vector
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add metadata
crm$metadata <- data.frame(sex = c("male","female"))
# Add comparison group
crm$addComparison(comp.group = "sex")
plotSamples()Plot the number of samples.
CRMetrics$plotSamples( comp.group = self$comp.group, h.adj = 0.05, exact = FALSE, metadata = self$metadata, second.comp.group = NULL, pal = self$pal )
comp.groupcharacter Comparison metric, must match a column name of metadata (default = self$comp.group).
h.adjnumeric Position of statistics test p value as % of max(y) (default = 0.05).
exactlogical Whether to calculate exact p values (default = FALSE).
metadatadata.frame Metadata for samples (default = self$metadata).
second.comp.groupcharacter Second comparison metric, must match a column name of metadata (default = NULL).
palcharacter Plotting palette (default = self$pal)
ggplot2 object
samples <- c("sample1", "sample2")
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
names(testdata.cms) <- samples
# Create metadata
metadata <- data.frame(sample = samples,
sex = c("male","female"),
condition = c("a","b"))
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, metadata = metadata, n.cores = 1)
# Plot
crm$plotSamples(comp.group = "sex", second.comp.group = "condition")
plotSummaryMetrics()Plot all summary stats or a selected list.
CRMetrics$plotSummaryMetrics(
comp.group = self$comp.group,
second.comp.group = NULL,
metrics = NULL,
h.adj = 0.05,
plot.stat = TRUE,
stat.test = c("non-parametric", "parametric"),
exact = FALSE,
metadata = self$metadata,
summary.metrics = self$summary.metrics,
plot.geom = "bar",
se = FALSE,
group.reg.lines = FALSE,
secondary.testing = TRUE,
pal = self$pal
)comp.groupcharacter Comparison metric (default = self$comp.group).
second.comp.groupcharacter Second comparison metric, used for the metric "samples per group" or when "comp.group" is a numeric or an integer (default = NULL).
metricscharacter Metrics to plot (default = NULL).
h.adjnumeric Position of statistics test p value as % of max(y) (default = 0.05)
plot.statlogical Show statistics in plot. Will be FALSE if "comp.group" = "sample" or if "comp.group" is a numeric or an integer (default = TRUE)
stat.testcharacter Statistical test to perform to compare means. Can either be "non-parametric" or "parametric" (default = "non-parametric").
exactlogical Whether to calculate exact p values (default = FALSE).
metadatadata.frame Metadata for samples (default = self$metadata).
summary.metricsdata.frame Summary metrics (default = self$summary.metrics).
plot.geomcharacter Which geometric is used to plot the data (default = "point").
selogical For regression lines, show SE (default = FALSE)
group.reg.lineslogical For regression lines, if FALSE show one line, if TRUE show line per group defined by second.comp.group (default = FALSE)
secondary.testinglogical Whether to show post hoc testing (default = TRUE)
palcharacter Plotting palette (default = self$pal)
ggplot2 object
\donttest{
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add summary metrics
crm$addSummaryFromCms()
crm$plotSummaryMetrics(plot.geom = "point")
}
plotDetailedMetrics()Plot detailed metrics from the detailed.metrics object
CRMetrics$plotDetailedMetrics( comp.group = self$comp.group, detailed.metrics = self$detailed.metrics, metadata = self$metadata, metrics = NULL, plot.geom = "violin", hline = TRUE, pal = self$pal )
comp.groupcharacter Comparison metric (default = self$comp.group).
detailed.metricsdata.frame Object containing the count matrices (default = self$detailed.metrics).
metadatadata.frame Metadata for samples (default = self$metadata).
metricscharacter Metrics to plot. NULL plots both plots (default = NULL).
plot.geomcharacter How to plot the data (default = "violin").
hlinelogical Whether to show median as horizontal line (default = TRUE)
palcharacter Plotting palette (default = self$pal)
data.pathcharacter Path to Cell Ranger count data (default = self$data.path).
ggplot2 object
\donttest{
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add detailed metrics
crm$addDetailedMetrics()
# Plot
crm$plotDetailedMetrics()
}
plotEmbedding()Plot cells in embedding using Conos and color by depth and doublets.
CRMetrics$plotEmbedding(
depth = FALSE,
doublet.method = NULL,
doublet.scores = FALSE,
depth.cutoff = 1000,
mito.frac = FALSE,
mito.cutoff = 0.05,
species = c("human", "mouse"),
size = 0.3,
sep = "!!",
pal = NULL,
...
)depthlogical Plot depth or not (default = FALSE).
doublet.methodcharacter Doublet detection method (default = NULL).
doublet.scoreslogical Plot doublet scores or not (default = FALSE).
depth.cutoffnumeric Depth cutoff (default = 1e3).
mito.fraclogical Plot mitochondrial fraction or not (default = FALSE).
mito.cutoffnumeric Mitochondrial fraction cutoff (default = 0.05).
speciescharacter Species to calculate the mitochondrial fraction for (default = c("human","mouse")).
sizenumeric Dot size (default = 0.3)
sepcharacter Separator for creating unique cell names (default = "!!")
palcharacter Plotting palette (default = NULL)
...Plotting parameters passed to sccore::embeddingPlot.
ggplot2 object
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
crm$plotEmbedding()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
plotDepth()Plot the sequencing depth in histogram.
CRMetrics$plotDepth( cutoff = 1000, samples = self$metadata$sample, sep = "!!", keep.col = "#E7CDC2", filter.col = "#A65141" )
cutoffnumeric The depth cutoff to color the cells in the embedding (default = 1e3).
samplescharacter Sample names to include for plotting (default = $metadata$sample).
sepcharacter Separator for creating unique cell names (default = "!!")
keep.colcharacter Color for density of cells that are kept (default = "#E7CDC2")
filter.colCharacter Color for density of cells to be filtered (default = "#A65141")
ggplot2 object
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Plot
crm$plotDepth()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
plotMitoFraction()Plot the mitochondrial fraction in histogram.
CRMetrics$plotMitoFraction(
cutoff = 0.05,
species = c("human", "mouse"),
samples = self$metadata$sample,
sep = "!!",
keep.col = "#E7CDC2",
filter.col = "#A65141"
)cutoffnumeric The mito. fraction cutoff to color the embedding (default = 0.05)
speciescharacter Species to calculate the mitochondrial fraction for (default = "human")
samplescharacter Sample names to include for plotting (default = $metadata$sample)
sepcharacter Separator for creating unique cell names (default = "!!")
keep.colcharacter Color for density of cells that are kept (default = "#E7CDC2")
filter.colCharacter Color for density of cells to be filtered (default = "#A65141")
ggplot2 object
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Plot
crm$plotMitoFraction()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
detectDoublets()Detect doublet cells.
CRMetrics$detectDoublets(
method = c("scrublet", "doubletdetection"),
cms = self$cms,
samples = self$metadata$sample,
env = "r-reticulate",
conda.path = system("whereis conda"),
n.cores = self$n.cores,
verbose = self$verbose,
args = list(),
export = FALSE,
data.path = self$data.path
)methodcharacter Which method to use, either scrublet or doubletdetection (default="scrublet").
cmslist List containing the count matrices (default=self$cms).
samplescharacter Vector of sample names. If NULL, samples are extracted from cms (default = self$metadata$sample)
envcharacter Environment to run python in (default="r-reticulate").
conda.pathcharacter Path to conda environment (default=system("whereis conda")).
n.coresinteger Number of cores to use (default = self$n.cores)
verboselogical Print messages or not (default = self$verbose)
argslist A list with additional arguments for either DoubletDetection or scrublet. Please check the respective manuals.
exportboolean Export CMs in order to detect doublets outside R (default = FALSE)
data.pathcharacter Path to write data, only relevant if export = TRUE. Last character must be / (default = self$data.path)
data.frame
\dontrun{
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Detect doublets
crm$detectDoublets(method = "scrublet",
conda.path = "/opt/software/miniconda/4.12.0/condabin/conda")
}
doPreprocessing()Perform conos preprocessing.
CRMetrics$doPreprocessing(
cms = self$cms,
preprocess = c("pagoda2", "seurat"),
min.transcripts.per.cell = 100,
verbose = self$verbose,
n.cores = self$n.cores,
get.largevis = FALSE,
tsne = FALSE,
make.geneknn = FALSE,
cluster = FALSE,
...
)cmslist List containing the count matrices (default = self$cms).
preprocesscharacter Method to use for preprocessing (default = c("pagoda2","seurat")).
min.transcripts.per.cellnumeric Minimal transcripts per cell (default = 100)
verboselogical Print messages or not (default = self$verbose).
n.coresinteger Number of cores for the calculations (default = self$n.cores).
get.largevislogical For Pagoda2, create largeVis embedding (default = FALSE)
tsnelogical Create tSNE embedding (default = FALSE)
make.geneknnlogical For Pagoda2, estimate gene kNN (default = FALSE)
clusterlogical For Seurat, estimate clusters (default = FALSE)
...Additional arguments for Pagaoda2::basicP2Proc or conos:::basicSeuratProc
Conos object
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Perform preprocessing
crm$doPreprocessing(preprocess = "pagoda2")
} else {
message("Package 'pagoda2' not available.")
}
}
createEmbedding()Create Conos embedding.
CRMetrics$createEmbedding( cms = self$cms.preprocessed, verbose = self$verbose, n.cores = self$n.cores, arg.buildGraph = list(), arg.findCommunities = list(), arg.embedGraph = list(method = "UMAP") )
cmslist List containing the preprocessed count matrices (default = self$cms.preprocessed).
verboselogical Print messages or not (default = self$verbose).
n.coresinteger Number of cores for the calculations (default = self$n.cores).
arg.buildGraphlist A list with additional arguments for the buildGraph function in Conos (default = list())
arg.findCommunitieslist A list with additional arguments for the findCommunities function in Conos (default = list())
arg.embedGraphlist A list with additional arguments for the embedGraph function in Conos (default = list(method = "UMAP))
Conos object
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
filterCms()Filter cells based on depth, mitochondrial fraction and doublets from the count matrix.
CRMetrics$filterCms(
depth.cutoff = NULL,
mito.cutoff = NULL,
doublets = NULL,
species = c("human", "mouse"),
samples.to.exclude = NULL,
verbose = self$verbose,
sep = "!!",
raw = FALSE
)depth.cutoffnumeric Depth (transcripts per cell) cutoff (default = NULL).
mito.cutoffnumeric Mitochondrial fraction cutoff (default = NULL).
doubletscharacter Doublet detection method to use (default = NULL).
speciescharacter Species to calculate the mitochondrial fraction for (default = "human").
samples.to.excludecharacter Sample names to exclude (default = NULL)
verboselogical Show progress (default = self$verbose)
sepcharacter Separator for creating unique cell names (default = "!!")
rawboolean Filter on raw, unfiltered count matrices. Usually not intended (default = FALSE)
list of filtered count matrices
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Filter CMs
crm$filterCms(depth.cutoff = 1e3, mito.cutoff = 0.05)
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
selectMetrics()Select metrics from summary.metrics
CRMetrics$selectMetrics(ids = NULL)
idscharacter Metric id to select (default = NULL).
vector
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Select metrics
crm$selectMetrics()
selection.metrics <- crm$selectMetrics(c(1:4))
plotFilteredCells()Plot filtered cells in an embedding, in a bar plot, on a tile or export the data frame
CRMetrics$plotFilteredCells(
type = c("embedding", "bar", "tile", "export"),
depth = TRUE,
depth.cutoff = 1000,
doublet.method = NULL,
mito.frac = TRUE,
mito.cutoff = 0.05,
species = c("human", "mouse"),
size = 0.3,
sep = "!!",
cols = c("grey80", "red", "blue", "green", "yellow", "black", "pink", "purple"),
...
)typecharacter The type of plot to use: embedding, bar, tile or export (default = c("embedding","bar","tile","export")).
depthlogical Plot the depth or not (default = TRUE).
depth.cutoffnumeric Depth cutoff, either a single number or a vector with cutoff per sample and with sampleIDs as names (default = 1e3).
doublet.methodcharacter Method to detect doublets (default = NULL).
mito.fraclogical Plot the mitochondrial fraction or not (default = TRUE).
mito.cutoffnumeric Mitochondrial fraction cutoff, either a single number or a vector with cutoff per sample and with sampleIDs as names (default = 0.05).
speciescharacter Species to calculate the mitochondrial fraction for (default = c("human","mouse")).
sizenumeric Dot size (default = 0.3)
sepcharacter Separator for creating unique cell names (default = "!!")
colscharacter Colors used for plotting (default = c("grey80","red","blue","green","yellow","black","pink","purple"))
...Plotting parameters passed to sccore::embeddingPlot.
ggplot2 object or data frame
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Plot and extract result
crm$plotFilteredCells(type = "embedding")
filtered.cells <- crm$plotFilteredCells(type = "export")
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
getDepth()Extract sequencing depth from Conos object.
CRMetrics$getDepth(cms = self$cms)
cmslist List of (sparse) count matrices (default = self$cms)
data frame
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Get depth
crm$getDepth()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
getMitoFraction()Calculate the fraction of mitochondrial genes.
CRMetrics$getMitoFraction(species = c("human", "mouse"), cms = self$cms)speciescharacter Species to calculate the mitochondrial fraction for (default = "human").
cmslist List of (sparse) count matrices (default = self$cms)
data frame
\donttest{
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Get mito. fraction
crm$getMitoFraction(species = c("human", "mouse"))
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
}
prepareCellbender()Create plots and script call for CellBender
CRMetrics$prepareCellbender( shrinkage = 100, show.expected.cells = TRUE, show.total.droplets = TRUE, expected.cells = NULL, total.droplets = NULL, cms.raw = self$cms.raw, umi.counts = self$cellbender$umi.counts, data.path = self$data.path, samples = self$metadata$sample, verbose = self$verbose, n.cores = self$n.cores, unique.names = FALSE, sep = "!!" )
shrinkageinteger Select every nth UMI count per cell for plotting. Improves plotting speed drastically. To plot all cells, set to 1 (default = 100)
show.expected.cellslogical Plot line depicting expected number of cells (default = TRUE)
show.total.dropletslogical Plot line depicting total droplets included for CellBender run (default = TRUE)
expected.cellsnamed numeric If NULL, expected cells will be deduced from the number of cells per sample identified by Cell Ranger. Otherwise, a named vector of expected cells with sample IDs as names. Sample IDs must match those in summary.metrics (default: stored named vector)
total.dropletsnamed numeric If NULL, total droplets included will be deduced from expected cells multiplied by 3. Otherwise, a named vector of total droplets included with sample IDs as names. Sample IDs must match those in summary.metrics (default: stored named vector)
cms.rawlist Raw count matrices from HDF5 Cell Ranger outputs (default = self$cms.raw)
umi.countslist UMI counts calculated as column sums of raw count matrices from HDF5 Cell Ranger outputs (default: stored list)
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
verboselogical Show progress (default: stored vector)
n.coresinteger Number of cores (default: stored vector)
unique.nameslogical Create unique cell names (default = FALSE)
sepcharacter Separator for creating unique cell names (default = "!!")
ggplot2 object and bash script
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data")
crm$prepareCellbender()
}
saveCellbenderScript()CRMetrics$saveCellbenderScript( file = "cellbender_script.sh", fpr = 0.01, epochs = 150, use.gpu = TRUE, expected.cells = NULL, total.droplets = NULL, data.path = self$data.path, samples = self$metadata$sample, args = NULL )
filecharacter File name for CellBender script. Will be stored in data.path (default: "cellbender_script.sh")
fprnumeric False positive rate for CellBender (default = 0.01)
epochsinteger Number of epochs for CellBender (default = 150)
use.gpulogical Use CUDA capable GPU (default = TRUE)
expected.cellsnamed numeric If NULL, expected cells will be deduced from the number of cells per sample identified by Cell Ranger. Otherwise, a named vector of expected cells with sample IDs as names. Sample IDs must match those in summary.metrics (default: stored named vector)
total.dropletsnamed numeric If NULL, total droplets included will be deduced from expected cells multiplied by 3. Otherwise, a named vector of total droplets included with sample IDs as names. Sample IDs must match those in summary.metrics (default: stored named vector)
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
argscharacter (optional) Additional parameters for CellBender
bash script
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
}
getExpectedCells()Extract the expected number of cells per sample based on the Cell Ranger summary metrics
CRMetrics$getExpectedCells(samples = self$metadata$sample)
samplescharacter Sample names to include (default = self$metadata$sample)
A numeric vector
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Get summary
crm$addSummaryFromCms()
# Get no. cells
crm$getExpectedCells()
getTotalDroplets()Get the total number of droplets included in the CellBender estimations. Based on the Cell Ranger summary metrics and multiplied by a preset multiplier.
CRMetrics$getTotalDroplets(samples = self$metadata$sample, multiplier = 3)
samplescharacter Samples names to include (default = self$metadata$sample)
multipliernumeric Number to multiply expected number of cells with (default = 3)
A numeric vector
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add summary
crm$addSummaryFromCms()
# Get no. droplets
crm$getTotalDroplets()
addCms()Add a list of count matrices to the CRMetrics object.
CRMetrics$addCms( cms = NULL, data.path = self$data.path, samples = self$metadata$sample, cellbender = FALSE, raw = FALSE, symbol = TRUE, unique.names = TRUE, sep = "!!", add.metadata = TRUE, n.cores = self$n.cores, verbose = self$verbose )
cmslist List of (sparse) count matrices (default = NULL)
data.pathcharacter Path to cellranger count data (default = self$data.path).
samplescharacter Vector of sample names. If NULL, samples are extracted from cms (default = self$metadata$sample)
cellbenderlogical Add CellBender filtered count matrices in HDF5 format. Requires that "cellbender" is in the names of the files (default = FALSE)
rawlogical Add raw count matrices from Cell Ranger output. Cannot be combined with cellbender=TRUE (default = FALSE)
symbolcharacter The type of gene IDs to use, SYMBOL (TRUE) or ENSEMBLE (default = TRUE)
unique.nameslogical Make cell names unique based on sep parameter (default = TRUE)
sepcharacter Separator used to create unique cell names (default = "!!")
add.metadataboolean Add metadata from cms or not (default = TRUE)
n.coresinteger Number of cores to use (default = self$n.cores)
verboseboolean Print progress (default = self$verbose)
Add list of (sparse) count matrices to R6 class object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
crm$addCms(cms = testdata.cms)
}
plotCbTraining()Plot the results from the CellBender estimations
CRMetrics$plotCbTraining( data.path = self$data.path, samples = self$metadata$sample, pal = self$pal )
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
palcharacter Plotting palette (default = self$pal)
A ggplot2 object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbTraining()
}
plotCbCellProbs()Plot the CellBender assigned cell probabilities
CRMetrics$plotCbCellProbs( data.path = self$data.path, samples = self$metadata$sample, low.col = "gray", high.col = "red" )
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
low.colcharacter Color for low probabilities (default = "gray")
high.colcharacter Color for high probabilities (default = "red")
A ggplot2 object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run the CellBender script
crm$plotCbCellProbs()
}
plotCbAmbExp()Plot the estimated ambient gene expression per sample from CellBender calculations
CRMetrics$plotCbAmbExp( cutoff = 0.005, data.path = self$data.path, samples = self$metadata$sample )
cutoffnumeric Horizontal line included in the plot to indicate highly expressed ambient genes (default = 0.005)
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
A ggplot2 object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbAmbExp()
}
plotCbAmbGenes()Plot the most abundant estimated ambient genes from the CellBender calculations
CRMetrics$plotCbAmbGenes( cutoff = 0.005, data.path = self$data.path, samples = self$metadata$sample, pal = self$pal )
cutoffnumeric Cutoff of ambient gene expression to use to extract ambient genes per sample
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
palcharacter Plotting palette (default = self$pal)
A ggplot2 object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbAmbGenes()
}
addSummaryFromCms()Add summary metrics from a list of count matrices
CRMetrics$addSummaryFromCms( cms = self$cms, n.cores = self$n.cores, verbose = self$verbose )
cmslist A list of filtered count matrices (default = self$cms)
n.coresinteger Number of cores to use (default = self$n.cores)
verboselogical Show progress (default = self$verbose)
data.frame
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add summary
crm$addSummaryFromCms()
runSoupX()Run SoupX ambient RNA estimation and correction
CRMetrics$runSoupX( data.path = self$data.path, samples = self$metadata$sample, n.cores = self$n.cores, verbose = self$verbose, arg.load10X = list(), arg.autoEstCont = list(), arg.adjustCounts = list() )
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
n.coresnumeric Number of cores (default = self$n.cores)
verboselogical Show progress (default = self$verbose)
arg.load10Xlist A list with additional parameters for SoupX::load10X (default = list())
arg.autoEstContlist A list with additional parameters for SoupX::autoEstCont (default = list())
arg.adjustCountslist A list with additional parameters for SoupX::adjustCounts (default = list())
List containing a list with corrected counts, and a data.frame containing plotting estimations
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$runSoupX()
}
plotSoupX()Plot the results from the SoupX estimations
CRMetrics$plotSoupX(plot.df = self$soupx$plot.df)
plot.dfdata.frame SoupX estimations (default = self$soupx$plot.df)
A ggplot2 object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$runSoupX()
crm$plotSoupX()
}
plotCbCells()Plot CellBender cell estimations against the estimated cell numbers from Cell Ranger
CRMetrics$plotCbCells( data.path = self$data.path, samples = self$metadata$sample, pal = self$pal )
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
palcharacter Plotting palette (default = self$pal)
A ggplot2 object
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbCells()
}
addDoublets()Add doublet results created from exported Python script
CRMetrics$addDoublets(
method = c("scrublet", "doubletdetection"),
data.path = self$data.path,
samples = self$metadata$sample,
cms = self$cms,
verbose = self$verbose
)methodcharacter Which method to use, either scrublet or doubletdetection (default is both).
data.pathcharacter Path to Cell Ranger outputs (default = self$data.path)
samplescharacter Sample names to include (default = self$metadata$sample)
cmslist List containing the count matrices (default = self$cms).
verboseboolean Print progress (default = self$verbose)
List of doublet results
\dontrun{
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$detectDoublets(export = TRUE)
## Run Python script
crm$addDoublets()
}
clone()The objects of this class are cloneable with this method.
CRMetrics$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `CRMetrics$new`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$addDetailedMetrics`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Run function
crm$addDetailedMetrics()
## ------------------------------------------------
## Method `CRMetrics$addComparison`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add metadata
crm$metadata <- data.frame(sex = c("male","female"))
# Add comparison group
crm$addComparison(comp.group = "sex")
## ------------------------------------------------
## Method `CRMetrics$plotSamples`
## ------------------------------------------------
samples <- c("sample1", "sample2")
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
names(testdata.cms) <- samples
# Create metadata
metadata <- data.frame(sample = samples,
sex = c("male","female"),
condition = c("a","b"))
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, metadata = metadata, n.cores = 1)
# Plot
crm$plotSamples(comp.group = "sex", second.comp.group = "condition")
## ------------------------------------------------
## Method `CRMetrics$plotSummaryMetrics`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add summary metrics
crm$addSummaryFromCms()
crm$plotSummaryMetrics(plot.geom = "point")
## ------------------------------------------------
## Method `CRMetrics$plotDetailedMetrics`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add detailed metrics
crm$addDetailedMetrics()
# Plot
crm$plotDetailedMetrics()
## ------------------------------------------------
## Method `CRMetrics$plotEmbedding`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
crm$plotEmbedding()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$plotDepth`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Plot
crm$plotDepth()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$plotMitoFraction`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Plot
crm$plotMitoFraction()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$detectDoublets`
## ------------------------------------------------
## Not run:
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Detect doublets
crm$detectDoublets(method = "scrublet",
conda.path = "/opt/software/miniconda/4.12.0/condabin/conda")
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$doPreprocessing`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Perform preprocessing
crm$doPreprocessing(preprocess = "pagoda2")
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$createEmbedding`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$filterCms`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Filter CMs
crm$filterCms(depth.cutoff = 1e3, mito.cutoff = 0.05)
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$selectMetrics`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Select metrics
crm$selectMetrics()
selection.metrics <- crm$selectMetrics(c(1:4))
## ------------------------------------------------
## Method `CRMetrics$plotFilteredCells`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Plot and extract result
crm$plotFilteredCells(type = "embedding")
filtered.cells <- crm$plotFilteredCells(type = "export")
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$getDepth`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Get depth
crm$getDepth()
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$getMitoFraction`
## ------------------------------------------------
if (requireNamespace("pagoda2", quietly = TRUE)) {
if (requireNamespace("conos", quietly = TRUE)) {
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Create embedding
crm$doPreprocessing()
crm$createEmbedding()
# Get mito. fraction
crm$getMitoFraction(species = c("human", "mouse"))
} else {
message("Package 'conos' not available.")
}
} else {
message("Package 'pagoda2' not available.")
}
## ------------------------------------------------
## Method `CRMetrics$prepareCellbender`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data")
crm$prepareCellbender()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$saveCellbenderScript`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$getExpectedCells`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Get summary
crm$addSummaryFromCms()
# Get no. cells
crm$getExpectedCells()
## ------------------------------------------------
## Method `CRMetrics$getTotalDroplets`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add summary
crm$addSummaryFromCms()
# Get no. droplets
crm$getTotalDroplets()
## ------------------------------------------------
## Method `CRMetrics$addCms`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
crm$addCms(cms = testdata.cms)
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$plotCbTraining`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbTraining()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$plotCbCellProbs`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run the CellBender script
crm$plotCbCellProbs()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$plotCbAmbExp`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbAmbExp()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$plotCbAmbGenes`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbAmbGenes()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$addSummaryFromCms`
## ------------------------------------------------
# Simulate data
testdata.cms <- lapply(seq_len(2), \(x) {
out <- Matrix::rsparsematrix(2e3, 1e3, 0.1)
out[out < 0] <- 1
dimnames(out) <- list(sapply(seq_len(2e3), \(x) paste0("gene",x)),
sapply(seq_len(1e3), \(x) paste0("cell",x)))
return(out)
})
# Initialize
crm <- CRMetrics$new(cms = testdata.cms, samples = c("sample1", "sample2"), n.cores = 1)
# Add summary
crm$addSummaryFromCms()
## ------------------------------------------------
## Method `CRMetrics$runSoupX`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$runSoupX()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$plotSoupX`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$runSoupX()
crm$plotSoupX()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$plotCbCells`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$prepareCellbender()
crm$saveCellbenderScript()
## Run CellBender script
crm$plotCbCells()
## End(Not run)
## ------------------------------------------------
## Method `CRMetrics$addDoublets`
## ------------------------------------------------
## Not run:
crm <- CRMetrics$new(data.path = "/path/to/count/data/")
crm$detectDoublets(export = TRUE)
## Run Python script
crm$addDoublets()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.