Case study – All register data for a person
Get all the data for a list of FINNGENID's
# helper function
# returns a data frame with all the data for given FINNGENID's
get_all_data <- function(...){
finngenids <- list(...)
sql<-paste0(
"SELECT * ",
"FROM finngen-production-library.",
".sandbox_tools_r10.",
"finngen_r10_service_sector_detailed_longitudinal_v2 ",
"WHERE FINNGENID IN (", paste0("'", finngenids, "'", collapse = ","), ")"
)
tb <- bq_project_query(projectid, sql)
}
# give a list of FINNGENIDs here (these are fake ID's)
tb <- get_all_data('FG00001', 'FG00002', 'FG00003')
# extend with code translation by using FinnGenUtilsR package
df <- FinnGenUtilsR::fg_bq_append_code_info_to_longitudinal_data(
projectid, tb,
"finngen-production-library.medical_codes.fg_codes_info_v1"
)
df_with_codes <- bq_table_download(df) %>%
arrange(EVENT_AGE) %>%
mutate(AGE = round(EVENT_AGE)) %>%
select(FINNGENID, AGE, SOURCE, name_en, CODE1, CODE2, CODE3)
# # for a small data set we can use an interactive table
# DT::datatable(df_with_codes)
# this works even with large data sets
df_with_codes
Get all the data for a file of FINNGENID's
Last updated
Was this helpful?