Last updated: 2022-06-16

Checks: 5 2

Knit directory: codemapper_notes/

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


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

The global environment had objects present when the code in the R Markdown file was run. These objects 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. Use wflow_publish or wflow_build to ensure that the code is always run in an empty environment.

The following objects were defined in the global environment when these results were created:

Name Class Size
install_codemapper function 1.2 Kb

The command set.seed(20210923) 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 ef137c6. 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:    .Renviron
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    _targets/meta/process
    Ignored:    _targets/meta/progress
    Ignored:    _targets/objects/
    Ignored:    _targets/scratch/
    Ignored:    _targets/user/
    Ignored:    all_lkps_maps.db
    Ignored:    renv/library/
    Ignored:    renv/staging/
    Ignored:    tar_make.R

Untracked files:
    Untracked:  analysis/ukb_self_report_cancer_illness_caliber_mapping.Rmd
    Untracked:  data_small/ukb_self_report_cancer_to_caliber_map.csv
    Untracked:  data_small/ukb_self_report_cancer_to_caliber_map_raw.csv

Unstaged changes:
    Modified:   _targets.R
    Modified:   _targets/meta/meta
    Modified:   analysis/index.Rmd
    Modified:   analysis/ukb_self_report_non_cancer_illness_caliber_mapping.Rmd
    Modified:   analysis/ukb_self_report_operations_caliber_mapping.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/ukb_self_report_operations_caliber_mapping.Rmd) and HTML (public/ukb_self_report_operations_caliber_mapping.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 ef137c6 rmgpanw 2022-06-14 update notes on mapping ukb self-report ops to CALIBER
html ef137c6 rmgpanw 2022-06-14 update notes on mapping ukb self-report ops to CALIBER
Rmd 1b7e625 rmgpanw 2022-06-14 add notes for mapping UKB self-reported ops to CALIBER
html 1b7e625 rmgpanw 2022-06-14 add notes for mapping UKB self-reported ops to CALIBER

library(tidyverse)
library(reactable)
library(readxl)
library(crosstalk)
library(targets)
library(codemapper)
library(flextable)

# read codes that map to opcs4
tar_load(read_codes_that_map_to_opcs4)

# caliber codes - filter for diseases including opcs4 codes, then filter for OPCS4/read codes only, then filter read codes for only those that can map to OPCS4
tar_load(caliber_codes)

caliber_codes_operations <- caliber_codes %>% 
  # diseases that include OPCS4 codes
  group_by(disease) %>% 
  mutate(disease_includes_opcs4 = case_when("opcs4" %in% code_type ~ TRUE,
                                    TRUE ~ FALSE)) %>% 
  ungroup() %>% 
  filter(disease_includes_opcs4) %>% 
  select(-disease_includes_opcs4) %>% 
  
  # filter for opcs4 codes, and read codes that can map to OPCS4
  filter(
    (code_type == "opcs4") |
      ((code_type == "read2") & (code %in% read_codes_that_map_to_opcs4$read2)) |
      ((code_type == "read3") & (code %in% read_codes_that_map_to_opcs4$read3))
  )

# self-reported UKB non-cancer illnesses
coding5 <- tar_read(ukb_codings) %>% 
  filter(Coding == "5")

Overview

Aim: to assign UKB self-reported operation codes to CALIBER conditions.

Approach:

  • Filter CALIBER codelists for diseases including OPCS4 codes, then filter for OPCS4 and Read codes only
  • Filter Read codes for only those in the read2/3-to-OPCS4 mapping tables
  • Manually review UKB self-reported operation codes and assign to CALIBER diseases (also manually review Read codes)

UKB self-reported operations lookup table

coding5 %>% 
  select(-Coding,
         data_coding_5 = Value,
         ukb_meaning = Meaning) %>% 
  reactable(filterable = TRUE,
            searchable = TRUE,
            paginationType = "jump",
            showPageSizeOptions = TRUE,
            resizable = TRUE,
            pageSizeOptions = c(10, 25, 50, 100, 200, 300, 350))

CALIBER diseases that include OPCS4 codes

caliber_codes_operations %>% 
  distinct(disease) %>% 
  reactable(filterable = TRUE,
            paginationType = "jump",
            showPageSizeOptions = TRUE,
            resizable = TRUE,
            pageSizeOptions = c(10, 30))

Manual mapping of UKB self-reported operations codes to CALIBER diseases

Write csv file for manual mapping

# write to csv
ukb_self_report_operations_to_caliber_map_unselected <-
  caliber_codes_operations %>%
  distinct(disease) %>%
  mutate(
    description = "",
    category = "UKB self-reported",
    code_type = "data_coding_5",
    code = "",
    author = "caliber"
  )

ukb_self_report_operations_to_caliber_map_unselected %>% 
  write_csv(here::here(file.path("data_small",
                                 "ukb_self_report_operations_to_caliber_map_raw.csv")))

# NOTE: when manually reviewing, save the csv as a separate file without the '_raw' suffix
# test that `ukb_self_report_non_cancer_to_caliber_map.csv` contains the same mappings as `ukb_self_report_non_cancer_to_caliber_map_raw.csv` (apart from the manuall mapping column) - RAISE ERROR AND HALT KNITTING IF NOT
ukb_self_report_operations_to_caliber_map <- read_csv(here::here(file.path("data_small",
                                                                           "ukb_self_report_operations_to_caliber_map.csv")),
                                                      col_types = readr::cols(.default = "c"))

assertthat::are_equal(
  x = ukb_self_report_operations_to_caliber_map %>% 
    distinct(disease) %>% 
    arrange(),
  y = ukb_self_report_operations_to_caliber_map_unselected %>% 
    distinct(disease) %>% 
    arrange(),
  msg = "Manually selected mapping csv does not match 'ukb_self_report_operations_to_caliber_map_raw.csv'. These should contain the same values under column 'disease'. Has the raw version been updated?"
)

# general validation checks
ukb_self_report_operations_to_caliber_map %>% 
  filter(selected == "Y") %>% 
  select(-selected) %>% 
  ukbwranglr::validate_clinical_codes()

# check self-report codes/descriptions are correct
assertthat::are_equal(
  ukb_self_report_operations_to_caliber_map %>%
    filter(selected == "Y") %>%
    select(-selected) %>%
    inner_join(coding5,
              by = c(
                "code" = "Value",
                "description" = "Meaning"
              )) %>%
    nrow(),
  nrow(
    ukb_self_report_operations_to_caliber_map %>%
      filter(selected == "Y")
  )
)

Review examples of questionable mappings

CALIBER disease Potential issues
End stage renal disease Includes OPCS4 code for ‘Pre-transplantation of kidney work-up - recipient’ (‘M172’).
Glaucoma Includes procedures (such as laser treatments and operations on the iris) that are not covered by the UKB self-reported code ‘glaucoma surgery/trabeculectomy’.
Peripheral arterial disease Includes procedures (such as endarterectomy, embolectomy, reconstruction) that are not covered by the UKB self-reported codes ‘fem-pop bypass/leg artery bypass’ and ‘leg artery angioplasty +/- stent’.
list(caliber_codes_operations,
     ukb_self_report_operations_to_caliber_map) %>%
  bind_rows() %>%
  filter(code_type %in% c("opcs4",
                          "data_coding_5")) %>%
  filter(disease %in% c(
    "End stage renal disease",
    "Glaucoma",
    "Peripheral arterial disease"
  )) %>%
  select(all_of(names(ukbwranglr::example_clinical_codes()))) %>% 
  reactable(
    filterable = TRUE,
    paginationType = "jump",
    showPageSizeOptions = TRUE,
    resizable = TRUE,
    pageSizeOptions = c(10, 30)
  )

Manually annotated mapping file

ukb_self_report_operations_to_caliber_map %>% 
  mutate(selected = case_when(is.na(selected) ~ "N",
                              TRUE ~ selected)) %>% 
  reactable(filterable = TRUE,
            searchable = TRUE,
            paginationType = "jump",
            showPageSizeOptions = TRUE,
            pageSizeOptions = c(10, 25, 50))

Final codelist

CALIBER diseases with OPCS4 codes and 1 or more UKB mapped self-reported operation codes, filtered for Read codes that map to an OPCS4 code.

# filter mapped self-reported op codes for selected CALIBER diseases only
ukb_self_report_operations_to_caliber_map_selected <-
  ukb_self_report_operations_to_caliber_map %>%
  filter(selected == "Y") %>%
  select(-selected)

ukb_self_report_operations_to_caliber_map_selected %>%
  bind_rows(caliber_codes_operations) %>%
  filter(disease %in% ukb_self_report_operations_to_caliber_map_selected$disease) %>%
  arrange(disease,
          category,
          code_type) %>%
  reactable(
    filterable = TRUE,
    searchable = TRUE,
    paginationType = "jump",
    showPageSizeOptions = TRUE,
    resizable = TRUE,
    pageSizeOptions = c(10, 25, 50, 100, 200, 300, 350)
  )  

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur/Monterey 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

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

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

other attached packages:
 [1] flextable_0.7.0       codemapper_0.0.0.9001 targets_0.12.0       
 [4] crosstalk_1.2.0       readxl_1.4.0          reactable_0.3.0      
 [7] forcats_0.5.1         stringr_1.4.0         dplyr_1.0.9          
[10] purrr_0.3.4           readr_2.1.2           tidyr_1.2.0          
[13] tibble_3.1.7          ggplot2_3.3.5         tidyverse_1.3.1      
[16] workflowr_1.7.0      

loaded via a namespace (and not attached):
 [1] fs_1.5.2              bit64_4.0.5           lubridate_1.8.0      
 [4] httr_1.4.2            rprojroot_2.0.3       tools_4.2.0          
 [7] backports_1.4.1       bslib_0.3.1           utf8_1.2.2           
[10] R6_2.5.1              DBI_1.1.2             colorspace_2.0-3     
[13] withr_2.5.0           tidyselect_1.1.2      processx_3.5.3       
[16] bit_4.0.4             compiler_4.2.0        git2r_0.30.1         
[19] cli_3.3.0             rvest_1.0.2           xml2_1.3.3           
[22] officer_0.4.2         sass_0.4.1            scales_1.2.0         
[25] callr_3.7.0           systemfonts_1.0.4     digest_0.6.29        
[28] rmarkdown_2.14        base64enc_0.1-3       pkgconfig_2.0.3      
[31] htmltools_0.5.2       dbplyr_2.2.0          fastmap_1.1.0        
[34] highr_0.9             htmlwidgets_1.5.4     rlang_1.0.2          
[37] rstudioapi_0.13       shiny_1.7.1           jquerylib_0.1.4      
[40] generics_0.1.2        jsonlite_1.8.0        vroom_1.5.7          
[43] zip_2.2.0             magrittr_2.0.3        Rcpp_1.0.8.3         
[46] munsell_0.5.0         fansi_1.0.3           gdtools_0.2.4        
[49] lifecycle_1.0.1       stringi_1.7.6         whisker_0.4          
[52] yaml_2.3.5            grid_4.2.0            parallel_4.2.0       
[55] promises_1.2.0.1      crayon_1.5.1          haven_2.5.0          
[58] hms_1.1.1             knitr_1.39            ps_1.7.0             
[61] pillar_1.7.0          uuid_1.1-0            igraph_1.3.1         
[64] base64url_1.4         codetools_0.2-18      reprex_2.0.1         
[67] glue_1.6.2            evaluate_0.15         getPass_0.2-2        
[70] ukbwranglr_0.0.0.9000 data.table_1.14.2     renv_0.13.2          
[73] modelr_0.1.8          vctrs_0.4.1           tzdb_0.3.0           
[76] httpuv_1.6.5          cellranger_1.1.0      gtable_0.3.0         
[79] reactR_0.4.4          assertthat_0.2.1      xfun_0.30            
[82] mime_0.12             xtable_1.8-4          broom_0.8.0          
[85] later_1.3.0           ellipsis_0.3.2        here_1.0.1