biopython/biopython — pull request #277 by peterjc (2014-01-16 16:51:42+00:00)
Title: Allowing summation of Seq, SeqRecord and Alignment objects?

Hello all, this pull requests includes zero as a special case in the `__radd__` methods of these classes (invoked by Python when doing `0 + my_seq` or `0 + my_record` etc) which happens inside a summation call (e.g. `sum([seq1, seq2, seq3])`.

I recently I had to write something like this:

# Some loop to build up a combined alignment
merged_alignment = None
for x in y:
if z:
# create some new alignment object w, then...
if merged_alignment is None:
merged_alignment = w
else:
merged_alignment += w

This does not feel elegant, the natural style was to sum a list:

# Some loop to build up a list of alignments to be combined
alignments = []
for x in y:
if z:
# create some new alignment object w, then...
alignments.append(w)
merged_alignment = sum(alignments)

An interesting side effect of this is you can do things like this:

from Bio import SeqIO
merged_record = sum(SeqIO.parse(filename, format))

Which seems interesting. Overall I'm unsure if this is a compelling improvement or not... thoughts?