swiftcnv.run_from_adata#
- run_from_adata(adata, gtf_file, output_dir=None, cells_file=None, reference_col='reference', reference_vals=None, read_X=False, sample_col=None, arms_file=None, exclude_immune=False, sex_chr=False, plot=False, run_hmm=False, hmm_by='subcluster', n_clusters=3, threads=1, **kwargs)#
Helper function for running the SwiftCNV pipeline from an AnnData object or file.
- Parameters:
adata (str or anndata.AnnData) – Path to input
.h5adfile or an in-memory AnnData object.gtf_file (str or pandas.DataFrame) – Path to gene annotations file (
.gtf) or a DataFrame.output_dir (str, optional) – Output directory for writing results and plots.
cells_file (str, optional) – Path to a file containing cell metadata (cell names, reference status, and samples). Default uses data from
adata.obs.reference_col (str, default 'reference') – Column name in
adata.obsorcells_filedefining reference status.reference_vals (list-like, optional) – Values within
reference_colthat indicate reference cells. Default treatsreference_colas boolean.read_X (bool, default False) – Whether to read the
adata.Xmatrix. If False, readsadata.layers['counts'].sample_col (str, optional) – Column name in
cells_fileoradata.obsto retrieve sample IDs. Used to run sample-level analyses.arms_file (str or pandas.DataFrame, optional) – File path or DataFrame containing gene chromosome arm annotations. See
load_chr_arms().sex_chr (bool, default False) – Whether to keep genes from sex chromosomes (X and Y). Excluded by default.
exclude_immune (bool, default False) – Whether to exclude genes matching the pattern
(HLA-|IGH|IGK|IGL).plot (bool, default False) – Whether to output heatmaps and sample heatmaps to
output_dir.run_hmm (bool, default False) – Whether to perform HMM segmentation analysis on the CNV scores.
hmm_by ({'subcluster', 'sample', 'cell'}, default 'subcluster') – Level at which to stratify HMM segmentation: by subclusters within each sample, by whole samples, or by individual cells.
n_clusters (int, default 3) – Number of clusters to use when
hmm_by='subcluster'.threads (int, default 1) – Number of threads for multithreaded processing.
**kwargs – Additional keyword arguments passed to
run().
- Returns:
If
run_hmm=Falseand anAnnDataobject was provided, returns the updatedAnnDataobject. CNV scores are stored inadata.obsm['cnv_mat'], cell metadata inadata.obs, and gene metadata inadata.var, including boolean column'has_cnv'.If
run_hmm=True, returns a tuple of(updated_adata, cnv_states, tumor_subclusters), wherecnv_statesis apandas.DataFrameandtumor_subclustersis apandas.DataFrameorNone.If
adatawas provided as a file path (.h5ad), returnsNone.
- Return type:
anndata.AnnData or tuple[anndata.AnnData, pandas.DataFrame, pandas.DataFrame or None] or None