|
|
library(tidyverse) |
|
|
library(httr) |
|
|
library(here) |
|
|
library(arrow) |
|
|
library(readxl) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gene_table = arrow::open_dataset(here("data/genome_files/hf/features")) %>% |
|
|
as_tibble() |
|
|
|
|
|
|
|
|
hu_data = list( |
|
|
de = here("data/hu/gkq232_SuppTable1C_KOTargetGenes_Matrix_LogFoldChange.dat.xz"), |
|
|
pval = here("data/hu/gkq232_SuppTable1B_KOTargetGenes_Matrix_PValue.dat.xz") |
|
|
) |
|
|
|
|
|
hu_de_target_genes = as.character(read_delim(hu_data$de, |
|
|
delim=' ', |
|
|
col_names = FALSE, |
|
|
n_max = 1)[1,]) |
|
|
hu_de_target_genes = str_replace(hu_de_target_genes, "\\.", "-") |
|
|
|
|
|
hu_de_colnames = c('hu_regulator', hu_de_target_genes) |
|
|
|
|
|
hu_pval_target_genes = as.character(read_delim(hu_data$pval, |
|
|
delim=' ', |
|
|
col_names = FALSE, |
|
|
n_max = 1)[1,]) |
|
|
hu_pval_target_genes = str_replace(hu_pval_target_genes, "\\.", "-") |
|
|
|
|
|
hu_pval_colnames = c('hu_regulator', hu_pval_target_genes) |
|
|
|
|
|
stopifnot(setequal(hu_pval_colnames, hu_de_colnames)) |
|
|
|
|
|
|
|
|
|
|
|
de_df = read.delim( |
|
|
hu_data$de, |
|
|
sep=' ', |
|
|
col.names = hu_de_colnames, |
|
|
check.names=FALSE) %>% |
|
|
as_tibble() |
|
|
|
|
|
|
|
|
|
|
|
pval_df = read.delim( |
|
|
hu_data$pval, |
|
|
sep=' ', |
|
|
col.names = hu_pval_colnames, |
|
|
check.names=FALSE) %>% |
|
|
as_tibble() |
|
|
|
|
|
hu_df = de_df %>% |
|
|
pivot_longer(-hu_regulator, |
|
|
names_to='hu_target', |
|
|
values_to='effect') %>% |
|
|
left_join(pval_df %>% |
|
|
pivot_longer(-hu_regulator, |
|
|
names_to='hu_target', |
|
|
values_to='pval')) %>% |
|
|
mutate(hu_regulator = toupper(hu_regulator)) %>% |
|
|
|
|
|
filter(!hu_target %in% c('YER187W-A', 'YCR103C', 'YCL006C', "YIL080W")) |
|
|
|
|
|
tf_map = list() |
|
|
|
|
|
tf_map$init = hu_df %>% |
|
|
distinct(hu_regulator) %>% |
|
|
mutate(regulator_symbol = hu_regulator) %>% |
|
|
|
|
|
mutate(regulator_symbol = case_when( |
|
|
regulator_symbol == "CAF17" ~ "IBA57", |
|
|
regulator_symbol == "RCS1" ~ "AFT1", |
|
|
regulator_symbol == "RLR1" ~ "THO2", |
|
|
regulator_symbol == "ZMS1" ~ "RSF2", |
|
|
regulator_symbol == "RIS1" ~ "ULS1", |
|
|
.default = regulator_symbol |
|
|
)) %>% |
|
|
left_join(gene_table %>% |
|
|
select(symbol,locus_tag) %>% |
|
|
dplyr::rename(regulator_locus_tag = locus_tag, |
|
|
regulator_symbol = symbol)) %>% |
|
|
mutate(regulator_symbol = ifelse(is.na(regulator_locus_tag), |
|
|
NA, |
|
|
regulator_symbol)) |
|
|
|
|
|
tf_map$locus_tags = tf_map$init %>% |
|
|
filter(!complete.cases(.)) %>% |
|
|
select(hu_regulator) %>% |
|
|
mutate(regulator_locus_tag = hu_regulator) %>% |
|
|
left_join(gene_table %>% |
|
|
select(symbol,locus_tag) %>% |
|
|
dplyr::rename(regulator_locus_tag = locus_tag, |
|
|
regulator_symbol = symbol)) |
|
|
|
|
|
tf_map_df = bind_rows( |
|
|
tf_map$init %>% filter(complete.cases(.)), |
|
|
tf_map$locus_tags |
|
|
) |
|
|
|
|
|
stopifnot(setequal(tf_map$init$hu_regulator, tf_map_df$hu_regulator)) |
|
|
|
|
|
target_map = list() |
|
|
|
|
|
target_map$init = hu_df %>% |
|
|
distinct(hu_target) %>% |
|
|
mutate(target_locus_tag = hu_target) %>% |
|
|
left_join(select(gene_table, locus_tag, symbol) |
|
|
%>% dplyr::rename(target_locus_tag = locus_tag, |
|
|
target_symbol = symbol)) |
|
|
|
|
|
target_map$alias_df = gene_table %>% |
|
|
mutate(hu_target = map_chr(alias, ~ { |
|
|
alias_i <- .x |
|
|
match <- keep(target_map$init %>% |
|
|
filter(!complete.cases(.)) %>% |
|
|
pull(hu_target), |
|
|
~ str_detect(alias_i, .x)) |
|
|
if (length(match) > 0) match[[1]] else NA_character_ |
|
|
})) %>% |
|
|
filter(!is.na(hu_target)) %>% |
|
|
select(hu_target, locus_tag, symbol) %>% |
|
|
dplyr::rename(target_locus_tag = locus_tag, |
|
|
target_symbol = symbol) |
|
|
|
|
|
target_map_df = bind_rows(target_map$init %>% filter(complete.cases(.)), |
|
|
target_map$alias_df) |
|
|
|
|
|
stopifnot(setequal(target_map_df$hu_target, |
|
|
unique(hu_df$hu_target))) |
|
|
|
|
|
final_df = hu_df %>% |
|
|
left_join(tf_map_df) %>% |
|
|
left_join(target_map_df) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
supplement_table_1 = readxl::read_excel("data/hu/41588_2007_BFng2012_MOESM20_ESM.xlsx") %>% |
|
|
janitor::clean_names() %>% |
|
|
dplyr::rename(regulator_locus_tag = `tf_systematic_name`) %>% |
|
|
select(-tf_gene_name) %>% |
|
|
mutate(heat_shock = str_detect(growth_condition, "heat-shock"), |
|
|
tetracycline_treatment = str_detect(growth_condition, "tetracycline treatment")) %>% |
|
|
select(-growth_condition) |
|
|
|
|
|
supplement_table_1_filt = supplement_table_1 %>% |
|
|
filter(!heat_shock, !tetracycline_treatment) |
|
|
|
|
|
supplement_table_1_metadata = supplement_table_1_filt %>% |
|
|
bind_rows( |
|
|
supplement_table_1 %>% |
|
|
filter( |
|
|
!heat_shock, |
|
|
regulator_locus_tag %in% |
|
|
setdiff(final_df$regulator_locus_tag, |
|
|
supplement_table_1_filt$regulator_locus_tag))) |
|
|
|
|
|
final_df_for_parquet = final_df %>% |
|
|
mutate(sample_id = cur_group_id()) %>% |
|
|
select(sample_id, |
|
|
regulator_locus_tag, regulator_symbol, |
|
|
target_locus_tag, target_symbol, |
|
|
effect, pval) %>% |
|
|
ungroup() %>% |
|
|
arrange(regulator_locus_tag) %>% |
|
|
left_join(supplement_table_1_metadata) |
|
|
|
|
|
|
|
|
final_df_for_parquet %>% |
|
|
write_parquet(here("~/code/hf/hu_2007_reimand_2010/hu_2007_reimand_2010.parquet"), |
|
|
compression = "zstd", |
|
|
chunk_size = 6249, |
|
|
write_statistics = TRUE, |
|
|
use_dictionary = c( |
|
|
sample_id = TRUE, |
|
|
regulator_locus_tag = TRUE, |
|
|
regulator_symbol = TRUE, |
|
|
target_locus_tag = TRUE, |
|
|
target_symbol = TRUE, |
|
|
heat_shock = TRUE, |
|
|
tetracycline_treatment = TRUE |
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|