tests/testthat/test-PomaOddsRatio.R

context("PomaOddsRatio")

test_that("PomaOddsRatio works", {

  data("st000336")

  imputed <- POMA::PomaImpute(st000336, method = "knn")
  
  norm_none <- PomaNorm(imputed, method = "none")
  norm_ls <- PomaNorm(imputed, method = "log_scaling")

  a <- PomaOddsRatio(norm_none, feature_name = c("glutamic_acid", "glutamine", "glycine", "histidine", "isoleucine", "leucine", "lysine"))$OddsRatioPlot
  b <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "glutamine", "glycine", "histidine", "isoleucine", "leucine", "lysine"))$OddsRatioPlot

  c <- PomaOddsRatio(norm_ls, feature_name = "glutamic_acid")$OddsRatioPlot
  d <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "arginine"))$OddsRatioPlot

  df_a <- layer_data(a)
  df_b <- layer_data(b)

  df_c <- layer_data(c)
  df_d <- layer_data(d)

  ##

  expect_equal(nrow(df_a), nrow(df_b))
  expect_false(nrow(df_c) == nrow(df_d))

  ##

  e <- PomaOddsRatio(norm_none)$OddsRatioTable
  f <- PomaOddsRatio(norm_ls)$OddsRatioTable
  g <- PomaOddsRatio(norm_ls, feature_name = "glutamic_acid")$OddsRatioTable
  h <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "arginine"))$OddsRatioTable
  h_1 <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "arginine"), covariates = TRUE)$OddsRatioTable

  ##

  expect_equal(dim(e), dim(f))
  expect_false(nrow(f) == nrow(g))
  expect_false(nrow(g) == nrow(h))
  expect_false(nrow(h) == nrow(h_1))

  ##

  i <- PomaOddsRatio(norm_ls, feature_name = NULL, covariates = TRUE)$OddsRatioTable
  j <- PomaOddsRatio(norm_ls, feature_name = NULL, covariates = FALSE)$OddsRatioTable

  ##

  expect_false(nrow(i) == nrow(j))

  ##

  k <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "glutamine", "glycine", "histidine", "isoleucine", "leucine", "lysine"))$OddsRatioPlot
  l <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "glutamine", "glycine", "histidine", "isoleucine", "leucine", "lysine"), showCI = FALSE)$OddsRatioPlot
  m <- PomaOddsRatio(norm_ls, feature_name = c("glutamic_acid", "glutamine", "glycine", "histidine", "isoleucine", "leucine", "lysine"), showCI = FALSE, covariates = TRUE)$OddsRatioPlot

  df_k <- layer_data(k)
  df_l <- layer_data(l)
  df_m <- layer_data(m)

  ##

  expect_equal(nrow(df_k), nrow(df_l))
  expect_false(nrow(df_l) == nrow(df_m))

  ##

  expect_error(PomaOddsRatio(norm_ls, feature_name = "hello"))
  expect_error(PomaOddsRatio(norm_ls, feature_name = "glutamic_aci"))
  expect_error(PomaOddsRatio(norm_ls, feature_name = c("glutamic_aci", "arginine")))

  ##

  Biobase::pData(imputed) <- Biobase::pData(imputed)[1]
  expect_error(PomaOddsRatio(imputed, covariates = TRUE))
  
  ##
  
  expect_error(PomaOddsRatio())
  expect_error(PomaOddsRatio(iris))

})

Try the POMA package in your browser

Any scripts or data that you put into this service are public.

POMA documentation built on Nov. 8, 2020, 6:26 p.m.