cmatkhan commited on
Commit
1cecd8c
·
1 Parent(s): 15204a1

adding additional promoters

Browse files
README.md CHANGED
@@ -57,7 +57,40 @@ You can find these by clicking on the [files and versions](https://huggingface.c
57
  - **chrmap** (csv): This file provides a mapping between chromosome names between, eg
58
  UCSC, ensembl, etc.
59
 
60
- ## Usage
61
 
62
- Currently, we expect that this will be used for its raw files, eg by downloading a given
63
- file and opening it in your favorite program.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  - **chrmap** (csv): This file provides a mapping between chromosome names between, eg
58
  UCSC, ensembl, etc.
59
 
60
+ ## Accessing Data
61
 
62
+ The examples below require the
63
+ [HuggingFace Hub client](https://huggingface.co/docs/huggingface_hub/installation)
64
+ (`pip install huggingface_hub`).
65
+
66
+ Currently, we expect that this will be used for its raw files. Download
67
+ individual files and open them in your preferred tool.
68
+
69
+ ### Direct parquet access
70
+
71
+ ```python
72
+ from huggingface_hub import snapshot_download
73
+ import duckdb
74
+
75
+ repo_path = snapshot_download(
76
+ repo_id="BrentLab/yeast_genome_resources",
77
+ repo_type="dataset",
78
+ allow_patterns="brentlab_features.parquet",
79
+ )
80
+ conn = duckdb.connect()
81
+ # returns a pandas DataFrame with the first 5 rows
82
+ conn.execute(
83
+ "SELECT * FROM read_parquet(?) LIMIT 5",
84
+ [f"{repo_path}/brentlab_features.parquet"],
85
+ ).df()
86
+ ```
87
+
88
+ ### Accessing using R
89
+
90
+ Clone the repository and read parquet files directly with
91
+ [arrow](https://arrow.apache.org/docs/r/):
92
+
93
+ ```r
94
+ # install.packages("arrow")
95
+ arrow::read_parquet("brentlab_features.parquet")
96
+ ```
scripts/create_promoter_bed_from_mindel.R CHANGED
@@ -154,4 +154,4 @@ promoter_coordinates_final = promoter_coordinates_df %>%
154
  strand, promoter_sequence,
155
  in_mahendrawada_features, promoter_exact_aligns)
156
 
157
- write_csv(promoter_coordinates_final, "~/code/hf/yeast_genome_resources/mindel_promoters.csv.gz")
 
154
  strand, promoter_sequence,
155
  in_mahendrawada_features, promoter_exact_aligns)
156
 
157
+ # write_csv(promoter_coordinates_final, "~/code/hf/yeast_genome_resources/mindel_promoters.csv.gz")
scripts/create_promoter_regions.R CHANGED
@@ -6,6 +6,7 @@ library(BSgenome.Scerevisiae.UCSC.sacCer3)
6
  # half open. GRanges parses and represents the interval differently than what is
7
  # in the actual file
8
  tss_list = list(
 
9
  gal = rtracklayer::import("~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1_verified_orf.bed"),
10
  ypd = rtracklayer::import("~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1_verified_orf.bed"),
11
  median = rtracklayer::import("~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1_verified_orf.bed")
@@ -13,6 +14,7 @@ tss_list = list(
13
 
14
  # Fix: need to assign the result back and return the modified object
15
  tss_list = map(tss_list, ~{
 
16
  seqinfo(.x) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3)
17
  .x # Return the modified GRanges object
18
  })
@@ -40,8 +42,8 @@ seqinfo(intergenic_regions_sgd) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3)
40
  #' to include in the promoter region. Default is 50.
41
  #'
42
  #' @return A GRanges object containing the promoter regions with preserved strand
43
- #' information. If \code{intergenic_gr} is provided, promoters are truncated to
44
- #' only the portions overlapping intergenic regions. Promoters with no intergenic
45
  #' overlap are excluded.
46
  #'
47
  #' @details
@@ -61,56 +63,59 @@ seqinfo(intergenic_regions_sgd) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3)
61
  #'
62
  #' # Get only intergenic promoters
63
  #' promoters_intergenic <- get_promoter_regions(
64
- #' tss_gr,
65
  #' intergenic_gr = intergenic_regions,
66
- #' upstream = 500,
67
  #' downstream = 50
68
  #' )
69
  #' }
70
  get_promoter_regions = function(tss_gr, intergenic_gr, upstream = 500, downstream = 50){
71
  # Validate inputs
72
  stopifnot(
73
- "upstream must be a positive number" = upstream > 0,
74
- "downstream must be a positive number" = downstream > 0,
75
- "tss_gr must have seqinfo set for trimming" =
76
  !is.null(seqinfo(tss_gr)) && length(seqinfo(tss_gr)) > 0
77
  )
78
-
79
  pr_regions = GenomicRanges::trim(
80
  GenomicRanges::promoters(
81
  tss_gr,
82
  upstream = upstream,
83
  downstream = downstream,
84
  use.names = TRUE))
85
-
86
  # Optionally restrict to intergenic regions
87
  if (!missing(intergenic_gr)) {
88
  # Find which intergenic region contains each TSS
89
- tss_to_intergenic <- GenomicRanges::findOverlaps(tss_gr, intergenic_gr,
90
  type = "within",
91
  ignore.strand = TRUE,
92
  select = "first")
93
-
94
  # Keep only promoters whose TSS is in an intergenic region
95
  has_intergenic <- !is.na(tss_to_intergenic)
96
  pr_regions <- pr_regions[has_intergenic]
97
  intergenic_match <- intergenic_gr[tss_to_intergenic[has_intergenic]]
98
-
99
  # Manually clip to intergenic boundaries
100
  new_starts <- IRanges::pmax(GenomicRanges::start(pr_regions),
101
  GenomicRanges::start(intergenic_match))
102
  new_ends <- IRanges::pmin(GenomicRanges::end(pr_regions),
103
  GenomicRanges::end(intergenic_match))
104
-
105
  GenomicRanges::ranges(pr_regions) <- IRanges::IRanges(start = new_starts, end = new_ends)
106
  }
107
-
108
  pr_regions
109
  }
110
 
111
  # example, the first truncating by intergenic regions, the second not
112
- promoters_500_50_intergenic = map(tss_list, get_promoter_regions, intergenic_regions_sgd)
113
- promoters_500_50 = map(tss_list, get_promoter_regions)
114
-
115
 
 
 
 
 
116
 
 
6
  # half open. GRanges parses and represents the interval differently than what is
7
  # in the actual file
8
  tss_list = list(
9
+ start_codon = rtracklayer::import("~/code/hf/yeast_genome_resources/start_codon_verified_orf.bed"),
10
  gal = rtracklayer::import("~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1_verified_orf.bed"),
11
  ypd = rtracklayer::import("~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1_verified_orf.bed"),
12
  median = rtracklayer::import("~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1_verified_orf.bed")
 
14
 
15
  # Fix: need to assign the result back and return the modified object
16
  tss_list = map(tss_list, ~{
17
+ seqlevels(.x) <- seqlevels(BSgenome.Scerevisiae.UCSC.sacCer3)
18
  seqinfo(.x) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3)
19
  .x # Return the modified GRanges object
20
  })
 
42
  #' to include in the promoter region. Default is 50.
43
  #'
44
  #' @return A GRanges object containing the promoter regions with preserved strand
45
+ #' information. If \code{intergenic_gr} is provided, promoters are truncated to
46
+ #' only the portions overlapping intergenic regions. Promoters with no intergenic
47
  #' overlap are excluded.
48
  #'
49
  #' @details
 
63
  #'
64
  #' # Get only intergenic promoters
65
  #' promoters_intergenic <- get_promoter_regions(
66
+ #' tss_gr,
67
  #' intergenic_gr = intergenic_regions,
68
+ #' upstream = 500,
69
  #' downstream = 50
70
  #' )
71
  #' }
72
  get_promoter_regions = function(tss_gr, intergenic_gr, upstream = 500, downstream = 50){
73
  # Validate inputs
74
  stopifnot(
75
+ "upstream must be a positive number" = upstream >= 0,
76
+ "downstream must be a positive number" = downstream >= 0,
77
+ "tss_gr must have seqinfo set for trimming" =
78
  !is.null(seqinfo(tss_gr)) && length(seqinfo(tss_gr)) > 0
79
  )
80
+
81
  pr_regions = GenomicRanges::trim(
82
  GenomicRanges::promoters(
83
  tss_gr,
84
  upstream = upstream,
85
  downstream = downstream,
86
  use.names = TRUE))
87
+
88
  # Optionally restrict to intergenic regions
89
  if (!missing(intergenic_gr)) {
90
  # Find which intergenic region contains each TSS
91
+ tss_to_intergenic <- GenomicRanges::findOverlaps(tss_gr, intergenic_gr,
92
  type = "within",
93
  ignore.strand = TRUE,
94
  select = "first")
95
+
96
  # Keep only promoters whose TSS is in an intergenic region
97
  has_intergenic <- !is.na(tss_to_intergenic)
98
  pr_regions <- pr_regions[has_intergenic]
99
  intergenic_match <- intergenic_gr[tss_to_intergenic[has_intergenic]]
100
+
101
  # Manually clip to intergenic boundaries
102
  new_starts <- IRanges::pmax(GenomicRanges::start(pr_regions),
103
  GenomicRanges::start(intergenic_match))
104
  new_ends <- IRanges::pmin(GenomicRanges::end(pr_regions),
105
  GenomicRanges::end(intergenic_match))
106
+
107
  GenomicRanges::ranges(pr_regions) <- IRanges::IRanges(start = new_starts, end = new_ends)
108
  }
109
+
110
  pr_regions
111
  }
112
 
113
  # example, the first truncating by intergenic regions, the second not
114
+ # promoters_500_50_intergenic = map(tss_list, get_promoter_regions, intergenic_regions_sgd)
115
+ # promoters_500_50 = map(tss_list, get_promoter_regions)
 
116
 
117
+ # promoters_start_codons_500bp = get_promoter_regions(tss_list$start_codon, upstream=500, downstream=0)
118
+ # promoters_start_codons_500bp <- promoters_start_codons_500bp[width(promoters_start_codons_500bp) == 500]
119
+ # rtracklayer::export(promoters_start_codons_500bp,
120
+ # "~/code/hf/yeast_genome_resources/start_codon_500bp_upstream_promoters.bed")
121
 
scripts/create_tss_files.R CHANGED
@@ -3,12 +3,12 @@ library(BSgenome.Scerevisiae.UCSC.sacCer3)
3
  library(rtracklayer)
4
 
5
  gff = rtracklayer::import("~/ref/sacCer3/S288C_reference_genome_R64-5-1_20240529/saccharomyces_cerevisiae_R64-5-1_20240529_chr_normalized.gtf")
6
-
7
- gff_with_conditions = gff %>%
8
- as_tibble() %>%
9
- select(seqnames, start, end, strand, type, Name, conditions) %>%
10
- filter(type %in% c("gene", "mRNA", "CDS")) %>%
11
- mutate(locus_tag = str_remove(Name, "_.*")) %>%
12
  replace_na(list(conditions = "none"))
13
 
14
  gff_with_conditions_tss <- gff_with_conditions %>%
@@ -53,12 +53,12 @@ gff_with_conditions_tss <- gff_with_conditions %>%
53
  mutate(five_utr_width = abs(cds_start-tss)) %>%
54
  mutate(source = "sgd-5-1")
55
 
56
- orf_classifications_tmp = gff %>%
57
- as_tibble() %>%
58
  filter(type == "gene", !is.na(orf_classification)) %>%
59
  select(Name, orf_classification) %>%
60
  dplyr::rename(locus_tag = Name)
61
-
62
  orf_classifications_complete = orf_classifications_tmp %>%
63
  bind_rows(
64
  # the na orf_classifications
@@ -77,7 +77,7 @@ orf_classifications_complete = orf_classifications_tmp %>%
77
 
78
  gff_with_conditions_tss_complete_orf_classification = gff_with_conditions_tss %>%
79
  left_join(orf_classifications_complete)
80
-
81
 
82
  create_condition_specific_tss = function(df, sel_cond){
83
  gr = makeGRangesFromDataFrame(
@@ -89,7 +89,7 @@ create_condition_specific_tss = function(df, sel_cond){
89
  start.field = "tss",
90
  end.field = "tss",
91
  strand.field = "strand")
92
-
93
  suppressWarnings(seqinfo(gr) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3))
94
  message("trimming in order to avoid out of bounds locations on inferred TSS")
95
  trim(gr)
@@ -111,12 +111,22 @@ tss_gr_list = list(
111
  "median_utr_across_conds")
112
  )
113
 
114
- rtracklayer::export(tss_gr_list$ypd, "~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1.bed")
115
- rtracklayer::export(tss_gr_list$gal, "~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1.bed")
116
- rtracklayer::export(tss_gr_list$median_across_conds_tss_gr, "~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1.bed")
117
-
118
- rtracklayer::export(tss_gr_list$ypd[tss_gr_list$ypd$orf_classification=="Verified"], "~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1_verified_orf.bed")
119
-
120
- rtracklayer::export(tss_gr_list$gal[tss_gr_list$gal$orf_classification=="Verified"], "~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1_verified_orf.bed")
121
-
122
- rtracklayer::export(tss_gr_list$median_across_conds_tss_gr[tss_gr_list$median_across_conds_tss_gr$orf_classification=="Verified"], "~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1_verified_orf.bed")
 
 
 
 
 
 
 
 
 
 
 
3
  library(rtracklayer)
4
 
5
  gff = rtracklayer::import("~/ref/sacCer3/S288C_reference_genome_R64-5-1_20240529/saccharomyces_cerevisiae_R64-5-1_20240529_chr_normalized.gtf")
6
+
7
+ gff_with_conditions = gff %>%
8
+ as_tibble() %>%
9
+ select(seqnames, start, end, strand, type, Name, conditions) %>%
10
+ filter(type %in% c("gene", "mRNA", "CDS")) %>%
11
+ mutate(locus_tag = str_remove(Name, "_.*")) %>%
12
  replace_na(list(conditions = "none"))
13
 
14
  gff_with_conditions_tss <- gff_with_conditions %>%
 
53
  mutate(five_utr_width = abs(cds_start-tss)) %>%
54
  mutate(source = "sgd-5-1")
55
 
56
+ orf_classifications_tmp = gff %>%
57
+ as_tibble() %>%
58
  filter(type == "gene", !is.na(orf_classification)) %>%
59
  select(Name, orf_classification) %>%
60
  dplyr::rename(locus_tag = Name)
61
+
62
  orf_classifications_complete = orf_classifications_tmp %>%
63
  bind_rows(
64
  # the na orf_classifications
 
77
 
78
  gff_with_conditions_tss_complete_orf_classification = gff_with_conditions_tss %>%
79
  left_join(orf_classifications_complete)
80
+
81
 
82
  create_condition_specific_tss = function(df, sel_cond){
83
  gr = makeGRangesFromDataFrame(
 
89
  start.field = "tss",
90
  end.field = "tss",
91
  strand.field = "strand")
92
+
93
  suppressWarnings(seqinfo(gr) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3))
94
  message("trimming in order to avoid out of bounds locations on inferred TSS")
95
  trim(gr)
 
111
  "median_utr_across_conds")
112
  )
113
 
114
+ # create the ORF start cocon locations
115
+ # read_csv("~/code/hf/yeast_genome_resources/brentlab_features.csv.gz") |>
116
+ # filter(type == 'gene', str_detect(note, regex("dubious", ignore_case=TRUE), negate=TRUE)) |>
117
+ # mutate(orf = ifelse(strand == "-", end, start)) |>
118
+ # mutate(score = 100) |>
119
+ # dplyr::select(seqnames=chr, start=orf, end = orf, name=locus_tag, score, strand) |>
120
+ # GenomicRanges::GRanges() |>
121
+ # rtracklayer::export("~/code/hf/yeast_genome_resources/start_codon_verified_orf.bed")
122
+ #
123
+ #
124
+ # rtracklayer::export(tss_gr_list$ypd, "~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1.bed")
125
+ # rtracklayer::export(tss_gr_list$gal, "~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1.bed")
126
+ # rtracklayer::export(tss_gr_list$median_across_conds_tss_gr, "~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1.bed")
127
+ #
128
+ # rtracklayer::export(tss_gr_list$ypd[tss_gr_list$ypd$orf_classification=="Verified"], "~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1_verified_orf.bed")
129
+ #
130
+ # rtracklayer::export(tss_gr_list$gal[tss_gr_list$gal$orf_classification=="Verified"], "~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1_verified_orf.bed")
131
+ #
132
+ # rtracklayer::export(tss_gr_list$median_across_conds_tss_gr[tss_gr_list$median_across_conds_tss_gr$orf_classification=="Verified"], "~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1_verified_orf.bed")
scripts/get_promoter_seqs.R ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(GenomicRanges)
2
+ library(rtracklayer)
3
+ library(BSgenome)
4
+ library(BSgenome.Scerevisiae.UCSC.sacCer3)
5
+ library(tidyverse)
6
+
7
+ saccer3 <- BSgenome.Scerevisiae.UCSC.sacCer3
8
+
9
+ promoters <- rtracklayer::import("~/code/hf/yeast_genome_resources/yiming_promoters.bed")
10
+ promoters_unique <- promoters[!duplicated(paste(seqnames(promoters), start(promoters), end(promoters), strand(promoters)))]
11
+ promoter_seqs <- BSgenome::getSeq(saccer3, promoters_unique)
12
+
13
+ # Genome-wide base frequencies (all nuclear chromosomes, both strands balanced so +/- cancel)
14
+ genome_seqs <- BSgenome::getSeq(saccer3, seqnames(saccer3))
15
+ genome_freq <- Biostrings::alphabetFrequency(genome_seqs, as.prob = FALSE)
16
+ genome_freq_acgt <- colSums(genome_freq[, c("A", "C", "G", "T")])
17
+ genome_prop <- genome_freq_acgt / sum(genome_freq_acgt)
18
+
19
+ genome_df <- tibble(
20
+ basepair = names(genome_prop),
21
+ freq = genome_prop
22
+ )
23
+
24
+ # Promoter position frequency matrix
25
+ cm <- Biostrings::consensusMatrix(promoter_seqs)
26
+ pm <- prop.table(cm, margin = 2)
27
+ pm_acgt <- pm[c("A", "C", "G", "T"), ]
28
+
29
+ pm_acgt %>%
30
+ as_tibble(rownames = "basepair") %>%
31
+ pivot_longer(-basepair) %>%
32
+ mutate(name = as.numeric(str_remove(name, "V"))) %>%
33
+ filter(name <= 700) %>%
34
+ left_join(genome_df, by = "basepair") %>%
35
+ ggplot(aes(color = basepair)) +
36
+ geom_line(aes(name, value)) +
37
+ geom_hline(
38
+ data = genome_df,
39
+ aes(yintercept = freq, color = basepair),
40
+ linetype = "dashed"
41
+ ) +
42
+ labs(x = "position", y = "proportion")
start_codon_500bp_upstream_promoters.bed ADDED
The diff for this file is too large to render. See raw diff
 
start_codon_verified_orf.bed ADDED
The diff for this file is too large to render. See raw diff