smftools.preprocessing.label_deaminase_pcr_chimeras

smftools.preprocessing.label_deaminase_pcr_chimeras#

smftools.preprocessing.label_deaminase_pcr_chimeras(adata, min_events_per_span=3, min_segment_purity=0.9, max_single_strand_fraction=0.8, obs_column='deaminase_PCR_chimera', uns_flag='label_deaminase_pcr_chimeras_performed', bypass=False, force_redo=True)#

Flag deaminase PCR-chimeric reads from per-read strand-switch metrics.

A deaminase PCR chimera is a molecule stitched from two templates of opposite deamination state, so along the read it shows a span of C->T (top-consistent) events and a span of G->A (bottom-consistent) events. The per-read metrics ct_event_count, ga_event_count and strand_segment_purity are computed at raw extraction (see smftools.informatics.ragged_store.strand_switch_metrics) and carried on adata.obs. This step thresholds them into a boolean obs[obs_column] label; reads are not removed.

A read is labeled a chimera when both strand signatures are present in sufficient number, the best two-segment (single-switch) model is highly pure, and the read is not overwhelmingly one-sided:

  • ct_event_count >= min_events_per_span and ga_event_count >= min_events_per_span

  • strand_segment_purity >= min_segment_purity

  • single_strand_fraction <= max_single_strand_fraction where single_strand_fraction = max(ct, ga) / (ct + ga)

Parameters:
  • adata (AnnData) -- AnnData object (typically deaminase modality).

  • min_events_per_span (int (default: 3)) -- Minimum C->T and G->A events required on each side.

  • min_segment_purity (float (default: 0.9)) -- Minimum best two-segment purity to accept a clean switch.

  • max_single_strand_fraction (float (default: 0.8)) -- Maximum one-sidedness for a read to qualify.

  • obs_column (str (default: 'deaminase_PCR_chimera')) -- Name of the boolean obs column to write.

  • uns_flag (str (default: 'label_deaminase_pcr_chimeras_performed')) -- Flag in adata.uns indicating prior completion.

  • bypass (bool (default: False)) -- Whether to skip processing.

  • force_redo (bool (default: True)) -- Whether to rerun even if uns_flag is set.

Returns:

The input AnnData with obs[obs_column] set (label only).

Return type:

anndata.AnnData