[Seqinr-forum] suggested SeqinR function for printing a list of sequences to a fasta file
Coghlan, Avril
A.Coghlan at ucc.ie
Wed Nov 18 18:50:59 CET 2009
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
More information about the Seqinr-forum
mailing list