[Biopython-dev] Improving the Alignment object

Michiel de Hoon mdehoon at c2b2.columbia.edu
Sat Jul 28 15:23:51 UTC 2007


Peter wrote:
> Michiel de Hoon wrote:
>> Peter wrote:
>>>> For instance, the Alignment object should
>>>> support changing characters in the alignment without a need of 
>>>> copying it (using  aln[a,x] = "D"). Can it be done now with 
>>>> Alignment which is a list of SeqRecord objects with sequences 
>>>> implemented as immutable Seq objects ?
>> ....
>>> To me the obvious way to handle this is to have a MutableAlignment 
>>> sub-class, where editing individual elements with aln[r,c] = "D" 
>>> would be supported (possibly implemented using the MutableSeq class 
>>> internally rather than the immutable Seq class).
>>>
>> I don't think we'd need a separate MutableAlignment for that. An 
>> Alignment is a list of sequences and is therefore mutable. If we add a 
>> __setitem__ method to the Alignment class, then this method can take 
>> care of constructing a new sequence and put it in the appropriate row.
>>
> So rather than editing one character of a MutableSeq, we could replace 
> one immutable Seq object with a new immutable Seq object where one 
> character was different? That would work - sounds a little slow, but 
> certainly possible.
> 
At first, I also thought that that would be slow, especially for long 
sequences. But in practice, it's surprisingly fast. Unless somebody 
wants to edit an alignment of chromosome-size sequences, we probably 
won't run into a speed problem.

--Michiel.



More information about the Biopython-dev mailing list