tests/testthat/test_count_ion_annotations.R

context("test: count_ion_annotations")

test_that("Testing annotated ion count function", {

  # Load test files-------------------------------------------------------------

  # Read BU Match
  BU_Match <- readRDS(system.file("testdata", "BU_Match.RDS", package = "pspecterlib"))

  # Test count_ion_annotations input checks-------------------------------------

  # MatchedPeaks must be of the appropriate class
  expect_error(
    count_ion_annotations(data.frame(test = 1)),
    "MatchedPeaks is not an object of the matched_peaks class generated by get_matched_peaks."
  )

  # Include Isotopes should be a True or False
  expect_error(
    count_ion_annotations(BU_Match, NA),
    "IncludeIsotopes needs to be a single logical: a TRUE or FALSE."
  )

  # Create the count ion table object-------------------------------------------

  # Regardless of whether isotopes are included or not, 47 residues should be in the total
  Count1 <- count_ion_annotations(BU_Match, TRUE)
  Count2 <- count_ion_annotations(BU_Match)
  expect_true(nrow(Count1) == 47)
  expect_true(nrow(Count2) == 47)

  # Isotope count total is 65 with isotopes, and 38 without
  expect_true(sum(Count1$`Number of Ions`) == 65)
  expect_true(sum(Count2$`Number of Ions`) == 38)


})
EMSL-Computing/pspecterlib documentation built on Jan. 28, 2024, 8:13 p.m.