File size: 6,609 Bytes
2aff5da ed1b6b1 2aff5da ed1b6b1 c57c2f5 ed1b6b1 c57c2f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
library(tidyverse)
library(readxl)
library(here)
library(arrow)
# genomic feature harmonization table ----
# see https://huggingface.co/datasets/BrentLab/yeast_genome_resources
genes_table = arrow::open_dataset(here("data/genome_files/hf/features")) %>%
as_tibble()
# function to read in the harbison raw data ----
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="_")
}
# read in the raw pvalue data ----
# note that n_max is set to 6229, which is the end of the genomic data. on some
# sheets, there is data accidently left in by the original researcher
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)
# read in the raw effect ratio data ----
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)
# combine the effect and pvalue data ----
combined_harbison = harbison_effect_df %>%
select(-gene_name) %>%
left_join(select(harbison_pval_df, -gene_name)) %>%
# remove the control sample and remove locus tags that correspond to
# now deleted ORFs (these weren't merged into other annotations, they were
# simply complely removed from the annotation set)
filter(!locus_tag %in% c('YCL006C', 'YCR103C', 'YER187W-A')) %>%
dplyr::rename(harbison_locus_tag = locus_tag) %>%
mutate(tf = trimws(toupper(tf)))
# create a lookup map from the harbison targets to SGD 3-1 ----
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))
# create a lookup map from the regulator names to SGD 3-1 ----
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) %>%
# tf_main is the current SGD 3-1 symbol
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)))
# create the harmonized data ----
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)
# combined_harbison_harmonized_for_parquet %>%
# write_parquet("~/code/hf/harbison_2004/harbison_2004.parquet",
# compression = "zstd",
# write_statistics = TRUE,
# chunk_size = 6226,
# use_dictionary = c(
# sample_id = TRUE,
# condition = TRUE,
# regulator_locus_tag = TRUE,
# regulator_symbol = TRUE,
# target_locus_tag = TRUE,
# target_symbol = TRUE
# )
# )
#
#
# combined_harbison_harmonized %>%
# select(harbison_locus_tag, target_locus_tag) %>%
# distinct() %>%
# write_csv("~/code/hf/harbison_2004/scripts/harbison_locus_tag_to_target_locus_tag.csv")
#
# combined_harbison_harmonized %>%
# select(harbison_regulator, regulator_locus_tag) %>%
# distinct() %>%
# write_csv("~/code/hf/harbison_2004/scripts/harbison_regulator_to_regulator_locus_tag.csv")
|