tests/testthat/testFileImporting.R

context("Importing BED files of peaks and features")
library(PeakMapper)

test_that("Dataframe has correct dimensions",  {
  pathToPeaks <- system.file("extdata", "testPeaks.bed", package = "PeakMapper")
  pathToGenes <- system.file("extdata", "testGenes.bed", package = "PeakMapper")

  peaksForTesting <- importBED(pathToPeaks)
  genesForTesting <- importBED(pathToGenes)

  expect_equal(dim(peaksForTesting)[1], 5)
  expect_equal(dim(peaksForTesting)[2], 6)

  expect_equal(dim(genesForTesting)[1], 5)
  expect_equal(dim(genesForTesting)[2], 6)

})

test_that("Dataframe has correct column names",  {
  pathToPeaks <- system.file("extdata", "testPeaks.bed", package = "PeakMapper")
  pathToGenes <- system.file("extdata", "testGenes.bed", package = "PeakMapper")

  peaksForTesting <- importBED(pathToPeaks)
  genesForTesting <- importBED(pathToGenes)

  correctColNames <- c("Chr", "Start", "End", "Name", "Score", "Strand")

  expect_equal(colnames(peaksForTesting), correctColNames)
  expect_equal(colnames(genesForTesting), correctColNames)

})

test_that("Imported values are correct",  {
  pathToPeaks <- system.file("extdata", "testPeaks.bed", package = "PeakMapper")
  pathToGenes <- system.file("extdata", "testGenes.bed", package = "PeakMapper")

  peaksForTesting <- importBED(pathToPeaks)
  genesForTesting <- importBED(pathToGenes)

  expect_equal(peaksForTesting$Chr, c("chr1", "chr1", "chr2", "chr3", "chr2"))
  expect_equal(peaksForTesting$Start, c(100, 500, 200, 100, 1250))

  expect_equal(genesForTesting$End, c(2000, 450, 75, 1100, 200))
  expect_equal(genesForTesting$Name, c("Gene_1", "Gene_2", "Gene_3", "Gene_4",
                                       "Gene_5"))


})
fuscada2/PeakMapper documentation built on Dec. 8, 2019, 12:35 p.m.