knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(knitr)
library(mhcnuggetsr)
library(testthat)

For this vignette, we use the same example as the MHCnuggets Python notebooks.

Get the path to the testing peptides, and show them:

if (is_mhcnuggets_installed()) {
  peptides_path <- get_example_filename("test_peptides.peps")
  expect_true(file.exists(peptides_path))
  readLines(peptides_path, warn = FALSE)
}

Pick an MHC-I haplotype:

if (is_mhcnuggets_installed()) {
  mhc_1_haplotype <- "HLA-A02:01"
  expect_true(mhc_1_haplotype %in% get_trained_mhc_1_haplotypes())
}

Predict:

#{r mhc1_predict_ic50_from_file_no_ba_models}
if (is_mhcnuggets_installed()) {
  mhcnuggets_options <- create_mhcnuggets_options(
    mhc = mhc_1_haplotype
  )
  df <- predict_ic50_from_file(
    peptides_path = peptides_path,
    mhcnuggets_options = mhcnuggets_options
  )
  kable(df)
}

Predict:

#{r mhc1_predict_ic50_from_file_ba_models}
if (is_mhcnuggets_installed()) {
  mhcnuggets_options <- create_mhcnuggets_options(
    mhc = mhc_1_haplotype,
    ba_models = TRUE
  )
  df <- predict_ic50_from_file(
    peptides_path = peptides_path,
    mhcnuggets_options = mhcnuggets_options
  )
  kable(df)
}

Use MCH-II haplotype:

if (is_mhcnuggets_installed()) {
  mhc_2_haplotype <- "HLA-DRB101:01"
  expect_true(mhc_2_haplotype %in% get_trained_mhc_2_haplotypes())
}

Predict:

#{r mhc2_predict_ic50_from_file_no_ba_models}
if (is_mhcnuggets_installed()) {
  mhcnuggets_options <- create_mhcnuggets_options(
    mhc = mhc_2_haplotype
  )
  df <- predict_ic50_from_file(
    peptides_path = peptides_path,
    mhcnuggets_options = mhcnuggets_options
  )
  kable(df)
}

Use another MHC-I haplotype. In this case, MHCnuggets has not been trained upon it, but it is a valid supertype:

if (is_mhcnuggets_installed()) {
  mhc_1_haplotype <- "HLA-A02:60"
  expect_false(mhc_1_haplotype %in% get_trained_mhc_1_haplotypes())
}

Predict:

#{r predict_mhc_1_haplotype_supertype}
if (is_mhcnuggets_installed()) {
  mhcnuggets_options <- create_mhcnuggets_options(
    mhc_class = "I",
    mhc = mhc_1_haplotype
  )
  df <- predict_ic50_from_file(
    peptides_path = peptides_path,
    mhcnuggets_options = mhcnuggets_options
  )
  kable(df)
}

Appendix

All example files

if (is_mhcnuggets_installed()) {
  basename(get_example_filenames())
}

All MHC-I haplotypes

These are the MHC-I haplotypes that have a trained model.

if (is_mhcnuggets_installed()) {
  cat(get_trained_mhc_1_haplotypes())
}

All MHC-II haplotypes

These are the MHC-II haplotypes that have a trained model.

if (is_mhcnuggets_installed()) {
  cat(get_trained_mhc_2_haplotypes())
}

Session info

mhcnuggetsr_report()


richelbilderbeek/mhcnuggetsr documentation built on Nov. 9, 2023, 10 p.m.