Ancestry-adjusted LD¶
In a structured or admixed sample, variants that differ in frequency between
populations are correlated even when they are far apart, so the standard LD
statistic, e.g. plink --r2, mixes LD with population structure. Pruning and
clumping on it then remove too many variants. The ancestry-adjusted LD removes
the structure first. See our
paper for more details.
The ancestry-adjusted LD is the correlation between the residuals of the
genotypes after removing the top principal components, which capture the
population structure. We first figure out the number of PCs (-k/--pc) that
capture population structure and run the PCA. In this example, assuming that 3
PCs can account for population structure:
Then pass its prefix to -P/--USV in any of the LD analyses below. PCAone
reads the genotypes again, removes the PCs in adj.eigvecs from them as they
are read, and computes the LD from the residuals, so no residual matrix is
written to disk. The PCs must come from the same samples in the same order, but
the variants need not be the ones the PCA used (e.g. a different --maf). This
works in-core and out-of-core (-m), for PLINK (-b) and PGEN (-p) input.
By default every PC in .eigvecs is removed; -k/--pc removes only the
leading ones, so one reference PCA run with e.g. -k 10 serves any smaller
number of PCs (-P adj -k 3). Use --ld-stats 1 without -P for the standard
LD instead. BGEN, BEAGLE and CSV input do not support LD.
Report LD statistics¶
-R/--print-r2 writes the R2 of every pair of SNPs within --ld-bp to
.ld.gz, in the long format of
plink --r2.
To plot LD decay curves from the .ld.gz files, e.g. standard (--ld-stats 1)
against ancestry-adjusted LD, use plot-ld-decay.R:
The nextflow workflow ld.nf runs the whole comparison. See the plotting guide for both.
Pruning¶
--ld-r2 prunes the variants as PLINK's --indep-pairwise does, but on the
ancestry-adjusted LD: of each pair of variants within --ld-bp whose R2 is
above the cutoff, the one with the lower MAF is removed. The kept and removed
variants are written to .ld.prune.in and .ld.prune.out, for --extract.
Clumping¶
--clump groups the variants of association results around their most
significant ones, as plink --clump does, on the ancestry-adjusted LD. It
reads one or more comma-separated association files; --clump-names gives
the columns of the chromosome, position and p-value (default CHR,BP,P).
Index variants have p below --clump-p1, and the variants within
--clump-bp of one, with p below --clump-p2 and R2 above --clump-r2, join
its clump. The clumps of the i-th file (from 0) are written to
<out>.p<i>.clump: its columns, plus SP2 with the variants in each clump.
./PCAone -b example/plink \
-P adj \
--clump example/plink.pheno0.assoc,example/plink.pheno1.assoc \
--clump-p1 0.01 \
--clump-p2 0.05 \
--clump-r2 0.1 \
--clump-bp 10000000 \
-o adj
Method details¶
Before v0.8.0, -D/--ld wrote a .residuals matrix G - U S V' and
-B/--binary read it back. PCAone now computes the residuals (I - Q Q') G
as the genotypes are read, from the .eigvecs alone. This section explains why
the two are the same thing, where they differ, and how the LD is computed.
The residuals are a projection¶
G is the N x M matrix of centred genotypes, one column per site. Missing calls
are imputed to the site mean, i.e. 0. U (N x k) holds the top k PCs, with
orthonormal columns: U'U = I.
Regress one site g on the PCs. The coefficients are b = (U'U)^-1 U' g = U' g,
and the residual is
Over all sites, R = (I - U U') G. This is what "ancestry adjusted" means: what
is left of each site once the PCs are regressed out.
Why it equals G - U S V'¶
Write the full SVD of G as the top k components plus the rest:
Multiply on the left by U':
so
Row by row, row j of V is S^-1 U' g_j. V never adds information:
it can always be recomputed from U and the genotypes. That is why the new path
needs only the .eigvecs, and neither .sigvals, .loadings nor .mbim.
Where the two can differ¶
- The SVD method. The identity needs
S V' = U' Gexactly. It holds for an exact truncated SVD, and for any method whose finalVis the projection ofGontoU: IRAM (V = G' U S^-1) and a Halko-style last step (the SVD ofB = Q'G). If an approximate method'sVdoes not satisfy it,G - U S V'keeps part of the PCs, while(I - U U') Gremoves them exactly, whatever producedU. The old--ldrecommended--svd 1for this reason. - Standardisation. A default PCA decomposes
G D, whereDis a diagonal matrix of per-site scalessqrt(ploidy) / sd. ThenU S V'approximatesG D, notG, andG - U S V'mixes two scales. This is why-D/--ldran its PCA unstandardised. The projection does not care:
The two differ only by a per-site scale, and a correlation ignores that. The
PCs themselves do change with standardisation. Add --scale 0 to the PCA to
get the PCs -D/--ld used, and hence the same R2.
- Centring. Every column of G sums to 0, so the PCs are orthogonal to the
intercept and the residuals stay centred. They are re-centred anyway, which
only removes rounding.
- Precision of .eigvecs. The file keeps 6 significant digits, so U'U = I
only to about 1e-6. PCAone uses Q from a QR decomposition of U. Q spans
the same PCs and Q Q' is an exact projector; for an exactly orthonormal U,
Q Q' = U U'.
- --emu. The old in-core path subtracted the PCs from the EM-imputed
genotypes. The new path uses mean imputation, as every other LD path does,
including the old out-of-core one.
How it is computed¶
LDColumns (src/LD.cpp) holds the residuals of the sites in memory: the whole
matrix in-core, or with -m the two consecutive blocks the current windows
need. Each column is scaled to unit norm once, so the correlation of two sites is
the dot product of their columns. A site with no variance (monomorphic, or fully
explained by the PCs) becomes a zero column, and its R2 is reported as 0.
The correlations of a batch of windows come from one matrix product,
C = X_rows' X_cols, rather than one dot product per pair. That reuses every
column while it is in cache.
- Pruning takes the next windows whose lead site is still kept. It
multiplies them against the kept sites of their span, then applies the greedy
rule (remove the lower-MAF site of each pair above
--ld-r2) in window order. This makes the same decisions as one window at a time. The batch grows while leads survive and shrinks while they are pruned away. -Rmultiplies consecutive windows over their span. It then formats and gzip-compresses the lines on all threads, one gzip member per thread. The.ld.gzis a series of members, whichzcat,gzip -d, R and Python read as one file.- Clumping reads its target sites and takes dot products.
In-core and -m go through the same code. A window must fit in two blocks of
-m; otherwise PCAone asks for a larger -m or a smaller --ld-bp.
Checks¶
- Old vs new, the same PCs. Both paths used the IRAM
.eigvecsofexample/plink.chr1(400 x 50,736). - R2 is equal to the printed precision (max difference 1e-6).
- Pruning at r2 0.2/0.8/0.99 and clumping are identical, in-core and
-m. - With
--ld-stats 1and with--maf 0.1, R2 is also equal to the printed precision. - Independent reference. numpy decodes the
.bed, centres it, and projects withQfromnumpy.linalg.qr. It matches PCAone to 5e-7. - PCs.
--scale 0reproduces the PCs of the old-D/--ldexactly. - Speed. On 4 threads and simulated data with N x M = 1e8 (N = 2,000 to
20,000, 1 Mb windows, up to 50M pairs), the new path reads 16x less data than
a
.residualsfile (2 bits against 4 bytes per genotype). The batched products make it faster still: - pruning is 1.4-3.4x faster in-core and 5-14x faster with
-m; -Ris 2.5-10x faster in-core and up to 38x faster with-m;- the output is bit-identical before and after.