Skip to contents

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.

Usage

fastCNV(
  seuratObj,
  sampleName,
  referenceVar = NULL,
  referenceLabel = NULL,
  assay = NULL,
  prepareCounts = "default",
  aggregFactor = 15000,
  clusterResolution = 0.8,
  aggregateByVar = TRUE,
  reCluster = 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,
  k_clusters = NULL,
  h_clusters = NULL,
  cellTypesToCluster = NULL,
  mergeCNV = TRUE,
  mergeThreshold = 0.98,
  doPlot = TRUE,
  denoise = TRUE,
  printPlot = FALSE,
  savePath = ".",
  outputType = "png",
  clustersVar = "cnv_clusters",
  splitPlotOnVar = clustersVar,
  referencePalette = "default",
  clusters_palette = "default"
)

Arguments

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 seuratObj.

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 prepareCountsForCNVAnalysis by default if available.

prepareCounts

One of TRUE, FALSE, or "default" (default). When "default", prepareCountsForCNVAnalysis is run only if the number of cells/spots is below 60,000.

aggregFactor

The number of counts per spot desired (default = 15 000). If less than 1,000, will not run the prepareCountsForCNVAnalysis function.

clusterResolution

The resolution wanted for the Seurat clusters (default = 0.8).

aggregateByVar

If referenceVar is given, determines whether to use it to pool the observations (default = TRUE).

reCluster

Whether to re-cluster if the Seurat object given already has a seurat_clusters slot in its metadata (default = FALSE).

pooledReference

Default is TRUE. Will build a pooled reference across all samples if TRUE.

scaleOnReferenceLabel

If TRUE, scales the results depending on the normal observations (default = TRUE).

thresholdPercentile

Which quantiles to take (default 0.01). For example, 0.01 will take quantiles between 0.01-0.99. Background noise appears with higher numbers.

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 TRUE, saves the information of the genomic windows in the current directory (default = FALSE).

topNGenes

Number of top expressed genes to keep (default = 7000).

chrArmsToForce

A chromosome arm (e.g., "8p", "3q") or a list of chromosome arms (e.g., c("3q", "8p", "17p")) to force into the analysis.

genesToForce

A list of genes to force into the analysis (e.g. c("FOXP3","MUC16","SAMD15")).

regionToForce

Chromosome region to force into the analysis (vector containing chr, start, end).

getCNVPerChromosomeArm

If TRUE, will save the CNV per chromosome arm into the metadata.

getCNVClusters

If TRUE, will perform clustering on the CNV scores and save them in the metadata of the Seurat object as cnv_clusters.

k_clusters

Optional. Number of clusters to cut the dendrogram into. If NULL, the optimal number of clusters is determined automatically using the elbow method.

h_clusters

Optional. The height at which to cut the dendrogram for clustering. If both k and h are provided, k takes precedence.

cellTypesToCluster

Optional. Cell type annotations to use for clustering. If NULL (default), all observations will be clustered.

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 TRUE, will build a heatmap for each of the samples (default = TRUE).

denoise

If TRUE, the denoised data will be used in the heatmap (default = TRUE).

printPlot

If TRUE, the heatmap will be printed in the console (default = FALSE, the plot will only be saved in a PDF).

savePath

Path to save the heatmap plot. If NULL, the plot won't be saved (default = .).

outputType

Specifies the file format for saving the plot, either "png" or "pdf" (default = "png").

clustersVar

The variable name of the clusters in the Seurat metadata (default = "cnv_clusters").

splitPlotOnVar

The name of the metadata column to split the observations during the plotCNVResults step, if different from referenceVar.

referencePalette

The color palette that should be used for referenceVar (default = "default").

clusters_palette

The color palette that should be used for clustersVar (default = "default").

Value

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).