Пример #1
0
    def test_codons(self):
        """PositionalBaseUsage codons should give expected codon freqs"""
        #one of each base should give freqs if 1/64 for everything
        orig = CodonUsage('UUUCCCAAAGGG')
        b = orig.positionalBases()
        final = b.codons()
        self.assertEqual(len(final), 64)
        for i in final:
            self.assertFloatEqual(final[i], 1.0/64)

        #two bases at each position should give correct freqs
        orig = CodonUsage('UCGAGUUCGUCG')
        final = orig.positionalBases().codons()
        exp = {
            'UCG':  0.75 * 0.75 * 0.75,
            'UCU':  0.75 * 0.75 * 0.25,
            'UGG':  0.75 * 0.25 * 0.75,
            'UGU':  0.75 * 0.25 * 0.25,
            'ACG':  0.25 * 0.75 * 0.75,
            'ACU':  0.25 * 0.75 * 0.25,
            'AGG':  0.25 * 0.25 * 0.75,
            'AGU':  0.25 * 0.25 * 0.25,
            }
        for f in final:
            if f in exp:
                self.assertFloatEqual(final[f], exp[f])
            else:
                self.assertEqual(final[f], 0)
Пример #2
0
    def test_aminoAcids(self):
        """PositionalBaseUsage aminoAcids should return correct amino acids"""
        #check hand-calculated values on a particular sequence
        orig = CodonUsage('UCGAGUUCGUCG')
        final = orig.positionalBases().aminoAcids()
        exp = {
            'S':  0.75 * 0.75 * 0.75 + 0.75 * 0.75 * 0.25 + 0.25*0.25*0.25,
            'W':  0.75 * 0.25 * 0.75,
            'C':  0.75 * 0.25 * 0.25,
            'T':  0.25 * 0.75 * 0.75 + 0.25 * 0.75 * 0.25,
            'R':  0.25 * 0.25 * 0.75,
            }
        for f in final:
            if f in exp:
                self.assertFloatEqual(final[f], exp[f])
            else:
                self.assertEqual(final[f], 0)

        #test for unbiased freqs on a couple of different genetic codes
        orig = CodonUsage('UUUCCCAAAGGG')
        final = orig.positionalBases().aminoAcids()
        SGC = GeneticCodes[1]
        for aa in final:
            self.assertEqual(final[aa], len(SGC[aa])/64.0)
        mt = GeneticCodes[2]
        final_mt = orig.positionalBases().aminoAcids(mt)
        self.assertNotEqual(final, final_mt)
        for aa in final_mt:
            self.assertEqual(final_mt[aa], len(mt[aa])/64.0)
Пример #3
0
 def test_positionalBases(self):
     """CodonUsage bases should count bases at each position correctly"""
     freqs = {'UUC':5, 'AUA':10, 'AUG':10, 'CGC':3, 'AGG':2, 'XYZ':8,
         'UAA':2, 'UGA':1}
     u = CodonUsage(freqs)
     b = u.positionalBases()
     assert isinstance(b, PositionalBaseUsage)
     first, second, third = b
     self.assertEqual(first, BaseUsage({'U':8,'C':3,'A':22,'X':8}))
     self.assertEqual(second, BaseUsage({'U':25,'C':0,'A':2,'G':6,'Y':8}))
     self.assertEqual(third, BaseUsage({'C':8,'A':13,'G':12,'Z':8}))
     #check that it also works when we purge
     p = u.positionalBases(purge_unwanted=True)
     first, second, third = p
     self.assertEqual(first, BaseUsage({'U':5,'C':3,'A':2}))
     self.assertEqual(second, BaseUsage({'U':5,'G':5}))
     self.assertEqual(third, BaseUsage({'C':8,'G':2}))
     #check that it also works with a different genetic code, and, 
     #incidentally, that the purging didn't affect the original object
     u.GeneticCode = GeneticCodes[2] #mt code: different stop codons
     p = u.positionalBases(purge_unwanted=True)
     first, second, third = p
     self.assertEqual(first, BaseUsage({'U':6,'C':3,'A':20}))
     self.assertEqual(second, BaseUsage({'U':25,'G':4}))
     self.assertEqual(third, BaseUsage({'C':8,'A':11,'G':10}))