[BioC] Unit tests with DNAString objects

Hervé Pagès hpages at fhcrc.org
Wed Jan 29 22:43:25 CET 2014


Hi Jonathon,

On 01/29/2014 12:14 PM, Jonathon Hill [guest] wrote:
> I am trying to create some unit tests for an S4 class I have created that includes a DNAString class object in one of its slots. However, all.equals and identical (as well as their corresponding RUnit functions) fail; all.equals returns an error and identical always returns "FALSE." Based on the all.equals error message, it appears that it is because DNAString class objects include an external pointer that cannot be handled by all.equals and can sometimes differ between objects, even if they contain identical sequence, causing identical to return "FALSE." Do you have any suggestions on a work around?

Unfortunately identical() cannot (and should not) be used on objects
that contain external pointers.

To test equality between 2 DNAString objects, you can use ==.
Note that this only compares the sequences. The metadata columns
(if any) are not compared.

To make all.equal() work on DNAString objects, you can define the
following all.equal method (S3):

all.equal.XString <- function(target, current, ...)
{
     ok1 <- target == current
     if (!ok1)
         ok1 <- "sequence mismatch"
     ok2 <- identical(class(target), class(current))
     if (!ok2)
         ok2 <- "class mismatch"
     ok3 <- all.equal(target at metadata, current at metadata)
     ok4 <- all.equal(target at elementMetadata, current at elementMetadata)
     ans <- character(0)
     if (!isTRUE(ok1))
         ans <- c(ans, ok1)
     if (!isTRUE(ok2))
         ans <- c(ans, ok2)
     if (!isTRUE(ok3))
         ans <- c(ans, ok3)
     if (!isTRUE(ok4))
         ans <- c(ans, ok4)
     if (length(ans) == 0L)
         return(TRUE)
     ans
}

I should probably add this method to Biostrings.

If you're not subscribed to the Bioc-devel mailing list yet I
recommend you do so and use it for any follow up questions you
may have about this. See:

   http://bioconductor.org/help/mailing-list/

Thanks,
H.

>
> Thanks,
>
> Jonathon Hill
>
>   -- output of sessionInfo():
>
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] parallel  stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] sangerseqR_0.99    RUnit_0.4.26       Biostrings_2.30.1  XVector_0.2.0      IRanges_1.20.6     BiocGenerics_0.8.0
> [7] roxygen2_3.0.0
>
> loaded via a namespace (and not attached):
> [1] brew_1.0-6      codetools_0.2-8 digest_0.6.4    stats4_3.0.2    stringr_0.6.2   tools_3.0.2
>>
>
> --
> Sent via the guest posting facility at bioconductor.org.
>

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioconductor mailing list