Skip to content

Commit b969d2a

Browse files
authored
Merge pull request #4 from EMSL-Computing/develop
Additional package CHNOSZ added to manage more difficult molecular formula annotations
2 parents 8327527 + c517b14 commit b969d2a

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: pspecterlib
22
Type: Package
33
Title: PSpecteR Library - Visualization tools for top-down and bottom-up proteomics data
4-
Version: 1.0.0
4+
Version: 1.0.1
55
Date: 2022-10-03
66
Authors@R: c(person("David", "Degnan", email = "[email protected]", role = c("aut", "cre")))
77
Description: Provides functionality to visually examine LC-MS top-down and bottom-up proteomics data. Supports reading various mass spectrometry files, labeling spectra with fragmenetation patterns, testing post-translational modifications, plotting where identified fragments map to reference sequences, and visualizing algorithmic output from database search tools (MSPathFinder) and metadata.
@@ -30,7 +30,8 @@ Imports:
3030
tidyr,
3131
htmltools,
3232
RColorBrewer,
33-
isopat
33+
isopat,
34+
CHNOSZ
3435
Suggests:
3536
rmarkdown,
3637
knitr

R/molform_functions.R

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#' # Generate a molecular formula object
1616
#' as.molform("C6H12O6")
1717
#'
18+
#' # Duplicates should be added
19+
#' as.molform("CHCO3")
20+
#'
1821
#' # This should fail, as 'Ot' and 'Lp' are not elements
1922
#' as.molform("C6H12Ot5Lp2")
2023
#'
@@ -32,9 +35,6 @@ as.molform <- function(MolForm) {
3235
stop("MolForm must be a single string.")
3336
}
3437

35-
# Split out elements
36-
Elements <- strsplit(MolForm, "-?[0-9]") %>% unlist() %>% .[. != ""]
37-
3838
# List acceptable elements
3939
AcceptableElements <- c(
4040
"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al",
@@ -46,27 +46,24 @@ as.molform <- function(MolForm) {
4646
"Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn",
4747
"Fr", "Ra", "Ac", "Th", "Pa", "U"
4848
)
49-
50-
# Check for non-established elements
51-
NonEstablished <- Elements[Elements %in% AcceptableElements == FALSE]
52-
53-
if (length(NonEstablished) != 0) {
54-
stop(paste("The elements", paste0(NonEstablished, collapse = ", "),
55-
"are not supported at this time."))
49+
50+
# Extract element names
51+
AtomVec <- CHNOSZ::makeup(MolForm)
52+
53+
# Make sure elements match
54+
if (!all(names(AtomVec) %in% AcceptableElements)) {
55+
stop(paste("The following are not acceptable elements:",
56+
paste0(names(AtomVec)[names(AtomVec) %in% AcceptableElements == FALSE], collapse = ", ")))
5657
}
57-
58+
5859
#########################
5960
## GENERATE ATTRIBUTES ##
6061
#########################
6162

62-
# Pull elemental counts
63-
Counts <- strsplit(MolForm, "[[:alpha:]]") %>% unlist() %>% .[. != ""] %>% as.numeric()
64-
Counts <- round(Counts)
65-
6663
# Fill an atomic vector
6764
AtomList <- rep(0, length(AcceptableElements))
6865
names(AtomList) <- AcceptableElements
69-
AtomList[Elements] <- Counts
66+
AtomList[names(AtomVec)] <- AtomVec
7067

7168
# Add a class
7269
class(AtomList) <- c(class(AtomList), "molform")

man/as.molform.Rd

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

test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)