Learn R Programming

AlphaSimR (version 0.11.1)

writePlink: Writes a Pop-class as PLINK files

Description

Writes a Pop-class as PLINK PED and MAP files

Usage

writePlink(
  pop,
  baseName,
  trait = 1L,
  snpChip = 1L,
  simParam = NULL,
  chromLength = 10L^8
)

Arguments

pop

an object of Pop-class

baseName

a character. Basename of PED and MAP files.

trait

an integer. Which phenotype trait should be used.

snpChip

an integer. Which SNP array should be used.

simParam

an object of SimParam

chromLength

an integer. The size of chromosomes in base pairs; assuming all chromosomes are of the same size.

Examples

Run this code
# NOT RUN {
#Create founder haplotypes
founderPop = quickHaplo(nInd=10, nChr=1, segSites=10)

#Set simulation parameters
SP = SimParam$new(founderPop)
SP$setGender(gender = "yes_rand")
SP$addTraitA(nQtlPerChr = 10)
SP$addSnpChip(nSnpPerChr = 5)

#Create population
pop = newPop(rawPop = founderPop)
pop = setPheno(pop, varE = SP$varA)
writePlink(pop, baseName="test")

#Test
test = read.table(file = "test.ped")
#...gender
if (!identical(x = c("M", "F")[test[[5]]], y = pop@gender)) { stop() }
#...pheno (issues with rounding)
# if (!identical(x = test[[6]], y = pop@pheno[, 1])) { stop() }
#...genotypes
x = test[, -(1:6)]  - 1
x[, 1] = x[, 1] + x[, 2]
x[, 2] = x[, 3] + x[, 4]
x[, 3] = x[, 5] + x[, 6]
x[, 4] = x[, 7] + x[, 8]
x[, 5] = x[, 9] + x[, 10]
y = pullSnpGeno(pop)
if (sum(x[, 1:5] - y) != 0) { stop() }
# }

Run the code above in your browser using DataLab