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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(tidyverse)
|
| 2 |
+
library(here)
|
| 3 |
+
library(httr)
|
| 4 |
+
library(arrow)
|
| 5 |
+
library(readxl)
|
| 6 |
+
|
| 7 |
+
# genomic feature harmonization table ----
|
| 8 |
+
# see https://huggingface.co/datasets/BrentLab/yeast_genome_resources
|
| 9 |
+
gene_table = arrow::open_dataset(here("data/genome_files/hf/features")) %>%
|
| 10 |
+
as_tibble()
|
| 11 |
+
|
| 12 |
+
## there is a mislabeling in both regulator and target
|
| 13 |
+
## with YDR022C. The common name is given as CIS1. However,
|
| 14 |
+
## SGD reports YDR022C as ATG31. CIS1 systematic ID is YLR346C
|
| 15 |
+
## That is labeled as ATG31.
|
| 16 |
+
## This appears to be a swap
|
| 17 |
+
|
| 18 |
+
## regulator and geneSymbol LUG1 is actually YCR087C-A, which was
|
| 19 |
+
## made an alias but only documented on SGD, not actually in the
|
| 20 |
+
## GFF/GTF. This needs to be updated in the gene_table as an alias
|
| 21 |
+
|
| 22 |
+
add_datatype_to_colnames = function(df, skip_indicies){
|
| 23 |
+
# Suffixes to append
|
| 24 |
+
suffixes <- c("_M", "_A", "_pval")
|
| 25 |
+
|
| 26 |
+
# Repeat the suffixes to match the length of my_vector
|
| 27 |
+
repeated_suffixes <- rep(suffixes, length.out = length(colnames(df)[-skip_indicies]))
|
| 28 |
+
|
| 29 |
+
# Append the suffixes to each element of my_vector
|
| 30 |
+
modified_vector <- paste0(colnames(df)[-skip_indicies], repeated_suffixes)
|
| 31 |
+
|
| 32 |
+
colnames(df)[-skip_indicies] = modified_vector
|
| 33 |
+
|
| 34 |
+
# drop the first row, which is the "data type" row in the original data
|
| 35 |
+
# where the entries are M, A and P_value. These entries are added to the
|
| 36 |
+
# colname
|
| 37 |
+
df[-1,]
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
get_clean_headers = function(path, skip_indicies = 1:3) {
|
| 41 |
+
headers <- read_tsv(path, n_max = 1, name_repair = "minimal") %>%
|
| 42 |
+
add_datatype_to_colnames(skip_indicies = skip_indicies) %>%
|
| 43 |
+
colnames()
|
| 44 |
+
|
| 45 |
+
# Replace " vs" (optionally followed by ".") with ";"
|
| 46 |
+
headers <- str_replace(headers, " vs\\.? ", ";")
|
| 47 |
+
|
| 48 |
+
# Find empty (or NA) headers and replace with X1, X2, ...
|
| 49 |
+
empties <- which(is.na(headers) | headers == "")
|
| 50 |
+
if (length(empties) > 0) {
|
| 51 |
+
headers[empties] <- paste0("X", seq_along(empties))
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
headers
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
read_in_kemmeren_data = function(path, ...){
|
| 58 |
+
read.delim(path,
|
| 59 |
+
sep='\t',
|
| 60 |
+
skip=2,
|
| 61 |
+
check.names=FALSE,
|
| 62 |
+
col.names=get_clean_headers(path, ...)) %>%
|
| 63 |
+
as_tibble()
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
stopifnot(identical(get_clean_headers(here('data/kemmeren/deleteome_all_mutants_ex_wt_var_controls.txt.xz')),
|
| 67 |
+
get_clean_headers(here('data/kemmeren/deleteome_all_mutants_controls.txt.xz'))))
|
| 68 |
+
|
| 69 |
+
deleteome_all_mutants_controls =
|
| 70 |
+
read_in_kemmeren_data(here('data/kemmeren/deleteome_all_mutants_controls.txt.xz'))
|
| 71 |
+
|
| 72 |
+
deleteome_ex_wt_var_controls =
|
| 73 |
+
read_in_kemmeren_data(here('data/kemmeren/deleteome_all_mutants_ex_wt_var_controls.txt.xz'))
|
| 74 |
+
|
| 75 |
+
by_hand_locustag_map = tibble(
|
| 76 |
+
systematicName = c('YAR062W', 'YDL038C', 'snR10', 'YGR272C', 'YIL080W', 'YIL168W', 'YIR044C'),
|
| 77 |
+
locus_tag = c('YAR061W', 'YDL039C', 'YNCG0013W', 'YGR271C-A', 'YIL082W-A', 'YIL167W', 'YIR043C')) %>%
|
| 78 |
+
deframe()
|
| 79 |
+
|
| 80 |
+
by_hand_symbol_map = gene_table %>%
|
| 81 |
+
filter(locus_tag %in% by_hand_locustag_map) %>%
|
| 82 |
+
select(locus_tag, symbol) %>%
|
| 83 |
+
deframe()
|
| 84 |
+
|
| 85 |
+
# note that by using the target_locus_tag and target_symbol,
|
| 86 |
+
# the YCR087C-A, YLR352W nomenclature is fixed (in original,
|
| 87 |
+
# YCR087C-A was called LUG1, but that name was removed in 2012 per SGD.)
|
| 88 |
+
# Additionally, the YDR022C/CIS1 error is corrected by using target_locus_tag
|
| 89 |
+
# and target_symbol, and aligns with the deletion evidence (the TF labelled
|
| 90 |
+
# ATG31/YDR022C is KOed at YDR022C, not YLR346C, which is what is
|
| 91 |
+
# currently labeled CIS1)
|
| 92 |
+
target_df = deleteome_all_mutants_controls %>%
|
| 93 |
+
select(reporterId, systematicName, geneSymbol) %>%
|
| 94 |
+
distinct() %>%
|
| 95 |
+
left_join(select(gene_table, locus_tag, symbol) %>%
|
| 96 |
+
mutate(systematicName = locus_tag)) %>%
|
| 97 |
+
mutate(locus_tag = ifelse(is.na(locus_tag), by_hand_locustag_map[systematicName], locus_tag)) %>%
|
| 98 |
+
mutate(symbol = ifelse(is.na(symbol), by_hand_symbol_map[locus_tag], symbol)) %>%
|
| 99 |
+
group_by(locus_tag) %>%
|
| 100 |
+
mutate(multiple_probes = n()>1) %>%
|
| 101 |
+
ungroup() %>%
|
| 102 |
+
mutate(variable_in_wt = reporterId %in%
|
| 103 |
+
setdiff(deleteome_all_mutants_controls$reporterId,
|
| 104 |
+
deleteome_ex_wt_var_controls$reporterId)) %>%
|
| 105 |
+
dplyr::rename(target_locus_tag = locus_tag,
|
| 106 |
+
target_symbol = symbol)
|
| 107 |
+
|
| 108 |
+
rm(deleteome_ex_wt_var_controls)
|
| 109 |
+
gc()
|
| 110 |
+
|
| 111 |
+
deleteome_all_mutants_controls_long = deleteome_all_mutants_controls %>%
|
| 112 |
+
pivot_longer(-c(reporterId, systematicName, geneSymbol),
|
| 113 |
+
names_to='sample_metric', values_to='values') %>%
|
| 114 |
+
separate(sample_metric, c('sample', 'metric'), sep="_") %>%
|
| 115 |
+
pivot_wider(names_from='metric', values_from='values') %>%
|
| 116 |
+
separate_wider_delim(cols=sample,
|
| 117 |
+
names=c('kemmeren_regulator', 'control'),
|
| 118 |
+
delim=";") %>%
|
| 119 |
+
mutate(kemmeren_regulator = toupper(str_remove(tolower(kemmeren_regulator), "-del-1$|-del-mata$|-del$"))) %>%
|
| 120 |
+
mutate(kemmeren_regulator = ifelse(kemmeren_regulator == "ARG5,6", "ARG56", kemmeren_regulator))
|
| 121 |
+
|
| 122 |
+
kem_sup1_regulator_info = read_excel(here("data/kemmeren/mmc1.xlsx")) %>%
|
| 123 |
+
# additional columns are not tabular
|
| 124 |
+
.[,1:9]
|
| 125 |
+
|
| 126 |
+
parsed_regulators = deleteome_all_mutants_controls_long %>%
|
| 127 |
+
select(kemmeren_regulator) %>%
|
| 128 |
+
distinct()
|
| 129 |
+
|
| 130 |
+
regulators_munging_list = list()
|
| 131 |
+
|
| 132 |
+
regulators_munging_list$x1 = parsed_regulators %>%
|
| 133 |
+
mutate(gene = kemmeren_regulator) %>%
|
| 134 |
+
left_join(kem_sup1_regulator_info) %>%
|
| 135 |
+
filter(complete.cases(.))
|
| 136 |
+
|
| 137 |
+
regulators_munging_list$x2 = parsed_regulators %>%
|
| 138 |
+
filter(!kemmeren_regulator %in% regulators_munging_list$x1$kemmeren_regulator) %>%
|
| 139 |
+
mutate(`orf name` = kemmeren_regulator) %>%
|
| 140 |
+
left_join(kem_sup1_regulator_info) %>%
|
| 141 |
+
filter(complete.cases(.))
|
| 142 |
+
|
| 143 |
+
stopifnot(length(intersect(regulators_munging_list$x1$kemmeren_regulator, regulators_munging_list$x2)) == 0)
|
| 144 |
+
|
| 145 |
+
regulators_munging_list$x3 = read_csv(here("data/kemmeren/supplement_failure_regulator_mapping.csv.gz"))
|
| 146 |
+
|
| 147 |
+
stopifnot(length(intersect(regulators_munging_list$x2$kemmeren_regulator, regulators_munging_list$x3$kemmeren_regulator)) == 0)
|
| 148 |
+
|
| 149 |
+
regulators_munging_df = bind_rows(regulators_munging_list) %>%
|
| 150 |
+
# the orf name for these two was the symbol
|
| 151 |
+
mutate(`orf name` = case_when(
|
| 152 |
+
`orf name` == "TLC1" ~ "YNCB0010W",
|
| 153 |
+
`orf name` == "CMS1" ~ "YLR003C",
|
| 154 |
+
.default = `orf name`
|
| 155 |
+
)) %>%
|
| 156 |
+
filter(kemmeren_regulator != "LUG1") %>%
|
| 157 |
+
bind_rows(tibble(
|
| 158 |
+
kemmeren_regulator = "LUG1",
|
| 159 |
+
gene = "YCR087C-A",
|
| 160 |
+
`orf name` = "YCR087C-A",
|
| 161 |
+
description = paste0("Protein of unknown function; binds zinc; phosphomutants ",
|
| 162 |
+
"exhibit phenotypes, suggesting functionality of phosphosites; green ",
|
| 163 |
+
"fluorescent protein (GFP)-fusion protein localizes to the nucleolus; ",
|
| 164 |
+
"YCR087C-A is not an essential gene"),
|
| 165 |
+
`functional category` = "unknown",
|
| 166 |
+
`slide(s)` = "THM_00005835_S01 / THM_00005836_S01",
|
| 167 |
+
`mating type` = "MATalpha",
|
| 168 |
+
`source of deletion mutant(s)` = "Open Biosystems / Open Biosystems",
|
| 169 |
+
`primary Hybset(s)` = "THM006 / THM006",
|
| 170 |
+
`responsive/non-responsive` = "responsive mutant",
|
| 171 |
+
chase_notes = paste0("This was originally called LUG1. However, that name ",
|
| 172 |
+
"for this locus was removed in 2012 per SGD. The expression confirms ",
|
| 173 |
+
"that the KO locus is YCR087C-A, not YLR352W, which is the locus ",
|
| 174 |
+
"currently called LUG1 in 2025"))) %>%
|
| 175 |
+
left_join(
|
| 176 |
+
select(gene_table, locus_tag, symbol) %>%
|
| 177 |
+
mutate(`orf name` = locus_tag) %>%
|
| 178 |
+
dplyr::rename(regulator_locus_tag = locus_tag,
|
| 179 |
+
regulator_symbol = symbol)) %>%
|
| 180 |
+
replace_na(list(chase_notes = "none")) %>%
|
| 181 |
+
mutate(regulator_locus_tag = ifelse(str_detect(kemmeren_regulator, "^WT-"), kemmeren_regulator, regulator_locus_tag),
|
| 182 |
+
regulator_symbol = ifelse(str_detect(kemmeren_regulator, "^WT-"), kemmeren_regulator, regulator_symbol))
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
stopifnot(setequal(regulators_munging_df$kemmeren_regulator,
|
| 186 |
+
unique(deleteome_all_mutants_controls_long$kemmeren_regulator)))
|
| 187 |
+
|
| 188 |
+
deleteome_all_mutants_svd_transforms =
|
| 189 |
+
read_tsv(here("data/kemmeren/deleteome_all_mutants_svd_transformed.txt.xz"),
|
| 190 |
+
name_repair = "minimal")
|
| 191 |
+
|
| 192 |
+
colnames(deleteome_all_mutants_svd_transforms)[1] = "systematicName"
|
| 193 |
+
|
| 194 |
+
colnames(deleteome_all_mutants_svd_transforms) =
|
| 195 |
+
str_replace(colnames(deleteome_all_mutants_svd_transforms), "mf.alpha.1", "mf(alpha)1")
|
| 196 |
+
colnames(deleteome_all_mutants_svd_transforms) =
|
| 197 |
+
str_replace(colnames(deleteome_all_mutants_svd_transforms), "mf.alpha.2", "mf(alpha)2")
|
| 198 |
+
colnames(deleteome_all_mutants_svd_transforms) =
|
| 199 |
+
str_replace(colnames(deleteome_all_mutants_svd_transforms), "arg5.6", "arg56")
|
| 200 |
+
|
| 201 |
+
deleteome_all_mutants_svd_transforms_long = deleteome_all_mutants_svd_transforms %>%
|
| 202 |
+
dplyr::rename(geneSymbol = commonName) %>%
|
| 203 |
+
pivot_longer(-c(systematicName, geneSymbol),
|
| 204 |
+
names_to = "condition",
|
| 205 |
+
values_to = "Madj") %>%
|
| 206 |
+
separate_wider_delim(condition,
|
| 207 |
+
names = c("kemmeren_regulator", "tmp"),
|
| 208 |
+
delim = ".",
|
| 209 |
+
too_many = "merge") %>%
|
| 210 |
+
mutate(kemmeren_regulator = toupper(kemmeren_regulator)) %>%
|
| 211 |
+
mutate(
|
| 212 |
+
# these regulators are missing appropriate suffixes
|
| 213 |
+
kemmeren_regulator = recode(kemmeren_regulator,
|
| 214 |
+
"YIL014C" = "YIL014C-A",
|
| 215 |
+
"YOL086W" = "YOL086W-A",
|
| 216 |
+
"YDR034W" = "YDR034W-B",
|
| 217 |
+
"YAL044W" = "YAL044W-A"
|
| 218 |
+
),
|
| 219 |
+
# these targets are incorrectly labeled with symbols rather than systematic IDs
|
| 220 |
+
systematicName = recode(systematicName,
|
| 221 |
+
"ANR2" = "YKL047W",
|
| 222 |
+
"CMS1" = "YLR003C"
|
| 223 |
+
)
|
| 224 |
+
) %>%
|
| 225 |
+
# this is not in the other kemmeren data
|
| 226 |
+
filter(systematicName != "Q0010")
|
| 227 |
+
|
| 228 |
+
stopifnot(length(setdiff(deleteome_all_mutants_svd_transforms_long$kemmeren_regulator,
|
| 229 |
+
regulators_munging_df$kemmeren_regulator)) == 0)
|
| 230 |
+
|
| 231 |
+
stopifnot(length(setdiff(deleteome_all_mutants_svd_transforms_long$systematicName,
|
| 232 |
+
target_df$systematicName)) == 0)
|
| 233 |
+
|
| 234 |
+
final_parsed_list = list(
|
| 235 |
+
all = deleteome_all_mutants_controls_long %>%
|
| 236 |
+
select(reporterId, kemmeren_regulator, M, A, pval) %>%
|
| 237 |
+
left_join(select(target_df, reporterId, target_locus_tag,
|
| 238 |
+
target_symbol, multiple_probes, variable_in_wt)),
|
| 239 |
+
|
| 240 |
+
slow_growth = deleteome_all_mutants_svd_transforms_long %>%
|
| 241 |
+
select(kemmeren_regulator, systematicName, Madj) %>%
|
| 242 |
+
# necessary to wrap in distinct to eliminate cases where there are two reporterId
|
| 243 |
+
left_join(distinct(select(target_df, systematicName, target_locus_tag, target_symbol))) %>%
|
| 244 |
+
select(-systematicName)
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
final_parsed_df = Reduce(left_join, final_parsed_list) %>%
|
| 248 |
+
group_by(kemmeren_regulator) %>%
|
| 249 |
+
# since the slow growth removed data identifies records by systematicName
|
| 250 |
+
# and not reporterId, there is a many-to-many join and one reporterId is
|
| 251 |
+
# duplicated to mulitple Madj. This removes those duplicates
|
| 252 |
+
distinct(reporterId, .keep_all = TRUE) %>%
|
| 253 |
+
ungroup() %>%
|
| 254 |
+
left_join(select(regulators_munging_df, kemmeren_regulator,
|
| 255 |
+
regulator_locus_tag, regulator_symbol)) %>%
|
| 256 |
+
select(regulator_locus_tag, regulator_symbol, reporterId,
|
| 257 |
+
target_locus_tag, target_symbol, M, Madj, A, pval,
|
| 258 |
+
variable_in_wt, multiple_probes)
|
| 259 |
+
|
| 260 |
+
final_parsed_df %>%
|
| 261 |
+
arrange(regulator_locus_tag) %>%
|
| 262 |
+
write_parquet(here("data/kemmeren/kemmeren_2014.parquet"),
|
| 263 |
+
compression = "zstd",
|
| 264 |
+
chunk_size = 6181,
|
| 265 |
+
write_statistics = TRUE,
|
| 266 |
+
use_dictionary = c(
|
| 267 |
+
regulator_locus_tag = TRUE,
|
| 268 |
+
target_locus_tag = TRUE
|
| 269 |
+
)
|
| 270 |
+
)
|