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

  1. The data and the true values
  2. Three ways to write the same SNPs
  3. The letter on the sites line decides the datatype
  4. Base frequencies and invariant sites
  5. Results: full sequences, linked SNPs, unlinked SNPs
  6. Run time: what makes SNP runs slow
  7. 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):

ParameterTrue
Theta_West0.004
Theta_Middle0.002
Theta_East0.003
M Middle->West250
M West->Middle500
M East->Middle500
M Middle->East250

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:

FileSites lineWhat 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=SNP in a parmfile does not mean SNP data: Migrate reads only the first letter, S, which is sequence data. The SNP datatype is datatype=NucleotidePolymorphismData (first letter N). 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.txt and unlinkedall_s.txt are 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):

RunDataDatatypeBase frequenciesTheta priorM priorlong-inc
fullfull sequencessequencefrom data0-0.020-2,000100
linked-N-totallinked SNPsSNP + snp-invariants={1000}given0-0.020-2,000100
linked-Slinked SNPssequencegiven0-10-10020
linked-Nlinked SNPsSNPgiven0-10-10020
linked-N-widelinked SNPsSNPgiven0-10-1,00020
linked-N-datalinked SNPsSNPfrom data0-10-10020
unl1-Sone SNP per locussequencegiven0-10-10020
unl1-None SNP per locusSNPgiven0-10-10020
unlall-Severy SNP a locussequencegiven0-10-10020
unlall-Nevery SNP a locusSNPgiven0-10-10020

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):

RunTheta_WestTheta_MiddleTheta_EastM Middle->WestM West->MiddleM East->MiddleM Middle->East
truth0.00400.00200.0030250500500250
full0.00410.00190.0029231603526310
linked-N-total0.00390.00180.0031270653553233
linked-S0.1140.0380.09010433710
linked-N0.0160.0100.01366776672
linked-N-wide0.0110.00500.0090192405378190
linked-N-data0.0160.0100.01260897588
unl1-S0.230.160.164535522
unl1-N0.0880.220.05046547033
unlall-S0.160.140.1311584915
unlall-N0.0830.130.07632505915

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):

RunMiddle->WestWest->MiddleEast->MiddleMiddle->East
truth1110.75
full0.951.171.020.90
linked-N-total1.061.191.010.73
linked-S1.151.611.390.85
linked-N1.080.800.680.93
linked-N-wide2.112.021.891.71
linked-N-data0.950.920.771.03
unl1-S0.868.58.83.5
unl1-N4.111.615.11.7
unlall-S1.88.37.12.0
unlall-N2.76.57.71.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:

RunLociRun time (min)long-inc
full10012100
linked-N-total1007100
linked-S, linked-N, linked-N-data1004-520
linked-N-wide1001420
unl1-S, unl1-N1007-820
unlall-S, unlall-N4,4807320

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, or datatype=NucleotidePolymorphismData. datatype=SNP is 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 --snpinvariants writes the line; --abbrevref puts 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.

Available Materials