File size: 7,411 Bytes
b8df475
 
 
 
 
1fcd609
 
 
 
 
 
b8df475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1fcd609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
library(tidyverse)
library(here)
library(arrow)
library(readxl)

# from fetchngs, the multiqc metadata has an easy way to map between
# accessions and samples
multqc_chec_config = yaml::read_yaml("~/Downloads/multiqc_config.yml")
chec_meta <- map_dfr(multqc_chec_config$sample_names_rename,
             ~tibble(!!!setNames(., multqc_chec_config$sample_names_rename_buttons)))

# genomic feature harmonization table ----
# see https://huggingface.co/datasets/BrentLab/yeast_genome_resources
genomicfeatures = arrow::open_dataset(here("data/genome_files/hf/features")) %>%
  as_tibble()

chec_data = read_excel(here("data/mahendrawada_2024_rnaseq/41586_2025_8916_MOESM5_ESM.xlsx"),
                         sheet="Table-S3b") %>%
  dplyr::rename(mahedrawada_target = `...1`) %>%
  pivot_longer(-mahedrawada_target,
               names_to = "mahedrawada_regulator_orig",
               values_to = "peak_score") %>%
  arrange(mahedrawada_regulator_orig, mahedrawada_target) %>%
  filter(!is.na(peak_score)) %>%
  mutate(mahedrawada_regulator = case_when(
    mahedrawada_regulator_orig == "MED15" ~ "GAL11",
    mahedrawada_regulator_orig == "YNR063W" ~ "PUL4",
    .default = mahedrawada_regulator_orig
  ))

rnaseq_data = read_excel(here("data/mahendrawada_2024_rnaseq/41586_2025_8916_MOESM5_ESM.xlsx"),
                         sheet="Table-S3c") %>%
  dplyr::rename(mahedrawada_target = `...1`) %>%
  pivot_longer(-c(mahedrawada_target, Kmeans_clusters),
               names_to = "mahedrawada_regulator_tmp",
               values_to = "log2fc") %>%
  arrange(mahedrawada_regulator_tmp, mahedrawada_target) %>%
  filter(!is.na(log2fc)) %>%
  separate(mahedrawada_regulator_tmp, into = c("mahedrawada_regulator_orig", "cond")) %>%
  replace_na(list(cond="SC")) %>%
  mutate(
    mahedrawada_regulator = case_when(
      mahedrawada_regulator_orig == "MED15" ~ "GAL11",
      mahedrawada_regulator_orig == "GALG4" ~ "GAL4",
      mahedrawada_regulator_orig == "YNR063W" ~ "PUL4",
      .default = mahedrawada_regulator_orig),
    cond = case_when(
      mahedrawada_regulator_orig == "GALG4" ~ "GAL",
      .default = cond
    ))

mahedrawada_genomicfeatures <- read_excel(
  here("data/mahendrawada_2024_rnaseq/41586_2025_8916_MOESM4_ESM.xlsx"),
  sheet = "ref_all"
) %>%
  mutate(gene_name = case_when(
    gene_name == "YPR022C" ~ "SDD4",
    gene_name == "YNR063W" ~ "PUL4",
    .default = gene_name
  ))

stopifnot(setequal(intersect(chec_data$mahedrawada_target, mahedrawada_genomicfeatures$gene_id),
                   chec_data$mahedrawada_target))

stopifnot(setequal(intersect(rnaseq_data$mahedrawada_target, mahedrawada_genomicfeatures$gene_id),
                   rnaseq_data$mahedrawada_target))

stopifnot(setequal(intersect(chec_data$mahedrawada_regulator, mahedrawada_genomicfeatures$gene_name),
                   chec_data$mahedrawada_regulator))

stopifnot(setequal(intersect(rnaseq_data$mahedrawada_regulator, mahedrawada_genomicfeatures$gene_name),
                   rnaseq_data$mahedrawada_regulator))

# note: verified by hand that where the symbol != gene_name, that the gene_name
# was listed as an alias of the current official symbol.
# Where the gene_name is == to the gene_id, that id is == to the locus_tag
stopifnot(
  tibble(mahedrawada_target = union(chec_data$mahedrawada_target,
                                    rnaseq_data$mahedrawada_target)) %>%
            left_join(genomicfeatures %>% select(locus_tag, symbol),
                      by = c("mahedrawada_target" = "locus_tag")) %>%
            left_join(mahedrawada_genomicfeatures %>% select(gene_name, gene_id),
                      by = c("mahedrawada_target" = "gene_id")) %>%
            filter(!complete.cases(.)) %>%
            nrow() == 0)

stopifnot(
  tibble(mahedrawada_regulator = union(chec_data$mahedrawada_regulator,
                                       rnaseq_data$mahedrawada_regulator)) %>%
  left_join(genomicfeatures %>%
              select(locus_tag, symbol),
            by = c("mahedrawada_regulator" = "symbol")) %>%
  left_join(mahedrawada_genomicfeatures %>%
              select(gene_name, gene_id),
            by = c("mahedrawada_regulator" = "gene_name")) %>%
    filter(!complete.cases(.) | locus_tag != gene_id) %>%
    nrow() == 0)

chec_data_final = chec_data %>%
  left_join(
    genomicfeatures %>%
      select(locus_tag, symbol) %>%
      mutate(mahedrawada_target = locus_tag) %>%
      dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol)) %>%
  left_join(
    genomicfeatures %>%
      select(locus_tag, symbol) %>%
      mutate(mahedrawada_regulator = symbol) %>%
      dplyr::rename(regulator_locus_tag = locus_tag, regulator_symbol = symbol)) %>%
  select(regulator_locus_tag, regulator_symbol, target_locus_tag, target_symbol, peak_score) %>%
  arrange(regulator_locus_tag, target_locus_tag)

rnaseq_data_final = rnaseq_data %>%
  left_join(
    genomicfeatures %>%
      select(locus_tag, symbol) %>%
      mutate(mahedrawada_target = locus_tag) %>%
      dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol)) %>%
  left_join(
    genomicfeatures %>%
      select(locus_tag, symbol) %>%
      mutate(mahedrawada_regulator = symbol) %>%
      dplyr::rename(regulator_locus_tag = locus_tag, regulator_symbol = symbol)) %>%
  select(regulator_locus_tag, regulator_symbol, target_locus_tag, target_symbol, log2fc) %>%
  arrange(regulator_locus_tag, target_locus_tag)

sample_id_map = tibble(
  regulator_locus_tag = union(rnaseq_data_final$regulator_locus_tag,
                                     chec_data_final$regulator_locus_tag)) %>%
  mutate(sample_id = row_number())


# chec_data_final %>%
#   left_join(sample_id_map) %>%
#   select(sample_id, all_of(colnames(chec_data_final))) %>%
#   write_parquet(here("~/code/hf/mahendrawada_2025/chec_mahendrawada_2025.parquet"),
#                 compression = "zstd",
#                 write_statistics = TRUE,
#                 use_dictionary = c(
#                   sample_id = TRUE,
#                   regulator_locus_tag = TRUE,
#                   regulator_symbol = TRUE,
#                   target_locus_tag = TRUE,
#                   target_symbol = TRUE
#                 )
#   )
#
# rnaseq_data_final %>%
#   left_join(sample_id_map) %>%
#   select(sample_id, all_of(colnames(rnaseq_data_final))) %>%
#   write_parquet(here("~/code/hf/mahendrawada_2025/rnaseq_mahendrawada_2025.parquet"),
#                 compression = "zstd",
#                 write_statistics = TRUE,
#                 use_dictionary = c(
#                   sample_id = TRUE,
#                   regulator_locus_tag = TRUE,
#                   regulator_symbol = TRUE,
#                   target_locus_tag = TRUE,
#                   target_symbol = TRUE
#                 )
#   )
#
# mahedrawada_genomicfeatures %>%
#   left_join(genomicfeatures %>%
#               select(locus_tag, symbol) %>%
#               mutate(gene_id = locus_tag)) %>%
#   write_parquet(here("~/code/hf/mahendrawada_2025/features_mahendrawada_2025.parquet"),
#                 compression = "zstd",
#                 write_statistics = TRUE,
#                 use_dictionary = c(
#                   gene_id = TRUE,
#                   gene_name = TRUE,
#                   chr = TRUE,
#                   locus_tag = TRUE,
#                   symbol = TRUE,
#                   coactivator = TRUE
#                 )
#   )