[Seqinr-forum] suggested SeqinR function for printing a list of sequences to a fasta file
Jean lobry
lobry at biomserv.univ-lyon1.fr
Wed Nov 18 20:29:08 CET 2009
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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: %myseqs.fasta
Type: application/applefile
Size: 122 bytes
Desc: not available
Url : http://lists.r-forge.r-project.org/pipermail/seqinr-forum/attachments/20091118/24b39beb/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myseqs.fasta
Type: application/octet-stream
Size: 1914 bytes
Desc: not available
Url : http://lists.r-forge.r-project.org/pipermail/seqinr-forum/attachments/20091118/24b39beb/attachment.obj
More information about the Seqinr-forum
mailing list