R/selectionscan.R

Defines functions GtoFreq

Documented in GtoFreq

#' Compute allele frequency matrix from genotype frequency matrix.
#'
#' @param G genotype frequency matrix.
#' @param ploidy the number of chromosomes.
#'
#' @return a matrix of allele frequencies for each locus.
#' @export
GtoFreq <- function(G, ploidy) {
  G.array <- array(G, c(ploidy + 1, nrow(G) / (ploidy + 1), ncol(G)))
  Freq <- apply(G.array, c(2,3), function(g) sum(0:ploidy * g / ploidy))
  return(Freq)
}
bcm-uga/TESS3_encho_sen documentation built on June 30, 2023, 3:08 a.m.