Skip to content

Commit

Permalink
update testthat tests, params and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jackieduckie committed Mar 7, 2022
1 parent 09ac2e6 commit ea86208
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 23 deletions.
8 changes: 3 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Package: svaNUMT
Type: Package
Title: NUMT detection from structural variant calls
Version: 1.1.1
Date: 2021-03-09
Version: 1.1.2
Date: 2022-03-07
Authors@R: c(
person("Ruining", "Dong", email="lnyidrn@gmail.com", role=c("aut", "cre"), comment=c(ORCID = "0000-0003-1433-0484")))
Description: svaNUMT contains functions for detecting NUMT events from structural variant calls.
It takes structural variant calls in GRanges of breakend notation and identifies NUMTs by
nuclear-mitochondrial breakend junctions. The main function reports candidate NUMTs if there is a pair of valid insertion
sites found on the nuclear genome within a certain distance threshold.
The candidate NUMTs are reported by events.
License: GPL-3
License: GPL-3 + file LICENSE
Depends:
GenomicRanges,
rtracklayer,
Expand All @@ -21,7 +21,6 @@ Depends:
R (>= 4.0)
Imports:
assertthat,
Biostrings,
stringr,
dplyr,
methods,
Expand All @@ -40,7 +39,6 @@ Suggests:
readr,
plyranges,
circlize,
tictoc,
IRanges,
SummarizedExperiment,
rmarkdown
Expand Down
11 changes: 7 additions & 4 deletions R/eventDetection.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
#' nuclear chromosome and mitochondrial genome. Only BND notations are supported at the current stage.
#' Possible linked nuclear insertion sites are reported by chromosome in GRanges format.
#' @param gr A GRanges object
#' @param max_ins_dist The maximum distance allowed on the reference genome between the paired insertion sites.
#' Only intra-chromosomal NUMT events are supported. Default value is 10.
#' @inheritParams numtDetect_MT
#' @inheritParams numtDetect_insseq
#' @inheritParams numtDetect_known
#' @return A nested list of GRanges objects of candidate NUMTs.
#' @examples
#' vcf.file <- system.file("extdata", "MT.vcf", package = "svaNUMT")
#' vcf <- VariantAnnotation::readVcf(vcf.file, "hg19")
#' gr <- breakpointRanges(vcf, nominalPosition=TRUE)
#' library(BSgenome.Hsapiens.UCSC.hg19)
#' genome <- BSgenome.Hsapiens.UCSC.hg19
#' numtS <- readr::read_table(system.file("extdata", "numtS.txt", package = "svaNUMT"), col_names = FALSE)
#' colnames(numtS) <- c("bin", "seqnames", "start", "end", "name", "score", "strand")
#' numtS <- `seqlevelsStyle<-`(GRanges(numtS), "NCBI")
#' genome <- BSgenome.Hsapiens.UCSC.hg19::BSgenome.Hsapiens.UCSC.hg19
#' genomeMT <- genome$chrMT
#' numt.gr <- numtDetect(gr, numtS, genomeMT, max_ins_dist=20)
#' @export
Expand Down
1 change: 0 additions & 1 deletion R/insSeq.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#' @return A nested list of GRanges objects of candidate NUMTs.
numtDetect_insseq <- function(gr, genomeMT, min_len=20, min.Align=0.8){
assertthat::assert_that(is(gr, "GRanges"), msg = "gr should be a GRanges object")
assertthat::assert_that(is(numtS, "GRanges"), msg = "numtS should be a GRanges object")
assertthat::assert_that(!isEmpty(gr), msg = "gr can't be empty")
gr <- gr[seqnames(gr) %in% standardChromosomes(gr) &
seqnames(partner(gr)) %in% standardChromosomes(gr)]
Expand Down
2 changes: 1 addition & 1 deletion R/numtS.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param numtS A GRanges object of known NUMT sites.
#' @param max_ins_dist The maximum distance allowed on the reference genome between the paired insertion sites.
#' Only intra-chromosomal NUMT events are supported. Default value is 10.
#' @param gaxgap_numtS The maximum distance allowed betweeen the insertion sequence loci and known NUMTs.
#' @param maxgap_numtS The maximum distance allowed betweeen the insertion sequence loci and known NUMTs.
#' @keywords internal
#' @return A nested list of GRanges objects of candidate NUMTs.
numtDetect_known <- function(gr, numtS, max_ins_dist=10, maxgap_numtS=10){
Expand Down
18 changes: 16 additions & 2 deletions man/numtDetect.Rd

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

2 changes: 1 addition & 1 deletion man/numtDetect_known.Rd

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

1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library(testthat)
library(svaNUMT)


test_check("svaNUMT")
60 changes: 51 additions & 9 deletions tests/testthat/test-eventDetection.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,72 @@
context('event detection functions')
library(readr)
library(BSgenome.Hsapiens.UCSC.hg19)
na12878 <- readVcf(system.file("extdata", "gridss-na12878.vcf", package = "svaNUMT"))
numt <- readVcf(system.file("extdata", "MT.vcf", package = "svaNUMT"))
#known NUMTs as GRanges
numtS <- read_table(system.file("extdata", "numtS.txt", package = "svaNUMT"), col_names = FALSE)
colnames(numtS) <- c("bin", "seqnames", "start", "end", "name", "score", "strand")
numtS <- `seqlevelsStyle<-`(GRanges(numtS), "NCBI")
#mitochondria reference genome
genomeMT <- BSgenome.Hsapiens.UCSC.hg19$chrMT
#default numtDetect() parameters
max_ins_dist=10
maxgap_numtS=10
min_len=20
min.Align=0.8

#NUMT detection
test_that("numtDetect returns nothing with no nu-mt fusion", {
test_that("numtDetect returns an empty list and messages with no nu-mt fusion", {
gr <- suppressWarnings(breakpointRanges(na12878))
expect_equal(NULL,numtDetect(gr))
expect_message(numtDetect(gr),
expect_equal(list(MT=NULL, known=NULL, insSeq=NULL),
numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align))
expect_message(numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align),
"There is no NUMT event detected. Check whether 'chrM' or 'MT' is present in the VCF.")
expect_message(numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align),
"There is no MT sequence from known NUMT events detected.")
expect_message(numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align),
"There is no NUMT event detected by insertion sequences.")
})

test_that("numtDetect returns nothing but message when no paired candidate insertion site is found within the given threshold", {
test_that("numtDetect returns an empty and message when no paired candidate insertion site is found within the given threshold", {
gr <- suppressWarnings(breakpointRanges(numt))
expect_equal(NULL, numtDetect(gr, 10))
expect_message(numtDetect(gr, 10),
expect_equal(list(MT=NULL, known=NULL, insSeq=NULL),
numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align))
expect_message(numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align),
"There is no NUMT event detected. Paired candidate insertion site not found.")

expect_message(numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align),
"There is no MT sequence from known NUMT events detected.")
expect_message(numtDetect(gr, numtS, genomeMT,
max_ins_dist = 10, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align),
"There is no NUMT event detected by insertion sequences.")
# expect_equal(c("11", "11", "MT", "MT"), as.character(seqnames(gr)))
# expect_equal(c(49883572, 49883585, 16093, 16493), start(gr))
# expect_equal(c(49883572, 49883585, 16093, 16493), end(gr))
# expect_equal(c("+", "-", "-", "+"), as.character(strand(gr)))
# expect_equal(CharacterList("gridss9h", "gridss39h", "gridss9h", "gridss39h"), gr$candidatePartnerId)
})

test_that("numtDetect returns a list of 2 when candidate NUMTs are found", {
test_that("numtDetect returns a list element MT which consists of 2 lists when
candidate NUMTs by MT breakpoints are found", {
gr <- suppressWarnings(breakpointRanges(numt))
expect_equal(2, length(numtDetect(gr, 20)))
NUMT <- numtDetect(gr, numtS, genomeMT,
max_ins_dist = 20, maxgap_numtS=maxgap_numtS,
min_len=min_len, min.Align=min.Align)
expect_equal(2, length(NUMT$MT))
})

0 comments on commit ea86208

Please sign in to comment.