Use this to write an entire file containing the given records. records - a SeqRecord iterator, or list of SeqRecords Right now this code uses Bio.Clustalw.ClustalAlignment to do the hard work - this may change in the future.
Reimplemented from Bio::SeqIO::Interfaces::SequenceWriter.
00137 : """Use this to write an entire file containing the given records. records - a SeqRecord iterator, or list of SeqRecords Right now this code uses Bio.Clustalw.ClustalAlignment to do the hard work - this may change in the future. """ # ToDo - decide if using Bio.Clustalw.ClustalAlignment is # actually the best way to handle this. # # Copying that thirty lines of code (with slight tweaks) # would be much simpler, and would probably run quicker and # use less memory as it doesn't build a ClustalAlignment # object. # # The downside is code duplication. length_of_sequences = None alignment = ClustalAlignment() for record in records : if length_of_sequences is None : length_of_sequences = len(record.seq) elif length_of_sequences <> len(record.seq) : raise ValueError("Sequences must all be the same length") if length_of_sequences <= 0 : raise ValueError("Non-empty sequences are required") #ToDo, check alphabet for this sequence matches that #specified for the alignment. Not sure how the #alphabet.contains() method is intended to be used, #but it doesn't make sense to me right now. #Doing this works, but ClustalAlignment currently uses #the record.descrption when outputing the records. #alignment._records.append(record) #Make sure we don't get any spaces in the record #identifier when output in the file by replacing #them with underscores: alignment.add_sequence(record.id.replace(" ","_"), record.seq.tostring()) if len(alignment.get_all_seqs()) == 0 : raise ValueError("Must have at least one sequence") self.handle.write(str(alignment)) #Don't close the handle. Doing so would prevent this code #from writing concatenated Clustal files which might be used #in phylogenetic bootstrapping (very common with phylip). #self.handle.close() if __name__ == "__main__" :