[Biopython] SeqIO.write and user-specified wrapping
Ivan Gregoretti
ivangreg at gmail.com
Mon Mar 4 17:20:45 UTC 2013
I am trying this
from Bio import SeqIO
SeqIO.FastaIO.FastaWriter( handle, wrap=0 ).write_file( record )
but I get the following error:
File "/usr/lib64/python2.7/site-packages/Bio/SeqIO/Interfaces.py",
line 254, in write_file
count = self.write_records(records)
File "/usr/lib64/python2.7/site-packages/Bio/SeqIO/Interfaces.py",
line 239, in write_records
self.write_record(record)
File "/usr/lib64/python2.7/site-packages/Bio/SeqIO/FastaIO.py", line
174, in write_record
id = self.clean(record.id)
AttributeError: 'str' object has no attribute 'id'
Any ideas?
Thank you,
Ivan
Ivan Gregoretti, PhD
Bioinformatics
On Mon, Mar 4, 2013 at 12:00 PM, Ivan Gregoretti <ivangreg at gmail.com> wrote:
> Thank you Peter. I'll try the FastaWriter.
>
>
>
> Ivan Gregoretti, PhD
> Bioinformatics
>
>
>
> On Mon, Mar 4, 2013 at 11:54 AM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
>> On Mon, Mar 4, 2013 at 4:14 PM, Ivan Gregoretti <ivangreg at gmail.com> wrote:
>>> Hi Everybody,
>>>
>>> Could a kind soul show how to produce a FASTA file without wrapping
>>> its sequences?
>>>
>>> I am looking for something like this:
>>>
>>> from Bio import SeqIO
>>> SeqIO.write(my_records, "my_example.fa", "fasta", wrap=0)
>>>
>>> as opposed to the default wrapping after 60 characters.
>>>
>>> Thanks for Biopython.
>>>
>>> Ivan
>>
>> Currently SeqIO doesn't allow extra file format specific
>> argument like that (although it could in principle). Here
>> you must currently use the underlying writer directly,
>> something like this:
>>
>> from Bio.SeqIO.FastaIO import FastaWriter
>> handle = open("my_example.fa", "w")
>> writer = FastaWriter(handle, wrap=0)
>> writer.write_file(my_records)
>> handle.close()
>>
>> Or, since you want no line wrapping you could do
>> something like this instead:
>>
>> handle = open("my_example.fa", "w")
>> for record in my_records:
>> handle.write(">%s %s\n%s\n" % (record.id, record.description, record.seq))
>> handle.close()
>>
>> Peter
More information about the Biopython
mailing list