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
index_graphreadsindex.gfaand lists every position of--motif(defaultCG) on every node, writingnode_sizes.csv,nodes_list.csvandindex.csv.gztoout/index/panmethyl/module/main.nf:67-83.bamtags_to_BEDrunstagtobedon each BAM, extracting the modification calls for--code(defaultC+m, 5-methylcytosine on the forward strand) into<sample>.mods.gzpanmethyl/module/main.nf:136-148.lift_epigenomejoins the modification calls with the sample's graph alignment by read name and projects each modified base onto graph node coordinates withlift_mods, writingout/lifted/<sample>.csv.gzpanmethyl/module/main.nf:150-166.merge_CSVaggregates the per-read calls into per-node levels at the indexed motif positions, writingout/levels/<sample>.csv.gzpanmethyl/module/main.nf:168-187.annotate_VCFwalks each allele's path (INFO/AT) in the sample'svg callVCF, averages the levels on the nodes of that path, and writesout/annotation/<sample>.mods.vcf.gzplus a long-format<sample>.mods.tsvwith one row per allelepanmethyl/module/main.nf:1-15,panmethyl/module/resources/usr/bin/annotate_vcf.py:44-46. It leaves a record whose genotype is missing altogether (GTis.) out of both filespanmethyl/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_withmust 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 warningmain.nf:251,266. - GraffiTE does not call panmethyl's own aligners (
align_giraffe,align_graphaligner,align_minigraph) or itslift_nucleotidesprocess; the alignment comes fromgraph_align_reads.