Skip to content

ccnv.stats.fragmentomics

Stateless mathematical and machine learning kernels for cfDNA fragmentomics.

Attributes

NameDescription
CANONICAL_CHROMATOSOME_BPNo description.
FRAG_MAX_LENNo description.
FRAG_MIN_LENNo description.
FRAG_NUM_BINSNo description.

Classes

NameDescription
FragmentomicLandmarksPure scalar sample-level cfDNA fragmentomic landmarks and QC metrics.

Functions

NameDescription
align_histogramSub-pixel linear shift of a 1-bp histogram onto the canonical frame.
build_fragmentomic_feature_vectorExtract a 36-dimensional mode-aligned feature vector for the FF_size ensemble.
compute_band_fisher_weightsDerive Fisher-optimal read weights mapped to 24 discrete fragmentomic bands.
compute_fragment_length_llrCompute fragment length log-likelihood ratio over [50, 350] bp in nats.
compute_helical_periodicityEvaluate 10.4 bp helical cleavage periodicity via DFT in the sub-nucleosomal band.
compute_motif_diversity_scoreCompute the normalized Shannon entropy (MDS) over 256 5' end motifs in [0, 1].
deconvolve_fetal_maternal_densitiesCohort EM deconvolution of pure fetal and maternal cfDNA fragment length densities.
estimate_sample_landmarksExtract pure scalar structural landmarks, helical periodicity, and motif ratios.
evaluate_band_weighted_countsEvaluate Fisher-weighted coverage and compound-Poisson variance dispersion factor from 24 frag_bands.
fit_ff_fragmentomics_ensembleTrain a standardized convex logit-link RidgeCV + ElasticNetCV ensemble for FF_size.
predict_ff_fragmentomicsPredict fetal fraction from pure fragmentomic arrays via mode-aligned KL MLE + logit ensemble.
predict_ff_kl_deconvolutionZero-parameter maximum likelihood estimation of fetal fraction via KL deconvolution.

CANONICAL_CHROMATOSOME_BPattributemodule attribute#

CANONICAL_CHROMATOSOME_BP: Final[float] = 166.0

FRAG_MAX_LENattributemodule attribute#

FRAG_MAX_LEN: Final[int] = 600

FRAG_MIN_LENattributemodule attribute#

FRAG_MIN_LEN: Final[int] = 30

FRAG_NUM_BINSattributemodule attribute#

FRAG_NUM_BINS: Final[int] = 571

FragmentomicLandmarksclassdataclass#

class FragmentomicLandmarks(paired_end: bool, total_paired_fragments: int, chromatosome_mode_bp: float, core_shoulder_bp: float, sizing_shift_bp: float, self_referenced_peak_ratio: float, dinucleosome_fraction: float, high_mw_fraction: float, helical_10bp_amplitude: float, helical_10bp_phase: float, motif_diversity_score: float, fetal_motif_ratio: float)

Pure scalar sample-level cfDNA fragmentomic landmarks and QC metrics.

chromatosome_mode_bpattributeinstance attribute#

chromatosome_mode_bp: float

core_shoulder_bpattributeinstance attribute#

core_shoulder_bp: float

dinucleosome_fractionattributeinstance attribute#

dinucleosome_fraction: float

fetal_motif_ratioattributeinstance attribute#

fetal_motif_ratio: float

helical_10bp_amplitudeattributeinstance attribute#

helical_10bp_amplitude: float

helical_10bp_phaseattributeinstance attribute#

helical_10bp_phase: float

high_mw_fractionattributeinstance attribute#

high_mw_fraction: float

motif_diversity_scoreattributeinstance attribute#

motif_diversity_score: float

paired_endattributeinstance attribute#

paired_end: bool

self_referenced_peak_ratioattributeinstance attribute#

self_referenced_peak_ratio: float

sizing_shift_bpattributeinstance attribute#

sizing_shift_bp: float

total_paired_fragmentsattributeinstance attribute#

total_paired_fragments: int

align_histogramfunction#

def align_histogram(hist: ArrayLike, shift_bp: float) -> NDArray[np.float64]

Sub-pixel linear shift of a 1-bp histogram onto the canonical frame.

build_fragmentomic_feature_vectorfunction#

def build_fragmentomic_feature_vector(hist_autosomal: ArrayLike, motif_counts: ArrayLike, chromatosome_mode_bp: float = CANONICAL_CHROMATOSOME_BP, sizing_shift_bp: float = 0.0, helical_10bp_amp: float | None = None, motif_mds: float | None = None, fetal_motif_ratio: float | None = None, reference_maternal_571: ArrayLike | None = None) -> NDArray[np.float64]

Extract a 36-dimensional mode-aligned feature vector for the FF_size ensemble.

compute_band_fisher_weightsfunction#

def compute_band_fisher_weights(p_fetal_571: ArrayLike, p_maternal_571: ArrayLike, *, f0: float = 0.08) -> tuple[NDArray[np.float64], float, float]

Derive Fisher-optimal read weights mapped to 24 discrete fragmentomic bands.

compute_fragment_length_llrfunction#

def compute_fragment_length_llr(hist: ArrayLike, p_fetal: ArrayLike, p_maternal: ArrayLike, *, sizing_shift_bp: float = 0.0, baseline_ff: float | None = None, is_gain: bool = False) -> float

Compute fragment length log-likelihood ratio over [50, 350] bp in nats.

When baseline_ff is provided, evaluates the exact Kass-Raftery log-Bayes-factor between fetal-origin CNV mixture q_fetal and maternal-origin CNV mixture q_maternal (matching chrx_llr_fetal < -2.0 in classify_sca_ray_4d). Otherwise evaluates sum_L h_L * ln(p_F(L) / p_M(L)) over [50, 350] bp.

compute_helical_periodicityfunction#

def compute_helical_periodicity(hist: ArrayLike) -> tuple[float, float]

Evaluate 10.4 bp helical cleavage periodicity via DFT in the sub-nucleosomal band.

compute_motif_diversity_scorefunction#

def compute_motif_diversity_score(motif_counts: ArrayLike) -> float

Compute the normalized Shannon entropy (MDS) over 256 5’ end motifs in [0, 1].

deconvolve_fetal_maternal_densitiesfunction#

def deconvolve_fetal_maternal_densities(hist_autosomal_matrix: ArrayLike, hist_chry_matrix: ArrayLike, ff: ArrayLike, is_male: ArrayLike, *, smooth_sigma: float = 1.2, em_steps: int = 8) -> tuple[NDArray[np.float64], NDArray[np.float64]]

Cohort EM deconvolution of pure fetal and maternal cfDNA fragment length densities.

estimate_sample_landmarksfunction#

def estimate_sample_landmarks(hist_autosomal: ArrayLike, end_motif_counts: ArrayLike, *, paired_end: bool = True) -> FragmentomicLandmarks

Extract pure scalar structural landmarks, helical periodicity, and motif ratios.

evaluate_band_weighted_countsfunction#

def evaluate_band_weighted_counts(frag_bands: ArrayLike, raw_counts: ArrayLike, paired_counts: ArrayLike, band_weights_24: ArrayLike) -> tuple[NDArray[np.float64], NDArray[np.float32]]

Evaluate Fisher-weighted coverage and compound-Poisson variance dispersion factor from 24 frag_bands.

fit_ff_fragmentomics_ensemblefunction#

def fit_ff_fragmentomics_ensemble(features: ArrayLike, ff_targets: ArrayLike, *, seed: int = 42) -> LogitEnsembleFit

Train a standardized convex logit-link RidgeCV + ElasticNetCV ensemble for FF_size.

predict_ff_fragmentomicsfunction#

def predict_ff_fragmentomics(hist_autosomal: ArrayLike, motif_counts: ArrayLike, *, paired_end: bool = True, chromatosome_mode_bp: float = CANONICAL_CHROMATOSOME_BP, sizing_shift_bp: float = 0.0, helical_10bp_amp: float | None = None, motif_mds: float | None = None, fetal_motif_ratio: float | None = None, p_fetal_density: ArrayLike | None = None, p_maternal_density: ArrayLike | None = None, ff_frag_weights: ArrayLike | None = None, ff_frag_bias: float = 0.0, ff_frag_feature_mean: ArrayLike | None = None, ff_frag_feature_scale: ArrayLike | None = None) -> float | None

Predict fetal fraction from pure fragmentomic arrays via mode-aligned KL MLE + logit ensemble.

predict_ff_kl_deconvolutionfunction#

def predict_ff_kl_deconvolution(hist_sample: ArrayLike, p_fetal: ArrayLike, p_maternal: ArrayLike) -> tuple[float, float]

Zero-parameter maximum likelihood estimation of fetal fraction via KL deconvolution.