% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/genotype_freq.R
\name{genotype_freq}
\alias{genotype_freq}
\alias{calculate_genotype_frequencies}
\title{Genotype Frequency Calculator for Genetic Populations}
\usage{
genotype_freq(
  cross_type,
  generation = 2,
  genotype_index,
  recomb_aq,
  recomb_qb = 0
)
}
\arguments{
\item{cross_type}{Population type used in the calculation:
\itemize{
  \item \code{"Fn"}: F-n generation populations (n > 2)
  \item \code{"BCP1"}: Backcross to parent 1 populations
  \item \code{"BCP2"}: Backcross to parent 2 populations
  \item \code{"F2"}: F2 generation populations
  \item \code{"DH"}: Doubled haploid populations
  \item \code{"RIL"}: Recombinant inbred line populations
}}

\item{generation}{Generation number (for example, 2 for F2, 3 for F3). Must be greater than 1.}

\item{genotype_index}{Index of the genotype class to evaluate.
Valid range depends on `cross_type`:
\itemize{
  \item \code{"Fn"}: 1-20 (20 different genotype classes)
  \item \code{"BCP1/BCP2"}: 1-8 (8 genotype classes)
  \item \code{"F2"}: 1-9 (9 genotype classes)
}}

\item{recomb_aq}{Recombination fraction between loci A and Q.
Use a value between 0 and 0.5.}

\item{recomb_qb}{Recombination fraction between loci Q and B.
Use a value between 0 and 0.5. Default is 0.}
}
\value{
A numeric value representing the frequency of the specified genotype in the given generation.
  The result is always between 0 and 1.
}
\description{
Calculates genotype frequencies for different cross types and generations in genetic mapping studies.
This function implements complex recurrence relations to compute genotype frequencies in various
genetic populations including Fn, backcross, and advanced generation populations.
}
\details{
This function calculates genotype frequencies using sophisticated mathematical models:

\strong{For Fn Populations (y > 0):}
\itemize{
  \item Handles 20 different genotype classes with complex recurrence relations
  \item Accounts for recombination between three loci (A, Q, B)
  \item Uses the relationship \eqn{z = x + y - 2xy} for flanking marker recombination
  \item Implements generation-by-generation frequency calculations
}

\strong{For BCP1 Populations:}
\itemize{
  \item Handles 8 genotype classes
  \item Backcross to the first parent (AAQQBB)
  \item Specific recurrence relations for each genotype class
}

\strong{For BCP2 Populations:}
\itemize{
  \item Handles 8 genotype classes
  \item Backcross to the second parent (aaqqbb)
  \item Different initial conditions and recurrence relations
}

\strong{For F2 Populations (y = 0):}
\itemize{
  \item Handles 9 genotype classes
  \item Simplified two-locus model
  \item Standard F2 generation frequencies
}

\strong{Mathematical Foundation:}
The function uses recurrence relations to calculate genotype frequencies across generations.
For each generation, the frequency of each genotype class is computed based on the
frequencies in the previous generation and the recombination fractions between loci.
}
\examples{
# Calculate frequency for F2 generation, genotype 1, with recombination fraction 0.1
freq_f2 <- genotype_freq("Fn", generation = 2, genotype_index = 1, recomb_aq = 0.1, recomb_qb = 0)

# Calculate frequency for BCP1 generation, genotype 5, with recombination fractions
freq_bcp1 <- genotype_freq(
  "BCP1", generation = 3, genotype_index = 5, recomb_aq = 0.15, recomb_qb = 0.25
)

# Calculate frequency for Fn generation, genotype 10, with recombination fractions
freq_fn <- genotype_freq(
  "Fn", generation = 4, genotype_index = 10, recomb_aq = 0.2, recomb_qb = 0.3
)

# Calculate frequency for BCP2 generation, genotype 3
freq_bcp2 <- genotype_freq(
  "BCP2", generation = 2, genotype_index = 3, recomb_aq = 0.1, recomb_qb = 0.2
)

# Example with different generation numbers
freq_gen3 <- genotype_freq("Fn", generation = 3, genotype_index = 1, recomb_aq = 0.1, recomb_qb = 0)
freq_gen5 <- genotype_freq("Fn", generation = 5, genotype_index = 1, recomb_aq = 0.1, recomb_qb = 0)

}
\references{
Haldane, J.B.S. (1919). The combination of linkage values and the calculation of 
distances between the loci of linked factors. Journal of Genetics, 8(3), 299-309.
}
\seealso{
\code{\link{expected_genotype_dist}} for expected allele genotype distribution calculations
}
