% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/genotype_prob.R
\name{genotype_prob}
\alias{genotype_prob}
\title{Calculate Genotype Probabilities and Impute Missing Data}
\usage{
genotype_prob(GeneticMap, GenoData, method, croType = NULL, steps = 0, Gn = 2)
}
\arguments{
\item{GeneticMap}{A data frame containing genetic map information with columns:
\itemize{
  \item \code{marker}: Marker names (character)
  \item \code{chr}: Chromosome numbers (numeric or factor)
  \item \code{pos}: Genetic positions in centimorgans (numeric)
}}

\item{GenoData}{A matrix or data frame containing genotype data with individuals as rows 
and markers as columns. Genotype codes:
\itemize{
  \item \code{0}: Homozygous for reference allele
  \item \code{1}: Heterozygous
  \item \code{2}: Homozygous for alternative allele
  \item \code{9} or \code{NA}: Missing data
}}

\item{method}{Character string specifying the mapping method:
\itemize{
  \item \code{"AM"}: Association Mapping - combines map with genotype data
  \item \code{"LM"}: Linkage Mapping - performs missing data imputation
}}

\item{croType}{Character string specifying the cross type for LM method. Required when \code{method="LM"}:
\itemize{
  \item \code{"RIL"}: Recombinant Inbred Lines
  \item \code{"DH"}: Doubled Haploids
  \item \code{"F2"}: F2 population
  \item \code{"BCP1"}: Backcross to Parent 1
  \item \code{"BCP2"}: Backcross to Parent 2
  \item \code{"Fn"}: Advanced generation (n > 2)
}}

\item{steps}{Numeric value specifying the step size (in cM) for virtual marker creation in LM.
If 0, no virtual markers are created. Default is 0.}

\item{Gn}{Numeric value specifying the generation number for advanced populations.
Must be greater than 1. Default is 2.}
}
\value{
A data frame containing the processed genotype data with genetic map information
  and calculated genotype probabilities. The structure depends on the method:
  \itemize{
    \item \strong{AM method}: Original data combined with genetic map
    \item \strong{LM method}: Imputed genotype data with probabilities and optional virtual markers
  }
}
\description{
Calculates genotype probabilities and imputes missing genotype data for genetic mapping studies.
Supports both Association Mapping (AM) and Linkage Mapping (LM) methods with comprehensive
missing data handling and virtual marker creation capabilities.
}
\details{
This function provides comprehensive genotype data processing for genetic mapping:

\strong{Association Mapping (AM):}
\itemize{
  \item Simply combines genetic map with genotype data
  \item Converts missing values to code 9
  \item No imputation performed
}

\strong{Linkage Mapping (LM):}
\itemize{
  \item Validates genotype codes based on cross type expectations
  \item Imputes missing genotypes using flanking marker information
  \item Creates virtual markers at specified intervals when \code{steps > 0}
  \item Uses Haldane mapping function for recombination calculations
  \item Applies cross-type specific genotype probability calculations
}

\strong{Cross Type Genotype Expectations:}
\itemize{
  \item \code{RIL/DH}: Only codes 0 and 2 allowed
  \item \code{F2}: Codes 0, 1, and 2 allowed
  \item \code{BCP1/BCP2}: Codes 0, 1, and 2 with specific constraints
  \item \code{Fn}: Codes 0, 1, and 2 for advanced generations
}

\strong{Virtual Marker Creation:}
When \code{steps > 0}, virtual markers are created at regular intervals between
existing markers to improve mapping resolution and handle large gaps in the genetic map.
}
\examples{
# Example genetic map
genetic_map <- data.frame(
  marker = c("M1", "M2", "M3", "M4", "M5"),
  chr = c(1, 1, 1, 1, 1),
  pos = c(0, 10, 25, 40, 50)
)

# Example genotype data with missing values
geno_data <- matrix(
  c(2, 0, NA, 1, 2,
    1, 0, 2, NA, 0,
    2, 1, 0, 2, 1,
    0, NA, 1, 0, 2),
  nrow = 4, ncol = 5,
  dimnames = list(c("Ind1", "Ind2", "Ind3", "Ind4"), 
                  c("M1", "M2", "M3", "M4", "M5"))
)

# Association mapping (no imputation)
result_am <- genotype_prob(genetic_map, geno_data, method = "AM")
result_am

# Linkage mapping with virtual marker creation
result_lm_vm <- genotype_prob(genetic_map, geno_data, method = "LM", 
                           croType = "F2", steps = 5)
result_lm_vm

}
\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{haldane_map}} for recombination fraction calculations,
         \code{\link{expected_genotype_dist}} for expected genotype probabilities
}
