DELFI

finaletoolkit.frag.delfi(input_file, chrom_sizes, bins_file, reference_file, blacklist_file=None, gap_file=None, output_file=None, no_gc_correct=False, gc_correct=None, remove_nocov=True, merge_bins=True, window_size=5000000, quality_threshold=30, workers=1, verbose=False)[source]

Compute DELFI features, replicating Cristiano et al. (2019).

Parameters:
  • input_file (str) – BAM/CRAM/fragment file of paired-end reads.

  • chrom_sizes (str) – .chrom.sizes file (autosomes only to match the original scripts).

  • bins_file (str) – BED of bins (100kb to match the original methodology).

  • reference_file (str) – Reference genome (.2bit or FASTA; FASTA required for CRAM input).

  • blacklist_file (str, optional) – BED of regions to ignore.

  • gap_file (str or GenomeGaps, optional) – Telomere/centromere annotations: a BED4 file, a genome name ("b37"/"hg19"/"hg38"/"GRCh38"), or a GenomeGaps.

  • output_file (str, optional) – Output BED/.bed.gz/.tsv/.csv path, or "-" for stdout.

  • no_gc_correct (bool, optional) – Skip GC correction (default False).

  • gc_correct (bool, optional) – Deprecated; overrides no_gc_correct when set.

  • remove_nocov (bool, optional) – Remove the two hg19 no-coverage windows of Cristiano et al. (default True). Disable for non-hg19 references.

  • merge_bins (bool, optional) – Merge 100kb bins to 5Mb (default True).

  • window_size (int, optional) – Merge window size in bp (default 5,000,000).

  • quality_threshold (int, optional) – Minimum mapping quality (default 30).

  • workers (int, optional) – Worker-process count (default 1).

  • verbose (int or bool, optional) – Print progress/timing.

Returns:

DELFI results with the original author’s column names.

Return type:

pandas.DataFrame

finaletoolkit.frag.delfi_gc_correct(windows, alpha=0.75, it=8, verbose=False)[source]

GC-correct DELFI window features with a LOESS fit per feature.

For each of short, long, num_frags and ratio, a degree-2 LOESS curve is fit over GC content and subtracted (re-centered on the feature median), producing {feature}_corrected columns.

Parameters:
  • windows (pandas.DataFrame) – DELFI windows; must contain a gc column and the feature columns.

  • alpha (float, optional) – LOESS smoothing fraction (default 0.75).

  • it (int, optional) – Retained for signature compatibility (unused).

  • verbose (bool, optional) – Print timing.

Returns:

A copy of windows with {feature}_corrected columns added.

Return type:

pandas.DataFrame

finaletoolkit.frag.delfi_merge_bins(hundred_kb_bins, gc_corrected=True, verbose=False)[source]

Merge 100kb DELFI bins into non-overlapping 5Mb windows per arm.

p-arms are aggregated 5’->3’; q-arms are aggregated 3’->5’ and then reversed, matching the original DELFI scripts. Partial (<50-bin) chunks at arm ends are dropped.

Parameters:
  • hundred_kb_bins (pandas.DataFrame) – 100kb bins with an arm column and DELFI feature columns. When gc_corrected is True the *_corrected columns must be present.

  • gc_corrected (bool, optional) – Whether the input carries GC-corrected columns to aggregate (default True). Unlike the original implementation this flag is honored, so merging works with GC correction disabled.

  • verbose (bool, optional) – Unused; kept for signature compatibility.

Returns:

The merged 5Mb bins, with the same columns as the input (minus any index column).

Return type:

pandas.DataFrame