mahendrawada_2025 / scripts /parse_authors_data.R
cmatkhan's picture
Restructure repository with new dataset organization
5b577ce
library(tidyverse)
library(here)
library(arrow)
library(readxl)
# from fetchngs, the multiqc metadata has an easy way to map between
# accessions and samples
multqc_chec_config = yaml::read_yaml("~/Downloads/multiqc_config.yml")
chec_meta <- map_dfr(multqc_chec_config$sample_names_rename,
~tibble(!!!setNames(., multqc_chec_config$sample_names_rename_buttons)))
# genomic feature harmonization table ----
# see https://huggingface.co/datasets/BrentLab/yeast_genome_resources
genomicfeatures = arrow::open_dataset(here("data/genome_files/hf/features")) %>%
as_tibble()
chec_data = read_excel(here("data/mahendrawada_2024_rnaseq/41586_2025_8916_MOESM5_ESM.xlsx"),
sheet="Table-S3b") %>%
dplyr::rename(mahedrawada_target = `...1`) %>%
pivot_longer(-mahedrawada_target,
names_to = "mahedrawada_regulator_orig",
values_to = "peak_score") %>%
arrange(mahedrawada_regulator_orig, mahedrawada_target) %>%
filter(!is.na(peak_score)) %>%
mutate(mahedrawada_regulator = case_when(
mahedrawada_regulator_orig == "MED15" ~ "GAL11",
mahedrawada_regulator_orig == "YNR063W" ~ "PUL4",
.default = mahedrawada_regulator_orig
))
rnaseq_data = read_excel(here("data/mahendrawada_2024_rnaseq/41586_2025_8916_MOESM5_ESM.xlsx"),
sheet="Table-S3c") %>%
dplyr::rename(mahedrawada_target = `...1`) %>%
pivot_longer(-c(mahedrawada_target, Kmeans_clusters),
names_to = "mahedrawada_regulator_tmp",
values_to = "log2fc") %>%
arrange(mahedrawada_regulator_tmp, mahedrawada_target) %>%
filter(!is.na(log2fc)) %>%
separate(mahedrawada_regulator_tmp, into = c("mahedrawada_regulator_orig", "cond")) %>%
replace_na(list(cond="SC")) %>%
mutate(
mahedrawada_regulator = case_when(
mahedrawada_regulator_orig == "MED15" ~ "GAL11",
mahedrawada_regulator_orig == "GALG4" ~ "GAL4",
mahedrawada_regulator_orig == "YNR063W" ~ "PUL4",
.default = mahedrawada_regulator_orig),
cond = case_when(
mahedrawada_regulator_orig == "GALG4" ~ "GAL",
.default = cond
))
mahedrawada_genomicfeatures <- read_excel(
here("data/mahendrawada_2024_rnaseq/41586_2025_8916_MOESM4_ESM.xlsx"),
sheet = "ref_all"
) %>%
mutate(gene_name = case_when(
gene_name == "YPR022C" ~ "SDD4",
gene_name == "YNR063W" ~ "PUL4",
.default = gene_name
))
stopifnot(setequal(intersect(chec_data$mahedrawada_target, mahedrawada_genomicfeatures$gene_id),
chec_data$mahedrawada_target))
stopifnot(setequal(intersect(rnaseq_data$mahedrawada_target, mahedrawada_genomicfeatures$gene_id),
rnaseq_data$mahedrawada_target))
stopifnot(setequal(intersect(chec_data$mahedrawada_regulator, mahedrawada_genomicfeatures$gene_name),
chec_data$mahedrawada_regulator))
stopifnot(setequal(intersect(rnaseq_data$mahedrawada_regulator, mahedrawada_genomicfeatures$gene_name),
rnaseq_data$mahedrawada_regulator))
# note: verified by hand that where the symbol != gene_name, that the gene_name
# was listed as an alias of the current official symbol.
# Where the gene_name is == to the gene_id, that id is == to the locus_tag
stopifnot(
tibble(mahedrawada_target = union(chec_data$mahedrawada_target,
rnaseq_data$mahedrawada_target)) %>%
left_join(genomicfeatures %>% select(locus_tag, symbol),
by = c("mahedrawada_target" = "locus_tag")) %>%
left_join(mahedrawada_genomicfeatures %>% select(gene_name, gene_id),
by = c("mahedrawada_target" = "gene_id")) %>%
filter(!complete.cases(.)) %>%
nrow() == 0)
stopifnot(
tibble(mahedrawada_regulator = union(chec_data$mahedrawada_regulator,
rnaseq_data$mahedrawada_regulator)) %>%
left_join(genomicfeatures %>%
select(locus_tag, symbol),
by = c("mahedrawada_regulator" = "symbol")) %>%
left_join(mahedrawada_genomicfeatures %>%
select(gene_name, gene_id),
by = c("mahedrawada_regulator" = "gene_name")) %>%
filter(!complete.cases(.) | locus_tag != gene_id) %>%
nrow() == 0)
chec_data_final = chec_data %>%
left_join(
genomicfeatures %>%
select(locus_tag, symbol) %>%
mutate(mahedrawada_target = locus_tag) %>%
dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol)) %>%
left_join(
genomicfeatures %>%
select(locus_tag, symbol) %>%
mutate(mahedrawada_regulator = symbol) %>%
dplyr::rename(regulator_locus_tag = locus_tag, regulator_symbol = symbol)) %>%
select(regulator_locus_tag, regulator_symbol, target_locus_tag, target_symbol, peak_score) %>%
arrange(regulator_locus_tag, target_locus_tag)
rnaseq_data_final = rnaseq_data %>%
left_join(
genomicfeatures %>%
select(locus_tag, symbol) %>%
mutate(mahedrawada_target = locus_tag) %>%
dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol)) %>%
left_join(
genomicfeatures %>%
select(locus_tag, symbol) %>%
mutate(mahedrawada_regulator = symbol) %>%
dplyr::rename(regulator_locus_tag = locus_tag, regulator_symbol = symbol)) %>%
select(regulator_locus_tag, regulator_symbol, target_locus_tag, target_symbol, log2fc) %>%
arrange(regulator_locus_tag, target_locus_tag)
sample_id_map = tibble(
regulator_locus_tag = union(rnaseq_data_final$regulator_locus_tag,
chec_data_final$regulator_locus_tag)) %>%
mutate(sample_id = row_number())
# chec_data_final %>%
# left_join(sample_id_map) %>%
# select(sample_id, all_of(colnames(chec_data_final))) %>%
# write_parquet(here("~/code/hf/mahendrawada_2025/chec_mahendrawada_2025.parquet"),
# compression = "zstd",
# write_statistics = TRUE,
# use_dictionary = c(
# sample_id = TRUE,
# regulator_locus_tag = TRUE,
# regulator_symbol = TRUE,
# target_locus_tag = TRUE,
# target_symbol = TRUE
# )
# )
#
# rnaseq_data_final %>%
# left_join(sample_id_map) %>%
# select(sample_id, all_of(colnames(rnaseq_data_final))) %>%
# write_parquet(here("~/code/hf/mahendrawada_2025/rnaseq_mahendrawada_2025.parquet"),
# compression = "zstd",
# write_statistics = TRUE,
# use_dictionary = c(
# sample_id = TRUE,
# regulator_locus_tag = TRUE,
# regulator_symbol = TRUE,
# target_locus_tag = TRUE,
# target_symbol = TRUE
# )
# )
#
# mahedrawada_genomicfeatures %>%
# left_join(genomicfeatures %>%
# select(locus_tag, symbol) %>%
# mutate(gene_id = locus_tag)) %>%
# write_parquet(here("~/code/hf/mahendrawada_2025/features_mahendrawada_2025.parquet"),
# compression = "zstd",
# write_statistics = TRUE,
# use_dictionary = c(
# gene_id = TRUE,
# gene_name = TRUE,
# chr = TRUE,
# locus_tag = TRUE,
# symbol = TRUE,
# coactivator = TRUE
# )
# )