Пример #1
0
    def test_codons(self):
        """AminoAcidUsage codons should return most likely codon freqs"""
        a = AminoAcidUsage('GGG')
        c = CodonUsage('GGUGGCGGAGGG')
        c.normalize()
        self.assertEqual(a.codons(), c)
        a = AminoAcidUsage('D')
        c = CodonUsage('GAUGAC')
        c.normalize()
        self.assertEqual(a.codons(), c)

        a = AminoAcidUsage('GDDFMM')
        c = CodonUsage('GGUGGCGGAGGG'+'GAUGAC'*4+'UUUUUC'*2+'AUG'*8)
        c.normalize()
        self.assertEqual(a.codons(), c)

        a = AminoAcidUsage('II*')
        c = CodonUsage('AUUAUCAUA'*2+'UAAUAGUGA')
        c.normalize()
        self.assertEqual(a.codons(), c)

        #check that it works with a nonstandard code
        code = GeneticCode('A'*4+'C'*28+'G'*32)
        a = AminoAcidUsage('AAA')
        c = CodonUsage('UUUUUCUUAUUG')
        c.normalize()
        self.assertEqual(a.codons(code), c)

        #check that it works with unequal codon frequencies
        unequal = CodonUsage({'GGU':5,'GGC':2,'GGA':2,'GGG':1,'UUU':3,'UUC':1})
        a = AminoAcidUsage('GFFF')
        exp = {
            'GGU':0.5*0.25,
            'GGC':0.2*0.25,
            'GGA':0.2*0.25,
            'GGG':0.1*0.25,
            'UUU':0.75*0.75,
            'UUC':0.25*0.75
        }
        obs = a.codons(codon_usage=unequal)
        for codon, freq in obs.items():
            self.assertFloatEqual(freq, exp.get(codon, 0))
Пример #2
0
 def test_init_string(self):
     """CodonUsage should count codons in string"""
     u = CodonUsage('UUUCCCUUUUUUGA')
     self.assertEqual(u, CodonUsage({'UUU':3, 'CCC':1, 'GA':1}))
     u.normalize()
     self.assertEqual(u, CodonUsage({'UUU':0.75, 'CCC':0.25}))