|
|
library(tidyverse) |
|
|
library(readxl) |
|
|
library(here) |
|
|
library(arrow) |
|
|
|
|
|
|
|
|
|
|
|
genes_table = arrow::open_dataset(here("data/genome_files/hf/features")) %>% |
|
|
as_tibble() |
|
|
|
|
|
|
|
|
read_in_harbison_data = function(xls_path, sheet_name, values_colname, n_max=6229){ |
|
|
read_excel(xls_path, |
|
|
sheet=sheet_name, |
|
|
skip=1, |
|
|
n_max = n_max) %>% |
|
|
dplyr::rename(locus_tag=`...1`, |
|
|
gene_name=`...2`, |
|
|
description=`...3`) %>% |
|
|
mutate(across(!c(locus_tag, gene_name, description), as.numeric)) %>% |
|
|
pivot_longer(!c(locus_tag, gene_name, description), |
|
|
names_to='tf_cond', |
|
|
values_to=values_colname) %>% |
|
|
separate(tf_cond, c('tf', 'condition'), sep="_") |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
harbison_pval_df_list = list( |
|
|
ypd = read_in_harbison_data( |
|
|
here('data/harbison/pvalbygene_forpaper_abbr.xls'), |
|
|
'YPD', |
|
|
'pvalue'), |
|
|
other_conds = read_in_harbison_data( |
|
|
here('data/harbison/pvalbygene_forpaper_abbr.xls'), |
|
|
"other conditions", |
|
|
"pvalue") |
|
|
) |
|
|
|
|
|
harbison_pval_df = bind_rows(harbison_pval_df_list) |
|
|
|
|
|
|
|
|
harbison_effect_df_list = list( |
|
|
ypd = read_in_harbison_data( |
|
|
here('data/harbison/ratiobygene_forpaper_abbr.xls'), |
|
|
'YPD', |
|
|
"effect"), |
|
|
other_conds = read_in_harbison_data( |
|
|
here('data/harbison/ratiobygene_forpaper_abbr.xls'), |
|
|
'Other Conditions', |
|
|
'effect')) |
|
|
|
|
|
harbison_effect_df = bind_rows(harbison_effect_df_list) |
|
|
|
|
|
|
|
|
combined_harbison = harbison_effect_df %>% |
|
|
select(-gene_name) %>% |
|
|
left_join(select(harbison_pval_df, -gene_name)) %>% |
|
|
|
|
|
|
|
|
|
|
|
filter(!locus_tag %in% c('YCL006C', 'YCR103C', 'YER187W-A')) %>% |
|
|
dplyr::rename(harbison_locus_tag = locus_tag) %>% |
|
|
mutate(tf = trimws(toupper(tf))) |
|
|
|
|
|
|
|
|
locus_tags = combined_harbison %>% |
|
|
select(harbison_locus_tag) %>% |
|
|
distinct() %>% |
|
|
left_join(genes_table, by = c("harbison_locus_tag" = "locus_tag")) %>% |
|
|
mutate(locus_tag = harbison_locus_tag) %>% |
|
|
select(harbison_locus_tag, locus_tag, symbol) |
|
|
|
|
|
locus_tags_aliases = read_csv('data/harbison/locus_tags_aliases.csv') %>% |
|
|
left_join(genes_table, by = c('curr_notation'='locus_tag')) %>% |
|
|
dplyr::rename(locus_tag = curr_notation) %>% |
|
|
select(harbison_locus_tag, locus_tag, symbol) |
|
|
|
|
|
locus_tags_complete = locus_tags %>% |
|
|
filter(!is.na(symbol)) %>% |
|
|
bind_rows(locus_tags_aliases) %>% |
|
|
dplyr::rename(target_locus_tag = locus_tag, |
|
|
target_symbol = symbol) |
|
|
|
|
|
stopifnot(nrow(locus_tags_complete) == nrow(locus_tags)) |
|
|
|
|
|
stopifnot(setequal(unique(combined_harbison$harbison_locus_tag), |
|
|
locus_tags_complete$harbison_locus_tag)) |
|
|
|
|
|
|
|
|
tf_symbol_to_locus_tag_df = combined_harbison %>% |
|
|
select(tf) %>% |
|
|
mutate(tf = trimws(toupper(tf))) %>% |
|
|
distinct() %>% |
|
|
left_join(genes_table, by = c('tf' = 'symbol')) %>% |
|
|
select(tf, locus_tag) %>% |
|
|
dplyr::rename(regulator_locus_tag = locus_tag) %>% |
|
|
mutate(regulator_symbol = tf) %>% |
|
|
select(tf, regulator_symbol, regulator_locus_tag) |
|
|
|
|
|
tf_locus_tag_to_locus_tag_df = tf_symbol_to_locus_tag_df %>% |
|
|
filter(!complete.cases(.)) %>% |
|
|
select(tf) %>% |
|
|
left_join(genes_table, by = c('tf' = 'locus_tag')) %>% |
|
|
filter(!is.na(symbol)) %>% |
|
|
select(tf, symbol) %>% |
|
|
dplyr::rename(regulator_symbol = symbol) %>% |
|
|
mutate(regulator_locus_tag = tf) |
|
|
|
|
|
tf_name_df_na = read_csv("data/harbison/tf_name_aliases.csv") %>% |
|
|
left_join(genes_table) %>% |
|
|
|
|
|
select(tf, tf_main, locus_tag) %>% |
|
|
dplyr::rename(regulator_symbol = tf_main, regulator_locus_tag = locus_tag) %>% |
|
|
select(tf, regulator_symbol, regulator_locus_tag) |
|
|
|
|
|
harbison_tf_map = bind_rows( |
|
|
tf_symbol_to_locus_tag_df[complete.cases(tf_symbol_to_locus_tag_df),], |
|
|
tf_locus_tag_to_locus_tag_df, |
|
|
tf_name_df_na |
|
|
) |
|
|
|
|
|
stopifnot(setequal(harbison_tf_map$tf, unique(combined_harbison$tf))) |
|
|
|
|
|
|
|
|
combined_harbison_harmonized = combined_harbison %>% |
|
|
left_join(harbison_tf_map) %>% |
|
|
left_join(locus_tags_complete) %>% |
|
|
dplyr::rename(harbison_regulator=tf) %>% |
|
|
select(-description) |
|
|
|
|
|
harbison_db_meta <- read_csv("data/promotersetsig_db_20251127.csv", |
|
|
col_types = cols(composite_binding = col_character())) |
|
|
|
|
|
db_id_map = harbison_db_meta %>% |
|
|
filter(source_name == "harbison_chip") %>% |
|
|
select(id, regulator_locus_tag, condition) %>% |
|
|
distinct() %>% |
|
|
dplyr::rename(db_id = id) %>% |
|
|
bind_rows( |
|
|
tibble( |
|
|
regulator_locus_tag = c("YSC0017"), |
|
|
db_id = 0, |
|
|
condition = c('YPD') |
|
|
)) |
|
|
|
|
|
combined_harbison_harmonized_for_parquet = combined_harbison_harmonized %>% |
|
|
select(regulator_locus_tag, regulator_symbol, |
|
|
condition, target_locus_tag, target_symbol, |
|
|
effect, pvalue) %>% |
|
|
left_join(db_id_map) %>% |
|
|
arrange(db_id) %>% |
|
|
group_by(db_id) %>% |
|
|
mutate(sample_id = cur_group_id()) %>% |
|
|
ungroup() %>% |
|
|
select(sample_id, db_id, regulator_locus_tag, regulator_symbol, |
|
|
condition, |
|
|
target_locus_tag, target_symbol, |
|
|
effect, pvalue) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|