Skip to content

Commit

Permalink
Adding pulse pressure to be calculated automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorsanderson committed Oct 28, 2024
1 parent 5417912 commit f545afb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions resources/phenotypes/organise_phenotypes.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ saveRDS(os, file = file.path(Sys.getenv("results_dir"), "02", "summary.rds"))
- Remove outliers
- Summarise the data
- Save age and sex specific files for the GWAS
- Note: Pulse pressure will be calculated if both sbp and dbp are avaliable - it does not need to be included in the phenotypes list.

```{r phenotype_processing, echo=FALSE}
for(i in 1:length(phenotypes)){
cat("\n### ", phenotypes[i], "\n\n")
organise_phenotype(phenotypes[i], phenotypes, df, gen_covs, covdat, agebins, pl=TRUE)
}
organise_phenotype(pp, phenotypes, df, gen_covs, covdat, agebins, pl=TRUE)
```

## Run details
Expand Down
36 changes: 34 additions & 2 deletions resources/phenotypes/phenotype_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,36 @@ phenoplot <- function(Yvbl, Xvbl, Quantiles=c(0.25,0.5,0.75), knots=NA, Nknots=0
}

organise_phenotype <- function(phecode, phenotypes, df, gen_covs, covdat, agebins, pl=TRUE) {

if(phecode != "pp"){
type <- filter(df, pheno_id == phecode)$var_type
str(filter(df, pheno_id == phecode))
cs <- list()
phen <- read_phenotype_data(phecode, Sys.getenv("phenotype_input_dir"), agebins)
}

if(phecode == "pp") {
phecode1 <- sbp
phen1 <- read_phenotype_data(phecode1, Sys.getenv("phenotype_input_dir"), agebins)
if(is.null(phen1)) {
return(NULL)
}
phen1 <- rename(phen1, sbp = value)
phen1$value <- phen1$value + (15 * phen1$bp_med)

phecode2 <- dbp
phen2 <- read_phenotype_data(phecode2, Sys.getenv("phenotype_input_dir"), agebins)
if(is.null(phen2)) {
return(NULL)
}
phen2 <- rename(phen2, dbp = value)
phen2$value <- phen2$value + (10 * phen2$bp_med)

phen <- inner_join(phen1, phen2)
phen$value <- sbp - dbp
phen <- phen %>%
select(!c(sbp, dbp))
}

if(is.null(phen)) {
return(NULL)
Expand Down Expand Up @@ -382,14 +408,18 @@ organise_phenotype <- function(phecode, phenotypes, df, gen_covs, covdat, agebin

# medication adjustment - note this assumes that the value in the phenotype covariates is the same as the column name

if(grepl("cholesterol_med", filter(df, pheno_id == phecode)$covs) == TRUE){
if(phecode=="ldl"){
analysis_data$value <- analysis_data$value + (0.40 * analysis_data$value * analysis_data$cholesterol_med)
}

if(grepl("bp_med", filter(df, pheno_id == phecode)$covs) == TRUE){
if(phecode=="sbp"){
analysis_data$value <- analysis_data$value + (15 * analysis_data$bp_med)
}

if(phecode=="dbp"){
analysis_data$value <- analysis_data$value + (10 * analysis_data$bp_med)
}

if (filter(df, pheno_id == phecode)$transformation=="log") {
print("log transformed")
} else if(filter(df, pheno_id == phecode)$transformation=="rank") {
Expand Down Expand Up @@ -565,3 +595,5 @@ organise_phenotype <- function(phecode, phenotypes, df, gen_covs, covdat, agebin

saveRDS(cs, file=file.path(Sys.getenv("results_dir"), "02", paste0(phecode,"_summary.rds")))
}


0 comments on commit f545afb

Please sign in to comment.