tests/testthat/test_get_peptide_coverage.R

context("test: get_peptide_coverage")

test_that("Testing get peptide coverage function", {

  # Download required test files------------------------------------------------

  source(system.file("tests/testthat/file_check.R", package = "pspecterlib"))
  downfolder <- file_check("downfolder")
  BU_ScanMetadata <- file_check("BU")
  ProteinTable <- readRDS(system.file("testdata", "ProteinTable.RDS", package = "pspecterlib"))

  # Test get_peptide_coverage input checks--------------------------------------

  # Scan Metadata object should be a scan_metadata object
  expect_error(
    get_peptide_coverage(data.frame(test = 1)),
    "ScanMetadata must be a scan_metadata object generated by get_scan_metadata."
  )

  # Protein Table should be a protein_table object
  expect_error(
    get_peptide_coverage(BU_ScanMetadata, data.frame(test = 1)),
    "ProteinTable must be a protein_table object generated by get_protein_table."
  )

  # Protein ID must be a string
  expect_error(
    get_peptide_coverage(
      ScanMetadata = BU_ScanMetadata,
      ProteinTable = ProteinTable,
      ProteinID = 1
    ),
    "Protein must be a single string."
  )

  # Protein ID must be in the list
  expect_error(
    get_peptide_coverage(
      ScanMetadata = BU_ScanMetadata,
      ProteinTable = ProteinTable,
      ProteinID = "ProteinA"
    ),
    "Protein must be in the ProteinTable. ProteinA was not found."
  )

  # Create the peptide coverage object------------------------------------------

  # Run a standard example
  PeptideCoverage <- get_peptide_coverage(
    ScanMetadata = BU_ScanMetadata,
    ProteinTable = ProteinTable,
    ProteinID = "SO_0225"
  )
  expect_true(inherits(PeptideCoverage, "peptide_coverage"))

  # Run an example with a high Q value maximum and Score maximum
  BU_ScanMetadata$`Q Value` <- runif(nrow(BU_ScanMetadata))
  suppressWarnings({PeptideCoverage2 <- get_peptide_coverage(
    ScanMetadata = BU_ScanMetadata,
    ProteinTable = get_protein_table(BU_ScanMetadata, file.path(downfolder, "QC_Shew.fasta"),
                                     QValueMaximum = 0.5, ScoreMaximum = 0.5),
    "SO_0225"
  )})
  expect_true(inherits(PeptideCoverage2, "peptide_coverage"))

  # Run an example without score
  BU_ScanMetadata$Score <- NA
  suppressWarnings({PeptideCoverage3 <- get_peptide_coverage(
    ScanMetadata = BU_ScanMetadata,
    ProteinTable = ProteinTable,
    "SO_0225"
  )})
  expect_true(inherits(PeptideCoverage3, "peptide_coverage"))

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