Skip to main content

write_contig

Function write_contig 

Source
pub fn write_contig<W: Write>(
    writer: &mut W,
    chrom: &str,
    reference: &[u8],
    variants: &[VariantRecord],
    methylation: &ContigMethylation,
    sample_ploidy: usize,
) -> Result<()>
Expand description

Write all methylation-only records for one contig as VCF text rows.

Each row has the form:

  • Standalone (Case 1, REF=C ALT=.): <chrom>\t<POS>\t.\tC\t.\t.\t.\t.\tMT:MB\t<mt>:<mb>
  • Variant (Case 2, with GT): <chrom>\t<POS>\t.\t<REF>\t<ALT>\t.\t.\t.\tGT:MT:MB\t<gt>:<mt>:<mb>

POS is 1-based. <mt>/<mb> are |-separated per-haplotype bitstrings: "1" = methylated CpG, "0" = unmethylated CpG, "." = haplotype carries REF or no CpGs in the alt allele. For standalone records the per-haplotype value is always a single bit ("0" or "1").

Standalone and variant records are interleaved in ascending reference position order. Header writing is the caller’s responsibility.

§Errors

Returns an error if any variant has an unphased genotype, two variants have overlapping REF spans (see classify_cpgs), or any write to writer fails.