[BioC] write.XStringView/write.XStringSet highly inefficient (solved)
Steve Lianoglou
mailinglist.honeypot at gmail.com
Wed Jul 28 15:07:18 CEST 2010
Hi,
On Wed, Jul 28, 2010 at 5:10 AM, Michael Dondrup <Michael.Dondrup at uni.no> wrote:
<snip>
> The downside of this function is it does not wrap long sequence lines. So I came up with another one:
>
> 3.
> writeFASTA <- function(sequences, desc=names(sequences), width=80, file=stdout(), append=FALSE) {
> sequences <- as.character(sequences)
> if(!is.null(desc) && length(sequences) != length(desc))
> stop("wrong length of 'desc'")
> desc <- if (is.null(desc))
> paste(">", seq(along=sequences))
> else
> paste(">", desc, "\n", sep="")
> ## Adjust line width or add a \n
> sequences <- if (! is.null(width))
> gsub( sprintf("(.{1,%d})", width), "\\1\n", sequences )
> else
> paste(sequences, "\n", sep="")
> cat(paste(desc,sequences, sep="", collapse=""), sep="", file=file, append=append )
> }
Nice use of regex's! Reminds me of:
http://xkcd.com/208/
;-)
--
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 Bioconductor
mailing list