Chase Mateusiak commited on
Commit ·
ff375da
1
Parent(s): bc5d4d7
adding yep and macs peaks
Browse files- README.md +29 -2
- macs2_annotated_peaks_combined.parquet +3 -0
- scripts/parse_rossi_filtered_peaks.R +48 -36
- scripts/rossi_peak_analysis.R +325 -0
- yep_filtered_peaks.parquet +2 -2
README.md
CHANGED
|
@@ -71,6 +71,7 @@ features:
|
|
| 71 |
- rossi_2021_af_combined_start_codon_500bp
|
| 72 |
- rossi_2021_af_replicates_intergenic_replicates
|
| 73 |
- rossi_2021_af_combined_intergenic
|
|
|
|
| 74 |
fields:
|
| 75 |
- name: regulator_locus_tag
|
| 76 |
dtype: string
|
|
@@ -90,6 +91,7 @@ features:
|
|
| 90 |
- rossi_2021_af_combined_start_codon_500bp
|
| 91 |
- rossi_2021_af_replicates_intergenic_replicates
|
| 92 |
- rossi_2021_af_combined_intergenic
|
|
|
|
| 93 |
fields:
|
| 94 |
- name: target_locus_tag
|
| 95 |
dtype: string
|
|
@@ -242,7 +244,7 @@ configs:
|
|
| 242 |
- config_name: rossi_2021_metadata_replicate
|
| 243 |
description: Metadata describing the tagged regulator in each experiment
|
| 244 |
dataset_type: metadata
|
| 245 |
-
applies_to: ["genome_map"]
|
| 246 |
data_files:
|
| 247 |
- split: train
|
| 248 |
path: rossi_2021_metadata.parquet
|
|
@@ -267,7 +269,7 @@ configs:
|
|
| 267 |
- config_name: rossi_2021_metadata_sample
|
| 268 |
description: Sample-level metadata for combined ChIP-exo experiments including experimental conditions
|
| 269 |
dataset_type: metadata
|
| 270 |
-
applies_to: ["rossi_2021_af_combined", "rossi_2021_af_combined_mindel", "yep_filtered_peaks_combined", "rossi_2021_af_combined_start_codon_500bp", "rossi_2021_af_combined_intergenic"]
|
| 271 |
data_files:
|
| 272 |
- split: train
|
| 273 |
path: rossi_2021_metadata_sample.parquet
|
|
@@ -375,6 +377,31 @@ configs:
|
|
| 375 |
dtype: int32
|
| 376 |
description: "Score assigned by ChExMix as reported by yeastepigenome.org"
|
| 377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
- config_name: rossi_2021_af_replicates
|
| 379 |
description: ChIP-exo annotated features at biological replicate level with binding peaks and statistical significance metrics
|
| 380 |
dataset_type: annotated_features
|
|
|
|
| 71 |
- rossi_2021_af_combined_start_codon_500bp
|
| 72 |
- rossi_2021_af_replicates_intergenic_replicates
|
| 73 |
- rossi_2021_af_combined_intergenic
|
| 74 |
+
- macs2_annotated_peaks_combined
|
| 75 |
fields:
|
| 76 |
- name: regulator_locus_tag
|
| 77 |
dtype: string
|
|
|
|
| 91 |
- rossi_2021_af_combined_start_codon_500bp
|
| 92 |
- rossi_2021_af_replicates_intergenic_replicates
|
| 93 |
- rossi_2021_af_combined_intergenic
|
| 94 |
+
- macs2_annotated_peaks_combined
|
| 95 |
fields:
|
| 96 |
- name: target_locus_tag
|
| 97 |
dtype: string
|
|
|
|
| 244 |
- config_name: rossi_2021_metadata_replicate
|
| 245 |
description: Metadata describing the tagged regulator in each experiment
|
| 246 |
dataset_type: metadata
|
| 247 |
+
applies_to: ["genome_map", "yep_filtered_peaks"]
|
| 248 |
data_files:
|
| 249 |
- split: train
|
| 250 |
path: rossi_2021_metadata.parquet
|
|
|
|
| 269 |
- config_name: rossi_2021_metadata_sample
|
| 270 |
description: Sample-level metadata for combined ChIP-exo experiments including experimental conditions
|
| 271 |
dataset_type: metadata
|
| 272 |
+
applies_to: ["rossi_2021_af_combined", "rossi_2021_af_combined_mindel", "yep_filtered_peaks_combined", "rossi_2021_af_combined_start_codon_500bp", "rossi_2021_af_combined_intergenic", "macs2_annotated_peaks_combined"]
|
| 273 |
data_files:
|
| 274 |
- split: train
|
| 275 |
path: rossi_2021_metadata_sample.parquet
|
|
|
|
| 377 |
dtype: int32
|
| 378 |
description: "Score assigned by ChExMix as reported by yeastepigenome.org"
|
| 379 |
|
| 380 |
+
- config_name: macs2_annotated_peaks_combined
|
| 381 |
+
description: "peaks called with macs2. see scripts/rossi_peak_analysis.R for details. peaks filtered to -log10(q) > 0.1, and to only those within 700 bp of the 5' end of the most 5' exon. max, median and nearest scores are assigned to the feature."
|
| 382 |
+
data_files:
|
| 383 |
+
- split: train
|
| 384 |
+
path: macs2_annotated_peaks_combined.parquet
|
| 385 |
+
dataset_info:
|
| 386 |
+
features:
|
| 387 |
+
- name: sample_id
|
| 388 |
+
dtype: string
|
| 389 |
+
description: sample identifier. use with rossi_2021_metadata_sample
|
| 390 |
+
- name: n_peaks
|
| 391 |
+
dtype: int32
|
| 392 |
+
description: number of peaks that are annotated to within 700 bp of the target. Note that a peak may be annotated to multiple targets
|
| 393 |
+
- name: nearest_score
|
| 394 |
+
dtype: float64
|
| 395 |
+
description: -log10(qvalue) of the peak nearest to the target
|
| 396 |
+
- name: median_score
|
| 397 |
+
dtype: float64
|
| 398 |
+
description: median -log10(qvalue) of the peaks annotated to the target
|
| 399 |
+
- name: max_score
|
| 400 |
+
dtype: float64
|
| 401 |
+
description: max -log10(qvalue) of the peaks annotated to the target
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
|
| 405 |
- config_name: rossi_2021_af_replicates
|
| 406 |
description: ChIP-exo annotated features at biological replicate level with binding peaks and statistical significance metrics
|
| 407 |
dataset_type: annotated_features
|
macs2_annotated_peaks_combined.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c1153f0d3b94608f484dabec7577134f89abe11678f42d43ec4dc78b68f5b367
|
| 3 |
+
size 7124660
|
scripts/parse_rossi_filtered_peaks.R
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 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.
|
|
@@ -68,7 +68,6 @@ library(here)
|
|
| 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 |
}
|
|
@@ -110,19 +109,21 @@ bed_to_granges <- function(bed_df, zero_indexed = TRUE) {
|
|
| 110 |
#' @return GRanges of retained gene features with metadata columns
|
| 111 |
#' \code{locus_tag} and \code{symbol}.
|
| 112 |
prepare_gene_features <- function(features_df) {
|
| 113 |
-
|
| 114 |
genes <- features_df |>
|
| 115 |
-
dplyr::filter(
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
GenomicRanges::GRanges(
|
| 121 |
seqnames = genes$chr,
|
| 122 |
-
ranges
|
| 123 |
-
strand
|
| 124 |
locus_tag = genes$locus_tag,
|
| 125 |
-
symbol
|
| 126 |
)
|
| 127 |
}
|
| 128 |
|
|
@@ -154,64 +155,74 @@ prepare_gene_features <- function(features_df) {
|
|
| 154 |
#'
|
| 155 |
#' @seealso \code{\link{bed_to_granges}}, \code{\link{prepare_gene_features}}
|
| 156 |
annotate_peaks_to_features <- function(peaks_df, features_gr, nbp = 500) {
|
| 157 |
-
|
| 158 |
peaks_gr <- bed_to_granges(peaks_df)
|
| 159 |
|
| 160 |
# round 1: nearest downstream feature (strand-agnostic) and its distance
|
| 161 |
ds_idx <- GenomicRanges::precede(peaks_gr, features_gr, ignore.strand = TRUE)
|
| 162 |
-
keep
|
| 163 |
|
| 164 |
-
peaks_gr
|
| 165 |
feat_hits <- features_gr[ds_idx[keep]]
|
| 166 |
|
| 167 |
round1 <- tibble::tibble(
|
| 168 |
-
score
|
| 169 |
target_locus_tag = feat_hits$locus_tag,
|
| 170 |
-
target_symbol
|
| 171 |
-
distance
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
dplyr::filter(distance <= nbp)
|
| 174 |
|
| 175 |
# round 2: aggregate peaks per target gene, median score as the peak score
|
| 176 |
round1 |>
|
| 177 |
dplyr::group_by(target_locus_tag, target_symbol) |>
|
| 178 |
-
dplyr::reframe(
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
|
| 184 |
-
rossi_meta
|
| 185 |
-
chrmap
|
| 186 |
|
| 187 |
-
brentlab_features
|
| 188 |
|
| 189 |
# protein-coding gene features used to annotate peaks (excludes dubious ORFs)
|
| 190 |
-
gene_features_gr
|
| 191 |
|
| 192 |
-
filtered_bed
|
| 193 |
-
names(filtered_bed)
|
| 194 |
|
| 195 |
-
read_in_filtered_bed
|
| 196 |
-
read_tsv(path, col_names = c(
|
| 197 |
left_join(dplyr::select(chrmap, chr, ucsc)) |>
|
| 198 |
dplyr::select(-chr) |>
|
| 199 |
dplyr::rename(chr = ucsc) |>
|
| 200 |
dplyr::relocate(chr)
|
| 201 |
}
|
| 202 |
|
| 203 |
-
filtered_bed_df_list
|
|
|
|
|
|
|
| 204 |
|
| 205 |
-
|
|
|
|
|
|
|
| 206 |
|
| 207 |
-
filtered_bed_df_list_no_null_in_meta =
|
| 208 |
-
|
|
|
|
| 209 |
|
| 210 |
# annotate each sample's peaks to nearest downstream genes within 500bp
|
| 211 |
-
annotated
|
| 212 |
-
|
|
|
|
|
|
|
| 213 |
|
| 214 |
-
annotated_df
|
| 215 |
mutate(yeastepigenome_id = as.integer(yeastepigenome_id)) |>
|
| 216 |
left_join(rossi_meta, by = "yeastepigenome_id") |>
|
| 217 |
group_by(sample_id, target_locus_tag, target_symbol) |>
|
|
@@ -219,7 +230,8 @@ annotated_df = bind_rows(annotated, .id = "yeastepigenome_id") |>
|
|
| 219 |
peak_score = median(peak_score),
|
| 220 |
n_peaks = sum(n_peaks),
|
| 221 |
max_distance = max(max_distance),
|
| 222 |
-
peak_n_replicates = n()
|
|
|
|
| 223 |
arrange(desc(peak_score), .by_group = TRUE)
|
| 224 |
|
| 225 |
# arrow::write_parquet(
|
|
|
|
| 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.
|
|
|
|
| 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 |
if (!all(c("chr", "start", "end") %in% names(bed_df))) {
|
| 72 |
stop("bed_df must have columns: chr, start, end")
|
| 73 |
}
|
|
|
|
| 109 |
#' @return GRanges of retained gene features with metadata columns
|
| 110 |
#' \code{locus_tag} and \code{symbol}.
|
| 111 |
prepare_gene_features <- function(features_df) {
|
|
|
|
| 112 |
genes <- features_df |>
|
| 113 |
+
dplyr::filter(
|
| 114 |
+
type == "gene",
|
| 115 |
+
stringr::str_detect(note, stringr::fixed("dubious", ignore_case = TRUE),
|
| 116 |
+
negate = TRUE
|
| 117 |
+
),
|
| 118 |
+
chr != "chrM"
|
| 119 |
+
)
|
| 120 |
|
| 121 |
GenomicRanges::GRanges(
|
| 122 |
seqnames = genes$chr,
|
| 123 |
+
ranges = IRanges::IRanges(start = genes$start, end = genes$end),
|
| 124 |
+
strand = genes$strand,
|
| 125 |
locus_tag = genes$locus_tag,
|
| 126 |
+
symbol = genes$symbol
|
| 127 |
)
|
| 128 |
}
|
| 129 |
|
|
|
|
| 155 |
#'
|
| 156 |
#' @seealso \code{\link{bed_to_granges}}, \code{\link{prepare_gene_features}}
|
| 157 |
annotate_peaks_to_features <- function(peaks_df, features_gr, nbp = 500) {
|
|
|
|
| 158 |
peaks_gr <- bed_to_granges(peaks_df)
|
| 159 |
|
| 160 |
# round 1: nearest downstream feature (strand-agnostic) and its distance
|
| 161 |
ds_idx <- GenomicRanges::precede(peaks_gr, features_gr, ignore.strand = TRUE)
|
| 162 |
+
keep <- !is.na(ds_idx)
|
| 163 |
|
| 164 |
+
peaks_gr <- peaks_gr[keep]
|
| 165 |
feat_hits <- features_gr[ds_idx[keep]]
|
| 166 |
|
| 167 |
round1 <- tibble::tibble(
|
| 168 |
+
score = peaks_df$score[keep],
|
| 169 |
target_locus_tag = feat_hits$locus_tag,
|
| 170 |
+
target_symbol = feat_hits$symbol,
|
| 171 |
+
distance = GenomicRanges::distance(peaks_gr, feat_hits,
|
| 172 |
+
ignore.strand = TRUE
|
| 173 |
+
)
|
| 174 |
+
) |>
|
| 175 |
dplyr::filter(distance <= nbp)
|
| 176 |
|
| 177 |
# round 2: aggregate peaks per target gene, median score as the peak score
|
| 178 |
round1 |>
|
| 179 |
dplyr::group_by(target_locus_tag, target_symbol) |>
|
| 180 |
+
dplyr::reframe(
|
| 181 |
+
peak_score = median(score),
|
| 182 |
+
n_peaks = dplyr::n(),
|
| 183 |
+
max_distance = max(distance)
|
| 184 |
+
)
|
| 185 |
}
|
| 186 |
|
| 187 |
|
| 188 |
+
rossi_meta <- arrow::read_parquet("~/projects/huggingface/rossi_2021/rossi_2021_metadata.parquet")
|
| 189 |
+
chrmap <- read_csv("~/projects/huggingface/yeast_genome_resources/chrmap.csv.gz")
|
| 190 |
|
| 191 |
+
brentlab_features <- arrow::read_parquet("~/projects/huggingface/yeast_genome_resources/brentlab_features.parquet")
|
| 192 |
|
| 193 |
# protein-coding gene features used to annotate peaks (excludes dubious ORFs)
|
| 194 |
+
gene_features_gr <- prepare_gene_features(brentlab_features)
|
| 195 |
|
| 196 |
+
filtered_bed <- list.files(here("data/yep_filtered_peaks"), full.names = TRUE)
|
| 197 |
+
names(filtered_bed) <- str_extract(basename(filtered_bed), "^\\d+")
|
| 198 |
|
| 199 |
+
read_in_filtered_bed <- function(path) {
|
| 200 |
+
read_tsv(path, col_names = c("chr", "start", "end", "source", "score")) |>
|
| 201 |
left_join(dplyr::select(chrmap, chr, ucsc)) |>
|
| 202 |
dplyr::select(-chr) |>
|
| 203 |
dplyr::rename(chr = ucsc) |>
|
| 204 |
dplyr::relocate(chr)
|
| 205 |
}
|
| 206 |
|
| 207 |
+
filtered_bed_df_list <- map(filtered_bed, read_in_filtered_bed)
|
| 208 |
+
|
| 209 |
+
filtered_bed_df_list_no_null <- filtered_bed_df_list[unlist(map(filtered_bed_df_list, ~ nrow(.) > 0))]
|
| 210 |
|
| 211 |
+
filtered_bed_df_list_no_null_in_meta <- filtered_bed_df_list_no_null[
|
| 212 |
+
as.integer(names(filtered_bed_df_list_no_null)) %in% rossi_meta$yeastepigenome_id
|
| 213 |
+
]
|
| 214 |
|
| 215 |
+
# bind_rows(filtered_bed_df_list_no_null_in_meta, .id = 'yeastepigenome_id') |>
|
| 216 |
+
# dplyr::select(yeastepigenome_id, chr, start, end, score) |>
|
| 217 |
+
# arrow::write_parquet("~/projects/huggingface/rossi_2021/yep_filtered_peaks.parquet")
|
| 218 |
|
| 219 |
# annotate each sample's peaks to nearest downstream genes within 500bp
|
| 220 |
+
annotated <- map(filtered_bed_df_list_no_null_in_meta,
|
| 221 |
+
annotate_peaks_to_features, gene_features_gr,
|
| 222 |
+
nbp = 500
|
| 223 |
+
)
|
| 224 |
|
| 225 |
+
annotated_df <- bind_rows(annotated, .id = "yeastepigenome_id") |>
|
| 226 |
mutate(yeastepigenome_id = as.integer(yeastepigenome_id)) |>
|
| 227 |
left_join(rossi_meta, by = "yeastepigenome_id") |>
|
| 228 |
group_by(sample_id, target_locus_tag, target_symbol) |>
|
|
|
|
| 230 |
peak_score = median(peak_score),
|
| 231 |
n_peaks = sum(n_peaks),
|
| 232 |
max_distance = max(max_distance),
|
| 233 |
+
peak_n_replicates = n()
|
| 234 |
+
) |>
|
| 235 |
arrange(desc(peak_score), .by_group = TRUE)
|
| 236 |
|
| 237 |
# arrow::write_parquet(
|
scripts/rossi_peak_analysis.R
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(tidyverse)
|
| 2 |
+
library(janitor)
|
| 3 |
+
library(GenomicRanges)
|
| 4 |
+
library(here)
|
| 5 |
+
|
| 6 |
+
exclude_regions <- rtracklayer::import(here("data/ChExMix_Peak_Filter_List_190612.bed"))
|
| 7 |
+
seqlevels(exclude_regions)[which(seqlevels(exclude_regions) == "chr2-micron")] <- "2-micron"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
read_in_annotated_peaks <- function(peak_path) {
|
| 11 |
+
df <- read_tsv(peak_path, show_col_types = FALSE)
|
| 12 |
+
|
| 13 |
+
# Skip empty annotations
|
| 14 |
+
if (nrow(df) == 0) {
|
| 15 |
+
warning(sprintf("Skipping empty annotation file: %s", basename(peak_path)))
|
| 16 |
+
return(NULL)
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
tryCatch(
|
| 20 |
+
{
|
| 21 |
+
# Convert peaks to GRanges for overlap detection
|
| 22 |
+
peaks_gr <- GenomicRanges::GRanges(
|
| 23 |
+
seqnames = df$Chr,
|
| 24 |
+
ranges = IRanges::IRanges(start = df$Start, end = df$End),
|
| 25 |
+
strand = df$Strand
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Find overlaps with exclude regions
|
| 29 |
+
overlaps <- GenomicRanges::findOverlaps(peaks_gr, exclude_regions)
|
| 30 |
+
|
| 31 |
+
# Label peaks that overlap with exclude regions
|
| 32 |
+
df <- df |>
|
| 33 |
+
mutate(
|
| 34 |
+
in_exclude_region = seq_len(nrow(df)) %in% S4Vectors::queryHits(overlaps)
|
| 35 |
+
) |>
|
| 36 |
+
janitor::clean_names()
|
| 37 |
+
|
| 38 |
+
return(df)
|
| 39 |
+
},
|
| 40 |
+
error = function(e) {
|
| 41 |
+
warning(sprintf("Error processing: %s. Error: %s", basename(peak_path), e$message))
|
| 42 |
+
return(NULL)
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
score_targets <- function(df, min_dist = 0, max_dist = 700) {
|
| 48 |
+
df |>
|
| 49 |
+
filter(!in_exclude_region) |>
|
| 50 |
+
filter(
|
| 51 |
+
peak_score > -log10(0.1),
|
| 52 |
+
str_detect(nearest_promoter_id, "mRNA"),
|
| 53 |
+
between(distance_to_tss, min_dist, max_dist)
|
| 54 |
+
) |>
|
| 55 |
+
group_by(entrez_id) |>
|
| 56 |
+
reframe(
|
| 57 |
+
n_peaks = n(),
|
| 58 |
+
nearest_score = peak_score[which.min(abs(distance_to_tss))],
|
| 59 |
+
median_score = median(peak_score),
|
| 60 |
+
max_score = max(peak_score)
|
| 61 |
+
)
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
annotated_peaks <- list(
|
| 66 |
+
files = list.files(here("data/chipexo_macs3/annotated_peaks"),
|
| 67 |
+
"_annotated_peaks.txt",
|
| 68 |
+
full.names = TRUE,
|
| 69 |
+
recursive = TRUE
|
| 70 |
+
)
|
| 71 |
+
)
|
| 72 |
+
names(annotated_peaks$files) <- str_remove(
|
| 73 |
+
basename(annotated_peaks$files),
|
| 74 |
+
"_annotated_peaks.txt"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
annotated_peaks$df <- map(annotated_peaks$files, read_in_annotated_peaks)
|
| 78 |
+
|
| 79 |
+
annotated_peaks$dfcomp
|
| 80 |
+
|
| 81 |
+
annotated_peaks$target_score <- map(compact(annotated_peaks$df), score_targets)
|
| 82 |
+
|
| 83 |
+
peaks_df <- bind_rows(annotated_peaks$target_score, .id = "tmp") |>
|
| 84 |
+
separate_wider_delim(tmp,
|
| 85 |
+
delim = "_", names = c(
|
| 86 |
+
"regulator_locus_tag",
|
| 87 |
+
"regulator_symbol",
|
| 88 |
+
"treatment",
|
| 89 |
+
"growth_media"
|
| 90 |
+
),
|
| 91 |
+
too_few = "align_start"
|
| 92 |
+
) |>
|
| 93 |
+
mutate(
|
| 94 |
+
treatment = ifelse(treatment == "Heat", "Heat Shock", treatment),
|
| 95 |
+
growth_media = ifelse(is.na(growth_media), "YPD", growth_media)
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
rossi_sample_meta <- arrow::read_parquet("~/projects/huggingface/rossi_2021/rossi_2021_metadata_sample.parquet")
|
| 100 |
+
|
| 101 |
+
brentlab_features <- read_csv("~/projects/huggingface/yeast_genome_resources/brentlab_features.csv.gz")
|
| 102 |
+
|
| 103 |
+
peaks_df_to_hf <- peaks_df |>
|
| 104 |
+
left_join(rossi_sample_meta) |>
|
| 105 |
+
dplyr::select(sample_id, regulator_locus_tag,
|
| 106 |
+
regulator_symbol,
|
| 107 |
+
target_locus_tag = entrez_id,
|
| 108 |
+
n_peaks, nearest_score, median_score, max_score
|
| 109 |
+
) |>
|
| 110 |
+
left_join(dplyr::select(brentlab_features,
|
| 111 |
+
target_locus_tag = locus_tag,
|
| 112 |
+
target_symbol = symbol
|
| 113 |
+
)) |>
|
| 114 |
+
dplyr::relocate(
|
| 115 |
+
sample_id, regulator_locus_tag, regulator_symbol,
|
| 116 |
+
target_locus_tag, target_symbol
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
peaks_df_to_hf |>
|
| 120 |
+
arrow::write_parquet("~/projects/huggingface/rossi_2021/macs2_annotated_peaks.parquet")
|
| 121 |
+
|
| 122 |
+
mcisaac_responsive <- arrow::read_parquet("~/projects/huggingface/hackett_2020/hackett_2020_analysis_set.parquet")
|
| 123 |
+
|
| 124 |
+
peaks_with_mcisaac <- peaks_df |>
|
| 125 |
+
dplyr::rename(target_locus_tag = entrez_id) |>
|
| 126 |
+
filter(
|
| 127 |
+
treatment == "Normal",
|
| 128 |
+
growth_media == "YPD",
|
| 129 |
+
median_score >= -log10(0.1)
|
| 130 |
+
) |>
|
| 131 |
+
left_join(dplyr::select(
|
| 132 |
+
mcisaac_responsive,
|
| 133 |
+
regulator_locus_tag,
|
| 134 |
+
target_locus_tag,
|
| 135 |
+
time,
|
| 136 |
+
responsive
|
| 137 |
+
)) |>
|
| 138 |
+
filter(!is.na(responsive))
|
| 139 |
+
|
| 140 |
+
peaks_with_mcisaac |>
|
| 141 |
+
filter(time == 30) |>
|
| 142 |
+
group_by(regulator_locus_tag) |>
|
| 143 |
+
nest() |>
|
| 144 |
+
mutate(
|
| 145 |
+
rr_nearest = map_dbl(data, ~ {
|
| 146 |
+
.x |>
|
| 147 |
+
arrange(desc(nearest_score)) |>
|
| 148 |
+
slice_head(n = 25) |>
|
| 149 |
+
summarise(sum(responsive) / n()) |>
|
| 150 |
+
pull()
|
| 151 |
+
}),
|
| 152 |
+
rr_max = map_dbl(data, ~ {
|
| 153 |
+
.x |>
|
| 154 |
+
arrange(desc(max_score)) |>
|
| 155 |
+
slice_head(n = 25) |>
|
| 156 |
+
summarise(sum(responsive) / n()) |>
|
| 157 |
+
pull()
|
| 158 |
+
}),
|
| 159 |
+
rr_median = map_dbl(data, ~ {
|
| 160 |
+
.x |>
|
| 161 |
+
arrange(desc(median_score)) |>
|
| 162 |
+
slice_head(n = 25) |>
|
| 163 |
+
summarise(sum(responsive) / n()) |>
|
| 164 |
+
pull()
|
| 165 |
+
})
|
| 166 |
+
) |>
|
| 167 |
+
dplyr::select(-data) |>
|
| 168 |
+
pivot_longer(
|
| 169 |
+
cols = starts_with("rr_"),
|
| 170 |
+
names_to = "score_type",
|
| 171 |
+
values_to = "rr"
|
| 172 |
+
) |>
|
| 173 |
+
ggplot(aes(x = score_type, y = rr)) +
|
| 174 |
+
geom_boxplot()
|
| 175 |
+
|
| 176 |
+
library(patchwork)
|
| 177 |
+
library(gridExtra)
|
| 178 |
+
|
| 179 |
+
score_summary <- peaks_with_mcisaac |>
|
| 180 |
+
filter(time == 30) |>
|
| 181 |
+
group_by(regulator_locus_tag) |>
|
| 182 |
+
reframe(
|
| 183 |
+
score_type = c("nearest", "max", "median"),
|
| 184 |
+
n_targets = c(
|
| 185 |
+
n_distinct(target_locus_tag),
|
| 186 |
+
n_distinct(target_locus_tag),
|
| 187 |
+
n_distinct(target_locus_tag)
|
| 188 |
+
),
|
| 189 |
+
n_peaks = c(n(), n(), n()),
|
| 190 |
+
min = c(min(nearest_score), min(max_score), min(median_score)),
|
| 191 |
+
max = c(max(nearest_score), max(max_score), max(median_score)),
|
| 192 |
+
median = c(median(nearest_score), median(max_score), median(median_score)),
|
| 193 |
+
mean = c(mean(nearest_score), mean(max_score), mean(median_score))
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
p1 <- score_summary |>
|
| 198 |
+
ggplot(aes(x = score_type, y = mean, fill = score_type)) +
|
| 199 |
+
geom_boxplot(alpha = 0.7) +
|
| 200 |
+
labs(title = "Mean Score Distribution", y = "Mean Score", x = "") +
|
| 201 |
+
theme_minimal() +
|
| 202 |
+
theme(legend.position = "none")
|
| 203 |
+
|
| 204 |
+
p3 <- score_summary |>
|
| 205 |
+
ggplot(aes(x = n_targets, y = mean, color = score_type)) +
|
| 206 |
+
geom_point(alpha = 0.6) +
|
| 207 |
+
facet_wrap(~score_type) +
|
| 208 |
+
scale_x_log10() +
|
| 209 |
+
labs(title = "Number of Targets vs Mean Score", x = "N Targets (log10)", y = "Mean") +
|
| 210 |
+
theme_minimal() +
|
| 211 |
+
theme(legend.position = "none")
|
| 212 |
+
|
| 213 |
+
# Calculate stats for table
|
| 214 |
+
n_targets_summary <- score_summary |>
|
| 215 |
+
dplyr::select(n_targets) |>
|
| 216 |
+
distinct() |>
|
| 217 |
+
pull(n_targets) %>%
|
| 218 |
+
{
|
| 219 |
+
tibble(
|
| 220 |
+
Min = round(quantile(., probs = 0), 2),
|
| 221 |
+
Q25 = round(quantile(., probs = 0.25), 2),
|
| 222 |
+
Median = round(quantile(., probs = 0.5), 2),
|
| 223 |
+
Q75 = round(quantile(., probs = 0.75), 2),
|
| 224 |
+
Max = round(quantile(., probs = 1), 2)
|
| 225 |
+
)
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
# Vertical boxplot
|
| 229 |
+
p4_plot <- score_summary |>
|
| 230 |
+
dplyr::select(regulator_locus_tag, n_targets) |>
|
| 231 |
+
distinct() |>
|
| 232 |
+
ggplot(aes(x = "", y = n_targets)) +
|
| 233 |
+
geom_boxplot(width = 0.3) +
|
| 234 |
+
scale_y_log10() +
|
| 235 |
+
labs(title = "Distribution of Targets per Regulator", y = "N Targets (log10)", x = "") +
|
| 236 |
+
theme_minimal() +
|
| 237 |
+
theme(legend.position = "none")
|
| 238 |
+
|
| 239 |
+
# Summary table
|
| 240 |
+
p4_table <- gridExtra::tableGrob(n_targets_summary,
|
| 241 |
+
rows = NULL,
|
| 242 |
+
theme = ttheme_minimal(base_size = 10)
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
(p1 + p3) / (p4_plot + p4_table)
|
| 246 |
+
|
| 247 |
+
authors_orig_peaks <- arrow::read_parquet("~/projects/huggingface/rossi_2021/yep_filtered_peaks.parquet") |>
|
| 248 |
+
mutate(yeastepigenome_id = as.integer(yeastepigenome_id))
|
| 249 |
+
authors_orig_peaks_meta <- arrow::read_parquet("~/projects/huggingface/rossi_2021/rossi_2021_metadata.parquet")
|
| 250 |
+
|
| 251 |
+
authors_orig_peaks_normal_conds <- authors_orig_peaks |>
|
| 252 |
+
left_join(authors_orig_peaks_meta) |>
|
| 253 |
+
filter(treatment == "Normal", growth_media == "YPD")
|
| 254 |
+
|
| 255 |
+
find_nearest_peaks <- function(macs_peaks, yep_chexmix_peaks, chrmap) {
|
| 256 |
+
library(GenomicRanges)
|
| 257 |
+
# Prepare MACS peaks (convert chr names)
|
| 258 |
+
macs_gr <- macs_peaks |>
|
| 259 |
+
left_join(chrmap |> dplyr::select(ucsc, chr)) |>
|
| 260 |
+
dplyr::select(-chr) |>
|
| 261 |
+
dplyr::rename(seqnames = ucsc) |>
|
| 262 |
+
filter(!is.na(seqnames)) |>
|
| 263 |
+
dplyr::select(seqnames, start, end, macs_score = peak_score) |>
|
| 264 |
+
GRanges()
|
| 265 |
+
|
| 266 |
+
# Prepare YEP ChExMix peaks (convert chr names)
|
| 267 |
+
yep_gr <- yep_chexmix_peaks |>
|
| 268 |
+
dplyr::select(seqnames = chr, start, end, yeastepigenome_id, yep_score = score) |>
|
| 269 |
+
GRanges()
|
| 270 |
+
|
| 271 |
+
# Find nearest neighbors
|
| 272 |
+
hits <- distanceToNearest(yep_gr, macs_gr)
|
| 273 |
+
|
| 274 |
+
# Add results back to YEP peaks
|
| 275 |
+
yep_with_nearest <- yep_chexmix_peaks |>
|
| 276 |
+
mutate(
|
| 277 |
+
query_idx = 1:n(),
|
| 278 |
+
subject_idx = subjectHits(hits),
|
| 279 |
+
distance = mcols(hits)$distance
|
| 280 |
+
) |>
|
| 281 |
+
left_join(
|
| 282 |
+
macs_peaks |>
|
| 283 |
+
mutate(subject_idx = 1:n()) |>
|
| 284 |
+
dplyr::select(subject_idx, macs_score = peak_score, nearest_promoter_id),
|
| 285 |
+
by = "subject_idx"
|
| 286 |
+
) |>
|
| 287 |
+
mutate(
|
| 288 |
+
macs_score_percentile = percent_rank(macs_score)
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
return(yep_with_nearest)
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
chrmap <- read_csv("~/projects/huggingface/yeast_genome_resources/chrmap.csv.gz")
|
| 295 |
+
|
| 296 |
+
# Usage:
|
| 297 |
+
authors_with_nearest <- find_nearest_peaks(
|
| 298 |
+
annotated_peaks$df$YJR060W_CBF1_Normal_YPD,
|
| 299 |
+
authors_orig_peaks_normal_conds |> filter(regulator_symbol == "CBF1"),
|
| 300 |
+
chrmap
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
norm_cond_reg_syms <- intersect(
|
| 304 |
+
str_extract(names(compact(annotated_peaks$df))[str_detect(names(compact(annotated_peaks$df)), "Normal")], "(?<=_)[^_]+(?=_)"),
|
| 305 |
+
unique(authors_orig_peaks_normal_conds$regulator_symbol)
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
results <- map(norm_cond_reg_syms, ~ {
|
| 310 |
+
yep_df <- filter(authors_orig_peaks_normal_conds, regulator_symbol == .x)
|
| 311 |
+
rlt <- unique(yep_df$regulator_locus_tag)
|
| 312 |
+
macs_df <- annotated_peaks$df[[paste(rlt, .x, "Normal_YPD", sep = "_")]] |>
|
| 313 |
+
filter(peak_score > -log10(0.05))
|
| 314 |
+
|
| 315 |
+
find_nearest_peaks(
|
| 316 |
+
macs_df,
|
| 317 |
+
yep_df,
|
| 318 |
+
chrmap
|
| 319 |
+
)
|
| 320 |
+
})
|
| 321 |
+
|
| 322 |
+
names(results) <- norm_cond_reg_syms
|
| 323 |
+
results_df <- bind_rows(results)
|
| 324 |
+
|
| 325 |
+
summary(results_df$macs_score_percentile)
|
yep_filtered_peaks.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5827b4bc79da5efdd878be32eeda371e129d2091613d7cf76fc985b97ae2beec
|
| 3 |
+
size 3618047
|