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
ok1 <- "sequence mismatch"
ok2 <- identical(class(target), class(current))
ok2 <- "class mismatch"
ok3 <- all.equal(target at metadata, current at metadata)
ok4 <- all.equal(target at elementMetadata, current at
ans <- character(0)
ans <- c(ans, ok1)
ans <- c(ans, ok2)
ans <- c(ans, ok3)
ans <- c(ans, ok4)
if (length(ans) == 0L)
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:
> Jonathon Hill
> -- output of sessionInfo():
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>  en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> attached base packages:
>  parallel stats graphics grDevices utils datasets
> other attached packages:
>  sangerseqR_0.99 RUnit_0.4.26 Biostrings_2.30.1
XVector_0.2.0 IRanges_1.20.6 BiocGenerics_0.8.0
>  roxygen2_3.0.0
> loaded via a namespace (and not attached):
>  brew_1.0-6 codetools_0.2-8 digest_0.6.4 stats4_3.0.2
> Sent via the guest posting facility at bioconductor.org.
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