[BioPython] save or display fasta format
Brad Chapman
chapmanb at uga.edu
Thu Dec 18 09:20:07 EST 2003
Hi Sebastian;
> When I parse a FASTA file I get the title and the sequence, and that's
> OK. But sometimes I want to save a FASTA record to a file or display it
> in the screen. The problem is that the sequences are printed as one line
> (it is a string after all).
> I'd like to know if there is an easy way to display them formated (70
> columns per line for example).
Sure, the standard Fasta.Record class will do this for you:
>>> from Bio import Fasta
>>> my_rec = Fasta.Record()
>>> my_rec.title = "My Record"
>>> print my_rec
>My Record
MEDQVGFGFRPNDEELVGHYLRNKIEGNTSRDVEVAISEVNICSYDPWNLRFQSKYKSRD
AMWYFFSRRENNKGNRQSRTTVSGKWKLTGESVEVKDQWGFCSEGFRGKIGHKRVLVFLD
GRYPDKTKSDWVIHEFHYDLLPEHQ
You can set the number of columns for output when initializing the
record:
my_rec = Fasta.Record(colwidth=30)
To write records to a file, you just need to do:
output_handle.write(str(my_rec) + "\n")
Hope this helps.
Brad
More information about the BioPython
mailing list