Skip to content

Commit

Permalink
small cleanups improving coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
yhoogstrate committed Feb 8, 2017
1 parent 8daa138 commit 6be409e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 45 deletions.
22 changes: 14 additions & 8 deletions drdisco/CigarAlignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,25 @@ def init_matrix(self):
for j in xrange(1, self.n + 1):
self.tb_matrix[0][j] = "-"

def print_tb_matrix(self):
def str_tb_matrix(self):
out = ''

for j in xrange(self.n + 1):
for i in xrange(self.m + 1):
print self.tb_matrix[i][j],
print
print
out += str(self.tb_matrix[i][j]) + "\t"
out += "\n"

return out

def str_sc_matrix(self):
out = ''

def print_matrix(self):
for j in xrange(self.n + 1):
for i in xrange(self.m + 1):
print str(self.matrix[i][j]) + "\t",
print
print
out += str(self.matrix[i][j]) + "\t"
out += "\n"

return out

def get_diagonal(self, diagonal):
# 0, 0
Expand Down
55 changes: 18 additions & 37 deletions tests/test_cigaralignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,83 +39,64 @@ def test_01(self):
cig1 = "15S15M"
cig2 = "15M15S"

ans1 = [(4, 15), (0, 15)]
ans2 = [(0, 15), (4, 15)]

ca = CigarAlignment(cigar_to_cigartuple(cig1), cigar_to_cigartuple(cig2))
self.assertEqual(ca.str_tb_matrix(), 't\t|\t|\t\n-\t?\t?\t\n-\t?\t?\t\n')
self.assertEqual(ca.str_sc_matrix(), '0\t225\t225\t\n225\t0\t0\t\n225\t0\t0\t\n')

ca.fill_matrix()
aligned_cigars = ca.traceback_matrix()
self.assertEqual(ca.str_tb_matrix(), 't\t|\t|\t\n-\tm\t|\t\n-\t-\tm\t\n')
self.assertEqual(ca.str_sc_matrix(), '0\t225\t225\t\n225\t0\t225\t\n225\t225\t0\t\n')

# print aligned_cigars[0]
# print aligned_cigars[1]
aligned_cigars = ca.traceback_matrix()
self.assertEqual(ca.str_tb_matrix(), 't\t|\t|\t\n-\tm\t|\t\n-\t-\tm\t\n')
self.assertEqual(ca.str_sc_matrix(), '0\t225\t225\t\n225\t0\t225\t\n225\t225\t0\t\n')

self.assertEqual(aligned_cigars[0], ans1)
self.assertEqual(aligned_cigars[1], ans2)
self.assertEqual(aligned_cigars[0], [(4, 15), (0, 15)])
self.assertEqual(aligned_cigars[1], [(0, 15), (4, 15)])

def test_02(self):
cig1 = "15M15S"
cig2 = "15S15M"

ans1 = [(0, 15), (4, 15)]
ans2 = [(4, 15), (0, 15)]

ca = CigarAlignment(cigar_to_cigartuple(cig1), cigar_to_cigartuple(cig2))
ca.fill_matrix()
aligned_cigars = ca.traceback_matrix()

# print aligned_cigars[0]
# print aligned_cigars[1]

self.assertEqual(aligned_cigars[0], ans1)
self.assertEqual(aligned_cigars[1], ans2)
self.assertEqual(aligned_cigars[0], [(0, 15), (4, 15)])
self.assertEqual(aligned_cigars[1], [(4, 15), (0, 15)])

def test_03(self):
cig1 = "16M28431N69M41S"
cig2 = "85S41M"

ans1 = [(0, 85), (4, 41)]
ans2 = [(4, 85), (0, 41)]

ca = CigarAlignment(cigar_to_cigartuple(cig1), cigar_to_cigartuple(cig2))
ca.fill_matrix()
aligned_cigars = ca.traceback_matrix()

# print aligned_cigars[0]
# print aligned_cigars[1]

self.assertEqual(aligned_cigars[0], ans1)
self.assertEqual(aligned_cigars[1], ans2)
self.assertEqual(aligned_cigars[0], [(0, 85), (4, 41)])
self.assertEqual(aligned_cigars[1], [(4, 85), (0, 41)])

def test_04(self):
cig1 = "85S41M"
cig2 = "16M28431N69M41S"

ans1 = [(4, 85), (0, 41)]
ans2 = [(0, 85), (4, 41)]

ca = CigarAlignment(cigar_to_cigartuple(cig1), cigar_to_cigartuple(cig2))
ca.fill_matrix()
aligned_cigars = ca.traceback_matrix()

# print aligned_cigars[0]
# print aligned_cigars[1]

self.assertEqual(aligned_cigars[0], ans1)
self.assertEqual(aligned_cigars[1], ans2)
self.assertEqual(aligned_cigars[0], [(4, 85), (0, 41)])
self.assertEqual(aligned_cigars[1], [(0, 85), (4, 41)])

def test_05(self):
cig1 = "40S32M1I52M"
cig2 = "40M85S"

ans1 = [(4, 40), (0, 84)]
ans2 = [(0, 40), (4, 85)]

ca = CigarAlignment(cigar_to_cigartuple(cig1), cigar_to_cigartuple(cig2))
ca.fill_matrix()
aligned_cigars = ca.traceback_matrix()

self.assertEqual(aligned_cigars[0], ans1)
self.assertEqual(aligned_cigars[1], ans2)
self.assertEqual(aligned_cigars[0], [(4, 40), (0, 84)])
self.assertEqual(aligned_cigars[1], [(0, 40), (4, 85)])
self.assertEqual(ca.get_order(), STRAND_REVERSE)


Expand Down

0 comments on commit 6be409e

Please sign in to comment.