[Biopython-dev] [Bug 1963] New: Adding __str__ method to codon tables and translators

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Sat Feb 25 09:33:25 EST 2006


http://bugzilla.open-bio.org/show_bug.cgi?id=1963

           Summary: Adding __str__ method to codon tables and translators
           Product: Biopython
           Version: Not Applicable
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Main Distribution
        AssignedTo: biopython-dev at biopython.org
        ReportedBy: biopython-bugzilla at maubp.freeserve.co.uk


The existing CodonTable and Translator objects do not provide a simple way to
"see" the table.  It would be nice to be able to just "print" them using the
__str__ method:

e.g.

>>> import Bio.Data.CodonTable
>>> print Bio.Data.CodonTable.standard_dna_table
  |   G     |  A     |  T     |  C     |
--+---------+--------+--------+--------+--
G | GGG G   |GAG E   |GTG V   |GCG A   | G
G | GGA G   |GAA E   |GTA V   |GCA A   | A
G | GGT G   |GAT D   |GTT V   |GCT A   | T
G | GGC G   |GAC D   |GTC V   |GCC A   | C
--+---------+--------+--------+--------+--
A | AGG R   |AAG K   |ATG M(s)|ACG T   | G
A | AGA R   |AAA K   |ATA I   |ACA T   | A
A | AGT S   |AAT N   |ATT I   |ACT T   | T
A | AGC S   |AAC N   |ATC I   |ACC T   | C
--+---------+--------+--------+--------+--
T | TGG W   |TAG Stop|TTG L(s)|TCG S   | G
T | TGA Stop|TAA Stop|TTA L   |TCA S   | A
T | TGT C   |TAT Y   |TTT F   |TCT S   | T
T | TGC C   |TAC Y   |TTC F   |TCC S   | C
--+---------+--------+--------+--------+--
C | CGG R   |CAG Q   |CTG L(s)|CCG P   | G
C | CGA R   |CAA Q   |CTA L   |CCA P   | A
C | CGT R   |CAT H   |CTT L   |CCT P   | T
C | CGC R   |CAC H   |CTC L   |CCC P   | C
--+---------+--------+--------+--------+--

This was done by adding the following method to Bio/Data/CodonTable.py class
CodonTable:

    def __str__(self) :
        """Returns a simple text representation of the codon table"""
        answer="  | " + "|".join( \
            ["  %s     " % c2 for c2 in self.nucleotide_alphabet.letters] \
            ) + "|"
        answer = answer + "\n--+---------+--------+--------+--------+--"
        for c1 in self.nucleotide_alphabet.letters :
            for c3 in self.nucleotide_alphabet.letters :
                line = c1 + " | "
                for c2 in self.nucleotide_alphabet.letters :
                    codon = c1+c2+c3
                    if codon in self.start_codons :
                        line = line + "%s %s(s)|" \
                               % (codon, self.forward_table[codon])
                    elif codon in self.stop_codons :
                        line = line + "%s Stop|" \
                               % (codon)
                    else:
                        line = line + "%s %s   |" \
                               % (codon, self.forward_table[codon])
                line = line + " " + c3
                answer = answer + "\n"+ line 
            answer = answer + "\n--+---------+--------+--------+--------+--"
        return answer

A similar __str__ method could be added to Bio/Translate.py to call the codon
table's __str__ method.

Comments?  Should the order be UCAG rather than following
self.nucleotide_alphabet.letters?   Should it include three letter amino acid
codes as well?




------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the Biopython-dev mailing list