Exemple #1
0
 def test_normalize(self):
     """PositionalBaseUsage normalize should normalize each position"""
     a, c, g = BaseUsage('AAGC'), BaseUsage('CCGA'), BaseUsage('GGCA')
     p = PositionalBaseUsage(a, c, g)
     self.assertEqual(p[0], {'A':2, 'C':1, 'G':1, 'U':0})
     p.normalize()
     self.assertEqual(p[0], {'A':0.5, 'C':0.25, 'G':0.25, 'U':0})
     self.assertEqual(p[1], {'A':0.25, 'C':0.5, 'G':0.25, 'U':0})
     self.assertEqual(p[2], {'A':0.25, 'C':0.25, 'G':0.5, 'U':0})
Exemple #2
0
 def test_normalize(self):
     """PositionalBaseUsage normalize should normalize each position"""
     a, c, g = BaseUsage('AAGC'), BaseUsage('CCGA'), BaseUsage('GGCA')
     p = PositionalBaseUsage(a, c, g)
     self.assertEqual(p[0], {'A': 2, 'C': 1, 'G': 1, 'U': 0})
     p.normalize()
     self.assertEqual(p[0], {'A': 0.5, 'C': 0.25, 'G': 0.25, 'U': 0})
     self.assertEqual(p[1], {'A': 0.25, 'C': 0.5, 'G': 0.25, 'U': 0})
     self.assertEqual(p[2], {'A': 0.25, 'C': 0.25, 'G': 0.5, 'U': 0})
Exemple #3
0
 def test_info(self):
     """PositionalBaseUsage info should work as expected"""
     #test a cycle of setting the Info and setting it back again
     p = PositionalBaseUsage()
     self.assertRaises(AttributeError, getattr, p, 'upper')
     p.Info = 'xyz'
     self.assertEqual(p.upper(), 'XYZ')
     p.Info = None
     self.assertRaises(AttributeError, getattr, p, 'upper')
Exemple #4
0
 def test_info(self):
     """PositionalBaseUsage info should work as expected"""
     #test a cycle of setting the Info and setting it back again
     p = PositionalBaseUsage()
     self.assertRaises(AttributeError, getattr, p, 'upper')
     p.Info = 'xyz'
     self.assertEqual(p.upper(), 'XYZ')
     p.Info = None
     self.assertRaises(AttributeError, getattr, p, 'upper')
Exemple #5
0
 def test_getitem(self):
     """PositionalBaseUsage getitem should return 1st, 2nd, 3rd in order"""
     a, c, g = BaseUsage('A'), BaseUsage('C'), BaseUsage('G')
     p = PositionalBaseUsage(a, c, g)
     assert p.First is a
     assert p.Second is c
     assert p.Third is g
     #make sure they're not all the same object
     assert p.First is not g
     #test positive indices
     assert p[0] is p.First
     assert p[1] is p.Second
     assert p[2] is p.Third
     #test negative indices
     assert p[-1] is p.Third
     assert p[-2] is p.Second
     assert p[-3] is p.First
     try:
         x = p[3]
     except IndexError:
         pass
     else:
         self.fail("Failed to raise IndexError on bad index")
     #test iteration
     for o, e in zip(p, [a, c, g]):
         assert o is e
Exemple #6
0
 def test_init_empty(self):
     """PositionalBaseUsage init when empty should set all freqs to 0"""
     p = PositionalBaseUsage()
     assert p[0] is not p[1]
     assert p[1] is not p[2]
     assert p[0] is not p[2]
     for i in p:
         self.assertEqual(i, BaseUsage())
Exemple #7
0
 def test_positionalBases(self):
     """PositionalBaseUsage positionalBases should return same object"""
     p = PositionalBaseUsage()
     x = p.positionalBases()
     assert p is x
Exemple #8
0
 def test_bases(self):
     """PositionalBaseUsage bases should sum bases at each position"""
     a, c, g = BaseUsage('AAGC'), BaseUsage('CCGA'), BaseUsage('GGCA')
     p = PositionalBaseUsage(a, c, g)
     b = p.bases()
     self.assertEqual(b, BaseUsage('AAGCCCGAGGCA'))
Exemple #9
0
 def test_positionalBases(self):
     """PositionalBaseUsage positionalBases should return same object"""
     p = PositionalBaseUsage()
     x = p.positionalBases()
     assert p is x
Exemple #10
0
 def test_bases(self):
     """PositionalBaseUsage bases should sum bases at each position"""
     a, c, g = BaseUsage('AAGC'), BaseUsage('CCGA'), BaseUsage('GGCA')
     p = PositionalBaseUsage(a, c, g)
     b = p.bases()
     self.assertEqual(b, BaseUsage('AAGCCCGAGGCA'))