Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

Commit

Permalink
Explicitly check upper bound of number of signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangehring committed Dec 15, 2015
1 parent efa9822 commit e183628
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SomaticSignatures
Type: Package
Title: Somatic Signatures
Version: 2.7.3
Version: 2.7.4
Author: Julian Gehring (EMBL Heidelberg)
Maintainer: Julian Gehring <[email protected]>
Description: The SomaticSignatures package identifies mutational signatures of single nucleotide variants (SNVs). It provides a infrastructure related to the methodology described in Nik-Zainal (2012, Cell), with flexibility in the matrix decomposition algorithms.
Expand Down
13 changes: 8 additions & 5 deletions R/mutational-signatures.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
identifySignaturesVRanges <- function(vr, group, nSigs, decomposition = nmfDecomposition, ...) {

m = motifMatrix(vr, group, normalize = TRUE)

res = findSignatures(m, nSigs, decomposition, ...)
res@decomposition = decomposition
res@options = list(...)
Expand All @@ -21,12 +21,15 @@ identifySignatures <- function(m, nSigs, decomposition = nmfDecomposition, ...)
findSignatures <- function(x, r, decomposition = nmfDecomposition, ...) {

## check input arguments
if(!( length(r) == 1 & all.equal(r, as.integer(r)) & r > 0 ))
stop("'nSigs | r' must be a single, positive integer.")
nm = min(dim(x))
if(!( length(r) == 1 & all.equal(r, as.integer(r)) & r > 0 & r <= nm)) {
msg = "'nSigs | r' must be a single, positive integer in the range [1,%d]"
stop(sprintf(msg, nm))
}

if(!is.function(decomposition))
stop("'decomposition' must be a function.")

dc = decomposition(x, r, ...)

## check returned object
Expand All @@ -36,7 +39,7 @@ findSignatures <- function(x, r, decomposition = nmfDecomposition, ...) {
paste(required_names, ", "))
stop(msg)
}

res = new("MutationalSignatures",
signatures = dc$w,
samples = dc$h,
Expand Down
16 changes: 15 additions & 1 deletion tests/testthat/test-SomaticSignatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test_that("'motifMatrix' works", {

data(sca_motifs_tiny)
vr = sca_motifs_tiny

mm = motifMatrix(vr, "study")

expect_equal( nrow(mm), 96 )
Expand Down Expand Up @@ -178,6 +178,10 @@ test_that("'identifySignatures' handles bad inputs", {
expect_error( identifySignatures(sca_mm, 0),
".*single, positive integer.*")

## bad number of signatures
expect_error( identifySignatures(sca_mm, min(dim(sca_mm))+1),
".*in the range.*")

## 'decomposition' argument no function
expect_error( identifySignatures(sca_mm, 3, "a"),
"*.must be a function.*")
Expand All @@ -203,6 +207,16 @@ test_that("'assessNumberSignatures' works", {

})

test_that("'assessNumberSignatures' handles bad inputs", {

data("sca_mm", package = "SomaticSignatures")

nm = min(dim(sca_mm))
expect_error( assessNumberSignatures(sca_mm, (nm-1):(nm+2)),
".*in the range.*")

})

test_that("'assessNumberSignatures' low-level functions work", {

x = matrix(rnorm(100, 20))
Expand Down

0 comments on commit e183628

Please sign in to comment.