R/PhenotypeNames.R

Defines functions getConceptIdsToPaste checkPhenotypeNames

#' @export
#'
checkPhenotypeNames <- function(
) {

  pathToCsv <- system.file(
    "settings",
    "concept_phenotypes.csv",
    package = "ODYPACK"
  )
  pheno <- read.csv(pathToCsv)
  print(unique(pheno$phenotype))
}

#' @export
#' @importFrom magrittr %>%
getConceptIdsToPaste <- function(
  phenotypeNameRegex
) {

  pathToCsv <- system.file(
    "settings",
    "concept_phenotypes.csv",
    package = "ODYPACK"
  )
  pheno <- read.csv(pathToCsv)

  inclusion <- pheno %>%
    dplyr::filter(
      stringr::str_detect(tolower(phenotype), tolower(phenotypeNameRegex)) &
        criteria == "inclusion"
    )

    exclusion <- pheno %>%
    dplyr::filter(
      stringr::str_detect(tolower(phenotype), tolower(phenotypeNameRegex)) &
        criteria == "exclusion"
    )
    stndrdDscdnts <- inclusion %>%
      dplyr::filter(include_descendants == 1) %>%
      dplyr::pull(concept_id) %>%
      paste(collapse = ", ")

    domainsStndrdDscdnts <- inclusion %>%
      dplyr::filter(include_descendants == 1) %>%
      dplyr::select(domain_id) %>% unique()

    stndrdWODscdnts <- inclusion %>%
      dplyr::filter(include_descendants == 0) %>%
      dplyr::pull(concept_id) %>%
      paste(collapse = ", ")

    domainsWOStndrdDscdnts <- inclusion %>%
      dplyr::filter(include_descendants == 0) %>%
      dplyr::select(domain_id) %>% unique()

    srcConceptIds <- inclusion %>%
      dplyr::filter(stringr::str_detect(phenotype, "source_concept")) %>%
      dplyr::pull(concept_id) %>%
      paste(collapse = ", ")
    domainsSrc <- inclusion %>%
      dplyr::filter(stringr::str_detect(phenotype, "source_concept")) %>%
      dplyr::select(domain_id) %>% unique()







    stndrdDscdntsEx <- exclusion %>%
      dplyr::filter(include_descendants == 1) %>%
      dplyr::pull(concept_id) %>%
      paste(collapse = ", ")

    domainsStndrdDscdntsEx <- exclusion %>%
      dplyr::filter(include_descendants == 1) %>%
      dplyr::select(domain_id) %>% unique()

    stndrdWODscdntsEx <- exclusion %>%
      dplyr::filter(include_descendants == 0) %>%
      dplyr::pull(concept_id) %>%
      paste(collapse = ", ")

    domainsWOStndrdDscdntsEx <- exclusion %>%
      dplyr::filter(include_descendants == 0) %>%
      dplyr::select(domain_id) %>% unique()

    srcConceptIdsEx <- exclusion %>%
      dplyr::filter(stringr::str_detect(phenotype, "source_concept")) %>%
      dplyr::pull(concept_id) %>%
      paste(collapse = ", ")
    domainsSrcEx <- exclusion %>%
      dplyr::filter(stringr::str_detect(phenotype, "source_concept")) %>%
      dplyr::select(domain_id) %>% unique()





    print(
      paste0("You should include following standard concept_ids and descendants: ", glue::glue({stndrdDscdnts})," and domain_ids ",
             glue::glue({domainsStndrdDscdnts}),
             ", you should include following standard concept_ids without descendants: ", glue::glue({stndrdWODscdnts}),
             " and domain_ids ", glue::glue({domainsWOStndrdDscdnts}), ".",
             " Additionally use following source_concept_ids: ",
             glue::glue({srcConceptIds}), " and domain_ids ",
             glue::glue({domainsSrc})
             )
    )
    print(
      paste0("You should exclude following standard concept_ids and descendants: ", glue::glue({stndrdDscdntsEx})," and domain_ids ",
             glue::glue({domainsStndrdDscdntsEx}),
             ", you should include following standard concept_ids without descendants: ", glue::glue({stndrdWODscdntsEx}),
             " and domain_ids ", glue::glue({domainsWOStndrdDscdntsEx}), ".",
             " Additionally use following source_concept_ids: ",
             glue::glue({srcConceptIdsEx}), " and domain_ids ",
             glue::glue({domainsSrcEx})
      )
    )
}
A1exanderAlexeyuk/ODYPACK documentation built on May 16, 2022, 12:22 a.m.