LD across an inversion (mosquitoes)
The tutorials target the JBrowse v5 beta, and the v4.3.0 release
on the download page lacks some of what they show. To install the
beta of JBrowse Web, run npm install -g @jbrowse/cli@next, then
jbrowse create jbrowse2 --branch v5.0.0-beta.21. Desktop beta builds for Linux and
macOS are on the releases page;
the Windows build waits on code signing.
The 2La chromosomal inversion of the malaria mosquito Anopheles gambiae spans about 22 Mb and suppresses crossing over between the inverted and standard arrangements, so linkage disequilibrium (LD, the correlation between variants) runs across it as one block in a population where both arrangements segregate. An inversion's LD block covers most of a chromosome arm, so the variants are thinned to a grid before PLINK writes every pair. On arm 2L in Cameroon and Gabon, we:
- load a thinned PLINK r² table for each population as an LD track
- load the inversion as one structural-variant record, genotyped per mosquito, and facet the rows by karyotype from a sample sheet
- open the whole arm with each population's LD track over its karyotype rows
Prerequisites
- a JBrowse to paste the tracks into (Web or Desktop)
- PLINK 2.0 (
plink2) - htslib (
bgzip,tabix) curlpython3node, for the JBrowse CLI
# Debian/Ubuntu
sudo apt install tabix nodejs
# or conda, which has every tool above
conda install -c bioconda -c conda-forge htslib nodejs plink2
# any platform
npm install -g @jbrowse/cli@nextThe data
Ag1000G phase 2 AR1 (Anopheles gambiae 1000 Genomes Consortium 2020).
You don't need these files to follow the page: the track configs below read the hosted results. The build script fetches them to rebuild those results. The PLINK steps take your own VCF in place of the Ag1000G slice.
| What it is | File |
|---|---|
| The phased haplotypes and their sample list for chromosome arm 2L, which the commands subset to one population at a time | shapeit/ |
The sample metadata the population lists come from, CMgam (Cameroon) and GAgam (Gabon) |
samples.meta.txt |
| The 2La tag SNPs, the ~200 positions whose allele marks which arrangement a chromosome has, which each mosquito's karyotype is scored from (Love et al. 2019) | 2La_targets.txt |
Loading the anoGam3 assembly and genes
The Ag1000G calls are on the AgamP4 reference, whose arms 2L, 2R, 3L, 3R and X have the same sequence as UCSC's anoGam3 (AgamP3), so the tracks go on anoGam3. The anoGam3 page on genomes.jbrowse.org opens that assembly with its Ensembl gene track, ready for the tracks below. On another JBrowse, load the hub's assembly:
{
"name": "anoGam3",
"displayName": "A. gambiae (anoGam3)",
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "anoGam3-refseq",
"adapter": {
"type": "TwoBitAdapter",
"uri": "https://hgdownload.soe.ucsc.edu/goldenPath/anoGam3/bigZips/anoGam3.2bit",
"chromSizes": "https://jbrowse.org/ucsc/anoGam3/anoGam3.chrom.sizes"
}
},
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"uri": "https://jbrowse.org/ucsc/anoGam3/anoGam3.chromAlias.txt"
}
},
"circularRefNames": ["chrM"],
"geneticCodes": { "chrM": 5 }
}The LD table and the inversion calls name the arm 2L, and the alias table maps
that to anoGam3's chr2L. The gene track is the hub's too:
Goes in the tracks array of config.json. See Tracks.
{
"type": "FeatureTrack",
"trackId": "anoGam3-ensGene",
"name": "Ensembl Genes",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "Gff3TabixAdapter",
"gffGzLocation": {
"uri": "https://jbrowse.org/ucsc/anoGam3/ensGene.gff.gz"
},
"index": {
"indexType": "CSI",
"location": {
"uri": "https://jbrowse.org/ucsc/anoGam3/ensGene.gff.gz.csi"
}
}
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "FeatureTrack",
"trackId": "anoGam3-ensGene",
"name": "Ensembl Genes",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "Gff3TabixAdapter",
"gffGzLocation": {
"uri": "https://jbrowse.org/ucsc/anoGam3/ensGene.gff.gz"
},
"index": {
"indexType": "CSI",
"location": {
"uri": "https://jbrowse.org/ucsc/anoGam3/ensGene.gff.gz.csi"
}
}
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "FeatureTrack",
"trackId": "anoGam3-ensGene",
"name": "Ensembl Genes",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "Gff3TabixAdapter",
"gffGzLocation": {
"uri": "https://jbrowse.org/ucsc/anoGam3/ensGene.gff.gz"
},
"index": {
"indexType": "CSI",
"location": {
"uri": "https://jbrowse.org/ucsc/anoGam3/ensGene.gff.gz.csi"
}
}
}
}Precomputing 2L LD with PLINK
JBrowse draws LD from a precomputed table: PLINK correlates the variants and
PlinkLDTabixAdapter reads its output.
PLINK reads a binary fileset, so we first convert the common variants' phased
VCF with --double-id, which sets each family id to the sample id:
plink2 --vcf common.vcf --double-id --allow-extra-chr --make-bed --out commonThen we thin, correlate and index. keep.CMgam.txt lists the Cameroon samples
in two tab-separated columns of the same sample id, the family/individual pair
plink asks for.
# the display uploads n(n-1)/2 cells, and ~800 SNPs across an arm already
# reach screen resolution, so keep roughly one variant per 50 kb
plink2 --bfile common --allow-extra-chr --keep keep.CMgam.txt --maf 0.2 \
--chr 2L --write-snplist --out sel
awk -F'_' -v g=50000 '{p=$2+0; if (p >= nxt) {print $0; nxt = p + g}}' \
sel.snplist > grid.snplist
# --r2-phased estimates r2 from haplotype frequencies, the statistic the
# display draws
# dprimeabs adds D' as a magnitude, the form the display reads
# --ld-window-r2 0 keeps the uncorrelated pairs
# PLINK 1.9 spells the pair `--r2 dprime`, with the columns at the same offsets
plink2 --bfile common --allow-extra-chr --keep keep.CMgam.txt \
--extract grid.snplist \
--r2-phased cols=chrom,pos,id,dprimeabs \
--ld-window 999999 --ld-window-kb 1000000 --ld-window-r2 0 \
--out ag1000g_2L_CMgam
# plink2 writes tabs and a commented header, which `tabix -H` returns
# sort-bed runs `sort -k1,1 -k2,2n` under LC_ALL=C and keeps the `#` line on
# top; this table sorts on the same first two columns
jbrowse sort-bed < ag1000g_2L_CMgam.vcor |
bgzip > ag1000g_2L_CMgam.vcor.gz
tabix -C -s 1 -b 2 -e 2 -f ag1000g_2L_CMgam.vcor.gzThe track over that file is an LDTrack. In
grammar-of-graphics terms, its
encoding.color is a color scale, and encoding.color.field picks r² or D',
the two metric columns, as its input:
Goes in the tracks array of config.json. See Tracks.
{
"type": "LDTrack",
"trackId": "ag1000g_2l_cmgam",
"name": "Cameroon, both arrangements segregating (r²)",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "PlinkLDTabixAdapter",
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2L_CMgam.vcor.gz",
"csi": true
},
"displays": [
{
"type": "LDTrackDisplay",
"encoding": { "color": "r2" },
"variantLayout": "genomic",
"legend": { "show": true },
"height": 340
}
]
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "LDTrack",
"trackId": "ag1000g_2l_cmgam",
"name": "Cameroon, both arrangements segregating (r²)",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "PlinkLDTabixAdapter",
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2L_CMgam.vcor.gz",
"csi": true
},
"displays": [
{
"type": "LDTrackDisplay",
"encoding": { "color": "r2" },
"variantLayout": "genomic",
"legend": { "show": true },
"height": 340
}
]
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "LDTrack",
"trackId": "ag1000g_2l_cmgam",
"name": "Cameroon, both arrangements segregating (r²)",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "PlinkLDTabixAdapter",
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2L_CMgam.vcor.gz",
"csi": true
},
"displays": [
{
"type": "LDTrackDisplay",
"encoding": { "color": "r2" },
"variantLayout": "genomic",
"legend": { "show": true },
"height": 340
}
]
}The inversion genotyped per mosquito
The 2La inversion also loads as one <INV> record, genotyped across every
mosquito, that spans the breakpoints. The
variant display at genomic positions
draws each genotype at the call's true span. END is the far breakpoint and
each sample column holds one GT:
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT AN0007-C AN0009-C
2L 20524058 2La N <INV> . PASS SVTYPE=INV;END=42165532 GT 0/0 0/1The samples TSV has a name column matching the VCF sample ids and a
karyotype column naming each mosquito's pair of arrangements: 2L+a/2L+a,
2La/2L+a, 2La/2La, the + marking the non-inverted arrangement.
Load each population as a VariantTrack whose adapter includes the samples TSV,
with a LinearVariantDisplay:
Goes in the tracks array of config.json. See Tracks.
{
"type": "VariantTrack",
"trackId": "ag1000g_2la_karyotype_cmgam",
"name": "Cameroon, one row per mosquito",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "VcfTabixAdapter",
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2La_CMgam.vcf.gz",
"csi": true,
"samplesTsvLocation": {
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2La_CMgam_samples.tsv"
}
},
"displays": [
{
"type": "LinearVariantDisplay",
"facet": {
"field": "karyotype",
"sort": ["2L+a/2L+a", "2La/2L+a", "2La/2La"]
},
"rows": { "color": "karyotype" }
}
]
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "VariantTrack",
"trackId": "ag1000g_2la_karyotype_cmgam",
"name": "Cameroon, one row per mosquito",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "VcfTabixAdapter",
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2La_CMgam.vcf.gz",
"csi": true,
"samplesTsvLocation": {
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2La_CMgam_samples.tsv"
}
},
"displays": [
{
"type": "LinearVariantDisplay",
"facet": {
"field": "karyotype",
"sort": ["2L+a/2L+a", "2La/2L+a", "2La/2La"]
},
"rows": { "color": "karyotype" }
}
]
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "VariantTrack",
"trackId": "ag1000g_2la_karyotype_cmgam",
"name": "Cameroon, one row per mosquito",
"assemblyNames": ["anoGam3"],
"adapter": {
"type": "VcfTabixAdapter",
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2La_CMgam.vcf.gz",
"csi": true,
"samplesTsvLocation": {
"uri": "https://jbrowse.org/demos/popgen/ag1000g_2La_CMgam_samples.tsv"
}
},
"displays": [
{
"type": "LinearVariantDisplay",
"facet": {
"field": "karyotype",
"sort": ["2L+a/2L+a", "2La/2L+a", "2La/2La"]
},
"rows": { "color": "karyotype" }
}
]
}facet splits the display into
one section per karyotype value, facet.sort orders them by dosage, and
rows.color is a color scale on each row's label bar. With
genotypes.reference.show
off, the default, the track fills with the reference color and alt cells are
painted on top.
The display draws a row for every sample in the file and divides the track
height among them, so each population goes in a separate track. Gabon's two
tracks are the same configs with CMgam replaced by GAgam in the trackIds and
file names:
https://jbrowse.org/demos/popgen/ag1000g_2L_GAgam.vcor.gzhttps://jbrowse.org/demos/popgen/ag1000g_2La_GAgam.vcf.gzhttps://jbrowse.org/demos/popgen/ag1000g_2La_GAgam_samples.tsv
Scoring each mosquito's 2La karyotype from tag SNPs
The build script writes the <INV> call at the published 2La extent
(Sharakhov et al. 2006,
White et al. 2007) and scores each
mosquito's karyotype as its mean alternate-allele count across the tag SNPs,
rounded to a genotype, as MalariaGEN does for its Ag3 release. The score is
trimodal, which the reproduce script checks.
Comparing the 2La LD block with karyotypes in Cameroon and Gabon
Open chr2L with the r² track of each population over the karyotype track of
the same population.
The block's edges line up with the published breakpoint coordinates.
- A second block, at the low-coordinate end of the arm in both populations, is Vgsc, a sodium channel gene whose codon-995 substitutions confer pyrethroid insecticide resistance (Clarkson et al. 2021).
- Gabon is near-fixed for the standard arrangement, so 2La is rare enough that
the variants tagging it fall below the
--mafcutoff.
Reproduce it end to end
build_ag1000g_ld.sh
uses the published 2La span only as a test window, and prints the evidence for
each choice it makes from there:
- Each panel is one population, since correlation pooled across populations shows linkage that is absent within each one. The script prints, per population, mean D' between variants more than 5 Mb apart inside the test window and outside it, because only a population with both arrangements can show the block.
- It keeps common variants, thins them to a grid, and writes each panel's r² and D' table.
- It bins D' to distant partners along the whole arm. The steps up and down are the inversion's breakpoints, recovered from the data alone.
- It scores each mosquito's karyotype from the tag SNPs, prints the score
histogram, which has to come out with three peaks, and writes the
<INV>calls and aconfig.jsonopening on the inversion.
curl -fO https://raw.githubusercontent.com/GMOD/jbrowse-components/main/scripts/build_ag1000g_ld.sh
bash build_ag1000g_ld.sh # writes ./ag1000g_ld_build/jbrowse2
npx --yes serve ag1000g_ld_build/jbrowse2See also
- Tutorial: LD at a selective sweep (human)
- Tutorial: Selection scans (Drosophila DGRP)
- User guide: Variant sample rows
- User guide: Variant track
- Config guide: Variant track
- Config guide: Grouping and lane order
Citations
- Anopheles gambiae 1000 Genomes Consortium (2020). Genome variation and population structure among 1142 mosquitoes of the African malaria vector species Anopheles gambiae and Anopheles coluzzii
- Clarkson et al. (2021). The genetic architecture of target-site resistance to pyrethroid insecticides in the African malaria vectors Anopheles gambiae and Anopheles coluzzii
- Love et al. (2019). In silico karyotyping of chromosomally polymorphic malaria mosquitoes in the Anopheles gambiae complex
- Sharakhov et al. (2006). Breakpoint structure reveals the unique origin of an interspecific chromosomal inversion (2La) in the Anopheles gambiae complex
- White et al. (2007). Molecular karyotyping of the 2La inversion in Anopheles gambiae
Feedback on this tutorial is welcome: contact us.