예제 #1
0
    def test_init(self):
        """JointEnumeration init should work as expected"""
        #should work for alphabet object
        a = JointEnumeration([DnaBases, RnaBases])
        self.assertEqual(len(a), 16)
        self.assertEqual(a.Shape, (4,4))
        self.assertEqual(a[0], ('T','U'))
        self.assertEqual(a[-1], ('G','G'))
        self.assertEqual(a._sub_enum_factors, array([[4],[1]]))

        #should work for arbitrary sequences
        a = JointEnumeration(['TCAG', 'UCAG'])
        self.assertEqual(len(a), 16)
        self.assertEqual(a[0], ('T','U'))
        self.assertEqual(a[-1], ('G','G'))
        self.assertEqual(a._sub_enum_factors, array([[4],[1]]))

        #should work for different length sequences
        a = JointEnumeration(['TCA', 'UCAG'])
        self.assertEqual(a.Shape, (3,4))
        self.assertEqual(len(a), 12)
        self.assertEqual(a[0], ('T','U'))
        self.assertEqual(a[-1], ('A','G'))
        self.assertEqual(a._sub_enum_factors, \
            array([[4],[1]])) #note: _not_ [3,1]
예제 #2
0
    def test_init(self):
        """JointEnumeration init should work as expected"""
        #should work for alphabet object
        a = JointEnumeration([DnaBases, RnaBases])
        self.assertEqual(len(a), 16)
        self.assertEqual(a.Shape, (4,4))
        self.assertEqual(a[0], ('T','U'))
        self.assertEqual(a[-1], ('G','G'))
        self.assertEqual(a._sub_enum_factors, array([[4],[1]]))

        #should work for arbitrary sequences
        a = JointEnumeration(['TCAG', 'UCAG'])
        self.assertEqual(len(a), 16)
        self.assertEqual(a[0], ('T','U'))
        self.assertEqual(a[-1], ('G','G'))
        self.assertEqual(a._sub_enum_factors, array([[4],[1]]))

        #should work for different length sequences
        a = JointEnumeration(['TCA', 'UCAG'])
        self.assertEqual(a.Shape, (3,4))
        self.assertEqual(len(a), 12)
        self.assertEqual(a[0], ('T','U'))
        self.assertEqual(a[-1], ('A','G'))
        self.assertEqual(a._sub_enum_factors, \
            array([[4],[1]])) #note: _not_ [3,1]
예제 #3
0
 def test_toString(self):
     """CharAlphabet toString should convert an input array to string"""
     r = CharAlphabet('UCAG')
     self.assertEqual(r.toString(array([[0,0,1],[0,3,2]], 'B')), 'UUC\nUGA')
     #should work with single seq
     self.assertEqual(r.toString(array([[0,0,1,0,3,2]], 'B')), 'UUCUGA')
     #should work with single seq
     self.assertEqual(r.toString(array([0,0,1,0,3,2], 'B')), 'UUCUGA')
     #should work with empty seq
     self.assertEqual(r.toString(array([], 'B')), '')
예제 #4
0
 def test_toString(self):
     """CharAlphabet toString should convert an input array to string"""
     r = CharAlphabet('UCAG')
     self.assertEqual(r.toString(array([[0,0,1],[0,3,2]], 'B')), 'UUC\nUGA')
     #should work with single seq
     self.assertEqual(r.toString(array([[0,0,1,0,3,2]], 'B')), 'UUCUGA')
     #should work with single seq
     self.assertEqual(r.toString(array([0,0,1,0,3,2], 'B')), 'UUCUGA')
     #should work with empty seq
     self.assertEqual(r.toString(array([], 'B')), '')
예제 #5
0
 def test_init(self):
     """CharAlphabet init should make correct translation tables"""
     r = CharAlphabet('UCAG')
     i2c, c2i = r._indices_to_chars, r._chars_to_indices
     s = array([0,0,1,0,3,2], 'b').tostring()
     self.assertEqual(s.translate(i2c), 'UUCUGA')
     self.assertEqual('UUCUGA'.translate(c2i), '\000\000\001\000\003\002')
예제 #6
0
 def test_init(self):
     """CharAlphabet init should make correct translation tables"""
     r = CharAlphabet('UCAG')
     i2c, c2i = r._indices_to_chars, r._chars_to_indices
     s = array([0,0,1,0,3,2], 'b').tostring()
     self.assertEqual(s.translate(i2c), 'UUCUGA')
     self.assertEqual('UUCUGA'.translate(c2i), '\000\000\001\000\003\002')
예제 #7
0
 def test_unpackArrays(self):
     """JointEnumeration unpackArrays should return correct arrays."""
     a = JointEnumeration(['xyz', 'abcd', 'ef'])
     v = [7, 15, 18, 0]
     result = a.unpackArrays(v)
     self.assertEqual(result,
                      array([[0, 1, 2, 0], [3, 3, 1, 0], [1, 1, 0, 0]]))
예제 #8
0
 def test_unpackArrays(self):
     """JointEnumeration unpackArrays should return correct arrays."""
     a = JointEnumeration(['xyz', 'abcd', 'ef'])
     v = [7,15,18,0]
     result = a.unpackArrays(v)
     self.assertEqual(result, array([[0,1,2,0],[3,3,1,0], [1,1,0,0]]))
예제 #9
0
 def test_toChars(self):
     """CharAlphabet toChars should convert an input array to chars"""
     r = CharAlphabet('UCAG')
     c = r.toChars(array([[0,0,1],[0,3,2]], 'B'))
     self.assertEqual(c, \
         array(['UUC','UGA'], 'c'))
예제 #10
0
 def test_fromArray(self):
     """CharAlphabet fromArray should return correct array"""
     r = CharAlphabet('UCAG')
     self.assertEqual(r.fromArray(array(['UUC','UGA'], 'c')), \
         array([[0,0,1],[0,3,2]], 'B'))
예제 #11
0
 def test_fromString(self):
     """CharAlphabet fromString should return correct array"""
     r = CharAlphabet('UCAG')
     self.assertEqual(r.fromString('UUCUGA'), array([0,0,1,0,3,2],'B'))
예제 #12
0
 def test_counts(self):
     """Enumeration counts should count freqs in array"""
     a = DnaBases
     f = array([[0,0,1,0,0,3]])
     self.assertEqual(a.counts(f), array([4,1,0,1]))
     #check that it works with byte array
     f = array([[0,0,1,0,0,3]], 'B')
     self.assertEqual(a.counts(f), array([4,1,0,1]))
     #should ignore out-of-bounds items
     g = [0,4]
     self.assertEqual(a.counts(g), array([1,0,0,0]))
     #make sure it works for long sequences, i.e. no wraparound at 255
     h = [0, 3] * 70000
     self.assertEqual(a.counts(h), array([70000,0,0,70000]))
     h2 = array(h).astype('B')
     self.assertEqual(a.counts(h2), array([70000,0,0,70000]))
     i = array([0,3] * 75000)
     self.assertEqual(a.counts(i), array([75000,0,0,75000]))
     #make sure it works for long _binary_ sequences, e.g. the results
     #of array comparisons.
     a = array([0,1,2,3]*10000)
     b = array([0,0,0,0]*10000)
     same = (a==b)
예제 #13
0
 def test_toChars(self):
     """CharAlphabet toChars should convert an input array to chars"""
     r = CharAlphabet('UCAG')
     c = r.toChars(array([[0,0,1],[0,3,2]], 'B'))
     self.assertEqual(c, \
         array(['UUC','UGA'], 'c'))
예제 #14
0
 def test_fromArray(self):
     """CharAlphabet fromArray should return correct array"""
     r = CharAlphabet('UCAG')
     self.assertEqual(r.fromArray(array(['UUC','UGA'], 'c')), \
         array([[0,0,1],[0,3,2]], 'B'))
예제 #15
0
 def test_fromString(self):
     """CharAlphabet fromString should return correct array"""
     r = CharAlphabet('UCAG')
     self.assertEqual(r.fromString('UUCUGA'), array([0,0,1,0,3,2],'B'))
예제 #16
0
 def test_counts(self):
     """Enumeration counts should count freqs in array"""
     a = DnaBases
     f = array([[0,0,1,0,0,3]])
     self.assertEqual(a.counts(f), array([4,1,0,1]))
     #check that it works with byte array
     f = array([[0,0,1,0,0,3]], 'B')
     self.assertEqual(a.counts(f), array([4,1,0,1]))
     #should ignore out-of-bounds items
     g = [0,4]
     self.assertEqual(a.counts(g), array([1,0,0,0]))
     #make sure it works for long sequences, i.e. no wraparound at 255
     h = [0, 3] * 70000
     self.assertEqual(a.counts(h), array([70000,0,0,70000]))
     h2 = array(h).astype('B')
     self.assertEqual(a.counts(h2), array([70000,0,0,70000]))
     i = array([0,3] * 75000)
     self.assertEqual(a.counts(i), array([75000,0,0,75000]))
     #make sure it works for long _binary_ sequences, e.g. the results
     #of array comparisons.
     a = array([0,1,2,3]*10000)
     b = array([0,0,0,0]*10000)
     same = (a==b)