Nanopore - Variant Calling

Overview

Teaching: 15 min
Exercises: 15 min
Questions
  • How can I use nanopore data for variant calling?

Objectives
  • Align reads from long-read data.

  • Perform variant calling using nanopore data.

Sequence alignment

Tools for generating alignments

Alignment with dorado and minimap2 on REANNZ

Check that we’ve got a reference genome:

ls genome
GCF_000006945.2_ASM694v2_genomic.fna

What does the genome look like (spolier alert: kind of boring…):

head genome/GCF_000006945.2_ASM694v2_genomic.fna
>NC_003197.2 Salmonella enterica subsp. enterica serovar Typhimurium str. LT2, complete genome
AGAGATTACGTCTGGTTGCAAGAGATCATGACAGGGGGAATTGGTTGAAAATAAATATATCGCCAGCAGCACATGAACAA
GTTTCGGAATGTGATCAATTTAAAAATTTATTGACTTAGGCGGGCAGATACTTTAACCAATATAGGAATACAAGACAGAC
AAATAAAAATGACAGAGTACACAACATCCATGAACCGCATCAGCACCACCACCATTACCACCATCACCATTACCACAGGT
AACGGTGCGGGCTGACGCGTACAGGAAACACAGAAAAAAGCCCGCACCTGAACAGTGCGGGCTTTTTTTTCGACCAGAGA
TCACGAGGTAACAACCATGCGAGTGTTGAAGTTCGGCGGTACATCAGTGGCAAATGCAGAACGTTTTCTGCGTGTTGCCG
ATATTCTGGAAAGCAATGCCAGGCAAGGGCAGGTAGCGACCGTACTTTCCGCCCCCGCGAAAATTACCAACCATCTGGTG
GCAATGATTGAAAAAACTATCGGCGGCCAGGATGCTTTGCCGAATATCAGCGATGCAGAACGTATTTTTTCTGACCTGCT
CGCAGGACTTGCCAGCGCGCAGCCGGGATTCCCGCTTGCACGGTTGAAAATGGTTGTCGAACAAGAATTCGCTCAGATCA
AACATGTTCTGCATGGTATCAGCCTGCTGGGTCAGTGCCCGGATAGCATCAACGCCGCGCTGATTTGCCGTGGCGAAAAA

Load the SAMtools module:

module load SAMtools

Load the Dorado module:

module load dorado

Make a folder for our aligned data:

mkdir bam-aligned

Reminder: our unaligned .bam files are located at:

bam-unaligned/NO_MISSV2_P2I/P2I_96/20260413_1636_P2I-00014-B_PBK98658_853a956f/bam_pass/

We still have our $FOLDER variable from earlier:

echo $FOLDER
bam-unaligned/NO_MISSV2_P2I/P2I_96/20260413_1636_P2I-00014-B_PBK98658_853a956f/bam_pass/
tree $FOLDER
bam-unaligned/NO_MISSV2_P2I/P2I_96/20260413_1636_P2I-00014-B_PBK98658_853a956f/bam_pass/
├── barcode01
│   ├── PBK98658_pass_barcode01_853a956f_57f83f46_0.bam
│   └── PBK98658_pass_barcode01_853a956f_57f83f46_0.bam.bai
├── barcode02
│   ├── PBK98658_pass_barcode02_853a956f_57f83f46_0.bam
│   └── PBK98658_pass_barcode02_853a956f_57f83f46_0.bam.bai
├── barcode03
│   ├── PBK98658_pass_barcode03_853a956f_57f83f46_0.bam
│   └── PBK98658_pass_barcode03_853a956f_57f83f46_0.bam.bai
.
.
.
└── unclassified
    ├── PBK98658_pass_unclassified_853a956f_57f83f46_0.bam
    └── PBK98658_pass_unclassified_853a956f_57f83f46_0.bam.bai

The first three barcodes relate to Salmonella isolates. Let’s copy those to a separate folder to make them a little easier to find. By using the barcode* pattern, we can select just the files whose barcodes were reliably detected (i.e., not the “unclassified” reads).

mkdir salmonella-bamfiles

cp $FOLDER/barcode01/*.bam salmonella-bamfiles/ 
cp $FOLDER/barcode02/*.bam salmonella-bamfiles/ 
cp $FOLDER/barcode03/*.bam salmonella-bamfiles/ 

ls -1 salmonella-bamfiles/
PBK98658_pass_barcode01_853a956f_57f83f46_0.bam
PBK98658_pass_barcode02_853a956f_57f83f46_0.bam
PBK98658_pass_barcode03_853a956f_57f83f46_0.bam

We can use dorado again to align the reads to our reference genome (note, this can also be done as part of the basecalling process, but that means you’re performing alignemnt prior to having done any QC checking).

dorado uses the minimap2 aligner (another software tool from ONT). The syntax for performing alignemnt on basecalled data is (-t 4 specifies four threads: faster):

dorado aligner -t 4 \
  genome/GCF_000006945.2_ASM694v2_genomic.fna \
  salmonella-bamfiles/ | \
  samtools sort -o bam-aligned/salmonella-aligned-sort.bam 

Index the bam file:

samtools index bam-aligned/salmonella-aligned-sort.bam 

Generate basic mapping information using samtools:

samtools coverage bam-aligned/salmonella-aligned-sort.bam 
#rname       startpos      endpos  numreads   covbases  coverage  meandepth    meanbaseq    meanmapq
NC_003197.2         1     4857450     19698    4661869   95.9736    8.08004         19.4        57.3
NC_003277.2         1       93933       110      16030   17.0654    1.31684         19.5        50.4

Variant calling

NB - code below is taken from the “Variant Calling Workflow” section of the Genomic Data Carpentry course:

https://datacarpentry.org/wrangling-genomics/04-variant_calling/index.html

Load the BCFtools module:

module load BCFtools

Make a folder for the output data:

mkdir bcf-files

Generate a “pileup” file to enable variant calling (might take a little bit of time):

bcftools mpileup --threads 4 \
   -B -Q5 --max-BQ 30 -I \
   -o bcf-files/salmonella-pass.bcf \
   -f genome/GCF_000006945.2_ASM694v2_genomic.fna  \
   bam-aligned/salmonella-aligned-sort.bam

Make a folder to hold vcf (variant call format) files:

mkdir vcf-files

Use bcftools to call variants in the salmonella data:

bcftools call --ploidy 1 -m -v \
   -o vcf-files/salmonella-variants.vcf \
   bcf-files/salmonella-pass.bcf 

Use vcfutils.pl to filter the variants (in this case, everything gets kept):

vcfutils.pl varFilter vcf-files/salmonella-variants.vcf  > vcf-files/salmonella-final-variants.vcf
head -40 vcf-files/salmonella-final-variants.vcf
##fileformat=VCFv4.2
##FILTER=<ID=PASS,Description="All filters passed">
##bcftoolsVersion=1.22+htslib-1.22
##bcftoolsCommand=mpileup --threads 4 -B -Q5 --max-BQ 30 -I -o bcf-files/salmonella-pass.bcf -f genome/GCF_000006945.2_ASM694v2_genomic.fna bam-aligned/salmonella-aligned-sort.bam
##reference=file://genome/GCF_000006945.2_ASM694v2_genomic.fna
##contig=<ID=NC_003197.2,length=4857450>
##contig=<ID=NC_003277.2,length=93933>
##ALT=<ID=*,Description="Represents allele(s) other than observed.">
##INFO=<ID=INDEL,Number=0,Type=Flag,Description="Indicates that the variant is an INDEL.">
##INFO=<ID=IDV,Number=1,Type=Integer,Description="Maximum number of raw reads supporting an indel">
##INFO=<ID=IMF,Number=1,Type=Float,Description="Maximum fraction of raw reads supporting an indel">
##INFO=<ID=DP,Number=1,Type=Integer,Description="Raw read depth">
##INFO=<ID=VDB,Number=1,Type=Float,Description="Variant Distance Bias for filtering splice-site artefacts in RNA-seq data (bigger is better)",Version="3">
##INFO=<ID=RPBZ,Number=1,Type=Float,Description="Mann-Whitney U-z test of Read Position Bias (closer to 0 is better)">
##INFO=<ID=MQBZ,Number=1,Type=Float,Description="Mann-Whitney U-z test of Mapping Quality Bias (closer to 0 is better)">
##INFO=<ID=BQBZ,Number=1,Type=Float,Description="Mann-Whitney U-z test of Base Quality Bias (closer to 0 is better)">
##INFO=<ID=MQSBZ,Number=1,Type=Float,Description="Mann-Whitney U-z test of Mapping Quality vs Strand Bias (closer to 0 is better)">
##INFO=<ID=SCBZ,Number=1,Type=Float,Description="Mann-Whitney U-z test of Soft-Clip Length Bias (closer to 0 is better)">
##INFO=<ID=SGB,Number=1,Type=Float,Description="Segregation based metric, http://samtools.github.io/bcftools/rd-SegBias.pdf">
##INFO=<ID=MQ0F,Number=1,Type=Float,Description="Fraction of MQ0 reads (smaller is better)">
##FORMAT=<ID=PL,Number=G,Type=Integer,Description="List of Phred-scaled genotype likelihoods">
##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allelic depths (high-quality bases)">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##INFO=<ID=AC,Number=A,Type=Integer,Description="Allele count in genotypes for each ALT allele, in the same order as listed">
##INFO=<ID=AN,Number=1,Type=Integer,Description="Total number of alleles in called genotypes">
##INFO=<ID=DP4,Number=4,Type=Integer,Description="Number of high-quality ref-forward , ref-reverse, alt-forward and alt-reverse bases">
##INFO=<ID=MQ,Number=1,Type=Integer,Description="Average mapping quality">
##bcftools_callVersion=1.22+htslib-1.22
##bcftools_callCommand=call --ploidy 1 -m -v -o vcf-files/salmonella-variants.vcf bcf-files/salmonella-pass.bcf; Date=Wed Nov 18 14:53:45 2026
#CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  barcode01       barcode02       barcode03
NC_003197.2     18      .       G       T       28.1818 .       DP=3;VDB=0.0221621;SGB=-0.281359;MQSBZ=0;MQ0F=0;AC=2;AN=2;DP4=0,0,1,2;MQ=60   GT:PL:AD        1:22,0:0,1      .:0,0:0,0       1:34,0:0,2
NC_003197.2     43      .       G       A       3.4791  .       DP=5;VDB=0.02;SGB=0.366792;RPBZ=-0.816497;MQBZ=0;MQSBZ=0;BQBZ=0;SCBZ=-0.645497;MQ0F=0;AC=1;AN=3;DP4=1,2,1,1;MQ=60     GT:PL:AD        0:0,29:1,0      1:37,0:0,2      0:0,26:2,0
NC_003197.2     81      .       G       A       50.8935 .       DP=6;VDB=0.00766117;SGB=-0.374956;RPBZ=-0.5;MQBZ=0;MQSBZ=0;BQBZ=0.92582;SCBZ=0;MQ0F=0;AC=2;AN=3;DP4=1,1,1,3;MQ=60     GT:PL:AD        1:28,0:0,1      0:0,37:2,0      1:59,0:0,3
NC_003197.2     483     .       A       G       111.176 .       DP=8;VDB=0.0231369;SGB=-1.39713;MQSBZ=0;MQ0F=0;AC=3;AN=3;DP4=0,0,3,4;MQ=60    GT:PL:AD        1:47,0:0,2      1:29,0:0,2      1:63,0:0,3
NC_003197.2     507     .       C       T       66.0691 .       DP=7;VDB=0.178985;SGB=0.123302;RPBZ=1.0146;MQBZ=0;MQSBZ=0;BQBZ=1.1619;SCBZ=0.977008;MQ0F=0;AC=2;AN=3;DP4=0,2,2,3;MQ=60        GT:PL:AD        1:45,0:0,2      0:0,23:2,0      1:57,0:0,3
NC_003197.2     537     .       A       C       59.1756 .       DP=8;VDB=0.105075;SGB=-1.28032;MQSBZ=0;MQ0F=0;AC=3;AN=3;DP4=0,0,3,3;MQ=60     GT:PL:AD        1:37,0:0,2      1:44,0:0,3      1:6,0:0,1
NC_003197.2     649     .       C       T       120.176 .       DP=8;VDB=0.128485;SGB=-1.45883;MQSBZ=0;MQ0F=0;AC=3;AN=3;DP4=0,0,3,5;MQ=60     GT:PL:AD        1:38,0:0,2      1:72,0:0,3      1:38,0:0,3
NC_003197.2     684     .       T       C       36.8834 .       DP=8;VDB=0.0433485;SGB=1.07566;RPBZ=-0.458258;MQBZ=0;MQSBZ=0;BQBZ=0;SCBZ=-0.150878;MQ0F=0;AC=1;AN=3;DP4=2,3,1,2;MQ=60 GT:PL:AD        0:0,40:2,0      1:73,0:0,3      0:0,72:3,0
NC_003197.2     796     .       T       C       36.9004 .       DP=7;VDB=0.0506481;SGB=1.07566;RPBZ=0.178377;MQBZ=0;MQSBZ=0;BQBZ=1.60539;SCBZ=-0.178377;MQ0F=0;AC=1;AN=3;DP4=1,3,1,2;MQ=60    GT:PL:AD        0:0,21:1,0      1:73,0:0,3      0:0,48:3,0
NC_003197.2     810     .       C       T       9.71231 .       DP=6;VDB=0.18;SGB=0.346553;RPBZ=0;MQBZ=0;MQSBZ=0;BQBZ=1.85164;SCBZ=0.234834;MQ0F=0;AC=1;AN=3;DP4=1,3,1,1;MQ=60        GT:PL:AD        0:0,8:1,0       1:45,0:0,2      0:0,29:3,0

How many variants are there?

bcftools view -H -Ov vcf-files/salmonella-final-variants.vcf | wc -l
50899

Key Points

  • Long-read based algorithms (e.g., the minimap2 aligner used by dorado) need to be used when aligning long read data.

  • Post-alignment, standard software tools (e.g., samtools, bcftools, etc) can be used to perform variant calling.