|
|
library(tidyverse) |
|
|
library(DESeq2) |
|
|
library(arrow) |
|
|
library(here) |
|
|
|
|
|
|
|
|
run_degron_deseq2 <- function(regulator_sym, env_cond, timepoint_val, |
|
|
degron_data = degron, |
|
|
baseline_data = baseline_control) { |
|
|
|
|
|
|
|
|
degron_meta_filtered <- degron_data$meta %>% |
|
|
filter( |
|
|
regulator_symbol == regulator_sym, |
|
|
env_condition == env_cond, |
|
|
timepoint == timepoint_val) %>% |
|
|
mutate(degron_treatment = factor(degron_treatment, |
|
|
levels = c("DMSO", "IAA"))) |
|
|
|
|
|
|
|
|
|
|
|
if (nrow(degron_meta_filtered) != 6) { |
|
|
stop(sprintf("We expect exactly 3 replicates in each conditition for a total of 6 samples. These parameters result in %s", nrow(degron_meta_filtered))) |
|
|
} |
|
|
|
|
|
|
|
|
iaa_samples <- degron_meta_filtered %>% |
|
|
filter(degron_treatment == "IAA") %>% |
|
|
pull(sra_accession) |
|
|
|
|
|
dmso_samples <- degron_meta_filtered %>% |
|
|
filter(degron_treatment == "DMSO") %>% |
|
|
pull(sra_accession) |
|
|
|
|
|
if (length(iaa_samples) != 3 || length(dmso_samples) != 3) { |
|
|
stop("Missing IAA or DMSO samples for the specified parameters") |
|
|
} |
|
|
|
|
|
|
|
|
counts_filtered <- degron_data$counts_long %>% |
|
|
filter(sra_accession %in% c(iaa_samples, dmso_samples)) |
|
|
|
|
|
|
|
|
counts_wide <- counts_filtered %>% |
|
|
select(target_locus_tag, sra_accession, count) %>% |
|
|
pivot_wider( |
|
|
names_from = sra_accession, |
|
|
values_from = count) %>% |
|
|
column_to_rownames("target_locus_tag") |
|
|
|
|
|
|
|
|
sample_meta <- degron_meta_filtered %>% |
|
|
select(sra_accession, degron_treatment) %>% |
|
|
column_to_rownames("sra_accession") |
|
|
|
|
|
|
|
|
counts_wide <- counts_wide[, rownames(sample_meta)] |
|
|
|
|
|
|
|
|
dds <- DESeqDataSetFromMatrix( |
|
|
countData = counts_wide, |
|
|
colData = sample_meta, |
|
|
design = ~ degron_treatment |
|
|
) |
|
|
|
|
|
|
|
|
dds <- DESeq(dds) |
|
|
|
|
|
|
|
|
res <- results(dds) |
|
|
|
|
|
|
|
|
return(list( |
|
|
dds = dds, |
|
|
results = res %>% |
|
|
as_tibble(rownames="target_locus_tag") %>% |
|
|
mutate(sample_id = paste(unique(degron_meta_filtered$sample_id), collapse="_")) %>% |
|
|
left_join(distinct(degron$counts_long %>% select(target_locus_tag, target_symbol))) %>% |
|
|
mutate(regulator_locus_tag = unique(degron_meta_filtered$regulator_locus_tag), |
|
|
regulator_symbol = unique(degron_meta_filtered$regulator_symbol), |
|
|
env_condition = unique(degron_meta_filtered$env_condition), |
|
|
timepoint = unique(degron_meta_filtered$timepoint)) %>% |
|
|
dplyr::relocate(sample_id, regulator_locus_tag, regulator_symbol, |
|
|
env_condition, timepoint), |
|
|
metadata = degron_meta_filtered |
|
|
)) |
|
|
} |
|
|
|
|
|
|
|
|
baseline_control = list( |
|
|
counts_long = arrow::read_parquet( |
|
|
"~/code/hf/mahendrawada_2025/wt_baseline_counts.parquet"), |
|
|
meta = arrow::read_parquet( |
|
|
"~/code/hf/mahendrawada_2025/wt_baseline_counts_meta.parquet") |
|
|
) |
|
|
|
|
|
degron = list( |
|
|
counts_long = arrow::read_parquet("~/code/hf/mahendrawada_2025/degron_counts.parquet"), |
|
|
meta = arrow::read_parquet("~/code/hf/mahendrawada_2025/degron_counts_meta.parquet") |
|
|
) |
|
|
|
|
|
z = run_degron_deseq2("CYC8", 'standard_30C', 30, degron, baseline_control) |
|
|
|
|
|
x = map(unique(degron$meta$regulator_symbol), |
|
|
~run_degron_deseq2(., 'standard_30C', 30, degron, baseline_control)) |
|
|
|
|
|
results_df <- map_dfr(x, ~.$results) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|