Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ALPS
Title: AnaLysis routines for ePigenomicS data
Version: 0.99.9
Version: 0.100.1
Author: Venu Thatikonda, Natalie Jäger
Maintainer: Venu Thatikonda <thatikonda92@gmail.com>
Description: The package provides analysis and publication quality visualization routines for genome-wide
Expand All @@ -12,7 +12,7 @@ Description: The package provides analysis and publication quality visualization
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: false
RoxygenNote: 6.1.1
RoxygenNote: 7.2.3
Depends: R (>= 3.6)
Imports:
assertthat,
Expand All @@ -39,6 +39,7 @@ Imports:
tidyr,
TxDb.Hsapiens.UCSC.hg19.knownGene,
TxDb.Hsapiens.UCSC.hg38.knownGene,
TxDb.Mmusculus.UCSC.mm10.knownGene,
utils
URL: https://github.com/itsvenu/ALPS
BugReports: https://github.com/itsvenu/ALPS/issues
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(process_transfac)
import(corrplot)
import(ggplot2)
import(org.Hs.eg.db)
importFrom(AnnotationDbi,mapIds)
importFrom(BiocParallel,bplapply)
importFrom(ChIPseeker,annotatePeak)
importFrom(GGally,ggpairs)
Expand All @@ -26,8 +27,10 @@ importFrom(GenomicRanges,reduce)
importFrom(Gviz,DataTrack)
importFrom(Gviz,GeneRegionTrack)
importFrom(Gviz,plotTracks)
importFrom(IRanges,ranges)
importFrom(TxDb.Hsapiens.UCSC.hg19.knownGene,TxDb.Hsapiens.UCSC.hg19.knownGene)
importFrom(TxDb.Hsapiens.UCSC.hg38.knownGene,TxDb.Hsapiens.UCSC.hg38.knownGene)
importFrom(TxDb.Mmusculus.UCSC.mm10.knownGene,TxDb.Mmusculus.UCSC.mm10.knownGene)
importFrom(data.table,dcast)
importFrom(data.table,fread)
importFrom(dplyr,filter)
Expand All @@ -42,6 +45,8 @@ importFrom(genefilter,rowVars)
importFrom(gghalves,geom_half_violin)
importFrom(ggseqlogo,ggseqlogo)
importFrom(magrittr,"%>%")
importFrom(org.Hs.eg.db,org.Hs.eg.db)
importFrom(org.Mm.eg.db,org.Mm.eg.db)
importFrom(reshape2,melt)
importFrom(rtracklayer,BigWigFileList)
importFrom(rtracklayer,summary)
Expand Down
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
VERSION 0.100.0
--------------
* Added support for mm10

VERSION 0.99.8
--------------
* Bioc review fixes
Expand All @@ -9,4 +13,3 @@ VERSION 0.99.7
VERSION 0.99.0
--------------
* FIRST RELEASE

7 changes: 4 additions & 3 deletions R/get_genomic_annotations.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ merge_GR <- function(x) {
#'
#' @param data_table a data.frame of sample table, as is for
#' \code{multiBigwig_summary} input table, default NULL
#' @param ref_gen reference genome, either \code{hg38 or hg19},
#' @param ref_gen reference genome, either \code{hg38, mm10 or hg19},
#' default \code{hg38}
#' @param tss_region bp ± TSS to define promoter regions
#' @param merge_level either \code{all, group_level} or \code{none}.
Expand All @@ -71,6 +71,7 @@ merge_GR <- function(x) {
#'
#' @importFrom TxDb.Hsapiens.UCSC.hg38.knownGene TxDb.Hsapiens.UCSC.hg38.knownGene
#' @importFrom TxDb.Hsapiens.UCSC.hg19.knownGene TxDb.Hsapiens.UCSC.hg19.knownGene
#' @importFrom TxDb.Mmusculus.UCSC.mm10.knownGene TxDb.Mmusculus.UCSC.mm10.knownGene
#' @importFrom dplyr filter pull
#' @importFrom ChIPseeker annotatePeak
#' @importFrom data.table dcast
Expand Down Expand Up @@ -100,10 +101,10 @@ get_genomic_annotations <- function(data_table,

## check ref_gen
if (ref_gen == "hg38") {

txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene::TxDb.Hsapiens.UCSC.hg38.knownGene
} else if (ref_gen == "mm10") {
txdb <- TxDb.Mmusculus.UCSC.mm10.knownGene::TxDb.Mmusculus.UCSC.mm10.knownGene
} else {

txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene::TxDb.Hsapiens.UCSC.hg19.knownGene
}

Expand Down
168 changes: 93 additions & 75 deletions R/plot_browser_tracks.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
getChrStartEnd <- function(x) {

x_chr <- gsub(":.*", "", x) %>% as.character()
x_start <- gsub(".*:", "", x) %>% gsub("-.*",
"", .) %>% as.numeric()
x_end <- gsub(".*:", "", x) %>% gsub(".*-",
"", .) %>% as.numeric()

x_res <- list(chr = x_chr, from = x_start,
to = x_end)

return(x_res)
x_chr <- gsub(":.*", "", x) %>% as.character()
x_start <- gsub(".*:", "", x) %>% gsub("-.*",
"", .) %>% as.numeric()
x_end <- gsub(".*:", "", x) %>% gsub(".*-",
"", .) %>% as.numeric()
x_res <- list(chr = x_chr, from = x_start,
to = x_end)
return(x_res)
}

#' UCSC Genome browser like plots
Expand All @@ -21,15 +21,20 @@ getChrStartEnd <- function(x) {
#'
#' @param data_table a dataframe that contains \code{bw_path}, \code{sample_id} and \code{color_code}. Tracks are colored according to \code{color_code}. Default \code{NULL}
#' @param gene_range genomic region for which browser-like plots needed in format \code{chr:start-end}. Default \code{NULL}
#' @param ref_gen reference genome, to get gene annotations, currently supports \code{hg19} and \code{hg38}. Default, \code{hg38}
#' @param ref_gen reference genome, to get gene annotations, currently supports \code{hg19} \code{mm10} and \code{hg38}. Default, \code{hg38}
#' @param cex.axis axis label size, default \code{0.5}
#' @param cex.title axis title size, default \code{0.8}
#' @param ... additional arguments to change the appearence of a plot. All arguments that can be passed to base R graphics are supported
#'
#' @importFrom TxDb.Hsapiens.UCSC.hg38.knownGene TxDb.Hsapiens.UCSC.hg38.knownGene
#' @importFrom TxDb.Hsapiens.UCSC.hg19.knownGene TxDb.Hsapiens.UCSC.hg19.knownGene
#' @importFrom TxDb.Mmusculus.UCSC.mm10.knownGene TxDb.Mmusculus.UCSC.mm10.knownGene
#' @importFrom dplyr filter pull
#' @importFrom Gviz GeneRegionTrack DataTrack plotTracks
#' @importFrom org.Mm.eg.db org.Mm.eg.db
#' @importFrom org.Hs.eg.db org.Hs.eg.db
#' @importFrom IRanges ranges
#' @importFrom AnnotationDbi mapIds
#'
#' @return plot of genome browser tracks
#'
Expand Down Expand Up @@ -58,67 +63,80 @@ plot_browser_tracks <- function(data_table,
ref_gen = "hg38",
cex.axis = 0.5,
cex.title = 0.8, ...) {

assertthat::assert_that(is.data.frame(data_table), msg = "Please provide `data_table`")
assertthat::assert_that(assertthat::has_name(data_table, "bw_path"))
assertthat::assert_that(assertthat::has_name(data_table, "sample_id"))
assertthat::assert_that(assertthat::has_name(data_table, "color_code"))

assertthat::assert_that(!is.null(gene_range), msg = "Please provide `gene_range` in format; chr:start-end")

gene_range_split <- getChrStartEnd(x = gene_range)

## build genetrack
if (ref_gen == "hg38") {

txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene::TxDb.Hsapiens.UCSC.hg38.knownGene

} else {

txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene::TxDb.Hsapiens.UCSC.hg19.knownGene
}

##
grtrack <- Gviz::GeneRegionTrack(txdb,
genome = ref_gen,
chromosome = gene_range_split$chr,
window = -1, name = NULL, background.title = "white",
col.frame = "white", col.axis = "black",
col = "black", col.title = "black",
geneSymbol = TRUE, showId = TRUE,
from = gene_range_split$from, to = gene_range_split$to)

## build enrichment tracks
dt_list <- list()
all_sample_ids <- data_table$sample_id %>%
as.character()

for (i in seq_along(all_sample_ids)) {

x_id <- all_sample_ids[i]
x_dat <- data_table %>% dplyr::filter(sample_id == get("x_id"))

x_bw <- x_dat %>% dplyr::pull(bw_path) %>% as.character()
x_col <- x_dat %>% dplyr::pull(color_code) %>% as.character()

x_dt <- Gviz::DataTrack(range = x_bw,
genome = ref_gen,
chromosome = gene_range_split$chr,
name = x_id, type = "hist", window = -1,
fill.histogram = x_col, col.histogram = "NA",
background.title = "white", col.frame = "white",
col.axis = "black", col = "black",
col.title = "black")

dt_list[[i]] <- x_dt

}

gtrack_pos <- length(dt_list) + 1
dt_list[[gtrack_pos]] <- grtrack

Gviz::plotTracks(dt_list, from = gene_range_split$from,
to = gene_range_split$to, cex.axis = cex.axis,
cex.title = cex.title, ...)


assertthat::assert_that(is.data.frame(data_table), msg = "Please provide `data_table`")
assertthat::assert_that(assertthat::has_name(data_table, "bw_path"))
assertthat::assert_that(assertthat::has_name(data_table, "sample_id"))
assertthat::assert_that(assertthat::has_name(data_table, "color_code"))

assertthat::assert_that(!is.null(gene_range), msg = "Please provide `gene_range` in format; chr:start-end")

gene_range_split <- getChrStartEnd(x = gene_range)

## build genetrack
if (ref_gen == "hg38") {
txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene::TxDb.Hsapiens.UCSC.hg38.knownGene
symbol_db <- org.Hs.eg.db::org.Hs.eg.db
} else if (ref_gen == "mm10") {
txdb <- TxDb.Mmusculus.UCSC.mm10.knownGene::TxDb.Mmusculus.UCSC.mm10.knownGene
symbol_db <- org.Mm.eg.db::org.Mm.eg.db
} else {
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene::TxDb.Hsapiens.UCSC.hg19.knownGene
symbol_db <- org.Hs.eg.db::org.Hs.eg.db
}

##
grtrack <- Gviz::GeneRegionTrack(txdb,
genome = ref_gen,
chromosome = gene_range_split$chr,
window = -1, name = NULL, background.title = "white",
col.frame = "white", col.axis = "black",
col = "black", col.title = "black",
geneSymbol = TRUE, showId = TRUE,
from = gene_range_split$from, to = gene_range_split$to,
collapseTranscripts="longest", shape="arrow", transcriptAnnotation = "symbol")

# map gene symbol
gene_ids = IRanges::ranges(grtrack)
gene_symbols <- AnnotationDbi::mapIds(symbol_db, keys=gene_ids$gene, column = "SYMBOL", keytype = "ENTREZID", multiVals = "first")
gene_symbols[is.na(names(gene_symbols))] <- gene_ids$transcript[is.na(names(gene_symbols))]
gene_ids$symbol <- gene_symbols
IRanges::ranges(grtrack) <- gene_ids

## build enrichment tracks
dt_list <- list()
all_sample_ids <- data_table$sample_id %>%
as.character()

axisTrack <- Gviz::GenomeAxisTrack()
atrack <- length(dt_list)+1
dt_list[[atrack]] <- axisTrack

for (i in seq_along(all_sample_ids)) {

x_id <- all_sample_ids[i]
x_dat <- data_table %>% dplyr::filter(sample_id == get("x_id"))

x_bw <- x_dat %>% dplyr::pull(bw_path) %>% as.character()
x_col <- x_dat %>% dplyr::pull(color_code) %>% as.character()

x_dt <- Gviz::DataTrack(range = x_bw,
genome = ref_gen,
chromosome = gene_range_split$chr,
name = gsub("_", " ", x_id), type = "hist", window = -1,
fill.histogram = x_col, col.histogram = "NA",
background.title = "white", col.frame = "white",
col.axis = "black", col = "black",
col.title = "black")

dt_list[[i+1]] <- x_dt

}

gtrack_pos <- length(dt_list) + 1
dt_list[[gtrack_pos]] <- grtrack

Gviz::plotTracks(dt_list, from = gene_range_split$from,
to = gene_range_split$to, cex.axis = cex.axis,
cex.title = cex.title, ...)
}
Loading