Skip to content

Commit

Permalink
fix: fix documentation and vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Feb 9, 2022
1 parent e2de7d3 commit e3a622b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 67 deletions.
85 changes: 41 additions & 44 deletions R/kendrickMass.R
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
#' @title m/z matching
#' @title Kendrick mass defects
#'
#' @name calculateKendrickMass
#'

#'
#' @description
#'
#' Kendrick mass defect analysis is a way to analyze high-resolution MS data in
#' order to identify homologous series. The Kendrick mass (KM) is calculated by
#' order to identify homologous series. The Kendrick mass (KM) is calculated by
#' choosing a specific molecular fragment (e.g. CH2) and settings its mass to an
#' integer mass. In case of CH2 the mass of 14.01565 would be set to 14.The
#' Kendrick mass defect (KMD) is defined as the difference between the KM and
#' the nominial (integer) KM. All molecules of homologoues series, e.g. only
#' integer mass. In case of CH2 the mass of 14.01565 would be set to 14.The
#' Kendrick mass defect (KMD) is defined as the difference between the KM and
#' the nominial (integer) KM. All molecules of homologoues series, e.g. only
#' differing in the number of CH2, will have an identical KMD. In an additional
#' step the KMD can be referenced to the mass defect of specific lipid backbone
#' and by this normalize values to the referenced KMD (RKMD). This leads to
#' step the KMD can be referenced to the mass defect of specific lipid backbone
#' and by this normalize values to the referenced KMD (RKMD). This leads to
#' values of 0 for saturated species or -1, -2, -3, etc for unsaturated species.
#'
#'
#' Available functoins are:
#'
#' - `calculateKm`: calculates the Kendrick mass from an exact mass for a
#' specific molecular fragment, e.g. "CH2".
#'
#' - `calculateKm`: calculates the Kendrick mass from an exact mass for a
#' specific molecular fragment, e.g. `"CH2"`.
#' - `calculateKmd`: calculates the Kendrick mass defect from an exact mass for
#' a specific molecular fragment, e.g. "CH2"
#' - `calculateRkmd`: calculates the referenced Kendrick mass defect from an
#' exact mass for a specific molecular fragment, e.g. "CH2", and a reference
#' a specific molecular fragment, e.g. `"CH2"`.
#' - `calculateRkmd`: calculates the referenced Kendrick mass defect from an
#' exact mass for a specific molecular fragment, e.g. `"CH2"`, and a reference
#' KMD.
#' - `isRkmd`: Checks if a calculated RKMD falls within a specific error range
#' around an negative integer corresponding the number of double bonds, in
#' around an negative integer corresponding the number of double bonds, in
#' case of CH2 as fragment.
#'
#' @param x `numeric` Vector with exact masses or calculated RKMDs in case of
#' `isRkmd`
#' @param framgent `numeric(1)` or `character(1)` corresponding factor or molecular
#' formula of molecular fragment, e.g. 14 /14.01565 or "CH2" for CH2.
#' @param rkmd `numeric(1)` KMD used for referencing of KMDs
#' @param rkmdTolerance `numeric(1)` Tolerance to check if RKMD fall around a
#'
#' @param x `numeric` with exact masses or calculated RKMDs in case of `isRkmd`.
#'
#' @param fragment `numeric(1)` or `character(1)` corresponding factor or
#' molecular formula of molecular fragment, e.g. `14 / 14.01565` or `"CH2"`
#' for CH2.
#'
#' @param rkmd `numeric(1)` KMD used for referencing of KMDs.
#'
#' @param rkmdTolerance `numeric(1)` Tolerance to check if RKMD fall around a
#' negative integer corresponding to the number of double bonds
#'
#' @return `numeric` or `boolean` All functions, except `isRkmd` return a numeric
#' with same length as the input corresponding to the KM, KMD or RMKD.
#' `isRkmd` returns a list TRUE or FALSE indicating if the RKMD falls within
#' a specific range around a negative integer corresponding to the number
#' of double bonds
#'
#'
#'
#' @return `numeric` or `boolean`. All functions, except `isRkmd` return a
#' `numeric` with same length as the input corresponding to the KM, KMD or
#' RMKD.
#' `isRkmd` returns a `logical` with `TRUE` or `FALSE` indicating if the
#' RKMD falls within a specific range around a negative integer
#' corresponding to the number of double bonds.
#'
#' @author Michael Witting
#'
#'
#' @examples
#'
#' calculateKm(760.5851)
#'
#' calculateKmd(760.5851)
#'
#' calculateRkmd(760.5851, rkmd = 0.749206)
#'
#' isRkmd(calculateRkmd(760.5851, rkmd = 0.749206))
#'
#' isRkmd(calculateRkmd(760.5851, rkmd = 0.749206))
#'
NULL


#' @rdname calculateKendrickMass
#'
#'
#' @export
calculateKm <- function(x, fragment = 14.00000 / 14.01565) {
if(is.numeric(fragment)) {
Expand All @@ -74,27 +75,23 @@ calculateKm <- function(x, fragment = 14.00000 / 14.01565) {
}

#' @rdname calculateKendrickMass
#'
#'
#' @export
calculateKmd <- function(x, fragment = 14.00000 / 14.01565) {
kendrick <- calculateKm(x, fragment)
kendrick - as.integer(kendrick)
}

#' @rdname calculateKendrickMass
#'
#'
#' @export
calculateRkmd <- function(x, fragment = 14.00000 / 14.01565, rkmd = 0.749206) {

(calculateKmd(x) - rkmd) / 0.013399

}

#' @rdname calculateKendrickMass
#'
#'
#' @export
isRkmd <- function(x, rkmdTolerance = 0.1) {

abs(round(x, digits = 0) - x) < rkmdTolerance

}
}
32 changes: 16 additions & 16 deletions man/calculateKendrickMass.Rd

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

14 changes: 7 additions & 7 deletions vignettes/MetaboCoreUtils.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ countElements(frml)
## Kendrick mass defect calculation

Lipids and other homologous series based on fatty acyls can be found in data by
using Kendrick mass defects (KMD) or referenced kendrick mass defects (RKMD). The
`MetaboCoreUtils` package provides functions to calculate everything around
Kendrick mass defects. The following example calculates the KMD and RKMD for
three lipids (PC(16:0/18:1(9Z)), PC(16:0/18:0), PS(16:0/18:1(9Z))) and checks,
if they fit the RKMD of PCs detected as [M+H]+ adducts.
using Kendrick mass defects (KMD) or referenced kendrick mass defects
(RKMD). The `MetaboCoreUtils` package provides functions to calculate everything
around Kendrick mass defects. The following example calculates the KMD and RKMD
for three lipids (PC(16:0/18:1(9Z)), PC(16:0/18:0), PS(16:0/18:1(9Z))) and
checks, if they fit the RKMD of PCs detected as [M+H]+ adducts.

```{r}
lipid_masses <- c(760.5851, 762.6007, 762.5280)
calculateKendrickMassDefect(lipid_masses)
calculateKmd(lipid_masses)
```

Next the RKMD is calculated and checked if it fits to a specific range. RKMDs
are either 0 or negative integers according to the number of double bonds in the
lipids, e.g. -2 if two double bonds are present in the lipids.

```{r}
lipid_rkmd <- calculateReferencedKendrickMassDefect(lipid_masses)
lipid_rkmd <- calculateRkmd(lipid_masses)
isRkmd(lipid_rkmd)
```

Expand Down

0 comments on commit e3a622b

Please sign in to comment.