R/RcppExports.R

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Round digits to specified decimal places
#' @param number A number to round
#' @param digits The number of digits to round to
roundDecimal <- function(number, digits) {
    .Call('_isoRelate_roundDecimal', PACKAGE = 'isoRelate', number, digits)
}

#' The emission probabilities for 2 haploid chromosomes
#' @param pop_allele_freq The population allele frequency for SNP i. This corresponds to the reference allele
#' @param genotype_1 The genotype for isolate 1 from the pair for SNP i
#' @param genotype_2 The genotype for isolate 2 from the pair for SNP i
#' @param ibd The IBD state
emissionProbHH <- function(pop_allele_freq, genotype_1, genotype_2, ibd) {
    .Call('_isoRelate_emissionProbHH', PACKAGE = 'isoRelate', pop_allele_freq, genotype_1, genotype_2, ibd)
}

#' The emission probabilities for 1 haploid chromosome and 1 diploid chromosome
#' @param pop_allele_freq The population allele frequency for SNP i. This corresponds to the reference allele
#' @param genotype_1 The genotype for isolate 1 from the pair for SNP i
#' @param genotype_2 The genotype for isolate 2 from the pair for SNP i
#' @param ibd The IBD state
#' @param male_column The haploid isolate from the pair. Either 1 or 2
#' @param female_column The diploid isolate from the pair. Either 1 or 2
emissionProbHD <- function(pop_allele_freq, genotype_1, genotype_2, ibd, male_column, female_column) {
    .Call('_isoRelate_emissionProbHD', PACKAGE = 'isoRelate', pop_allele_freq, genotype_1, genotype_2, ibd, male_column, female_column)
}

#' The emission probabilities for 2 diploid chromosomes
#' @param pop_allele_freq The population allele frequency for SNP i. This corresponds to the reference allele
#' @param genotype_1 The genotype for isolate 1 from the pair for SNP i
#' @param genotype_2 The genotype for isolate 2 from the pair for SNP i
#' @param ibd The IBD state
emissionProbDD <- function(pop_allele_freq, genotype_1, genotype_2, ibd) {
    .Call('_isoRelate_emissionProbDD', PACKAGE = 'isoRelate', pop_allele_freq, genotype_1, genotype_2, ibd)
}

#' The transition probabilities for 2 haploid chromosomes
#' @param omega_0 The probability of sharing 0 alleles IBD
#' @param meiosis The number of meiosis separating the two isoaltes
#' @param dist_cM The genetic map distance (cM) between SNP i and SNP j
#' @param ibd_current The IBD state of SNP j
#' @param ibd_previous The IBD state of SNP i
transitionProbHH <- function(omega_0, meiosis, dist_cM, ibd_current, ibd_previous) {
    .Call('_isoRelate_transitionProbHH', PACKAGE = 'isoRelate', omega_0, meiosis, dist_cM, ibd_current, ibd_previous)
}

#' The transition probabilities for 1 haploid and 1 diploid chromosome
#' @param omega_0 The probability of sharing 0 alleles IBD
#' @param meiosis The number of meiosis separating the two isoaltes
#' @param dist_cM The genetic map distance (cM) between SNP i and SNP j
#' @param ibd_current The IBD state of SNP j
#' @param ibd_previous The IBD state of SNP i
transitionProbHD <- function(omega_0, meiosis, dist_cM, ibd_current, ibd_previous) {
    .Call('_isoRelate_transitionProbHD', PACKAGE = 'isoRelate', omega_0, meiosis, dist_cM, ibd_current, ibd_previous)
}

#' The transition probabilities for 2 diploid chromosomes
#' @param omega_0 The probability of sharing 0 alleles IBD
#' @param omega_1 The probability of sharing 1 allele IBD
#' @param omega_2 The probability of sharing 2 alleles IBD
#' @param meiosis The number of meiosis separating the two isoaltes
#' @param dist_cM The genetic map distance (cM) between SNP i and SNP j
#' @param ibd_current The IBD state of SNP j
#' @param ibd_previous The IBD state of SNP i
transitionProbDD <- function(omega_0, omega_1, omega_2, meiosis, dist_cM, ibd_current, ibd_previous) {
    .Call('_isoRelate_transitionProbDD', PACKAGE = 'isoRelate', omega_0, omega_1, omega_2, meiosis, dist_cM, ibd_current, ibd_previous)
}

#' The genotyping error probability for 1 haploid chromosome
#' @param truth The true genotype
#' @param observed The observed genotype
#' @param error The genotype error rate
genotypeErrorH <- function(truth, observed, error) {
    .Call('_isoRelate_genotypeErrorH', PACKAGE = 'isoRelate', truth, observed, error)
}

#' The genotyping error probability for 1 diploid chromosome
#' @param truth The true genotype
#' @param observed The observed genotype
#' @param error The genotype error rate
genotypeErrorD <- function(truth, observed, error) {
    .Call('_isoRelate_genotypeErrorD', PACKAGE = 'isoRelate', truth, observed, error)
}

#' Matrices of all possible genotype combinations between pairs, given MOI
#' @param gender_1 The MOI estimate of isolate 1
#' @param gender_2 The MOI estimate of isolate 2
trueGenotypes <- function(gender_1, gender_2) {
    .Call('_isoRelate_trueGenotypes', PACKAGE = 'isoRelate', gender_1, gender_2)
}

#' Calculating the emission probability sumation when missing genotype calls present
#' @param pop_allele_freq The population allele frequency of SNP t
#' @param genotype_1 The genotype of isolate 1 at SNP t
#' @param genotype_2 The genotype of isolate 2 at SNP t
#' @param error The genotype error rate
#' @param gender_1 The MOI estimate of isolate 1
#' @param gender_2 The MOI estimate of isolate 2
#' @param ibd_j The IBD state
emissionProbMissingGeno <- function(pop_allele_freq, genotype_1, genotype_2, error, gender_1, gender_2, ibd_j) {
    .Call('_isoRelate_emissionProbMissingGeno', PACKAGE = 'isoRelate', pop_allele_freq, genotype_1, genotype_2, error, gender_1, gender_2, ibd_j)
}

#' Calculate alpha
#' @param number_states Integer. The number of IBD states in the model
#' @param initial_prob A numeric vector containing the initial state probabilities
#' @param meiosis Integer. The number of meiosis separating the two isolates
#' @param number_snps Integer. The number of SNPs
#' @param genotypes A integer martix containing the genotype calls for a pair of isolates
#' @param pop_allele_freqs A numeric vector of population allele frequencies
#' @param positions_cM A numeric vector of SNP genetic map positions in cM
#' @param error Numeric. The genotype error rate
#' @param gender_1 Integer. The MOI estimate of isolate 1
#' @param gender_2 Integer. The MOI estimate of isolate 2
calculateAlpha <- function(number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2) {
    .Call('_isoRelate_calculateAlpha', PACKAGE = 'isoRelate', number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2)
}

#' Calculate scale
#' @param number_states Integer. The number of IBD states in the model
#' @param initial_prob A numeric vector containing the initial state probabilities
#' @param meiosis Integer. The number of meiosis separating the two isolates
#' @param number_snps Integer. The number of SNPs
#' @param genotypes A integer martix containing the genotype calls for a pair of isolates
#' @param pop_allele_freqs A numeric vector of population allele frequencies
#' @param positions_cM A numeric vector of SNP genetic map positions in cM
#' @param error Numeric. The genotype error rate
#' @param gender_1 Integer. The MOI estimate of isolate 1
#' @param gender_2 Integer. The MOI estimate of isolate 2
calculateScale <- function(number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2) {
    .Call('_isoRelate_calculateScale', PACKAGE = 'isoRelate', number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2)
}

#' Calculate beta
#' @param number_states Integer. The number of IBD states in the model
#' @param initial_prob A numeric vector containing the initial state probabilities
#' @param meiosis Integer. The number of meiosis separating the two isolates
#' @param number_snps Integer. The number of SNPs
#' @param genotypes A integer martix containing the genotype calls for a pair of isolates
#' @param pop_allele_freqs A numeric vector of population allele frequencies
#' @param positions_cM A numeric vector of SNP genetic map positions in cM
#' @param scale A numeric vector containing the scaling values used to scale alpha
#' @param error Numeric. The genotype error rate
#' @param gender_1 Integer. The MOI estimate of isolate 1
#' @param gender_2 Integer. The MOI estimate of isolate 2
calculateBeta <- function(number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, scale, error, gender_1, gender_2) {
    .Call('_isoRelate_calculateBeta', PACKAGE = 'isoRelate', number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, scale, error, gender_1, gender_2)
}

#' Calculate the Viterbi sequence
#' @param number_states Integer. The number of IBD states in the model
#' @param initial_prob A numeric vector containing the initial state probabilities
#' @param meiosis Integer. The number of meiosis separating the two isolates
#' @param number_snps Integer. The number of SNPs
#' @param genotypes A integer martix containing the genotype calls for a pair of isolates
#' @param pop_allele_freqs A numeric vector of population allele frequencies
#' @param positions_cM A numeric vector of SNP genetic map positions in cM
#' @param error Numeric. The genotype error rate
#' @param gender_1 Integer. The MOI estimate of isolate 1
#' @param gender_2 Integer. The MOI estimate of isolate 2
calculateViterbi <- function(number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2) {
    .Call('_isoRelate_calculateViterbi', PACKAGE = 'isoRelate', number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2)
}

#' Calculate gamma
#' @param number_states Integer. The number of IBD states in the model
#' @param initial_prob A numeric vector containing the initial state probabilities
#' @param meiosis Integer. The number of meiosis separating the two isolates
#' @param number_snps Integer. The number of SNPs
#' @param genotypes A integer martix containing the genotype calls for a pair of isolates
#' @param pop_allele_freqs A numeric vector of population allele frequencies
#' @param positions_cM A numeric vector of SNP genetic map positions in cM
#' @param error Numeric. The genotype error rate
#' @param gender_1 Integer. The MOI estimate of isolate 1
#' @param gender_2 Integer. The MOI estimate of isolate 2
calculateGamma <- function(number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2) {
    .Call('_isoRelate_calculateGamma', PACKAGE = 'isoRelate', number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2)
}

#' Calculate the log-likelihood of the data
#' @param number_states Integer. The number of IBD states in the model
#' @param initial_prob A numeric vector containing the initial state probabilities
#' @param meiosis Integer. The number of meiosis separating the two isolates
#' @param number_snps Integer. The number of SNPs
#' @param genotypes A integer martix containing the genotype calls for a pair of isolates
#' @param pop_allele_freqs A numeric vector of population allele frequencies
#' @param positions_cM A numeric vector of SNP genetic map positions in cM
#' @param error Numeric. The genotype error rate
#' @param gender_1 Integer. The MOI estimate of isolate 1
#' @param gender_2 Integer. The MOI estimate of isolate 2
calculateLogLikelihood <- function(number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2) {
    .Call('_isoRelate_calculateLogLikelihood', PACKAGE = 'isoRelate', number_states, initial_prob, meiosis, number_snps, genotypes, pop_allele_freqs, positions_cM, error, gender_1, gender_2)
}

#' The vector b in the equation Ax=b for 2 haploid chromosomes
#' @param genotypes An integer matrix of genotype calls for a pair of isolates. Each coloumn represents and isolate and each row represents a SNP.
bVectorHH <- function(genotypes) {
    .Call('_isoRelate_bVectorHH', PACKAGE = 'isoRelate', genotypes)
}

#' The matrix A in the equation Ax=b for 2 haploid chromosomes
#' @param pop_allele_freqs A numeric vector of population allele frequencies for each SNP
#' @param genotypes An integer matrix of genotype calls for a pair of isolates. Each coloumn represents and isolate and each row represents a SNP.
AmatrixHH <- function(pop_allele_freqs, genotypes) {
    .Call('_isoRelate_AmatrixHH', PACKAGE = 'isoRelate', pop_allele_freqs, genotypes)
}

#' The vector b in the equation Ax=b for 1 haploid chromosome and 1 diploid chromosome
#' @param genotypes An integer matrix of genotype calls for a pair of isolates. Each coloumn represents and isolate and each row represents a SNP.
bVectorHD <- function(genotypes) {
    .Call('_isoRelate_bVectorHD', PACKAGE = 'isoRelate', genotypes)
}

#' The matrix A in the equation Ax=b for 1 haploid and 1 diploid chromosome
#' @param pop_allele_freqs A numeric vector of population allele frequencies for each SNP
#' @param genotypes An integer matrix of genotype calls for a pair of isolates. Each coloumn represents and isolate and each row represents a SNP.
AmatrixHD <- function(pop_allele_freqs, genotypes) {
    .Call('_isoRelate_AmatrixHD', PACKAGE = 'isoRelate', pop_allele_freqs, genotypes)
}

#' The vector b in the equation Ax=b for 2 diploid chromosomes
#' @param genotypes An integer matrix of genotype calls for a pair of isolates. Each coloumn represents and isolate and each row represents a SNP.
bVectorDD <- function(genotypes) {
    .Call('_isoRelate_bVectorDD', PACKAGE = 'isoRelate', genotypes)
}

#' The matrix A in the equation Ax=b for 2 diploid chromosomes
#' @param pop_allele_freqs A numeric vector of population allele frequencies for each SNP
#' @param genotypes An integer matrix of genotype calls for a pair of isolates. Each coloumn represents and isolate and each row represents a SNP.
AmatrixDD <- function(pop_allele_freqs, genotypes) {
    .Call('_isoRelate_AmatrixDD', PACKAGE = 'isoRelate', pop_allele_freqs, genotypes)
}

#' Binary Matrix of IBD
#' 
#' Creates a binary matrix of IBD (1) and non-IBD (0) with each row representing a single SNP
#' and each column representing a unique pair. The number of rows is equal to the total 
#' number of SNPs and the number of columns is equal to the number of pairs.
#' 
#' @param chromosomes A character vector containing the corresponding chromosome for each SNP
#' @param positions_bp A numeric vector containing the corresponding bp position for each SNP
#' @param number_pairs Numeric. The total number of pairs analysed
#' @param ibd_pairs_colnumbers A numeric vector corresponding to column numbers in the output matrix 
#' where each unique number refers to a unique pair with IBD inferred
#' @param ibd_chromosomes A character vector containing the chromosome for each detected IBD segment
#' @param ibd_start_bp A numeric vector containing the base-pair position for the start of each detected IBD segment
#' @param ibd_stop_bp A numeric vector containing the base-pair position for the end of each detected IBD segment
#' @export
IBDMatrix <- function(chromosomes, positions_bp, number_pairs, ibd_pairs_colnumbers, ibd_chromosomes, ibd_start_bp, ibd_stop_bp) {
    .Call('_isoRelate_IBDMatrix', PACKAGE = 'isoRelate', chromosomes, positions_bp, number_pairs, ibd_pairs_colnumbers, ibd_chromosomes, ibd_start_bp, ibd_stop_bp)
}

#' Calculate Allele Frequencies for SNPs from Genotype Data
#' 
#' \code{calculatePopAlleleFreq} calculates reference allele frequencies for each SNP given genotype data.
#' 
#' @param genotypes An integer matrix of genotype data of the form -1, 0, 1 and 2 representing missing genotypes, homozygous reference, 
#' heterozygous and homozygous alternative respectively. Each column of \code{genotypes} represents a unique isolate and each row of \code{genotypes}
#' represents a unique SNP.
#' @param moi An integer vector of multiplicity of infection (MOI) estimates for each isoalte. Isolate MOI estimates should be ordered such that value \code{n} of 
#' \code{moi} corresponds to column \code{n} of \code{genotypes}.
#' @export
calculatePopAlleleFreq <- function(genotypes, moi) {
    .Call('_isoRelate_calculatePopAlleleFreq', PACKAGE = 'isoRelate', genotypes, moi)
}

#' Calculate Missingness Proportions
#' 
#' Calculates the proportion of missing data for each SNPs or each isolate where missing values are denoted by -1. 
#' Missing values are calculated for each column of \code{genotypes} (where columns are isolates and rows are SNPs),
#' however \code{genotypes} can be transposed to calculate missingness proportions for SNPs.
#' 
#' @param genotypes An integer matrix of genotype data of the form -1, 0, 1 and 2 representing missing genotypes, homozygous reference, heterozygous and homozygous alternative respectively.
#' @return A vector of length \code{n} where \code{n} is the number of columns in \code{genotypes}. 
#' @export
calculateMissingness <- function(genotypes) {
    .Call('_isoRelate_calculateMissingness', PACKAGE = 'isoRelate', genotypes)
}

#' Group Combinations for Analysis
#' 
#' Creates a data frame containing family IDs and isolate IDs for each pair to be analysed. Each row
#' corresponds to a unique pair.
#' 
#' @param group A character vector of all family IDs
#' @export
groupPairs <- function(group) {
    .Call('_isoRelate_groupPairs', PACKAGE = 'isoRelate', group)
}

#' Pair Combinations for Analysis
#' 
#' Creates a data frame containing family IDs and isolate IDs for each pair to be analysed. Each row
#' corresponds to a unique pair.
#' 
#' @param fid A character vector of all family IDs
#' @param iid A character vector of all individual ID
#' @export
isolatePairs <- function(fid, iid) {
    .Call('_isoRelate_isolatePairs', PACKAGE = 'isoRelate', fid, iid)
}

#' Call Genotypes from Haplotype Data
#'
#' \code{haplotypeToGenotype} transforms PLINK haplotype data into genotype data of the form -1, 0, 1 and 2 representing missing genotypes,
#' homozygous reference, heterozygous and homozygous alternative respectively. Haploid isolates are coded as diploid although will not have
#' heterozygous genotypes.
#'
#' @param haplotypes An integer matrix of haplotype data in PLINK format. A allele is denoted 1, B allele is denoted 2 and missing data is denoted 0
#' @param moi An integer vector of multiplicity of infection (MOI) estimates for each isoalte. Isolate MOI estimates should be ordered such that value \code{n} of
#' \code{moi} corresponds to column \code{n} of \code{haplotypes}.
#' @return A matrix with genotype calls where columns correspond to isolates and rows correspond to SNPs
haplotypeToGenotype <- function(haplotypes, moi) {
    .Call('_isoRelate_haplotypeToGenotype', PACKAGE = 'isoRelate', haplotypes, moi)
}

#' Internal Function
#' 
#' \code{IBDLabel} is a function used to label unique IBD segments in a pair of isolates for a particular chromosome by determining 
#' breakpoints in IBD vs non-IBD regions. IBD segments are labelled in sequential order genome wide.
#' 
#' @param snp_id A numeric vector of SNP identifiers for IBD segments on the chromosome of interest.
#' @param number_snps integer. The number of IBD SNPs for the chromosome of interest.
IBDLabel <- function(snp_id, number_snps) {
    .Call('_isoRelate_IBDLabel', PACKAGE = 'isoRelate', snp_id, number_snps)
}
bahlolab/isoRelate documentation built on May 11, 2019, 5:25 p.m.