[Biopython-dev] Bio.SeqIO

Peter biopython-dev at maubp.freeserve.co.uk
Mon Feb 26 10:40:29 UTC 2007


Michiel de Hoon wrote:
> Alex Griffing wrote:
>>> The easiest way to accomplish this might be to change the __init__ of 
>>> the Alignment class from
>>>
>>> def __init__(self, alphabet)
>>>
>>> to
>>>
>>> def __init__(self, alphabet, records=[])
>>>   
>> Does this apply here?
>> http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects 
>>
> In theory, yes, but since we won't be modifying records it doesn't 
> matter. The full function would look like:
> 
>      def __init__(self, alphabet, records=[]):
>          self._alphabet = alphabet
>          self._records = list(records)
> 
> The "list" is necessary since the user may pass an iterator for records 
> instead of a list.

We (or the user) might well change the records - in particular, they 
might add MORE records.  How about this:

     def __init__(self, alphabet, records=None):
         """Initialize a new Alignment object.

         Arguments:
         o alphabet - The alphabet to use for the sequence objects that
                      are created.  This alphabet must be a gapped type.
         o records -  A list or iterator returning of SeqRecord objects
                      whose (gapped) sequences must be the same length.
         """
         self._alphabet = alphabet
         if records :
             self._records = list(records)
             #TODO - Check all seq lengths are the same?
             #TODO - Check the seq's alphabet is compatible?
         else :
             self._records = []


This passes relevant unit tests.

Peter




More information about the Biopython-dev mailing list