Stage 3.1: genotyping¶
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.
Stage 3 takes pangenome.vcf from Stage 2 and the read sets listed in
--genotype_with, builds a graph with the polymorphisms as bubbles, and genotypes each sample at
each bubble. On the PanGenie path some alleles never reach the graph; see PanGenie.
It runs by default; --genotype false stops after Stage 2
main.nf:188.
What a bubble is¶
INS record the
reference path skips the element and the ALT path runs through it. For a DEL record
it is the other way round. Each read counts for whichever path it traverses, so reads through
the TE node come from haplotypes that carry the element, whichever allele that is.
As the home page says, the ALT allele means TE present for INS records and
TE absent for DEL records.
Read sets¶
--genotype_with is a samplesheet with sample, path and type columns
(see Samplesheets). The type column selects a Giraffe
parameter preset main.nf:189-191:
type |
preset | used by |
|---|---|---|
pb, hifi |
hifi |
vg giraffe --parameter-preset hifi |
ont |
r10 |
vg giraffe --parameter-preset r10 |
| anything else, including an empty column | default |
vg giraffe --parameter-preset default -i |
Two details follow from that table:
- With the
defaultpreset,vg giraffeis given-i, so the FASTQ is read as interleaved paired-endmodule/main.nf:837-839,844. Supply short-read samples as a single interleaved file, not as two mate files. - PanGenie ignores the preset: it counts k-mers and never aligns
module/main.nf:748.
A path ending in .bam goes through bam_to_fastq first, which strips the alignment tags,
name-sorts the file and converts it back to FASTQ with samtools fastq
main.nf:192-197, module/main.nf:808-824. The alignments in the BAM
are not used; only the reads are. Methylation tags in such a BAM are read separately, see
Epigenetic mapping.
Choosing a graph method¶
--graph_method |
Graph | Reads are | Genotyper | When |
|---|---|---|---|---|
pangenie (default) |
PanGenie-index on a merged VCF |
counted as k-mers | PanGenie | k-mer counting, no alignment step; stops at launch with --human unless --hervk_reconcile false |
giraffe |
vg autoindex (GBZ) |
aligned with vg giraffe |
vg call |
short or long reads; the back end the HERV-K consolidation is validated on |
graphaligner |
vg construct (GFA) |
aligned with GraphAligner |
vg call |
long reads |
precomputed |
supplied with --graph |
supplied with --graph_alignments, or skipped with --vcfs |
vg call, or none |
re-genotyping an existing graph |
Source: main.nf:200-264, nextflow.config:38.
Anything else stops the run:
precomputed builds nothing itself. Without --graph and one of --vcfs or
--graph_alignments the run stops before any process starts
main.nf:51-56:
--graph_method precomputed builds nothing itself: it needs --graph (an index directory holding
index.gfa and index.pb, as make_graph writes) and either --vcfs (per-sample vg call VCFs) or
--graph_alignments (per-sample gaf,pack).
See Resuming and skipping work for what each of those inputs looks like.
PanGenie¶
Two processes module/main.nf:714-771.
pangenie_index, once per run:
bcftools view -Gdrops the genotype columns frompangenome.vcf.pangenie_graph_vcf.py preparewrites the one-sample VCF the graph is built from (a pseudo-samplerefcarrying1|0at every record) and starts a table with one row per ALT allele. It gives one graph variant to records that shareCHROM,POS,REFandALT, and replaces an ID that is missing, already used, or contains a character PanGenie splits on (;,,,:,=,|, space). Without this,merge_vcfs.pystopped on such records (issue #93)bin/pangenie_graph_vcf.py:8-16.bcftools sortandbcftools norm -m+join records at the same position into multi-allelic sites.merge_vcfs.py merge -ploidy 2(PanGenie's own helper, shipped inbin/) turns the file into the multi-sample graph VCF PanGenie reads, with anINFO/IDfield naming the graph variant behind each ALT allele. Three kinds of allele never reach the graph, so PanGenie gives them no genotype (issue #102):- an allele that overlaps another at the same site, because the pseudo-sample carries every
allele on one haplotype
bin/merge_vcfs.py:425-430; - the third and later alleles at one position, because step 3 joins them into one site and a diploid genotype holds two;
- every allele of a site whose REF or ALT holds a base other than A, C, G or T, such as
Nbin/merge_vcfs.py:468-470.
- an allele that overlaps another at the same site, because the pseudo-sample carries every
allele on one haplotype
On the synthetic test set PanGenie genotyped 15 of 29 alleles, and the 14 it missed all held a
base other than A, C, G or T; giraffe and GraphAligner genotyped all 29.
5. pangenie_graph_vcf.py report fills the table's in_graph column from that output.
6. PanGenie-index builds the k-mer index.
The table is published as 4_Genotyping/pangenie_graph_variants.tsv, columns record,
CHROM, POS, pangenome_ID, allele, graph_ID, in_graph, note. PanGenie writes each
allele's graph_ID to INFO/ID of the genotyped VCFs, so you use the table to find a
pangenome.vcf record in them bin/pangenie_graph_vcf.py:18-21,25.
pangenie, once per sample: PanGenie -s <sample> -i <(zcat -f reads) -f pangenie_index.
PanGenie writes no ##contig lines, so samtools faidx <ref> and bcftools reheader -f
<ref>.fai add the reference contigs to its header first. Without them, bcftools norm stops on
the first record and leaves a zero-byte .vcf.gz. Then bcftools norm -f ref -N -m- splits the
multi-allelic genotypes back into one record per GraffiTE variant, so that they match
pangenome.vcf one for one when the merge transfers INFO. -N keeps the position, since -f
turns on left-alignment as well as splitting and a realigned insertion matches nothing at the
merge module/main.nf:748-769.
The result is published as 4_Genotyping/<sample>_genotyping.vcf.gz with its index. The
reference is passed as a value channel; as a queue channel it held one item, and PanGenie ran
for one sample and stopped main.nf:202-205.
Resources: --pangenie_threads, --pangenie_memory, --pangenie_time for both processes
nextflow.config:248-257. --pangenie_memory defaults to 32G, so Nextflow
starts only as many PanGenie tasks at once as the memory allows. Each task peaked at about 23 GB
on the synthetic test set and on the chr22 example.
Giraffe and GraphAligner¶
Three processes, plus bam_to_fastq when needed.
make_graph¶
module/main.nf:773-806. bcftools +setGT -- -t a -n u unphases every genotype
in pangenome.vcf, then:
| method | commands | index/ holds |
|---|---|---|
giraffe |
vg autoindex -w sr-giraffe -w lr-giraffe, vg convert --vg-algorithm -f, vg snarls |
index.giraffe.gbz and its companions, index.gfa, index.pb |
graphaligner |
vg construct -a -m 1024, vg convert --vg-algorithm -f, vg snarls |
index.vg, index.gfa, index.pb |
index.gfa is the graph as GFA, index.pb the snarl (bubble) decomposition vg call needs.
The directory is published as GraffiTE_graph/index/ and is what --graph takes on a later
run. With --graph, make_graph does not run main.nf:210-214.
Resources: --make_graph_threads, --make_graph_memory (default 40G), --make_graph_time
(default 6h) nextflow.config:258-262.
graph_align_reads¶
module/main.nf:826-861, once per sample:
| method | aligner | then |
|---|---|---|
giraffe |
vg giraffe --parameter-preset <preset> -o gam --index-basename index/index [-i] -f reads |
vg pack -Q <min_mapq> and vg convert -G to GAF |
graphaligner |
GraphAligner -x vg -g index/index.gfa -f reads -a sample.gam |
same |
vg pack builds the per-node coverage vg call reads, dropping alignments below
--min_mapq (default 0) nextflow.config:125. The GAF is passed
through subset_gaf.py, which keeps the twelve standard columns plus the cs/cg difference
string, then sorted by read name and gzipped. The GAM is deleted. Published as
GraffiTE_alignments/<sample>.gaf.gz and <sample>.pack, which is the pair
--graph_alignments takes on a later run.
This process runs with errorStrategy = 'finish': when a sample fails, the tasks already
submitted or running finish before the run stops nextflow.config:268-273.
Resources: --graph_align_threads, --graph_align_memory, --graph_align_time (default
12h); bam_to_fastq uses the same three.
vg_call¶
module/main.nf:863-879, once per sample:
vg call -a -A --threads N -R chrX:1,chrY:1 -m 2,4 -r index/index.pb -s <sample> -k <sample>.pack index/<graph> \
| bcftools norm -m- | bcftools sort -Oz -o <sample>.vcf.gz
<graph>isindex.giraffe.gbzforgiraffeandindex.gfaotherwise,precomputedincluded.-aand-Arequest a call at every snarl, reference calls and nested snarls included, so that every sample has a genotype at every bubble and the merge lines up. Checkvg call --helpfor the exact wording in your vg version; the container ships vg 1.77.0.-m 2,4is--min_support, passed to vg as its minimum allele and site supportnextflow.config:126.-R chrX:1,chrY:1sets ploidy 1 on the contigs named exactlychrXandchrY. Every other contig is called diploid, so a reference that names themXandY, orNC_000023.11, gets diploid calls on the sex chromosomes. GraffiTE passes no other ploidy option tovg call.bcftools norm -m-splits multi-allelic calls into one record per ALT.
Resources: --vg_call_threads, --vg_call_memory, --vg_call_time (default 2h)
nextflow.config:274-278.
Merged genotypes¶
merge_VCFs module/main.nf:881-907 takes every per-sample VCF and:
bcftools merge -m nonejoins them into one multi-sample VCF without creating multi-allelic records.bcftools annotate -a pangenome.vcf -c CHROM,POS,ID,REF,ALT,INFOcopies every INFO field of the matchingpangenome.vcfrecord, so the genotyped records carry the repeat annotation, TSD and polyA fields. The match is onCHROM,POS,REFand at least one sharedALT;IDis one of the columns being copied, not part of the key (matching on it would need~ID). Allele comparison ignores case, which matters becausepangenome.vcfcarries soft-masked lowercase bases and the graph upper-cases them. A record that matches nothing keeps whatever the genotyper gave it and arrives with no annotationmodule/main.nf:902.- The
##GraffiTE_versionheader line is added.
Published as 4_Genotyping/GraffiTE.merged.genotypes.vcf.gz. No .tbi is published for it: the
index written earlier in the script belongs to the pre-annotation file, which is deleted. Run
tabix -p vcf on it yourself.
Resources: --merge_vcf_memory (default 10G), --merge_vcf_time (default 1h)
nextflow.config:279-283.
Trusted subset of the genotypes¶
trusted_genotypes module/main.nf:931-961 writes the counterpart of
pangenome.trusted.vcf for the genotyped calls:
4_Genotyping/GraffiTE.merged.genotypes.trusted.vcf.gzand its.tbi4_Genotyping/GraffiTE.merged.genotypes.presence-absence_trusted.tsv, the same schema as the discovery tables in3_TSD_search/
Every record in it has n_hits=1, so every record has one repeat class. See
The trusted subset for the full expression and the parameters
(--trusted_min_svlen, --trusted_max_ultra_span, --trusted_ignore_filter), which govern both
files.
The expression is evaluated on pangenome.vcf and the genotyped calls are subset by the IDs it
returns. It tests FILTER, and step 2 above copies INFO without FILTER, so on the merged VCF it
would test the genotyper's FILTER instead.
Not written under --human. There the subset of interest is the human MEI one, and
hervk_reconcile writes GraffiTE.merged.genotypes.human.vcf.gz instead.
What happened to each record¶
genotyping_audit writes 4_Genotyping/genotyping_record_audit.tsv, one row per ALT allele of
pangenome.vcf, with a lost_at column naming the first stage that dropped it and the counts
summarized at the top of the file.
lost_at |
meaning |
|---|---|
genotyped |
in the merged VCF under its own ID, with its annotation |
not_in_graph |
the allele never entered the graph; see PanGenie |
duplicate_of_record_N |
it shared CHROM, POS, REF and ALT with record N, which carries the call |
no_match_in_merge |
the graph genotyped it, and the annotate step in merge_VCFs could not find it |
not_genotyped |
absent from the merged VCF |
genotyped and annotated are separate columns. On the
PanGenie path INFO/ID names the graph variant behind each record, so a record that was
genotyped and then missed by the annotate step is visible as genotyped=yes, annotated=no. The
vg back ends carry no such field, the audit joins on the ID column instead, and the report says
which key it used.
With --human, the human subset of the merged genotypes goes through one more step,
hervk_reconcile, which writes GraffiTE.merged.genotypes.human.vcf.gz.
Reading a genotype¶
| Record | GT |
The TE is |
|---|---|---|
SVTYPE=INS |
0/0 |
absent from this sample |
SVTYPE=INS |
0/1, 1/1 |
present on one or both haplotypes |
SVTYPE=DEL |
0/0 |
present (the reference carries it) |
SVTYPE=DEL |
0/1, 1/1 |
absent from one or both haplotypes |
FORMAT fields beyond GT are whatever vg call or PanGenie wrote; see
VCF fields.
Next¶
- Human MEIs: the HERV-K consolidation that follows genotyping under
--human - Epigenetic mapping: lifting base-modification calls onto the graph
- Resuming and skipping work:
--graph,--graph_alignments,--vcfs - Output files