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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(tidyverse)
|
| 2 |
+
library(here)
|
| 3 |
+
library(arrow)
|
| 4 |
+
library(readxl)
|
| 5 |
+
|
| 6 |
+
# Constants ----
|
| 7 |
+
GENOMIC_FEATURES_PATH <- here("data/genome_files/hf/features")
|
| 8 |
+
HUGHES_DATA_DIR <- here("data/hughes_2006")
|
| 9 |
+
|
| 10 |
+
# Load genomic features harmonization table ----
|
| 11 |
+
# See https://huggingface.co/datasets/BrentLab/yeast_genome_resources
|
| 12 |
+
genomicfeatures <- arrow::open_dataset(GENOMIC_FEATURES_PATH) %>%
|
| 13 |
+
as_tibble()
|
| 14 |
+
|
| 15 |
+
#' Read and process Hughes normalized data
|
| 16 |
+
#'
|
| 17 |
+
#' @param path Path to Excel file
|
| 18 |
+
#' @param ko Logical indicating if this is knockout data (TRUE) or overexpression (FALSE)
|
| 19 |
+
#' @return Tibble with processed data
|
| 20 |
+
read_hughes_normalized_data <- function(path, ko = TRUE) {
|
| 21 |
+
if (!file.exists(path)) {
|
| 22 |
+
stop("File not found: ", path)
|
| 23 |
+
}
|
| 24 |
+
df <- read_excel(path)
|
| 25 |
+
# Standardize first column name
|
| 26 |
+
colnames(df)[1] <- "hughes_target"
|
| 27 |
+
# Pivot to long format
|
| 28 |
+
df_long <- df %>%
|
| 29 |
+
pivot_longer(
|
| 30 |
+
cols = -hughes_target,
|
| 31 |
+
names_to = "sample",
|
| 32 |
+
values_to = "norm_log2fc"
|
| 33 |
+
) %>%
|
| 34 |
+
mutate(norm_log2fc = as.numeric(norm_log2fc)) %>%
|
| 35 |
+
# remove deleted ORFs
|
| 36 |
+
filter(!hughes_target %in% c(
|
| 37 |
+
"YCL006C",
|
| 38 |
+
"YCR103C",
|
| 39 |
+
"YER187W-A"
|
| 40 |
+
)) %>%
|
| 41 |
+
# these are transposons/retrotransposons and just have
|
| 42 |
+
# typos
|
| 43 |
+
mutate(hughes_target = case_when(
|
| 44 |
+
hughes_target == "YDR034CD01" ~ "YDR034C-D",
|
| 45 |
+
hughes_target == "YDR210WD01" ~ "YDR210W-D",
|
| 46 |
+
hughes_target == "YDR261CD01" ~ "YDR261C-D",
|
| 47 |
+
hughes_target == "YGR161CD01" ~ "YGR161C-D",
|
| 48 |
+
hughes_target == "YPR158CD01" ~ "YPR158C-D",
|
| 49 |
+
.default = hughes_target
|
| 50 |
+
))
|
| 51 |
+
# Process based on data type
|
| 52 |
+
if (ko) {
|
| 53 |
+
df_long = df_long %>%
|
| 54 |
+
separate(sample, into = c("prefix", "suffix"), sep = "/", remove = FALSE) %>%
|
| 55 |
+
mutate(
|
| 56 |
+
dye_orientation = str_extract(suffix, "[+-]$"),
|
| 57 |
+
regulator_symbol = str_to_upper(str_remove(suffix, "[+-]"))
|
| 58 |
+
) %>%
|
| 59 |
+
select(-prefix, -suffix)
|
| 60 |
+
} else {
|
| 61 |
+
df_long = df_long %>%
|
| 62 |
+
mutate(
|
| 63 |
+
dye_orientation = str_extract(sample, "[+-]$"),
|
| 64 |
+
regulator_symbol = str_to_upper(str_remove(sample, "(-A)?OE[+-]"))
|
| 65 |
+
)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
df_long %>%
|
| 69 |
+
select(-sample) %>%
|
| 70 |
+
pivot_wider(id_cols = c(regulator_symbol, hughes_target),
|
| 71 |
+
names_from = dye_orientation,
|
| 72 |
+
values_from = norm_log2fc) %>%
|
| 73 |
+
rename(dye_plus = `+`, dye_minus = `-`) %>%
|
| 74 |
+
rowwise() %>%
|
| 75 |
+
mutate(
|
| 76 |
+
mean_norm_log2fc = case_when(
|
| 77 |
+
# Both values are NA
|
| 78 |
+
is.na(dye_plus) & is.na(dye_minus) ~ NA_real_,
|
| 79 |
+
# Only one value is available - use that value
|
| 80 |
+
is.na(dye_plus) & !is.na(dye_minus) ~ dye_minus,
|
| 81 |
+
!is.na(dye_plus) & is.na(dye_minus) ~ dye_plus,
|
| 82 |
+
# Both values available but have opposite signs - average to zero
|
| 83 |
+
!is.na(dye_plus) & !is.na(dye_minus) & (sign(dye_plus) != sign(dye_minus)) ~ 0,
|
| 84 |
+
# Both values available with same sign - take the mean
|
| 85 |
+
TRUE ~ mean(c(dye_plus, dye_minus), na.rm = TRUE)
|
| 86 |
+
)
|
| 87 |
+
) %>%
|
| 88 |
+
ungroup()
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# Load and process data ----
|
| 93 |
+
message("Loading knockout data...")
|
| 94 |
+
df_ko <- read_hughes_normalized_data(
|
| 95 |
+
file.path(HUGHES_DATA_DIR, "Del_NormalizedRatios.xls"),
|
| 96 |
+
ko = TRUE
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
message("Loading overexpression data...")
|
| 100 |
+
df_oe <- read_hughes_normalized_data(
|
| 101 |
+
file.path(HUGHES_DATA_DIR, "OE_NormalizedRatios.xls"),
|
| 102 |
+
ko = FALSE
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
message("Loading Z-scores...")
|
| 106 |
+
zscore_df <- read_excel(file.path(HUGHES_DATA_DIR, "Z_SCORES_FOR_106_EXPERIMENTS.xls")) %>%
|
| 107 |
+
rename(hughes_target = `...1`) %>%
|
| 108 |
+
pivot_longer(
|
| 109 |
+
cols = -hughes_target,
|
| 110 |
+
names_to = "sample",
|
| 111 |
+
values_to = "zscore"
|
| 112 |
+
) %>%
|
| 113 |
+
mutate(
|
| 114 |
+
perturbation = case_when(
|
| 115 |
+
str_detect(sample, "-D$") ~ "deletion",
|
| 116 |
+
str_detect(sample, "^OE") ~ "overexpression",
|
| 117 |
+
TRUE ~ "unknown"
|
| 118 |
+
),
|
| 119 |
+
hughes_regulator = str_to_upper(str_remove(sample, "-D$|^OE"))
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# Load metadata ----
|
| 123 |
+
message("Loading metadata...")
|
| 124 |
+
hughes_2006_meta <- read_excel(file.path(HUGHES_DATA_DIR, "TRANSCRIPTION_FACTOR_LIST.xls")) %>%
|
| 125 |
+
rename(
|
| 126 |
+
regulator_locus_tag = Id_001,
|
| 127 |
+
regulator_symbol = Id_002
|
| 128 |
+
) %>%
|
| 129 |
+
mutate(
|
| 130 |
+
essential = `Essential/Nonessential` == "essential",
|
| 131 |
+
oe_passed_qc = `OE passed QC` == "yes",
|
| 132 |
+
del_passed_qc = `DEL passed QC` == "yes"
|
| 133 |
+
) %>%
|
| 134 |
+
select(-`Essential/Nonessential`, -ends_with("passed QC"))
|
| 135 |
+
|
| 136 |
+
# Data validation ----
|
| 137 |
+
message("Validating data consistency...")
|
| 138 |
+
|
| 139 |
+
validate_data_consistency <- function() {
|
| 140 |
+
tests <- list(
|
| 141 |
+
# Check regulator locus tags match genomic features
|
| 142 |
+
regulator_locus_consistency = setequal(
|
| 143 |
+
intersect(genomic_features$locus_tag, hughes_2006_meta$regulator_locus_tag),
|
| 144 |
+
hughes_2006_meta$regulator_locus_tag
|
| 145 |
+
),
|
| 146 |
+
|
| 147 |
+
# Check regulator symbols match genomic features
|
| 148 |
+
regulator_symbol_consistency = setequal(
|
| 149 |
+
intersect(genomic_features$symbol, hughes_2006_meta$regulator_symbol),
|
| 150 |
+
hughes_2006_meta$regulator_symbol
|
| 151 |
+
),
|
| 152 |
+
|
| 153 |
+
# Check OE regulators match metadata
|
| 154 |
+
oe_regulator_consistency = setequal(
|
| 155 |
+
intersect(hughes_2006_meta$regulator_symbol, unique(df_oe$regulator_symbol)),
|
| 156 |
+
unique(df_oe$regulator_symbol)
|
| 157 |
+
),
|
| 158 |
+
|
| 159 |
+
# Check KO regulators match metadata
|
| 160 |
+
ko_regulator_consistency = setequal(
|
| 161 |
+
intersect(hughes_2006_meta$regulator_symbol, unique(df_ko$regulator_symbol)),
|
| 162 |
+
unique(df_ko$regulator_symbol)
|
| 163 |
+
),
|
| 164 |
+
|
| 165 |
+
# Check target consistency between KO and OE
|
| 166 |
+
target_consistency = setequal(
|
| 167 |
+
unique(df_ko$hughes_target),
|
| 168 |
+
unique(df_oe$hughes_target)
|
| 169 |
+
),
|
| 170 |
+
|
| 171 |
+
# Check targets match genomic features
|
| 172 |
+
target_genomic_consistency = setequal(
|
| 173 |
+
unique(df_oe$hughes_target),
|
| 174 |
+
intersect(unique(df_oe$hughes_target), genomic_features$locus_tag)
|
| 175 |
+
)
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
# Report results
|
| 179 |
+
failed_tests <- names(tests)[!unlist(tests)]
|
| 180 |
+
|
| 181 |
+
if (length(failed_tests) == 0) {
|
| 182 |
+
message("✓ All validation tests passed")
|
| 183 |
+
} else {
|
| 184 |
+
stop("✗ Validation failed for: ", paste(failed_tests, collapse = ", "))
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
invisible(tests)
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
validate_data_consistency()
|
| 191 |
+
|
| 192 |
+
# Summary statistics ----
|
| 193 |
+
message("Data loading complete. Summary:")
|
| 194 |
+
message("- Knockout experiments: ", length(unique(df_ko$regulator_symbol)), " regulators")
|
| 195 |
+
message("- Overexpression experiments: ", length(unique(df_oe$regulator_symbol)), " regulators")
|
| 196 |
+
message("- Target genes: ", length(unique(df_ko$hughes_target)))
|
| 197 |
+
message("- Z-score experiments: ", length(unique(zscore_df$sample)))
|
| 198 |
+
|
| 199 |
+
# Note about missing targets in Z-score data
|
| 200 |
+
missing_targets_count <- length(setdiff(unique(df_ko$hughes_target),
|
| 201 |
+
unique(zscore_df$hughes_target)))
|
| 202 |
+
if (missing_targets_count > 0) {
|
| 203 |
+
message("- Z-score data missing ", missing_targets_count, " targets present in KO/OE data")
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
missing_locus_tags <- setdiff(
|
| 207 |
+
unique(df_oe$hughes_target),
|
| 208 |
+
intersect(unique(df_oe$hughes_target), genomic_features$locus_tag)
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
genome_map = tibble(
|
| 212 |
+
locus_tag = intersect(unique(df_oe$hughes_target),
|
| 213 |
+
genomic_features$locus_tag)) %>%
|
| 214 |
+
left_join(genomicfeatures %>% select(locus_tag, symbol)) %>%
|
| 215 |
+
mutate(hughes_target = locus_tag) %>%
|
| 216 |
+
bind_rows(
|
| 217 |
+
genomic_features %>%
|
| 218 |
+
filter(str_detect(alias, paste(missing_locus_tags, collapse = "|"))) %>%
|
| 219 |
+
mutate(alias_match = str_extract(alias, paste(missing_locus_tags, collapse = "|"))) %>%
|
| 220 |
+
dplyr::rename(hughes_target = alias_match) %>%
|
| 221 |
+
select(hughes_target, locus_tag, symbol)
|
| 222 |
+
) %>%
|
| 223 |
+
dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol)
|
| 224 |
+
|
| 225 |
+
stopifnot(setequal(genome_map$hughes_target, unique(df_oe$hughes_target)))
|
| 226 |
+
|
| 227 |
+
df_oe_harmonized =
|
| 228 |
+
df_oe %>%
|
| 229 |
+
select(-c(sample, regulator_symbol)) %>%
|
| 230 |
+
pivot_wider(id_cols = c(regulator_symbol, hughes_target),
|
| 231 |
+
names_from = dye_orientation,
|
| 232 |
+
values_from = norm_log2fc) %>%
|
| 233 |
+
dplyr::rename(dye_plus = `+`, dye_minus = `-`) %>%
|
| 234 |
+
left_join(df_oe)
|
| 235 |
+
left_join(
|
| 236 |
+
select(hughes_2006_meta,
|
| 237 |
+
regulator_locus_tag,
|
| 238 |
+
regulator_symbol) %>%
|
| 239 |
+
left_join(genome_map) %>%
|
| 240 |
+
select(regulator_locus_tag, regulator_symbol,
|
| 241 |
+
target_locus_tag, target_symbol,
|
| 242 |
+
mean_log2fc)
|
| 243 |
+
|
| 244 |
+
|