test-main.R 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. CALDER_CLI=file.path(system.file("scripts", package="CALDER"), "calder")
  2. test_that("CALDER works with cool files", {
  3. input_cool_path <- file.path(testthat::test_path("data"), "test.cool")
  4. output_path <- testthat::test_path("test-main-cool-out")
  5. CMD = paste0(CALDER_CLI, " -i ", input_cool_path, " -t cool -g hg38 -o ", output_path)
  6. system(CMD)
  7. expect_snapshot_file(file.path(output_path, "sub_compartments", "all_sub_compartments.bed"), name = "TestCool_all_sub_compartments.bed")
  8. expect_snapshot_file(file.path(output_path, "sub_compartments", "all_sub_compartments.tsv"), name = "TestCool_all_sub_compartments.tsv")
  9. expect_snapshot_file(file.path(output_path, "sub_domains", "all_nested_boundaries.bed"), name = "TestCool_all_nested_boundaries.bed")
  10. unlink(output_path, recursive=TRUE)
  11. })
  12. test_that("CALDER works with dumps", {
  13. chrs = c(21:22)
  14. ## demo contact matrices in dump format
  15. contact_file_dump = as.list(system.file("extdata", sprintf("mat_chr%s_10kb_ob.txt.gz", chrs),
  16. package='CALDER'))
  17. names(contact_file_dump) = chrs
  18. output_path <- testthat::test_path("test-main-dump-out")
  19. ## Run CALDER to compute compartments but not nested sub-domains
  20. CALDER(contact_file_dump=contact_file_dump,
  21. chrs=chrs,
  22. bin_size=10E3,
  23. genome='hg19',
  24. save_dir=output_path,
  25. save_intermediate_data=FALSE,
  26. n_cores=2,
  27. sub_domains=FALSE)
  28. expect_snapshot_file(file.path(output_path, "sub_compartments", "all_sub_compartments.bed"), name = "TestDump_all_sub_compartments.bed")
  29. expect_snapshot_file(file.path(output_path, "sub_compartments", "all_sub_compartments.tsv"), name = "TestDump_all_sub_compartments.tsv")
  30. unlink(output_path, recursive=TRUE)
  31. })
  32. test_that("CALDER works with custom feature track", {
  33. input_cool_path <- file.path(testthat::test_path("data"), "test.cool")
  34. feature_track_path <- file.path(testthat::test_path("data"), "test_gene_coverage.bed")
  35. output_path <- testthat::test_path("test-main-featuretrack-out")
  36. CMD = paste0(CALDER_CLI, " -i ", input_cool_path, " -t cool -g hg38 -o ", output_path, " -f ", feature_track_path)
  37. system(CMD)
  38. expect_snapshot_file(file.path(output_path, "sub_compartments", "all_sub_compartments.bed"), name = "TestFeatureTrack_all_sub_compartments.bed")
  39. expect_snapshot_file(file.path(output_path, "sub_compartments", "all_sub_compartments.tsv"), name = "TestFeatureTrack_all_sub_compartments.tsv")
  40. expect_snapshot_file(file.path(output_path, "sub_domains", "all_nested_boundaries.bed"), name = "TestFeatureTrack_all_nested_boundaries.bed")
  41. unlink(output_path, recursive=TRUE)
  42. })