File size: 1,692 Bytes
3c8f60f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)