LDscan: Multi-Locus Linkage Disequilibrium

View source: R/haplotype.R

LDscanR Documentation

Multi-Locus Linkage Disequilibrium


LDscan computes a matrix of pairwise linkage disequilibrium (LD) coefficients (|r|) from a set of loci (which must be bi-allelic; if not, the results are not guaranteed to be meaningful). The genotypes must be phased.

LDmap plots a matrix of LD coefficients, optionally with the positions of the loci.


LDscan(x, ...)

## S3 method for class 'DNAbin'
LDscan(x, quiet = FALSE, what = c("r", "Dprime"), ...)
## S3 method for class 'loci'
LDscan(x, depth = NULL, quiet = FALSE,
        what = c("r", "Dprime"), ...)

LDmap(d, POS = NULL, breaks = NULL, col = NULL, border = NA,
      angle = 0, asp = 1, cex = 1, scale.legend = 0.8, ...)



an object of class "loci" with phased genotypes.


a vector of integers giving the the depth(s) (or lags) at which the r's are calculated. By default, all possible depths are considered.


a logical: should the progress of the operation be printed?


the quantity to be computed. Two choices are possible: "r" (the default) for the absolute value of the correlation between alleles and "Dprime" for the (scaled) coefficients.


a correlation matrix (can be an object of class "dist").


an optional vector of locus positions (e.g., from a VCF file; see examples).


a vector of break intervals to count the values in d; by default, ten equally-sized intervals are used.


an optional vector of colours; a scale from lightyellow to red is used by default.


the border of the rectangles: the default is to have no border (this is not the same than default in rect; see examples).


value (in degrees) to rotate the graphic.


the aspect ratio of the graphic; one by default so the elements are squares (not rectangles).


the scaling of the labels and text.


the scaling of the legend rectangles.


further arguments passed to methods (LDscan) or to plot.default (LDmap).


The LD coefficient r is well defined when the two loci have only two alleles. In other cases, LD is well defined (see LD) but the definition of r is not clear.

All levels of ploidy are accepted, but all loci should have the same ploidy level.

If depth is used, the r's are calculated only for the pairs of loci that are distant by these values in x, but necessarily on the chromosome. The returned list has names set with the values of depth.

The value returned is actually |r| (not r^2).


LDscan returns an object of class "dist" by default, or a list if depth is used.


Emmanuel Paradis

See Also

LD, read.vcf


d <- LDscan(woodmouse)
LDmap(d, seg.sites(woodmouse), seq(0, 1, .1))

## Not run: 
## Download the VCF file from Dryad:

## the VCF file should have this name:
fl <- "global.pop.GATK.SNP.hard.filters.V3.phased_all.pop.maf.05.recode.vcf.gz" <- VCFloci(fl)

## LD map from the first 100 loci:
x <- read.vcf(fl, to = 100) # read only 100 loci
res <- LDscan(x)
bks <- seq(0, 1, 0.2)
LDmap(res,$POS[1:100], bks, scale.legend = 3)

## check the chromosomes:

## LD map from 100 loci randomly distributed on the chromosome:
s <- ceiling(seq(1, 224253, length.out = 100))
xs <- read.vcf(fl, which.loci = s)
res2 <- LDscan(xs)
LDmap(res2,$POS[s], bks, scale.legend = 3)

## something simpler with 10 loci:
x10 <- x[, 1:10]
## the VCF file has no locus IDs, so we give some here:
names(x10) <- paste0("Loc", 1:10)
res10 <- LDscan(x10, quiet = TRUE)
LDmap(res10, angle = 45, border = NULL)

## End(Not run)

pegas documentation built on March 7, 2023, 7:21 p.m.