R/phewas_categories.R

Defines functions phewas_categories

Documented in phewas_categories

#' phewas_categories
#' @param codes vector of icd10 codes
#' @return vector of categories
#' @export
phewas_categories <- function(codes) {
  
  n <- length(codes)
  
  result = rep('OTHERS',n)
  result[grep("A|B",codes)] <- "INFECTIOUS"
  result[grepl("C",codes) | (grepl("D",codes) & as.numeric(substring(codes,2,3))<50)] <- "NEOPLASTIC"
  result[grepl("D",codes) & as.numeric(substring(codes,2,3))>=50] <- "HEMATOLOGIC"
  result[grep("E",codes)] <- "ENDOCRINE & METABOLIC"
  result[grep("F",codes)] <- "PSYCHIATRIC"
  result[grep("G",codes)] <- "NEUROLOGIC"
  result[grepl("H",codes) & as.numeric(substring(codes,2,3))<60] <- "EYE & ADNEXA"
  result[grepl("H",codes) & as.numeric(substring(codes,2,3))>=60] <- "EAR & MASTOID PROCESS"
  result[grep("I",codes)] <- "CARDIOVASCULAR"
  result[grep("J",codes)] <- "PULMONARY"
  result[grep("K",codes)] <- "DIGESTIVE"
  result[grep("L",codes)] <- "DERMATOLOGIC"
  result[grep("M",codes)] <- "MUSCULOSKELETAL"
  result[grep("N",codes)] <- "GENITOURINARY"
  result[grep("O",codes)] <- "OBSTETRIC"
  result[grep("P",codes)] <- "OBSTETRIC"
  result[grep("Q",codes)] <- "CONGENITAL"
  result[grep("R",codes)] <- "SYMPTOMS & SIGNS"
  result[grep("S|T",codes)] <- "INJURIES"
  #result[grep("V|W|X|Y|Z",codes)] <- "OTHERS"
  result<- factor(result, levels = c("INFECTIOUS",
                                     "NEOPLASTIC",
                                     "HEMATOLOGIC",
                                     "ENDOCRINE & METABOLIC",
                                     "PSYCHIATRIC", 
                                     "NEUROLOGIC",
                                     "EYE & ADNEXA", 
                                     "EAR & MASTOID PROCESS",
                                     "CARDIOVASCULAR",
                                     "PULMONARY",
                                     "DIGESTIVE",
                                     "DERMATOLOGIC",
                                     "MUSCULOSKELETAL",
                                     "GENITOURINARY",
                                     "OBSTETRIC",
                                     "CONGENITAL",
                                     "SYMPTOMS & SIGNS",
                                     "OTHERS"))
  
  return(result)
}
aneuraz/multiWAS documentation built on July 29, 2017, 3:39 a.m.