forked from showteeth/ggcoverage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggprotein.R
71 lines (69 loc) · 3.8 KB
/
ggprotein.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#' Create Mass Spectrometry Protein Coverage Plot.
#'
#' @param coverage.file Exported protein coverage file, should be in excel.
#' @param fasta.file Input reference protein fasta file.
#' @param protein.id The protein ID of exported coverage file. This should be unique and in \code{fasta.file}.
#' @param XCorr.threshold The cross-correlation threshold. Default: 2.
#' @param confidence The confidence level. Default: High.
#' @param contaminant Whether to remove contaminant peptides. Default: NULL (not remove).
#' @param remove.na Logical value, whether to remove NA value in Abundance column. Default: TRUE.
#' @param color The fill color of coverage plot. Default: grey.
#' @param mark.bare Logical value, whether to mark region where Abundance is zero or NA. Default: TRUE.
#' @param mark.color The color used for the marked region. Default: red.
#' @param mark.alpha The transparency used for the marked region. Default: 0.5.
#' @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.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
#' 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)
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"), plot.space = 0.2) {
# check parameters
table.position <- match.arg(arg = table.position)
range.position <- match.arg(arg = range.position)
# ms protein plot
protein.plot <- ggplot() +
geom_protein(
coverage.file = coverage.file, fasta.file = fasta.file, protein.id = protein.id,
XCorr.threshold = XCorr.threshold, confidence = confidence, contaminant = contaminant,
remove.na = remove.na, color = color, mark.bare = mark.bare, mark.color = mark.color,
mark.alpha = mark.alpha, show.table = show.table, table.position = table.position,
table.size = table.size, table.color = table.color, range.size = range.size, range.position = range.position
)
# add theme
if (range.position == "in") {
protein.plot +
theme_protein()
} else if (range.position == "out") {
protein.plot +
theme_protein2()
}
}