Commit d9a26bc7 by Eric Coissac

Add documentation to functions

parent 381b48a1
......@@ -45,7 +45,20 @@ error_jc = function(rate) {
#' Generate substitution sequencing error.
#'
#' Simulate substitution sequencing error on a set of nucleotides following
#' substitution rates stored in an error matrix.
#'
#' @param nuc character; a vector of nucleotide to be modified according
#' to a error matrix.
#' @param error numeric 4 x 4 matrix; the error matrix as produced by the
#' \code{\link{error_jc}} function.
#'
#' @examples
#' sequencing_error(c("A","A","C","T","T","G"),
#' error_jc(0.2))
#'
#' @seealso \code{\link{error_jc}}
#' @author Eric Coissac
#' @export
sequencing_error = function(nuc,error) {
apply(error[nuc,],
......@@ -55,7 +68,33 @@ sequencing_error = function(nuc,error) {
prob = p))
}
#' Simulate the shotgun sequencing of a diploid loci.
#'
#' Build a contengency table of observed nucleotide for a given site
#' after its sequencing.
#'
#' @param haplotype.1 character; the first haplotype A, C, G or T of the locus.
#' @param haplotype.2 character; the second haplotype A, C, G or T of the locus.
#' @param coverage numeric; the average sequencing depth of the sequencing.
#' @param error numeric 4 x 4 matrix; the error matrix as produced by the
#' \code{\link{error_jc}} function
#'
#' @return a tibble with seven columns. \code{haplotype.1} and \code{haplotype.2} are both
#' the true happlotypes at the given locus. \code{haplotype.1} is by convention
#' always lexicographically smaller than \code{haplotype.2}.
#' \code{coverage} the actual sequencing
#' depth at that locus. It a random number drawn from a Poisson distribution
#' of mean \code{coverage}. \code{A}, \code{C}, \code{G}, \code{T}
#' the simulated observation of each nucleotide after the sequencing.
#'
#' @examples
#' simulate_sites(c("A","C","T"),
#' c("A","G","G"),
#' coverage=10,
#' error = error_jc(0.1))
#'
#' @seealso \code{\link{error_jc}}
#' @author Eric Coissac
#' @export
simulate_sites = function(haplotype.1,haplotype.2,coverage,error) {
n = length(haplotype.1)
......@@ -66,6 +105,8 @@ simulate_sites = function(haplotype.1,haplotype.2,coverage,error) {
MARGIN = 1,
sort)))
colnames(genotypes) = c("haplotype.1","haplotype.2")
cov = rpois(n,lambda = coverage)
obs1= vapply(cov,function(x) rbinom(1,x,0.5),0)
obs2 = cov - obs1
......
......@@ -6,6 +6,25 @@
\usage{
sequencing_error(nuc, error)
}
\arguments{
\item{nuc}{character; a vector of nucleotide to be modified according
to a error matrix.}
\item{error}{numeric 4 x 4 matrix; the error matrix as produced by the
\code{\link{error_jc}} function.}
}
\description{
Generate substitution sequencing error.
Simulate substitution sequencing error on a set of nucleotides following
substitution rates stored in an error matrix.
}
\examples{
sequencing_error(c("A","A","C","T","T","G"),
error_jc(0.2))
}
\seealso{
\code{\link{error_jc}}
}
\author{
Eric Coissac
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate.R
\name{simulate_sites}
\alias{simulate_sites}
\title{Simulate the shotgun sequencing of a diploid loci.}
\usage{
simulate_sites(haplotype.1, haplotype.2, coverage, error)
}
\arguments{
\item{haplotype.1}{character; the first haplotype A, C, G or T of the locus.}
\item{haplotype.2}{character; the second haplotype A, C, G or T of the locus.}
\item{coverage}{numeric; the average sequencing depth of the sequencing.}
\item{error}{numeric 4 x 4 matrix; the error matrix as produced by the
\code{\link{error_jc}} function}
}
\value{
a tibble with seven columns. \code{haplotype.1} and \code{haplotype.2} are both
the true happlotypes at the given locus. \code{haplotype.1} is by convention
always lexicographically smaller than \code{haplotype.2}.
\code{coverage} the actual sequencing
depth at that locus. It a random number drawn from a Poisson distribution
of mean \code{coverage}. \code{A}, \code{C}, \code{G}, \code{T}
the simulated observation of each nucleotide after the sequencing.
}
\description{
Build a contengency table of observed nucleotide for a given site
after its sequencing.
}
\examples{
simulate_sites(c("A","C","T"),
c("A","G","G"),
coverage=10,
error = error_jc(0.1))
}
\seealso{
\code{\link{error_jc}}
}
\author{
Eric Coissac
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment