[Biopython] SeqIO.write and user-specified wrapping
Ivan Gregoretti
ivangreg at gmail.com
Mon Mar 4 20:34:06 UTC 2013
I have to rectify myself. Both your code and Peter's suggestions work.
I had a bug in my code that prevented me from overriding the default
60 character length.
Thank you,
Ivan
Ivan Gregoretti, PhD
Bioinformatics
On Mon, Mar 4, 2013 at 2:26 PM, Lenna Peterson <arklenna at gmail.com> wrote:
> For me, this works as expected. I will paste my exact code below.
>
> I am creating the SeqRecord from your string, so perhaps it's some
> difference there.
>
> Cheers,
>
> Lenna
>
> from Bio.Seq import Seq
> from Bio.SeqRecord import SeqRecord
> from Bio.SeqIO.FastaIO import FastaWriter
>
> mystr = """SVRFQTALASIKLIQASAVLDLTEDDFDFLTSNKVWIATDRSRARRCVEACVYGTLDFVG
> YPRFPAPVEFIAAVIAYYVHPVNIQTACLIMEGAEFTENIINGVERPVKAAELFAFTLRV
> RAGNTDV"""
>
> myseq = Seq(mystr.replace("\n", ""))
> myrec = SeqRecord(myseq)
>
> with open("nowrap.fa", "wb") as fh:
> FastaWriter(fh, wrap=0).write_file([myrec])
>
> with open("wrap10.fa", "wb") as fh:
> FastaWriter(fh, wrap=10).write_file([myrec])
>
>
>
> On Mon, Mar 4, 2013 at 1:28 PM, Ivan Gregoretti <ivangreg at gmail.com> wrote:
>>
>> Sorry to pester the list's subscribers but there seems to be bug in
>> FastaWriter
>>
>> It appears that FastaWriter does not respect the wrap argument:
>>
>> # No wrapping
>> SeqIO.FastaIO.FastaWriter( handle, wrap=0 ).write_file( [record] )
>>
>> or
>>
>> # wrap after 10 characters
>> SeqIO.FastaIO.FastaWriter( handle, wrap=10 ).write_file( [record] )
>>
>> both produce the same output:
>>
>> >M01483:6:000000000-A2WVJ:1:1101:12685:1873
>> SVRFQTALASIKLIQASAVLDLTEDDFDFLTSNKVWIATDRSRARRCVEACVYGTLDFVG
>> YPRFPAPVEFIAAVIAYYVHPVNIQTACLIMEGAEFTENIINGVERPVKAAELFAFTLRV
>> RAGNTDV
>> >M01483:6:000000000-A2WVJ:1:1101:19629:2231
>> LTLADDRLEAFYDNPNALRDYFRDIGRMVLAAEGRKANDSHADCYQYFCVPEYGTANGRL
>> HFHAVHFMRTLPTGSVDPNFGRRVRNRRQLNSLQNTWPYGYSMP
>> >M01483:6:000000000-A2WVJ:1:1101:12952:2294
>> GFENQKELTKMQLDNQKEIAEMQNETQKEIAGIQSATSRQNTKDQVYAQNEMLAYQQKES
>> TARVASIMENTNLSKQQQVSEIMRQMLTQAQTAGQYFTNDQIKEMTRKVS
>>
>> FastaWriter does produce an error when I pass wrap="hello world", so,
>> the argument is interpreted initially. Also, as expected, when I
>> comment out the SeqIO.FastaIO.FastaWriter line, there is no output.
>>
>> I checked and double checked.
>>
>> I am using Python 2.7.3 on a linux 64bit (Fedora 18) and my Biopython is
>> 1.6.1.
>>
>> Thank you,
>>
>> Ivan
>>
>>
>>
>>
>> Ivan Gregoretti, PhD
>> Bioinformatics
>>
>>
>>
>> On Mon, Mar 4, 2013 at 12:26 PM, Peter Cock <p.j.a.cock at googlemail.com>
>> wrote:
>> > On Mon, Mar 4, 2013 at 5:20 PM, Ivan Gregoretti <ivangreg at gmail.com>
>> > wrote:
>> >> I am trying this
>> >>
>> >> from Bio import SeqIO
>> >> SeqIO.FastaIO.FastaWriter( handle, wrap=0 ).write_file( record )
>> >>
>> >
>> > That should be a list of SeqRecord objects, not just one SeqRecord.
>> > If you have just one, try [record] instead.
>> >
>> > Peter
>> _______________________________________________
>> Biopython mailing list - Biopython at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/biopython
>
>
More information about the Biopython
mailing list