| Title: | Fast CNV Detection for Single-Cell and Spatial Transcriptomics |
|---|---|
| Description: | Fast and accurate detection of Copy Number Variations (CNVs) in single-cell RNA sequencing (scRNA-seq) and Spatial Transcriptomics (ST) data, including 10X Visium and Visium HD. Provides sliding window-based CNV inference, hierarchical clustering of CNV profiles, and publication-ready visualization. Compatible with Seurat 4.x/5.x. |
| Authors: | Zaoqu Liu [cre, aut], Gadea Cabrejas [aut, cph], Clarice Groeneveld [aut] |
| Maintainer: | Zaoqu Liu <[email protected]> |
| License: | GPL-3 |
| Version: | 2.0.0 |
| Built: | 2026-05-23 08:38:08 UTC |
| Source: | https://github.com/Zaoqu-Liu/fastCNV |
This function annotates a phylogenetic tree with copy number variation (CNV) events. It identifies significant CNV events in the provided matrix, links them to clones and ancestral nodes, and updates the tree with this information.
annotateCNVTree(tree, cnv_mat, cnv_thresh = 0.15)annotateCNVTree(tree, cnv_mat, cnv_thresh = 0.15)
tree |
A phylogenetic tree (of class |
cnv_mat |
A matrix of copy number variation (CNV) values, with samples as rows and regions as columns. |
cnv_thresh |
A numeric threshold to filter significant CNV events. Default is 0.15. |
A data frame with the tree data, including annotations for CNV events.
cnv_matrix <- structure(c(0.2, 0.4, 0, 0, 0.1, 0, 0.1, 0.2, 0.2), dim = c( 3L, 3L ), dimnames = list(c("Clone 1", "Clone 2", "Clone 3"), c( "Region 1", "Region 2", "Region 3" ))) tree <- buildCNVTree(cnv_matrix) tree_data <- annotateCNVTree(tree, cnv_matrix)cnv_matrix <- structure(c(0.2, 0.4, 0, 0, 0.1, 0, 0.1, 0.2, 0.2), dim = c( 3L, 3L ), dimnames = list(c("Clone 1", "Clone 2", "Clone 3"), c( "Region 1", "Region 2", "Region 3" ))) tree <- buildCNVTree(cnv_matrix) tree_data <- annotateCNVTree(tree, cnv_matrix)
This function projects annotations from a high-resolution (8µm) spatial assay onto a lower-resolution (16µm) spatial assay by finding the nearest 8µm spot to each 16µm spot based on spatial coordinates.
annotations8umTo16um(HDobj, referenceVar)annotations8umTo16um(HDobj, referenceVar)
HDobj |
A |
referenceVar |
A character string specifying the name of the metadata column in the 8µm assay to project (e.g., a clustering or annotation label). |
The function uses FNN::get.knnx() to find the nearest 8µm spot for each 16µm spot based on tissue coordinates.
It assigns the annotation from the closest 8µm spot to each 16µm spot. The new annotation column is added to the metadata of HDobj.
A modified Seurat object with a new metadata column named projected_<referenceVar> containing the projected annotation on 16µm spots.
This function constructs a phylogenetic tree based on a given copy number variation (CNV) matrix. It adds a baseline "Normal" profile only to root the tree, which is not shown in final output. First, it computes pairwise distances between profiles using Euclidean distance, and then applies a specified tree-building function (e.g., Neighbor-Joining) to construct the tree.
buildCNVTree(cnv_matrix, tree_function = nj, dist_method = "euclidean")buildCNVTree(cnv_matrix, tree_function = nj, dist_method = "euclidean")
cnv_matrix |
A matrix representing copy number variation, where rows correspond to samples and columns correspond to genomic regions. Each value represents the CNV at a given region in a sample. |
tree_function |
A function to construct the phylogenetic tree from a distance matrix. The default is
|
dist_method |
The distance method to be used. |
A rooted phylogenetic tree (of class phylo)
# Example usage with Neighbor-Joining (default)# Example usage with Neighbor-Joining (default)
This function performs CNV analysis by calculating genomic scores, applying optional denoising, and optionally scaling the results based on a reference population. It processes single-cell or spatial transcriptomics data, generating an additional assay with genomic scores and adding a new metadata column for CNV fractions.
CNVAnalysis( object, referenceVar = NULL, referenceLabel = NULL, pooledReference = TRUE, scaleOnReferenceLabel = TRUE, assay = NULL, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL )CNVAnalysis( object, referenceVar = NULL, referenceLabel = NULL, pooledReference = TRUE, scaleOnReferenceLabel = TRUE, assay = NULL, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL )
object |
A Seurat object or a list of Seurat objects containing the data for CNV analysis. Each object can be either single-cell or spatial transcriptomics data. |
referenceVar |
The name of the metadata column in the Seurat object that contains reference annotations. |
referenceLabel |
The label within |
pooledReference |
Logical. If |
scaleOnReferenceLabel |
Logical. If |
assay |
Name of the assay to run the CNV analysis on. Defaults to the results of |
thresholdPercentile |
Numeric. Specifies the quantile range to consider (e.g., |
geneMetadata |
A dataframe containing gene metadata, typically from Ensembl. |
windowSize |
Integer. Defines the size of genomic windows for CNV analysis. |
windowStep |
Integer. Specifies the step size between genomic windows. |
saveGenomicWindows |
Logical. If |
topNGenes |
Integer. The number of top-expressed genes to retain in the analysis. |
chrArmsToForce |
A chromosome arm (e.g., |
genesToForce |
A list of genes to force into the analysis (e.g. |
regionToForce |
Chromosome region to force into the analysis (vector containing chr, start, end). |
If given a single Seurat object, returns the same object with:
An additional assay containing genomic scores per genomic window.
A new CNV fraction column added to the object’s metadata. If given a list of Seurat objects, returns the modified list.
CNVCalling Performs Copy Number Variation (CNV) analysis on a Seurat object.
CNVCalling( seuratObj, assay = NULL, referenceVar = NULL, referenceLabel = NULL, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL )CNVCalling( seuratObj, assay = NULL, referenceVar = NULL, referenceLabel = NULL, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL )
seuratObj |
A Seurat object containing the data for CNV analysis. Can be either single-cell or spatial transcriptomics data. |
assay |
Name of the assay to run the CNV analysis on. Defaults to the results of |
referenceVar |
The name of the metadata column in the Seurat object that contains reference annotations. |
referenceLabel |
The label within |
scaleOnReferenceLabel |
Logical. If |
thresholdPercentile |
Numeric. Specifies the quantile range to consider (e.g., |
geneMetadata |
A dataframe containing gene metadata, typically from Ensembl. |
windowSize |
Integer. Defines the size of genomic windows for CNV analysis. |
windowStep |
Integer. Specifies the step size between genomic windows. |
saveGenomicWindows |
Logical. If |
topNGenes |
Integer. The number of top-expressed genes to retain in the analysis. |
chrArmsToForce |
A chromosome arm (e.g., |
genesToForce |
A list of genes to force into the analysis (e.g. |
regionToForce |
Chromosome region to force into the analysis (vector containing chr, start, end). |
The same Seurat object provided in seuratObj, with:
An additional assay containing genomic scores per genomic window.
A new CNV fraction column added to the object’s metadata.
CNVCalling for a List of Seurat Objects Performs Copy Number Variation (CNV) analysis on a list of Seurat objects.
CNVCallingList( seuratList, assay = NULL, referenceVar = NULL, referenceLabel = NULL, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL )CNVCallingList( seuratList, assay = NULL, referenceVar = NULL, referenceLabel = NULL, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL )
seuratList |
A list of Seurat objects containing the data for CNV analysis. Each object can be either single-cell or spatial transcriptomics data. |
assay |
Name of the assay to run the CNV analysis on. Defaults to the results of |
referenceVar |
The name of the metadata column in the Seurat object that contains reference annotations. |
referenceLabel |
The label within |
scaleOnReferenceLabel |
Logical. If |
thresholdPercentile |
Numeric. Specifies the quantile range to consider (e.g., |
geneMetadata |
A dataframe containing gene metadata, typically from Ensembl. |
windowSize |
Integer. Defines the size of genomic windows for CNV analysis. |
windowStep |
Integer. Specifies the step size between genomic windows. |
saveGenomicWindows |
Logical. If |
topNGenes |
Integer. The number of top-expressed genes to retain in the analysis. |
chrArmsToForce |
A chromosome arm (e.g., |
genesToForce |
A list of genes to force into the analysis (e.g. |
regionToForce |
Chromosome region to force into the analysis (vector containing chr, start, end). |
A list of Seurat objects, where each:
Contains an additional assay with genomic scores per genomic window.
Has a new CNV fraction column added to its metadata.
CNV Classification Classifies the CNV results into loss, gain, or no alteration for each observation and chromosome arm.
CNVClassification(seuratObj, peaks = c(-0.1, 0, 0.1))CNVClassification(seuratObj, peaks = c(-0.1, 0, 0.1))
seuratObj |
A Seurat object containing the results of the CNV analysis (e.g., from |
peaks |
A numeric vector containing the thresholds for classifying CNVs. The default is
|
The same Seurat object with an additional classification for each observation and chromosome arm in the metadata.
The classification can be one of "loss", "gain", or "no_alteration".
The CNVcluster function performs hierarchical clustering on a genomic score matrix extracted from a Seurat object.
It provides options for plotting a dendrogram, an elbow plot for optimal cluster determination,
and cluster visualization on the dendrogram. The resulting cluster assignments are stored in the Seurat object.
CNVCluster( seuratObj, referenceVar = NULL, tumorLabel = NULL, k = NULL, h = NULL, plotDendrogram = FALSE, plotClustersOnDendrogram = FALSE, plotElbowPlot = FALSE )CNVCluster( seuratObj, referenceVar = NULL, tumorLabel = NULL, k = NULL, h = NULL, plotDendrogram = FALSE, plotClustersOnDendrogram = FALSE, plotElbowPlot = FALSE )
seuratObj |
A Seurat object containing a "genomicScores" assay with a matrix of genomic scores for clustering. |
referenceVar |
The name of the metadata column in the Seurat object containing reference annotations. |
tumorLabel |
The label within |
k |
Optional. The number of clusters to cut the dendrogram into. If |
h |
Optional. The height at which to cut the dendrogram for clustering. If both |
plotDendrogram |
Logical. If |
plotClustersOnDendrogram |
Logical. If |
plotElbowPlot |
Logical. If |
The function computes a Manhattan distance matrix and performs hierarchical clustering using the Ward.D2 method.
If k is not provided, the elbow method is applied to determine the optimal number of clusters based on the within-cluster sum of squares (WSS).
The clusters are assigned to the Seurat object under the metadata column cnv_clusters.
A Seurat object with an additional metadata column, cnv_clusters, containing the cluster assignments.
CNV Per Chromosome Arm Computes the CNV fraction of each spot/cell per chromosome arm, then stores the results into the metadata.
CNVPerChromosomeArm(seuratObj)CNVPerChromosomeArm(seuratObj)
seuratObj |
A Seurat object, typically the output from the |
The function returns the same Seurat object with the CNV fraction for each chromosome arm added to the metadata.
fastCNV()
Build, annotate and plot a Phylogenetic Tree from a seurat Object containing the CNV results from fastCNV()
CNVTree( seuratObj, healthyClusters = NULL, values = "scores", cnv_thresh = 0.15, tree_function = nj, dist_method = "euclidean", clone_cols = TRUE )CNVTree( seuratObj, healthyClusters = NULL, values = "scores", cnv_thresh = 0.15, tree_function = nj, dist_method = "euclidean", clone_cols = TRUE )
seuratObj |
A Seurat object containing CNV data and metadata. |
healthyClusters |
A numeric vector or |
values |
one of 'scores' or 'calls'. 'scores' returns the mean CNV score per cluster,
while 'calls' uses |
cnv_thresh |
A numeric threshold to filter significant CNV events. Default is 0.15. |
tree_function |
A function to construct the phylogenetic tree from a distance matrix. The default is
|
dist_method |
The distance method to be used. |
clone_cols |
a color palette to color the clones. If NULL, points are
not colored. If TRUE, clones are colored using default color palette. If a
palette is given, clones are colored following the palette, with
values passed to |
This function calculates the average gene expression for each patient across different cell types. It first retrieves patient data from LN, then extracts the corresponding count data from LrawcountsByPatient, and calculates the mean expression.
computeAverageExpression(LN, LrawcountsByPatient)computeAverageExpression(LN, LrawcountsByPatient)
LN |
A list where each element represents a cell type with sublists containing patient data. |
LrawcountsByPatient |
A named list where each element contains count data for a specific patient. |
A named vector containing the average expression for each patient.
This function orchestrates the CNV analysis on a Seurat object (or multiple objects). It calls internal functions such as
prepareCountsForCNVAnalysis, CNVAnalysis, CNVPerChromosomeArm, CNVCluster, and plotCNVResults to compute the CNVs,
perform clustering, and generate heatmaps. The results are saved in the metadata of the Seurat object(s), with options for
generating and saving plots.
fastCNV( seuratObj, sampleName, referenceVar = NULL, referenceLabel = NULL, assay = NULL, prepareCounts = TRUE, aggregFactor = 15000, seuratClusterResolution = 0.8, aggregateByVar = TRUE, reClusterSeurat = FALSE, pooledReference = TRUE, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL, getCNVPerChromosomeArm = TRUE, getCNVClusters = TRUE, tumorLabel = NULL, k_clusters = NULL, h_clusters = NULL, plotDendrogram = FALSE, plotClustersOnDendrogram = FALSE, plotElbowPlot = FALSE, mergeCNV = TRUE, mergeThreshold = 0.98, doPlot = TRUE, denoise = TRUE, printPlot = FALSE, savePath = ".", outputType = "png", clustersVar = "cnv_clusters", splitPlotOnVar = clustersVar, referencePalette = "default", clusters_palette = "default" )fastCNV( seuratObj, sampleName, referenceVar = NULL, referenceLabel = NULL, assay = NULL, prepareCounts = TRUE, aggregFactor = 15000, seuratClusterResolution = 0.8, aggregateByVar = TRUE, reClusterSeurat = FALSE, pooledReference = TRUE, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL, getCNVPerChromosomeArm = TRUE, getCNVClusters = TRUE, tumorLabel = NULL, k_clusters = NULL, h_clusters = NULL, plotDendrogram = FALSE, plotClustersOnDendrogram = FALSE, plotElbowPlot = FALSE, mergeCNV = TRUE, mergeThreshold = 0.98, doPlot = TRUE, denoise = TRUE, printPlot = FALSE, savePath = ".", outputType = "png", clustersVar = "cnv_clusters", splitPlotOnVar = clustersVar, referencePalette = "default", clusters_palette = "default" )
seuratObj |
Seurat object or list of Seurat objects to perform the CNV analysis on. |
sampleName |
Name of the sample or a list of names corresponding to the samples in the |
referenceVar |
The variable name of the annotations in the Seurat metadata to be used as reference. |
referenceLabel |
The label given to the observations you want as reference (can be any type of annotation). |
assay |
Name of the assay to run the CNV on. Takes the results of |
prepareCounts |
If |
aggregFactor |
The number of counts per spot desired (default = 15 000). If less than 1,000, will not run the |
seuratClusterResolution |
The resolution wanted for the Seurat clusters (default = 0.8). |
aggregateByVar |
If |
reClusterSeurat |
Whether to re-cluster if the Seurat object given already has a |
pooledReference |
Default is |
scaleOnReferenceLabel |
If |
thresholdPercentile |
Which quantiles to take (default 0.01). For example, |
geneMetadata |
List of genes and their metadata (default uses genes from Ensembl version 113). |
windowSize |
Size of the genomic windows for CNV analysis (default = 150). |
windowStep |
Step between the genomic windows (default = 10). |
saveGenomicWindows |
If |
topNGenes |
Number of top expressed genes to keep (default = 7000). |
chrArmsToForce |
A chromosome arm (e.g., |
genesToForce |
A list of genes to force into the analysis (e.g. |
regionToForce |
Chromosome region to force into the analysis (vector containing chr, start, end). |
getCNVPerChromosomeArm |
If |
getCNVClusters |
If |
tumorLabel |
The label within |
k_clusters |
Optional. Number of clusters to cut the dendrogram into. If |
h_clusters |
Optional. The height at which to cut the dendrogram for clustering. If both |
plotDendrogram |
Logical. Whether to plot the dendrogram (default = |
plotClustersOnDendrogram |
Logical. Whether to highlight clusters on the dendrogram (default = |
plotElbowPlot |
Logical. Whether to plot the elbow plot used for determining the optimal number of clusters (default = |
mergeCNV |
Logical. Whether to merge the highly correlated CNV clusters. |
mergeThreshold |
A numeric value between 0 and 1. Clusters with correlation greater than this threshold will be merged. Default is 0.98. |
doPlot |
If |
denoise |
If |
printPlot |
If |
savePath |
Path to save the heatmap plot. If |
outputType |
Specifies the file format for saving the plot, either |
clustersVar |
The variable name of the clusters in the Seurat metadata (default = |
splitPlotOnVar |
The name of the metadata column to split the observations during the |
referencePalette |
The color palette that should be used for |
clusters_palette |
The color palette that should be used for |
A list of Seurat objects after all the analysis is complete. Heatmaps of the CNVs for every object in seuratObj are generated and saved in the specified path (default = current working directory).
This function orchestrates the CNV analysis on a Seurat Visium HD object (or multiple objects). It calls internal functions such as
CNVAnalysis and PlotCNVResults to compute the CNVs and generate heatmaps. The results are saved in the metadata of the Seurat object(s), with options for
generating and saving plots.
fastCNV_10XHD( seuratObjHD, sampleName, referenceVar = NULL, referenceLabel = NULL, assay = "Spatial.016um", pooledReference = TRUE, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL, getCNVPerChromosomeArm = TRUE, getCNVClusters = FALSE, tumorLabel = NULL, k_clusters = NULL, h_clusters = NULL, plotDendrogram = FALSE, plotClustersOnDendrogram = FALSE, plotElbowPlot = FALSE, mergeCNV = TRUE, mergeThreshold = 0.98, doPlot = TRUE, denoise = TRUE, printPlot = FALSE, savePath = ".", outputType = "png", clustersVar = "cnv_clusters", clusters_palette = "default", splitPlotOnVar = clustersVar, referencePalette = "default" )fastCNV_10XHD( seuratObjHD, sampleName, referenceVar = NULL, referenceLabel = NULL, assay = "Spatial.016um", pooledReference = TRUE, scaleOnReferenceLabel = TRUE, thresholdPercentile = 0.01, geneMetadata = getGenes(), windowSize = 150, windowStep = 10, saveGenomicWindows = FALSE, topNGenes = 7000, chrArmsToForce = NULL, genesToForce = NULL, regionToForce = NULL, getCNVPerChromosomeArm = TRUE, getCNVClusters = FALSE, tumorLabel = NULL, k_clusters = NULL, h_clusters = NULL, plotDendrogram = FALSE, plotClustersOnDendrogram = FALSE, plotElbowPlot = FALSE, mergeCNV = TRUE, mergeThreshold = 0.98, doPlot = TRUE, denoise = TRUE, printPlot = FALSE, savePath = ".", outputType = "png", clustersVar = "cnv_clusters", clusters_palette = "default", splitPlotOnVar = clustersVar, referencePalette = "default" )
seuratObjHD |
Seurat object or list of Seurat objects to perform the CNV analysis on. |
sampleName |
Name of the sample or a list of names corresponding to the samples in the |
referenceVar |
The variable name of the annotations in the Seurat metadata to be used as reference. |
referenceLabel |
The label given to the observations you want as reference (can be any type of annotation). |
assay |
Name of the assay to run the CNV on. Takes the results of |
pooledReference |
Default is |
scaleOnReferenceLabel |
If |
thresholdPercentile |
Which quantiles to take (default 0.01). For example, |
geneMetadata |
List of genes and their metadata (default uses genes from Ensembl version 113). |
windowSize |
Size of the genomic windows for CNV analysis (default = 150). |
windowStep |
Step between the genomic windows (default = 10). |
saveGenomicWindows |
If |
topNGenes |
Number of top expressed genes to keep (default = 7000). |
chrArmsToForce |
A chromosome arm (e.g., |
genesToForce |
A list of genes to force into the analysis (e.g. |
regionToForce |
Chromosome region to force into the analysis (vector containing chr, start, end). |
getCNVPerChromosomeArm |
If |
getCNVClusters |
If |
tumorLabel |
The label within |
k_clusters |
Optional. Number of clusters to cut the dendrogram into. If |
h_clusters |
Optional. The height at which to cut the dendrogram for clustering. If both |
plotDendrogram |
Logical. Whether to plot the dendrogram (default = |
plotClustersOnDendrogram |
Logical. Whether to highlight clusters on the dendrogram (default = |
plotElbowPlot |
Logical. Whether to plot the elbow plot used for determining the optimal number of clusters (default = |
mergeCNV |
Logical. Whether to merge the highly correlated CNV clusters. |
mergeThreshold |
A numeric value between 0 and 1. Clusters with correlation greater than this threshold will be merged. Default is 0.98. |
doPlot |
If |
denoise |
If |
printPlot |
If |
savePath |
Path to save the heatmap plot. If |
outputType |
Specifies the file format for saving the plot, either |
clustersVar |
The name of the metadata column containing cluster information (default = |
clusters_palette |
A color palette for |
splitPlotOnVar |
The name of the metadata column to split the observations during the |
referencePalette |
A color palette for |
A Seurat object or a list of Seurat objects after all the analysis is complete. Heatmaps of the CNVs for every object in seuratObj are generated and saved in the specified path (default = current working directory).
Data downloaded from the Ensembl website (version 113), containing detailed gene information for approximately 76,000 genes. The dataset includes Ensembl gene IDs, HUGO nomenclature (HGNC symbol), Entrez gene IDs, chromosome locations, gene biotype, and gene length for each gene.
data(geneMetadata)data(geneMetadata)
An object of class list, containing gene information as described above.
Ensembl Genome Browser, Version 113: https://www.ensembl.org/index.html
data(geneMetadata) hgnc <- geneMetadata$hgnc_symbol entrez <- geneMetadata$entrezgene_iddata(geneMetadata) hgnc <- geneMetadata$hgnc_symbol entrez <- geneMetadata$entrezgene_id
This function generates a matrix of metacells where each metacell corresponds to a CNV cluster. The CNV matrix is calculated by chromosome arm. If specified, certain clusters will be labeled as "Benign" rather than "Clone".
generateCNVClonesMatrix( seuratObj, healthyClusters = NULL, values = "scores", cnv_thresh = 0.15 )generateCNVClonesMatrix( seuratObj, healthyClusters = NULL, values = "scores", cnv_thresh = 0.15 )
seuratObj |
A Seurat object containing CNV data and metadata. |
healthyClusters |
A numeric vector or |
values |
one of 'scores' or 'calls'. 'scores' returns the mean CNV score per cluster,
while 'calls' uses |
cnv_thresh |
A numeric threshold to filter significant CNV events. Default is 0.15. |
A matrix of CNVs with row names corresponding to the clone or benign labels and columns representing the chromosome arms, with values corresponding to CNV scores or CNV calls.
This function retrieves gene information from the Ensembl database using the specified filters. It can either fetch the latest data or use cached data if available.
getGenes(filters = NULL, cache = TRUE)getGenes(filters = NULL, cache = TRUE)
filters |
A character vector of filters to be applied in the query. These filters determine which genes and their associated information are returned from the Ensembl database. |
cache |
Logical. If |
A list containing gene information retrieved from Ensembl, with each element representing data for a specific gene (e.g., gene IDs, descriptions, associated attributes).
This function merges CNV clusters in a Seurat object based on the correlation of their average CNV profiles across chromosome arms. Clusters with correlation greater than a user-specified threshold are merged into a single cluster.
mergeCNVClusters(seuratObj, mergeThreshold = 0.98)mergeCNVClusters(seuratObj, mergeThreshold = 0.98)
seuratObj |
A Seurat object containing fastCNV's results by chromosome arm, and CNV clustering. |
mergeThreshold |
A numeric value between 0 and 1. Clusters with correlation greater than this threshold will be merged. Default is 0.98. |
A Seurat Object with updated CNV clusters, where highly correlated clusters have been merged.
Plot CNV Results into a Heatmap Builds a heatmap to visualize the CNV results based on genomic scores.
plotCNVResults( seuratObj, referenceVar = NULL, clustersVar = "cnv_clusters", splitPlotOnVar = clustersVar, denoise = TRUE, savePath = ".", printPlot = FALSE, referencePalette = "default", clusters_palette = "default", outputType = "png" )plotCNVResults( seuratObj, referenceVar = NULL, clustersVar = "cnv_clusters", splitPlotOnVar = clustersVar, denoise = TRUE, savePath = ".", printPlot = FALSE, referencePalette = "default", clusters_palette = "default", outputType = "png" )
seuratObj |
A Seurat object containing the genomic scores computed previously. |
referenceVar |
The name of the metadata column in the Seurat object containing reference annotations. |
clustersVar |
The name of the metadata column containing cluster information (default = |
splitPlotOnVar |
The name of the metadata column used to split the heatmap rows (e.g., cell type or cluster) (default = |
denoise |
If |
savePath |
The path where the heatmap will be saved. If |
printPlot |
Logical. If |
referencePalette |
A color palette for |
clusters_palette |
A color palette for |
outputType |
Character. Specifies the file format for saving the plot, either |
This function generates a heatmap and saves it as a .pdf or .png file in the specified path (default = working directory).
Plot Visium HD CNV Results into a Heatmap Builds a heatmap to visualize the Visium HD CNV results based on genomic scores.
plotCNVResultsHD( seuratObjHD, referenceVar = NULL, clustersVar = "cnv_clusters", splitPlotOnVar = clustersVar, denoise = TRUE, savePath = ".", printPlot = FALSE, referencePalette = "default", clusters_palette = "default", outputType = "png" )plotCNVResultsHD( seuratObjHD, referenceVar = NULL, clustersVar = "cnv_clusters", splitPlotOnVar = clustersVar, denoise = TRUE, savePath = ".", printPlot = FALSE, referencePalette = "default", clusters_palette = "default", outputType = "png" )
seuratObjHD |
A Seurat object containing the genomic scores computed previously. |
referenceVar |
The name of the metadata column in the Seurat object containing reference annotations. |
clustersVar |
The name of the metadata column containing cluster information (default = |
splitPlotOnVar |
The name of the metadata column used to split the heatmap rows (e.g., cell type or cluster) (default = |
denoise |
If |
savePath |
The path where the heatmap will be saved. If |
printPlot |
Logical. If |
referencePalette |
A color palette for |
clusters_palette |
A color palette for |
outputType |
Character. Specifies the file format for saving the plot, either |
This function generates a heatmap and saves it as a .pdf or .png file in the specified path (default = working directory).
This function generates a plot of an annotated phylogenetic tree using ggtree.
It displays tip labels, tip points, and labels for CNV events associated with
each node.
plotCNVTree(tree_data, clone_cols = NULL)plotCNVTree(tree_data, clone_cols = NULL)
tree_data |
A data frame containing tree structure and annotations,
typically produced by |
clone_cols |
a color palette to color the clones. If NULL, points are
not colored. If TRUE, clones are colored using default color palette. If a
palette is given, clones are colored following the palette, with
values passed to |
A ggplot object representing the annotated phylogenetic tree.
cnv_matrix <- structure(c(0.2, 0.4, 0, 0, 0.1, 0, 0.1, 0.2, 0.2), dim = c( 3L, 3L ), dimnames = list(c("Clone 1", "Clone 2", "Clone 3"), c( "Region 1", "Region 2", "Region 3" ))) tree <- buildCNVTree(cnv_matrix) tree_data <- annotateCNVTree(tree, cnv_matrix) plotCNVTree(tree_data)cnv_matrix <- structure(c(0.2, 0.4, 0, 0, 0.1, 0, 0.1, 0.2, 0.2), dim = c( 3L, 3L ), dimnames = list(c("Clone 1", "Clone 2", "Clone 3"), c( "Region 1", "Region 2", "Region 3" ))) tree <- buildCNVTree(cnv_matrix) tree_data <- annotateCNVTree(tree, cnv_matrix) plotCNVTree(tree_data)
Aggregate Observations by Cell Type for CNV Analysis Aggregates observations with the same cell types to increase counts per observation, improving Copy Number Variation (CNV) computation.
prepareCountsForCNVAnalysis( seuratObj, sampleName = NULL, referenceVar = NULL, aggregateByVar = TRUE, aggregFactor = 15000, seuratClusterResolution = 0.8, reClusterSeurat = FALSE )prepareCountsForCNVAnalysis( seuratObj, sampleName = NULL, referenceVar = NULL, aggregateByVar = TRUE, aggregFactor = 15000, seuratClusterResolution = 0.8, reClusterSeurat = FALSE )
seuratObj |
A Seurat object containing the data. |
sampleName |
A character string specifying the sample name. |
referenceVar |
The name of the metadata column in the Seurat object that contains reference annotations. |
aggregateByVar |
Logical. If |
aggregFactor |
Integer. The target number of counts per observation (default = |
seuratClusterResolution |
Numeric. The resolution used for Seurat clustering (default = |
reClusterSeurat |
Logical. If |
A Seurat object with:
A new assay called "AggregatedCounts" containing the modified count matrix.
Seurat clusters stored in the metadata.