[BioPython] question regarding writing SeqRecord objects in Fasta format

Ann Loraine loraine at loraine.net
Fri Jul 15 08:51:44 EDT 2005


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




More information about the BioPython mailing list