Last updated: 2025-09-06

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 dc84680. 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:  analysis/download_ontology.Rmd
    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/non_ontology_trait_collapse.Rmd) and HTML (docs/non_ontology_trait_collapse.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 dc84680 IJbeasley 2025-09-06 Updating trait collapsing once again
html 3584988 IJbeasley 2025-09-06 Build site.
Rmd 82b6e8a IJbeasley 2025-09-06 Update trait collapsing
html 13c5442 IJbeasley 2025-09-05 Build site.
Rmd b209d1f IJbeasley 2025-09-05 Even more trait collapsing

1 Set up

library(dplyr)
library(data.table)
library(ggplot2)
library(stringr)
gwas_study_info <- fread(here::here("output/gwas_study_info_trait_ontology_info.csv"))

2 Number of studies per trait - before any grouping

# gwas_study_info |> 
#   dplyr::filter(DISEASE_STUDY == T) |>
#   dplyr::filter(all_disease_terms == "") |>
#   View()

n_studies_trait = gwas_study_info |>
  dplyr::filter(DISEASE_STUDY == T) |>
  dplyr::select(all_disease_terms, PUBMED_ID) |>
  dplyr::distinct() |>
  dplyr::group_by(all_disease_terms) |>
  dplyr::summarise(n_studies = dplyr::n()) |>
  dplyr::arrange(desc(n_studies))

head(n_studies_trait)
# A tibble: 6 × 2
  all_disease_terms         n_studies
  <chr>                         <int>
1 type 2 diabetes mellitus        148
2 major depressive disorder       110
3 alzheimer disease               108
4 schizophrenia                   102
5 asthma                          100
6 breast carcinoma                100
dim(n_studies_trait)
[1] 2722    2

3 Collapse more traits

gwas_study_info$all_disease_terms = sub(",$", "", gwas_study_info$all_disease_terms)

gwas_study_info$all_disease_terms = stringr::str_trim(gwas_study_info$all_disease_terms)

# collapse more traits 
gwas_study_info = gwas_study_info |> 
  mutate(collected_all_disease_terms = all_disease_terms) 

3.1 Susceptibility to X measurement, X disorder measurement etc.

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        str_replace(collected_all_disease_terms, 
                    "^susceptibility to (.*?) measurement$", "\\1")

         ) |>
    mutate(collected_all_disease_terms = 
        str_replace(collected_all_disease_terms, 
                    "^susceptibility to (.*?) (.*?) measurement$", "\\1")

         ) |>
      mutate(collected_all_disease_terms = 
        str_replace(collected_all_disease_terms, 
                    "^susceptibility to (.*?) (.*?) infection$", "\\1")

         ) 


gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        str_replace(collected_all_disease_terms, 
                    "susceptibility to viral and mycobacterial infections",
                    "viral and mycobacterial infections")

         ) |>
    mutate(collected_all_disease_terms = 
        str_replace(collected_all_disease_terms, 
                    "susceptibility to strep throat",
                    "strep throat")
         )

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
          stringr::str_remove(collected_all_disease_terms, " symptom severity measurement")
         ) |>
  mutate(collected_all_disease_terms = 
          stringr::str_remove(collected_all_disease_terms, " severity measurement| exacerbation measurement")
         ) 



gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms =
           str_replace_all(collected_all_disease_terms,
                           "\\bdependence\\s+measurement\\b",
                           "dependence")) |> 
  mutate(collected_all_disease_terms =
           str_replace_all(collected_all_disease_terms,
                           "\\ballergy\\s+measurement\\b",
                           "allergy")) |> 
  mutate(collected_all_disease_terms =
           str_replace_all(collected_all_disease_terms,
                           "\\baddiction\\s+measurement\\b",
                           "addiction")) |> 
    mutate(collected_all_disease_terms =
           str_replace_all(collected_all_disease_terms,
                           "\\baddiction\\s+measurement\\b",
                           "addiction")) |> 
      mutate(collected_all_disease_terms =
           str_replace_all(collected_all_disease_terms,
                           "\\bsyndrome\\s+measurement\\b",
                           "syndrome")) |> 
      mutate(collected_all_disease_terms =
           str_replace_all(collected_all_disease_terms,
                           "\\bdisorder\\s+measurement\\b",
                           "disorder")) 

3.2 Age of onset of

gwas_study_info = gwas_study_info |>
      mutate(collected_all_disease_terms = 
         stringr::str_remove(collected_all_disease_terms,
                         pattern = "age of onset of "))

3.3 Family history of

gwas_study_info = gwas_study_info |>
      mutate(collected_all_disease_terms = 
         stringr::str_remove(collected_all_disease_terms,
                         pattern = "family history of "))

3.4 Cancer

gwas_study_info = gwas_study_info |>
      mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "\\bcarcinoma",
                            "cancer")
         )

gwas_study_info = gwas_study_info |>
      mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "triple-negative breast cancer",
                            "breast cancer"
           ))

3.4.1 Melanoma

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "cutaneous melanoma",
                          "melanoma"
         ))

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "uveal melanoma|uveal melanoma disease severity|epithelioid cell uveal melanoma|choroidal melanoma",
                          "ocular melanoma"
         ))

3.4.2 Head and neck cancer

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "head and neck malignant neoplasia",
                          "head and neck cancer"
         ))

3.5 Substance abuse

3.5.1 Alcohol

gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "alcohol dependence measurement",
                          "alcohol dependence"
         ))

gwas_study_info = gwas_study_info |>
      mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "alcohol dependence|alcohol withdrawal|alcohol withdrawal delirium|alcohol abuse",
                            "alcohol-related disorders"
           ))

3.5.2 Cannibis

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "cannabis dependence measurement",
                          "cannabis dependence"
         ))

3.5.3 Cocaine

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "cocaine use disorder|cocaine dependence",
                          "cocaine-related disorders"
         ))

3.5.4 Nicotine

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "nicotine dependence symptom count",
                          "nicotine dependence"
         ))

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "nicotine withdrawal symptom count|nicotine withdrawal measurement",
                          "nicotine withdrawal"
         ))

3.6 Infectious disease

3.6.1 Influenza

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "influenza a (h1n1)",
                          "influenza"
         ))

3.7 hepatitis

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "hepatitis a virus infection",
                          "hepatitis a infection"
         )) |>
      mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "hepatitis b virus infection",
                          "hepatitis b infection"
         )) |>
        mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "hepatitis c virus infection",
                          "hepatitis c infection"
         ))

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "chronic hepatitis c virus infection",
                          "chronic hepatitis, hepatitis c infection"
         )) |>
      mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "chronic hepatitis b virus infection",
                          "chronic hepatitis, hepatitis b infection"
         ))

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "hepatitis virus-related liver cancer",
                          "hepatitis, liver cancer"
         ))

3.7.1 HIV

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "hiv-1 infection",
                          "hiv infection"
         ))

3.7.2 COVID

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "time to remission of covid-19 symptoms",
                          "covid-19"
         ))

3.7.3 Mumps

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "mumps virus infectious disease",
                          "mumps"
         ))

3.7.4 Rubella

gwas_study_info = gwas_study_info |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "rubella infection",
                          "rubella"
         ))

3.8 Asthma

gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "asthma exacerbation measurement",
                          "asthma"
         )) |>
    mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "adult onset asthma|childhood onset asthma",
                            "asthma"
           )) |>
  mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "asthma symptoms measurement",
                            "asthma"
           )) |> 
    mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "atopic asthma",
                            "asthma"
           )) |>
    mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "asthma, asthma",
                            "asthma"
           )) |>
  mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "chronic obstructive asthma",
                            "asthma"
           ))

3.9 Psychiatric

gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "bipolar ii disorder|bipolar i disorder",
                          "bipolar disorder"
         ))


gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "insomnia measurement",
                          "insomnia"
         ))


gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "post-traumatic stress disorder symptom measurement",
                          "post-traumatic stress disorder"
         )) |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "multiple sclerosis symptom measurement",
                          "multiple sclerosis"
         ))  


gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "anxiety disorder measurement",
                          "anxiety disorder"
         ))




gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "agoraphobia symptom measurement",
                          "agoraphobia"
         ))

3.9.1 ADHD & Autism

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        stringr::str_replace_all(collected_all_disease_terms,
                         "autism spectrum disorder",
                         "autism")
        ) |>
    mutate(collected_all_disease_terms = 
        stringr::str_replace_all(collected_all_disease_terms,
                         "asperger syndrome",
                         "autism")
        )
  

gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "attention deficit hyperactivity disorder",
                            "adhd"
         )) |>
  mutate(collected_all_disease_terms = 
           stringr::str_replace_all(collected_all_disease_terms,
                            "adhd symptom measurement",
                            "adhd")
         )

3.10 Psychosis predisposition

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        stringr::str_replace_all(collected_all_disease_terms,
                         "psychosis predisposition measurement",
                         "psychosis predisposition")
        )

3.11 Photosensitivity

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        stringr::str_replace_all(collected_all_disease_terms,
                         "phototoxic dermatitis|skin sensitivity to sun",
                         "photosensitivity disease")
        )

3.12 Tenosynovitis

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        stringr::str_replace_all(collected_all_disease_terms,
                         "stenosing tenosynovitis",
                         "tenosynovitis")
        )

3.13 Juvenile idiopathic arthritis

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
        stringr::str_replace_all(collected_all_disease_terms,
                         "systemic juvenile idiopathic arthritis|oligoarticular juvenile idiopathic arthritis|
                         polyarticular juvenile idiopathic arthritis",
                         "juvenile idiopathic arthritis")
        )

3.13.1 Dementia, Alzheimer’s, Parkinson’s etc.

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "early-onset alzheimers disease|late-onset alzheimers disease",
                          "alzheimers disease"
         )) |>
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "alzheimer’s disease", 
                          "alzheimers disease"
         )) |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "family history of alzheimer’s disease",
                          "alzheimers disease"
         )) |>
  mutate(collected_all_disease_terms =
         stringr::str_replace_all(collected_all_disease_terms,
                          "alzheimer disease",
                          "alzheimers disease"
         ))

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "parkinson's disease symptom measurement",
                          "parkinsons disease"
         ))

3.13.2 Sleep Apnea

gwas_study_info = gwas_study_info |> 
    mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "lewy body dementia measurement",
                          "lewy body dementia"
         )) |>
      mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "sleep apnea measurement",
                          "sleep apnea"
         )) |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "sleep apnea during non-rem sleep|sleep apnea during rem sleep",
                          "sleep apnea")
  )
gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "contact dermatitis due to nickel",
                          "contact dermatitis"
         ))


gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "covid-19 symptoms measurement",
                          "covid-19")
  )

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "coronary atherosclerosis measurement",
                          "coronary atherosclerosis")
  ) 

3.14 Allergies

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "allergic contact dermatitis of eyelid",
                          "allergic contact dermatitis"
         ))


gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "seasonal allergic rhinitis",
                          "allergic rhinitis"
         ))

3.15 Irritable bowel syndrome

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "irritable bowel syndrome symptom measurement",
                          "irritable bowel syndrome"
         ))

3.16 Respiratory respiratory symptom

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "respiratory symptom change measurement" ,
                          "respiratory symptom measurement" 
         ))

3.17 Infertility

gwas_study_info = gwas_study_info |>
  mutate(collected_all_disease_terms = 
         stringr::str_replace_all(collected_all_disease_terms,
                          "tubal factor infertility",
                          "female infertility"
                          )) |>
  mutate(collected_all_disease_terms = 
                  stringr::str_replace_all(collected_all_disease_terms,
                          "azoospermia",
                          "male infertility"
                          )  )

3.18 Putting it all together

gwas_study_info = gwas_study_info |>
  rowwise() |>
  mutate(
    collected_all_disease_terms = paste0(
      unique(unlist(stringr::str_split(collected_all_disease_terms, ", "))),
      collapse = ", "
    )
  ) |>
  ungroup()

           
gwas_study_info$collected_all_disease_terms = stringr::str_trim(gwas_study_info$collected_all_disease_terms)
gwas_study_info$collected_all_disease_terms = sub(",$", "", gwas_study_info$collected_all_disease_terms)

n_studies_trait = gwas_study_info |>
  dplyr::filter(DISEASE_STUDY == T) |>
  dplyr::select(collected_all_disease_terms, PUBMED_ID) |>
  dplyr::distinct() |>
  dplyr::group_by(collected_all_disease_terms) |>
  dplyr::summarise(n_studies = dplyr::n()) |>
  dplyr::arrange(desc(n_studies))

head(n_studies_trait)
# A tibble: 6 × 2
  collected_all_disease_terms n_studies
  <chr>                           <int>
1 type 2 diabetes mellitus          149
2 asthma                            133
3 alzheimers disease                125
4 breast cancer                     115
5 major depressive disorder         110
6 schizophrenia                     106
dim(n_studies_trait)
[1] 2571    2
diseases <- stringr::str_split(pattern = ", ", 
                               gwas_study_info$collected_all_disease_terms)  |> 
            unlist() |>
            stringr::str_trim()

length(unique(diseases))
[1] 1812

4 Grouping - level 1

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms = collected_all_disease_terms)

4.0.1 Ontology help

library(httr)
library(jsonlite)


get_descendants <- function(url){
  
  terms <- c()

repeat {
  res <- GET(url)
  stop_for_status(res)
  data <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  
  terms <- c(terms, 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
  }
}
  
terms = unlist(terms)
terms = stringr::str_trim(tolower(terms))
terms = unique(terms)
  
print("Number of terms collected:")
print(length(terms))

print("\n Some example terms")
print(terms[1:5])

return(terms)


}

4.1 Cancers

4.1.1 Breast cancer

breast_cancer_terms <- grep("breast cancer", unique(diseases), value = T)

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(breast_cancer_terms, collapse = "|"),
                                   "breast cancer"
                          )  
        ) |>
   mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = "breast cancer in situ",
                                   "breast cancer"
                          )  
        )

4.1.2 Colorectal cancer

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

colorectal_cancer_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 106
[1] "\n Some example terms"
[1] "colorectal lymphoma"        "colorectal carcinoma"      
[3] "familial colorectal cancer" "malignant colon neoplasm"  
[5] "rectal cancer"             
colorectal_cancer_terms = stringr::str_replace_all(colorectal_cancer_terms,
                            "\\bcarcinoma",
                            "cancer")
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(colorectal_cancer_terms, collapse = "|"),
                                   "colorectal cancer"
                          )  
        )

4.1.3 Skin Cancer

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

skin_cancer_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 131
[1] "\n Some example terms"
[1] "sebaceous gland cancer"           "eyelid cancer"                   
[3] "cd4+/cd56+ hematodermic neoplasm" "primary cutaneous lymphoma"      
[5] "cutaneous melanoma"              
# plus skin carcinoma terms

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


skin_carcinoma_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 46
[1] "\n Some example terms"
[1] "skin appendage carcinoma"    "vulvar seborrheic keratosis"
[3] "non-melanoma skin carcinoma" "skin carcinoma in situ"     
[5] "eyelid carcinoma"           
skin_cancer_terms = c(skin_cancer_terms, skin_carcinoma_terms) 

skin_cancer_terms = stringr::str_replace_all(skin_cancer_terms,
                            "\\bcarcinoma",
                            "cancer")

skin_cancer_terms = unique(skin_cancer_terms)
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(skin_cancer_terms, collapse = "|"),
                                   "skin cancer"
                          )  
        )

4.1.4 Male reproductive organ cancer

male_repro_cancer_terms = c("metastatic prostate cancer",
                              "prostate cancer",
                            "scrotum cancer",
                            "epididymis cancer",
                            "penile cancer"
                              )

gwas_study_info = 
 gwas_study_info |>
 mutate(l1_all_disease_terms  = 
                  stringr::str_replace_all(l1_all_disease_terms,
                           pattern = paste0(male_repro_cancer_terms, collapse = "|"),
                          "male reproductive organ cancer"
                          ))

4.1.5 Female reproductive organ cancer

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

female_repro_cancer_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 252
[1] "\n Some example terms"
[1] "uterine cancer"                         
[2] "female reproductive endometrioid cancer"
[3] "ovarian cancer"                         
[4] "fallopian tube cancer"                  
[5] "paraurethral gland cancer"              
url <- "http://www.ebi.ac.uk/ols4/api/ontologies/ncit/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FNCIT_C181162/descendants"

female_repro_carcinoma_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 801
[1] "\n Some example terms"
[1] "cervical carcinoma"          "endometrial carcinoma"      
[3] "ovarian carcinoma"           "vulvar carcinoma"           
[5] "gestational choriocarcinoma"
female_repro_cancer_terms <- c(female_repro_cancer_terms,
                               female_repro_carcinoma_terms)

female_repro_cancer_terms = stringr::str_replace_all(female_repro_cancer_terms,
                            "\\bcarcinoma",
                            "cancer")

female_repro_cancer_terms = unique(female_repro_cancer_terms)

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(female_repro_cancer_terms, collapse = "|"),
                                   "female reproductive organ cancer"
                          )  
        )

4.1.6 Kidney cancer

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


kidney_cancer_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 51
[1] "\n Some example terms"
[1] "malignant cystic nephroma"       "kidney liposarcoma"             
[3] "renal pelvis carcinoma"          "congenital mesoblastic nephroma"
[5] "renal carcinoma"                
kidney_cancer_terms = stringr::str_replace_all(kidney_cancer_terms,
                            "\\bcarcinoma",
                            "cancer")
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(kidney_cancer_terms, collapse = "|"),
                                   "kidney cancer"
                          )  
        )

4.1.7 Liver cancer

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

liver_cancer_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 76
[1] "\n Some example terms"
[1] "carcinoma of liver and intrahepatic biliary tract"      
[2] "calcifying nested epithelial stromal tumor of the liver"
[3] "liver lymphoma"                                         
[4] "biliary tract cancer"                                   
[5] "liver sarcoma"                                          
liver_cancer_terms = stringr::str_replace_all(liver_cancer_terms,
                            "\\bcarcinoma",
                            "cancer")
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(liver_cancer_terms, collapse = "|"),
                                   "liver cancer"
                          )  
        )

4.1.8 Lung cancer

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

lung_cancer_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 63
[1] "\n Some example terms"
[1] "graham-boyle-troxell syndrome"      "malignant superior sulcus neoplasm"
[3] "lung carcinoma"                     "lung hilum cancer"                 
[5] "lung lymphoma"                     
lung_cancer_terms = stringr::str_replace_all(lung_cancer_terms,
                            "\\bcarcinoma",
                            "cancer")
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(lung_cancer_terms, collapse = "|"),
                                   "lung cancer"
                          )  
        )

4.1.9 Leukemia

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

leukemia_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 133
[1] "\n Some example terms"
[1] "chronic eosinophilic leukemia, not otherwise specified"
[2] "acute leukemia"                                        
[3] "mast-cell leukemia"                                    
[4] "lymphoid leukemia"                                     
[5] "myeloid leukemia"                                      
leukemia_terms = stringr::str_replace_all(leukemia_terms,
                            "\\bcarcinoma",
                            "cancer")
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(leukemia_terms, collapse = "|"),
                                   "leukemia"
                          )  
        )

4.1.10 Non-Hodgkins lymphoma

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

nhl_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 93
[1] "\n Some example terms"
[1] "b-cell non-hodgkins lymphoma" "lymphoma, aids-related"      
[3] "sezary's disease"             "acute lymphoblastic leukemia"
[5] "gastric non-hodgkin lymphoma"
nhl_terms = stringr::str_replace_all(leukemia_terms,
                            "\\bcarcinoma",
                            "cancer")
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(nhl_terms, collapse = "|"),
                                   "non-hodgkins lymphoma"
                          )  
        )

4.2 Allergies

allergy_terms <- grep("allergy", unique(diseases), value = T)

allergic_terms <- grep("allergic", unique(diseases), value = T) 
allergic_terms = allergic_terms[allergic_terms != "non-allergic rhinitis"]

eczema_terms <- grep("eczema", unique(diseases), value = T) 

allergy_terms <- c(allergy_terms, 
                   allergic_terms, 
                   eczema_terms)
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(allergy_terms, collapse = "|"),
                                   "allergic disease"
                          )  
        )

4.3 Infectious disease

4.3.1 Abscess

abscess_terms <- grep("abscess", unique(diseases), value = T)
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(abscess_terms, collapse = "|"),
                                   "abscess"
                          )  
        )

4.3.2 Staphylococcal skin infections

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


staph_skin_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 15
[1] "\n Some example terms"
[1] "staphyloenterotoxemia"           "staphylococcal pneumonia"       
[3] "staphylococcus aureus infection" "staphylococcal toxemia"         
[5] "staphylococcus aureus pneumonia"
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(staph_skin_terms, collapse = "|"),
                                   "staphylococcal skin infections"
                          )  
        )

4.3.3 Herpes

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = "herpes simplex infection",
                                   "herpesviridae infectious disease"
                          )  
        )

4.4 Prion disease

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

prion_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 13
[1] "\n Some example terms"
[1] "scrapie"                   "kuru"                     
[3] "inherited prion disease"   "creutzfeldt jacob disease"
[5] "prp systemic amyloidosis" 
gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(prion_terms, collapse = "|"),
                                   "prion disease"
                          )  
        )

4.5 Epilepsy

# juvenile absence epilepsy
# 
# juvenile myoclonic epilepsy

4.6 rheumatoid arthritis

ra_terms <- c("acpa-positive rheumatoid arthritis",
               "acpa-negative rheumatoid arthritis")

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(ra_terms, collapse = "|"),
                                   "rheumatoid arthritis"
                          )  
        )

4.7 Parkinson disease (PD)

pd_terms <- c("secondary parkinson disease",
               "young adult-onset parkinsonism",
              "parkinsons disease")

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(pd_terms, collapse = "|"),
                                   "parkinson disease"
                          )  
        )

4.8 orofacial cleft

cleft_terms <- c("cleft lip",
               "cleft palate")

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(cleft_terms, collapse = "|"),
                                   "orofacial cleft"
                          )  
        )

4.9 celiac disease

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = c("refractory celiac disease"),
                                   "celiac disease"
                          )  
        )

4.10 Obesity

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = c("morbid obesity|metabolically healthy obesity"),
                                   "obesity"
                          )  
        )

4.11 Diabetic eye disease

diabetic_eye_terms <- c("diabetic maculopathy",
                        "diabetic macular edema",
                        "diabetic retinopathy",
                        "proliferative diabetic retinopathy",
                         "non-proliferative diabetic retinopathy",
                        "diabetes mellitus type 2 associated cataract")


gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = paste0(diabetic_eye_terms, collapse = "|"),
                                   "diabetic eye disease"
                          )  
        )

gwas_study_info = 
gwas_study_info |> 
 mutate(l1_all_disease_terms  = 
          stringr::str_replace_all(l1_all_disease_terms ,
                                  pattern = "age of onset of type 2 diabetes mellitus",
                                   "type 2 diabetes mellitus"
                          )  
        )

?Maybe: could group further into hypersensitivity reaction disease (with drug hypersensitivity syndrome)

4.12 Putting it all together

gwas_study_info = gwas_study_info |>
  rowwise() |>
  mutate(
    l1_all_disease_terms = paste0(
      unique(unlist(stringr::str_split(l1_all_disease_terms, ", "))),
      collapse = ", "
    )
  ) |>
  ungroup()

gwas_study_info$l1_all_disease_terms = stringr::str_trim(gwas_study_info$l1_all_disease_terms)
gwas_study_info$l1_all_disease_terms = sub(",$", "", gwas_study_info$l1_all_disease_terms)

n_studies_trait = gwas_study_info |>
  dplyr::filter(DISEASE_STUDY == T) |>
  dplyr::select(l1_all_disease_terms, PUBMED_ID) |>
  dplyr::distinct() |>
  dplyr::group_by(l1_all_disease_terms) |>
  dplyr::summarise(n_studies = dplyr::n()) |>
  dplyr::arrange(desc(n_studies))

head(n_studies_trait)
# A tibble: 6 × 2
  l1_all_disease_terms      n_studies
  <chr>                         <int>
1 type 2 diabetes mellitus        149
2 asthma                          133
3 breast cancer                   127
4 alzheimers disease              125
5 major depressive disorder       110
6 schizophrenia                   106
dim(n_studies_trait)
[1] 2436    2
diseases <- stringr::str_split(pattern = ", ", 
                               gwas_study_info$l1_all_disease_terms)  |> 
            unlist() |>
            stringr::str_trim()

length(unique(diseases))
[1] 1709
# make frequency table
freq <- table(as.factor(diseases))

# sort in decreasing order
freq_sorted <- sort(freq, decreasing = TRUE)

# show top N, e.g. top 10
head(freq_sorted, 10)

                             chronic kidney disease              hypertension 
                   109388                     10828                      6995 
 type 2 diabetes mellitus major depressive disorder   coronary artery disease 
                      922                       471                       444 
            schizophrenia             breast cancer                    asthma 
                      356                       354                       346 
                 covid-19 
                      305 

5 (?) Even more grouping to maybe add later:

  • Cancer
  • Cardiovascular disease
  • Autoimmune disease
  • Allergy
  • Dementia
  • Substance abuse

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] data.table_1.17.8 dplyr_1.1.4       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] utf8_1.2.6         cachem_1.1.0       stringi_1.8.7      httpuv_1.6.16     
[29] xfun_0.52          getPass_0.2-4      fs_1.6.6           sass_0.4.10       
[33] cli_3.6.5          withr_3.0.2        magrittr_2.0.3     ps_1.9.1          
[37] grid_4.3.1         digest_0.6.37      processx_3.8.6     rstudioapi_0.17.1 
[41] lifecycle_1.0.4    vctrs_0.6.5        evaluate_1.0.4     glue_1.8.0        
[45] farver_2.1.2       whisker_0.4.1      rmarkdown_2.29     tools_4.3.1       
[49] pkgconfig_2.0.3    htmltools_0.5.8.1