Skip to content

Commit 21080a8

Browse files
committed
fix: remove conflicting package ggpp from geom_protein; closes #21
1 parent 735f1ff commit 21080a8

10 files changed

+75
-71
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Imports:
5656
BiocParallel,
5757
openxlsx,
5858
stringr,
59-
ggpp
59+
gridExtra
6060
Suggests:
6161
rmarkdown,
6262
knitr,

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ importFrom(ggplot2,scale_y_continuous)
122122
importFrom(ggplot2,theme)
123123
importFrom(ggplot2,theme_classic)
124124
importFrom(ggplot2,unit)
125-
importFrom(ggpp,annotate)
126125
importFrom(ggrepel,geom_text_repel)
127126
importFrom(grDevices,col2rgb)
128127
importFrom(grDevices,colorRampPalette)
128+
importFrom(gridExtra,tableGrob)
129+
importFrom(gridExtra,ttheme_default)
129130
importFrom(magrittr,"%>%")
130131
importFrom(methods,extends)
131132
importFrom(openxlsx,read.xlsx)

R/geom_protein.R

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' @param show.table Logical value, whether to show coverage summary table. Default: TRUE.
1515
#' @param table.position The position of the coverage summary table, choose from right_top, left_top, left_bottom, right_bottom.
1616
#' Default: right_top.
17-
#' @param table.size The font size of coverage summary table. Default: 4.
17+
#' @param table.size The font size of coverage summary table. Default: 12.
1818
#' @param table.color The font color of coverage summary table. Default: black.
1919
#' @param range.size The label size of range text, used when \code{range.position} is in. Default: 3.
2020
#' @param range.position The position of y axis range, chosen from in (move y axis in the plot) and
@@ -30,8 +30,8 @@
3030
#' @importFrom GenomicRanges reduce GRanges setdiff
3131
#' @importFrom IRanges IRanges
3232
#' @importFrom ggplot2 ggplot geom_rect geom_text aes aes_string
33-
#' @importFrom ggpp annotate
3433
#' @importFrom scales scientific
34+
#' @importFrom gridExtra ttheme_default tableGrob
3535
#' @export
3636
#'
3737
#' @examples
@@ -49,7 +49,7 @@
4949
geom_protein <- function(coverage.file, fasta.file, protein.id, XCorr.threshold = 2,
5050
confidence = "High", contaminant = NULL, remove.na = TRUE,
5151
color = "grey", mark.bare = TRUE, mark.color = "red", mark.alpha = 0.5,
52-
show.table = TRUE, table.position = c("right_top", "left_top", "left_bottom", "right_bottom"),
52+
show.table = TRUE, table.position = c("top_right", "top_left", "bottom_right", "bottom_left"),
5353
table.size = 4, table.color = "black", range.size = 3, range.position = c("in", "out")) {
5454
# check parameters
5555
table.position <- match.arg(arg = table.position)
@@ -169,22 +169,37 @@ geom_protein <- function(coverage.file, fasta.file, protein.id, XCorr.threshold
169169
# summary table
170170
if (show.table) {
171171
# table position
172-
if (table.position == "left_top") {
173-
table.x <- 0
174-
table.y <- max(coverage.final[, "abundance"])
175-
} else if (table.position == "right_top") {
176-
table.x <- nchar(aa.seq.used)
177-
table.y <- max(coverage.final[, "abundance"])
178-
} else if (table.position == "left_bottom") {
179-
table.x <- 0
180-
table.y <- 0
181-
} else if (table.position == "right_bottom") {
182-
table.x <- nchar(aa.seq.used)
183-
table.y <- 0
172+
173+
if (table.position == "top_left") {
174+
table_xmin <- 0
175+
table_xmax <- nchar(aa.seq.used) * 0.5
176+
table_ymin <- max(coverage.final[, "abundance"]) * 0.5
177+
table_ymax <- max(coverage.final[, "abundance"]) * 1.0
178+
} else if (table.position == "top_right") {
179+
table_xmin <- nchar(aa.seq.used) * 0.5
180+
table_xmax <- nchar(aa.seq.used) * 1.0
181+
table_ymin <- max(coverage.final[, "abundance"]) * 0.5
182+
table_ymax <- max(coverage.final[, "abundance"]) * 1.0
183+
} else if (table.position == "bottom_left") {
184+
table_xmin <- 0
185+
table_xmax <- nchar(aa.seq.used) * 0.5
186+
table_ymin <- 0
187+
table_ymax <- max(coverage.final[, "abundance"]) * 0.5
188+
} else if (table.position == "bottom_right") {
189+
table_xmin <- nchar(aa.seq.used) * 0.5
190+
table_xmax <- nchar(aa.seq.used) * 1.0
191+
table_ymin <- 0
192+
table_ymax <- max(coverage.final[, "abundance"]) * 0.5
184193
}
185-
summary.table <- ggpp::annotate(
186-
geom = "table", label = list(coverage.summary), x = table.x, y = table.y,
187-
color = table.color, size = table.size
194+
table_theme <- gridExtra::ttheme_default(
195+
base_size = table.size, base_colour = table.color
196+
)
197+
summary.table <- ggplot2::annotation_custom(
198+
grob = gridExtra::tableGrob(
199+
d = coverage.summary,
200+
theme = table_theme),
201+
xmin = table_xmin, xmax = table_xmax,
202+
ymin = table_ymin, ymax = table_ymax
188203
)
189204
plot.ele <- append(plot.ele, summary.table)
190205
}

R/ggprotein.R

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,28 @@
2121
#' out (normal y axis). Default: in.
2222
#'
2323
#' @return A ggplot2 object.
24-
#' @importFrom openxlsx read.xlsx
25-
#' @importFrom magrittr %>%
26-
#' @importFrom dplyr filter group_by summarise arrange
27-
#' @importFrom rlang .data
28-
#' @importFrom Biostrings readAAStringSet
29-
#' @importFrom stringr str_locate
30-
#' @importFrom GenomicRanges reduce GRanges setdiff
31-
#' @importFrom IRanges IRanges
32-
#' @importFrom ggplot2 ggplot geom_rect geom_text aes aes_string scale_x_continuous theme_classic theme
33-
#' element_blank annotate rel scale_y_continuous expansion
34-
#' @importFrom ggpp annotate
35-
#' @importFrom scales scientific
3624
#' @export
3725
#'
3826
#' @examples
39-
#' # library(ggcoverage)
40-
#' # coverage.file <- system.file(
41-
#' # "extdata", "Proteomics", "MS_BSA_coverage.xlsx", package = "ggcoverage"
42-
#' # )
43-
#' # fasta.file <- system.file(
44-
#' # "extdata", "Proteomics", "MS_BSA_coverage.fasta", package = "ggcoverage"
45-
#' # )
46-
#' # protein.id = "sp|P02769|ALBU_BOVIN"
47-
#' #
48-
#' # ggprotein(
49-
#' # coverage.file = coverage.file,
50-
#' # fasta.file = fasta.file,
51-
#' # protein.id = protein.id
52-
#' # )
27+
#' library(ggcoverage)
28+
#' coverage.file <- system.file(
29+
#' "extdata", "Proteomics", "MS_BSA_coverage.xlsx", package = "ggcoverage"
30+
#' )
31+
#' fasta.file <- system.file(
32+
#' "extdata", "Proteomics", "MS_BSA_coverage.fasta", package = "ggcoverage"
33+
#' )
34+
#' protein.id = "sp|P02769|ALBU_BOVIN"
35+
#'
36+
#' ggprotein(
37+
#' coverage.file = coverage.file,
38+
#' fasta.file = fasta.file,
39+
#' protein.id = protein.id
40+
#' )
5341
ggprotein <- function(coverage.file, fasta.file, protein.id, XCorr.threshold = 2,
5442
confidence = "High", contaminant = NULL, remove.na = TRUE,
5543
color = "grey", mark.bare = TRUE, mark.color = "red", mark.alpha = 0.5,
56-
show.table = TRUE, table.position = c("right_top", "left_top", "left_bottom", "right_bottom"),
57-
table.size = 4, table.color = "black", range.size = 3, range.position = c("in", "out")) {
44+
show.table = TRUE, table.position = c("top_right", "top_left", "bottom_left", "bottom_right"),
45+
table.size = 10, table.color = "black", range.size = 3, range.position = c("in", "out")) {
5846
# check parameters
5947
table.position <- match.arg(arg = table.position)
6048
range.position <- match.arg(arg = range.position)

README.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ protein_set
779779

780780
### Protein coverage
781781

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

795795
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.
796796

797-
```{r basic_coverage_protein_feature, warning=FALSE, fig.height = 6, fig.width = 12, fig.align = "center"}
797+
```{r basic_coverage_protein_feature, warning=FALSE, fig.height = 6, fig.width = 10, fig.align = "center"}
798798
# protein feature obtained from UniProt
799799
protein_feature_df <- data.frame(
800800
ProteinID = "sp|P02769|ALBU_BOVIN",
-397 Bytes
Loading
-363 Bytes
Loading

man/geom_protein.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ggprotein.Rd

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/ggcoverage.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The goal of `ggcoverage` is simplify the process of visualizing omics coverage.
5151
* **peak annotation**: Visualize genome coverage and peak identified
5252
* **contact map annotation**: Visualize genome coverage with Hi-C contact map
5353
* **link annotation**: Visualize genome coverage with contacts
54-
* **peotein feature annotation**: Visualize protein coverage with features
54+
* **protein feature annotation**: Visualize protein coverage with features
5555

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

@@ -819,7 +819,7 @@ protein_coverage <- ggprotein(
819819
protein_coverage
820820
```
821821

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

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

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

0 commit comments

Comments
 (0)