12 SNPs: linked and unlinked SNPs compared with full sequences
Status: tested (2026-11-23). Run with migrate-n 6.1.97 (full), 6.1.99 and
6.1.100 (snp-invariants: linked-N-total, linked-N-wide); the option needs 6.1.100 or 7.0.124,
the #*freq counts of vcf2mig.py --abbrevref need 6.1.101 or 7.0.125.
HPC regression passed with 7.0.125 and 6.1.102.
Many data sets today are SNPs: RADseq, SNP chips, or the variable sites picked out of genome data. This recipe shows how to write SNP data for Migrate, which datatype and options to use, and how close SNP estimates come to estimates from the full sequences of the same loci. Read 00-basics and 01-migration first; 09-mutation-models section 5 has a first SNP example.
Contents
- The data and the true values
- Three ways to write the same SNPs
- The letter on the sites line decides the datatype
- Base frequencies and invariant sites
- Results: full sequences, linked SNPs, unlinked SNPs
- Run time: what makes SNP runs slow
- Recommendations
1. The data and the true values
Three populations in a stepping stone, West <-> Middle <-> East, with no
direct migration between West and East. 100 unlinked loci of 1,000 sites,
8 sequences per population and locus, simulated with msprime under HKY
(kappa 4, base frequencies A 0.3, C 0.2, G 0.2, T 0.3;
scripts/simulate_snps.py, truth in data/truth.json):
| Parameter | True |
|---|---|
| Theta_West | 0.004 |
| Theta_Middle | 0.002 |
| Theta_East | 0.003 |
| M Middle->West | 250 |
| M West->Middle | 500 |
| M East->Middle | 500 |
| M Middle->East | 250 |
Theta x M is 1 for three routes and 0.75 for Middle->East. The 100 loci have 4,480 variable sites (14-123 per locus, mean 45).
2. Three ways to write the same SNPs
From the full sequences (data/full.txt, one (s1000) per locus) the script
writes three SNP data sets:
| File | Sites line | What it is |
|---|---|---|
data/linked.txt | (n27) (n46) (n14) ... | linked SNPs: the variable sites of each locus stay together, one locus per original locus |
data/unlinked1.txt | (n1) (n1) (n1) ... (100) | unlinked SNPs: one random variable site per locus |
data/unlinkedall.txt | (n1) (n1) (n1) ... (4,480) | every variable site as its own locus |
The first two are correct descriptions of the data: SNPs within a locus share one genealogy, SNPs from different loci are independent. The third treats SNPs of the same locus as if they had independent genealogies; this is what one gets when every SNP of a RADseq or genome data set is entered as its own locus without checking linkage.
For many unlinked SNPs the sites line can be written compactly: a count in square brackets cuts the following locus into that many loci,
3 4480 every SNP its own locus
[4480](n4480)
is the same as 4,480 times (n1). The number of loci on the first line is
the number after cutting (4480 here). Up to 6.1.97 and 7.0.121 it had to
match (with 1, 6.1.97 crashed); later releases count the loci on the sites
line and use that count. 10-loci-and-units section 6 has all the bracket
forms.
3. The letter on the sites line decides the datatype
The letter in front of the number of sites, (s1000), (n27), (n1), sets
the datatype of that locus: s sequence data, n SNP data. When all loci
have the same letter, it overrides datatype= in the parmfile. Two
consequences:
datatype=SNPin a parmfile does not mean SNP data: Migrate reads only the first letter,S, which is sequence data. The SNP datatype isdatatype=NucleotidePolymorphismData(first letterN). With an infile whose loci are written(n...), the infile wins and the run is a SNP run anyway; with plain numbers or(s...)it is a sequence run.- To analyse the same SNPs as sequence data, the infile itself must say so:
data/linked_s.txt,unlinked1_s.txtandunlinkedall_s.txtare the same data with(s...).
Older Migrate versions had a separate datatype for unlinked SNPs
(datatype=UnlinkedSNPData, u, every column of a plain site count treated
as its own locus). The (n1) loci and the [count] form above replace it;
infiles with (u1) stop with an error (from 6.1.99 and 7.0.123 with a
message that says to use (n1) loci).
4. Base frequencies and invariant sites
Base frequencies. With freqs-from-data=YES Migrate counts the bases of
every locus. For SNPs these counts come from the variable sites only, and for
a one-site locus from a single column, so they say little about the
frequencies of the sequence. The SNP runs here give the frequencies:
freqs-from-data=NO:0.3,0.2,0.2,0.3
(estimated once from all the data, or taken from a reference genome). One
linked-SNP run uses freqs-from-data=YES to show the difference.
Invariant sites. SNP data lack the invariant sites. Migrate’s SNP likelihood
(datatype N, (n...) loci) corrects for this by conditioning on every site
being variable, so Theta is per variable site and cannot be compared with
Theta from sequences (09-mutation-models section 5). If the number of sites
the SNPs were found in is known, give it with snp-invariants:
snp-invariants={1000}
snp-invariants={1000 980 1200}
One value per locus, the total number of sites with the SNPs; the last value
is used for all remaining loci. Migrate adds the missing invariant sites
(total minus SNPs) to every locus, split by the base frequencies, and drops
the conditioning, so the locus is analysed like a full sequence and Theta is
per site. The outfile reports how many sites were added
(“snp-invariants: on average 955 invariant sites per locus are added to the
SNPs”). A locus with more SNPs than its total stops the run with a message.
snp-invariants=NO (the default) is the plain SNP analysis.
For SNPs called from reads mapped to a reference, the total of a locus is the length of the reference contig (or of the RAD tag). Without a reference, the position of the last SNP is a lower bound.
From a VCF file. vcf2mig.py (in contribution/ of the Migrate
distribution) converts a VCF file into a Migrate infile and, with
--snpinvariants, writes the matching snp-invariants line into a separate
file. Each CHROM (contig, RAD tag) becomes one locus with its SNPs linked
(--linksnp chrom):
vcf2mig.py --vcf snps.vcf.gz --popmap samples.txt --linksnp chrom \
--snpinvariants snpinv.txt --out infile
samples.txt has two columns, sample name and population. Copy the line in
snpinv.txt into the parmfile (before end). Without a reference
vcf2mig.py takes the position of the last SNP of each locus as its total,
a lower bound that assumes the locus starts at position 1. For a VCF made
from the 30 first loci of this recipe (1,000 sites each) the totals came out
as 909-1,000 (mean 978). With the reference the totals are exact; use
--abbrevref, which writes the base counts of the invariant sites of every
locus into the infile itself (#*freq lines):
vcf2mig.py --vcf snps.vcf.gz --popmap samples.txt --linksnp chrom \
--abbrevref reference.fasta --out infile
Migrate (6.1.101, 7.0.125 or later) adds these invariant sites to the SNPs
without a snp-invariants line; the outfile says “#*freq base counts of
the infile: on average … invariant sites per locus are added to the
SNPs”. These counts come from the reference and take precedence over
snp-invariants. With --linksnp number the loci are windows of that many
sites instead of whole contigs, and the totals are the window lengths (the
last window of a contig ends at the contig end, or at its last SNP without
a reference). Unlinked single SNPs (no --linksnp) get no
snp-invariants line. vcf2mig.py --help lists all options.
Before 6.1.100 and 7.0.124 the total was given after the base frequencies,
freqs-from-data=NO:0.3,0.2,0.2,0.3 [1000]. That form is still read (one
value for all loci), but in older versions it did not work with heating: the
cold chain never accepted a new genealogy and the results describe the start
genealogy (run linked-N-total-old in section 5: all three Thetas about
0.0066, genealogy acceptance 0.02). Rerun such analyses with a current
version.
The runs (all HKY with kappa 4, custom-migration={**0 *** 0**},
heating=YES:1:POWER:5, 101 MPI ranks, one replicate per locus):
| Run | Data | Datatype | Base frequencies | Theta prior | M prior | long-inc |
|---|---|---|---|---|---|---|
| full | full sequences | sequence | from data | 0-0.02 | 0-2,000 | 100 |
| linked-N-total | linked SNPs | SNP + snp-invariants={1000} | given | 0-0.02 | 0-2,000 | 100 |
| linked-S | linked SNPs | sequence | given | 0-1 | 0-100 | 20 |
| linked-N | linked SNPs | SNP | given | 0-1 | 0-100 | 20 |
| linked-N-wide | linked SNPs | SNP | given | 0-1 | 0-1,000 | 20 |
| linked-N-data | linked SNPs | SNP | from data | 0-1 | 0-100 | 20 |
| unl1-S | one SNP per locus | sequence | given | 0-1 | 0-100 | 20 |
| unl1-N | one SNP per locus | SNP | given | 0-1 | 0-100 | 20 |
| unlall-S | every SNP a locus | sequence | given | 0-1 | 0-100 | 20 |
| unlall-N | every SNP a locus | SNP | given | 0-1 | 0-100 | 20 |
The runs with Theta per variable site have M priors of 0-100 (linked-N-wide
0-1,000) to keep the run time short (section 6). scripts/make_parmfiles.sh
writes all parmfiles.
5. Results: full sequences, linked SNPs, unlinked SNPs
scripts/summarize.py collects the outfiles into results/summary.md. The
table shows the Joint medians (00-basics explains why the Joint row and not
the All row is the multilocus estimate; the All rows here are again far off
for every run):
| Run | Theta_West | Theta_Middle | Theta_East | M Middle->West | M West->Middle | M East->Middle | M Middle->East |
|---|---|---|---|---|---|---|---|
| truth | 0.0040 | 0.0020 | 0.0030 | 250 | 500 | 500 | 250 |
| full | 0.0041 | 0.0019 | 0.0029 | 231 | 603 | 526 | 310 |
| linked-N-total | 0.0039 | 0.0018 | 0.0031 | 270 | 653 | 553 | 233 |
| linked-S | 0.114 | 0.038 | 0.090 | 10 | 43 | 37 | 10 |
| linked-N | 0.016 | 0.010 | 0.013 | 66 | 77 | 66 | 72 |
| linked-N-wide | 0.011 | 0.0050 | 0.0090 | 192 | 405 | 378 | 190 |
| linked-N-data | 0.016 | 0.010 | 0.012 | 60 | 89 | 75 | 88 |
| unl1-S | 0.23 | 0.16 | 0.16 | 4 | 53 | 55 | 22 |
| unl1-N | 0.088 | 0.22 | 0.050 | 46 | 54 | 70 | 33 |
| unlall-S | 0.16 | 0.14 | 0.13 | 11 | 58 | 49 | 15 |
| unlall-N | 0.083 | 0.13 | 0.076 | 32 | 50 | 59 | 15 |
Theta and M of runs on different scales cannot be compared directly, but in principle their product can: Theta x M = 4Nm of the receiving population does not depend on the mutation rate (01-migration section 9):
| Run | Middle->West | West->Middle | East->Middle | Middle->East |
|---|---|---|---|---|
| truth | 1 | 1 | 1 | 0.75 |
| full | 0.95 | 1.17 | 1.02 | 0.90 |
| linked-N-total | 1.06 | 1.19 | 1.01 | 0.73 |
| linked-S | 1.15 | 1.61 | 1.39 | 0.85 |
| linked-N | 1.08 | 0.80 | 0.68 | 0.93 |
| linked-N-wide | 2.11 | 2.02 | 1.89 | 1.71 |
| linked-N-data | 0.95 | 0.92 | 0.77 | 1.03 |
| unl1-S | 0.86 | 8.5 | 8.8 | 3.5 |
| unl1-N | 4.1 | 11.6 | 15.1 | 1.7 |
| unlall-S | 1.8 | 8.3 | 7.1 | 2.0 |
| unlall-N | 2.7 | 6.5 | 7.7 | 1.1 |
What the runs show:
- Linked SNPs plus the number of sites (linked-N-total) give the same
answer as the full sequences: every true value lies inside the 95%
intervals of both runs (
results/summary.md). Nothing is lost by keeping only the variable sites, as long as the number of sites is known. - Linked SNPs without the number of sites (linked-N, linked-N-wide, linked-N-data) give Theta per variable site, and its scale depends on the M prior. With M 0-100, Theta is about 4 times the per-site Theta and the M posteriors touch the upper prior bound; with M 0-1,000 (linked-N-wide), Theta drops to about 2.7 times the per-site value and M rises to near the per-site truth (190-405), while Theta x M doubles. The SNP likelihood conditions on every site being variable, which removes most of the information on the overall mutation scale: Theta and M can trade off, and the prior decides where the estimate lands. Only the ratios between the populations are stable (Theta West : Middle : East is 1 : 0.63 : 0.80 and 1 : 0.45 : 0.82 in the two runs, true 1 : 0.5 : 0.75). Theta from SNPs cannot be converted to per-site Theta with the fraction of variable sites (45 of 1,000 would give 22 times).
- Base frequencies from the SNPs (linked-N-data, counted from the variable sites only) changed little here; with stronger base-composition bias they would.
- SNPs analysed as sequences (linked-S) have no invariant sites and no correction for that: Theta is inflated 19-30 times and Theta x M is off by up to 60%. Do not run SNP data as datatype sequence.
- One SNP per locus (unl1) carries too little information: the genealogy acceptance is 0.80, that is, the data hardly constrain the genealogies, and Theta x M into Middle is 8-15 times too large.
- Every SNP as its own locus (unlall) uses all 4,480 SNPs but treats SNPs of the same locus as independent. The intervals are narrow and wrong: Theta x M into Middle is 6.5-8.3 times too large, and the Joint combination collapsed (reweighting ESS 1-2).
All Joint rows are flagged (Joint*, large genealogy-sampling error). The
reweighting ESS of the Joint combination is 45-94 for the linked runs, 11
for linked-N-wide and 1-6 for the unlinked runs; below 50 the outfile calls
the combination collapsed. Longer runs would help; for full and
linked-N-total the estimates were already close to the truth.
6. Run time: what makes SNP runs slow
Run times on 101 MPI ranks (backfill2), one replicate per locus:
| Run | Loci | Run time (min) | long-inc |
|---|---|---|---|
| full | 100 | 12 | 100 |
| linked-N-total | 100 | 7 | 100 |
| linked-S, linked-N, linked-N-data | 100 | 4-5 | 20 |
| linked-N-wide | 100 | 14 | 20 |
| unl1-S, unl1-N | 100 | 7-8 | 20 |
| unlall-S, unlall-N | 4,480 | 73 | 20 |
Three things set the run time:
- Loci. Every locus runs its own chain, so the cost grows with the number of loci. 4,480 one-SNP loci take 15 times longer than 100 linked loci with the same SNPs and give worse answers. Group SNPs by locus.
- The prior range of M. Run time grows with M, because larger M means more migration events in every genealogy. linked-N took 4 minutes with the M prior 0-100 and 14 minutes with 0-1,000 (linked-N-wide, M posterior 190-405). The first SNP runs used the M prior of the full run, 0-2,000, and long-inc 100 instead of 20; they did not finish within the 4-hour limit.
- Sites. The likelihood is computed per site pattern, not per site: linked-N-total has the same chain length as full but takes 7 instead of 12 minutes, because the 955 added invariant sites form only 4 patterns.
7. Recommendations
- Keep the SNPs of a locus together in one locus (
(n27)etc.), and keep loci that are unlinked apart. Do not enter every SNP as its own locus. - Use the SNP datatype: write
(n...)on the sites line, ordatatype=NucleotidePolymorphismData.datatype=SNPis sequence data. - If the number of sites of each locus is known (reference contig length,
RAD tag length), give it with
snp-invariants={...}(vcf2mig.py --snpinvariantswrites the line;--abbrevrefputs the counts into the infile). Theta is then per site and comparable with sequence data and with mutation rates per site. - Without the number of sites, Theta and M are on an unknown scale and depend on the priors (section 5). Report the ratios between populations, and compare two M priors before trusting anything else.
- Give the base frequencies (
freqs-from-data=NO:...) from all data or a reference genome. - Check that the posterior of M does not touch the upper prior bound; a wider prior costs run time (section 6).
- Use the Joint row for multilocus estimates and check its reweighting ESS.