Skip to content

Annotate immunoglobulin somatic hypermutation

Source code

Description

[Experimental]

Calculate overall, V-region, and AIRR-region somatic-hypermutation counts and frequencies from aligned observed and reconstructed germline sequences.

The input must contain the columns selected by sequence_col and germline_col, v_sequence_start, v_alignment_start, and the canonical AIRR *_start and *_end columns for FWR1, CDR1, FWR2, CDR2, FWR3, CDR3, and FWR4. The default germline column is normally created with annotate_ig_germlines().

Usage

annotate_ig_shm(
  idata,
  sequence_col = "sequence_alignment",
  germline_col = "germline_alignment",
  by = "<auto>"
)

Arguments

idata immundata::ImmunData. IgBLAST AIRR data to annotate.
sequence_col Character scalar. Aligned observed-sequence column.
germline_col Character scalar. Aligned reconstructed germline column. sequence_col and germline_col may select alternative alignment columns, but those columns must use the same alignment and coordinate system as the canonical AIRR region-coordinate columns.
by Character vector, "<auto>", or NULL. Columns used to calculate group-level mu_freq summaries. The default uses clone_id, with subject_id when available; locus is added when available. NULL skips grouped summaries.

Details

AIRR region coordinates are interpreted as 1-based closed intervals on the unaligned query sequence. v_alignment_start identifies the aligned position corresponding to v_sequence_start. While mapping query positions, N consumes a query coordinate, whereas . and - do not.

A position is comparable only when both aligned characters are unambiguous A, C, G, or T nucleotides. Thus N, ., and - positions contribute to neither mutation counts nor frequency denominators. mu_count is the sum of classifiable replacement and silent mutations across all available regions; mu_freq divides that count by the number of comparable positions in those regions. Overall and combined CDR/FWR replacement and silent frequencies use the sum of comparable positions across their selected regions, not aggregated regional frequencies. Individual-region frequencies use the comparable positions in that region as their denominator.

Replacement and silent consequences are classified independently for each mutation against the germline codon. Stop-producing substitutions are not counted as either class. If one boundary of a region is missing, all four outputs for that region are missing while other regions and overall outputs remain available. A valid region with no comparable positions has zero counts and missing frequencies. Combined CDR and framework metrics use the available regions in their respective sets. If no region in a set has both boundaries, all combined outputs for that set are missing.

When grouping is enabled, mu_freq_median and mu_freq_mean summarize non-missing mu_freq values without weighting, and mu_freq_n counts their contributors. Rows missing any grouping key receive missing median and mean values and a zero count. Explicit by columns are used exactly as supplied; include locus explicitly to keep heavy and light chains separate. Use dplyr::distinct() on the grouping columns and summaries when a group-level rather than row-level result is needed.

Value

immundata::ImmunData. The input rows with combined mu_count and mu_freq columns plus replacement and silent counts and frequencies overall, across the V region (FWR1 through FWR3), across all CDRs, across all framework regions, and for each individual region. When grouping is enabled, the result also includes mu_freq_median, mu_freq_mean, and mu_freq_n on every row.

Why SHM results may differ between tools

Results can differ between SHM tools, even for the same sequences. This function counts a mutation only when its codon (a group of three bases) is complete and has no alignment gap. Other tools may count mutations in codons with gaps. Removing . characters from an IMGT alignment can also shift codon boundaries and change which mutations are counted, including mutations that create a stop codon. For a fair comparison, use matching alignments and region positions, and check how each tool handles gaps and stop codons.