[Bioc-sig-seq] using subseq() on a DNAStringSet

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed May 26 20:32:52 CEST 2010


Hi,

On Wed, May 26, 2010 at 11:25 AM, Andrew Yee <yee at post.harvard.edu> wrote:
> I'm a complete novice in Biostrings and am starting to learn about
> DNAStringSet.  I was wondering how do you do a subseq operation on just one
> of the DNAStrings in the set.
>
> library('Biostrings')
>
> a <- DNAStringSet('TTGGAACT')
> subseq(a, start=2, end=3) <- NULL # works fine
>
>
> x <- c(DNAStringSet('TTGGAACT'), DNAStringSet('AAGGTT'))
> names(x) <- c('a', 'b')
>
> # now I'm interested in doing this operation on just the a string and not b
>
> subseq(x[['a']], start=2, end=3) <- NULL # doesn't work
>
> a1 <- x[['a']]
> subseq(a1, start=2, end=3) <- NULL # does work
>
> Welcome any thoughts or suggestions!

It looks like the "subseq(SOMETHING)<-" assignment will work when that
SOMETHING is a DNAStringSet.

You can use single-bracket indexing to return a DNAStringSet of length
1 and subseq into that, eg:

R> x <- DNAStringSet(c('TTGGAACT', 'AAGGTT'))
R> x
  A DNAStringSet instance of length 2
    width seq
[1]     8 TTGGAACT
[2]     6 AAGGTT

R> is(x[[1]])
[1] "DNAString" "XString"   "XRaw"      "XVector"   "Sequence"  "Annotated"

R> is(x[1])
[1] "DNAStringSet" "XStringSet"   "XRawList"     "XVectorList"
"Sequence"     "Annotated"

## assigning `<-` into a DNAString in *this* context will fail
R> subseq(x[1], 2, 3) <- NULL
Error in `[[<-`(`*tmp*`, 1, value = <S4 object of class "DNAString">) :
  no method for assigning subsets of this S4 class

## But assigning `<-` into a DNAStringSet here will work

R> subseq(x[1], 2, 3) <- NULL
R> x
  A DNAStringSet instance of length 2
    width seq
[1]     6 TGAACT
[2]     6 AAGGTT

Also note that x['a'] doesn't work, so you have to use the index of
the elements you want to select for subseq.

I reckon you can use this approach for now to do what you want until
one of the guru's can comment on why it's working (or not) like this
in this context.

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the Bioc-sig-sequencing mailing list