[Bioc-devel] converting character vector to DNAStringSetList

Hervé Pagès hpages at fhcrc.org
Fri Apr 19 21:35:56 CEST 2013


Hi Stephanie,

On 04/19/2013 11:55 AM, Stephanie M. Gogarten wrote:
> Hi all,
>
> There is a non-exported function in VariantAnnotation called
> .toDNAStringSetList that converts a vector of comma-separated character
> strings to a DNAStringSetList.  I'd like to use this code in a package
> I'm working on.  Would it make sense to export this from Biostrings?  If
> not, what is the proper way to attribute code if I borrow a few lines
> from .toDNAStringSetList?

This should be a 1-liner but the 1-liner fails at the moment because the
DNAStringSetList() constructor doesn't work on a list:

   > comma_sep_strings <- c("AA,TT", "ACGT", "", "TT,A,,TAG")
   > DNAStringSetList(strsplit(comma_sep_strings, ",", fixed=TRUE))
   Error in strsplit(comma_sep_strings, ",") : non-character argument

Of course this should work (and it will work tomorrow after you run
biocLite()). In the mean time the workaround is to use do.call():

   > do.call(DNAStringSetList, strsplit(comma_sep_strings, ",", fixed=TRUE))
   DNAStringSetList of length 4
   [[1]] AA TT
   [[2]] ACGT
   [[3]]   A DNAStringSet instance of length 0
   [[4]] TT A  TAG

Cheers,
H.

PS: Calling strsplit() with 'fixed=TRUE' makes it about 4x faster :-)

>
> thanks,
> Stephanie
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel

-- 
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 Bioc-devel mailing list