| |
|
|
| library(tidyverse) |
| library(here) |
| library(arrow) |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| qc_django_data = read_csv("~/projects/parsing_yeast_database_data/data/qc_from_db/rr_20251222.csv") |
| expr_django_data = read_csv("~/projects/parsing_yeast_database_data/data/qc_from_db/expr_20251222.csv") |
| mcisaac_preferred_reps = expr_django_data %>% |
| filter(source_name == "mcisaac_oe") %>% |
| filter(preferred_replicate==TRUE) %>% |
| pull(id) |
|
|
| qc_django_data_in_modeling = list( |
| kemmeren = qc_django_data %>% |
| filter(binding_source == "brent_nf_cc", |
| !is.na(single_binding)) %>% |
| filter(expression_source == "kemmeren_tfko"), |
| mcisaac = qc_django_data %>% |
| filter(binding_source == "brent_nf_cc", |
| !is.na(single_binding)) %>% |
| filter(expression_source == "mcisaac_oe" |
| & expression %in% mcisaac_preferred_reps)) |
|
|
| analysis_set_meta = read_csv("~/htcf_ref/data/yeast_database_modelling/pull_data_20250805/data/brent_nf_cc_meta_20250805.csv") |
| composite_binding = read_csv("~/htcf_ref/data/yeast_database_modelling/pull_data_20250805/data/bindingconcat_meta_20250805.csv") %>% |
| filter(source_name == "brent_nf_cc") |
|
|
| barcode_details_root = "~/htcf_lts/sequence_data/yeast_cc/sequence" |
| barcode_details_list = list.files(barcode_details_root, "*_barcode_details.json", |
| recursive=TRUE) |
|
|
| passing_bam_paths = read_csv("~/htcf_local/cc/yeast/passing_bams_lookup.txt", col_names = 'bampath') |
|
|
| passing_fastq_from_bam_paths = list.files("~/htcf_local/cc/yeast/passing_fastq_from_bam") |
|
|
| fastq_df = tibble(filename = passing_fastq_from_bam_paths) %>% |
| extract( |
| filename, |
| into = c("batch", "regulator_symbol_replicate"), |
| regex = "^(.+?)_([^_]+)_passing_tagged\\.fastq\\.gz$", |
| remove = FALSE) %>% |
| mutate(replicate = str_remove(str_extract(regulator_symbol_replicate, "x\\d"), "x")) %>% |
| mutate(regulator_symbol = str_remove(regulator_symbol_replicate, "x\\d")) %>% |
| replace_na(list(replicate = '1')) %>% |
| mutate(replicate = as.integer(replicate)) %>% |
| mutate(batch = ifelse(batch == "run_5690_correct", "run_5690", batch)) %>% |
| filter(!batch %in% c('dsir4')) %>% |
| filter(regulator_symbol != "undetermined") %>% |
| |
| filter(filename != "run_6739_MOT3_passing_tagged.fastq.gz") |
|
|
| barcode_details_df = map(barcode_details_list, ~{ |
| message(sprintf("working on %s", basename(.x))) |
| x = jsonlite::read_json(file.path(barcode_details_root, .)) |
| tibble( |
| seq = names(x$components$tf$map), |
| regulator_symbol = unlist(x$components$tf$map)) %>% |
| mutate(r1_index = substr(seq,1,5), |
| r2_index = substr(seq,6,nchar(seq))) %>% |
| mutate(batch = basename(dirname(.x)))}) %>% |
| bind_rows() |
|
|
| composite_binding_unlisted = unlist(lapply(composite_binding$bindings, function(x) { |
| as.numeric(str_extract_all(x, "\\d+")[[1]])})) |
|
|
| analysis_binding_ids = c( |
| pull(filter(analysis_set_meta, !is.na(single_binding)), single_binding), |
| composite_binding_unlisted |
| ) |
|
|
|
|
| binding_django = read_csv(here("data/binding_from_django_db_20260128.csv")) |
|
|
| barcode_details_df_with_id = barcode_details_df %>% |
| mutate(replicate = str_remove(str_extract(regulator_symbol, "x\\d"), "x")) %>% |
| mutate(condition = case_when( |
| batch == "run_7380" & replicate == 2 ~ 'del_MET28', |
| regulator_symbol == "CBF1KOmet28" ~ 'del_MET28', |
| batch == "run_7380" & replicate == 2 ~ 'glu_1_gal_2', |
| batch == "run_7388" & replicate == 2 ~ 'glu_1_gal_2', |
| batch == "run_7390" & replicate == 2 ~ 'glu_1_gal_2', |
| batch == "run_7392" & replicate == 2 ~ 'glu_1_gal_2', |
| .default = 'standard')) %>% |
| mutate(replicate = ifelse(condition != "standard", 1, replicate)) %>% |
| mutate(regulator_symbol = ifelse(regulator_symbol == 'CBF1KOmet28', "CBF1", regulator_symbol)) %>% |
| mutate(regulator_symbol = str_remove(regulator_symbol, "x\\d")) %>% |
| replace_na(list(replicate = '1')) %>% |
| mutate(replicate = as.integer(replicate)) %>% |
| filter(batch != "run_5690") %>% |
| mutate(batch = ifelse(batch == 'run_5690_correct', 'run_5690', batch)) %>% |
| left_join( |
| binding_django %>% |
| select(id, regulator_symbol, batch, replicate)) %>% |
| dplyr::rename(binding_id = id) %>% |
| mutate(binding_id = as.character(binding_id)) %>% |
| replace_na(list(binding_id = "NA")) |
|
|
| brentlab_dirs = list.dirs("~/htcf_lts/sequence_data/yeast_cc/sequence", recursive=FALSE) |
| mitra_dirs = list.dirs("~/htcf_lts/sequence_data/yeast_cc/sequence/mitra_data", recursive=FALSE) |
|
|
| setdiff(basename(c(brentlab_dirs, mitra_dirs)), unique(binding_django$batch)) |
|
|
| gm_db = arrow::open_dataset("~/code/hf/callingcards/genome_map") |
|
|
| genome_map_meta_raw = arrow::read_parquet("~/code/hf/callingcards/genome_map_meta.parquet") |
|
|
| genome_map_meta = genome_map_meta_raw %>% |
| filter(condition == "standard") %>% |
| filter(!batch %in% c('dsir4')) |
|
|
| fastq_df_with_id = fastq_df %>% |
| left_join(genome_map_meta %>% |
| mutate(regulator_symbol = ifelse(str_detect(regulator_symbol, "unknown"), |
| regulator_locus_tag, |
| regulator_symbol))) %>% |
| filter(condition == 'standard') %>% |
| filter(batch != "run_7392") |
|
|
| fastq_df_lookup = fastq_df_with_id %>% |
| mutate(filename = file.path("passing_fastq_from_bam", filename), |
| newname = paste0(regulator_locus_tag, "_", regulator_symbol, "_", id)) %>% |
| select(filename, newname) |
|
|
| bam_lookup = passing_bam_paths %>% |
| mutate(base = str_remove(basename(bampath), ".bam")) %>% |
| |
| filter(base != "run_6739_MOT3_passing_tagged") %>% |
| left_join(fastq_df_lookup %>% |
| mutate(base = str_remove(basename(filename), ".fastq.gz"))) %>% |
| filter(str_detect(bampath, "undetermined", negate=TRUE)) %>% |
| select(-filename) %>% |
| |
| filter(complete.cases(.)) |
|
|
| setdiff(bam_lookup$newname, fastq_df_lookup$newname) |
| setdiff(fastq_df_lookup$newname, bam_lookup$newname) |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
|
|
| af_django_meta = arrow::read_parquet("~/code/hf/callingcards/annotated_features_meta.parquet") %>% |
| filter(condition == "standard") %>% |
| filter(genome_map_id %in% genome_map_meta$id) %>% |
| replace_na(list(binding_id = "NA")) %>% |
| mutate(data_usable = case_when( |
| batch %in% c('run_7477', 'run_7487') |
| & regulator_symbol %in% c('ACE2', 'ARG80', 'ARG81', 'LYS14', |
| 'STB5', 'SWI5', 'SWI6', 'CUP9', 'DAL80') ~ "pass", |
| batch %in% c('run_7477', 'run_7487') |
| & regulator_symbol %in% c('WTM1', 'MIG2', 'DIG1', 'ACA1') ~ "fail", |
| .default = data_usable)) %>% |
| mutate(in_modeling_analysis = binding_id %in% analysis_binding_ids) %>% |
| mutate(kemmeren_dto = binding_id %in% |
| (qc_django_data_in_modeling$kemmeren %>% |
| filter(dto_empirical_pvalue <= 0.01) %>% |
| pull(single_binding))) %>% |
| mutate(mcisaac_dto = binding_id %in% |
| (qc_django_data_in_modeling$mcisaac %>% |
| filter(dto_empirical_pvalue <= 0.01) %>% |
| pull(single_binding))) %>% |
| left_join(qc_django_data %>% |
| filter(!is.na(single_binding), binding_source == "brent_nf_cc") %>% |
| select(single_binding, genomic_inserts) %>% |
| distinct() %>% |
| mutate(single_binding = as.character(single_binding)) %>% |
| dplyr::rename(binding_id = single_binding)) %>% |
| left_join(select(barcode_details_df_with_id, condition, regulator_symbol, batch, binding_id, r1_index, r2_index)) %>% |
| dplyr::select(id, genome_map_id, batch, |
| r1_index, r2_index, |
| regulator_locus_tag, regulator_symbol, |
| data_usable, kemmeren_dto, mcisaac_dto, genomic_inserts, |
| in_modeling_analysis) %>% |
| mutate(notes = case_when( |
| genome_map_id %in% c(690, 685) ~ "manually exluded from analysis in favor of library 242", |
| genome_map_id %in% c(26, 612, 300, 119) ~ "less than 3k insertions", |
| .default = "none")) %>% |
| arrange(genome_map_id) |
|
|
| af_db = arrow::open_dataset("~/code/hf/callingcards/annotated_features") |
|
|
| setdiff(basename(c(brentlab_dirs, mitra_dirs)), unique(genome_map_meta$batch)) |
| setdiff(unique(genome_map_meta$batch),basename(c(brentlab_dirs, mitra_dirs))) |
|
|
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| id_batch_combos <- af_django_meta %>% |
| select(id, genome_map_id, batch) %>% |
| distinct() |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| af_data = arrow::open_dataset("~/code/hf/callingcards/annotated_features") %>% |
| filter(id %in% af_django_meta$id) %>% |
| collect() %>% |
| left_join( |
| af_django_meta %>% |
| mutate(regulator_locus_tag = as.character(regulator_locus_tag), |
| regulator_symbol = as.character(regulator_symbol)) %>% |
| mutate(regulator_symbol = ifelse(str_detect(regulator_symbol, "unknown"), regulator_locus_tag, regulator_symbol)) %>% |
| mutate(filename = paste0(regulator_locus_tag, "_", regulator_symbol, "_", genome_map_id)) %>% |
| select(id, genome_map_id, filename)) |
|
|
| promoters = read_tsv("~/code/hf/yeast_genome_resources/yiming_promoters.bed", |
| col_names = c("chr", "start", "end", "target_locus_tag", "score", "strand")) %>% |
| dplyr::select(target_locus_tag, chr, start, end, strand) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| submission_df = af_django_meta %>% |
| select(-id) %>% |
| arrange(regulator_locus_tag) %>% |
| mutate(regulator_locus_tag = as.character(regulator_locus_tag), |
| regulator_symbol = as.character(regulator_symbol)) %>% |
| mutate(regulator_symbol = ifelse( |
| str_detect(regulator_symbol, "unknown"), |
| regulator_locus_tag, |
| regulator_symbol)) %>% |
| mutate(`library name` = paste0(regulator_locus_tag, "_", regulator_symbol, "_", genome_map_id)) %>% |
| mutate(title = paste0(regulator_locus_tag, " (", regulator_symbol, ") calling cards; gmid ", genome_map_id), |
| `library strategy` = "OTHER", |
| organism = 'Saccharomyces cerevisiae', |
| `cell line` = "Saccharomyces cerevisiae S288C", |
| molecule = 'genomic DNA', |
| `single or paired-end` = 'single', |
| `instrument model` = 'Illumina MiSeq', |
| description = paste0(regulator_locus_tag, " tagged callingcards experiment. ", |
| "kemmeren_dto: ", kemmeren_dto, "; mcisaac_dto: ", mcisaac_dto, |
| "; in_modeling_analysis: ", in_modeling_analysis, |
| "; notes: ", notes), |
| `processed data file` = paste0(`library name`, ".csv.gz"), |
| `raw file` = paste0(`library name`, ".bam")) %>% |
| dplyr::rename(perturbation_validated = data_usable) %>% |
| dplyr::select( |
| `library name`, title, `library strategy`, organism, `cell line`, |
| molecule, `single or paired-end`, `instrument model`, |
| description, perturbation_validated, |
| `processed data file`, `raw file` |
| ) |
|
|
| setdiff(paste0(bam_lookup$newname,".bam"), submission_df$`raw file`) |
| setdiff(submission_df$`raw file`, paste0(bam_lookup$newname,".bam")) |
|
|
| write_csv(submission_df, here("data/cc_submission_df.csv")) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|