Skip to content

Commit

Permalink
fix: remove conflicting package ggpp from geom_protein; closes showte…
Browse files Browse the repository at this point in the history
  • Loading branch information
m-jahn committed Apr 17, 2024
1 parent 735f1ff commit 21080a8
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 71 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Imports:
BiocParallel,
openxlsx,
stringr,
ggpp
gridExtra
Suggests:
rmarkdown,
knitr,
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,unit)
importFrom(ggpp,annotate)
importFrom(ggrepel,geom_text_repel)
importFrom(grDevices,col2rgb)
importFrom(grDevices,colorRampPalette)
importFrom(gridExtra,tableGrob)
importFrom(gridExtra,ttheme_default)
importFrom(magrittr,"%>%")
importFrom(methods,extends)
importFrom(openxlsx,read.xlsx)
Expand Down
51 changes: 33 additions & 18 deletions R/geom_protein.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param show.table Logical value, whether to show coverage summary table. Default: TRUE.
#' @param table.position The position of the coverage summary table, choose from right_top, left_top, left_bottom, right_bottom.
#' Default: right_top.
#' @param table.size The font size of coverage summary table. Default: 4.
#' @param table.size The font size of coverage summary table. Default: 12.
#' @param table.color The font color of coverage summary table. Default: black.
#' @param range.size The label size of range text, used when \code{range.position} is in. Default: 3.
#' @param range.position The position of y axis range, chosen from in (move y axis in the plot) and
Expand All @@ -30,8 +30,8 @@
#' @importFrom GenomicRanges reduce GRanges setdiff
#' @importFrom IRanges IRanges
#' @importFrom ggplot2 ggplot geom_rect geom_text aes aes_string
#' @importFrom ggpp annotate
#' @importFrom scales scientific
#' @importFrom gridExtra ttheme_default tableGrob
#' @export
#'
#' @examples
Expand All @@ -49,7 +49,7 @@
geom_protein <- function(coverage.file, fasta.file, protein.id, XCorr.threshold = 2,
confidence = "High", contaminant = NULL, remove.na = TRUE,
color = "grey", mark.bare = TRUE, mark.color = "red", mark.alpha = 0.5,
show.table = TRUE, table.position = c("right_top", "left_top", "left_bottom", "right_bottom"),
show.table = TRUE, table.position = c("top_right", "top_left", "bottom_right", "bottom_left"),
table.size = 4, table.color = "black", range.size = 3, range.position = c("in", "out")) {
# check parameters
table.position <- match.arg(arg = table.position)
Expand Down Expand Up @@ -169,22 +169,37 @@ geom_protein <- function(coverage.file, fasta.file, protein.id, XCorr.threshold
# summary table
if (show.table) {
# table position
if (table.position == "left_top") {
table.x <- 0
table.y <- max(coverage.final[, "abundance"])
} else if (table.position == "right_top") {
table.x <- nchar(aa.seq.used)
table.y <- max(coverage.final[, "abundance"])
} else if (table.position == "left_bottom") {
table.x <- 0
table.y <- 0
} else if (table.position == "right_bottom") {
table.x <- nchar(aa.seq.used)
table.y <- 0

if (table.position == "top_left") {
table_xmin <- 0
table_xmax <- nchar(aa.seq.used) * 0.5
table_ymin <- max(coverage.final[, "abundance"]) * 0.5
table_ymax <- max(coverage.final[, "abundance"]) * 1.0
} else if (table.position == "top_right") {
table_xmin <- nchar(aa.seq.used) * 0.5
table_xmax <- nchar(aa.seq.used) * 1.0
table_ymin <- max(coverage.final[, "abundance"]) * 0.5
table_ymax <- max(coverage.final[, "abundance"]) * 1.0
} else if (table.position == "bottom_left") {
table_xmin <- 0
table_xmax <- nchar(aa.seq.used) * 0.5
table_ymin <- 0
table_ymax <- max(coverage.final[, "abundance"]) * 0.5
} else if (table.position == "bottom_right") {
table_xmin <- nchar(aa.seq.used) * 0.5
table_xmax <- nchar(aa.seq.used) * 1.0
table_ymin <- 0
table_ymax <- max(coverage.final[, "abundance"]) * 0.5
}
summary.table <- ggpp::annotate(
geom = "table", label = list(coverage.summary), x = table.x, y = table.y,
color = table.color, size = table.size
table_theme <- gridExtra::ttheme_default(
base_size = table.size, base_colour = table.color
)
summary.table <- ggplot2::annotation_custom(
grob = gridExtra::tableGrob(
d = coverage.summary,
theme = table_theme),
xmin = table_xmin, xmax = table_xmax,
ymin = table_ymin, ymax = table_ymax
)
plot.ele <- append(plot.ele, summary.table)
}
Expand Down
44 changes: 16 additions & 28 deletions R/ggprotein.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,28 @@
#' out (normal y axis). Default: in.
#'
#' @return A ggplot2 object.
#' @importFrom openxlsx read.xlsx
#' @importFrom magrittr %>%
#' @importFrom dplyr filter group_by summarise arrange
#' @importFrom rlang .data
#' @importFrom Biostrings readAAStringSet
#' @importFrom stringr str_locate
#' @importFrom GenomicRanges reduce GRanges setdiff
#' @importFrom IRanges IRanges
#' @importFrom ggplot2 ggplot geom_rect geom_text aes aes_string scale_x_continuous theme_classic theme
#' element_blank annotate rel scale_y_continuous expansion
#' @importFrom ggpp annotate
#' @importFrom scales scientific
#' @export
#'
#' @examples
#' # library(ggcoverage)
#' # coverage.file <- system.file(
#' # "extdata", "Proteomics", "MS_BSA_coverage.xlsx", package = "ggcoverage"
#' # )
#' # fasta.file <- system.file(
#' # "extdata", "Proteomics", "MS_BSA_coverage.fasta", package = "ggcoverage"
#' # )
#' # protein.id = "sp|P02769|ALBU_BOVIN"
#' #
#' # ggprotein(
#' # coverage.file = coverage.file,
#' # fasta.file = fasta.file,
#' # protein.id = protein.id
#' # )
#' library(ggcoverage)
#' coverage.file <- system.file(
#' "extdata", "Proteomics", "MS_BSA_coverage.xlsx", package = "ggcoverage"
#' )
#' fasta.file <- system.file(
#' "extdata", "Proteomics", "MS_BSA_coverage.fasta", package = "ggcoverage"
#' )
#' protein.id = "sp|P02769|ALBU_BOVIN"
#'
#' ggprotein(
#' coverage.file = coverage.file,
#' fasta.file = fasta.file,
#' protein.id = protein.id
#' )
ggprotein <- function(coverage.file, fasta.file, protein.id, XCorr.threshold = 2,
confidence = "High", contaminant = NULL, remove.na = TRUE,
color = "grey", mark.bare = TRUE, mark.color = "red", mark.alpha = 0.5,
show.table = TRUE, table.position = c("right_top", "left_top", "left_bottom", "right_bottom"),
table.size = 4, table.color = "black", range.size = 3, range.position = c("in", "out")) {
show.table = TRUE, table.position = c("top_right", "top_left", "bottom_left", "bottom_right"),
table.size = 10, table.color = "black", range.size = 3, range.position = c("in", "out")) {
# check parameters
table.position <- match.arg(arg = table.position)
range.position <- match.arg(arg = range.position)
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ protein_set

### Protein coverage

```{r basic_coverage_protein, warning=FALSE, fig.height = 6, fig.width = 12, fig.align = "center"}
```{r basic_coverage_protein, warning=FALSE, fig.height = 6, fig.width = 10, fig.align = "center"}
protein_coverage <- ggprotein(
coverage.file = coverage_file,
fasta.file = fasta_file,
Expand All @@ -794,7 +794,7 @@ protein_coverage

We can obtain features of the protein from [UniProt](https://www.uniprot.org/). For example, the above protein coverage plot shows that there is empty region in 1-24, and this empty region in [UniProt](https://www.uniprot.org/uniprotkb/P02769/entry) is annotated as Signal peptide and Propeptide peptide. When the protein is mature and released extracellular, these peptides will be cleaved. This is the reason why there is empty region in 1-24.

```{r basic_coverage_protein_feature, warning=FALSE, fig.height = 6, fig.width = 12, fig.align = "center"}
```{r basic_coverage_protein_feature, warning=FALSE, fig.height = 6, fig.width = 10, fig.align = "center"}
# protein feature obtained from UniProt
protein_feature_df <- data.frame(
ProteinID = "sp|P02769|ALBU_BOVIN",
Expand Down
Binary file modified man/figures/README-basic_coverage_protein-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-basic_coverage_protein_feature-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions man/geom_protein.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions man/ggprotein.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vignettes/ggcoverage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The goal of `ggcoverage` is simplify the process of visualizing omics coverage.
* **peak annotation**: Visualize genome coverage and peak identified
* **contact map annotation**: Visualize genome coverage with Hi-C contact map
* **link annotation**: Visualize genome coverage with contacts
* **peotein feature annotation**: Visualize protein coverage with features
* **protein feature annotation**: Visualize protein coverage with features

`ggcoverage` utilizes `ggplot2` plotting system, so its usage is **ggplot2-style**!

Expand Down Expand Up @@ -819,7 +819,7 @@ protein_coverage <- ggprotein(
protein_coverage
```

```{r basic_coverage_protein_plot, echo = FALSE, fig.height = 6, fig.width = 12, fig.align = "center"}
```{r basic_coverage_protein_plot, echo = FALSE, fig.height = 6, fig.width = 10, fig.align = "center"}
knitr::include_graphics("../man/figures/README-basic_coverage_protein-1.png")
```

Expand All @@ -842,7 +842,7 @@ protein_coverage +
feature.color = c("#4d81be", "#173b5e", "#6a521d"))
```

```{r basic_coverage_protein_feature_plot, echo = FALSE, fig.height = 6, fig.width = 12, fig.align = "center"}
```{r basic_coverage_protein_feature_plot, echo = FALSE, fig.height = 6, fig.width = 10, fig.align = "center"}
knitr::include_graphics("../man/figures/README-basic_coverage_protein_feature-1.png")
```

Expand Down

0 comments on commit 21080a8

Please sign in to comment.