# open an example dataset (HapMap)
genofile <- snpgdsOpen(snpgdsExampleFileName())
# chromosome 15
snpset <- read.gdsn(index.gdsn(genofile, "snp.id"))[
read.gdsn(index.gdsn(genofile, "snp.chromosome")) == 15]
length(snpset)
# LD matrix without sliding window
ld.noslide <- snpgdsLDMat(genofile, snp.id=snpset, slide=-1, method="composite")
# plot
image(t(ld.noslide$LD^2), col=terrain.colors(16))
# LD matrix with a sliding window
ld.slide <- snpgdsLDMat(genofile, snp.id=snpset, method="composite")
# plot
image(t(ld.slide$LD^2), col=terrain.colors(16))
# close the genotype file
snpgdsClose(genofile)
Run the code above in your browser using DataLab