Last updated: 2025-10-27

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 0e28f49. 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:    analysis/.DS_Store
    Ignored:    ancestry_dispar_env/
    Ignored:    data/.DS_Store
    Ignored:    data/cohort/
    Ignored:    data/gbd/.DS_Store
    Ignored:    data/gbd/IHME-GBD_2021_DATA-d8cf695e-1.csv
    Ignored:    data/gbd/ihme_gbd_2019_global_disease_burden_rate_all_ages.csv
    Ignored:    data/gbd/ihme_gbd_2019_global_paf_rate_percent_all_ages.csv
    Ignored:    data/gbd/ihme_gbd_2021_global_disease_burden_rate_all_ages.csv
    Ignored:    data/gbd/ihme_gbd_2021_global_paf_rate_percent_all_ages.csv
    Ignored:    data/gwas_catalog/
    Ignored:    data/icd/.DS_Store
    Ignored:    data/icd/IHME_GBD_2019_COD_CAUSE_ICD_CODE_MAP_Y2020M10D15.XLSX
    Ignored:    data/icd/IHME_GBD_2019_NONFATAL_CAUSE_ICD_CODE_MAP_Y2020M10D15.XLSX
    Ignored:    data/icd/IHME_GBD_2021_COD_CAUSE_ICD_CODE_MAP_Y2024M05D16.XLSX
    Ignored:    data/icd/IHME_GBD_2021_NONFATAL_CAUSE_ICD_CODE_MAP_Y2024M05D16.XLSX
    Ignored:    data/icd/UK_Biobank_master_file.tsv
    Ignored:    data/icd/cdc_valid_icd10_Sep_23_2025.xlsx
    Ignored:    data/icd/cdc_valid_icd9_Sep_23_2025.xlsx
    Ignored:    data/icd/manual_disease_icd10_mappings.xlsx
    Ignored:    data/icd/phecode_international_version_unrolled.csv
    Ignored:    data/icd/semiautomatic_ICD-pheno.txt
    Ignored:    data/who/
    Ignored:    output/.DS_Store
    Ignored:    output/abstracts/
    Ignored:    output/doccano/
    Ignored:    output/fulltexts/
    Ignored:    output/gwas_cat/
    Ignored:    output/gwas_cohorts/
    Ignored:    output/icd_map/
    Ignored:    output/trait_ontology/
    Ignored:    pubmedbert-cohort-ner-model/
    Ignored:    pubmedbert-cohort-ner/
    Ignored:    r-spacyr/
    Ignored:    renv/
    Ignored:    venv/

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/correcting_cohort_names.Rmd
    Modified:   analysis/disease_inves_by_ancest.Rmd
    Modified:   analysis/gbd_data_plots.Rmd
    Modified:   analysis/group_cancer_diseases.Rmd
    Modified:   analysis/gwas_to_gbd.Rmd
    Modified:   analysis/level_1_disease_group_non_cancer.Rmd
    Modified:   analysis/level_2_disease_group.Rmd
    Modified:   analysis/map_trait_to_icd10.Rmd
    Modified:   analysis/trait_ontology_categorization.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/get_dbgap_ids.Rmd) and HTML (docs/get_dbgap_ids.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 0e28f49 IJbeasley 2025-10-27 Compare dbgap sources
html dcc17fc IJbeasley 2025-10-27 Build site.
Rmd a418670 IJbeasley 2025-10-27 Testing overlap with annotation + text mining dbgap
html 3feefe9 IJbeasley 2025-10-20 Build site.
Rmd bdb7fae IJbeasley 2025-10-20 Extracting all dbgap id info
html 47e3b12 IJbeasley 2025-10-20 Build site.
Rmd 5909160 IJbeasley 2025-10-20 Extracting dbgap ids

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

Get pubmed ids for disease studies

gwas_study_info <- data.table::fread(here::here("output/gwas_cat/gwas_study_info_trait_group_l2.csv"))

gwas_study_info = gwas_study_info |>
  dplyr::rename_with(~ gsub(" ", "_", .x))

gwas_study_info =
  gwas_study_info |>
  dplyr::filter(DISEASE_STUDY == T)

all_pmids <-
unique(gwas_study_info$PUBMED_ID)

print(length(all_pmids))
[1] 4511

Get dbGaP ids for pubmed ids

Extract internal dbGAP ids

get_internal_dbgap_ids = function(pubmed_id) {

dbgap_links <- entrez_link(
            dbfrom = "pubmed",
            db = "gap",
            id = pubmed_id
)

dbgap_ids <- unlist(dbgap_links$links$pubmed_gap)

return(data.frame(PUBMED_ID = pubmed_id,
                  DBGAP_ID = str_flatten(dbgap_ids,
                                         collapse = ",",
                                         na.rm = TRUE)
                  )
)

}


pubmed_dbgap_mapping <-
purrr::map(all_pmids,
           get_internal_dbgap_ids
           ) |>
  dplyr::bind_rows()

Save dbGaP id mapping

data.table::fwrite(pubmed_dbgap_mapping,
                   here::here("output/gwas_cohorts/gwas_study_dbgap_ids.csv")
                   )

Percentage of studies with dbGAP ids

# load previously saved mapping
pubmed_dbgap_mapping <- data.table::fread(
  here::here("output/gwas_cohorts/gwas_study_dbgap_ids.csv")
)

n_with_dbgap = pubmed_dbgap_mapping |>
  dplyr::filter(DBGAP_ID != "") |>
  nrow()

percent_with_dbgap = n_with_dbgap / nrow(pubmed_dbgap_mapping) * 100

percent_with_dbgap
[1] 8.778541
# a lot of internal dbgap ids are not able be retrieve study accessions
# sad
# ? perhaps because they are old dbgap versions? 

Extract dbGAP study accessions

dbgap_ids = pubmed_dbgap_mapping$DBGAP_ID

dbgap_ids = dbgap_ids[dbgap_ids != ""]

dbgap_ids = dbgap_ids |>
  strsplit(",") |>
  unlist() |>
  unique()


get_dbgap_accession = function(internal_dbgap_id) {
  
  
  summary = entrez_summary(db = "gap", 
                           id = internal_dbgap_id)
  
  
  accession = summary$d_study_results$d_study_id
  
  return(data.frame(
    INTERNAL_DBGAP_ID = internal_dbgap_id,
    DBGAP_ACCESSION = str_flatten(accession, 
                                  collapse = ",", 
                                  na.rm = TRUE)
  )
  )

} 

dbgap_accession_mapping <-
  purrr::map(dbgap_ids,
             get_dbgap_accession
             ) |>
  dplyr::bind_rows()

pubmed_dbgap_mapping =
  pubmed_dbgap_mapping |>
  tidyr::separate_longer_delim(cols = "DBGAP_ID", 
                               delim = ",")

dbgap_accession_mapping = 
  dbgap_accession_mapping |>
  tidyr::separate_longer_delim(cols = "INTERNAL_DBGAP_ID", 
                               delim = ",")

dbgap_accession_mapping = 
left_join(pubmed_dbgap_mapping, 
     dbgap_accession_mapping,
     by = c("DBGAP_ID" = "INTERNAL_DBGAP_ID")
     ) 

Save dbGaP accession mapping

  data.table::fwrite(
    dbgap_accession_mapping,
     here::here("output/gwas_cohorts/gwas_study_dbgap_accessions.csv")
                     )

Percentage of studies with dbGaP accessions

# load previously saved mapping
dbgap_accession_mapping <- data.table::fread(
  here::here("output/gwas_cohorts/gwas_study_dbgap_accessions.csv")
)

# compress to one row per pubmed id
dbgap_accession_mapping =
  dbgap_accession_mapping |>
  group_by(PUBMED_ID) |>
  summarise(DBGAP_ACCESSION = str_flatten(unique(DBGAP_ACCESSION),
                                         collapse = ",",
                                         na.rm = TRUE),
            DBGAP_ID = str_flatten(unique(DBGAP_ID),
                                         collapse = ",",
                                         na.rm = TRUE)
            )

n_with_dbgap_accession = dbgap_accession_mapping |>
  dplyr::filter(DBGAP_ACCESSION != "") |>
  nrow()

percent_with_dbgap_accession = n_with_dbgap_accession / nrow(pubmed_dbgap_mapping) * 100

percent_with_dbgap_accession
[1] 4.832631

Do the reverse - dbGaP to pubmed

dbgap_to_pubmed_id <- function(dbgap_accession) {
  
  res <- entrez_search(db = "gap",
                       term = paste0(dbgap_accession, "[STID]"))
  
  links <- entrez_link(dbfrom = "gap",
                       db = "pubmed",
                       id = res$ids
                       )
  
  pmids <- unlist(links$links$gap_pubmed)
  
  return(data.frame(
    DBGAP_ACCESSION = dbgap_accession,
    DBGAP_ID = str_flatten(res$ids,
                            collapse = ",",
                            na.rm = TRUE),
    PUBMED_ID = str_flatten(pmids,
                            collapse = ",",
                            na.rm = TRUE)
  )
  )
  
}

safe_dbgap_to_pubmed_id <- purrr::possibly(dbgap_to_pubmed_id,
                                        otherwise = data.frame(
                                          DBGAP_ACCESSION = NA,
                                          DBGAP_ID = NA,
                                          PUBMED_ID = NA
                                        ))

# get known dbgap accessions from gwas study info
cohort_info <- readxl::read_xlsx(here::here("data/cohort/cohort_desc.xlsx"),
                                 sheet = 1)
dbgap_accessions <- 
  c(cohort_info$dbGaP[cohort_info$dbGaP != "" & !is.na(cohort_info$dbGaP)],
    dbgap_accession_mapping$DBGAP_ACCESSION[dbgap_accession_mapping$DBGAP_ACCESSION != ""]
    )

dbgap_accessions <- unlist(strsplit(dbgap_accessions, ","))

dbgap_accessions <- unique(dbgap_accessions)



dbgap_to_pubmed_mapping <-
  purrr::map(dbgap_accessions,
             safe_dbgap_to_pubmed_id
             ) |>
  dplyr::bind_rows()

dbgap_to_pubmed_mapping = 
dbgap_to_pubmed_mapping |>
  filter(!is.na(PUBMED_ID)) |>
  tidyr::separate_longer_delim(cols = "PUBMED_ID", delim = ",")

dbgap_accession_mapping =
  dbgap_accession_mapping |>
  mutate(DBGAP_ACCESSION = as.character(DBGAP_ACCESSION)) 

dbgap_to_pubmed_mapping =
  dbgap_to_pubmed_mapping |>
  mutate(PUBMED_ID = as.numeric(PUBMED_ID))

combined_dbgap_pubmed_mapping =
bind_rows(
dbgap_accession_mapping,
dbgap_to_pubmed_mapping)

combined_dbgap_pubmed_mapping =
combined_dbgap_pubmed_mapping |>
  distinct()

combined_dbgap_pubmed_mapping =
combined_dbgap_pubmed_mapping |>
  filter(!(DBGAP_ID == "" & is.na(DBGAP_ACCESSION))
         )

combined_dbgap_pubmed_mapping =
  combined_dbgap_pubmed_mapping |>
  filter(!(is.na(PUBMED_ID)))

# filter for pmids in gwas study info
combined_dbgap_pubmed_mapping =
  combined_dbgap_pubmed_mapping |>
  filter(PUBMED_ID %in% all_pmids)

combined_dbgap_pubmed_mapping = 
  combined_dbgap_pubmed_mapping |>
  arrange(PUBMED_ID)

combined_dbgap_pubmed_mapping =
  combined_dbgap_pubmed_mapping |>
  mutate(DBGAP_ACCESSION = stringr::str_remove_all(pattern = "^,|,$", 
                                                   DBGAP_ACCESSION),
         DBGAP_ID = stringr::str_remove_all(pattern = "^,|,$", 
                                            DBGAP_ID)
         )

combined_dbgap_pubmed_mapping =
  combined_dbgap_pubmed_mapping |>
  group_by(PUBMED_ID) |>
  summarise(
    DBGAP_ACCESSION = str_flatten(unique(
                                 unlist(strsplit(DBGAP_ACCESSION, ","))
                                       ),
                                 collapse = ",",
                                 na.rm = TRUE),
    DBGAP_ID = str_flatten(unique(
                                 unlist(strsplit(DBGAP_ID, ","))
                                 ),
                                 collapse = ",",
                                 na.rm = TRUE)
    )

Save complete dbGaP to pubmed mapping

data.table::fwrite(
    combined_dbgap_pubmed_mapping,
     here::here("output/gwas_cohorts/gwas_study_combined_dbgap_pubmed_mapping.csv")
                     )

Percentage now of studies with dbGaP accessions

# load previously saved mapping
combined_dbgap_pubmed_mapping <- data.table::fread(
  here::here("output/gwas_cohorts/gwas_study_combined_dbgap_pubmed_mapping.csv")
)

n_studies_with_dbgap =
combined_dbgap_pubmed_mapping |>
  filter(!(DBGAP_ACCESSION == "" & DBGAP_ID == "")) |>
  nrow()

n_studies_with_dbgap / nrow(pubmed_dbgap_mapping) * 100
[1] 12.65795

Compare dbgap retrieved via extracting full text vs via entrez

combined_dbgap_pubmed_mapping <- data.table::fread(
  here::here("output/gwas_cohorts/gwas_study_combined_dbgap_pubmed_mapping.csv")
)

combined_dbgap_pubmed_mapping =
  combined_dbgap_pubmed_mapping |>
  select(pmid = PUBMED_ID,
         dbgap_annotation = DBGAP_ACCESSION
         ) |>
  distinct()

combined_dbgap_pubmed_mapping = 
  combined_dbgap_pubmed_mapping |>
  filter(!is.na(dbgap_annotation) & dbgap_annotation != "") |>
  summarise(dbgap_annotation = str_flatten(unique(dbgap_annotation),
                                             collapse = "|",
                                             na.rm = TRUE),
            .by = pmid
            )

dbgap_text <- data.table::fread(
                   here::here("output/gwas_cat/gwas_study_dbgap_ega_sentences.csv")
)

pmid_to_pmcid = data.table::fread(
  here::here("output/gwas_cat/gwas_pubmed_to_pmcid_mapping.csv")
)

dbgap_text <- data.table::fread(
                   here::here("output/gwas_cat/gwas_study_dbgap_ega_sentences.csv")
)

dbgap_text <-
  dbgap_text |>
  select(dbgap_extracted = dbgap_id,
         pmcid
         ) |>
  filter(dbgap_extracted != "") 

dbgap_text =
  dbgap_text |>
  group_by(pmcid) |>
  summarise(dbgap_extracted = str_flatten(unique(dbgap_extracted),
                                          collapse = "|",
                                          na.rm = TRUE)
            )

dbgap_text =
  left_join(dbgap_text,
            pmid_to_pmcid |> rename(pmcid = pmcids,
                                    pmid = pmids),
            by = "pmcid"
            ) 

comparison_df =
  full_join(
    combined_dbgap_pubmed_mapping,
    dbgap_text,
    by = c("pmid")
  )

# overlaps
comparison_df |>
  filter(dbgap_annotation != "" &
         dbgap_extracted != ""
         ) |> 
  nrow()
[1] 20
# only in annotation
comparison_df |>
  filter(dbgap_annotation != "" &
         (is.na(dbgap_extracted) | dbgap_extracted == "")
         ) |> 
  nrow()
[1] 152
# only in extracted
comparison_df |>
  filter((is.na(dbgap_annotation) | dbgap_annotation == "") &
         dbgap_extracted != ""
         ) |> 
  nrow()
[1] 381

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] stringr_1.5.2     purrr_1.1.0       rentrez_1.2.4     data.table_1.17.8
[5] dplyr_1.1.4       workflowr_1.7.1  

loaded via a namespace (and not attached):
 [1] jsonlite_2.0.0    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.4       jquerylib_0.1.4   yaml_2.3.10       fastmap_1.2.0    
[13] here_1.0.1        R6_2.6.1          generics_0.1.4    knitr_1.50       
[17] XML_3.99-0.19     tibble_3.3.0      rprojroot_2.1.0   bslib_0.9.0      
[21] pillar_1.11.1     rlang_1.1.6       cachem_1.1.0      stringi_1.8.7    
[25] httpuv_1.6.16     xfun_0.53         getPass_0.2-4     fs_1.6.6         
[29] sass_0.4.10       cli_3.6.5         withr_3.0.2       magrittr_2.0.4   
[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.5    glue_1.8.0       
[41] whisker_0.4.1     rmarkdown_2.30    httr_1.4.7        tools_4.3.1      
[45] pkgconfig_2.0.3   htmltools_0.5.8.1