Skip to content

Stage 3.2: epigenetic mapping

Applies to GraffiTE v1.1

Verified against v1.1.0.0 at commit bf51777. The 2024 paper describes v1.0, which differs in places; see v1.0 vs v1.1.

Documented from the wiring, not from a run

This page describes what main.nf and the panmethyl module do when --epigenomes is set. It was written without a methylation run. Process behavior was read from panmethyl/module/main.nf at submodule commit f0aa2c0.

With --epigenomes, GraffiTE reads the base-modification tags (MM/ML) of the BAMs it is genotyping, lifts each modified base onto the graph node it maps to, and reports per-allele methylation levels in the genotyped VCF. The processes come from panmethyl, a git submodule that must be present for main.nf to parse at all; see Installation.


Requirements

Requirement Why Source
--graph_method giraffe, graphaligner or precomputed the methylation branch sits inside the vg genotyping block; PanGenie has no graph alignments to lift onto main.nf:206,234
--epigenomes switches the branch on nextflow.config:33
BAM entries in --genotype_with bamtags_to_BED reads the modifications from BAM tags, and annotate_VCF runs only for samples that have a mods CSV; a FASTQ sample is aligned and genotyped, then dropped by the join, so its calls never reach GraffiTE.merged.genotypes.vcf.gz main.nf:244,251
MM/ML tags in those BAMs what tagtobed extracts panmethyl/module/main.nf:146

The reads of a BAM sample are also extracted to FASTQ and aligned to the graph as for any other sample (Stage 3.1). The alignment inside the BAM is not used; lift_epigenome lifts the modifications through the graph alignment (<sample>.gaf.gz).


How it works

main.nf:234-257

  1. index_graph reads index.gfa and lists every position of --motif (default CG) on every node, writing node_sizes.csv, nodes_list.csv and index.csv.gz to out/index/ panmethyl/module/main.nf:67-83.
  2. bamtags_to_BED runs tagtobed on each BAM, extracting the modification calls for --code (default C+m, 5-methylcytosine on the forward strand) into <sample>.mods.gz panmethyl/module/main.nf:136-148.
  3. lift_epigenome joins the modification calls with the sample's graph alignment by read name and projects each modified base onto graph node coordinates with lift_mods, writing out/lifted/<sample>.csv.gz panmethyl/module/main.nf:150-166.
  4. merge_CSV aggregates the per-read calls into per-node levels at the indexed motif positions, writing out/levels/<sample>.csv.gz panmethyl/module/main.nf:168-187.
  5. annotate_VCF walks each allele's path (INFO/AT) in the sample's vg call VCF, averages the levels on the nodes of that path, and writes out/annotation/<sample>.mods.vcf.gz plus a long-format <sample>.mods.tsv with one row per allele panmethyl/module/main.nf:1-15, panmethyl/module/resources/usr/bin/annotate_vcf.py:44-46. It leaves a record whose genotype is missing altogether (GT is .) out of both files panmethyl/module/resources/usr/bin/annotate_vcf.py:54-55.

The annotated per-sample VCFs replace the plain vg call VCFs going into merge_VCFs, so the merged genotypes carry the methylation FORMAT fields main.nf:251. merge_VCFs writes a missing genotype for a sample whose VCF lacks a record, and a record left out for every sample does not reach GraffiTE.merged.genotypes.vcf.gz. Without --epigenomes that record stays, with no genotype in any column main.nf:260, module/main.nf:894.

FORMAT fields

Added by annotate_vcf.py panmethyl/module/resources/usr/bin/annotate_vcf.py:44-46, one value per allele of the genotype:

Field Type Meaning
PMN Float, Number=. number of modified nucleotides with coverage on the allele's path
PML Float, Number=. average modification level across the path
PMD Float, Number=. average depth across the modified nucleotides

With PML per allele, you can compare a TE insertion's methylation against the empty site, or one haplotype's copy against the other's.


Inputs

Parameter Default Effect Source
--epigenomes false run the branch nextflow.config:33
--motif "CG" motif indexed on the graph nextflow.config:170
--code "C+m" modification code passed to tagtobed (-T C -B C+m) nextflow.config:169, panmethyl/module/main.nf:146
--lifted false samplesheet (sample,path) of already-lifted <sample>.csv.gz files; skips steps 2 and 3 main.nf:239-242
--bed false a BED of regions to project onto the graph and annotate with methylation main.nf:253-257

With --bed, three more processes run: BED_to_graph projects the regions with vg annotate, annotate_BED averages levels over each region per sample into out/annotation/<sample>.bed, and merge_BED joins the samples into out/annotation/merged_epiannoation.bed (the filename is spelled that way in the module) panmethyl/module/main.nf:17-65.


Outputs

All relative to --out, and beside GraffiTE's numbered directories:

Path Written by
index/node_sizes.csv, nodes_list.csv, index.csv.gz index_graph
lifted/<sample>.csv.gz lift_epigenome
levels/<sample>.csv.gz merge_CSV
annotation/<sample>.mods.vcf.gz, <sample>.mods.tsv annotate_VCF
annotation/<sample>.bed, merged_epiannoation.bed annotate_BED, merge_BED (with --bed)
4_Genotyping/GraffiTE.merged.genotypes.vcf.gz merge_VCFs, now carrying PMN, PML, PMD

Resources

The panmethyl processes have fixed allocations in nextflow.config rather than parameters nextflow.config:304-343:

Process CPUs Memory Time
bamtags_to_BED 2 50 GB 6 h
lift_epigenome, merge_CSV 1 60 GB 6 h
index_graph, annotate_VCF, annotate_BED, BED_to_graph, merge_BED 1 40 GB 6 h

Change them with a -c config file that overrides the withName blocks.


Limitations

  • PanGenie runs get no methylation: the branch needs graph alignments.
  • One modification code per run.
  • Under --epigenomes, every entry in --genotype_with must be a BAM or be listed in --lifted. A FASTQ entry is aligned and genotyped, then left out of the merged genotype VCF with no warning main.nf:251,266.
  • GraffiTE does not call panmethyl's own aligners (align_giraffe, align_graphaligner, align_minigraph) or its lift_nucleotides process; the alignment comes from graph_align_reads.