cmatkhan commited on
Commit
c329a72
·
1 Parent(s): 5c9546d

major reorganization and reprocessing. scripts added

Browse files
Files changed (35) hide show
  1. README.md +226 -154
  2. yeastepigenome_annotatedfeatures.parquet → deprecated_rossi_2021_metadata.parquet +2 -2
  3. {genome_map → genome_map_control}/accession=SRR11466204/part-0.parquet +0 -0
  4. {genome_map → genome_map_control}/accession=SRR11466205/part-0.parquet +0 -0
  5. {genome_map → genome_map_control}/accession=SRR11466206/part-0.parquet +0 -0
  6. {genome_map → genome_map_control}/accession=SRR11466207/part-0.parquet +0 -0
  7. {genome_map → genome_map_control}/accession=SRR11466208/part-0.parquet +0 -0
  8. {genome_map → genome_map_control}/accession=SRR11466209/part-0.parquet +0 -0
  9. {genome_map → genome_map_control}/accession=SRR13866599/part-0.parquet +0 -0
  10. {genome_map → genome_map_control}/accession=SRR13866600/part-0.parquet +0 -0
  11. {genome_map → genome_map_control}/accession=SRR13866601/part-0.parquet +0 -0
  12. {genome_map → genome_map_control}/accession=SRR13866602/part-0.parquet +0 -0
  13. {genome_map → genome_map_control}/accession=SRR13866603/part-0.parquet +0 -0
  14. {genome_map → genome_map_control}/accession=SRR13866604/part-0.parquet +0 -0
  15. {genome_map → genome_map_control}/accession=SRR13866605/part-0.parquet +0 -0
  16. {genome_map → genome_map_control}/accession=SRR13866606/part-0.parquet +0 -0
  17. {genome_map → genome_map_control}/accession=SRR13866607/part-0.parquet +0 -0
  18. {genome_map → genome_map_control}/accession=SRR13866608/part-0.parquet +0 -0
  19. {genome_map → genome_map_control}/accession=SRR13866609/part-0.parquet +0 -0
  20. {genome_map → genome_map_control}/accession=SRR13866610/part-0.parquet +0 -0
  21. {genome_map → genome_map_control}/accession=SRR13866611/part-0.parquet +0 -0
  22. {genome_map → genome_map_control}/accession=SRR13866612/part-0.parquet +0 -0
  23. {genome_map → genome_map_control}/accession=SRR13866613/part-0.parquet +0 -0
  24. reprocess_annotatedfeatures.parquet → genome_map_control_meta.parquet +2 -2
  25. reprocess_annotatedfeatures.parquet.md5 +0 -1
  26. reprocess_annotatedfeatures_tagcounts.parquet.md5 +0 -1
  27. reprocess_annotatedfeatures_tagcounts.parquet → rossi_2021_af_combined.parquet +2 -2
  28. rossi_2021_af_replicates.parquet +3 -0
  29. rossi_2021_metadata.parquet +2 -2
  30. rossi_2021_metadata.parquet.md5 +0 -1
  31. rossi_2021_metadata_sample.parquet +3 -0
  32. scripts/genomecov_to_annotated_features.R +626 -0
  33. scripts/parse_pugh_genomecov_5p.R +16 -13
  34. scripts/parse_yeastepigenome_sample_data.R +127 -0
  35. yeastepigenome_annotatedfeatures.parquet.md5 +0 -1
README.md CHANGED
@@ -74,159 +74,243 @@ configs:
74
  - name: pileup
75
  dtype: int32
76
  description: "Depth of coverage (number of 5' tags) at this genomic position"
77
- - config_name: rossi_annotated_features
78
- description: ChIP-exo regulator-target binding features with peak statistics
79
- dataset_type: annotated_features
80
- default: true
81
- metadata_fields:
82
- - regulator_locus_tag
83
- - regulator_symbol
84
- - target_locus_tag
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  data_files:
86
- - split: train
87
- path: yeastepigenome_annotatedfeatures.parquet
88
  dataset_info:
89
  features:
90
- - name: sample_id
91
- dtype: int32
92
- description: >-
93
- Unique identifier for each ChIP-exo experimental sample.
94
- - name: pss_id
95
- dtype: float64
96
- description: >-
97
- Current brentlab promotersetsig table id. This will eventually be removed.
98
- - name: binding_id
99
- dtype: float64
100
- description: >-
101
- Current brentlab binding table id. This will eventually be removed.
102
- - name: yeastepigenome_id
103
- dtype: float64
104
- description: >-
105
- Unique identifier in the yeastepigenome database.
106
- - name: regulator_locus_tag
107
- dtype: string
108
- description: >-
109
- Systematic ORF name of the regulator.
110
- role: regulator_identifier
111
- - name: regulator_symbol
112
- dtype: string
113
- description: >-
114
- Common gene name of the regulator.
115
- role: regulator_identifier
116
- - name: target_locus_tag
117
- dtype: string
118
- description: >-
119
- The systematic ID of the feature to which the effect/pvalue is
120
- assigned. See hf/BrentLab/yeast_genome_resources
121
- role: target_identifier
122
- - name: target_symbol
123
- dtype: string
124
- description: >-
125
- The common name of the feature to which the effect/pvalue is
126
- assigned. If there is no common name, the `target_locus_tag` is
127
- used.
128
- role: target_identifier
129
- - name: n_sig_peaks
130
- dtype: float64
131
- description: >-
132
- Number of peaks in the promoter region of the the target gene
133
- role: quantitative_measure
134
- - name: max_fc
135
- dtype: float64
136
- description: >-
137
- If there are multiple peaks in the promoter region, then the maximum is
138
- reported. Otherwise, it is the fold change of the single peak in the
139
- promoter.
140
- role: quantitative_measure
141
- - name: min_pval
142
- dtype: float64
143
- description: >-
144
- The most significant p-value among peaks for this interaction.
145
- role: quantitative_measure
146
- - config_name: reprocess_annotatedfeatures
147
- description: >-
148
- Annotated features reprocessed with updated peak
149
- calling methodology
150
  dataset_type: annotated_features
151
  data_files:
152
- - split: train
153
- path: reprocess_annotatedfeatures.parquet
154
  dataset_info:
155
  features:
156
- - name: regulator_locus_tag
157
- dtype: string
158
- description: Systematic gene name (ORF identifier) of the transcription factor
159
- - name: regulator_symbol
160
- dtype: string
161
- description: Standard gene symbol of the transcription factor
162
- - name: target_locus_tag
163
- dtype: string
164
- description: Systematic gene name (ORF identifier) of the target gene
165
- - name: target_symbol
166
- dtype: string
167
- description: Standard gene symbol of the target gene
168
- - name: baseMean
169
- dtype: float64
170
- description: Average of normalized count values, dividing by size factors, taken over all samples
171
- - name: log2FoldChange
172
- dtype: float64
173
- description: Log2 fold change between comparison and control groups
174
- - name: lfcSE
175
- dtype: float64
176
- description: Standard error estimate for the log2 fold change estimate
177
- - name: stat
178
- dtype: float64
179
- description: Value of the test statistic for the gene
180
- - name: pvalue
181
- dtype: float64
182
- description: P-value of the test for the gene
183
- - name: padj
184
- dtype: float64
185
- description: Adjusted p-value for multiple testing for the gene
186
- - config_name: reprocess_annotatedfeatures_tagcounts
187
- description: Another version of the reprocessed data, quantified similarly to Calling Cards
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  dataset_type: annotated_features
189
  data_files:
190
- - split: train
191
- path: reprocess_annotatedfeatures_tagcounts.parquet
192
  dataset_info:
193
  features:
194
- - name: regulator_locus_tag
195
- dtype: string
196
- description: Systematic gene name (ORF identifier) of the transcription factor
197
- role: regulator_identifier
198
- - name: target_locus_tag
199
- dtype: string
200
- description: Systematic gene name (ORF identifier) of the target gene
201
- role: target_identifier
202
- - name: rank
203
- dtype: int64
204
- description: Rank (ties method min rank) of the peak based on pvalue with ties broken by enrichment. Largest rank is most significant.
205
- - name: control_count
206
- dtype: int64
207
- description: Number of tags in the control condition
208
- - name: experimental_count
209
- dtype: int64
210
- description: Number of tags in the experimental condition
211
- - name: mu
212
- dtype: float64
213
- description: Expected count under the null hypothesis (control_count + 1) * (experimental_total_tags / control_total_tags)
214
- - name: enrichment
215
- dtype: float64
216
- description: Enrichment ratio of experimental over control. (experimental_counts / experimental_total) / (control_counts + pseudocount) / control_total
217
- role: quantitative_measure
218
- - name: log2_enrichment
219
- dtype: float64
220
- description: Log2-transformed enrichment ratio
221
- role: quantitative_measure
222
- - name: neg_log10_pvalue
223
- dtype: float64
224
- description: Negative log10 of the p-value for binding significance
225
- role: quantitative_measure
226
- - name: neg_log10_qvalue
227
- dtype: float64
228
- description: Negative log10 of the FDR-adjusted q-value
229
- role: quantitative_measure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  ---
231
  # Rossi 2021
232
 
@@ -235,18 +319,6 @@ This work was published in
235
 
236
  [Rossi MJ, Kuntala PK, Lai WKM, Yamada N, Badjatia N, Mittal C, Kuzu G, Bocklund K, Farrell NP, Blanda TR, Mairose JD, Basting AV, Mistretta KS, Rocco DJ, Perkinson ES, Kellogg GD, Mahony S, Pugh BF. A high-resolution protein architecture of the budding yeast genome. Nature. 2021 Apr;592(7853):309-314. doi: 10.1038/s41586-021-03314-8. Epub 2021 Mar 10. PMID: 33692541; PMCID: PMC8035251.](https://doi.org/10.1038/s41586-021-03314-8)
237
 
238
- This repo provides 4 datasets:
239
-
240
- - **rossi_2021_metadata**: Metadata describing the tagged regulator in each
241
- experiment.
242
- - **genome_map**: ChIP-exo 5' tag coverage data partitioned by sample accession.
243
- - **reprocess_annotatedfeatures**: This data was reprocessed from the fastq files
244
- on GEO. See scripts/reprocessing_details.txt for more information.
245
- - **yeastepigenome_annotatedfeatures**: ChIP-exo regulator-target binding features
246
- with peak statistics.
247
- - **reprocess_annotatedfeatures_tagcounts**: Reprocessed using a similar method to
248
- the calling cards quantification
249
-
250
  ## Usage
251
 
252
  The python package `tfbpapi` provides an interface to this data which eases
 
74
  - name: pileup
75
  dtype: int32
76
  description: "Depth of coverage (number of 5' tags) at this genomic position"
77
+
78
+ - config_name: rossi_2021_metadata
79
+ description: Replicate-level metadata for ChIP-exo experiments including experimental conditions and sample information
80
+ dataset_type: metadata
81
+ applies_to: ["rossi_2021_af_replicates"]
82
+ data_files:
83
+ - split: train
84
+ path: rossi_2021_metadata.parquet
85
+ dataset_info:
86
+ features:
87
+ - name: regulator_locus_tag
88
+ dtype: string
89
+ description: Systematic gene identifier for the transcription factor
90
+ role: regulator_identifier
91
+ - name: regulator_symbol
92
+ dtype: string
93
+ description: Standard gene symbol for the transcription factor
94
+ role: regulator_identifier
95
+ - name: run_accession
96
+ dtype: string
97
+ description: SRA run accession identifier for this biological replicate
98
+ - name: yeastepigenome_id
99
+ dtype: string
100
+ description: Identifier from the Yeast Epigenome Project
101
+ - name: treatment
102
+ dtype: string
103
+ description: Experimental treatment condition
104
+ role: experimental_condition
105
+ - name: growth_media
106
+ dtype: string
107
+ description: Growth media composition
108
+ role: experimental_condition
109
+ - name: antibody
110
+ dtype: string
111
+ description: Antibody used for ChIP-exo immunoprecipitation
112
+ - name: sample_id
113
+ dtype: string
114
+ description: Unique identifier for the biological replicate
115
+
116
+ - config_name: rossi_2021_metadata_sample
117
+ description: Sample-level metadata for combined ChIP-exo experiments including experimental conditions
118
+ dataset_type: metadata
119
+ applies_to: ["rossi_2021_af_combined"]
120
  data_files:
121
+ - split: train
122
+ path: rossi_2021_metadata_sample.parquet
123
  dataset_info:
124
  features:
125
+ - name: regulator_locus_tag
126
+ dtype: string
127
+ description: Systematic gene identifier for the transcription factor
128
+ role: regulator_identifier
129
+ - name: regulator_symbol
130
+ dtype: string
131
+ description: Standard gene symbol for the transcription factor
132
+ role: regulator_identifier
133
+ - name: treatment
134
+ dtype: string
135
+ description: Experimental treatment condition
136
+ role: experimental_condition
137
+ - name: growth_media
138
+ dtype: string
139
+ description: Growth media composition
140
+ role: experimental_condition
141
+ - name: antibody
142
+ dtype: string
143
+ description: Antibody used for ChIP-exo immunoprecipitation
144
+ - name: sample_id
145
+ dtype: string
146
+ description: Unique identifier combining regulator and replicates
147
+
148
+ - config_name: rossi_2021_af_replicates
149
+ description: ChIP-exo annotated features at biological replicate level with binding peaks and statistical significance metrics
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  dataset_type: annotated_features
151
  data_files:
152
+ - split: train
153
+ path: rossi_2021_af_replicates.parquet
154
  dataset_info:
155
  features:
156
+ - name: sample_id
157
+ dtype: string
158
+ description: Unique identifier for the biological replicate
159
+ role: sample_id
160
+ - name: run_accession
161
+ dtype: string
162
+ description: SRA run accession identifier for this biological replicate
163
+ - name: regulator_locus_tag
164
+ dtype: string
165
+ description: Systematic gene identifier for the transcription factor
166
+ role: regulator_identifier
167
+ - name: regulator_symbol
168
+ dtype: string
169
+ description: Standard gene symbol for the transcription factor
170
+ role: regulator_identifier
171
+ - name: target_locus_tag
172
+ dtype: string
173
+ description: Systematic gene identifier for the target gene
174
+ role: target_identifier
175
+ - name: target_symbol
176
+ dtype: string
177
+ description: Standard gene symbol for the target gene
178
+ role: target_identifier
179
+ - name: seqnames
180
+ dtype: string
181
+ description: Chromosome identifier (e.g., chrI, chrII, chrXVI)
182
+ - name: start
183
+ dtype: int64
184
+ description: Promoter region start position (1-based coordinate)
185
+ - name: end
186
+ dtype: int64
187
+ description: Promoter region end position (1-based, inclusive)
188
+ - name: background_counts
189
+ dtype: int64
190
+ description: Read counts in the background/control sample for this peak region
191
+ role: quantitative_measure
192
+ - name: experiment_counts
193
+ dtype: int64
194
+ description: Read counts in the ChIP-exo experiment sample for this peak region
195
+ role: quantitative_measure
196
+ - name: total_background_counts
197
+ dtype: int64
198
+ description: Total read counts across the entire genome in the background sample
199
+ role: quantitative_measure
200
+ - name: total_experiment_counts
201
+ dtype: int64
202
+ description: Total read counts across the entire genome in the experiment sample
203
+ role: quantitative_measure
204
+ - name: enrichment
205
+ dtype: float64
206
+ description: Enrichment score for the binding peak
207
+ role: quantitative_measure
208
+ - name: poisson_pval
209
+ dtype: float64
210
+ description: P-value from Poisson distribution test for peak significance
211
+ role: quantitative_measure
212
+ - name: log_poisson_pval
213
+ dtype: float64
214
+ description: Log-transformed Poisson p-value
215
+ role: quantitative_measure
216
+ - name: hypergeometric_pval
217
+ dtype: float64
218
+ description: P-value from hypergeometric distribution test for peak significance
219
+ role: quantitative_measure
220
+ - name: log_hypergeometric_pval
221
+ dtype: float64
222
+ description: Log-transformed hypergeometric p-value
223
+ role: quantitative_measure
224
+ - name: poisson_qval
225
+ dtype: float64
226
+ description: FDR-adjusted q-value from Poisson test (multiple testing correction)
227
+ role: quantitative_measure
228
+ - name: hypergeometric_qval
229
+ dtype: float64
230
+ description: FDR-adjusted q-value from hypergeometric test (multiple testing correction)
231
+ role: quantitative_measure
232
+
233
+ - config_name: rossi_2021_af_combined
234
+ description: Combined ChIP-exo annotated features with binding peaks and statistical significance metrics aggregated across biological replicates
235
  dataset_type: annotated_features
236
  data_files:
237
+ - split: train
238
+ path: rossi_2021_af_combined.parquet
239
  dataset_info:
240
  features:
241
+ - name: sample_id
242
+ dtype: string
243
+ description: Unique identifier combining regulator and replicates
244
+ role: sample_id
245
+ - name: regulator_locus_tag
246
+ dtype: string
247
+ description: Systematic gene identifier for the transcription factor
248
+ role: regulator_identifier
249
+ - name: regulator_symbol
250
+ dtype: string
251
+ description: Standard gene symbol for the transcription factor
252
+ role: regulator_identifier
253
+ - name: target_locus_tag
254
+ dtype: string
255
+ description: Systematic gene identifier for the target gene
256
+ role: target_identifier
257
+ - name: target_symbol
258
+ dtype: string
259
+ description: Standard gene symbol for the target gene
260
+ role: target_identifier
261
+ - name: seqnames
262
+ dtype: string
263
+ description: Chromosome identifier (e.g., chrI, chrII, chrXVI)
264
+ - name: start
265
+ dtype: int64
266
+ description: Promoter region start position (1-based coordinate)
267
+ - name: end
268
+ dtype: int64
269
+ description: Promoter region end position (1-based, inclusive)
270
+ - name: background_counts
271
+ dtype: int64
272
+ description: Combined read counts in the background/control sample for this peak region
273
+ role: quantitative_measure
274
+ - name: experiment_counts
275
+ dtype: int64
276
+ description: Combined read counts in the ChIP-exo experiment sample for this peak region
277
+ role: quantitative_measure
278
+ - name: total_background_counts
279
+ dtype: int64
280
+ description: Total read counts across the entire genome in the combined background sample
281
+ role: quantitative_measure
282
+ - name: total_experiment_counts
283
+ dtype: int64
284
+ description: Total read counts across the entire genome in the combined experiment sample
285
+ role: quantitative_measure
286
+ - name: enrichment
287
+ dtype: float64
288
+ description: Enrichment score for the binding peak calculated from combined replicates
289
+ role: quantitative_measure
290
+ - name: poisson_pval
291
+ dtype: float64
292
+ description: P-value from Poisson distribution test for peak significance
293
+ role: quantitative_measure
294
+ - name: log_poisson_pval
295
+ dtype: float64
296
+ description: Log-transformed Poisson p-value
297
+ role: quantitative_measure
298
+ - name: hypergeometric_pval
299
+ dtype: float64
300
+ description: P-value from hypergeometric distribution test for peak significance
301
+ role: quantitative_measure
302
+ - name: log_hypergeometric_pval
303
+ dtype: float64
304
+ description: Log-transformed hypergeometric p-value
305
+ role: quantitative_measure
306
+ - name: poisson_qval
307
+ dtype: float64
308
+ description: FDR-adjusted q-value from Poisson test (multiple testing correction)
309
+ role: quantitative_measure
310
+ - name: hypergeometric_qval
311
+ dtype: float64
312
+ description: FDR-adjusted q-value from hypergeometric test (multiple testing correction)
313
+ role: quantitative_measure
314
  ---
315
  # Rossi 2021
316
 
 
319
 
320
  [Rossi MJ, Kuntala PK, Lai WKM, Yamada N, Badjatia N, Mittal C, Kuzu G, Bocklund K, Farrell NP, Blanda TR, Mairose JD, Basting AV, Mistretta KS, Rocco DJ, Perkinson ES, Kellogg GD, Mahony S, Pugh BF. A high-resolution protein architecture of the budding yeast genome. Nature. 2021 Apr;592(7853):309-314. doi: 10.1038/s41586-021-03314-8. Epub 2021 Mar 10. PMID: 33692541; PMCID: PMC8035251.](https://doi.org/10.1038/s41586-021-03314-8)
321
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  ## Usage
323
 
324
  The python package `tfbpapi` provides an interface to this data which eases
yeastepigenome_annotatedfeatures.parquet → deprecated_rossi_2021_metadata.parquet RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:897ea035f3999f23b0fafdc6e574d7d5d4d4e761bb98e2cd3a5c6ad0bac22e1a
3
- size 2551155
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:402b3f50713da090b7c6b33b4d36f70acefa2f56f2fc88eba9f24d08a80a3395
3
+ size 27770
{genome_map → genome_map_control}/accession=SRR11466204/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR11466205/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR11466206/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR11466207/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR11466208/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR11466209/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866599/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866600/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866601/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866602/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866603/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866604/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866605/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866606/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866607/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866608/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866609/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866610/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866611/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866612/part-0.parquet RENAMED
File without changes
{genome_map → genome_map_control}/accession=SRR13866613/part-0.parquet RENAMED
File without changes
reprocess_annotatedfeatures.parquet → genome_map_control_meta.parquet RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1ec8e7d23fb9c494a15a36232ffc7564017c2f9a4562071b822cc33642b6e295
3
- size 115758673
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49fd5f7062f1b700756371d4174769f9a6f14d68ad7d60d9b273b0d4bea188ce
3
+ size 1111
reprocess_annotatedfeatures.parquet.md5 DELETED
@@ -1 +0,0 @@
1
- a277cae297585ab8db9bef0248485d89 reprocess_annotatedfeatures.parquet
 
 
reprocess_annotatedfeatures_tagcounts.parquet.md5 DELETED
@@ -1 +0,0 @@
1
- 026a02d21abbe2809291c8ced11464ec reprocess_annotatedfeatures_tagcounts.parquet
 
 
reprocess_annotatedfeatures_tagcounts.parquet → rossi_2021_af_combined.parquet RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:105c70fb70f51f89c876044c757c79bd7057bc84ecdf95aa43a29387a87b9f1a
3
- size 173799419
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7bf68b04e72863c5cacc4f3da774e572fa71e646fc29bda8dcab04e4fc545c56
3
+ size 276431235
rossi_2021_af_replicates.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ef0bfd35bdfead581ee8fb799f041228d428e7ff2bf412c3b0fff031c18d8a0
3
+ size 416707331
rossi_2021_metadata.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8dbda57bbf680e0706bf9d7cb298848dfb09a7dfa744e79d7e9e5b6208a64e09
3
- size 14696
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ffd0d5ad6fdfcc19dbc0cd6a15d95a1c074e9484562c9613b263e8bf06f2ae4e
3
+ size 33667
rossi_2021_metadata.parquet.md5 DELETED
@@ -1 +0,0 @@
1
- b5cfc02f0086313ac1c7c290b189b1e7 rossi_2021_metadata.parquet
 
 
rossi_2021_metadata_sample.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a033c8b32656b6b38ecefb22a980a8f4d23737271ed84d8b0fb2262960916688
3
+ size 16751
scripts/genomecov_to_annotated_features.R ADDED
@@ -0,0 +1,626 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(tidyverse)
2
+ library(arrow)
3
+ library(here)
4
+ library(yaml)
5
+
6
+ #' Convert BED format data frame to GRanges
7
+ #'
8
+ #' Handles coordinate system conversion from 0-indexed half-open BED format
9
+ #' to 1-indexed closed GenomicRanges format
10
+ #'
11
+ #' @param bed_df Data frame with chr, start, end columns in BED format (0-indexed, half-open)
12
+ #' @param zero_indexed Logical, whether input is 0-indexed (default: TRUE)
13
+ #' @return GRanges object
14
+ bed_to_granges <- function(bed_df, zero_indexed = TRUE) {
15
+
16
+ if (!all(c("chr", "start", "end") %in% names(bed_df))) {
17
+ stop("bed_df must have columns: chr, start, end")
18
+ }
19
+
20
+ # Convert from 0-indexed half-open [start, end) to 1-indexed closed [start, end]
21
+ if (zero_indexed) {
22
+ gr_start <- bed_df$start + 1
23
+ gr_end <- bed_df$end
24
+ } else {
25
+ gr_start <- bed_df$start
26
+ gr_end <- bed_df$end
27
+ }
28
+
29
+ # Create GRanges object (strand-agnostic for calling cards)
30
+ gr <- GenomicRanges::GRanges(
31
+ seqnames = bed_df$chr,
32
+ ranges = IRanges::IRanges(start = gr_start, end = gr_end),
33
+ strand = "*"
34
+ )
35
+
36
+ # Add any additional metadata columns
37
+ extra_cols <- setdiff(names(bed_df), c("chr", "start", "end", "strand"))
38
+ if (length(extra_cols) > 0) {
39
+ GenomicRanges::mcols(gr) <- bed_df[, extra_cols, drop = FALSE]
40
+ }
41
+
42
+ return(gr)
43
+ }
44
+
45
+ #' Convert point-wise coverage to BED format
46
+ #'
47
+ #' @param coverage_df Data frame with chr, pos, pileup columns
48
+ #' @return Data frame in BED format with chr, start, end, score
49
+ coverage_to_bed <- function(coverage_df) {
50
+ coverage_df %>%
51
+ dplyr::rename(start = pos, score = pileup) %>%
52
+ dplyr::mutate(end = start + 1) %>% # pos is 0-indexed, end is exclusive
53
+ dplyr::select(chr, start, end, score)
54
+ }
55
+
56
+ #' Sum scores of overlapping insertions per region
57
+ #'
58
+ #' @param insertions_gr GRanges object with insertions containing a 'score' metadata column
59
+ #' @param regions_gr GRanges object with regions
60
+ #' @return Numeric vector of summed scores per region
61
+ sum_overlap_scores <- function(insertions_gr, regions_gr) {
62
+ # Find overlaps between regions and insertions
63
+ overlaps <- GenomicRanges::findOverlaps(regions_gr, insertions_gr)
64
+
65
+ # If no overlaps, return zeros
66
+ if (length(overlaps) == 0) {
67
+ return(rep(0, length(regions_gr)))
68
+ }
69
+
70
+ # Extract the scores for overlapping insertions
71
+ scores <- GenomicRanges::mcols(insertions_gr)$score[S4Vectors::subjectHits(overlaps)]
72
+
73
+ # Sum scores per region using tapply
74
+ summed_scores <- tapply(scores, S4Vectors::queryHits(overlaps), sum)
75
+
76
+ # Create result vector with zeros for regions without overlaps
77
+ result <- rep(0, length(regions_gr))
78
+ result[as.integer(names(summed_scores))] <- summed_scores
79
+
80
+ return(result)
81
+ }
82
+
83
+ #' Combine replicates for a given regulator
84
+ #'
85
+ #' @param sample_set_id sample_id that identifies a set of replicates
86
+ #' @param genomecov_data List containing meta and ds (tagged experiment data)
87
+ #' @param regions_gr GRanges object with regions to quantify
88
+ combine_replicates_af <- function(sample_set_id, genomecov_data, regions_gr) {
89
+
90
+ message(sprintf("Working on sample_id: %s", sample_set_id))
91
+
92
+ run_accession_list <- genomecov_data$meta %>%
93
+ filter(sample_id == sample_set_id) %>%
94
+ pull(run_accession)
95
+
96
+ library_totals <- genomecov_data$ds %>%
97
+ filter(accession %in% run_accession_list) %>%
98
+ group_by(accession) %>%
99
+ summarise(n = sum(pileup, na.rm = TRUE)) %>%
100
+ collect()
101
+
102
+ replicate_region_counts <- map(run_accession_list, ~{
103
+ run_acc <- .x
104
+
105
+ coverage_gr <- genomecov_data$ds %>%
106
+ filter(accession == run_acc) %>%
107
+ collect() %>%
108
+ coverage_to_bed() %>%
109
+ bed_to_granges()
110
+
111
+ sum_overlap_scores(coverage_gr, regions_gr)
112
+ })
113
+
114
+ replicates <- map2(replicate_region_counts, run_accession_list, ~{
115
+ replicate_regions <- regions_gr
116
+ replicate_regions$score <- .x
117
+ replicate_regions
118
+ })
119
+ names(replicates) <- run_accession_list
120
+
121
+ combined <- regions_gr
122
+ combined$score <- Reduce(`+`, replicate_region_counts)
123
+
124
+ list(
125
+ library_total = library_totals,
126
+ replicates = replicates,
127
+ combined = combined
128
+ )
129
+ }
130
+
131
+ #' Combine control samples
132
+ #'
133
+ #' @param genomecov_control List containing meta and ds (control data)
134
+ #' @param regions_gr GRanges object with regions to quantify
135
+ combine_control_af <- function(genomecov_control, regions_gr) {
136
+
137
+ message("Processing control samples...")
138
+
139
+ library_totals <- genomecov_control$ds %>%
140
+ group_by(accession) %>%
141
+ summarise(n = sum(pileup, na.rm = TRUE)) %>%
142
+ collect()
143
+
144
+ replicate_region_counts <- map(genomecov_control$meta$accession, ~{
145
+ run_acc <- .x
146
+
147
+ coverage_gr <- genomecov_control$ds %>%
148
+ filter(accession == run_acc) %>%
149
+ collect() %>%
150
+ coverage_to_bed() %>%
151
+ bed_to_granges()
152
+
153
+ sum_overlap_scores(coverage_gr, regions_gr)
154
+ })
155
+
156
+ out <- regions_gr
157
+ out$score <- Reduce(`+`, replicate_region_counts)
158
+
159
+ list(
160
+ library_totals = library_totals,
161
+ af = out
162
+ )
163
+ }
164
+
165
+ #' Calculate enrichment (calling cards effect)
166
+ #'
167
+ #' @param total_background_counts Total number of counts in background (scalar or vector)
168
+ #' @param total_experiment_counts Total number of counts in experiment (scalar or vector)
169
+ #' @param background_counts Number of counts in background per region (vector)
170
+ #' @param experiment_counts Number of counts in experiment per region (vector)
171
+ #' @param pseudocount Pseudocount to avoid division by zero (default: 0.1)
172
+ #' @return Enrichment values
173
+ calculate_enrichment <- function(total_background_counts,
174
+ total_experiment_counts,
175
+ background_counts,
176
+ experiment_counts,
177
+ pseudocount = 0.1) {
178
+
179
+ # Input validation
180
+ if (!all(is.numeric(c(total_background_counts, total_experiment_counts,
181
+ background_counts, experiment_counts)))) {
182
+ stop("All inputs must be numeric")
183
+ }
184
+
185
+ # Get the length of the region vectors
186
+ n_regions <- length(background_counts)
187
+
188
+ # Ensure experiment_counts is same length as background_counts
189
+ if (length(experiment_counts) != n_regions) {
190
+ stop("background_counts and experiment_counts must be the same length")
191
+ }
192
+
193
+ # Recycle scalar totals to match region length if needed
194
+ if (length(total_background_counts) == 1) {
195
+ total_background_counts <- rep(total_background_counts, n_regions)
196
+ }
197
+ if (length(total_experiment_counts) == 1) {
198
+ total_experiment_counts <- rep(total_experiment_counts, n_regions)
199
+ }
200
+
201
+ # Now check all are same length
202
+ if (length(total_background_counts) != n_regions ||
203
+ length(total_experiment_counts) != n_regions) {
204
+ stop("All input vectors must be the same length or scalars")
205
+ }
206
+
207
+ # Calculate enrichment
208
+ numerator <- experiment_counts / total_experiment_counts
209
+ denominator <- (background_counts + pseudocount) / total_background_counts
210
+ enrichment <- numerator / denominator
211
+
212
+ # Check for invalid values
213
+ if (any(enrichment < 0, na.rm = TRUE)) {
214
+ stop("Enrichment values must be non-negative")
215
+ }
216
+ if (any(is.na(enrichment))) {
217
+ stop("Enrichment values must not be NA")
218
+ }
219
+ if (any(is.infinite(enrichment))) {
220
+ stop("Enrichment values must not be infinite")
221
+ }
222
+
223
+ return(enrichment)
224
+ }
225
+
226
+ #' Calculate Poisson p-values
227
+ #'
228
+ #' @param total_background_counts Total number of counts in background (scalar or vector)
229
+ #' @param total_experiment_counts Total number of counts in experiment (scalar or vector)
230
+ #' @param background_counts Number of counts in background per region (vector)
231
+ #' @param experiment_counts Number of counts in experiment per region (vector)
232
+ #' @param pseudocount Pseudocount for lambda calculation (default: 0.1)
233
+ #' @param ... additional arguments to `ppois`. note that lower tail is set to FALSE already
234
+ #' @return Poisson p-values
235
+ calculate_poisson_pval <- function(total_background_counts,
236
+ total_experiment_counts,
237
+ background_counts,
238
+ experiment_counts,
239
+ pseudocount = 0.1,
240
+ ...) {
241
+
242
+ # Input validation
243
+ if (!all(is.numeric(c(total_background_counts, total_experiment_counts,
244
+ background_counts, experiment_counts)))) {
245
+ stop("All inputs must be numeric")
246
+ }
247
+
248
+ # Get the length of the region vectors
249
+ n_regions <- length(background_counts)
250
+
251
+ # Ensure experiment_counts is same length as background_counts
252
+ if (length(experiment_counts) != n_regions) {
253
+ stop("background_counts and experiment_counts must be the same length")
254
+ }
255
+
256
+ # Recycle scalar totals to match region length if needed
257
+ if (length(total_background_counts) == 1) {
258
+ total_background_counts <- rep(total_background_counts, n_regions)
259
+ }
260
+ if (length(total_experiment_counts) == 1) {
261
+ total_experiment_counts <- rep(total_experiment_counts, n_regions)
262
+ }
263
+
264
+ # Now check all are same length
265
+ if (length(total_background_counts) != n_regions ||
266
+ length(total_experiment_counts) != n_regions) {
267
+ stop("All input vectors must be the same length or scalars")
268
+ }
269
+
270
+ # Calculate hop ratio
271
+ hop_ratio <- total_experiment_counts / total_background_counts
272
+
273
+ # Calculate expected number of counts (mu/lambda parameter)
274
+ # Add pseudocount to avoid mu = 0
275
+ mu <- (background_counts + pseudocount) * hop_ratio
276
+
277
+ # Observed counts in experiment
278
+ x <- experiment_counts
279
+
280
+ # Calculate p-value: P(X >= x) = 1 - P(X < x) = 1 - P(X <= x-1)
281
+ pval <- ppois(x - 1, lambda = mu, lower.tail = FALSE, ...)
282
+
283
+ return(pval)
284
+ }
285
+
286
+ #' Calculate hypergeometric p-values
287
+ #'
288
+ #' @param total_background_counts Total number of counts in background (scalar or vector)
289
+ #' @param total_experiment_counts Total number of counts in experiment (scalar or vector)
290
+ #' @param background_counts Number of counts in background per region (vector)
291
+ #' @param experiment_counts Number of counts in experiment per region (vector)
292
+ #' @param ... additional arguments to phyper. Note that lower tail is set to false already
293
+ #' @return Hypergeometric p-values
294
+ calculate_hypergeom_pval <- function(total_background_counts,
295
+ total_experiment_counts,
296
+ background_counts,
297
+ experiment_counts,
298
+ ...) {
299
+
300
+ # Input validation
301
+ if (!all(is.numeric(c(total_background_counts, total_experiment_counts,
302
+ background_counts, experiment_counts)))) {
303
+ stop("All inputs must be numeric")
304
+ }
305
+
306
+ # Get the length of the region vectors
307
+ n_regions <- length(background_counts)
308
+
309
+ # Ensure experiment_counts is same length as background_counts
310
+ if (length(experiment_counts) != n_regions) {
311
+ stop("background_counts and experiment_counts must be the same length")
312
+ }
313
+
314
+ # Recycle scalar totals to match region length if needed
315
+ if (length(total_background_counts) == 1) {
316
+ total_background_counts <- rep(total_background_counts, n_regions)
317
+ }
318
+ if (length(total_experiment_counts) == 1) {
319
+ total_experiment_counts <- rep(total_experiment_counts, n_regions)
320
+ }
321
+
322
+ # Now check all are same length
323
+ if (length(total_background_counts) != n_regions ||
324
+ length(total_experiment_counts) != n_regions) {
325
+ stop("All input vectors must be the same length or scalars")
326
+ }
327
+
328
+ # Hypergeometric parameters
329
+ M <- total_background_counts + total_experiment_counts
330
+ n <- total_experiment_counts
331
+ N <- background_counts + experiment_counts
332
+ x <- experiment_counts - 1
333
+
334
+ # Handle edge cases
335
+ valid <- (M >= 1) & (N >= 1)
336
+ pval <- rep(1, length(M))
337
+
338
+ # Calculate p-value for valid cases
339
+ if (any(valid)) {
340
+ pval[valid] <- phyper(x[valid], n[valid], M[valid] - n[valid], N[valid],
341
+ lower.tail = FALSE, ...)
342
+ }
343
+
344
+ return(pval)
345
+ }
346
+
347
+ #' Call peaks/quantify regions using calling cards approach
348
+ #'
349
+ #' @param sample_set_id sample_id that identifies a set of replicates
350
+ #' @param background_counts Vector of background counts per region
351
+ #' @param total_background_counts Total background counts (scalar)
352
+ #' @param annotated_feature_counts List of combined replicate data
353
+ #' @param regions_gr GRanges object with regions
354
+ #' @param pseudocount Pseudocount for calculations (default: 0.1)
355
+ #' @return List with replicates and combined quantifications
356
+ enrichment_analysis <- function(sample_set_id,
357
+ background_counts,
358
+ total_background_counts,
359
+ annotated_feature_counts,
360
+ regions_gr,
361
+ pseudocount = 0.1) {
362
+
363
+ message(sprintf("Working on sample_id for %s", sample_set_id))
364
+
365
+ counts_regulator <- annotated_feature_counts[[as.character(sample_set_id)]]
366
+
367
+ replicate_quants <- map(names(counts_regulator$replicates), ~{
368
+ message(sprintf("Working on replicate: %s", .x))
369
+ gr <- counts_regulator$replicates[[.x]]
370
+
371
+ af <- regions_gr
372
+
373
+ experiment_counts <- gr$score
374
+ total_experiment_counts <- counts_regulator$library_total %>%
375
+ filter(accession == .x) %>%
376
+ pull(n)
377
+
378
+ # Add count columns
379
+ GenomicRanges::mcols(af)$background_counts <- background_counts
380
+ GenomicRanges::mcols(af)$experiment_counts <- experiment_counts
381
+ GenomicRanges::mcols(af)$total_background_counts <- total_background_counts
382
+ GenomicRanges::mcols(af)$total_experiment_counts <- total_experiment_counts
383
+
384
+ # Calculate statistics
385
+ GenomicRanges::mcols(af)$enrichment <- calculate_enrichment(
386
+ total_background_counts = total_background_counts,
387
+ total_experiment_counts = total_experiment_counts,
388
+ background_counts = background_counts,
389
+ experiment_counts = experiment_counts,
390
+ pseudocount = pseudocount
391
+ )
392
+
393
+ GenomicRanges::mcols(af)$poisson_pval <- calculate_poisson_pval(
394
+ total_background_counts = total_background_counts,
395
+ total_experiment_counts = total_experiment_counts,
396
+ background_counts = background_counts,
397
+ experiment_counts = experiment_counts,
398
+ pseudocount = pseudocount
399
+ )
400
+
401
+ GenomicRanges::mcols(af)$log_poisson_pval <- calculate_poisson_pval(
402
+ total_background_counts = total_background_counts,
403
+ total_experiment_counts = total_experiment_counts,
404
+ background_counts = background_counts,
405
+ experiment_counts = experiment_counts,
406
+ pseudocount = pseudocount,
407
+ log.p = TRUE
408
+ )
409
+
410
+ GenomicRanges::mcols(af)$hypergeometric_pval <- calculate_hypergeom_pval(
411
+ total_background_counts = total_background_counts,
412
+ total_experiment_counts = total_experiment_counts,
413
+ background_counts = background_counts,
414
+ experiment_counts = experiment_counts
415
+ )
416
+
417
+ GenomicRanges::mcols(af)$log_hypergeometric_pval <- calculate_hypergeom_pval(
418
+ total_background_counts = total_background_counts,
419
+ total_experiment_counts = total_experiment_counts,
420
+ background_counts = background_counts,
421
+ experiment_counts = experiment_counts,
422
+ log.p = TRUE
423
+ )
424
+
425
+ # Calculate adjusted p-values
426
+ GenomicRanges::mcols(af)$poisson_qval <- p.adjust(
427
+ GenomicRanges::mcols(af)$poisson_pval, method = "fdr")
428
+ GenomicRanges::mcols(af)$hypergeometric_qval <- p.adjust(
429
+ GenomicRanges::mcols(af)$hypergeometric_pval, method = "fdr")
430
+
431
+ af
432
+ })
433
+
434
+ names(replicate_quants) <- names(counts_regulator$replicates)
435
+
436
+ message(sprintf("Working on the combined for sample_id %s", sample_set_id))
437
+
438
+ combined_gr <- regions_gr
439
+
440
+ combined_experiment_counts <- counts_regulator$combined$score
441
+ combined_total_experiment_counts <- sum(counts_regulator$library_total$n)
442
+
443
+ # Add count columns
444
+ GenomicRanges::mcols(combined_gr)$background_counts <- background_counts
445
+ GenomicRanges::mcols(combined_gr)$experiment_counts <- combined_experiment_counts
446
+ GenomicRanges::mcols(combined_gr)$total_background_counts <- total_background_counts
447
+ GenomicRanges::mcols(combined_gr)$total_experiment_counts <- combined_total_experiment_counts
448
+
449
+ # Calculate statistics
450
+ GenomicRanges::mcols(combined_gr)$enrichment <- calculate_enrichment(
451
+ total_background_counts = total_background_counts,
452
+ total_experiment_counts = combined_total_experiment_counts,
453
+ background_counts = background_counts,
454
+ experiment_counts = combined_experiment_counts,
455
+ pseudocount = pseudocount
456
+ )
457
+
458
+ message("Calculating Poisson p-values...")
459
+ GenomicRanges::mcols(combined_gr)$poisson_pval <- calculate_poisson_pval(
460
+ total_background_counts = total_background_counts,
461
+ total_experiment_counts = combined_total_experiment_counts,
462
+ background_counts = background_counts,
463
+ experiment_counts = combined_experiment_counts,
464
+ pseudocount = pseudocount
465
+ )
466
+
467
+ GenomicRanges::mcols(combined_gr)$log_poisson_pval <- calculate_poisson_pval(
468
+ total_background_counts = total_background_counts,
469
+ total_experiment_counts = combined_total_experiment_counts,
470
+ background_counts = background_counts,
471
+ experiment_counts = combined_experiment_counts,
472
+ pseudocount = pseudocount,
473
+ log.p = TRUE
474
+ )
475
+
476
+ message("Calculating hypergeometric p-values...")
477
+ GenomicRanges::mcols(combined_gr)$hypergeometric_pval <- calculate_hypergeom_pval(
478
+ total_background_counts = total_background_counts,
479
+ total_experiment_counts = combined_total_experiment_counts,
480
+ background_counts = background_counts,
481
+ experiment_counts = combined_experiment_counts
482
+ )
483
+
484
+ GenomicRanges::mcols(combined_gr)$log_hypergeometric_pval <- calculate_hypergeom_pval(
485
+ total_background_counts = total_background_counts,
486
+ total_experiment_counts = combined_total_experiment_counts,
487
+ background_counts = background_counts,
488
+ experiment_counts = combined_experiment_counts,
489
+ log.p = TRUE
490
+ )
491
+
492
+ # Calculate adjusted p-values
493
+ message("Calculating adjusted p-values...")
494
+ GenomicRanges::mcols(combined_gr)$poisson_qval <- p.adjust(
495
+ GenomicRanges::mcols(combined_gr)$poisson_pval, method = "fdr")
496
+ GenomicRanges::mcols(combined_gr)$hypergeometric_qval <- p.adjust(
497
+ GenomicRanges::mcols(combined_gr)$hypergeometric_pval, method = "fdr")
498
+
499
+ message("Analysis complete!")
500
+
501
+ list(
502
+ replicates = replicate_quants,
503
+ combined = combined_gr
504
+ )
505
+ }
506
+
507
+ # ============================================================================
508
+ # Main analysis workflow
509
+ # ============================================================================
510
+
511
+ # Load data
512
+ genomic_features <- arrow::read_parquet(
513
+ "~/code/hf/yeast_genome_resources/brentlab_features.parquet")
514
+
515
+ genomecov <- list(
516
+ tagged = list(
517
+ meta = arrow::read_parquet("~/code/hf/rossi_2021/rossi_2021_metadata.parquet"),
518
+ ds = arrow::open_dataset("~/code/hf/rossi_2021/genome_map")
519
+ ),
520
+ control = list(
521
+ meta = arrow::read_parquet("~/code/hf/rossi_2021/genome_map_control_meta.parquet"),
522
+ ds = arrow::open_dataset("~/code/hf/rossi_2021/genome_map_control")
523
+ )
524
+ )
525
+
526
+ # Get unique regulators
527
+ sample_id_list <- genomecov$tagged$meta %>%
528
+ pull(sample_id) %>%
529
+ unique()
530
+
531
+ # Load regions
532
+ regions_gr <- read_tsv(
533
+ "~/code/hf/yeast_genome_resources/yiming_promoters.bed",
534
+ col_names = c('chr', 'start', 'end', 'locus_tag', 'score', 'strand')) %>%
535
+ bed_to_granges()
536
+
537
+ # Process control samples
538
+ rossi_2021_control <- combine_control_af(genomecov$control, regions_gr)
539
+
540
+ # Process all sample_id sets
541
+ annotated_feature_counts <- map(sample_id_list, ~{
542
+ combine_replicates_af(.x, genomecov$tagged, regions_gr)
543
+ })
544
+ names(annotated_feature_counts) <- sample_id_list
545
+
546
+ # Perform enrichment analysis
547
+ annotated_feature_quants <- map(sample_id_list, ~{
548
+ enrichment_analysis(
549
+ .x,
550
+ rossi_2021_control$af$score,
551
+ sum(rossi_2021_control$library_totals$n),
552
+ annotated_feature_counts,
553
+ regions_gr
554
+ )
555
+ })
556
+ names(annotated_feature_quants) <- sample_id_list
557
+
558
+ # Extract and format replicate-level results
559
+ annotated_features_quants_replicates <- map(annotated_feature_quants, ~{
560
+ map(.x$replicates, as_tibble) %>%
561
+ list_rbind(names_to = "run_accession")}) %>%
562
+ list_rbind(names_to = "sample_id") %>%
563
+ mutate(sample_id = as.integer(sample_id)) %>%
564
+ left_join(
565
+ genomecov$tagged$meta %>%
566
+ ungroup() %>%
567
+ select(sample_id, regulator_locus_tag, regulator_symbol, run_accession) %>%
568
+ distinct(),
569
+ by = c("sample_id", "run_accession")) %>%
570
+ left_join(select(genomic_features, locus_tag, symbol)) %>%
571
+ dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol) %>%
572
+ dplyr::relocate(sample_id, run_accession, regulator_locus_tag, regulator_symbol,
573
+ target_locus_tag, target_symbol) %>%
574
+ select(-c(score, width, strand))
575
+
576
+ # Write replicate-level results
577
+ # annotated_features_quants_replicates %>%
578
+ # write_parquet(
579
+ # "~/code/hf/rossi_2021/rossi_2021_af_replicates.parquet",
580
+ # compression = "zstd",
581
+ # write_statistics = TRUE,
582
+ # chunk_size = 6708,
583
+ # use_dictionary = c(
584
+ # sample_id = TRUE,
585
+ # run_accession = TRUE,
586
+ # regulator_locus_tag = TRUE,
587
+ # regulator_symbol = TRUE,
588
+ # seqnames = TRUE,
589
+ # target_locus_tag = TRUE,
590
+ # target_symbol = TRUE
591
+ # )
592
+ # )
593
+
594
+ # Extract and format combined results
595
+ annotated_feature_quants_combined <- map(annotated_feature_quants, ~{
596
+ as_tibble(.x$combined)}) %>%
597
+ list_rbind(names_to = "sample_id") %>%
598
+ mutate(sample_id = as.integer(sample_id)) %>%
599
+ left_join(
600
+ genomecov$tagged$meta %>%
601
+ ungroup() %>%
602
+ select(sample_id, regulator_locus_tag, regulator_symbol) %>%
603
+ distinct(),
604
+ by = "sample_id") %>%
605
+ left_join(select(genomic_features, locus_tag, symbol)) %>%
606
+ dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol) %>%
607
+ dplyr::relocate(sample_id, regulator_locus_tag, regulator_symbol,
608
+ target_locus_tag, target_symbol) %>%
609
+ select(-c(score, width, strand))
610
+
611
+ # Write combined results
612
+ # annotated_feature_quants_combined %>%
613
+ # write_parquet(
614
+ # "~/code/hf/rossi_2021/rossi_2021_af_combined.parquet",
615
+ # compression = "zstd",
616
+ # write_statistics = TRUE,
617
+ # chunk_size = 6708,
618
+ # use_dictionary = c(
619
+ # sample_id = TRUE,
620
+ # regulator_locus_tag = TRUE,
621
+ # regulator_symbol = TRUE,
622
+ # seqnames = TRUE,
623
+ # target_locus_tag = TRUE,
624
+ # target_symbol = TRUE
625
+ # )
626
+ # )
scripts/parse_pugh_genomecov_5p.R CHANGED
@@ -71,19 +71,22 @@ pugh_genomecov_meta = pugh_genomecov_tmp %>%
71
  filter(!is.na(locus_tag)) %>%
72
  bind_rows(
73
  filled_missing_locus_tag) %>%
74
- mutate(regulator_symbol = symbol, regulator_locus_tag = locus_tag)
75
-
76
- pugh_genomecov_meta %>%
77
- select(regulator_locus_tag, regulator_symbol,
78
- run_accession, yeastepigenome_id) %>%
79
- write_parquet("~/code/hf/rossi_2021/rossi_2021_metadata.parquet",
80
- compression = "zstd",
81
- write_statistics = TRUE,
82
- use_dictionary = c(
83
- regulator_locus_tag = TRUE,
84
- regulator_symbol = TRUE
85
- )
86
- )
 
 
 
87
 
88
  process_chipexo_genomecov_file = function(covpath, accession_str){
89
 
 
71
  filter(!is.na(locus_tag)) %>%
72
  bind_rows(
73
  filled_missing_locus_tag) %>%
74
+ mutate(regulator_symbol = symbol, regulator_locus_tag = locus_tag) %>%
75
+ arrange(regulator_locus_tag) %>%
76
+ group_by(regulator_locus_tag) %>%
77
+ mutate(sample_id = cur_group_id())
78
+
79
+ # pugh_genomecov_meta %>%
80
+ # select(regulator_locus_tag, regulator_symbol,
81
+ # run_accession, yeastepigenome_id) %>%
82
+ # write_parquet("~/code/hf/rossi_2021/rossi_2021_metadata.parquet",
83
+ # compression = "zstd",
84
+ # write_statistics = TRUE,
85
+ # use_dictionary = c(
86
+ # regulator_locus_tag = TRUE,
87
+ # regulator_symbol = TRUE
88
+ # )
89
+ # )
90
 
91
  process_chipexo_genomecov_file = function(covpath, accession_str){
92
 
scripts/parse_yeastepigenome_sample_data.R ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(httr)
2
+ library(jsonlite)
3
+ library(tidyverse)
4
+
5
+ ## TODO: this uses the rossi metadata that already existed. That will eventually
6
+ ## be removed. This needs to be created from the yeastepigenome pull below,
7
+ ## and the data from the getGEO directly
8
+
9
+ # Fetch all samples from the API
10
+ response <- GET("https://odin.cac.cornell.edu/yep_api/reviewSamples")
11
+
12
+ # Parse the JSON response
13
+ samples_data <- content(response, "text", encoding = "UTF-8") %>%
14
+ fromJSON(flatten = TRUE)
15
+
16
+ # Convert to tibble
17
+ # The data comes as a named list with numeric indices as names
18
+ yeastepigenome_sample_df <- samples_data %>%
19
+ map_df(~as_tibble(.), .id = "index") %>%
20
+ select(sampleId, assayType, treatments, growthMedia, antibody) %>%
21
+ dplyr::rename(yeastepigenome_id = sampleId,
22
+ assay_type = assayType,
23
+ treatment = treatments,
24
+ growth_media = growthMedia)
25
+
26
+ rossi_meta = arrow::read_parquet("~/code/hf/rossi_2021/deprecated_rossi_2021_metadata.parquet")
27
+
28
+ rossi_meta_with_addtl = rossi_meta %>%
29
+ left_join(yeastepigenome_sample_df) %>%
30
+ filter(!run_accession %in% c('SRR11466887', 'SRR11466891')) %>%
31
+ bind_rows(
32
+ tibble(
33
+ regulator_locus_tag = c("YNL076W", "YGL244W"),
34
+ regulator_symbol = c("MKS1", "RTF1"),
35
+ run_accession = c("SRR11466887", "SRR11466891"),
36
+ yeastepigenome_id = c(14846, 12031),
37
+ assay_type = "ChIP-exo",
38
+ treatment = "Normal",
39
+ growth_media = "YPD",
40
+ antibody = c("HA-tag: Santa Cruz sc-7392", "TAP-tag: Sigma i5006"))) %>%
41
+ arrange(regulator_locus_tag) %>%
42
+ select(-assay_type) %>%
43
+ group_by(regulator_locus_tag, treatment, growth_media) %>%
44
+ mutate(sample_id = cur_group_id()) %>%
45
+ ungroup()
46
+
47
+ # arrow::write_parquet(
48
+ # rossi_meta_with_addtl,
49
+ # "~/code/hf/rossi_2021/rossi_2021_metadata.parquet",
50
+ # compression = "zstd",
51
+ # write_statistics = TRUE,
52
+ # use_dictionary = c(
53
+ # sample_id = TRUE,
54
+ # regulator_locus_tag=TRUE,
55
+ # regulator_symbol = TRUE,
56
+ # treatment = TRUE,
57
+ # growth_media = TRUE))
58
+
59
+
60
+ # NOTE: the following works, but is currently unused
61
+ #
62
+ # library(GEOquery)
63
+ # library(tidyverse)
64
+ #
65
+ # # Get the GEO series data
66
+ # gse <- getGEO("GSE147927", GSEMatrix = FALSE)
67
+ # sample_list <- GSMList(gse)
68
+ #
69
+ # # Helper function for NULL coalescing
70
+ # `%||%` <- function(x, y) if (is.null(x)) y else x
71
+ #
72
+ # # Extract sample metadata
73
+ # extract_sample_metadata_robust <- function(gsm) {
74
+ # meta <- Meta(gsm)
75
+ #
76
+ # # Start with basic info
77
+ # result <- tibble(
78
+ # gsm_id = meta$geo_accession %||% NA,
79
+ # title = meta$title %||% NA,
80
+ # source_name = meta$source_name_ch1 %||% NA,
81
+ # organism = meta$organism_ch1 %||% NA
82
+ # )
83
+ #
84
+ # # Extract characteristics from the 'characteristics_ch1' field
85
+ # if (!is.null(meta$characteristics_ch1)) {
86
+ # for (char in meta$characteristics_ch1) {
87
+ # # Split on first colon
88
+ # parts <- str_split(char, ":\\s*", n = 2)[[1]]
89
+ # if (length(parts) == 2) {
90
+ # char_name <- parts[1]
91
+ # char_value <- parts[2]
92
+ # result[[char_name]] <- char_value
93
+ # }
94
+ # }
95
+ # }
96
+ #
97
+ # # Add protocols
98
+ # result$treatment_protocol <- paste(meta$treatment_protocol_ch1, collapse = " ") %||% NA
99
+ # result$growth_protocol <- paste(meta$growth_protocol_ch1, collapse = " ") %||% NA
100
+ # result$extract_protocol <- paste(meta$extract_protocol_ch1, collapse = " ") %||% NA
101
+ #
102
+ # # Add library info
103
+ # result$library_strategy <- meta$library_strategy %||% NA
104
+ # result$library_source <- meta$library_source %||% NA
105
+ # result$library_selection <- meta$library_selection %||% NA
106
+ # result$instrument_model <- meta$instrument_model %||% NA
107
+ #
108
+ # # Add data processing
109
+ # result$data_processing <- paste(meta$data_processing, collapse = " | ") %||% NA
110
+ #
111
+ # # Extract SRA accession
112
+ # relations <- meta$relation
113
+ # sra_relation <- relations[grepl("SRA", relations)]
114
+ # if (length(sra_relation) > 0) {
115
+ # result$sra_accession <- str_extract(sra_relation, "SR[XR]\\d+")
116
+ # } else {
117
+ # result$sra_accession <- NA
118
+ # }
119
+ #
120
+ # return(result)
121
+ # }
122
+ #
123
+ # # Apply to all samples
124
+ # all_samples_metadata <- map_df(sample_list, extract_sample_metadata_robust)
125
+ #
126
+ # # View results
127
+ # glimpse(all_samples_metadata)
yeastepigenome_annotatedfeatures.parquet.md5 DELETED
@@ -1 +0,0 @@
1
- b905c289a894fe8f92804fc87a79e5d2 yeastepigenome_annotatedfeatures.parquet