|
@@ -229,11 +229,9 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c
|
|
|
sd = ~sd(., na.rm = TRUE),
|
|
|
se = ~ifelse(sum(!is.na(.)) > 1, sd(., na.rm = TRUE) / sqrt(sum(!is.na(.)) - 1), NA)
|
|
|
), .names = "{.fn}_{.col}")
|
|
|
- ) %>%
|
|
|
- ungroup()
|
|
|
+ )
|
|
|
|
|
|
stats <- stats %>%
|
|
|
- group_by(across(all_of(group_vars))) %>%
|
|
|
mutate(
|
|
|
Raw_Shift_L = mean_L[[1]] - bg_means$L,
|
|
|
Raw_Shift_K = mean_K[[1]] - bg_means$K,
|
|
@@ -272,7 +270,8 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c
|
|
|
Zscore_K = Delta_K / WT_sd_K,
|
|
|
Zscore_r = Delta_r / WT_sd_r,
|
|
|
Zscore_AUC = Delta_AUC / WT_sd_AUC
|
|
|
- )
|
|
|
+ ) %>%
|
|
|
+ ungroup()
|
|
|
|
|
|
# Create linear models with error handling for missing/insufficient data
|
|
|
# This part is a PITA so best to contain it in its own function
|
|
@@ -345,7 +344,8 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c
|
|
|
Z_lm_K = (lm_Score_K - mean(lm_Score_K, na.rm = TRUE)) / sd(lm_Score_K, na.rm = TRUE),
|
|
|
Z_lm_r = (lm_Score_r - mean(lm_Score_r, na.rm = TRUE)) / sd(lm_Score_r, na.rm = TRUE),
|
|
|
Z_lm_AUC = (lm_Score_AUC - mean(lm_Score_AUC, na.rm = TRUE)) / sd(lm_Score_AUC, na.rm = TRUE)
|
|
|
- )
|
|
|
+ ) %>%
|
|
|
+ ungroup()
|
|
|
|
|
|
# Declare column order for output
|
|
|
calculations <- stats %>%
|
|
@@ -361,9 +361,8 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c
|
|
|
"Exp_L", "Exp_K", "Exp_r", "Exp_AUC",
|
|
|
"Delta_L", "Delta_K", "Delta_r", "Delta_AUC",
|
|
|
"Zscore_L", "Zscore_K", "Zscore_r", "Zscore_AUC",
|
|
|
- "NG", "SM", "DB") %>%
|
|
|
- ungroup()
|
|
|
-
|
|
|
+ "NG", "SM", "DB")
|
|
|
+
|
|
|
interactions <- stats %>%
|
|
|
select("OrfRep", "Gene", "num", "Raw_Shift_L", "Raw_Shift_K", "Raw_Shift_AUC", "Raw_Shift_r",
|
|
|
"Z_Shift_L", "Z_Shift_K", "Z_Shift_r", "Z_Shift_AUC",
|
|
@@ -374,13 +373,12 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c
|
|
|
"Z_lm_L", "Z_lm_K", "Z_lm_r", "Z_lm_AUC",
|
|
|
"NG", "SM", "DB") %>%
|
|
|
arrange(desc(lm_Score_L)) %>%
|
|
|
- arrange(desc(NG)) %>%
|
|
|
- ungroup()
|
|
|
+ arrange(desc(NG))
|
|
|
|
|
|
df <- df %>% select(-any_of(setdiff(names(calculations), group_vars)))
|
|
|
df <- left_join(df, calculations, by = group_vars)
|
|
|
- df <- df %>% select(-any_of(setdiff(names(interactions), group_vars)))
|
|
|
- df <- left_join(df, interactions, by = group_vars)
|
|
|
+ # df <- df %>% select(-any_of(setdiff(names(interactions), group_vars)))
|
|
|
+ # df <- left_join(df, interactions, by = group_vars)
|
|
|
|
|
|
return(list(calculations = calculations, interactions = interactions, joined = df))
|
|
|
}
|