cmatkhan commited on
Commit
03af824
·
1 Parent(s): 6130608

adding rossi original authors scores

Browse files
README.md CHANGED
@@ -75,11 +75,14 @@ features:
75
  dtype: string
76
  description: Standard gene symbol of the transcription factor
77
 
 
78
  - applies_to:
79
  - rossi_2021_af_replicates
80
  - rossi_2021_af_combined
81
  - rossi_2021_af_replicates_mindel
82
  - rossi_2021_af_combined_mindel
 
 
83
  fields:
84
  - name: target_locus_tag
85
  dtype: string
@@ -98,6 +101,13 @@ features:
98
  - name: end
99
  dtype: int64
100
  description: Promoter region end position (1-based, inclusive)
 
 
 
 
 
 
 
101
  - name: background_counts
102
  dtype: int64
103
  description: Read counts in the background/control sample for this peak region
@@ -146,6 +156,8 @@ features:
146
  - applies_to:
147
  - rossi_2021_af_replicates_mindel
148
  - rossi_2021_af_combined_mindel
 
 
149
  fields:
150
  - name: width
151
  dtype: int64
@@ -153,6 +165,11 @@ features:
153
  - name: strand
154
  dtype: string
155
  description: Genomic strand of the promoter region (+ or -)
 
 
 
 
 
156
  - name: mindel_name
157
  dtype: string
158
  description: Name of the promoter region as defined in the Mindel promoters
@@ -169,6 +186,22 @@ features:
169
  description: >-
170
  this is a feature from the Mindel data that I have not documented. It is a TODO.
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  configs:
173
  - config_name: rossi_2021_metadata_replicate
174
  description: Metadata describing the tagged regulator in each experiment
@@ -198,7 +231,7 @@ configs:
198
  - config_name: rossi_2021_metadata_sample
199
  description: Sample-level metadata for combined ChIP-exo experiments including experimental conditions
200
  dataset_type: metadata
201
- applies_to: ["rossi_2021_af_combined", "rossi_2021_af_combined_mindel"]
202
  data_files:
203
  - split: train
204
  path: rossi_2021_metadata_sample.parquet
@@ -343,7 +376,9 @@ configs:
343
  role: sample_id
344
 
345
  - config_name: rossi_2021_af_combined_mindel
346
- description: Combined ChIP-exo annotated features with binding peaks and statistical significance metrics aggregated across biological replicates
 
 
347
  dataset_type: annotated_features
348
  genome_resources:
349
  region_sets:
@@ -359,6 +394,54 @@ configs:
359
  dtype: int64
360
  description: Unique identifier combining regulator and replicates
361
  role: sample_id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  ---
363
  # Rossi 2021
364
 
 
75
  dtype: string
76
  description: Standard gene symbol of the transcription factor
77
 
78
+
79
  - applies_to:
80
  - rossi_2021_af_replicates
81
  - rossi_2021_af_combined
82
  - rossi_2021_af_replicates_mindel
83
  - rossi_2021_af_combined_mindel
84
+ - yep_filtered_peaks_yiming
85
+ - yep_filtered_peaks_mindel
86
  fields:
87
  - name: target_locus_tag
88
  dtype: string
 
101
  - name: end
102
  dtype: int64
103
  description: Promoter region end position (1-based, inclusive)
104
+
105
+ - applies_to:
106
+ - rossi_2021_af_replicates
107
+ - rossi_2021_af_combined
108
+ - rossi_2021_af_replicates_mindel
109
+ - rossi_2021_af_combined_mindel
110
+ fields:
111
  - name: background_counts
112
  dtype: int64
113
  description: Read counts in the background/control sample for this peak region
 
156
  - applies_to:
157
  - rossi_2021_af_replicates_mindel
158
  - rossi_2021_af_combined_mindel
159
+ - yep_filtered_peaks_yiming
160
+ - yep_filtered_peaks_mindel
161
  fields:
162
  - name: width
163
  dtype: int64
 
165
  - name: strand
166
  dtype: string
167
  description: Genomic strand of the promoter region (+ or -)
168
+
169
+ - applies_to:
170
+ - rossi_2021_af_replicates_mindel
171
+ - rossi_2021_af_combined_mindel
172
+ fields:
173
  - name: mindel_name
174
  dtype: string
175
  description: Name of the promoter region as defined in the Mindel promoters
 
186
  description: >-
187
  this is a feature from the Mindel data that I have not documented. It is a TODO.
188
 
189
+ - applies_to:
190
+ - yep_filtered_peaks_yiming
191
+ - yep_filtered_peaks_mindel
192
+ fields:
193
+ - name: score
194
+ dtype: float64
195
+ description: >-
196
+ The filtered bed file representing the high confidence ChExMix peaks from
197
+ yeastepigenome.org score. Where multiple peaks intersect the same promoter,
198
+ the median score is taken for that promoter. Replicates are then combined. When
199
+ combining replicates, the median score across all replicates is taken. Note that
200
+ when a replicate does not have a peak score for a promoter in the promoter set,
201
+ that promoter is assigned a score of 0. So if replicate A as a peak score of
202
+ 500 and replicate B did not have any peak intersecting with that promoter, then
203
+ the combined score for that promoter would be 250.
204
+
205
  configs:
206
  - config_name: rossi_2021_metadata_replicate
207
  description: Metadata describing the tagged regulator in each experiment
 
231
  - config_name: rossi_2021_metadata_sample
232
  description: Sample-level metadata for combined ChIP-exo experiments including experimental conditions
233
  dataset_type: metadata
234
+ applies_to: ["rossi_2021_af_combined", "rossi_2021_af_combined_mindel", "yep_filtered_peaks_yiming", "yep_filtered_peaks_mindel]
235
  data_files:
236
  - split: train
237
  path: rossi_2021_metadata_sample.parquet
 
376
  role: sample_id
377
 
378
  - config_name: rossi_2021_af_combined_mindel
379
+ description: >-
380
+ Combined ChIP-exo annotated features with binding peaks and statistical
381
+ significance metrics aggregated across biological replicates
382
  dataset_type: annotated_features
383
  genome_resources:
384
  region_sets:
 
394
  dtype: int64
395
  description: Unique identifier combining regulator and replicates
396
  role: sample_id
397
+
398
+ - config_name: yep_filtered_peaks_yiming
399
+ description: >-
400
+ The filtered high confidence peaks reported at yeastepigenome.org intersected
401
+ with the Kang promoter regions. see `scripts/parse_rossi_filtered_peaks.R`
402
+ for more details. NOTE: be sure to read the definition of the score column,
403
+ which is at the top of this README in the common features section, as the
404
+ score has been combined across peaks intersecting the same promoter in the same
405
+ replicate, and then also across replicates.
406
+ dataset_type: annotated_features
407
+ genome_resources:
408
+ region_sets:
409
+ Kang:
410
+ path: https://huggingface.co/datasets/BrentLab/yeast_genome_resources/blob/main/yiming_promoters.bed
411
+ join_column: target_locus_tag
412
+ data_files:
413
+ - split: train
414
+ path: yep_filtered_peaks_yiming.parquet
415
+ dataset_info:
416
+ features:
417
+ - name: sample_id
418
+ dtype: int64
419
+ description: Unique identifier for the biological replicate
420
+ role: sample_id
421
+
422
+ - config_name: yep_filtered_peaks_mindel
423
+ description: >-
424
+ The filtered high confidence peaks reported at yeastepigenome.org intersected
425
+ with the Mindel promoter regions. see `scripts/parse_rossi_filtered_peaks.R`
426
+ for more details. NOTE: be sure to read the definition of the score column,
427
+ which is at the top of this README in the common features section, as the
428
+ score has been combined across peaks intersecting the same promoter in the same
429
+ replicate, and then also across replicates.
430
+ dataset_type: annotated_features
431
+ genome_resources:
432
+ region_sets:
433
+ Mindel:
434
+ path: https://huggingface.co/datasets/BrentLab/yeast_genome_resources/blob/main/mindel_promoters.csv.gz
435
+ join_column: target_locus_tag
436
+ data_files:
437
+ - split: train
438
+ path: yep_filtered_peaks_mindel.parquet
439
+ dataset_info:
440
+ features:
441
+ - name: sample_id
442
+ dtype: int64
443
+ description: Unique identifier for the biological replicate
444
+ role: sample_id
445
  ---
446
  # Rossi 2021
447
 
scripts/parse_rossi_filtered_peaks.R ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # fetch the zip files from the yeastepigenome.org server
2
+ # https://www.datacommons.psu.edu/download/eberly/pughlab/yeast-epigenome-project/
3
+ # and then extract them
4
+ # with
5
+ #!/usr/bin/env bash
6
+ # fetch_yep_peaks.sh
7
+ #
8
+ # Extracts *_chexmix_filtered_peaks.bed from each *_YEP.zip in ZIP_DIR.
9
+ # Output: yep_filtered_peaks/ in the current working directory.
10
+ #
11
+ # set -euo pipefail
12
+ #
13
+ # ZIP_DIR="${1:-/lts/mblab/downloaded_data/chipexo/yeastepigenome_data}"
14
+ # OUT_DIR="$(pwd)/yep_filtered_peaks"
15
+ #
16
+ # if [[ ! -d "$ZIP_DIR" ]]; then
17
+ # echo "[error] ZIP_DIR not found: $ZIP_DIR" >&2
18
+ # exit 1
19
+ # fi
20
+ #
21
+ # mkdir -p "$OUT_DIR"
22
+ #
23
+ # COUNT=0; SKIP=0; FAIL=0
24
+ #
25
+ # for zip_path in "$ZIP_DIR"/*_YEP.zip; do
26
+ # zip_name=$(basename "$zip_path")
27
+ # sample_id="${zip_name%_YEP.zip}"
28
+ # bed_name="${sample_id}_chexmix_filtered_peaks.bed"
29
+ # dest="$OUT_DIR/$bed_name"
30
+ #
31
+ # if [[ -f "$dest" ]]; then
32
+ # echo "[skip] $bed_name already exists"
33
+ # (( SKIP++ )) || true
34
+ # continue
35
+ # fi
36
+ #
37
+ # # file path inside the zip may vary — find it
38
+ # bed_in_zip=$(unzip -Z1 "$zip_path" 2>/dev/null | grep -m1 "${bed_name}$" || true)
39
+ #
40
+ # if [[ -z "$bed_in_zip" ]]; then
41
+ # echo "[warn] $bed_name not found in $zip_name — skipping" >&2
42
+ # (( FAIL++ )) || true
43
+ # continue
44
+ # fi
45
+ #
46
+ # echo "[ext ] $zip_name → $bed_name"
47
+ # unzip -p "$zip_path" "$bed_in_zip" > "$dest"
48
+ # (( COUNT++ )) || true
49
+ # done
50
+ #
51
+ # echo ""
52
+ # echo "[done] extracted=$COUNT skipped=$SKIP failed=$FAIL"
53
+ # echo "[done] output in: $OUT_DIR"
54
+
55
+ # the following can be run on the output
56
+
57
+ library(tidyverse)
58
+ library(arrow)
59
+ library(GenomicRanges)
60
+ library(here)
61
+
62
+ #' Convert BED format data frame to GRanges
63
+ #'
64
+ #' Handles coordinate system conversion from 0-indexed half-open BED format
65
+ #' to 1-indexed closed GenomicRanges format
66
+ #'
67
+ #' @param bed_df Data frame with chr, start, end columns in BED format (0-indexed, half-open)
68
+ #' @param zero_indexed Logical, whether input is 0-indexed (default: TRUE)
69
+ #' @return GRanges object
70
+ bed_to_granges <- function(bed_df, zero_indexed = TRUE) {
71
+
72
+ if (!all(c("chr", "start", "end") %in% names(bed_df))) {
73
+ stop("bed_df must have columns: chr, start, end")
74
+ }
75
+
76
+ # Convert from 0-indexed half-open [start, end) to 1-indexed closed [start, end]
77
+ if (zero_indexed) {
78
+ gr_start <- bed_df$start + 1
79
+ gr_end <- bed_df$end
80
+ } else {
81
+ gr_start <- bed_df$start
82
+ gr_end <- bed_df$end
83
+ }
84
+
85
+ # Create GRanges object (strand-agnostic for calling cards)
86
+ gr <- GenomicRanges::GRanges(
87
+ seqnames = bed_df$chr,
88
+ ranges = IRanges::IRanges(start = gr_start, end = gr_end),
89
+ strand = "*"
90
+ )
91
+
92
+ # Add any additional metadata columns
93
+ extra_cols <- setdiff(names(bed_df), c("chr", "start", "end", "strand"))
94
+ if (length(extra_cols) > 0) {
95
+ GenomicRanges::mcols(gr) <- bed_df[, extra_cols, drop = FALSE]
96
+ }
97
+
98
+ return(gr)
99
+ }
100
+
101
+ #' Annotate genomic regions with ChExMix peak scores
102
+ #'
103
+ #' Intersects a set of genomic regions (e.g. promoters) with ChExMix filtered
104
+ #' peaks and assigns each region a score. Regions overlapping a single peak
105
+ #' receive that peak's score; regions overlapping multiple peaks receive the
106
+ #' median score across all overlapping peaks. Non-overlapping regions are
107
+ #' scored 0.
108
+ #'
109
+ #' @param peaks_df Data frame with BED-format peak calls (0-indexed, half-open)
110
+ #' and a \code{score} column, as produced by \code{read_in_filtered_bed}.
111
+ #' @param regions_gr GRanges object of genomic regions to annotate
112
+ #' (e.g. an element of \code{regions_list}).
113
+ #'
114
+ #' @return A copy of \code{regions_gr} with an additional metadata column
115
+ #' \code{score}: the peak score for overlapping regions, 0 otherwise.
116
+ #'
117
+ #' @seealso \code{\link{bed_to_granges}}, \code{\link{read_in_filtered_bed}}
118
+ peaks_to_promoter_scores <- function(peaks_df, regions_gr) {
119
+
120
+ peaks_gr <- bed_to_granges(peaks_df)
121
+
122
+ hits <- GenomicRanges::findOverlaps(regions_gr, peaks_gr)
123
+
124
+ # for each hit, pull the peak score
125
+ scores_df <- tibble(
126
+ region_idx = S4Vectors::queryHits(hits),
127
+ score = peaks_df$score[S4Vectors::subjectHits(hits)]
128
+ ) |>
129
+ summarise(score = median(score), .by = region_idx)
130
+
131
+ # initialize all promoters to 0, fill in overlapping ones
132
+ result <- rep(0, length(regions_gr))
133
+ result[scores_df$region_idx] <- scores_df$score
134
+
135
+ regions_gr_tmp <- regions_gr
136
+ regions_gr_tmp$score <- result
137
+ regions_gr_tmp
138
+ }
139
+
140
+
141
+ rossi_meta = arrow::read_parquet("~/code/hf/rossi_2021/rossi_2021_metadata.parquet")
142
+ chrmap = read_csv("~/code/hf/yeast_genome_resources/chrmap.csv.gz")
143
+
144
+ brentlab_features = read_csv("~/code/hf/yeast_genome_resources/brentlab_features.csv.gz")
145
+
146
+ # Load regions
147
+ regions_list = list(
148
+ yiming = read_tsv(
149
+ "~/code/hf/yeast_genome_resources/yiming_promoters.bed",
150
+ col_names = c('chr', 'start', 'end', 'locus_tag', 'score', 'strand')) %>%
151
+ bed_to_granges(),
152
+ mindel = arrow::read_parquet("~/code/hf/yeast_genome_resources/mindel_promoters.parquet") |>
153
+ bed_to_granges()
154
+ )
155
+
156
+ filtered_bed = list.files(here("data/yep_filtered_peaks"), full.names = TRUE)
157
+ names(filtered_bed) = str_extract(basename(filtered_bed), "^\\d+")
158
+
159
+ read_in_filtered_bed = function(path){
160
+ read_tsv(path, col_names = c('chr', 'start', 'end', 'source', 'score')) |>
161
+ left_join(dplyr::select(chrmap, chr, ucsc)) |>
162
+ dplyr::select(-chr) |>
163
+ dplyr::rename(chr = ucsc) |>
164
+ dplyr::relocate(chr)
165
+ }
166
+
167
+ filtered_bed_df_list = map(filtered_bed, read_in_filtered_bed)
168
+
169
+ filtered_bed_df_list_no_null = filtered_bed_df_list[unlist(map(filtered_bed_df_list, ~nrow(.) > 0))]
170
+
171
+ filtered_bed_df_list_no_null_in_meta = filtered_bed_df_list_no_null[
172
+ as.integer(names(filtered_bed_df_list_no_null)) %in% rossi_meta$yeastepigenome_id]
173
+
174
+ af_list = list(
175
+ yiming = map(filtered_bed_df_list_no_null_in_meta, peaks_to_promoter_scores, regions_list$yiming),
176
+ mindel = map(filtered_bed_df_list_no_null_in_meta, peaks_to_promoter_scores, regions_list$mindel)
177
+ )
178
+
179
+ af_list_dfs = list(
180
+ yiming = bind_rows(map(af_list$yiming, as_tibble), .id = "yeastepigenome_id") |>
181
+ mutate(yeastepigenome_id = as.integer(yeastepigenome_id)) |>
182
+ left_join(dplyr::select(brentlab_features, locus_tag, symbol)) |>
183
+ dplyr::rename(target_locus_tag = locus_tag, target_symbol = symbol) |>
184
+ left_join(rossi_meta) |>
185
+ dplyr::rename(seqnames = chr) |>
186
+ group_by(sample_id, seqnames, start, end, width, strand, target_locus_tag, target_symbol) |>
187
+ reframe(score = median(score)) |>
188
+ group_by(sample_id) |>
189
+ arrange(desc(score)),
190
+ mindel = bind_rows(map(af_list$mindel, as_tibble), .id = "yeastepigenome_id") |>
191
+ mutate(yeastepigenome_id = as.integer(yeastepigenome_id)) |>
192
+ left_join(rossi_meta) |>
193
+ dplyr::rename(seqnames = chr) |>
194
+ group_by(sample_id, seqnames, start, end, width, strand, target_locus_tag, target_symbol) |>
195
+ reframe(score = median(score)) |>
196
+ group_by(sample_id) |>
197
+ arrange(desc(score))
198
+ )
199
+
200
+ arrow::write_parquet(
201
+ af_list_dfs$yiming,
202
+ "~/code/hf/rossi_2021/yep_filtered_peaks_yiming.parquet",
203
+ compression = "zstd",
204
+ write_statistics = TRUE
205
+ )
206
+
207
+ arrow::write_parquet(
208
+ af_list_dfs$mindel,
209
+ "~/code/hf/rossi_2021/yep_filtered_peaks_mindel.parquet",
210
+ compression = "zstd",
211
+ write_statistics = TRUE
212
+ )
yep_filtered_peaks_mindel.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f8473129d802f994ddc01c9e2d5d1625da8b541dc3439b7a389397568a93662
3
+ size 24383507
yep_filtered_peaks_yiming.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbd1506072d97198bce01b497cb93a33a79772843bd6fa22bfe5dd04e3037795
3
+ size 30745732