| |
| |
|
|
| library(tidyverse) |
| library(here) |
| library(arrow) |
|
|
| |
| |
| genomefeatures = arrow::open_dataset(here("data/genome_files/hf/features")) %>% |
| as_tibble() %>% |
| mutate(rownum = row_number()) |
|
|
| chrmap = read_csv("~/projects/parsing_yeast_database_data/data/genome_files/chrmap.csv.gz") |
|
|
| |
| genomecov_files = list.files(here("data/chip_exo/paper_mimic_tag_count_20250718"), full.names = TRUE) |
|
|
| genomecov_df = tibble( |
| path = genomecov_files, |
| tmp = str_remove(basename(genomecov_files), ".mLb.mkD.sorted_r1_5p_cov.txt")) %>% |
| separate(tmp,c('sample', 'replicate'), extra = "merge", remove = FALSE) %>% |
| mutate(replicate = ifelse(sample != "control", |
| as.integer(str_extract(str_extract(replicate, "REP\\d"), "\\d")), |
| as.integer(str_extract(str_extract(replicate, "T\\d+"), "\\d+")))) |
|
|
| nf_core_meta = read_csv(here("data/chip_exo/nfcore_chipseq_full_samplesheet.csv")) %>% |
| group_by(sample) %>% |
| mutate(tmp = row_number()) %>% |
| ungroup() %>% |
| mutate(replicate = ifelse(sample == "control", tmp, replicate)) %>% |
| select(-tmp) |
|
|
| genomecov_df_meta = genomecov_df %>% |
| left_join(nf_core_meta) |
|
|
| pugh_genomecov_tmp <- genomecov_df_meta %>% |
| select(sample, replicate, run_accession, yeastepigenome_id, path) %>% |
| mutate(sample = tolower(sample)) %>% |
| left_join( |
| genomefeatures %>% |
| select(symbol, locus_tag) %>% |
| distinct() %>% |
| mutate(sample = tolower(symbol)), |
| by = "sample" |
| ) |
|
|
| filled_missing_locus_tag = pugh_genomecov_tmp %>% |
| filter(!complete.cases(.)) %>% |
| mutate( |
| alias_rownum = map_int(sample, function(s) { |
| idx <- which(str_detect(genomefeatures$alias, fixed(toupper(s)))) |
| if (length(idx) > 0) idx[1] else NA_integer_ |
| }), |
| alias_rownum = ifelse( |
| is.na(alias_rownum) & str_starts(sample, "y"), |
| map_int(sample, function(s) { |
| idx <- which(str_detect(genomefeatures$locus_tag, fixed(toupper(s)))) |
| if (length(idx) > 0) idx[1] else NA_integer_ |
| }), |
| alias_rownum |
| ) |
| ) %>% |
| select(-c(symbol, locus_tag)) %>% |
| left_join(genomefeatures %>% |
| select(rownum, symbol, locus_tag) %>% |
| dplyr::rename(alias_rownum=rownum)) %>% |
| select(-alias_rownum) |
|
|
| pugh_genomecov_meta = pugh_genomecov_tmp %>% |
| filter(!is.na(locus_tag)) %>% |
| bind_rows( |
| filled_missing_locus_tag) %>% |
| mutate(regulator_symbol = symbol, regulator_locus_tag = locus_tag) %>% |
| arrange(regulator_locus_tag) %>% |
| group_by(regulator_locus_tag) %>% |
| mutate(sample_id = cur_group_id()) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| process_chipexo_genomecov_file = function(covpath, accession_str){ |
|
|
| data.table::fread(covpath, sep = "\t", col.names=c('chr', 'pos', 'pileup')) %>% |
| left_join(chrmap %>% select(refseq, ucsc) %>% |
| dplyr::rename(chr=refseq)) %>% |
| mutate(chr = ucsc, |
| accession = accession_str) %>% |
| select(chr, pos, pileup, accession) |
|
|
| } |
|
|
|
|
| |
| output_parquet_dir = file.path(here("data/chip_exo/"), "genome_map") |
| dir.create(output_parquet_dir) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|