-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from mattssca/test_branch
New unit tests and minor improvements
- Loading branch information
Showing
12 changed files
with
189 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.Rproj.user | ||
.DS_Store | ||
my_bed.bed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# BioMaesteR | ||
A package with convenience functions for generic genomic analysis within R. | ||
Standardized, generic functions as well as bundled data objects that can be | ||
called in various settings in the scope of biological analysis in R. | ||
This package is specialized to provide bioinformatics infrastructure that can be | ||
used in a variety of analysis. | ||
# <img src="biomaesteR.png" align="right" alt="" width="120" /> | ||
# biomaesteR | ||
This is biomaesteR, an R package with convenience functions commonly requested in various types of genomic analysis within R. This package is specialized to provide bioinformatics infrastructure that can be | ||
used in a variety of genomic analysis. | ||
|
||
This repo is also an ongoing project intended for demonstrating and following best-practices in development of R packages. This includes adequate package documentation (functions, bundled data objects, etc.), reproducible unit tests and vignettes. Upon Pull Requests, this repo also executes a GitAction workflow where the package is installed in various environments and thorough testing of the complete code base. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#load packages | ||
library(testthat) | ||
|
||
test_that("bin_splitter returns correct number of bins", { | ||
result <- bin_splitter(qchrom = c("chr1"), qstart = c(1), qend = c(1001), bin_size = 100) | ||
expect_equal(nrow(result), 10) | ||
}) | ||
|
||
test_that("bin_splitter returns correct bin size", { | ||
result <- bin_splitter(qchrom = c("chr1"), qstart = c(1), qend = c(1000), bin_size = 100) | ||
expect_equal(result$bin_end[1] - result$bin_start[1], 100) | ||
}) | ||
|
||
test_that("bin_splitter handles multiple regions", { | ||
result <- bin_splitter(qchrom = c("chr1", "chr2"), qstart = c(1, 1001), qend = c(1001, 2001), bin_size = 100) | ||
expect_equal(nrow(result), 20) | ||
}) | ||
|
||
test_that("bin_splitter handles regions data frame", { | ||
my_regions <- data.frame(chrom = c("chr1", "chr2"), start = c(1, 1000), end = c(1001, 2001)) | ||
result <- bin_splitter(these_regions = my_regions, bin_size = 100) | ||
expect_equal(nrow(result), 20) | ||
}) | ||
|
||
test_that("bin_splitter returns correct chromosome names", { | ||
result <- bin_splitter(qchrom = c("chr1", "chr2"), qstart = c(1, 1001), qend = c(1000, 2000), bin_size = 100) | ||
expect_equal(unique(result$bin_chr), c("chr1", "chr2")) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
library(testthat) | ||
|
||
test_that("gene_ranger throws error with no genes", { | ||
expect_error(gene_ranger()) | ||
}) | ||
|
||
test_that("gene_ranger throws error with invalid projection", { | ||
expect_error(gene_ranger(these_genes = "MYC", projection = "invalid")) | ||
}) | ||
|
||
test_that("gene_ranger throws error with invalid return format", { | ||
expect_error(gene_ranger(these_genes = "MYC", return_as = "invalid")) | ||
}) | ||
|
||
test_that("gene_ranger throws error when write_to_bed is TRUE but bed_path, track_name, or track_description is not provided", { | ||
expect_error(gene_ranger(these_genes = "MYC", write_to_bed = TRUE), "Provide a path for output bed file") | ||
expect_error(gene_ranger(these_genes = "MYC", write_to_bed = TRUE, bed_path = "my_bed"), "Provide a track name for output bed file") | ||
expect_error(gene_ranger(these_genes = "MYC", write_to_bed = TRUE, bed_path = "my_bed", track_name = "MYC"), "Provide a track description for output bed file") | ||
}) | ||
|
||
test_that("gene_ranger runs successfully with valid input", { | ||
expect_silent(gene_ranger(these_genes = "MYC")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#load pacakges | ||
#load packages | ||
library(testthat) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
library(testthat) | ||
|
||
test_that("purify_chr throws error with no projection", { | ||
expect_error(purify_chr(), "You must provide a valid projection") | ||
}) | ||
|
||
test_that("purify_chr throws error with no incoming_table", { | ||
expect_error(purify_chr(projection = "hg38"), "You must provide a data table with `incoming_table`") | ||
}) | ||
|
||
test_that("purify_chr throws error with invalid projection", { | ||
expect_error(purify_chr(projection = "invalid", incoming_table = data.frame(chrom = c("1", "2", "3"))), "This function supports the following projections") | ||
}) | ||
|
||
test_that("purify_chr adds 'chr' prefix for hg38 projection", { | ||
df = data.frame(chrom = c("1", "2", "3")) | ||
result = purify_chr(projection = "hg38", incoming_table = df) | ||
expect_equal(result$chrom, c("chr1", "chr2", "chr3")) | ||
}) | ||
|
||
test_that("purify_chr removes 'chr' prefix for grch37 projection", { | ||
df = data.frame(chrom = c("chr1", "chr2", "chr3")) | ||
result = purify_chr(projection = "grch37", incoming_table = df) | ||
expect_equal(result$chrom, c("1", "2", "3")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library(testthat) | ||
|
||
test_that("purify_regions handles single region string", { | ||
result <- purify_regions(these_regions = "chr1:100-500") | ||
expect_equal(nrow(result), 1) | ||
expect_equal(result$chrom, "chr1") | ||
expect_equal(result$start, 100) | ||
expect_equal(result$end, 500) | ||
}) | ||
|
||
test_that("purify_regions handles multiple region strings", { | ||
result <- purify_regions(these_regions = c("chr1:100-500", "chr2:100-500")) | ||
expect_equal(nrow(result), 2) | ||
expect_equal(result$chrom, c("chr1", "chr2")) | ||
expect_equal(result$start, c(100, 100)) | ||
expect_equal(result$end, c(500, 500)) | ||
}) | ||
|
||
test_that("purify_regions handles individual region parameters", { | ||
result <- purify_regions(qchrom = "chr1", qstart = 100, qend = 500) | ||
expect_equal(nrow(result), 1) | ||
expect_equal(result$chrom, "chr1") | ||
expect_equal(result$start, 100) | ||
expect_equal(result$end, 500) | ||
}) | ||
|
||
test_that("purify_regions handles multiple individual region parameters", { | ||
result <- purify_regions(qchrom = c("chr1", "chr2"), qstart = c(100, 200), qend = c(500, 600)) | ||
expect_equal(nrow(result), 2) | ||
expect_equal(result$chrom, c("chr1", "chr2")) | ||
expect_equal(result$start, c(100, 200)) | ||
expect_equal(result$end, c(500, 600)) | ||
}) | ||
|
||
test_that("purify_regions handles data frame input", { | ||
my_regions <- data.frame(chrom = c("chr1", "chr2"), start = c(100, 200), end = c(500, 600)) | ||
result <- purify_regions(these_regions = my_regions) | ||
expect_equal(nrow(result), 2) | ||
expect_equal(result$chrom, c("chr1", "chr2")) | ||
expect_equal(result$start, c(100, 200)) | ||
expect_equal(result$end, c(500, 600)) | ||
}) | ||
|
||
test_that("purify_regions throws error with incorrect input", { | ||
expect_error(purify_regions(qchrom = "chr1", qstart = 100)) | ||
expect_error(purify_regions(these_regions = data.frame(chrom = c("chr1", "chr2"), start = c(100, 200), end = c(50, 100)))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
library(testthat) | ||
|
||
test_that("region_ranger throws error with no regions", { | ||
expect_error(region_ranger()) | ||
}) | ||
|
||
test_that("region_ranger throws error with invalid projection", { | ||
expect_error(region_ranger(these_regions = "chr8:127735434-127742951", projection = "invalid"), "This function supports the following projections") | ||
}) | ||
|
||
test_that("region_ranger returns correct number of columns when raw is FALSE", { | ||
result = region_ranger(these_regions = "chr8:127735434-127742951") | ||
expect_equal(ncol(result), 11) | ||
}) | ||
|
||
test_that("region_ranger returns all columns when raw is TRUE", { | ||
result = region_ranger(these_regions = "chr8:127735434-127742951", raw = TRUE) | ||
expect_true(ncol(result) > 11) | ||
}) | ||
|
||
test_that("region_ranger returns warning when no genes found", { | ||
expect_warning(region_ranger(these_regions = "chr1:1-10")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
library(testthat) | ||
|
||
test_that("sanity_check_regions throws error with no regions", { | ||
expect_error(sanity_check_regions(), "No regions provided") | ||
}) | ||
|
||
test_that("sanity_check_regions throws error with invalid projection", { | ||
my_regions <- data.frame(chrom = c("chr1"), start = c(100), end = c(200)) | ||
expect_error(sanity_check_regions(incoming_regions = my_regions, projection = "invalid"), "Invalid projection specified") | ||
}) | ||
|
||
test_that("sanity_check_regions throws error when start is greater than end", { | ||
my_regions <- data.frame(chrom = c("chr1"), start = c(200), end = c(100)) | ||
expect_error(sanity_check_regions(incoming_regions = my_regions, projection = "hg38"), "start is greater than or equal to end") | ||
}) | ||
|
||
test_that("sanity_check_regions throws error when start or end is outside chromosomal range", { | ||
my_regions <- data.frame(chrom = c("chr1"), start = c(100), end = c(300000000)) | ||
expect_error(sanity_check_regions(incoming_regions = my_regions, projection = "hg38"), "Specified start or end coordinates fall outside the actual chromosomal range") | ||
}) | ||
|
||
test_that("sanity_check_regions runs successfully with valid input", { | ||
my_regions <- data.frame(chrom = c("chr1"), start = c(100), end = c(200)) | ||
expect_silent(sanity_check_regions(incoming_regions = my_regions, projection = "hg38")) | ||
}) | ||
|
||
test_that("sanity_check_regions runs successfully with valid input", { | ||
my_regions <- data.frame(chrom = c("1"), start = c(100), end = c(200)) | ||
expect_silent(sanity_check_regions(incoming_regions = my_regions, projection = "grch37")) | ||
}) | ||
|