#' Displays the literature sequence with identified residues for a specific protein
#'
#' @description A plot of the literature sequence with identified fragment residues in green
#'
#' @param PeptideCoverage A "peptide_coverage" object generated by get_peptide_coverage. Required.
#'
#' @examples
#' \dontrun{
#'
#' # Make Peptide Coverage Object
#' PeptideCoverage <- get_peptide_coverage(ScanMetadata = BU_ScanMetadata, ProteinTable = ProteinTable, ProteinID = "SO_0225")
#'
#' # Make plot
#' coverage_lit_seq_plot(PeptideCoverage)
#'
#' }
#'
#' @export
coverage_lit_seq_plot <- function(PeptideCoverage) {
##################
## CHECK INPUTS ##
##################
# Assert that PeptideCoverage is a "peptide_coverage" object
if ("peptide_coverage" %in% class(PeptideCoverage) == FALSE) {
stop("PeptideCoverage must be an object of the peptide_coverage class generated by get_peptide_coverage.")
}
##############################
## GENERATE PLOT AESTHETICS ##
##############################
# Pull literature sequence and residue count
LitSeq <- PeptideCoverage$PeptidesByPosition[PeptideCoverage$PeptidesByPosition$`Scan Number` == 0, "Sequence"] %>% unlist()
Residues <- PeptideCoverage$ResidueCount
# Get size
sizeTest <- nchar(LitSeq) / 60
if (sizeTest <= 5) {
size <- 10
} else if (sizeTest <= 10) {
size <- 8
} else if (sizeTest <= 20) {
size <- 6
} else {
size <- 4
}
# Make plotting data.table
LitSeqDF <- data.table::data.table(
"x" = rep_len(1:60, nchar(LitSeq)),
"y" = (1:nchar(LitSeq) / -60) %>% floor(),
"Residue" = LitSeq %>% strsplit("") %>% unlist(),
"Ref" = ifelse(1:nchar(LitSeq) %in% Residues$Position, "In Scans", "Not in Scans")
)
###############
## MAKE PLOT ##
###############
return(
ggplot2::ggplot(LitSeqDF, ggplot2::aes(x = x, y = y, label = Residue, color = Ref)) +
ggplot2::geom_text(size = size) + ggplot2::theme_void() +
ggplot2::theme(legend.title = ggplot2::element_blank()) +
ggplot2::scale_color_manual(values = list("In Scans" = "forestgreen", "Not in Scans" = "black"))
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.