SwiftCNV
#
SwiftCNV is a fast and scalable Python implementation of the core InferCNV algorithm to infer copy number variations (CNVs) from single-cell RNA-seq data. It provides additional features and is designed for seamless interoperability with Anndata objects and Scanpy.
Documentation#
For detailed information and example tutorials, please refer to our documentation.
Installation#
SwiftCNV can be installed through pip:
pip install swiftcnv
Python dependencies are: numpy, pandas, scipy, scikit-learn, anndata, matplotlib
Extra dependencies for the tutorial: scanpy, ipykernel, leidenalg, requests
pip install swiftcnv[tutorial]
Usage#
SwiftCNV can be run from the command line from a h5ad file, but can also be imported to your script for advanced usage and AnnData/Scanpy integration. SwiftCNV requires a portion of the cells to be defined as reference to calculate the CNV score, normally being cells that are not expected to be malignant (e.g., based on cell type). The program requires a GTF file containing gene annotations, which be obtained from the Gencode database.
Command Line Interface#
Required arguments#
Option |
Description |
|---|---|
|
Path to input h5ad object |
|
Path to output directory |
|
Path to gtf gene annotations file for building gene order |
Optional arguments#
Option |
Description |
|---|---|
|
Raw counts are loaded from |
|
TSV with |
|
Column to find reference status. Default: |
|
Value(s) of reference cells in |
|
Column in |
|
Substract the mean of the reference cells for each sample instead of all samples together |
|
Exclude genes names that start with |
|
Include genes from chromosomes X and Y that are excluded by default |
|
Plot final heatmap and heatmaps by sample (if provided) |
|
Perform HMM segmentation of CNV states |
|
Stratification for HMM segmentation ( |
|
Number of clusters for performing HMM segmentation analysis. Default: |
|
Remove genes whose mean normalized expression across reference cells is below cutoff. Default: |
|
Remove genes expressed in less cells than this value. Default: |
|
Window size for smoothing in genes. Default: 1% of genes (min. 51) if |
|
Window size for smoothing in MB. Default: 30MB if |
|
Number of threads to use in parallel processes (HMM segmentation and clustering) |
Reference cells can be specified using a TSV file with two columns, cell_name and reference, where the reference column contains TRUE or FALSE to indicate whether each cell is used as a reference. Alternatively, reference cells can also be specified by providing the column in adata.obs containing the cell type annotations (–reference-col) and which ones should be used as reference (–reference-value). Finally, the column identifying the samples must be specified.
Example#
A typical call from a cells file would be:
swiftcnv \
-i /path/to/adata.h5ad \
-o /path/to/output \
-c /path/to/cells.tsv \
-a /path/to/gene_annotations.gtf.gz \
-s sample \
-p \
--hmm \
--exclude-immune
Where the required cells.tsv file (-c / --cells) would be:
cell_name |
reference |
sample |
|---|---|---|
AAATGCCTCACATACG |
True |
s1 |
AACCATGGTTATTCTC |
False |
s1 |
AACGTTGGTTTACTCT |
True |
s2 |
… |
… |
… |
Alternatively, one can use cell types from the input file to define the reference
swiftcnv \
-i /path/to/adata.h5ad \
-o /path/to/output \
-a /path/to/gene_annotations.gtf.gz \
--reference-col cell_type \
--reference-vals T_cell Macrophage Fibroblast \
-s sample \
-p \
--hmm
Outputs#
Output files are placed under -o/--output (or output_dir if defined). SwiftCNV generates 3 main files:
cnv_scores.npz: compressed matrix (cells x genes) containing the CNV valuescell_order.tsv.gz: file containing cell barcodes, reference status and sample_id if providedgene_order.tsv.gz: file containing gene metadata
If -p/--plot was specified:
cnv_scores.png: Heatmap plot of the whole CNV scores matrixcnv_scores_by_sample.pdf: Heatmap plots of each sample if provided
if --hmm was specified HMM segmentation outputs will go to a hmm/ directory:
cnv_states.tsv.gz: DataFrame containing 3-states labels matrix by subcluster, cell or sample, depending on--hmm-bycnv_states.png: Heatmap plot with the found HMM statestumor_subclusters.tsv.gz: subcluster labels for the state HMM clustering if--hmm-by=subcluster(default)