Last updated: 2025-09-10

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 a27c404. 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_cat/
    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/gwas_study_info_trait_ontology_info_l1.csv
    Ignored:    output/gwas_study_info_trait_ontology_info_l2.csv
    Ignored:    output/trait_ontology/
    Ignored:    renv/

Untracked files:
    Untracked:  code/get_term_descendants.R
    Untracked:  data/gbd/
    Untracked:  data/who/

Unstaged changes:
    Modified:   analysis/disease_inves_by_ancest.Rmd
    Modified:   analysis/index.Rmd
    Deleted:    analysis/level_1_disease_group.Rmd
    Modified:   analysis/level_2_disease_group.Rmd
    Deleted:    analysis/non_ontology_trait_collapse.Rmd
    Deleted:    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/level_1_disease_group_non_cancer.Rmd) and HTML (docs/level_1_disease_group_non_cancer.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
html 2250e22 IJbeasley 2025-09-10 Build site.
Rmd e3de56c IJbeasley 2025-09-10 Update cardiac disease grouping
html e713c34 IJbeasley 2025-09-10 Build site.
Rmd 934b11f IJbeasley 2025-09-10 workflowr::wflow_publish("analysis/level_1_disease_group_non_cancer.Rmd")

1 Set up

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

1.1 Ontology help - for getting disease subtypes

source(here::here("code/get_term_descendants.R"))
gwas_study_info <- fread(here::here("output/gwas_cat/gwas_study_info_disease_trait_simplified.csv"))

2 Initial summary

2.1 Objectives of this analysis:

Level 1 disease grouping: - collapse disease causes, e.g. contact dermatitis due to nickel to contact dermatitis - collapse disease subtypes, e.g. bipolar I and bipolar II to bipolar disorder - collapse disease onset times, e.g. early-onset alzheimers disease and late-onset alzheimers disease to alzheimers disease - collapse disease stages

2.2 Grouping - level 1 set up

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms = collected_all_disease_terms)

2.3 Initial summary - number of unique study 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          145
2 alzheimers disease                116
3 breast cancer                     112
4 asthma                            110
5 major depressive disorder         108
6 schizophrenia                     103
dim(n_studies_trait)
[1] 3083    2

2.3.1 When separate studies with multiple terms

diseases <- stringr::str_split(pattern = ", ", 
 gwas_study_info$collected_all_disease_terms[gwas_study_info$collected_all_disease_terms != ""])  |> 
            unlist() |>
            stringr::str_trim()

length(unique(diseases))
[1] 2196

3 Disease stage grouping

3.1 Chronic kidney disease (CKD)

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "chronic kidney disease stage 5|chronic kidney disease stage 4",
                          "chronic kidney disease"
         ))


gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "stage 5 chronic kidney disease",
                          "chronic kidney disease"
         ))

4 Disease cause grouping

4.1 Contact dermatitis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "contact dermatitis due to nickel",
                          "contact dermatitis"
         ))

5 Disease subtype grouping (non-cancer)

5.1 Abortion

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "habitual abortion|abortion|spontaneous loss of pregnancy|incomplete loss of pregnancy",
                          "loss of pregnancy"
         ))
# exact synonyms (to avoid partial matches
# https://www.ebi.ac.uk/ols4/ontologies/efo/classes/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_1001491?lang=en

5.2 Acute pancreatitis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "asparaginase-induced acute pancreatitis",
                          "acute pancreatitis"
         ))

5.3 Alopecia

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

alopecia_terms <- get_descendants(url)

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(alopecia_terms, collapse = "(?=,|$)|\\b"),
                          "alopecia"
         ))

5.4 Alcohol-use disorders

alchol_use_disorder_terms <- c("alcohol dependence",
                             "alcohol withdrawal",
                             "alcohol withdrawal delirium",
                             "alcohol abuse",
                             "alcohol-related disorders delirium",
                             "alcohol use disorder",
                             "addictive alcohol use"
                             )

gwas_study_info = gwas_study_info |>
      mutate(l1_all_disease_terms = 
           stringr::str_replace_all(l1_all_disease_terms,
                            paste0(alchol_use_disorder_terms, collapse = "(?=,|$)|\\b"),
                            "alcohol-related disorders"
           ))

gwas_study_info = gwas_study_info |>
      mutate(l1_all_disease_terms = 
           stringr::str_replace_all(l1_all_disease_terms,
                            paste0(alchol_use_disorder_terms, collapse = "(?=,|$)|\\b"),
                            "alcohol-related disorders"
           ))

5.5 Alcoholic liver disease

alcoholic_liver_disease_terms <- c("alcoholic liver cirrhosis",
                                   "alcoholic fatty liver disease",
                                   "alcoholic hepatitis"
                                   )


gwas_study_info = gwas_study_info |>
      mutate(l1_all_disease_terms = 
           stringr::str_replace_all(l1_all_disease_terms,
                             paste0(alcoholic_liver_disease_terms, collapse = "(?=,|$)|\\b"),
                            "alcoholic liver disease"
           ))

5.6 Alzheimer’s disease

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "early-onset alzheimers disease|late-onset alzheimers disease",
                          "alzheimers disease"
         ))

5.7 Allergic contact dermatitis

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

5.8 Allergic rhinitis

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

5.9 Astigmatism

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "corneal astigmatism",
                          "astigmatism"
         ))

5.10 Asthma

gwas_study_info = gwas_study_info |>
      mutate(l1_all_disease_terms  = 
           stringr::str_replace_all(l1_all_disease_terms,
                            "atopic asthma|chronic obstructive asthma",
                            "asthma"
           )) |>
    mutate(l1_all_disease_terms  = 
           stringr::str_replace_all(l1_all_disease_terms,
                            "childhood onset asthma|adult onset asthma|aspirin-induced asthma",
                            "asthma"
           ))

5.11 Autoimmune pancreatitis

gwas_study_info = gwas_study_info |>
      mutate(l1_all_disease_terms  = 
           stringr::str_replace_all(l1_all_disease_terms,
                            "autoimmune pancreatitis type 1",
                            "autoimmune pancreatitis"
           )) 

5.12 Back pain

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "low back pain",
                          "back pain"
         ))

5.13 Bipolar disorder

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

5.14 Bundle branch block

bundle_branch_block_terms <- c("left bundle branch block",
                             "right bundle branch block",
                             "complete right bundle branch block"
                             )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(bundle_branch_block_terms, collapse = "(?=,|$)|\\b"),
                          "bundle branch block"
         )
  )

5.15 Carotid artery disease

carotid_artery_disease_terms <- c("carotid artery thrombosis",
                             "carotid atherosclerosis"
                             )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(carotid_artery_disease_terms, collapse = "(?=,|$)|\\b"),
                          "carotid artery disease"
         ))

5.16 Celiac disease

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

5.17 Chronic pancreatitis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "thiopurine immunosuppressant-induced pancreatitis|non-alcoholic pancreatitis",
                          "chronic pancreatitis"
         ))

5.18 Chronic rhinosinusitis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "chronic rhinosinusitis with nasal polyps",
                          "chronic rhinosinusitis"
         ))

5.19 Coronary artery disease

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

coronary_artery_disease_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 16
[1] "\n Some example terms"
[1] "non-obstructive coronary artery disease"
[2] "myocardial ischemia"                    
[3] "intermediate coronary syndrome"         
[4] "coronary thrombosis"                    
[5] "coronary aneurysm"                      
gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(coronary_artery_disease_terms, collapse = "(?=,|$)|\\b"),
                          "coronary artery disease"
         ))

5.20 Congestive heart failure

congestive_heart_failure_terms <- c("systolic heart failure",
                                 "diastolic heart failure",
                                 "cor pulmonale",
                                 "congenital heart disease",
                                 "chronic pulmonary heart disease"
                                 )


gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(congestive_heart_failure_terms, collapse = "(?=,|$)|\\b"),
                          "congestive heart failure"
         ))

5.21 Creutzfeldt jacob disease

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "sporadic creutzfeld jacob disease",
                          "creutzfeldt jacob disease"
         ))

5.22 Dental caries

dental_caries_terms <- c("pit and fissure surface dental caries",
                         "smooth surface dental caries",
                         "primary dental caries",
                         "enamel caries",
                         "permanent dental caries"
                         )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(dental_caries_terms, collapse = "(?=,|$)|\\b"),
                          "dental caries"
         )
)

5.23 Drug allergy

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "beta-lactam allergy",
                          "drug allergy"
         ))

5.24 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"
           )  
  )

5.25 Diabetic neuropathy

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "diabetic polyneuropathy",
                          "diabetic neuropathy"
         ))

5.26 Food allergy

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "peanut allergy|milk allergy|egg allergy|wheat allergic reaction",
                          "food allergy"
         ))

5.27 Glaucoma

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

glaucoma_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 19
[1] "\n Some example terms"
[1] "pigmentary glaucoma"    "open-angle glaucoma"    "hereditary glaucoma"   
[4] "angle-closure glaucoma" "phacogenic glaucoma"   
gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(glaucoma_terms, collapse = "(?=,|$)|\\b"),
                          "glaucoma"
         ))

5.28 Heart block

heart_block_terms <- c("first degree atrioventricular block",
                      "second degree atrioventricular block",
                      "third-degree atrioventricular block",
                      "bundle branch block"
                      )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(heart_block_terms, collapse = "(?=,|$)|\\b"),
                          "heart block"
         ))

5.29 Hemolytic anemia

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


hemolytic_anemia_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 76
[1] "\n Some example terms"
[1] "paroxysmal nocturnal hemoglobinuria"        
[2] "non-autoimmune hemolytic anemia"            
[3] "6-phosphogluconate dehydrogenase deficiency"
[4] "hereditary stomatocytosis"                  
[5] "autoimmune hemolytic anemia"                
gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(hemolytic_anemia_terms, collapse = "(?=,|$)|\\b"),
                          "hemolytic anemia"
         ))

5.30 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"
                          )  
        )

5.31 Hypertension

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

hypertension_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 46
[1] "\n Some example terms"
[1] "secondary hypertension"           "treatment-resistant hypertension"
[3] "ocular hypertension"              "malignant hypertension"          
[5] "intracranial hypertension"       
hypertension_terms = c("primary hypertension",
                      hypertension_terms
                      )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(hypertension_terms, collapse = "(?=,|$)|\\b"),
                          "hypertension"
         ))

5.32 HIV

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

5.33 Hyperlipidemia

hyperlipidemia_terms <- c("hypercholesterolemia",
                         "familial hypercholesterolemia",
                         "familial hyperlipidemia"
                         )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(hyperlipidemia_terms, collapse = "(?=,|$)|\\b"),
                          "hyperlipidemia"
         ))

5.34 Inborn errors of metabolism

inborn_error_metab <- c("inborn disorder of amino acid metabolism",
                        "inborn disorder of amino acid transport",
                        "inborn disorder of porphyrin metabolism",
                        "inborn carbohydrate metabolic disorder",
                        "familial lipoprotein lipase deficiency",
                        "lactose intolerance",
                        "hereditary hemochromatosis",
                        "alpha 1-antitrypsin deficiency",
                        "urea cycle disorder",
                        "gaucher disease",
                        "plasma protein metabolism disease",
                        "disorder of metabolite absorption and transport")

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(inborn_error_metab, collapse = "(?=,|$)|\\b"),
                          "inborn errors of metabolism"
         ))

5.35 Infectious meningitis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "bacterial meningitis|pneumococcal meningitis|viral meningitis",
                          "infectious meningitis"
         ))

5.36 Infertility (female & male)

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

5.37 Influenza a (h1n1) (subset of influenza)

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

5.38 Juvenile idiopathic arthritis

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

5.39 Lewy body dementia

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "lewy body attribute",
                          "lewy body dementia"
         ))

5.40 Malaria

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "plasmodium falciparum malaria|plasmodium vivax malaria",
                          "malaria"
         ))

5.41 Methamphetamine use disorders

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "methamphetamine dependence|methamphetamine-induced psychosis",
                          "methamphetamine use disorders"
         ))

5.42 Migrane

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "migraine disorder|migraine with aura|migraine without aura",
                          "migraine"
         ))

5.43 Multiple sclerosis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "relapsing-remitting multiple sclerosis",
                          "multiple sclerosis"
         ))

5.44 Myocardial infarction

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

myocardial_infarction_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 7
[1] "\n Some example terms"
[1] "inferior myocardial infarction"                                                     
[2] "anterolateral myocardial infarction"                                                
[3] "subsequent st elevation (stemi) and non-st elevation (nstemi) myocardial infarction"
[4] "acute myocardial infarction"                                                        
[5] "acute anterolateral myocardial infarction"                                          
gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(myocardial_infarction_terms, collapse = "(?=,|$)|\\b"),
                          "myocardial infarction"
         ))

5.45 Photosensitivity disease

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

5.46 Phobic disorder

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

phobic_disorder_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 11
[1] "\n Some example terms"
[1] "specific phobia"         "social anxiety disorder"
[3] "agoraphobia"             "nosophobia"             
[5] "flying phobia"          
gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(phobic_disorder_terms, collapse = "(?=,|$)|\\b"),
                          "phobic disorder"
         ))

5.47 Hereditary heterochromatosis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "hereditary hemochromatosis type 1",
                          "hereditary hemochromatosis"
         ))

5.48 Myasthenia gravis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "late-onset myasthenia gravis",
                          "myasthenia gravis"
         ))

5.49 Neuromyelitis optica

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "aqp4-igg-negative neuromyelitis optica|aqp4-igg-positive neuromyelitis optica",
                          "neuromyelitis optica"
         ))

5.50 Neurofibromatosis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "neurofibromatosis type 1|neurofibromatosis type 2",
                          "neurofibromatosis"
         ))

5.51 Non-alcoholic fatty liver disease (NAFLD)

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "non-alcoholic steatohepatitis|non-alcoholic liver disease",
                          "non-alcoholic fatty liver disease"
         ))

5.52 Obesity

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

5.53 Pericardium disorder

pericardium_disorder_terms <- c("pericarditis",
                               "pericardial effusion"
                               )

5.54 Psoriasis

psoriasis_terms <- c("psoriasis vulgaris",
                      "psoriasis area and severity index",
                      "cutaneous psoriasis",
                      "psoriatic arthritis",
                     "parapsoriasis")


gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(psoriasis_terms, collapse = "(?=,|$)|\\b"),
                          "psoriasis")
  )

5.55 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 = "(?=,|$)|\\b"),
                                   "rheumatoid arthritis"
                          )  
        )

5.56 Scoliosis

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "adolescent idiopathic scoliosis",
                          "scoliosis")
         )

5.57 Sickle cell disease

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "sickle cell anemia",
                          "sickle cell disease and related diseases")
         )

5.58 Sleep apnea

sleep_apnea_terms <- c("sleep apnea measurement during non-rem sleep",
                      "sleep apnea measurement during rem sleep",
                      "obstructive sleep apnea")

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(sleep_apnea_terms, collapse = "(?=,|$)|\\b"),
                          "sleep apnea")
  )

5.59 Staphylococcus aureus infection

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "methicillin-resistant staphylococcus aureus infection",
                          "staphylococcus aureus infection"
         ))

5.60 Stroke

https://www.ebi.ac.uk/ols4/ontologies/efo/classes/http%253A%252F%252Fwww.ebi.ac.uk%252Fefo%252FEFO_0000712?lang=en

hemorrhage_terms <- c("intracerebral hemorrhage",
                      "non-lobar intracerebral hemorrhage",
                      "lobar intracerebral hemorrhage")

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(hemorrhage_terms, collapse = "(?=,|$)|\\b"),
                          "hemorrhagic stroke")
  )

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "stroke outcome|large artery stroke|small vessel stroke|ischemic stroke|stroke disorder|cardioembolic stroke",
                          "stroke")
  )


gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "post-operative stroke",
                          "post-operative, stroke")
  )

5.61 Tacycardia

tacycardia_terms <- c("paroxysmal tachycardia",
                     "ventricular tachycardia",
                     "supraventricular tachycardia",
                     "paroxysmal supraventricular tachycardia",
                     "paroxysmal ventricular tachycardia"
                     )


gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(tacycardia_terms, collapse = "(?=,|$)|\\b"),
                          "tacycardia"
         )
  )

5.62 Systemic scleroderma

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

scleroderma_terms <- get_descendants(url)
[1] "Number of terms collected:"
[1] 5
[1] "\n Some example terms"
[1] "limited scleroderma"                                        
[2] "anti-topoisomerase-i-antibody-positive systemic scleroderma"
[3] "anti-centromere-antibody-positive systemic scleroderma"     
[4] "diffuse scleroderma"                                        
[5] "limited cutaneous systemic sclerosis"                       
gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(scleroderma_terms, collapse = "(?=,|$)|\\b"),
                          "systemic scleroderma"
         ))

5.63 Tenosynovitis

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

5.64 Type 1 diabetes

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "latent autoimmune diabetes in adults",
                          "type 1 diabetes mellitus"
         ))

5.65 Thrombocytopenia

thrombocytopenia_terms <- c("thrombocytopenia 4",
                           "acquired thrombocytopenia",
                           "primary thrombocytopenia"
                           )

5.66 Tinea

tinea_terms <- c("tinea pedis",
                 "tinea unguium",
                 "dermatophytosis"
                 )


gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          pattern = paste0(tinea_terms, collapse = "(?=,|$)|\\b"),
                          "tinea"
         ))

5.67 Vitamin b deficiency

gwas_study_info = gwas_study_info |>
  mutate(l1_all_disease_terms  = 
         stringr::str_replace_all(l1_all_disease_terms,
                          "vitamin b12 deficiency",
                          "vitamin b deficiency"
         ))

6 Final summary - number of unique study terns

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        145
2 asthma                          131
3 alzheimers disease              124
4 breast cancer                   112
5 major depressive disorder       108
6 schizophrenia                   103
dim(n_studies_trait)
[1] 2901    2

6.0.1 When separate studies with multiple terms

diseases <- stringr::str_split(pattern = ", ", 
                               gwas_study_info$l1_all_disease_terms[gwas_study_info$l1_all_disease_terms != ""])  |> 
            unlist() |>
            stringr::str_trim()


test <- data.frame(trait = unique(diseases))

length(unique(diseases))
[1] 2029
# 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  type 2 diabetes mellitus 
                    10835                      7093                       922 
  coronary artery disease major depressive disorder        alzheimers disease 
                      514                       471                       422 
                   asthma             schizophrenia                  covid-19 
                      357                       356                       305 
            breast cancer 
                      270 

6.0.2 Save the updated gwas_study_info with harmonized disease terms

fwrite(gwas_study_info,
        here::here("output/gwas_cat/gwas_study_info_group_l1.csv")
         )

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     data.table_1.17.8
[5] dplyr_1.1.4       workflowr_1.7.1  

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