Commit b74f79da authored by mariefbourdon's avatar mariefbourdon
Browse files

2220620 modifs geno_strains

parent 097b8c2f
/home/marie/Documents/HB_CC011/F2/Geno/Maestro/F2_geno_estmap1.R="42B0AE06"
/home/marie/Documents/stuart/stuart_package/stuart/DESCRIPTION="55556B0B"
/home/marie/Documents/stuart/stuart_package/stuart/R/geno_strains.R="68944065"
/home/marie/Documents/stuart/stuart_package/stuart/R/mark_estmap.R="F759F000"
/home/marie/Documents/stuart/stuart_package/stuart/README.Rmd="4E06E7DC"
/home/marie/Documents/stuart/stuart_package/stuart/doc/stuart.R="A03ACF3D"
/home/marie/Documents/stuart/stuart_package/stuart/man/genos.Rd="75E7412F"
/home/marie/Documents/stuart/stuart_package/stuart/vignettes/stuart.Rmd="01396A37"
#' @title Create haplotype for inbred strains into a dataframe
#' @title Summarizes genotypes of multiple individuals
#'
#' @description This functions adds columns for parental strains used in the cross in the annotation data frame, from the genotype data frame in which one or several animal of the parental strains were genotyped.
#' @description This functions formats genotypes of genotyped individuals from a two letters encoding to a one letter encoding.
#' If several animals of one strain were genotyped, a consensus is created from these animals.
#' The consensus is created as follow : if the indivuals carry the same allele, this allele is kept, otherwise, the allele is noted as "N". If individuals show residual heterozygosity, it is encoded as "H".
#' The one letter encoding is made as follow: if the individual is homozygous, the letter of the allele (A, T, G or C) is kept. If the individual show residual heterozygosity, it is encoded as "H". If the genotype is missing, it is encoded as "N".
#' The consensus is created as follow : if the indivuals carry the same allele, this allele is kept. If one or several individuals are heterozygous, the genotype is encoded as "H". If one individual has a missing genotypes but another was correctly genotyped, its genotype is kept.
#' If the genotypes are completely discordant (i.e. if two individuals are both homozygous but for different alleles), the genotype is encoded as "D".
#' @param annot data frame with the annotation of the array used
#' @param geno data frame with the genotyping results for your cross from miniMUGA array
#' @param strn tibble or dataframe with the strains to analyse. Columns names are the name of the strains and the values in rows of each column are the IDs of the individuals genotyped for each strain.
......@@ -33,18 +35,28 @@ geno_strains <- function(annot,geno,strn,cols){
#pivoting
geno <- geno %>% select(marker,id,Geno) %>% tidyr::pivot_wider(names_from = id, values_from = Geno)
#create consensus
for(i in colnames(strn)){
inds <- na.omit(strn[,i]) %>%pull()
inds <- na.omit(strn[,i]) %>% pull()
geno <- geno %>% rename(!!sym(i):=!!sym(inds[1]))
if(length(inds) > 1){
for(j in 2:length(inds)){
geno <- geno %>% mutate(!!sym(i) := ifelse(!!sym(i)==!!sym(inds[j]),!!sym(i),"N"))
geno <- geno %>% mutate(!!sym(i) := case_when(!!sym(i)==!!sym(inds[j]) ~ !!sym(i),
!!sym(i) %in% c("A","T","G","C") & !!sym(inds[j]) == "H" ~ "H",
!!sym(inds[j]) %in% c("A","T","G","C") & !!sym(i) == "H" ~ "H",
!!sym(i) %in% c("A","T","G","C") & !!sym(inds[j]) == "N" ~ !!sym(i),
!!sym(inds[j]) %in% c("A","T","G","C") & !!sym(i) == "N" ~ !!sym(inds[j]),
!!sym(i) %in% c("A","T","G","C") & !!sym(inds[j]) %in% c("A","T","G","C") ~ "D"
)
)
}
}
}
geno <- geno %>% select(marker,colnames(strn))
#merge with annot file
......
No preview for this file type
No preview for this file type
......@@ -81,7 +81,6 @@ This is done with the `geno_strains()` function. If parental genotypes was in an
parental_strains <- tibble::tibble(parent1 = c("StrainsA_1","StrainsA_2"),
parent2 = c("StrainsB_1","StrainsB_2"))
strains <- geno_strains(annot=annot_mini,geno=genos,
strn=parental_strains,cols=c("chr","cM_cox"))
head(strains) %>% print.data.frame()
......
Supports Markdown
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