[Biopython-dev] adding rows to an alignment object

Peter biopython-dev at maubp.freeserve.co.uk
Sat Jul 28 16:00:34 UTC 2007


Michiel de Hoon wrote:
> Since an Alignment is essentially a list of SeqRecords, I propose that 
> we call the method to add a row to this list "append".

Sounds very sensible.

 > In addition, this method should be able to take a SeqRecord, a Seq
 > object, or a plain string.

Do you really think we should complicate things like this? I would just 
accept SeqRecord objects (with optional start/end/weight).

> Something like this:
> 
>      def append(self, sequence):
>          if isinstance(sequence, SeqRecord):
>              self._records.append(sequence)
>          elif isinstance(sequence, Seq):
>              self._records.append(SeqRecord(sequence))
>          elif isinstance(sequence, str):
>              self._records.append(SeqRecord(Seq(sequence)))
>          else:
>              raise TypeError("sequence should be a string, a Seq Object, 
> or a SeqRecord object")

One minor point - we should use the alignment's alphabet when building a 
Seq object from a string. Perhaps we should even check the alphabet when 
asked to append a SeqRecord or Seq object...

 > This method can be generalized to allow a descriptor, weight, start,
 > end, just like in the current add_sequence method.

Where the descriptor is expected for Seq and string input, and used as 
the SeqRecord's id?

I would personally check the length matches the rest of the alignment 
(something the current add_sequence method doesn't do) otherwise its 
very easy to get a malformed alignment where some sequences are longer 
than others.

Also, I would leave the existing .add_sequence() method in place, but 
update its docstring to encourage use of .append() instead.

Peter




More information about the Biopython-dev mailing list