[Bioc-sig-seq] unusual behavior when concatenating DNAStringSets

Martin Morgan mtmorgan at fhcrc.org
Fri Sep 24 16:21:22 CEST 2010


On 09/22/2010 12:06 PM, Andrew Yee wrote:
> I encountered some unusual behavior when concatenating multiple
> DNAStringSet objects as follows:
> 
> library('Biostrings')
> 
> x <- DNAStringSet('ATA')
> y <- DNAStringSet('GCG')
> z <- DNAStringSet('AGA')
> 
> foo <- rep(list(x,y,z),1)
> do.call(c, foo) # creates a DNAStringSet
> 
> names(foo) <- c('x', 'y', 'z')
> do.call(c, foo) # creates a DNAStringSet
> 
> names(foo) <- c('a', 'b', 'c')
> do.call(c, foo) # creates a list instead, not a DNAStringSet
> 
> It seems that in the last case, a list is created rather than a
> DNAStringSet.  It seems that the operation in sensitive to the names()
> of the list.  Or is there an alternative means of concatenating
> multiple DNAStringSets?

Hi Andrew -- this took quite a bit of time to realize what is going on,
but...

Here's an even more minimal example:

> c(x=DNAStringSet())
  A DNAStringSet instance of length 0
> c(a=DNAStringSet())
$a
  A DNAStringSet instance of length 0

The generic is

> getGeneric("c")
standardGeneric for "c" defined from package "base"

function (x, ..., recursive = FALSE)
standardGeneric("c", .Primitive("c"))
<environment: 0x17ce728>
Methods may be defined for arguments: x, recursive
Use  showMethods("c")  for currently available ones.

so when you do the equivalent of c(x=DNAStringSet()) the 'x' argument in
your function call matches the x argument in the generic, and the
c,DNAStringSet-method gets called.

When you c(a=DNAStringSet()), the 'x' argument in the generic is
missing, so the method used is c,missing-method, i.e., the default,
which returns its arguments concatenated together.

This requires some more investigation, though. In a new R session, I can

> setClass("A", representation("numeric"))
[1] "A"
> setMethod("c", "A", function(x, ...) TRUE)
[1] "c"
> c(new("A"))
[1] TRUE
> c(x=new("A"))
[1] TRUE
> c(a=new("A"))
[1] TRUE

It's only after library(Biostrings) that I see

> c(a=new("A"))
numeric(0)

Martin

> Thanks,
> Andrew
> 
> 
>> sessionInfo()
> R version 2.11.1 Patched (2010-09-04 r52880)
> Platform: x86_64-unknown-linux-gnu (64-bit)
> 
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> other attached packages:
> [1] Biostrings_2.16.9 IRanges_1.6.17
> 
> loaded via a namespace (and not attached):
> [1] Biobase_2.8.0
> 
> _______________________________________________
> Bioc-sig-sequencing mailing list
> Bioc-sig-sequencing at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioc-sig-sequencing



More information about the Bioc-sig-sequencing mailing list