mahendrawada_2025 / scripts /parse_mahendrawada_data.R
cmatkhan's picture
Restructure repository with new dataset organization
5b577ce
library(tidyverse)
library(arrow)
library(here)
library(yaml)
# from fetchngs, the multiqc metadata has an easy way to map between
# accessions and samples
multiqc_chec_config = yaml::read_yaml("data/mahendrawada_multiqc_config.yml")
chec_meta <- map_dfr(multiqc_chec_config$sample_names_rename,
~tibble(!!!setNames(., multiqc_chec_config$sample_names_rename_buttons)))
genetable = arrow::read_parquet("~/code/hf/yeast_genome_resources/brentlab_features.parquet")
parsed_chec_meta = chec_meta %>%
mutate(mahendrawada_symbol = str_remove(`sample_description"`, "_\\w_ChEC-seq"),
replicate = str_remove_all(str_extract(`sample_description"`, "_(A|B|C)"), "_")) %>%
select(sample, mahendrawada_symbol, replicate) %>%
mutate(mahendrawada_symbol = str_remove(mahendrawada_symbol, "_(A|B|C)$")) %>%
mutate(
condition = str_remove(str_extract(mahendrawada_symbol, "_.*"), "^_"),
mahendrawada_symbol = toupper(str_remove(mahendrawada_symbol, "_.*"))) %>%
replace_na(list(condition = "standard")) %>%
mutate(condition = str_remove(condition, "_(A|B|C)_S\\d+_L001")) %>%
mutate(tmp_m_symbol = case_when(
mahendrawada_symbol == "MED15" ~ "GAL11",
mahendrawada_symbol == "YNR063W" ~ "PUL4",
.default = mahendrawada_symbol
)) %>%
left_join(
select(genetable, locus_tag, symbol) %>%
dplyr::rename(tmp_m_symbol = symbol,
regulator_locus_tag = locus_tag)) %>%
dplyr::rename(regulator_symbol = tmp_m_symbol) %>%
mutate(regulator_locus_tag = case_when(
regulator_symbol == "FREEMNASE" ~ "FREEMNASE",
.default = regulator_locus_tag)) %>%
dplyr::rename(sra_accession = sample)
parsed_chec_meta_with_ids = parsed_chec_meta %>%
filter(regulator_symbol != "FREEMNASE") %>%
mutate(replicate = factor(replicate, levels = c("A", "B", "C"))) %>%
arrange(regulator_locus_tag, condition, replicate) %>%
group_by(regulator_locus_tag, condition) %>%
mutate(sample_id = cur_group_id()) %>%
ungroup() %>%
mutate(replicate = as.character(replicate))
# arrow::write_parquet(parsed_chec_meta_with_ids, "~/code/hf/mahendrawada_2025/chec_genome_map_meta.parquet")
annotated_feature_meta = parsed_chec_meta_with_ids %>%
select(regulator_locus_tag, regulator_symbol, condition, sample_id) %>%
distinct()
freemnase_meta = parsed_chec_meta %>%
filter(regulator_symbol == "FREEMNASE") %>%
mutate(replicate = factor(replicate, levels = c("A", "B", "C"))) %>%
arrange(regulator_locus_tag, condition, replicate) %>%
group_by(regulator_locus_tag, condition) %>%
mutate(sample_id = cur_group_id() + max(parsed_chec_meta_with_ids$sample_id)) %>%
ungroup() %>%
mutate(replicate = as.character(replicate)) %>%
select(sra_accession, replicate, condition)
# arrow::write_parquet(freemnase_meta, "~/code/hf/mahendrawada_2025/chec_genome_map_control_meta.parquet")
mahendrawada_genome_map_bed = list.files("~/code/hf/mahendrawada_2025/chec_genome_map_bed", ".bed$")
mahendrawada_genome_map = map(
mahendrawada_genome_map_bed,
~read_tsv(file.path("~/code/hf/mahendrawada_2025/chec_genome_map_bed", .),
col_names = c("chr", "start", "end", "name", "score", "strand"))
)
names(mahendrawada_genome_map) = str_remove(mahendrawada_genome_map_bed, "_REP1.mLb.mkD.sorted_5p.bed")
mahendrawada_genome_map_df = bind_rows(
mahendrawada_genome_map,
.id = 'sra_accession')
rm(mahendrawada_genome_map)
gc()
# arrow::write_dataset(
# mahendrawada_genome_map_df,
# path = "/home/chase/code/hf/mahendrawada_2025/chec_genome_map",
# format = "parquet",
# partitioning = c("sra_accession"),
# existing_data_behavior = "overwrite",
# compression = "zstd",
# write_statistics = TRUE,
# use_dictionary = c(
# chr = TRUE))