Skip to content
This repository
Browse code

Added unit tests.

  • Loading branch information...
commit f7ade9afd2f6978aaf41c4fe83148dbe0acba0ca 1 parent d4f9fb8
Bryan Lunt authored January 27, 2013 peterjc committed January 28, 2013

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. 41  Tests/test_pairwise2.py
41  Tests/test_pairwise2.py
@@ -378,6 +378,47 @@ def test_align_one_char3(self):
378 378
 """)
379 379
 
380 380
 
  381
+class TestPersiteGapPenalties(unittest.TestCase):
  382
+    """
  383
+    This tests that the gap penalty callbacks are really being used with the correct gap opening position.
  384
+    The second test forces a bad alignment by having a very expsive gap penalty where one would noremally expect a gap, and a cheap gap pentaly in another place.
  385
+    """
  386
+
  387
+
  388
+    def test_gap_here_only_1(self):
  389
+        seq1 = "AAAABBBAAAACCCCCCCCCCCCCCAAAABBBAAAA"
  390
+        seq2 = "AABBBAAAACCCCAAAABBBAA"
  391
+        breaks = [0,11,len(seq2)]
  392
+        nogaps = lambda x,y: -2000 -y#Very expensive to open a gap in seq1
  393
+        specificgaps = lambda x,y: (-2 -y) if x in breaks else (-2000 -y)#Very expensive to open a gap in seq2 unless it is in one of the allowed positions
  394
+        alignments = pairwise2.align.globalmc(seq1,seq2,1,-1,nogaps,specificgaps)
  395
+        self.assertEqual(len(alignments),1)
  396
+	formatted = pairwise2.format_alignment(*alignments[0])
  397
+	self.assertEqual(formatted,"""\
  398
+AAAABBBAAAACCCCCCCCCCCCCCAAAABBBAAAA
  399
+||||||||||||||||||||||||||||||||||||
  400
+--AABBBAAAACC----------CCAAAABBBAA--
  401
+  Score=2
  402
+""")
  403
+
  404
+
  405
+    def test_gap_here_only_2(self):
  406
+        seq1 = "AAAABBBAAAACCCCCCCCCCCCCCAAAABBBAAAA"
  407
+        seq2 = "AABBBAAAACCCCAAAABBBAA"
  408
+        breaks = [0,3,len(seq2)]
  409
+        nogaps = lambda x,y: -2000 -y#Very expensive to open a gap in seq1
  410
+        specificgaps = lambda x,y: (-2 -y) if x in breaks else (-2000 -y)#Very expensive to open a gap in seq2 unless it is in one of the allowed positions
  411
+        alignments = pairwise2.align.globalmc(seq1,seq2,1,-1,nogaps,specificgaps)
  412
+        self.assertEqual(len(alignments),1)
  413
+	formatted = pairwise2.format_alignment(*alignments[0])
  414
+	self.assertEqual(formatted,"""\
  415
+AAAABBBAAAACCCCCCCCCCCCCCAAAABBBAAAA
  416
+||||||||||||||||||||||||||||||||||||
  417
+--AAB----------BBAAAACCCCAAAABBBAA--
  418
+  Score=-10
  419
+""")
  420
+
  421
+
381 422
 if __name__ == '__main__':
382 423
     runner = unittest.TextTestRunner(verbosity = 2)
383 424
     unittest.main(testRunner=runner)

0 notes on commit f7ade9a

Please sign in to comment.
Something went wrong with that request. Please try again.