[Seqinr-forum] FASTA output splits into all headers then all sequences

Lionel Guy lionel.guy at unil.ch
Fri Feb 19 08:19:24 CET 2010


Hi Oliver,

This is due to the fact that you have sequences that have only the  
same length. Thus, getSequence returns a matrix instead of a list,  
which confuses write.fasta.

getSequence.list <- function (object, as.string = FALSE, ...) {
    lapply(seq_len(length(object)), function(i) getSequence(object[[i]],
      as.string = as.string, ...))
}

I don't have a patch to propose, but as a workaround, you can do the  
following:

library(seqinr)
choosebank("genbank")
query("mydat", "AU=Matute")
modifylist("mydat",operation=">614")
modifylist("mydat",operation="<615")

myseqs <- getSequence(mydat)
mynames <- getName(mydat)

# this won't work
write.fasta(myseqs,mynames, file = "myseqs.fasta")
# change the matrix to a list
mylist <- list()
for (i in 1:ncol(myseqs)){
     mylist <- c(mylist, list(myseqs[,i]))
}
# this should work
write.fasta(mylist,mynames, file = "myseqs2.fasta")
Best,

Lionel

On 19 Feb 2010, at 4:06 , Oliver Clay wrote:

> 	• [Seqinr-forum] suggested SeqinR function for printing a list of	 
> sequences to a fasta file   Coghlan, Avril  Thu Dec 10 17:51:11 CET  
> 2009
> Dear Jean and Simon,
>
> I took Jean's example from the above thread,
> > library(seqinr)
> > choosebank("genbank")
> > query("humtRNAs", "SP=homo sapiens AND M=TRNA")
> > myseqs <- getSequence(humtRNAs)
> > mynames <- getName(humtRNAs)
>
> > write.fasta(myseqs,mynames, file = "myseqs.fasta") ######
>
> and made a few changes, but after those changes my output was no
> longer a normal FASTA file: instead, it first had all header lines
> bunched together, then all the DNA sequences concatenated in one
>
> block. Here are the commands I used:
>
> library(seqinr)
> choosebank("genbank")
> query("mydat", "AU=Matute")
> modifylist("mydat",operation=">613")
> modifylist("mydat",operation="<615")
>
> myseqs <- getSequence(mydat)
> mynames <- getName(mydat)
> write.fasta(myseqs,mynames, file = "myseqs.fasta")
>
> I've tried repeating this example many times under the same conditions
> (new R console, on Mac OSX). The problem seem to be intermittent,
>
> because very rarely I do get the normal FASTA output, but then the
> next time everything segregates again. Do you have an idea what might
> be causing this?
>
> Many thanks for your help,
>
> Best regards,
>
>
> Oliver Clay
>
>
> _______________________________________________
> Seqinr-forum mailing list
> Seqinr-forum at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/seqinr-forum



More information about the Seqinr-forum mailing list