Skip to content

Commit

Permalink
update data freeze and skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang committed Nov 15, 2023
1 parent 1e8aa09 commit 29d2537
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 77 deletions.
111 changes: 55 additions & 56 deletions R/data_freeze.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
data_freeze <- function(onedrive.dir = file.path("~", "OneDrive - VUMC"),
data_freeze <- function(onedrive.dir = file.path("C:", "Users", "zhanp15", "OneDrive - VUMC"),
output.dir = NULL,
redcap.api.uri = "https://redcap.vanderbilt.edu/api/",
save = TRUE,
return = TRUE) {

# define important directories
vmac.dir <- file.path(onedrive.dir, "VMAC BIOSTAT")
data.dir <- file.path(vmac.dir, "DATA", "MAP")
med.dir <- file.path(data.dir, "Medication")
surg.dir <- file.path(data.dir, "Surgeries")
data.raw.dir <- file.path(data.dir, "rawData")

# set timezone
Sys.setenv(TZ = "US/Central")

# initialize list
MAPfreeze.list <- list(
general = list(
Expand All @@ -28,29 +28,29 @@ data_freeze <- function(onedrive.dir = file.path("~", "OneDrive - VUMC"),
),
vmap_edc = list(
project = "VMAP Electronic Data Capture Epochs 1-6",
token = "REPLACE"
token = "63B603E229D3215CFB08ECAF3A5DB405"
),
questionnaires = list(
project = "VMAP Questionnaires",
token = "REPLACE"
token = "57359675748C4E7ABDC99A28CA29CEDA"
),
biomarkers = list(
project = "VMAP CSF, Plasma, and Serum Biomarkers Epoch 1-6",
token = "REPLACE"
token = "1692640B08F01AD8548523DF8D8AFBEC"
),
apoe = list(
project = "MAP APOE",
token = "REPLACE"
token = "1C58CF9FDF2F1AC3DACA10F60714A04E"
)
)

###

# use REDCap API to download data
for (redcap.i in setdiff(names(MAPfreeze.list), "general")) {

message(paste0("Currently downloading: ", MAPfreeze.list[[redcap.i]][["project"]], "\n\n"))

# grab data
MAPfreeze.list[[redcap.i]][["data"]] <- REDCapR::redcap_read(
batch_size = 50L,
Expand All @@ -59,157 +59,157 @@ data_freeze <- function(onedrive.dir = file.path("~", "OneDrive - VUMC"),
raw_or_label = "raw",
verbose = TRUE
)$data

MAPfreeze.list[[redcap.i]][["metadata"]] <- REDCapR::redcap_metadata_read(
redcap_uri = redcap.api.uri,
token = MAPfreeze.list[[redcap.i]][["token"]],
verbose = TRUE
)$data
}

MAPfreeze.list$general$versions[["REDCap"]] <- as.character(
REDCapR::redcap_version(
redcap_uri = redcap.api.uri,
token = MAPfreeze.list[[redcap.i]][["token"]],
verbose = FALSE
)
)

###

med.file.date <- 20230227 # date for main medication files
antihypSubtype.file.date <- 20230227 # date for antihyp subtype files
surg.file.date <- 20230227 # date for afibsurgery

# Biospecimen Availability
biospecimen_availability.file <- file.path(
data.raw.dir,
data.raw.dir, "old",
"VMAP_biospecimens_collected_20210719.xlsx"
)

# Physlog data
physlog.file <- file.path(
data.raw.dir,
"20220916 - vmap_physlog_data.csv"
)

# ABP consent info
track.file <- file.path(
data.dir, "rawData",
data.raw.dir, "old",
"MAPParticipantTracki_DATA_2015-08-26_1412.csv"
)

# Selected data from eligibility.
elig.file <- file.path(
data.dir, "rawData",
data.raw.dir, "old",
"MAPEligibility_DATA_2016-11-03_1532.csv"
)

chol.file <- file.path(
med.dir,
paste0("CholesterolMedNumbers_", med.file.date, ".csv")
)

afib.file <- file.path(
med.dir,
paste0("AFibMedNumbers_", med.file.date, ".csv")
)

# antihyp.file <- file.path(
# med.dir, "old (save for reference)",
# paste0("AntihypertensiveMedNumbers_", med.file.date, ".csv")
# )

diab.file <- file.path(
med.dir,
paste0("DiabetesMedNumbers_", med.file.date, ".csv")
)

# antihypertensive med subtypes
antihypBetaBlocker.file <- file.path(
med.dir,
paste0("antiHyp_BetaBlockers_", antihypSubtype.file.date, ".csv")
)

antihypBetaBlockerIfNotDrop.file <- file.path(
med.dir,
paste0("antiHyp_BetaBlockersIfNotDrops_", antihypSubtype.file.date, ".csv")
)

antihypACEInhib.file <- file.path(
med.dir,
paste0("antiHyp_ACEInhibitors_", antihypSubtype.file.date, ".csv")
)

antihypARB.file <- file.path(
med.dir,
paste0("antiHyp_ARBs_", antihypSubtype.file.date, ".csv")
)

antihypCCB.file <- file.path(
med.dir,
paste0("antiHyp_CaChannelBlockers_", antihypSubtype.file.date, ".csv")
)

antihypKSD.file <- file.path(
med.dir,
paste0("antiHyp_PotassiumSparingDiuretics_", antihypSubtype.file.date, ".csv")
)

antihypOther.file <- file.path(
med.dir,
paste0("antiHyp_Other_", antihypSubtype.file.date, ".csv")
)

# surgery lookup files
afibsurg.file <- file.path(
surg.dir,
paste0("AFibSurgNumbers_", surg.file.date, ".csv")
)

thyroidsurg.file <- file.path(
surg.dir,
paste0("ThyroidSurgNumbers_", surg.file.date, ".csv")
)

# epoch_1
abp.raw.derived.file <- file.path(
data.dir,
"ABP_RawAndDerived",
"MapAbpData_Epoch1_20150625.rds"
)

srt.file <- file.path(
data.raw.dir,
data.raw.dir, "old",
"MAPSRTErrorAnalysisEpoch1_DATA_2017-09-01_0936.csv"
)

np.composite.file <- file.path(
data.raw.dir,
"np_composite_20220926.rds"
)

polygenetic.file <- file.path(
data.raw.dir,
data.raw.dir, "old",
"VMAP_PRS.rds"
)

map_163_invalidation.file <- file.path(
data.dir,
"Documentation",
"MAP163_variablesunusable_20220916.xlsx"
)

invalid_neuropsych.file <- file.path(
data.dir,
"Documentation", "InvalidNeuropsych",
"VMAP NP Invalids QC 8.29.22_DL.xlsx"
)

###

# epoch_0

static.list.0 = list(
project = paste0(
"MAP ",
Expand Down Expand Up @@ -288,17 +288,17 @@ data_freeze <- function(onedrive.dir = file.path("~", "OneDrive - VUMC"),
),
metadata = rep("NA", 20)
)

names(static.list.0[["token"]]) <- static.list.0$shortname
names(static.list.0[["data"]]) <- static.list.0$shortname
names(static.list.0[["metadata"]]) <- static.list.0$shortname

for (list.names in names(static.list.0)) {
MAPfreeze.list[["static"]][[list.names]] <- c(MAPfreeze.list[["static"]][[list.names]], static.list.0[[list.names]])
}

# epoch_1

static.list.1 = list(
project = paste0(
"MAP ",
Expand All @@ -320,15 +320,15 @@ data_freeze <- function(onedrive.dir = file.path("~", "OneDrive - VUMC"),
),
metadata = rep("NA", 2)
)

names(static.list.1[["token"]]) <- static.list.1$shortname
names(static.list.1[["data"]]) <- static.list.1$shortname
names(static.list.1[["metadata"]]) <- static.list.1$shortname

for (list.names in names(static.list.1)) {
MAPfreeze.list[["static"]][[list.names]] <- c(MAPfreeze.list[["static"]][[list.names]], static.list.1[[list.names]])
}

if (save == TRUE) {
if (is.null(output.dir)) {
saveRDS(
Expand All @@ -348,9 +348,8 @@ data_freeze <- function(onedrive.dir = file.path("~", "OneDrive - VUMC"),
)
}
}

if (return == TRUE) {
return(MAPfreeze.list)
}
}

Loading

0 comments on commit 29d2537

Please sign in to comment.