Ejemplo n.º 1
0
 def test_positionalBases(self):
     """AminoAcidUsage positionalBases should return best positional bases"""
     a = AminoAcidUsage('WQRSFADDQW')
     exp = a.codons().positionalBases()
     obs = a.positionalBases()
     for o, e in zip(obs, exp):
         self.assertFloatEqual(o, e)
Ejemplo n.º 2
0
 def test_positionalBases(self):
     """AminoAcidUsage positionalBases should return best positional bases"""
     a = AminoAcidUsage('WQRSFADDQW')
     exp = a.codons().positionalBases()
     obs = a.positionalBases()
     for o, e in zip(obs, exp):
         self.assertFloatEqual(o, e)
Ejemplo n.º 3
0
 def test_init_empty(self):
     """AminoAcidUsage should init with empty freqs"""
     a = AminoAcidUsage()
     for key, val in a.items():
         self.assertEqual(val, 0)
     self.assertEqual(len(a), 21)
     assert 'A' in a
     assert 'a' in a
Ejemplo n.º 4
0
 def test_init_empty(self):
     """AminoAcidUsage should init with empty freqs"""
     a = AminoAcidUsage()
     for key, val in a.items():
         self.assertEqual(val, 0)
     self.assertEqual(len(a), 21)
     assert 'A' in a
     assert 'a' in a
Ejemplo n.º 5
0
    def test_bases(self):
        """AminoAcidUsage bases should return most likely base freqs"""
        a = AminoAcidUsage('GGG')
        self.assertEqual(a.bases(),
            {'G':9.0/12,'U':1.0/12,'C':1.0/12,'A':1.0/12})

        a = AminoAcidUsage('CAGTWERQWE')
        exp = a.codons().bases()
        exp.normalize()
        self.assertFloatEqual(a.bases(), exp)
Ejemplo n.º 6
0
 def test_init_data(self):
     """AminoAcidUsage should init with data"""
     a = AminoAcidUsage('aadddx')
     self.assertEqual(a['A'], 2)
     self.assertEqual(a['d'], 3)
     self.assertEqual(a['X'], 1)
     a.normalize()
     self.assertEqual(a['a'], 0.4)
     self.assertEqual(a['d'], 0.6)
     assert 'x' not in a
Ejemplo n.º 7
0
 def test_init_data(self):
     """AminoAcidUsage should init with data"""
     a = AminoAcidUsage('aadddx')
     self.assertEqual(a['A'], 2)
     self.assertEqual(a['d'], 3)
     self.assertEqual(a['X'], 1)
     a.normalize()
     self.assertEqual(a['a'], 0.4)
     self.assertEqual(a['d'], 0.6)
     assert 'x' not in a
Ejemplo n.º 8
0
    def test_bases(self):
        """AminoAcidUsage bases should return most likely base freqs"""
        a = AminoAcidUsage('GGG')
        self.assertEqual(a.bases(), {
            'G': 9.0 / 12,
            'U': 1.0 / 12,
            'C': 1.0 / 12,
            'A': 1.0 / 12
        })

        a = AminoAcidUsage('CAGTWERQWE')
        exp = a.codons().bases()
        exp.normalize()
        self.assertFloatEqual(a.bases(), exp)
Ejemplo n.º 9
0
 def test_aminoAcids(self):
     """BaseUsage aminoAcids should give the same results as the codons"""
     known_data = {
         'AAA': .6 * .6 * .6,
         'AAU': .6 * .6 * .4,
         'AUA': .6 * .4 * .6,
         'AUU': .6 * .4 * .4,
         'UAA': .4 * .6 * .6,
         'UAU': .4 * .6 * .4,
         'UUA': .4 * .4 * .6,
         'UUU': .4 * .4 * .4,
     }
     known = CodonUsage(known_data)
     b = BaseUsage({'a': 3, 'T': 2, 'X': 1})
     self.assertEqual(b.aminoAcids(), known.aminoAcids())
     #check that the genetic code is passed through correctly
     all_g = GeneticCode('G' * 64)
     self.assertEqual(b.aminoAcids(all_g), AminoAcidUsage({'G': 1}))
Ejemplo n.º 10
0
 def test_aminoAcids(self):
     """AminoAcidUsage aminoAcids should return same object"""
     a = AminoAcidUsage('REWQDFTDSF')
     b = a.aminoAcids()
     assert a is b
Ejemplo n.º 11
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))
Ejemplo n.º 12
0
 def test_aminoAcids(self):
     """AminoAcidUsage aminoAcids should return same object"""
     a = AminoAcidUsage('REWQDFTDSF')
     b = a.aminoAcids()
     assert a is b
Ejemplo n.º 13
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))
Ejemplo n.º 14
0
 def test_aminoAcids(self):
     """CodonUsage aminoAcids should correctly count amino acids"""
     freqs = {
         'UUC': 5,
         'AUA': 10,
         'AUG': 10,
         'CGC': 3,
         'AGG': 2,
         'XYZ': 8,
         'UAA': 2,
         'UGA': 1
     }
     u = CodonUsage(freqs, "test")
     self.assertEqual(u.Info, 'test')
     for key, val in u.items():
         if key in freqs:
             self.assertEqual(val, freqs[key])
         else:
             self.assertEqual(val, 0)
     aa = u.aminoAcids()
     self.assertEqual(
         aa,
         AminoAcidUsage({
             'F': 5,
             'I': 10,
             'M': 10,
             'R': 5,
             '*': 3,
             'X': 8
         }))
     #check that it works with a different genetic code
     u.GeneticCode = GeneticCodes['2']
     aa = u.aminoAcids()
     self.assertEqual(
         aa,
         AminoAcidUsage({
             'F': 5,
             'I': 0,
             'M': 20,
             'R': 3,
             '*': 4,
             'W': 1,
             'X': 8
         }))
     #check that it works if a genetic code is supplied explicitly
     u.GeneticCode = GeneticCodes[1]
     aa = u.aminoAcids()
     self.assertEqual(
         aa,
         AminoAcidUsage({
             'F': 5,
             'I': 10,
             'M': 10,
             'R': 5,
             '*': 3,
             'X': 8
         }))
     aa_2 = u.aminoAcids(2)
     self.assertEqual(
         aa_2,
         AminoAcidUsage({
             'F': 5,
             'I': 0,
             'M': 20,
             'R': 3,
             '*': 4,
             'W': 1,
             'X': 8
         }))
     #check that we held onto the info object through the above
     self.assertEqual(aa_2.Info, 'test')