Learn R Programming

miraculix (version 0.9.23)

Random Haplotype Values: Generation of Random Haplotype Matrix

Description

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

Usage

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

Run this code
# NOT RUN {
 
# }
# NOT RUN {
<!-- %    library(miraculix) -->
# }
# NOT RUN {
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)
}
# }

Run the code above in your browser using DataLab