美文网首页
012或0-11格式转换

012或0-11格式转换

作者: 董八七 | 来源:发表于2022-01-07 14:30 被阅读0次
    #' convert an intact (without missing values) genotyped matrix, sample x genotype, 
    #' into 012 coding format, used for add, dom, or epi analysis
    #'
    #' @param genotype 
    #'
    #' @return
    #' @export
    #'
    #' @examples
    genoTo012 <- function(genotype) {
      allel_all <- genotype %>% str_split("") %>% unlist
      allel_uni=unique(allel_all)
      allel_tab=table(allel_all)
      allel_min=names(allel_tab[which.min(allel_tab)])
      allel_max=allel_uni[allel_uni!=allel_min]
      geno_2=paste0(allel_min,allel_min)
      geno_0=paste0(allel_max,allel_max)
      genotype[which(genotype==geno_0)]=0
      genotype[which(genotype==geno_2)]=2
      genotype[which(genotype!=0&genotype!=2)]=1
      genotype=as.numeric(genotype)
      return(genotype)
    }
    #' convert an intact (without missing values) genotyped matrix, sample x genotype, 
    #' into 0,-1,1 coding format, used for imprinting analysis
    #'
    #' @param genotype 
    #'
    #' @return
    #' @export
    #'
    #' @examples
    genoTo01_12 <- function(genotype) {
      allel_all <- genotype %>% str_split("") %>% unlist
      allel_uni=unique(allel_all)
      allel_tab=table(allel_all)
      allel_min=names(allel_tab[which.min(allel_tab)])
      allel_max=allel_uni[allel_uni!=allel_min]
      
      geno_1=paste0(allel_min,allel_max)
      geno__1=paste0(allel_max,allel_min)
      genotype[which(genotype==geno_1)]=1
      genotype[which(genotype==geno__1)]=-1
      genotype[which(genotype!=1&genotype!=-1)]=0
      genotype=as.numeric(genotype)
      return(genotype)
    }

    相关文章

      网友评论

          本文标题:012或0-11格式转换

          本文链接:https://www.haomeiwen.com/subject/avghlhtx.html