tests/testthat/test-predict_ic50s.R

test_that("peptide lengths must be at most 15", {

  if (!is_mhcnuggets_installed()) return()

  peptide <- "AIAACAMLLVCCCCCC"
  n_rows_expected <- nchar(peptide) - 15 + 1
  first_peptide_expected <- substr(peptide, 1, 15)
  second_peptide_expected <- substr(peptide, 2, 16)

  mhcnuggets_options <- create_mhcnuggets_options(
    mhc_class = "I",
    mhc = "HLA-A02:01"
  )

  df <- predict_ic50s(
    protein_sequence = peptide,
    peptide_length = 15,
    mhcnuggets_options = mhcnuggets_options
  )

  expect_true("peptide" %in% names(df))
  expect_true("ic50" %in% names(df))
  expect_equal("character", class(df$peptide))
  expect_equal("numeric", class(df$ic50))
  expect_equal(n_rows_expected, nrow(df))
  expect_equal(df$peptide[1], first_peptide_expected)
  expect_equal(df$peptide[2], second_peptide_expected)
})

test_that("peptide lengths must be at most 15", {

  if (!is_mhcnuggets_installed()) return()

  expect_error(
    predict_ic50s(
      mhcnuggets_options = create_test_mhcnuggets_options(),
      protein_sequence = "AIAACAMLLVCCCCCC",
      peptide_length = 16
    ),
    "'peptide_length' must be 15 at most"
  )
})

test_that("peptide lengths must be long enough", {

  if (!is_mhcnuggets_installed()) return()

  expect_error(
    predict_ic50s(
      mhcnuggets_options = create_test_mhcnuggets_options(),
      protein_sequence = "FAMILYVW",
      peptide_length = 9
    ),
    "'protein_sequence' must have more characters than 'peptide_length'"
  )
})
richelbilderbeek/mhcnuggetsr documentation built on Nov. 9, 2023, 10 p.m.