Selection pressure between two genomes (dN/dS)
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.22. Desktop beta builds for Linux and
macOS are on the releases page;
the Windows build waits on code signing.
The ratio of non-synonymous to synonymous substitution rates, dN/dS, measures the selection pressure on a protein-coding gene between two species. We:
- build a human against rhesus macaque ortholog table with jcvi, and measure dN
and dS on every pair with
orthologs2jbrowse kaks - load both genomes and genes, and the table as a synteny track
- color each ortholog link by the ratio
- read the lysozyme (LYZ) neighbourhood on human chromosome 12, with the conserved neighbour YEATS4 as the control
Prerequisites
- a JBrowse to open the files in: Desktop takes a local file by path, Web through Add track
- jcvi
- DIAMOND
- orthologs2jbrowse, and python3 with biopython
- htslib (
bgzip,tabix) - the NCBI datasets CLI
node, for the JBrowse CLI
jcvi compiles C extensions at install time, and the compile fails on some Python
versions. If pip install jcvi fails, uv venv --python 3.12 followed by
uv pip install jcvi biopython gives an interpreter it builds on.
# Debian/Ubuntu
sudo apt install tabix diamond-aligner nodejs python-is-python3
# or conda, which has every tool above
conda install -c bioconda -c conda-forge htslib diamond ncbi-datasets-cli \
nodejs python
# or Linux x86_64 binaries for the tools apt lacks
wget -P ~/.local/bin \
https://ftp.ncbi.nlm.nih.gov/pub/datasets/command-line/v2/linux-amd64/datasets \
https://ftp.ncbi.nlm.nih.gov/pub/datasets/command-line/v2/linux-amd64/dataformat
chmod +x ~/.local/bin/datasets ~/.local/bin/dataformat
# any platform
pip install jcvi biopython git+https://github.com/cmdcolin/orthologs2jbrowse
npm install -g @jbrowse/cli@nextThe data
Each genome is an NCBI RefSeq assembly, and the script fetches its GFF3, CDS
FASTA and sequence report together with datasets download genome accession.
You don't need these files to follow the session, which reads a hosted copy. The track configs name local files that the build script writes, so run it first (it needs about 3 GB of memory), or follow the same steps on a GFF3 and a CDS FASTA per genome of your own.
| What it is | File |
|---|---|
| Human, GRCh38.p14 | GCF_000001405.40 |
| Rhesus macaque, T2T-MMU8v2.0 | GCF_049350105.2 |
Synonymous and non-synonymous rates
A coding substitution is synonymous (the codon changes, the amino acid does not) or non-synonymous.
- dS is the synonymous rate. Selection acts weakly on synonymous changes, so dS approximates the mutation rate.
- dN is the non-synonymous rate, which reflects the selection acting on those changes.
- dN/dS below 1 indicates purifying selection, where most genes sit, and a ratio above 1 needs positive selection to explain.
Producing the human-rhesus ortholog table and its rates
dS has to be large enough to estimate and small enough not to saturate. Rhesus macaque sits in that window against human.1
Calling human-rhesus orthologs with jcvi
jcvi takes a BED and a proteome per genome under one set of ids. The BED comes from the GFF3, one transcript per gene on the assembled chromosomes, and the adapter reads the same file. jcvi writes one from any GFF3:
# --primary_only keeps one mRNA per gene; --key=ID names it by its GFF3 ID,
# which every GFF3 has and which gffread -x names its CDS by, so the BED, the
# proteome and the CDS share ids
python -m jcvi.formats.gff bed --type=mRNA --key=ID \
--primary_only genes.gff3 -o genes.bedThe end-to-end script does the same for each NCBI
download in Python, keeping each protein-coding gene's longest-CDS mRNA under
its RefSeq accession, renaming each chromosome to the sequence report's name,
and translating each CDS into human.pep and rhesus.pep under the same ids.
DIAMOND aligns human against rhesus, and jcvi chains the hits:
diamond makedb --in rhesus.pep -d rhesus.pep
diamond blastp --threads 14 --query human.pep --db rhesus.pep \
--out human.rhesus.last --max-target-seqs 20 --evalue 1e-10 --outfmt 6
python -m jcvi.compara.catalog ortholog --no_strip_names --dbtype prot \
--align_soft diamond_blastp --no_dotplot human rhesusTwo input mistakes leave jcvi with no orthologs:
- the alignment file has to be query = the first species, subject = the
second. Reversed, jcvi looks up every id in the wrong BED and the run ends
with
A total of 0 anchor was found - NCBI's CDS FASTA is keyed on the protein accession (
XP_,NP_) and the BED on the transcript (XM_,NM_), so nothing matches until the two are joined. A CDS row in the GFF3 has both, and the script joins on it
Measuring dN and dS on each pair
The pair list is the two gene columns of human.rhesus.anchors. The script
skips human.rhesus.lifted.anchors, where jcvi adds extra pairs recruited near
an established syntenic block. Their median dS is several times that of the
chained pairs, which marks them as paralogs.
# skip the ### lines that separate blocks
awk '!/^#/ && NF >= 2 {print $1 "\t" $2}' human.rhesus.anchors > pairs.tsv
# one CDS file for both genomes, whose RefSeq accessions are distinct
cat human.cds.fa rhesus.cds.fa > both.cds.faorthologs2jbrowse kaks pairs.tsv both.cds.fa \
--key record --min-syn-subs 3 --max-ds 0.3 -o primate.blocks
gzip -kf primate.blocks human.bed rhesus.bedorthologs2jbrowse kaks aligns
each pair as protein, back-translates to codons so that nothing shifts frame,
and runs Nei-Gojobori.
Filtering paralogs and low-count pairs
True orthologs share one divergence time, so their dS values cluster. A pair
well above the cluster is a paralog the aligner preferred, and --max-ds drops
every pair whose dS exceeds its value.
The top of a table sorted by dN/dS is the pairs with almost nothing to divide
by: COX20 sorts there because it has a single synonymous difference.
--min-syn-subs is a floor on that count, and drops every pair with fewer
synonymous differences than its value.
Every row also has that count and a two-sided Fisher exact p, the test
MEGA
prescribes for small substitution counts. The track config below lists both in
attributeColumns, so clicking a link shows the evidence behind its color.
Loading the human and rhesus genomes and genes
A gene-level synteny view needs only sequence names and lengths, so each
assembly is a .chrom.sizes file (a name and a length per line) that the script
writes from the sequence report. We load human here and rhesus the same way
under the name rhesus:
Goes in the assemblies array of config.json. See Assemblies.
{ "name": "human", "uri": "human.chrom.sizes" }Edits config.json in the current folder, creating it if there is none. See JBrowse CLI with Desktop.
jbrowse add-assembly human.chrom.sizes \
--name human \
--load copyIn JBrowse Desktop, Open your own genome on the start screen (or File → Open genome... in a session), then Open from a URL and paste:
human.chrom.sizesJBrowse reads the format off the file name. Then fill in:
- Genome name:
human
human.chrom.sizes is relative to a config.json. Replace it with its URL or its path on this computer.
The view draws each panel's genes from a track on that panel's assembly. The
script writes human.genes.gff3.gz and rhesus.genes.gff3.gz, bgzipped and
CSI-indexed (prep). For your own annotation the GFF3
needs the same refNames as the assembly:
Goes in the tracks array of config.json. See Tracks.
{
"type": "FeatureTrack",
"trackId": "human_genes",
"name": "human genes",
"assemblyNames": ["human"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "human.genes.gff3.gz",
"csi": true
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "FeatureTrack",
"trackId": "human_genes",
"name": "human genes",
"assemblyNames": ["human"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "human.genes.gff3.gz",
"csi": true
}
}'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": "human_genes",
"name": "human genes",
"assemblyNames": ["human"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "human.genes.gff3.gz",
"csi": true
}
}human.genes.gff3.gz is relative to a config.json. Replace it with its URL or its path on this computer.
Add the rhesus track the same way, with rhesus_genes under rhesus.
Loading the ortholog table as a synteny track
primate.blocks lists each pair's two gene ids, then dN, dS, the synonymous
substitution count and the Fisher p, the .blocks format
MCScanBlocksAdapter reads.
attributeColumns names the columns after the two gene columns, and the detail
panel lists each as a feature attribute:
Goes in the tracks array of config.json. See Tracks.
{
"type": "SyntenyTrack",
"trackId": "primate_orthologs",
"name": "Human / rhesus orthologs (dN/dS)",
"assemblyNames": ["human", "rhesus"],
"adapter": {
"type": "MCScanBlocksAdapter",
"uri": "primate.blocks.gz",
"blockAssemblies": ["human", "rhesus"],
"bedLocations": ["human.bed.gz", "rhesus.bed.gz"],
"attributeColumns": ["dn", "ds", "syn_subs", "fisher_p"]
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "SyntenyTrack",
"trackId": "primate_orthologs",
"name": "Human / rhesus orthologs (dN/dS)",
"assemblyNames": ["human", "rhesus"],
"adapter": {
"type": "MCScanBlocksAdapter",
"uri": "primate.blocks.gz",
"blockAssemblies": ["human", "rhesus"],
"bedLocations": ["human.bed.gz", "rhesus.bed.gz"],
"attributeColumns": ["dn", "ds", "syn_subs", "fisher_p"]
}
}'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": "SyntenyTrack",
"trackId": "primate_orthologs",
"name": "Human / rhesus orthologs (dN/dS)",
"assemblyNames": ["human", "rhesus"],
"adapter": {
"type": "MCScanBlocksAdapter",
"uri": "primate.blocks.gz",
"blockAssemblies": ["human", "rhesus"],
"bedLocations": ["human.bed.gz", "rhesus.bed.gz"],
"attributeColumns": ["dn", "ds", "syn_subs", "fisher_p"]
}
}primate.blocks.gz, human.bed.gz, rhesus.bed.gz are relative to a config.json. Replace each with its URL or its path on this computer.
That shows it in the linear view. For the synteny view, open Add → Linear synteny view, pick the track under Quick start, and click Launch.
Color by value → dN/dS in the palette button menu sets the view's
encoding.color, a color scale that reads dn and ds, on a ramp with 1 at
the middle and 2 at the top.
Two view settings matter for a view this sparse:
- Opacity on the sliders button in the view header sets
encoding.opacity, which starts low for whole-genome views where ribbons overlap, and at 0.95 the color shows unfaded. - Curved lines on the same menu sets
mark: { interpolate: 'bump' }, which separates stacked neighbours.
Reading lysozyme (LYZ) against its neighbours by dN/dS
The session below opens, from the hosted copy, the stretch around lysozyme (LYZ) on human chromosome 12 where gene order matches rhesus, colored by dN/dS. The build script's default session is the same view.
Goes at the top level of config.json, replacing any defaultSession there. See Default session.
{
"defaultSession": {
"name": "Selection pressure across a primate gene neighbourhood",
"views": [
{
"type": "LinearSyntenyView",
"views": [
{
"assembly": "human",
"loc": "12:67,835,000-70,835,000",
"tracks": ["human_genes"]
},
{
"assembly": "rhesus",
"loc": "11:74,978,000-77,959,000",
"tracks": ["rhesus_genes"]
}
],
"tracks": [["primate_orthologs"]],
"encoding": { "color": "dnds", "opacity": 0.95 },
"mark": { "interpolate": "bump" }
}
]
}
}Replaces any defaultSession in config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse set-default-session --session - << 'EOF'
{
"name": "Selection pressure across a primate gene neighbourhood",
"views": [
{
"type": "LinearSyntenyView",
"views": [
{
"assembly": "human",
"loc": "12:67,835,000-70,835,000",
"tracks": ["human_genes"]
},
{
"assembly": "rhesus",
"loc": "11:74,978,000-77,959,000",
"tracks": ["rhesus_genes"]
}
],
"tracks": [["primate_orthologs"]],
"encoding": { "color": "dnds", "opacity": 0.95 },
"mark": { "interpolate": "bump" }
}
]
}
EOFOpen this session in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fdemos%2Fprimate_selection%2Fconfig.json&session=json-%7B%22session%22%3A%7B%22name%22%3A%22Selection+pressure+across+a+primate+gene+neighbourhood%22%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearSyntenyView%22%2C%22views%22%3A%5B%7B%22assembly%22%3A%22human%22%2C%22loc%22%3A%2212%3A67%2C835%2C000-70%2C835%2C000%22%2C%22tracks%22%3A%5B%22human_genes%22%5D%7D%2C%7B%22assembly%22%3A%22rhesus%22%2C%22loc%22%3A%2211%3A74%2C978%2C000-77%2C959%2C000%22%2C%22tracks%22%3A%5B%22rhesus_genes%22%5D%7D%5D%2C%22tracks%22%3A%5B%5B%22primate_orthologs%22%5D%5D%2C%22encoding%22%3A%7B%22color%22%3A%22dnds%22%2C%22opacity%22%3A0.95%7D%2C%22mark%22%3A%7B%22interpolate%22%3A%22bump%22%7D%7D%5D%7D%7D&sessionName=JBrowse+docs+exampleGene order is the same in both genomes here, so color is the only thing that varies. Click the orange LYZ ribbon for its synonymous count and Fisher p in the detail panel; Messier and Stewart (1997) reported adaptive evolution of primate lysozyme.
YEATS4 begins just past where LYZ ends, so the two share a locus and a divergence time, and its blue ribbon is the control. Click it for the same fields at the other end of the ramp.
Reproduce it end to end
build_primate_selection.sh
runs everything above and writes a config.json with both assemblies, both gene
tracks, the ortholog track and a session opening the locus:
- Download each genome's annotation from NCBI, and turn it into a BED, a CDS file and a proteome keyed on one transcript per gene.
- Align human against rhesus with DIAMOND and chain the hits with jcvi, keeping the chained anchors and not the lifted ones.
- Measure dN and dS on each pair, dropping pairs with too few synonymous differences or a dS far above the cluster.
- Print the count of pairs genome-wide with dN/dS above 1, and dN/dS and dS for every pair around LYZ, and write the config.
curl -fO https://raw.githubusercontent.com/GMOD/jbrowse-components/main/scripts/build_primate_selection.sh
bash build_primate_selection.sh
npx --yes serve primate_selection_build/jbrowse2 # then open the printed URLSee also
- Tutorial: Synteny visualization (a polyploid against itself)
- Tutorial: Synteny from an ortholog table (grape, peach, cacao)
- Tutorial: Synteny from MCScan anchors (grape, peach)
Citations
- Nei and Gojobori (1986). Simple methods for estimating the numbers of synonymous and nonsynonymous nucleotide substitutions
- Messier and Stewart (1997). Episodic adaptive evolution of primate lysozymes
- Tang et al. (2024). jcvi: A versatile toolkit for comparative genomics analysis
Notes
-
Against chimpanzee, dS is near zero for most genes. ↩
Feedback on this tutorial is welcome: contact us.