[Seqinr-forum] suggested SeqinR function for printing a list of sequences to a fasta file

Coghlan, Avril A.Coghlan at ucc.ie
Thu Dec 10 17:51:11 CET 2009


Dear Jean,

Thanks for explaining this about write.fasta(). I didn't realise that it
could already handle multiple sequences, that is great.

Thanks again,
Avril

-----Original Message-----
From: Jean lobry [mailto:lobry at biomserv.univ-lyon1.fr] 
Sent: 18 November 2009 19:29
To: seqinr-forum at r-forge.wu-wien.ac.at
Cc: Coghlan, Avril
Subject: Re: [Seqinr-forum] suggested SeqinR function for printing a
list of sequences to a fasta file

At 17:50 +0000 18/11/09, Coghlan, Avril wrote:
>Dear SeqinR forum,
>
>I am wondering would it be useful to have a SeqinR function for 
>printing out a list of sequences in fasta format to a file.
>At present, there is a function write.fasta() that prints one sequence 
>in fasta format to a file.
>However, I think it would be useful to have a more general function 
>that can print a list of sequences in fasta format to a file.
>
>Here is my suggested code, using the example of printing the sequences 
>for all human tRNAs to a fasta format file called 'humantRNAs.fasta'.
>>  choosebank("genbank")
>>  query("humtRNAs", "SP=homo sapiens AND M=TRNA")  numhumtRNAs <- 
>> humtRNAs$nelem # Find the number of matching sequences  for (i in 1: 
>> numhumtRNAs) {
>         seq <- getSequence(humtRNAs$req[[i]]) # get the sequence
>         name <- getName(humtRNAs$req[[i]])    # get the name of the
>sequence
>         # write the sequence to the file:
>         if (i == 1) { write.fasta(sequences = seq, names=name, 
>file.out = "humantRNAs.fasta", open="w") }
>         else        { write.fasta(sequences = seq, names=name,
file.out
>= "humantRNAs.fasta", open="a") }
>  }
>
>I imagine that this could be adapted to make a function that would take

>a fasta format file name (eg. humantRNAs.fasta here), and a list of 
>sequences (eg. humtRNAs here), and write the sequences to the file.
>
>What do you think?
>
>I am relatively new to R, so I imagine that somebody else could write a

>much better function than me. Also, I have no idea how I can submit a 
>new function to the SeqinR library. So this is just a suggestion..
>
>Regards,
>Avril
>
>Avril Coghlan
>University College Cork,
>Ireland
>
>

Dear Avril,

the function write.fasta() can already handle more than one sequence at
once. For instance, with your example:

######
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") ######

yields the there-included fasta file.

I will change the title in the doc for the write.fasta() function to
make more explicit that it works with many sequences too.

Best,

-- 
Jean R. Lobry            (lobry at biomserv.univ-lyon1.fr)
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - LYON I,
43 Bd 11/11/1918, F-69622 VILLEURBANNE CEDEX, FRANCE
allo  : +33 472 43 27 56     fax    : +33 472 43 13 88
http://pbil.univ-lyon1.fr/members/lobry/


More information about the Seqinr-forum mailing list