Skip to content

Commit

Permalink
Merge pull request #43 from m-jahn/dev
Browse files Browse the repository at this point in the history
fix: reduced size footprint + examples for CRAN submission
  • Loading branch information
showteeth authored Jan 16, 2025
2 parents fcfe3ec + 0bf8fb7 commit 9959cb7
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 257 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Type: Package
Package: ggcoverage
Title: Visualize Genome/Protein Coverage with Various Annotations
Version: 1.4.0
Version: 1.4.1
Authors@R: c(
person("Yabing", "Song", , "[email protected]", role = c("aut", "cre", "cph")),
person("Michael", "Jahn", , "[email protected]", role = c("aut", "cph"),
comment = c(ORCID = "0000-0002-3913-153X"))
)
Maintainer: Yabing Song <[email protected]>
Description: The goal of `ggcoverage` is to visualize coverage tracks from
Description: The goal of 'ggcoverage' is to visualize coverage tracks from
genomics, transcriptomics or proteomics data. It contains functions to
load data from BAM, BigWig, BedGraph, txt, or xlsx files, create
genome/protein coverage plots, and add various annotations including
base and amino acid composition, GC content, copy number variation
(CNV), genes, transcripts, ideograms, peak highlights, HiC contact
maps, contact links and protein features. It is based on and
integrates well with `ggplot2`.
integrates well with 'ggplot2'.
License: MIT + file LICENSE
URL: https://showteeth.github.io/ggcoverage/,
https://github.com/showteeth/ggcoverage
Expand Down Expand Up @@ -49,7 +49,6 @@ Suggests:
ggforce,
graphics,
HiCBricks,
HiCDataHumanIMR90,
htmltools,
knitr,
rmarkdown
Expand Down
59 changes: 30 additions & 29 deletions R/geom_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,41 @@
#' @export
#'
#' @examples
#' library("BSgenome.Hsapiens.UCSC.hg19")
#' if (requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) {
#' library("BSgenome.Hsapiens.UCSC.hg19")
#'
#' # get sample metadata
#' sample.meta <- data.frame(
#' SampleName = c("tumorA.chr4.selected"),
#' Type = c("tumorA"),
#' Group = c("tumorA")
#' )
#'
#' # get bam file
#' bam.file <-
#' system.file("extdata", "DNA-seq", "tumorA.chr4.selected.bam", package = "ggcoverage")
#' # get sample metadata
#' sample.meta <- data.frame(
#' SampleName = c("tumorA.chr4.selected"),
#' Type = c("tumorA"),
#' Group = c("tumorA")
#' )
#'
#' # load bam file
#' track.df <- LoadTrackFile(
#' track.file = bam.file,
#' meta.info = sample.meta,
#' single.nuc = TRUE,
#' single.nuc.region = "chr4:62474235-62474295"
#' )
#' # get bam file
#' bam.file <-
#' system.file("extdata", "DNA-seq", "tumorA.chr4.selected.bam", package = "ggcoverage")
#'
#' # plot
#' ggcoverage(
#' data = track.df,
#' color = "grey",
#' range.position = "out",
#' single.nuc = TRUE,
#' rect.color = "white"
#' ) +
#' geom_base(
#' bam.file = bam.file,
#' bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19
#' # load bam file
#' track.df <- LoadTrackFile(
#' track.file = bam.file,
#' meta.info = sample.meta,
#' single.nuc = TRUE,
#' single.nuc.region = "chr4:62474235-62474295"
#' )
#'
#' # plot
#' ggcoverage(
#' data = track.df,
#' color = "grey",
#' range.position = "out",
#' single.nuc = TRUE,
#' rect.color = "white"
#' ) +
#' geom_base(
#' bam.file = bam.file,
#' bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19
#' )
#' }
geom_base <- function(bam.file, fa.file = NULL, bs.fa.seq = NULL, chr.split = "[[:space:]]",
nuc.offset = -0.1, nuc.size = 4, nuc.padding = 0.05, nuc.padding.r = 0,
nuc.color = c("A" = "#ff2b08", "C" = "#009aff", "G" = "#ffb507", "T" = "#00bc0d"),
Expand Down
47 changes: 30 additions & 17 deletions R/geom_cnv.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,36 @@
#' @export
#'
#' @examples
#' # library(ggcoverage)
#' # library(utils)
#' # library("BSgenome.Hsapiens.UCSC.hg19")
#' # # prepare files
#' # cnv.file <- system.file("extdata", "DNA-seq", "SRR054616_copynumber.txt", package = "ggcoverage")
#' # track.file <- system.file("extdata", "DNA-seq", "SRR054616.bw", package = "ggcoverage")
#' # # read CNV
#' # cnv.df = read.table(file = cnv.file, sep = "\t", header = TRUE)
#' # # load track
#' # track.df = LoadTrackFile(track.file = track.file, format = "bw")
#' # track.df$seqnames = paste0("chr", track.df$seqnames)
#' # # plot
#' # ggcoverage(data = track.df, color = "grey", region = "chr4:1-160000000",
#' # mark.region = NULL, range.position = "out") +
#' # geom_gc(bs.fa.seq=BSgenome.Hsapiens.UCSC.hg19) +
#' # geom_cnv(cnv.df = cnv.df, bin.col = 3, cn.col = 4) +
#' # geom_ideogram(genome = "hg19",plot.space = 0, highlight.centromere = TRUE)
#' if (requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) {
#' library("BSgenome.Hsapiens.UCSC.hg19")
#'
#' # load track data
#' track_file <-
#' system.file("extdata", "DNA-seq", "SRR054616.bw", package = "ggcoverage")
#' track_df <- LoadTrackFile(
#' track.file = track_file,
#' format = "bw",
#' region = "4:1-160000000"
#' )
#' track_df$seqnames <- paste0("chr", track_df$seqnames)
#'
#' # read CNV data
#' cnv_file <-
#' system.file("extdata", "DNA-seq", "SRR054616_copynumber.txt", package = "ggcoverage")
#' cnv_df <- read.table(file = cnv_file, sep = "\t", header = TRUE)
#'
#' # plot coverage, GC content, CNV
#' basic_coverage <- ggcoverage(
#' data = track_df,
#' color = "grey",
#' mark.region = NULL,
#' range.position = "out"
#' )
#'
#' basic_coverage +
#' geom_gc(bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19) +
#' geom_cnv(cnv.df = cnv_df, bin.col = 3, cn.col = 4)
#' }
geom_cnv <- function(cnv.df, bin.col = 3, cn.col = 4, ref.cn = 2,
bin.point.color = "grey", bin.point.alpha = 0.6, cn.line.color = "red",
ref.line.color = "black", plot.space = 0.1, plot.height = 0.2) {
Expand Down
38 changes: 24 additions & 14 deletions R/geom_gc.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@
#' @export
#'
#' @examples
#' # library(ggcoverage)
#' # library(utils)
#' # library(rtracklayer)
#' # library("BSgenome.Hsapiens.UCSC.hg19")
#' # track folder
#' # track.file <- system.file("extdata", "DNA-seq", "CNV_example.txt", package = "ggcoverage")
#' # track.df <- utils::read.table(track.file, header = TRUE)
#' # gtf.file <- system.file("extdata", "used_hg19.gtf", package = "ggcoverage")
#' # gtf.gr <- rtracklayer::import.gff(con = gtf.file, format = "gtf")
#' # basic.coverage <- ggcoverage(
#' # data = track.df, color = NULL, mark.region = NULL,
#' # region = "chr4:61750000-62,700,000", range.position = "out"
#' # )
#' # basic.coverage + geom_gc(bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19)
#' if (requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) {
#' library("BSgenome.Hsapiens.UCSC.hg19")
#'
#' # load track data
#' track_file <-
#' system.file("extdata", "DNA-seq", "SRR054616.bw", package = "ggcoverage")
#' track_df <- LoadTrackFile(
#' track.file = track_file,
#' format = "bw",
#' region = "4:1-160000000"
#' )
#' track_df$seqnames <- paste0("chr", track_df$seqnames)
#'
#' # plot coverage and GC content
#' basic_coverage <- ggcoverage(
#' data = track_df,
#' color = "grey",
#' mark.region = NULL,
#' range.position = "out"
#' )
#'
#' basic_coverage +
#' geom_gc(bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19)
#' }
geom_gc <- function(fa.file = NULL, bs.fa.seq = NULL, chr.split = "[[:space:]]", guide.line = NULL,
line.color = "black", guide.line.color = "red", guide.line.type = "dashed",
plot.space = 0.1, plot.height = 0.2) {
Expand Down
1 change: 1 addition & 0 deletions R/geom_ideogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#'
#' @examples
#' \dontrun{
#' # note that you need to have package 'ggbio' installed
#' library(ggbio)
#'
#' # load metadata
Expand Down
81 changes: 41 additions & 40 deletions R/geom_tad.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,54 @@
#' @importFrom utils write.table
#'
#' @examples
#' library(ggcoverage)
#' library(HiCBricks)
#' if (requireNamespace("HiCBricks", quietly = TRUE)) {
#' library(HiCBricks)
#'
#' # prepare track dataframe
#' track.file <- system.file("extdata", "HiC", "H3K36me3.bw", package = "ggcoverage")
#' track.df <- LoadTrackFile(
#' track.file = track.file, format = "bw",
#' region = "chr2L:8050000-8300000", extend = 0
#' )
#' track.df$score <- ifelse(track.df$score < 0, 0, track.df$score)
#' # check the data
#' head(track.df)
#' # prepare track dataframe
#' track.file <- system.file("extdata", "HiC", "H3K36me3.bw", package = "ggcoverage")
#' track.df <- LoadTrackFile(
#' track.file = track.file, format = "bw",
#' region = "chr2L:8100000-8200000", extend = 0
#' )
#' track.df$score <- ifelse(track.df$score < 0, 0, track.df$score)
#' # check the data
#' head(track.df)
#'
#' # Load Hi-C data
#' hic.mat.file <- system.file("extdata", "HiC", "HiC_mat.txt", package = "ggcoverage")
#' hic.mat <- read.table(file = hic.mat.file, sep = "\t")
#' hic.mat <- as.matrix(hic.mat)
#' # Load Hi-C data
#' hic.mat.file <- system.file("extdata", "HiC", "HiC_mat.txt", package = "ggcoverage")
#' hic.mat <- read.table(file = hic.mat.file, sep = "\t")
#' hic.mat <- as.matrix(hic.mat)
#'
#' # bin data
#' hic.bin.file <- system.file("extdata", "HiC", "HiC_bin.txt", package = "ggcoverage")
#' hic.bin <- read.table(file = hic.bin.file, sep = "\t")
#' colnames(hic.bin) <- c("chr", "start", "end")
#' hic.bin.gr <- GenomicRanges::makeGRangesFromDataFrame(df = hic.bin)
#' # bin data
#' hic.bin.file <- system.file("extdata", "HiC", "HiC_bin.txt", package = "ggcoverage")
#' hic.bin <- read.table(file = hic.bin.file, sep = "\t")
#' colnames(hic.bin) <- c("chr", "start", "end")
#' hic.bin.gr <- GenomicRanges::makeGRangesFromDataFrame(df = hic.bin)
#'
#' # transfrom function
#' failsafe_log10 <- function(x) {
#' x[is.na(x) | is.nan(x) | is.infinite(x)] <- 0
#' return(log10(x + 1))
#' }
#' # transfrom function
#' failsafe_log10 <- function(x) {
#' x[is.na(x) | is.nan(x) | is.infinite(x)] <- 0
#' return(log10(x + 1))
#' }
#'
#' # load link data: prepare arcs
#' link.file <- system.file("extdata", "HiC", "HiC_link.bedpe", package = "ggcoverage")
#' # load link data: prepare arcs
#' link.file <- system.file("extdata", "HiC", "HiC_link.bedpe", package = "ggcoverage")
#'
#' # basic coverage
#' basic.coverage <- ggcoverage(
#' data = track.df, color = "grey",
#' mark.region = NULL, range.position = "out"
#' )
#' # basic coverage
#' basic.coverage <- ggcoverage(
#' data = track.df, color = "grey",
#' mark.region = NULL, range.position = "out"
#' )
#'
#' # add annotations
#' basic.coverage +
#' geom_tad(
#' matrix = hic.mat, granges = hic.bin.gr, value.cut = 0.99,
#' color.palette = "viridis", transform.fun = failsafe_log10,
#' top = FALSE, show.rect = TRUE
#' ) +
#' geom_link(link.file = link.file, file.type = "bedpe", show.rect = TRUE)
#' # add annotations
#' basic.coverage +
#' geom_tad(
#' matrix = hic.mat, granges = hic.bin.gr, value.cut = 0.99,
#' color.palette = "viridis", transform.fun = failsafe_log10,
#' top = FALSE, show.rect = TRUE
#' ) +
#' geom_link(link.file = link.file, file.type = "bedpe", show.rect = TRUE)
#' }
#'
#' @export
geom_tad <- function(matrix, granges, color.palette = NULL, value.cut = NULL,
Expand Down
18 changes: 0 additions & 18 deletions R/geom_transcript.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
#' @export
#'
#' @examples
#' library(ggcoverage)
#' library(utils)
#' library(rtracklayer)
#'
#' # load metadata
#' meta_file <- system.file("extdata", "RNA-seq", "meta_info.csv", package = "ggcoverage")
#' sample_meta <- read.csv(meta_file)
Expand All @@ -75,20 +71,6 @@
#' basic_coverage +
#' geom_transcript(gtf.gr = gtf_gr, label.vjust = 1.5)
#'
#' # plot with custom style
#' basic_coverage +
#' geom_transcript(
#' gtf.gr = gtf_gr,
#' exon.size = 2.0,
#' arrow.size.im = 1.0,
#' arrow.length.im = 5,
#' arrow.type.im = "open",
#' color.by.im = "strand",
#' fill.color = c(
#' "-" = "darkblue",
#' "+" = "darkgreen"
#' )
#' )
geom_transcript <-
function(gtf.gr,
gene.name = "HNRNPC",
Expand Down
4 changes: 3 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ basic_coverage

##### Add GC annotations

Add **GC**, **ideogram** and **gene** annotaions.
Add **GC**, **ideogram** and **gene** annotations.
The plotting of the GC content requires the genome annotation package `BSgenome.Hsapiens.UCSC.hg19`.
This package needs to be installed separately (it is only 'Suggested' by `ggcoverage`).

```{r gc_coverage, warning = FALSE, fig.height = 10, fig.width = 12, fig.align = "center"}
# load genome data
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ basic_coverage

##### Add GC annotations

Add **GC**, **ideogram** and **gene** annotaions.
Add **GC**, **ideogram** and **gene** annotations. The plotting of the
GC content requires the genome annotation package
`BSgenome.Hsapiens.UCSC.hg19`. This package needs to be installed
separately (it is only ‘Suggested’ by `ggcoverage`).

``` r
# load genome data
Expand Down Expand Up @@ -657,7 +660,7 @@ graphics::par(opar)

Default color scheme for amino acid annotation is from [Residual
colours: a proposal for
aminochromography](https://doi.org/10.1093/protein/10.7.743):
aminochromography](https://pubmed.ncbi.nlm.nih.gov/9342138/):

``` r
aa_color <- c(
Expand Down Expand Up @@ -898,7 +901,7 @@ a contact map.

The Hi-C data is taken from [pyGenomeTracks: reproducible plots for
multivariate genomic
datasets](https://doi.org/10.1093/bioinformatics/btaa692).
datasets](https://pubmed.ncbi.nlm.nih.gov/32745185/).

The Hi-C matrix visualization is implemented by
[`HiCBricks`](https://github.com/koustav-pal/HiCBricks). This package
Expand Down
Loading

0 comments on commit 9959cb7

Please sign in to comment.