def testStopCodonsNotInCodonTable(self): """ The stop codons must not be in the main table. """ for stop in STOP_CODONS: for codons in CODONS.values(): self.assertNotIn(stop, codons)
def testCodonContent(self): """ Codons must only contain the letters A, T, G, C. """ for codons in CODONS.values(): for codon in codons: self.assertTrue(all(letter in 'ACGT' for letter in codon))
def testCodonsAreNotAbbrev3s(self): """ No codon can be the same as an amino acid 3-letter abbreviation (or else our find function may not be unambiguous in what it returns). """ for codons in CODONS.values(): self.assertFalse( any(codon.title() in ABBREV3_TO_ABBREV1 for codon in codons))
def testDistinct(self): """ All nucleotide triples must be distinct. """ seen = set() for codons in CODONS.values(): for codon in codons: seen.add(codon) self.assertEqual(61, len(seen))
def testAllCodonsPresent(self): """ All possible codons must be present, as either coding for an AA or as a stop codon. """ combinations = set(''.join(x) for x in product('ACGT', 'ACGT', 'ACGT')) for codons in CODONS.values(): for codon in codons: combinations.remove(codon) # Just the stop codons should be left. self.assertEqual(set(STOP_CODONS), combinations)
def testAllCodonsPresent(self): """ All possible codons must be present, as either coding for an AA or as a stop codon. """ combinations = set( ''.join(x) for x in product('ACGT', 'ACGT', 'ACGT')) for codons in CODONS.values(): for codon in codons: combinations.remove(codon) # Just the stop codons should be left. self.assertEqual(set(STOP_CODONS), combinations)
def findOrDie(s): """ Look up an amino acid. @param s: A C{str} amino acid specifier. This may be a full name, a 3-letter abbreviation or a 1-letter abbreviation. Case is ignored. @return: An C{AminoAcid} instance, if one can be found. Else exit. """ aa = find(s) if aa: return aa else: print("Unknown amino acid or codon: %s" % s, file=sys.stderr) print("Valid arguments are: %s." % list(CODONS.keys()), file=sys.stderr) sys.exit(1)
def findOrDie(s): """ Look up an amino acid. @param s: A C{str} amino acid specifier. This may be a full name, a 3-letter abbreviation or a 1-letter abbreviation. Case is ignored. @return: An C{AminoAcid} instance, if one can be found. Else exit. """ aa = find(s) if aa: return aa else: print('Unknown amino acid or codon: %s' % s, file=sys.stderr) print('Valid arguments are: %s.' % list(CODONS.keys()), file=sys.stderr) sys.exit(1)
def testNumberCodons(self): """ The table must contain the right number of codons. """ self.assertEqual(44, sum(len(codons) for codons in CODONS.values()))
def testNumberCodons(self): """ The table must contain 61 codons. This is 4^3 - 3. I.e., all possible combinations of 3 bases minus the three stop codons. """ self.assertEqual(61, sum(len(codons) for codons in CODONS.values()))
def testCorrectAAs(self): """ The CODONS dict must have the correct AA keys. """ self.assertEqual(AA_LETTERS, sorted(CODONS.keys()))
def testCodonLength(self): """ All codons must be three bases long. """ for codons in CODONS.values(): self.assertTrue(all(len(codon) == 3 for codon in codons))
#!/usr/bin/env python import sys from Bio import SeqIO from os.path import exists from dark.aa import CODONS START_CODON = 'ATG' STOP_CODONS = {'TAA', 'TAG', 'TGA'} CODON_TO_AA = {} START_AA = 'M' STOP_AA = '*' for aa, codons in CODONS.items(): for codon in codons: CODON_TO_AA[codon] = aa for codon in STOP_CODONS: CODON_TO_AA[codon] = STOP_AA _rcTable = str.maketrans('ACGT', 'TGCA') def revcomp(s): """ Reverse complement a nucleotide string. """ return s.translate(_rcTable)[::-1]