|
|
library(tidyverse) |
|
|
library(BSgenome.Scerevisiae.UCSC.sacCer3) |
|
|
library(rtracklayer) |
|
|
|
|
|
gff = rtracklayer::import("~/ref/sacCer3/S288C_reference_genome_R64-5-1_20240529/saccharomyces_cerevisiae_R64-5-1_20240529_chr_normalized.gtf") |
|
|
|
|
|
gff_with_conditions = gff %>% |
|
|
as_tibble() %>% |
|
|
select(seqnames, start, end, strand, type, Name, conditions) %>% |
|
|
filter(type %in% c("gene", "mRNA", "CDS")) %>% |
|
|
mutate(locus_tag = str_remove(Name, "_.*")) %>% |
|
|
replace_na(list(conditions = "none")) |
|
|
|
|
|
gff_with_conditions_tss <- gff_with_conditions %>% |
|
|
filter(seqnames != "chrM") %>% |
|
|
mutate(fiveprime_loc = ifelse(strand == "+", start, end)) %>% |
|
|
group_by(locus_tag) %>% |
|
|
reframe( |
|
|
seqnames = unique(seqnames), |
|
|
strand = unique(strand), |
|
|
cds_start = ifelse( |
|
|
any(type == "CDS"), |
|
|
ifelse( |
|
|
unique(strand) == "+", |
|
|
min(start[type == "CDS"], na.rm = TRUE), |
|
|
max(end[type == "CDS"], na.rm = TRUE) |
|
|
), |
|
|
NA_integer_ |
|
|
), |
|
|
tss_ypd = ifelse( |
|
|
any(type == "mRNA" & conditions == "YPD"), |
|
|
fiveprime_loc[type == "mRNA" & conditions == "YPD"][1], |
|
|
NA_integer_ |
|
|
), |
|
|
tss_gal = ifelse( |
|
|
any(type == "mRNA" & conditions == "GAL"), |
|
|
fiveprime_loc[type == "mRNA" & conditions == "GAL"][1], |
|
|
NA_integer_ |
|
|
) |
|
|
) %>% |
|
|
pivot_longer(-c(locus_tag, seqnames, strand, cds_start), names_to = "conditions", values_to = "tss") %>% |
|
|
mutate(inferred = is.na(tss), |
|
|
five_utr_width = abs(cds_start-tss)) %>% |
|
|
mutate(avg_5utr_width_across_conds = median(five_utr_width, na.rm=TRUE)) %>% |
|
|
group_by(conditions) %>% |
|
|
mutate(avg_5utr_width_in_conds = median(five_utr_width, na.rm=TRUE)) %>% |
|
|
mutate(tss = case_when( |
|
|
is.na(tss) & strand == "+" ~ cds_start - avg_5utr_width_in_conds, |
|
|
is.na(tss) & strand == "-" ~ cds_start + avg_5utr_width_in_conds, |
|
|
.default = tss |
|
|
)) %>% |
|
|
ungroup() %>% |
|
|
mutate(five_utr_width = abs(cds_start-tss)) %>% |
|
|
mutate(source = "sgd-5-1") |
|
|
|
|
|
orf_classifications_tmp = gff %>% |
|
|
as_tibble() %>% |
|
|
filter(type == "gene", !is.na(orf_classification)) %>% |
|
|
select(Name, orf_classification) %>% |
|
|
dplyr::rename(locus_tag = Name) |
|
|
|
|
|
orf_classifications_complete = orf_classifications_tmp %>% |
|
|
bind_rows( |
|
|
|
|
|
gff_with_conditions_tss %>% |
|
|
select(locus_tag) %>% |
|
|
distinct() %>% |
|
|
filter(!locus_tag %in% orf_classifications_tmp$locus_tag) %>% |
|
|
select(locus_tag) %>% |
|
|
left_join( |
|
|
gff %>% |
|
|
as_tibble() %>% |
|
|
filter(type %in% c("transposable_element_gene", "blocked_reading_frame")) %>% |
|
|
select(ID, type, display), by = c("locus_tag" = "ID")) %>% |
|
|
select(locus_tag, type) %>% dplyr::rename(orf_classification = type) |
|
|
) |
|
|
|
|
|
gff_with_conditions_tss_complete_orf_classification = gff_with_conditions_tss %>% |
|
|
left_join(orf_classifications_complete) |
|
|
|
|
|
|
|
|
create_condition_specific_tss = function(df, sel_cond){ |
|
|
gr = makeGRangesFromDataFrame( |
|
|
df %>% |
|
|
filter(conditions == sel_cond) %>% |
|
|
dplyr::rename(name = locus_tag), |
|
|
keep.extra.columns = TRUE, |
|
|
seqnames.field = "seqnames", |
|
|
start.field = "tss", |
|
|
end.field = "tss", |
|
|
strand.field = "strand") |
|
|
|
|
|
suppressWarnings(seqinfo(gr) <- seqinfo(BSgenome.Scerevisiae.UCSC.sacCer3)) |
|
|
message("trimming in order to avoid out of bounds locations on inferred TSS") |
|
|
trim(gr) |
|
|
} |
|
|
|
|
|
median_across_conds_tss = gff_with_conditions_tss_complete_orf_classification %>% |
|
|
select(locus_tag, seqnames, orf_classification, |
|
|
strand, cds_start, avg_5utr_width_across_conds) %>% |
|
|
distinct() %>% |
|
|
mutate(tss = ifelse(strand == "+", |
|
|
cds_start - avg_5utr_width_across_conds, |
|
|
cds_start + avg_5utr_width_across_conds)) %>% |
|
|
mutate(conditions = "median_utr_across_conds") |
|
|
|
|
|
tss_gr_list = list( |
|
|
ypd = create_condition_specific_tss(gff_with_conditions_tss_complete_orf_classification, "tss_ypd"), |
|
|
gal = create_condition_specific_tss(gff_with_conditions_tss_complete_orf_classification, "tss_gal"), |
|
|
median_across_conds_tss_gr = create_condition_specific_tss(median_across_conds_tss, |
|
|
"median_utr_across_conds") |
|
|
) |
|
|
|
|
|
rtracklayer::export(tss_gr_list$ypd, "~/code/hf/yeast_genome_resources/ypd_tss_sgd-5-1.bed") |
|
|
rtracklayer::export(tss_gr_list$gal, "~/code/hf/yeast_genome_resources/gal_tss_sgd-5-1.bed") |
|
|
rtracklayer::export(tss_gr_list$median_across_conds_tss_gr, "~/code/hf/yeast_genome_resources/median_across_conds_tss_sgd-5-1.bed") |
|
|
|
|
|
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") |
|
|
|
|
|
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") |
|
|
|
|
|
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") |
|
|
|