ccnv.stats.fragmentomics
Stateless mathematical and machine learning kernels for cfDNA fragmentomics.
Attributes
| Name | Description |
|---|---|
CANONICAL_CHROMATOSOME_BP | No description. |
FRAG_MAX_LEN | No description. |
FRAG_MIN_LEN | No description. |
FRAG_NUM_BINS | No description. |
Classes
| Name | Description |
|---|---|
FragmentomicLandmarks | Pure scalar sample-level cfDNA fragmentomic landmarks and QC metrics. |
Functions
| Name | Description |
|---|---|
align_histogram | Sub-pixel linear shift of a 1-bp histogram onto the canonical frame. |
build_fragmentomic_feature_vector | Extract a 36-dimensional mode-aligned feature vector for the FF_size ensemble. |
compute_band_fisher_weights | Derive Fisher-optimal read weights mapped to 24 discrete fragmentomic bands. |
compute_fragment_length_llr | Compute fragment length log-likelihood ratio over [50, 350] bp in nats. |
compute_helical_periodicity | Evaluate 10.4 bp helical cleavage periodicity via DFT in the sub-nucleosomal band. |
compute_motif_diversity_score | Compute the normalized Shannon entropy (MDS) over 256 5' end motifs in [0, 1]. |
deconvolve_fetal_maternal_densities | Cohort EM deconvolution of pure fetal and maternal cfDNA fragment length densities. |
estimate_sample_landmarks | Extract pure scalar structural landmarks, helical periodicity, and motif ratios. |
evaluate_band_weighted_counts | Evaluate Fisher-weighted coverage and compound-Poisson variance dispersion factor from 24 frag_bands. |
fit_ff_fragmentomics_ensemble | Train a standardized convex logit-link RidgeCV + ElasticNetCV ensemble for FF_size. |
predict_ff_fragmentomics | Predict fetal fraction from pure fragmentomic arrays via mode-aligned KL MLE + logit ensemble. |
predict_ff_kl_deconvolution | Zero-parameter maximum likelihood estimation of fetal fraction via KL deconvolution. |
CANONICAL_CHROMATOSOME_BPattributemodule attribute#
CANONICAL_CHROMATOSOME_BP: Final[float] = 166.0FRAG_MAX_LENattributemodule attribute#
FRAG_MAX_LEN: Final[int] = 600FRAG_MIN_LENattributemodule attribute#
FRAG_MIN_LEN: Final[int] = 30FRAG_NUM_BINSattributemodule attribute#
FRAG_NUM_BINS: Final[int] = 571FragmentomicLandmarksclassdataclass#
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: floatcore_shoulder_bpattributeinstance attribute#
core_shoulder_bp: floatdinucleosome_fractionattributeinstance attribute#
dinucleosome_fraction: floatfetal_motif_ratioattributeinstance attribute#
fetal_motif_ratio: floathelical_10bp_amplitudeattributeinstance attribute#
helical_10bp_amplitude: floathelical_10bp_phaseattributeinstance attribute#
helical_10bp_phase: floathigh_mw_fractionattributeinstance attribute#
high_mw_fraction: floatmotif_diversity_scoreattributeinstance attribute#
motif_diversity_score: floatpaired_endattributeinstance attribute#
paired_end: boolself_referenced_peak_ratioattributeinstance attribute#
self_referenced_peak_ratio: floatsizing_shift_bpattributeinstance attribute#
sizing_shift_bp: floattotal_paired_fragmentsattributeinstance attribute#
total_paired_fragments: intalign_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) -> floatCompute 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) -> floatCompute 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) -> FragmentomicLandmarksExtract 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) -> LogitEnsembleFitTrain 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 | NonePredict 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.