[Biopython-dev] syntax of indices for future Alignment object

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


# Current method to add a row to the alignment:
>>> aln.add_sequence("seq1", "ATCGTTGC")
...

Peter wrote:
> We also could add an add_record method to the alignment object which
> takes a SeqRecord, plus optional weight (and start and end?). Marc
> Colosimo also made this point on bug 1944 (although I don't like his
> mixed case method name).

This is Marc Colosimo's suggestion for adding a SeqRecord:
     def addSeqRecord(self, seqRec):
         """Add a Sequence Record to the Alignment

         @param seqRec: a sequence record (SeqRecord) to add.
         """
         if isinstance(seqRec, SeqRecord):
             self._records.append(seqRec)
         else:
             raise TypeError("sequence is NOT a SeqRecord Object")

Since an Alignment is essentially a list of SeqRecords, I propose that 
we call the method to add a row to this list "append". In addition, this 
method should be able to take a SeqRecord, a Seq object, or a plain 
string. 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")

This method can be generalized to allow a descriptor, weight, start, end 
end, just like in the current add_sequence method. Then we can replace 
add_sequence and addSeqRecord by a single append method.

--Michiel.



More information about the Biopython-dev mailing list