smftools.analysis.filters.obs_filters

smftools.analysis.filters.obs_filters#

Composable obs-level filters for AnnData.

Key functions: max_cigar_deletion(), build_obs_mask().

Example:

from smftools.analysis.filters.obs_filters import build_obs_mask

mask = build_obs_mask(
    adata.obs,
    barcode="NB01",
    ref_strand="6B6_top",
    demux_type="double",
    wt_ref_strands=["6B6_top", "6B6_bottom"],
    max_cigar_del=200,
)
idx = np.flatnonzero(mask)

Functions

build_obs_mask(obs[, barcode, ref_strand, ...])

Build a boolean obs mask with composable read filters.

max_cigar_deletion(cigar)

Return the largest single deletion length in a CIGAR string, or 0.

smftools.analysis.filters.obs_filters.max_cigar_deletion(cigar)#

Return the largest single deletion length in a CIGAR string, or 0.

Return type:

int

smftools.analysis.filters.obs_filters.build_obs_mask(obs, barcode=None, ref_strand=None, demux_type=None, wt_ref_strands=None, max_cigar_del=None, extra_eq=None, barcode_col='Barcode', ref_strand_col='Reference_strand', demux_col='demux_type', cigar_col='CIGAR')#

Build a boolean obs mask with composable read filters.

Return type:

ndarray

Parameters#

obspd.DataFrame

adata.obs DataFrame.

barcodestr, optional

Keep reads with this barcode value.

ref_strandstr, optional

Keep reads mapped to this reference strand.

demux_typestr, optional

Keep reads with this demux_type (e.g. "double").

wt_ref_strandslist of str, optional

If ref_strand is in this list, apply the CIGAR deletion filter.

max_cigar_delint, optional

Maximum allowed single deletion in the CIGAR string (bp). Applied only when ref_strand is in wt_ref_strands. Use to exclude enh-del allele reads misassigned to the WT reference.

extra_eqdict, optional

Additional equality filters as {column: value}.

barcode_colstr

obs column for barcode identity.

ref_strand_colstr

obs column for reference strand.

demux_colstr

obs column for demultiplexing type.

cigar_colstr

obs column containing CIGAR strings.

Returns#

np.ndarray

Boolean array of length n_obs.