Skip to content

Commit

Permalink
revised tests
Browse files Browse the repository at this point in the history
moved GenomicRanges and IRanges from Suggested packages to imported packages in DESCRIPTION
  • Loading branch information
rnbatra committed Jul 13, 2020
1 parent 7da4b19 commit 556ad7d
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 25 deletions.
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: false
Depends: R (>= 3.6), data.table (>= 1.12.4), SummarizedExperiment
Imports: DelayedArray, HDF5Array, BSgenome, rjson, DelayedMatrixStats, parallel, methods, ggplot2, matrixStats, graphics, stats, utils
RoxygenNote: 7.1.0
Imports: DelayedArray, HDF5Array, BSgenome, rjson, DelayedMatrixStats, parallel, methods, ggplot2, matrixStats, graphics, stats, utils, GenomicRanges, IRanges
RoxygenNote: 7.1.1
Suggests:
knitr,
rmarkdown,
Expand All @@ -26,9 +26,7 @@ Suggests:
GenomicScores,
Biostrings,
RColorBrewer,
GenomicRanges,
GenomeInfoDb,
IRanges,
testthat (>= 2.1.0)
VignetteBuilder: knitr
biocViews: DNAMethylation, Sequencing, Coverage
11 changes: 7 additions & 4 deletions R/methrix_operations.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ get_region_summary = function(m, regions = NULL, type = "M", how = "mean", ov

start_proc_time = proc.time()


if("data.table" %in% class(regions)) regions<-makeGRangesFromDataFrame(df = regions)

target_regions = (regions)
#Add a unique id for every target range (i.e, rows)
target_regions@elementMetadata$rid <- paste0("rid_", 1:length(target_regions))
Expand All @@ -39,7 +42,7 @@ get_region_summary = function(m, regions = NULL, type = "M", how = "mean", ov
r_dat$seqnames<-as.character(r_dat$chr)
r_dat$chr<-NULL
if(is.null(r_dat$end)) r_dat$end<-r_dat$start+1
r_dat<- GenomicRanges::makeGRangesFromDataFrame(r_dat, keep.extra.columns = F)
r_dat<- makeGRangesFromDataFrame(r_dat, keep.extra.columns = F)


if(!all(elementMetadata.col %in% colnames(m@elementMetadata))) stop("variables provided to elementMetadata.col not correct")
Expand Down Expand Up @@ -121,7 +124,7 @@ get_region_summary = function(m, regions = NULL, type = "M", how = "mean", ov

output<-output[order(output$rid),]
setnames(output, "seqnames", "chr")
keep=c("chr","start","end","n_overlap_CpGs","rid",elementMetadata.col,colnames(m))
keep<-c("chr","start","end","n_overlap_CpGs","rid",elementMetadata.col,colnames(m))
output<-output[, ..keep]


Expand Down Expand Up @@ -227,8 +230,8 @@ subset_methrix <- function(m, regions = NULL, contigs = NULL, samples = NULL, ov
#' @details Takes \code{\link{methrix}} object and filters CpGs based on coverage statistics
#' @param m \code{\link{methrix}} object
#' @param cov_thr minimum coverage required to call a loci covered
#' @param min_samples At least these many samples should have a loci with coverage >= \code{cov_thr}. If \code{group} is given, then this applies per group.Only need one of \code{prop_samples} or \code{min_samples}.
#' @param prop_samples At least this % of samples should have a loci with coverage >= \code{cov_thr}. If \code{group} is given, then this applies per group. Only need one of \code{prop_samples} or \code{min_samples}.
#' @param min_samples Minimum number of samples that should have a loci with coverage >= \code{cov_thr}. If \code{group} is given, then this applies per group. Only need one of \code{prop_samples} or \code{min_samples}.
#' @param prop_samples Minimum proportion of samples that should have a loci with coverage >= \code{cov_thr}. If \code{group} is given, then this applies per group. Only need one of \code{prop_samples} or \code{min_samples}.
#' @param group a column name from sample annotation that defines groups. In this case, the number of min_samples will be
#' tested group-wise.
#' @param n_chunks Number of chunks to split the \code{\link{methrix}} object in case it is very large. Default = 1.
Expand Down
2 changes: 1 addition & 1 deletion R/snp_removal.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ remove_snps <- function(m, populations = NULL, maf_threshold = 0.01, reduce_filt
}


regions <- gUtils::gr.nochr(GenomicRanges::makeGRangesFromDataFrame(elementMetadata(m), start.field = "start", end.field = "start"))
regions <- gr.nochr(GenomicRanges::makeGRangesFromDataFrame(elementMetadata(m), start.field = "start", end.field = "start"))


if(n_cores==1) {
Expand Down
20 changes: 17 additions & 3 deletions man/coverage_filter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions man/get_region_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/mask_methrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/remove_snps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions methrix_super_big.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
4 changes: 2 additions & 2 deletions tests/testthat/test-coverage_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ test_that("Expected filtering", {

test_that("Expected errors", {
expect_error(coverage_filter("not methrix", cov_thr = 10, min_samples = 5), "A valid methrix object needs to be supplied.")
expect_error(coverage_filter(m1, cov_thr = "not_number", min_samples = 5), "cov_thr and min_samples variables are not numeric.")
expect_error(coverage_filter(m1, cov_thr = 10, min_samples = "nn"), "cov_thr and min_samples variables are not numeric.")
expect_error(coverage_filter(m1, cov_thr = "not_number", min_samples = 5), "cov_thr is not numeric.")
expect_error(coverage_filter(m1, cov_thr = 10, min_samples = "nn"), "min_samples and prop_samples variables are not numeric.")

})

12 changes: 6 additions & 6 deletions tests/testthat/test-get_region_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ C_max <- apply(get_matrix(methrix_data[1:3,], type = "C", add_loci = FALSE), 2,

test_that("selected regions", {
expect_equal(as.numeric(get_region_summary(methrix_data,
regions=gr, type = "M", how = "mean", overlap_type = "any")[1,-(1:4)]), as.numeric(M_mean))
regions=gr, type = "M", how = "mean", overlap_type = "any")[1,-(1:5)]), as.numeric(M_mean))
expect_equal(as.numeric(get_region_summary(methrix_data,
regions=gr, type = "C", how = "mean", overlap_type = "any")[1,-(1:4)]), as.numeric(C_mean))
regions=gr, type = "C", how = "mean", overlap_type = "any")[1,-(1:5)]), as.numeric(C_mean))

expect_equal(as.numeric(get_region_summary(methrix_data,
regions=gr, type = "M", how = "min", overlap_type = "any")[1,-(1:4)]), as.numeric(M_min))
regions=gr, type = "M", how = "min", overlap_type = "any")[1,-(1:5)]), as.numeric(M_min))
expect_equal(as.numeric(get_region_summary(methrix_data,
regions=gr, type = "C", how = "min", overlap_type = "any")[1,-(1:4)]), as.numeric(C_min))
regions=gr, type = "C", how = "min", overlap_type = "any")[1,-(1:5)]), as.numeric(C_min))

expect_equal(as.numeric(get_region_summary(methrix_data,
regions=gr, type = "M", how = "max", overlap_type = "any")[1,-(1:4)]), as.numeric(M_max))
regions=gr, type = "M", how = "max", overlap_type = "any")[1,-(1:5)]), as.numeric(M_max))
expect_equal(as.numeric(get_region_summary(methrix_data,
regions=gr, type = "C", how = "max", overlap_type = "any")[1,-(1:4)]), as.numeric(C_max))
regions=gr, type = "C", how = "max", overlap_type = "any")[1,-(1:5)]), as.numeric(C_max))
})


Expand Down

0 comments on commit 556ad7d

Please sign in to comment.