rhaplo: Generation of Random Haplotype Matrix

Description Usage Arguments Value See Also Examples

View source: R/rhaplo.R

Description

A random haplotype matrix is generated according to some given frequencies.

Usage

1
2
3
rhaplo(freq, indiv, loci, freq2, file,
       file.type = c("beagle", "plink", "plink2"),
       debugging = FALSE)

Arguments

freq

vector of probabilities which gives the allele frequencies for one or both haplotypes; if not given, a half is assumed and loci must be given.

indiv

number of individuals

loci

if not given, the number of loci equals the length of freq, otherwise freq is recycled to reach the given nnumber of loci

freq2

optional. Frequencies for the second chromosome. The vector freq2 may have a different length than freq if loci is given or freq2 is a scalar. The vector freq2 may contain NAs. Then, the value of the second chromosome at this locus is taken over from the first chromosome.

file, file.type

string. If given, a file is written that mimics the file.type style. An extension is appended to file according to the file.type style.

debugging

logical. Mainly for internal purposes. If TRUE the genomic matrix is appended as an attribute to the return value.

Value

If missing(file) an object of class genomicmatrix is returned, else the file name with appended extension according to file.type

See Also

A haplotype file can be read in by genomicmatrix.

as.matrix transforms a genomicmatrix to a human readable matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 

as.matrix(rhaplo(seq(0, 1, len=10), indiv=5))

## note that the next examples write a file on the current directory
file <- "miraculix"
if (interactive() && !file.exists(paste0(file, ".bgl"))) {
  f <- rhaplo(freq = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6),
              freq2 = c(0.6, 0.4, 0.5, 0.3, 0.0, 1.0),
              indiv=5, file=file, file.type="beagle",
              debugging = TRUE)
  print(f)
  print(as.genomicmatrix(f))
  print(g <- genomicmatrix(f))
  print(as.matrix(g))
 
  stopifnot(all(as.matrix(g) == attr(f, "M")))
  file.remove(f)
}

miraculix documentation built on Sept. 22, 2021, 5:07 p.m.

Related to rhaplo in miraculix...