File size: 6,073 Bytes
84b2161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6d16ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
## NOTE: gene_table and genomicfeature_tbl are confirmed identical

library(tidyverse)
library(here)
library(arrow)

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

# see the README in the mcisaac data directory
df = read_tsv(here("data/mcisaac/idea_tall_expression_data/idea_tall_expression_data.tsv")) %>%
  # filter(!TF %in% c("GEV","Z3EV")) %>%
  mutate(GeneName = str_remove(GeneName,',')) %>%
  mutate(GeneName = str_remove(GeneName, '\''))

tf_table = df %>%
  select(TF) %>%
  distinct() %>%
  filter(TF != 'YLL054C') %>%
  left_join(gene_table, by = c('TF' = 'symbol')) %>%
  select(TF, locus_tag) %>%
  bind_rows(tibble(TF='YLL054C', locus_tag="YLL054C")) %>%
  dplyr::rename(regulator_locus_tag = locus_tag) %>%
  mutate(regulator_symbol = TF) %>%
  mutate(regulator_locus_tag = ifelse(TF %in% c("GEV", "Z3EV"), TF, regulator_locus_tag))

stopifnot(setequal(tf_table$TF, unique(df$TF)))

mcisaac_gene_table_incomplete = df %>%
  select(GeneName) %>%
  distinct() %>%
  left_join(gene_table, by = c('GeneName' = 'symbol')) %>%
  filter(complete.cases(.)) %>%
  mutate(symbol = GeneName) %>%
  select(GeneName, locus_tag, symbol) %>%
  bind_rows(df %>%
              select(GeneName) %>%
              distinct() %>%
              left_join(gene_table,
                        by = c('GeneName' = 'locus_tag')) %>%
              filter(complete.cases(.)) %>%
              mutate(locus_tag = GeneName) %>%
              select(GeneName, locus_tag, symbol)) %>%
  distinct() %>%
  dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol)

# df %>%
#   select(GeneName) %>%
#   distinct(GeneName) %>%
#   filter(!GeneName %in% tmp$GeneName) %>%
#   mutate(id=NA) %>%
#   select(GeneName, id) %>%
#   dplyr::rename(gene_id=id) %>%
#   write_csv("data/mcisaac/mcisaac_gene_lookup.txt")

# This is sort of an interesting aside. I'm looking back at how I parsed the mcisaac dataset as I add it to huggingface. As I do this, I am reminded of little details like the fact that in their probe set, they have a prob for AAD6 and AAD16 . In the current annotation set, it is noted that AAD16 is a -1 frameshift of AAD6 and it is removed. AAD6 itself is labeled a pseudogene.
# that made me think that what would be interesting is how correlated they are (plotted, generally correlated).
# I looked at the absolute of the differences wondering which genes showed the greatest difference -- possibly these two loci are differentially regulated, who knows.
# More interesting, I looked at regulators where the signs differed for AAD6 and AAD16. Possibly this is due to differential regulation. But it is also possible that this might give insight into what the minimum reliable threshold of the effect is.
# The maximum unshrunken effect of a pair with different signs was 0.54. For DTO we set a threshold of 0.6, so this isn't really useful in any way. But I thought I'd share anyway
mcisaac_gene_aliases = read_csv("data/mcisaac/mcisaac_gene_lookup.txt") %>%
  # this is a -1 frameshift to AAD6 (also in mcisaac) and is not in 3-1. Added
  # by hand -- this * might * be an interesting locus to look at for variance?
  bind_rows(tibble(GeneName="AAD16", locus_tag="YFL056C")) %>%
  dplyr::rename(target_locus_tag=locus_tag) %>%
  mutate(target_symbol=GeneName)


mcisaac_gene_table = mcisaac_gene_table_incomplete %>%
  bind_rows(mcisaac_gene_aliases)

stopifnot(setequal(mcisaac_gene_table$GeneName, unique(df$GeneName)))

mcisaac_for_parquet = df %>%
  mutate(date=str_remove_all(as.Date(date, format='%m/%d/%Y'),'-')) %>%
  left_join(tf_table) %>%
  left_join(mcisaac_gene_table)

mcisaac_tf_to_regulator_locus_tag = mcisaac_for_parquet %>%
  select(TF, regulator_locus_tag) %>%
  distinct()

mcisaac_GeneName_to_target_locus_tag = mcisaac_for_parquet %>%
  select(GeneName, target_locus_tag) %>%
  distinct()

# mcisaac_for_parquet %>%
#   select(regulator_locus_tag, time, mechanism, restriction, date, strain,
#          target_locus_tag, ends_with("median"), starts_with("log2")) %>%
#   group_by(regulator_locus_tag, time, mechanism, restriction, date, strain) %>%
#   write_dataset(path = here("data/mcisaac/hf/data"), format = "parquet")

db_mcisaac_data = read_csv("data/mcisaac/database_mcisaac_20251126.csv") %>%
  select(id, regulator_locus_tag, mechanism, restriction, time, notes) %>%
  mutate(
    strain = trimws(str_extract(notes, "(?<=strain_id:)[^;]+")),
    date = trimws(str_extract(notes, "(?<=date:)[^;]+")),
    mechanism = toupper(mechanism)) %>%
  select(-notes) %>%
  dplyr::rename(db_id = id) %>%
  bind_rows(
    mcisaac_for_parquet %>%
      filter(regulator_locus_tag %in% c("GEV", "Z3EV")) %>%
      select(regulator_locus_tag, time, mechanism,
             restriction, date, strain) %>%
      distinct() %>%
      mutate(db_id = 0)) %>%
  arrange(db_id) %>%
  mutate(sample_id = row_number())

final_mcisaac = mcisaac_for_parquet %>%
  left_join(db_mcisaac_data) %>%
  select(sample_id, db_id,
         regulator_locus_tag, regulator_symbol,
         target_locus_tag, target_symbol,
         time, mechanism, restriction, date, strain,
         ends_with("median"), starts_with("log2"))

# note! verify before overwriting that the sample_id for the unique sample
# tuple is the same as it is in the current hackett_2020, or that any changes
# are intentional

# final_mcisaac %>%
#   write_parquet("~/code/hf/hackett_2020/hackett_2020.parquet",
#               compression = "zstd",
#               chunk_size = 6175,
#               write_statistics = TRUE,
#               use_dictionary = c(
#                 sample_id = TRUE,
#                 regulator_locus_tag = TRUE,
#                 regulator_symbol = TRUE,
#                 target_locus_tag = TRUE,
#                 target_symbol = TRUE,
#                 time = TRUE,
#                 mechanism = TRUE,
#                 restriction = TRUE,
#                 date = TRUE,
#                 strain = TRUE))