-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-02-2024_cass_BHRC_PRSAdjustment.R
43 lines (36 loc) · 1.12 KB
/
04-02-2024_cass_BHRC_PRSAdjustment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
source("functions_to_source.R")
file_list <-
list.files(
glue("{Path}/PRS_database/Final_Scores_PRSCS"),
pattern = "\\.profile$"
)
prs_values <- list()
for (file in file_list) {
file_path <- file.path(glue("{Path}/PRS_database/Final_Scores_PRSCS/"), file)
file_name <- gsub("^PRSCS_(.*?)_Score\\.profile$", "\\1", file)
data <-
data.table::fread(file_path, header = TRUE) %>%
select(IID, PRSCS_zscore) %>%
rename(PRS = PRSCS_zscore)
prs_values[[file_name]] <- data
}
# ajustar pra fazer a regressão e os testes de modelo
# fazer PRSCS com as mesmas bases, porém
# com burn-ins e interactions diferente (omitzado)
new_PRS <- NULL
for(df_name in names(prs_values)) {
data <- prs_values[[df_name]]
glm_result <-
adjust_model(list(data, sex, ages, state, pc))
samples <- glm_result$data$IID
values <- glm_result$residuals
new_PRS[[df_name]] <-
data.frame(IID = samples, PRS = values)
}
final_PRS <- plyr::join_all(new_PRS, by = "IID", type = "inner")
colnames(final_PRS)[2:ncol(final_PRS)] <- names(prs_values)
str(final_PRS)
saveRDS(
final_PRS,
glue("{Path}/objects_R/cass_BHRC_PRS.RDS")
)