# open an example dataset (HapMap)
genofile <- snpgdsOpen(snpgdsExampleFileName())
# autosomal SNPs
selsnp <- snpgdsSelectSNP(genofile, autosome.only=TRUE, remove.monosnp=FALSE)
# sample ID
sample.id <- read.gdsn(index.gdsn(genofile, "sample.id"))
father.id <- read.gdsn(index.gdsn(genofile, "sample.annot/father.id"))
offspring.id <- sample.id[father.id != ""]
father.id <- father.id[father.id != ""]
# calculate average genotype scores
z1 <- snpgdsPairScore(genofile, offspring.id, father.id, snp.id=selsnp,
method="IBS", type="per.pair")
names(z1)
z1$score
# calculate average genotype scores
z2 <- snpgdsPairScore(genofile, offspring.id, father.id, snp.id=selsnp,
method="IBS", type="per.snp")
names(z2)
mean(z2$score["Avg",])
mean(z2$score["SD",])
plot(z2$score["Avg",], pch=20, cex=0.75, xlab="SNP Index", ylab="IBS score")
# calculate a matrix of genotype scores over samples and SNPs
z3 <- snpgdsPairScore(genofile, offspring.id, father.id, snp.id=selsnp,
method="IBS", type="matrix")
dim(z3$score)
# output the score matrix to a GDS file
snpgdsPairScore(genofile, offspring.id, father.id, snp.id=selsnp,
method="IBS", type="gds.file", output="tmp.gds")
(f <- snpgdsOpen("tmp.gds"))
snpgdsClose(f)
# close the file
snpgdsClose(genofile)
unlink("tmp.gds", force=TRUE)
Run the code above in your browser using DataLab