diff --git a/src/dandelion/base/preprocessing/_preprocessing.py b/src/dandelion/base/preprocessing/_preprocessing.py index 8ed1a9169..502c5b9e4 100644 --- a/src/dandelion/base/preprocessing/_preprocessing.py +++ b/src/dandelion/base/preprocessing/_preprocessing.py @@ -2866,6 +2866,7 @@ def check_contigs( adata: AnnData | None = None, productive_only: bool = True, library_type: Literal["ig", "tr-ab", "tr-gd"] | None = None, + min_umi: int = 1, umi_foldchange_cutoff: int = 2, consensus_foldchange_cutoff: int = 5, ntop_vdj: int = 1, @@ -2921,6 +2922,8 @@ def check_contigs( TRA, TRB `tr-gd`: TRG, TRD + min_umi : int, optional + Minimum UMI count for a contig to be considered. umi_foldchange_cutoff : int, optional related to minimum fold change of UMI count, required to rescue contigs/barcode otherwise they will be marked as extra/ambiguous. consensus_foldchange_cutoff : int, optional @@ -2986,6 +2989,9 @@ def check_contigs( else: dat = dat_.copy() + # filter based on umi + dat = dat[dat["umi_count"].astype(int) >= min_umi].copy() + if acceptable is not None: dat = dat[dat.locus.isin(acceptable)].copy() diff --git a/src/dandelion/polars/preprocessing/_preprocessing.py b/src/dandelion/polars/preprocessing/_preprocessing.py index 09f178d93..428a32dce 100644 --- a/src/dandelion/polars/preprocessing/_preprocessing.py +++ b/src/dandelion/polars/preprocessing/_preprocessing.py @@ -4213,6 +4213,7 @@ def check_contigs( adata: AnnData | None = None, productive_only: bool = True, library_type: Literal["ig", "tr-ab", "tr-gd"] | None = None, + min_umi: int = 1, umi_foldchange_cutoff: float = 2.0, consensus_foldchange_cutoff: float = 5.0, ntop_vdj: int = 1, @@ -4247,6 +4248,8 @@ def check_contigs( - `ig`: IGH, IGK, IGL - `tr-ab`: TRA, TRB - `tr-gd`: TRG, TRD + min_umi : int, optional + Minimum UMI count for a contig to be considered. umi_foldchange_cutoff : float, default=2.0 Minimum UMI fold-change threshold for dominance test. consensus_foldchange_cutoff : float, default=5.0 @@ -4323,8 +4326,6 @@ def check_contigs( mark_ambiguous_contigs_vec : Core vectorized function for marking contigs check_chimeric_genes_vec : Detects chimeric gene calls """ - from pathlib import Path - import os if verbose: print("Filtering contigs...") @@ -4384,6 +4385,11 @@ def check_contigs( else: dat = dat_ + # filter by minimum UMI count (lazy) + dat = dat.filter( + pl.col("umi_count").cast(pl.Int64) >= min_umi + ) # if the row has no umi_count, it will be filtered out since it will be null and null >= min_umi is false + # Filter by library type (lazy) if acceptable is not None: dat = dat.filter(pl.col("locus").is_in(acceptable))