Skip to content

Variation graph construction for regenotyping

Elina Wilson edited this page Oct 13, 2026 · 1 revision

Last update: October 2026. Run on vg v1.76.1 - Chomper.


The Working with a whole genome variation graph tutorial will work in most cases. However, if you want to genotype the original VCF using the variation graph (aka 'regenotype'), you must construct the graph differently.

In this tutorial, we will construct a graph from GRCh37 and the 1000G phase 3 release using vg construct and manually create the indexes needed by vg map. While the vg giraffe mapper is highly recommended for the majority of use cases, vg map is used here because it requires less indexes and does not require the original input VCF to be phased.

Three files are required:

Let's begin by downloading the source files and unzipping the reference:

# get the reference
wget ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz
# and the 1000G VCF
wget ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.wgs.phase3_shapeit2_mvncall_integrated_v5c.20130502.sites.vcf.gz
# and its index
wget ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.wgs.phase3_shapeit2_mvncall_integrated_v5c.20130502.sites.vcf.gz.tbi
# and some reads
wget ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/HG00096/alignment/HG00096.chrom11.ILLUMINA.bwa.GBR.low_coverage.20120522.bam
# unpack the reference
gunzip hs37d5.fa.gz

Construction / indexing

Using vg map to create alignments requires a GCSA index and an XG index. We will first create a graph with vg construct, then index it. Building indexes for an entire large graph at once can take 30+ hours, so it is recommended to create individual graphs for each chromosome and and index them in parallel. For the purposes of this tutorial we will only regenotype chromosome 1, but parallelized instructions can be found here.

.vg Graph

ref=hs37d5.fa
vars=ALL.wgs.phase3_shapeit2_mvncall_integrated_v5c.20130502.sites.vcf.gz
vg construct -a -r "$ref" -v "$vars" -R 1 -C -t 4 > chr1.vg

This step takes a few minutes and 30GB of RAM, and generates an 600MB .vg pangenome graph.

.xg Index

An XG index is a "lightweight" version of the graph it indexes, storing information about a graph's structure (nodes, edges, paths) but not the sequences themselves. We can create one by using vg convert on our graph.

# create .xg index
vg convert -x chr1.vg > chr1.xg

This takes about 15 minutes, 25GB of RAM, and generates a 4GB .xg index.

.gcsa Index

A GCSA (generalized compressed suffix array index) is a graph that allows for quick lookup of sequences, and is used alongside an LCP array (.gcsa.lcp). However, we must prune the complex regions of the graph first.

vg prune -r chr1.vg > chr1.pruned.vg

This takes about 15 minutes, 15GB of RAM, and generates a 2GB .pruned.vg graph.

Now we can use vg gcsa to generate the GCSA and the LCP array at once.

vg index -g chr1.gcsa -f mapping chr1.pruned.vg

This takes about two hours, 40GB of RAM, and generates a 2GB .gcsa index plus its .gcsa.lcp array.

Alignment with vg map

With the index created, we can map reads against it. In this case we'll use paired-end mapping based off of an interleaved FASTQ file. An easy way to generate one is to use samtools sort -n on an existing SAM/BAM/CRAM file, and then stream it into an interleaved FASTQ format with samtools bam2fq.

Assuming we a 32-core machine, we can use this command line to run mapping:

# sort the BAM file by read name so we can use the pairs in mapping
samtools sort -@ 16 -n HG00096.chrom11.ILLUMINA.bwa.GBR.low_coverage.20120522.bam > aln.rnsrt.bam
# convert the alignments to interleaved fastq and map
samtools bam2fq aln.rnsrt.bam > aln.rnsrt.i.bam
vg map -t 32 -d chr1 -f aln.rnsrt.i.bam -i  > aln.gam

This step takes about 25 minutes and 10GB of RAM.

Regenotype original VCF

We can now do variant calling on the original VCF using vg call.

# compute the support
vg pack -x [chr1.xg](http://chr1.xg/) -g aln.gam -o chr1.pack

# call variants on the graph
vars=ALL.wgs.phase3_shapeit2_mvncall_integrated_v5c[.20130502.sites.vcf.gz](http://.20130502.sites.vcf.gz/)
vg call [chr1.xg](http://chr1.xg/) -k chr1.pack -s HG00096 -v "$vars" > chr1.vcf

This step takes about three hours and 40GB of RAM using a negligible amount of threads.

With the resulting VCF, we can now look at the precise genotypes supported by the reads. We can take a look at the some variants to confirm that they have a genotype by running the following:

# print the first ten variants with QUAL>0
bcftools query -i 'QUAL>0' -f '%CHROM\t%POS\t%REF\t%ALT\t%QUAL[\t%GT]\n' chr1.vcf | head -n 10

Finally, you can compare the locations of these variants to their locations in the original ungenotyped VCF to ensure they are unchanged:

# print the first ten variants of the original VCF
# note that there are no genotypes
vars=ALL.wgs.phase3_shapeit2_mvncall_integrated_v5c[.20130502.sites.vcf.gz](http://.20130502.sites.vcf.gz/)
bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%QUAL[\t%GT]\n' "$vars" | head -n 10

# print the first ten variants of the regenotyped VCF
bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%QUAL[\t%GT]\n' chr1.vcf | head -n 10

Clone this wiki locally