Last updated: 2025-09-07

Checks: 7 0

Knit directory: genomics_ancest_disease_dispar/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20220216) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 972e7da. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store
    Ignored:    data/gwas_catalog/
    Ignored:    output/gwas_study_info_cohort_corrected.csv
    Ignored:    output/gwas_study_info_trait_corrected.csv
    Ignored:    output/gwas_study_info_trait_ontology_info.csv
    Ignored:    output/trait_ontology/
    Ignored:    renv/

Untracked files:
    Untracked:  analysis/disease_burden.qmd
    Untracked:  data/gbd/
    Untracked:  data/who/

Unstaged changes:
    Modified:   analysis/disease_inves_by_ancest.Rmd
    Modified:   analysis/trait_ontology_collapse.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/download_ontology.Rmd) and HTML (docs/download_ontology.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 972e7da IJbeasley 2025-09-07 workflowr::wflow_publish("analysis/download_ontology.Rmd")

1 Set up

knitr::opts_chunk$set(echo = TRUE, 
                      message = FALSE, 
                      warning = FALSE
                      )

library(data.table)
library(dplyr)
library(ggplot2)
library(stringr)

2 Get trait ontology terms relating to ‘Disease’ (etc.)

library(httr)
library(jsonlite)

2.1 Mondo ‘Human Disease’ (http://purl.obolibrary.org/obo/MONDO_0700096)

url <-
"http://www.ebi.ac.uk/ols4/api/ontologies/mondo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMONDO_0700096/descendants"

mondo_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  mondo_descendants <- c(mondo_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(mondo_descendants)
mondo_descendants[1:5]

writeLines(mondo_descendants, here::here("output/trait_ontology/mondo_0700096_descendants.txt"))

2.2 EFO ‘Disease’ Descendants (http://www.ebi.ac.uk/efo/EFO_0000408)

url <-
"http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0000408/descendants"

efo_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  efo_descendants <- c(efo_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(efo_descendants)
efo_descendants[1:5]

writeLines(efo_descendants, here::here("output/trait_ontology/efo_0000408_descendants.txt"))

2.3 NCIT (Disease or Disorder): http://purl.obolibrary.org/obo/NCIT_C2991

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/ncit/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FNCIT_C2991/descendants"


ncit_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  ncit_descendants <- c(ncit_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(ncit_descendants)
ncit_descendants[1:5]

writeLines(ncit_descendants, here::here("output/trait_ontology/ncit_C2991_descendants.txt"))

2.4 Orphanet Disorder (http://www.orpha.net/ORDO/Orphanet_557493)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/ordo/terms/http%253A%252F%252Fwww.orpha.net%252FORDO%252FOrphanet_557493/descendants"

orphanet_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  orphanet_descendants <- c(orphanet_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(orphanet_descendants)
orphanet_descendants[1:5]

writeLines(orphanet_descendants, here::here("output/trait_ontology/orphanet_557493_descendants.txt"))

2.5 Pathologic process (http://purl.obolibrary.org/obo/OBI_1110122)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FOBI_1110122/descendants"

path_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  path_descendants <- c(path_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(path_descendants)
path_descendants[1:5]

writeLines(path_descendants, here::here("output/trait_ontology/obi_1110122_descendants.txt"))

2.6 Disease course http://purl.obolibrary.org/obo/OGMS_0000063

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FOGMS_0000063/descendants"

disease_course_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  disease_course_descendants <- c(disease_course_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(disease_course_descendants)
disease_course_descendants[1:5]

writeLines(disease_course_descendants, here::here("output/trait_ontology/ogms_0000063_descendants.txt"))

2.7 Age of onset of disease (http://purl.obolibrary.org/obo/OBA_2020000)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/oba/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FOBA_2020000/descendants"

age_of_onset_descendants <- c()

repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  age_of_onset_descendants <- c(age_of_onset_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(age_of_onset_descendants)
age_of_onset_descendants[1:5]

writeLines(age_of_onset_descendants, here::here("output/trait_ontology/oba_2020000_descendants.txt"))

3 Get trait ontology terms relating to ‘Phenotypic abnormality’ (http://purl.obolibrary.org/obo/HP_0000118)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FHP_0000118/descendants"


hp_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  hp_descendants <- c(hp_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(hp_descendants)
[1] 2625
hp_descendants[1:5]
[1] "hypoxia"                                  
[2] "necrosis"                                 
[3] "Abnormality of limbs"                     
[4] "Abnormality of the musculoskeletal system"
[5] "Vocal cord dysfunction"                   
hp_descendants = c(
                   "Abnormal aortic morphology",  
                   "Abnormal chest sounds",
                   "Abnormality of the eye", 
                   "Abnormal foot morphology",
                   "Abnormality of the gastrointestinal tract",                   
                   "Abnormality of the genital system",
                   "Abnormality of the liver",
                   "Abnormality of the nervous system",
                   "Abnormality of the skeletal system",
                   "Abnormality of the vasculature",
                   "Abnormal venous morphology",
                   hp_descendants)

hp_descendants = c("Phenotypic abnormality", hp_descendants)

writeLines(hp_descendants, here::here("output/trait_ontology/hp_0000118_descendants.txt"))

4 Get trait ontology terms relating to ‘Measurement’

4.1 Measurement terms (http://www.ebi.ac.uk/efo/EFO_0001444)

# Define the API endpoint
url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0001444/descendants"

measurement_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  measurement_descendants <- c(measurement_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(measurement_descendants)
measurement_descendants[1:5]

disease_measurement_grep_terms = c("age of onset",
                                   "alcohol use",
                                   "allergy",
                                   "anemia (phenotype)",
                                  "anxiety",
                                  "cancer aggressiveness",
                                  "coronary atherosclerosis",
                                  "dependence",
                                  "depressive",
                                  "psoriasis 14,pustular",
                                  "disease progression",
                                  "disease severity",
                                  "exacerbation",
                                  "family history",
                                  "food addiction",
                                  "insomnia",
                                  "lung disease",
                                  "lewy body dementia",                                  
                                  "preeclampsia",
                                  "rosacea",
                                  "stroke outcome",
                                  "sleep apnea",
                                  "susceptibility to",
                                  "symptom",
                                  "oppositional defiant",
                                  "withdrawal",
                                  "psoriasis",
                                  "psychosis"
                                  )

disease_measurement_terms = 
grep(pattern = paste0(disease_measurement_grep_terms, collapse = "|"),
     measurement,
      value = T
      )

measurement_descendants = measurement_descendants[!measurement_descendants %in% disease_measurement_terms]


writeLines(measurement_descendants, here::here("output/trait_ontology/efo_0001444_descendants.txt"))

writeLines(disease_measurement_terms, here::here("output/trait_ontology/efo_0001444_disease_measurement_terms.txt"))

4.2 Total cholesterol measurements (http://www.ebi.ac.uk/efo/EFO_0004574)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0004574/descendants"


total_choles_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  total_choles_descendants <- c(total_choles_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

writeLines(total_choles_descendants, here::here("output/trait_ontology/efo_0004574_descendants.txt"))


length(total_choles_descendants)
total_choles_descendants[1:5]

5 Get ontology terms - response to stimulus (http://purl.obolibrary.org/obo/GO_0050896)

Includes:

5.1 From GO

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/go/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FGO_0050896/descendants"

go_response_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  go_response_descendants <- c(go_response_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(go_response_descendants)
go_response_descendants[1:5]

writeLines(go_response_descendants, here::here("output/trait_ontology/go_0050896_descendants.txt"))

5.2 From EFO

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FGO_0050896/descendants"

efo_response_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  efo_response_descendants <- c(efo_response_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(efo_response_descendants)
efo_response_descendants[1:5]

writeLines(efo_response_descendants, here::here("output/trait_ontology/efo_go_0050896_descendants.txt"))

6 Get ontology terms relating to ‘Phenotype’ (http://www.ebi.ac.uk/efo/EFO_0000651)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0000651/descendants"

phenotype_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  phenotype_descendants <- c(phenotype_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(phenotype_descendants)
phenotype_descendants[1:5]


writeLines(phenotype_descendants, here::here("output/trait_ontology/efo_0000651_descendants.txt"))

7 Mental process (http://www.ebi.ac.uk/efo/EFO_0004323)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0004323/descendants"

mental_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  mental_descendants <- c(mental_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(mental_descendants)
mental_descendants[1:5]
mental_descendants = c("mental process", 
                       "cognitive function measurement",
                       mental_descendants)

writeLines(mental_descendants, here::here("output/trait_ontology/efo_0004323_descendants.txt"))

8 Behavior (http://purl.obolibrary.org/obo/GO_0007610)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FGO_0007610/descendants"

behavior_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  behavior_descendants <- c(behavior_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(behavior_descendants)
behavior_descendants[1:5]

behavior_descendants = c("behavior", behavior_descendants)
writeLines(behavior_descendants, here::here("output/trait_ontology/go_0007610_descendants.txt"))

9 Injury (http://www.ebi.ac.uk/efo/EFO_0000546)

url <- "http://www.ebi.ac.uk/ols4/api/ontologies/efo/terms/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0000546/descendants"

injury_descendants <- c()
repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  injury_descendants <- c(injury_descendants, data$`_embedded`$terms$label)
  
  # check if there is a next page
  if (!is.null(data$`_links`$`next`$href)) {
    url <- data$`_links`$`next`$href
  } else {
    break
  }
}

length(injury_descendants)
injury_descendants[1:5]

injury_descendants = c("injury", injury_descendants)
writeLines(injury_descendants, here::here("output/trait_ontology/efo_0000546_descendants.txt"))

10 Sociological / environmental factors

enviro_factors <- c(
  "income",
"socioeconomic status",
"encounter with health service related to socioeconomic and psychosocial circumstances" ,
"townsend deprivation index",
"household income",
"social deprivation",
"economic and social preference",
"social deprivation",
"physical activity",
"exercise",
"family relationship",
"cannabis use",
"alcohol drinking"
)

sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 15.6.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] jsonlite_2.0.0    httr_1.4.7        stringr_1.5.1     ggplot2_3.5.2    
[5] dplyr_1.1.4       data.table_1.17.8 workflowr_1.7.1  

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       compiler_4.3.1     renv_1.0.3         promises_1.3.3    
 [5] tidyselect_1.2.1   Rcpp_1.1.0         git2r_0.36.2       callr_3.7.6       
 [9] later_1.4.2        jquerylib_0.1.4    scales_1.4.0       yaml_2.3.10       
[13] fastmap_1.2.0      here_1.0.1         R6_2.6.1           generics_0.1.4    
[17] curl_6.4.0         knitr_1.50         tibble_3.3.0       rprojroot_2.1.0   
[21] RColorBrewer_1.1-3 bslib_0.9.0        pillar_1.11.0      rlang_1.1.6       
[25] cachem_1.1.0       stringi_1.8.7      httpuv_1.6.16      xfun_0.52         
[29] getPass_0.2-4      fs_1.6.6           sass_0.4.10        cli_3.6.5         
[33] withr_3.0.2        magrittr_2.0.3     ps_1.9.1           grid_4.3.1        
[37] digest_0.6.37      processx_3.8.6     rstudioapi_0.17.1  lifecycle_1.0.4   
[41] vctrs_0.6.5        evaluate_1.0.4     glue_1.8.0         farver_2.1.2      
[45] whisker_0.4.1      rmarkdown_2.29     tools_4.3.1        pkgconfig_2.0.3   
[49] htmltools_0.5.8.1