[BioPython] question regarding writing SeqRecord objects in Fasta format

Ann Loraine loraine at loraine.net
Fri Jul 22 19:45:31 EDT 2005


Hi,

I made the SeqRecord following an example in one of the tutorials:

from: http://www.biopython.org/docs/tutorial/Tutorial003.html#toc7:

 >>> from Bio import Fasta
 >>> parser = Fasta.RecordParser()
 >>> file = open("ls_orchid.fasta")
 >>> iterator = Fasta.Iterator(file, parser)

To get the first record in the file, I did this:

 >>> cur_record = iterator.next()

Probably I should use the SeqIO.Fasta.FastaReader for my application - 
which is reading in sequences and then selecting a subset of records to 
write to an output file.

-Ann


On Jul 15, 2005, at 12:30 PM, Iddo Friedberg wrote:

> Hi Ann,
>
> How did you create the SeqRecord instances in the first place? Did you 
> read in using SeqIO.Fasta.FastaReader, or something else?
>
> Your SeqRecord instance lacks an id attribute, which should have been 
> read in, or inserted some other way.
>
> Let me know.
>
> Cheers,
>
> Iddo
>
>
>
>
>
> Ann Loraine wrote:
>
>> Hi,
>>
>> I'm trying to create a new fasta file from a larger one by selecting 
>> out records that contain specific ids.
>>
>> Reading the records worked fine - I just followed the directions in 
>> the tutorial.
>>
>> But now I want to write them out in fasta format to a file handle.
>>
>> I tried using the SeqIO.FASTA.FastaWriter class to do this, but got 
>> this error:
>>
>> >>> writer = Bio.SeqIO.FASTA.FastaWriter('test.fa')
>> >>> writer.write(cur_record)
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>>   File "/usr/local/lib/python2.4/site-packages/Bio/SeqIO/FASTA.py", 
>> line 67, in write
>>     id = record.id
>> AttributeError: Record instance has no attribute 'id'
>>
>> Looks like FastaWriter expects a different type of object.
>>
>> Printing the record works fine, however:
>>
>> >>> print cur_record
>> >consensus:Rat230_2:1367552_at; gb|M25590; gb:M25590.1 
>> /DB_XREF=gi:202756 /FEA=FLmRNA /CNT=455 /TID=Rn.9942.1 /TIER=FL+Stack 
>> /STK=452 /UG=Rn.9942 /LL=24802 /UG_GENE=Svp4 /UG_TITLE=Seminal 
>> vesicle protein 4 /DEF=Rat androgen-dependent protein mRNA, complete 
>> cds. /FL=gb:NM_012662.1 gb:M25590.1
>> atataaactaagaactcagctcagccttcagtcaagagcttttctggcaagatgaagtct
>> accagcttgttcctctgttctctgctcctccttctagtgacaggagccattgggagaaaa
>> acnaaggaaaaatactcacagtcggaagaagttgtcagtgagagctttgcctcgggccct
>> tcctcgggttcttctgatgatgaattagtgagagacaagccatatggccccaaagtctcg
>> ggcggctcctttggtgaggaagcttctgaggagataagtagcagaaggagcaagcacatc
>> tctaggagttccggtggctccaacatggaaggtgagagctcgtatgccaagaaaaagagg
>> agccggtttgcccaagacgtactcaactgatagtgcatcgggcagctgaacatcttggac
>> caatatgccggagccacattgcctggatgaagcctgtgatgtcttcagcatgcagctccc
>> natgtggtctcagaggcagtccctggatggcatttccttctcatgcttgtttgtcttgag
>> gttcttaaacctaacattcaggaactttctgtccaataaagagataacaatctgcatcnt
>> taaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnn
>>
>>
>> But I don't want to print the record to stdout -- I want to write it 
>> to a filehandle.  I'd like the record to be formatted nicely -  same 
>> number of characters per line in the sequence part - but I can't 
>> figure out how to do it.
>>
>> Is there another 'writer' type object I could use that would accept a 
>> SeqRecord?
>>
>> -Ann
>>
>>
>> _______________________________________________
>> BioPython mailing list  -  BioPython at biopython.org
>> http://biopython.org/mailman/listinfo/biopython
>>
>>
>
>
> -- 
> Iddo Friedberg, Ph.D.
> The Burnham Institute
> 10901 N. Torrey Pines Rd.
> La Jolla, CA 92037 USA
> Tel: +1 (858) 646 3100 x3516
> Fax: +1 (858) 713 9949
> http://ffas.ljcrf.edu/~iddo
>
>



More information about the BioPython mailing list