cmatkhan commited on
Commit
fe05257
·
1 Parent(s): 9869370

adding analysis set column to orig CC data

Browse files
README.md CHANGED
@@ -118,6 +118,12 @@ configs:
118
  dtype: int64
119
  description: Count or score for composite binding events
120
  role: quantitative_measure
 
 
 
 
 
 
121
  - name: id
122
  dtype: string
123
  description: Unique identifier for the metadata record
@@ -209,6 +215,12 @@ configs:
209
  - name: batch
210
  dtype: string
211
  description: Experimental batch identifier for controlling batch effects
 
 
 
 
 
 
212
  - name: condition
213
  dtype: string
214
  description: Experimental condition for this sample
 
118
  dtype: int64
119
  description: Count or score for composite binding events
120
  role: quantitative_measure
121
+ - name: analysis_set
122
+ dtype: bool
123
+ description: >-
124
+ TRUE if this record is to be used for analysis. FALSE otherwise.
125
+ This was determined in 2025. Replicates needed `>=`3k hops and
126
+ DTO `<=` 0.01 in either kemmeren or hackett
127
  - name: id
128
  dtype: string
129
  description: Unique identifier for the metadata record
 
215
  - name: batch
216
  dtype: string
217
  description: Experimental batch identifier for controlling batch effects
218
+ - name: analysis_set
219
+ dtype: bool
220
+ description: >-
221
+ For a TF with more than 1 passing replicate, a combined samples is created.
222
+ This is based on the QC done in 2025 for the modeling paper. See the
223
+ annotated_features_meta for more details
224
  - name: condition
225
  dtype: string
226
  description: Experimental condition for this sample
annotated_features_combined_meta.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1f58b2c09c3061d035b5d6d09f8efa10dd758465204650513ce2c4d29606faa1
3
- size 6401
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a524b6e621e0b027bdca9c942ca639368f14618bb093ea4e27fb9dbeb9b29ad
3
+ size 6642
annotated_features_meta.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b0805253b44b0bea473a19bfbd6c38fe3ded123154f728a1c092f40ee97e878c
3
- size 24549
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2f0c27cea8819144b7ec616a6e5165dee46b94d3f6ba0de2fbe0751bf753fe7
3
+ size 24871
scripts/cc_sra_submission_with_addtl.R ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(tidyverse)
2
+ library(here)
3
+
4
+ # TODO: REMOVE HYPERGEOMETRIC PVALUE FROM PROCESSED DATA
5
+ # TODO: when making processing scripts github, add the background file
6
+ # and make sure the repo gets registered to zenodo. Put that link to the
7
+ # background files in the SRA submission
8
+
9
+ # for "data_usable" in sra submission, change to "perturbation_validated".
10
+ # factor levels should be "true", "false", "unreviewed" (DTO only)
11
+ # num_insertions for number of insertions
12
+ #
13
+ # cells grown on solid media at room temperature
14
+ # put the definition of the "Description" values in the
15
+
16
+ qc_django_data = read_csv("~/projects/parsing_yeast_database_data/data/qc_from_db/rr_20251222.csv")
17
+ expr_django_data = read_csv("~/projects/parsing_yeast_database_data/data/qc_from_db/expr_20251222.csv")
18
+ mcisaac_preferred_reps = expr_django_data %>%
19
+ filter(source_name == "mcisaac_oe") %>%
20
+ filter(preferred_replicate==TRUE) %>%
21
+ pull(id)
22
+
23
+ qc_django_data_in_modeling = list(
24
+ kemmeren = qc_django_data %>%
25
+ filter(binding_source == "brent_nf_cc",
26
+ !is.na(single_binding)) %>%
27
+ filter(expression_source == "kemmeren_tfko"),
28
+ mcisaac = qc_django_data %>%
29
+ filter(binding_source == "brent_nf_cc",
30
+ !is.na(single_binding)) %>%
31
+ filter(expression_source == "mcisaac_oe"
32
+ & expression %in% mcisaac_preferred_reps))
33
+
34
+ analysis_set_meta = read_csv("~/htcf_ref/data/yeast_database_modelling/pull_data_20250805/data/brent_nf_cc_meta_20250805.csv")
35
+ composite_binding = read_csv("~/htcf_ref/data/yeast_database_modelling/pull_data_20250805/data/bindingconcat_meta_20250805.csv") %>%
36
+ filter(source_name == "brent_nf_cc")
37
+
38
+ barcode_details_list = list.files("~/htcf_local/cc/yeast/data", "*_barcode_details.json",
39
+ recursive=TRUE)
40
+
41
+ passing_fastq_from_bam_paths = list.files("~/htcf_local/cc/yeast/passing_fastq_from_bam")
42
+
43
+ fastq_df = tibble(filename = passing_fastq_from_bam_paths) %>%
44
+ extract(
45
+ filename,
46
+ into = c("batch", "regulator_symbol_replicate"),
47
+ regex = "^(.+?)_([^_]+)_passing_tagged\\.fastq\\.gz$",
48
+ remove = FALSE) %>%
49
+ mutate(replicate = str_remove(str_extract(regulator_symbol_replicate, "x\\d"), "x")) %>%
50
+ mutate(regulator_symbol = str_remove(regulator_symbol_replicate, "x\\d")) %>%
51
+ replace_na(list(replicate = '1')) %>%
52
+ mutate(replicate = as.integer(replicate)) %>%
53
+ mutate(batch = ifelse(batch == "run_5690_correct", "run_5690", batch)) %>%
54
+ filter(!batch %in% c('dsir4')) %>%
55
+ filter(regulator_symbol != "undetermined") %>%
56
+ # this is empty -- no passing hops
57
+ filter(filename != "run_6739_MOT3_passing_tagged.fastq.gz")
58
+
59
+ barcode_details_df = map(barcode_details_list, ~{
60
+ message(sprintf("working on %s", basename(.x)))
61
+ x = jsonlite::read_json(file.path("~/htcf_local/cc/yeast/data", .))
62
+ tibble(
63
+ seq = names(x$components$tf$map),
64
+ regulator_symbol = unlist(x$components$tf$map)) %>%
65
+ mutate(r1_index = substr(seq,1,5),
66
+ r2_index = substr(seq,6,nchar(seq))) %>%
67
+ mutate(batch = basename(dirname(.x)))}) %>%
68
+ bind_rows()
69
+
70
+ composite_binding_unlisted = unlist(lapply(composite_binding$bindings, function(x) {
71
+ as.numeric(str_extract_all(x, "\\d+")[[1]])}))
72
+
73
+ analysis_binding_ids = c(
74
+ pull(filter(analysis_set_meta, !is.na(single_binding)), single_binding),
75
+ composite_binding_unlisted
76
+ )
77
+
78
+
79
+ binding_django = read_csv(here("data/binding_from_django_db_20260128.csv"))
80
+
81
+ barcode_details_df_with_id = barcode_details_df %>%
82
+ mutate(replicate = str_remove(str_extract(regulator_symbol, "x\\d"), "x")) %>%
83
+ mutate(regulator_symbol = str_remove(regulator_symbol, "x\\d")) %>%
84
+ replace_na(list(replicate = '1')) %>%
85
+ mutate(replicate = as.integer(replicate)) %>%
86
+ filter(batch != "run_5690") %>%
87
+ mutate(batch = ifelse(batch == 'run_5690_correct', 'run_5690', batch)) %>%
88
+ left_join(
89
+ binding_django %>%
90
+ select(id, regulator_symbol, batch, replicate)) %>%
91
+ dplyr::rename(binding_id = id) %>%
92
+ mutate(binding_id = as.character(binding_id)) %>%
93
+ replace_na(list(binding_id = "NA"))
94
+
95
+ brentlab_dirs = list.dirs("~/htcf_lts/sequence_data/yeast_cc/sequence", recursive=FALSE)
96
+ mitra_dirs = list.dirs("~/htcf_lts/sequence_data/yeast_cc/sequence/mitra_data", recursive=FALSE)
97
+
98
+ setdiff(basename(c(brentlab_dirs, mitra_dirs)), unique(binding_django$batch))
99
+
100
+ gm_db = arrow::open_dataset("~/code/hf/callingcards/genome_map")
101
+
102
+ genome_map_meta = arrow::read_parquet("~/code/hf/callingcards/genome_map_meta.parquet") %>%
103
+ # filter(condition == "standard") %>%
104
+ filter(!batch %in% c('dsir4'))
105
+
106
+ fastq_df_with_id = fastq_df %>%
107
+ left_join(genome_map_meta %>%
108
+ mutate(regulator_symbol = ifelse(str_detect(regulator_symbol, "unknown"),
109
+ regulator_locus_tag,
110
+ regulator_symbol))) %>%
111
+ filter(condition == 'standard')
112
+
113
+ fastq_df_with_id %>%
114
+ filter(binding_id == "NA") %>%
115
+ filter(condition == "standard") %>%
116
+ filter(regulator_symbol != "OTU1") %>%
117
+ mutate(qbed_path = file.path(sprintf("/home/chase/htcf_local/cc/yeast/results/%s/hops/%s_%s.qbed", batch, batch, regulator_symbol_replicate))) %>%
118
+ select(qbed_path) %>%
119
+ write_tsv("~/tmp/unprocessed_in_db_qbeds_lookup.txt")
120
+
121
+
122
+ # ACE2, ARG80, ARG81, LYS14, STB5, SWI5, SWI6 pass in at least one (didn't check which mcisaac cond pass, but all pass in kemmeren pass)
123
+ # CUP9 and DAL80 pass in mcisaac at 15 minutes
124
+ #
125
+ # WTM1, MIG2, DIG1 ACA1 fails due to non-passing in kemmeren and/or mcisaac. NOTE: the only timepoint MIG2 fails is 15 minutes.
126
+ # UME6 has no 15 minute condition in mcisaac and is not in kemmeren
127
+
128
+ af_django_meta = arrow::read_parquet("~/code/hf/callingcards/annotated_features_meta.parquet") %>%
129
+ filter(condition == "standard") %>%
130
+ filter(genome_map_id %in% genome_map_meta$id) %>%
131
+ replace_na(list(binding_id = "NA")) %>%
132
+ mutate(data_usable = case_when(
133
+ batch %in% c('run_7477', 'run_7487')
134
+ & regulator_symbol %in% c('ACE2', 'ARG80', 'ARG81', 'LYS14',
135
+ 'STB5', 'SWI5', 'SWI6', 'CUP9', 'DAL80') ~ "pass",
136
+ batch %in% c('run_7477', 'run_7487')
137
+ & regulator_symbol %in% c('WTM1', 'MIG2', 'DIG1', 'ACA1') ~ "fail",
138
+ .default = data_usable)) %>%
139
+ mutate(in_modeling_analysis = binding_id %in% analysis_binding_ids) %>%
140
+ mutate(kemmeren_dto = binding_id %in%
141
+ (qc_django_data_in_modeling$kemmeren %>%
142
+ filter(dto_empirical_pvalue <= 0.01) %>%
143
+ pull(single_binding))) %>%
144
+ mutate(mcisaac_dto = binding_id %in%
145
+ (qc_django_data_in_modeling$mcisaac %>%
146
+ filter(dto_empirical_pvalue <= 0.01) %>%
147
+ pull(single_binding))) %>%
148
+ left_join(qc_django_data %>%
149
+ filter(!is.na(single_binding), binding_source == "brent_nf_cc") %>%
150
+ select(single_binding, genomic_inserts) %>%
151
+ distinct() %>%
152
+ mutate(single_binding = as.character(single_binding)) %>%
153
+ dplyr::rename(binding_id = single_binding)) %>%
154
+ left_join(select(barcode_details_df_with_id, regulator_symbol, batch, binding_id, r1_index, r2_index)) %>%
155
+ dplyr::select(id, genome_map_id, batch,
156
+ r1_index, r2_index,
157
+ regulator_locus_tag, regulator_symbol,
158
+ data_usable, kemmeren_dto, mcisaac_dto, genomic_inserts,
159
+ in_modeling_analysis) %>%
160
+ mutate(notes = case_when(
161
+ genome_map_id %in% c(690, 685) ~ "manually exluded from analysis in favor of library 242",
162
+ genome_map_id %in% c(26, 612, 300, 119) ~ "less than 3k insertions",
163
+ .default = "none")) %>%
164
+ arrange(genome_map_id)
165
+
166
+ af_db = arrow::open_dataset("~/code/hf/callingcards/annotated_features")
167
+
168
+ setdiff(basename(c(brentlab_dirs, mitra_dirs)), unique(genome_map_meta$batch))
169
+ setdiff(unique(genome_map_meta$batch),basename(c(brentlab_dirs, mitra_dirs)))
170
+
171
+
172
+ # db2506 = read_tsv("~/Downloads/2506.qbed.gz")
173
+ # hf2506 = gm_db %>%
174
+ # filter(id == 1) %>%
175
+ # collect()
176
+
177
+ library(arrow)
178
+ library(dplyr)
179
+ library(readr)
180
+
181
+ # Specify output directory
182
+ # output_dir <- here("~/htcf_local/cc/yeast/callingcards_geo_submission/processed")
183
+ # dir.create(output_dir, showWarnings = FALSE, recursive = TRUE)
184
+
185
+ # Get unique combinations of id and batch
186
+ id_batch_combos <- af_django_meta %>%
187
+ select(id, genome_map_id, batch) %>%
188
+ distinct()
189
+
190
+ # for (i in 1:nrow(id_batch_combos)) {
191
+ # current_id <- id_batch_combos$id[i]
192
+ # current_batch <- id_batch_combos$batch[i]
193
+ # gm_id = id_batch_combos$genome_map_id[i]
194
+ #
195
+ # # Filter and format as af file
196
+ # af_data <- af_db %>%
197
+ # filter(id == current_id,
198
+ # batch == current_batch) %>%
199
+ # collect() %>%
200
+ # mutate(genome_map_id = gm_id) %>%
201
+ # select(-id) %>%
202
+ # dplyr::rename(library_name = genome_map_id) %>%
203
+ # mutate(target_symbol = ifelse(str_detect(target_symbol, "unknown"),
204
+ # target_locus_tag, target_symbol)) %>%
205
+ # dplyr::relocate(library_name, batch)
206
+ #
207
+ # # Create filename
208
+ # filename <- file.path(output_dir, paste0(gm_id, ".csv.gz"))
209
+ #
210
+ # # Write gzipped csv file
211
+ # write_csv(af_data, filename)
212
+ #
213
+ # if (i %% 10 == 0) cat("Wrote", i, "of", nrow(id_batch_combos), "files\n")
214
+ # }
215
+ #
216
+ # cat("Done! Wrote", nrow(id_batch_combos), "CSV files to", output_dir, "\n")
217
+
218
+ submission_df = af_django_meta %>%
219
+ select(-id) %>%
220
+ arrange(regulator_locus_tag) %>%
221
+ mutate(regulator_symbol = ifelse(
222
+ str_detect(regulator_symbol, "unknown"),
223
+ regulator_locus_tag,
224
+ regulator_symbol)) %>%
225
+ mutate(`library name` = paste0(regulator_locus_tag, "_", regulator_symbol, "_", genome_map_id)) %>%
226
+ mutate(title = paste0(regulator_locus_tag, " (", regulator_symbol, ") calling cards"),
227
+ `library strategy` = "CallingCards",
228
+ organism = 'Saccharomyces cerevisiae',
229
+ strain = '',
230
+ molecule = 'genomic DNA',
231
+ `single or paired-end` = 'single-end',
232
+ `instrument model` = 'illumina MiSeq i100',
233
+ description = paste0(regulator_locus_tag, " tagged callingcards experiment. ",
234
+ "kemmeren_dto: ", kemmeren_dto, "; mcisaac_dto: ", mcisaac_dto,
235
+ "; genomic_inserts: ", genomic_inserts,
236
+ "; in_modeling_analysis: ", in_modeling_analysis,
237
+ "; notes: ", notes),
238
+ `processed data file` = paste0(`library name`, ".csv.gz"),
239
+ `raw file` = paste0(`library name`, ".fastq.gz")) %>%
240
+ dplyr::select(
241
+ `library name`, title, `library strategy`, organism,
242
+ strain, molecule, `single or paired-end`, `instrument model`,
243
+ description,
244
+ `processed data file`, `raw file`
245
+ )
246
+
247
+ # write_csv(submission_df, here("data/cc_submission_df.csv"))