mailr27253 - /trunk/test_suite/unit_tests/_lib/_sequence_alignment/test_needleman_wunsch.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on January 21, 2015 - 11:39:
Author: bugman
Date: Wed Jan 21 11:39:24 2015
New Revision: 27253

URL: http://svn.gna.org/viewcvs/relax?rev=27253&view=rev
Log:
Created a unit test for checking the Needleman-Wunsch sequence alignment 
algorithm.

This uses the DNA data from the example in the Wikipedia article at
https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm.  The test 
shows that the
implementation of the 
lib.sequence_alignment.needleman_wunsch.needleman_wunsch_align() function is
correct.


Added:
    
trunk/test_suite/unit_tests/_lib/_sequence_alignment/test_needleman_wunsch.py

Added: 
trunk/test_suite/unit_tests/_lib/_sequence_alignment/test_needleman_wunsch.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_lib/_sequence_alignment/test_needleman_wunsch.py?rev=27253&view=auto
==============================================================================
--- 
trunk/test_suite/unit_tests/_lib/_sequence_alignment/test_needleman_wunsch.py 
      (added)
+++ 
trunk/test_suite/unit_tests/_lib/_sequence_alignment/test_needleman_wunsch.py 
      Wed Jan 21 11:39:24 2015
@@ -0,0 +1,58 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2015 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# This program is distributed in the hope that it will be useful,            
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Python module imports.
+from unittest import TestCase
+
+# relax module imports.
+from lib.sequence_alignment.needleman_wunsch import needleman_wunsch_align
+
+
+class Test_needleman_wunsch(TestCase):
+    """Unit tests for the lib.sequence_alignment.needleman_wunsch relax 
module."""
+
+    def test_needleman_wunsch_align_DNA(self):
+        """Test the Needleman-Wunsch sequence alignment for two DNA 
sequences."""
+
+        # The sequences.
+        seq1 = 'GCATGCU'
+        seq2 = 'GATTACA'
+        print(seq1)
+        print(seq2)
+
+        # Perform the alignment. 
+        align1, align2, gaps = needleman_wunsch_align(seq1, seq2)
+        print(align1)
+        print(align2)
+        print(gaps)
+
+        # Check the alignment.
+        self.assertEqual(align1, 'GCA-TGCU')
+        self.assertEqual(align2, 'G-ATTACA')
+
+        # The gap matrix.
+        real_gaps = [
+                [0, 0, 0, 1, 0, 0, 0, 0],
+                [0, 1, 0, 0, 0, 0, 0, 0]
+        ]
+        for i in range(2):
+            for j in range(8):
+                self.assertEqual(gaps[i, j], real_gaps[i][j])




Related Messages


Powered by MHonArc, Updated Wed Jan 21 12:20:02 2015