| library(arrow) |
| library(duckdb) |
| library(tidyverse) |
|
|
|
|
| full_data = arrow::read_parquet("~/code/hf/hackett_2020/hackett_2020.parquet") |
|
|
| con <- duckdb::dbConnect(duckdb::duckdb()) |
| duckdb::duckdb_register_arrow(con, "hackett_meta", arrow::open_dataset("~/code/hf/hackett_2020/hackett_2020.parquet")) |
|
|
| query <- " |
| WITH regulator_tiers AS ( |
| SELECT |
| regulator_locus_tag, |
| CASE |
| WHEN BOOL_OR(mechanism = 'ZEV' AND restriction = 'P') THEN 1 |
| WHEN BOOL_OR(mechanism = 'GEV' AND restriction = 'P') THEN 2 |
| ELSE 3 |
| END AS tier |
| FROM hackett_meta |
| GROUP BY regulator_locus_tag |
| ), |
| tier_filtered AS ( |
| SELECT |
| h.*, |
| t.tier |
| FROM hackett_meta h |
| JOIN regulator_tiers t USING (regulator_locus_tag) |
| WHERE |
| (t.tier = 1 AND h.mechanism = 'ZEV' AND h.restriction = 'P') |
| OR (t.tier = 2 AND h.mechanism = 'GEV' AND h.restriction = 'P') |
| OR (t.tier = 3 AND h.mechanism = 'GEV' AND h.restriction = 'M') |
| ) |
| SELECT DISTINCT |
| sample_id, |
| db_id, |
| regulator_locus_tag, |
| regulator_symbol, |
| target_locus_tag, |
| target_symbol, |
| time, |
| mechanism, |
| restriction, |
| date, |
| strain, |
| green_median, |
| red_median, |
| log2_ratio, |
| log2_cleaned_ratio, |
| log2_noise_model, |
| log2_cleaned_ratio_zth2d, |
| log2_selected_timecourses, |
| log2_shrunken_timecourses, |
| responsive |
| FROM tier_filtered |
| WHERE regulator_symbol NOT IN ('GCN4', 'RDS2', 'SWI1', 'MAC1') |
| " |
|
|
| result <- DBI::dbGetQuery(con, query) |
| duckdb::dbDisconnect(con) |
|
|
| analysis_set_ids <- result |> distinct(sample_id) |> pull(sample_id) |
|
|
| full_data <- full_data |> |
| mutate(analysis_set = sample_id %in% analysis_set_ids) |
|
|