swiftcnv.run_from_adata

Contents

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 .h5ad file 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.obs or cells_file defining reference status.

  • reference_vals (list-like, optional) – Values within reference_col that indicate reference cells. Default treats reference_col as boolean.

  • read_X (bool, default False) – Whether to read the adata.X matrix. If False, reads adata.layers['counts'].

  • sample_col (str, optional) – Column name in cells_file or adata.obs to 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=False and an AnnData object was provided, returns the updated AnnData object. CNV scores are stored in adata.obsm['cnv_mat'], cell metadata in adata.obs, and gene metadata in adata.var, including boolean column 'has_cnv'.

  • If run_hmm=True, returns a tuple of (updated_adata, cnv_states, tumor_subclusters), where cnv_states is a pandas.DataFrame and tumor_subclusters is a pandas.DataFrame or None.

  • If adata was provided as a file path (.h5ad), returns None.

Return type:

anndata.AnnData or tuple[anndata.AnnData, pandas.DataFrame, pandas.DataFrame or None] or None