Package test_suite :: Package unit_tests :: Package _lib :: Package _sequence_alignment :: Module test_needleman_wunsch
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._lib._sequence_alignment.test_needleman_wunsch

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2015 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from unittest import TestCase 
 24   
 25  # relax module imports. 
 26  from lib.sequence_alignment.needleman_wunsch import needleman_wunsch_align 
 27  from lib.sequence_alignment.substitution_matrices import NUC_4_4, NUC_4_4_SEQ, SIMILARITY_DNA, SIMILARITY_DNA_SEQ 
 28   
 29   
30 -class Test_needleman_wunsch(TestCase):
31 """Unit tests for the lib.sequence_alignment.needleman_wunsch relax module.""" 32
34 """Test the Needleman-Wunsch sequence alignment for two DNA sequences.""" 35 36 # The sequences. 37 seq1 = 'GCATTACT' 38 seq2 = 'GATTACT' 39 print("\nIn:") 40 print(seq1) 41 print(seq2) 42 43 # Perform the alignment. 44 score, align1, align2, gaps = needleman_wunsch_align(seq1, seq2, sub_matrix=SIMILARITY_DNA, sub_seq=SIMILARITY_DNA_SEQ, gap_open_penalty=1, gap_extend_penalty=1) 45 print("\nOut:") 46 print(score) 47 print(align1) 48 print(align2) 49 print(gaps) 50 print("\n") 51 52 # Check the alignment. 53 self.assertEqual(align1, 'GCATTACT') 54 self.assertEqual(align2, 'G-ATTACT') 55 56 # The gap matrix. 57 real_gaps = [ 58 [0, 0, 0, 0, 0, 0, 0, 0], 59 [0, 1, 0, 0, 0, 0, 0, 0] 60 ] 61 for i in range(2): 62 for j in range(8): 63 self.assertEqual(gaps[i, j], real_gaps[i][j])
64 65
67 """Test the Needleman-Wunsch sequence alignment for two DNA sequences using the NUC 4.4 matrix. 68 69 From online servers, the results with a gap open penalty of 5 and gap extend of 1 should be:: 70 71 https://www.ebi.ac.uk/Tools/psa/emboss_needle/ 72 EMBOSS_001 1 GAAAAAAT 8 73 | ||| 74 EMBOSS_001 1 G----AAT 4 75 """ 76 77 # The sequences. 78 seq1 = 'GAAAAAAT' 79 seq2 = 'GAAT' 80 print("\nIn:") 81 print(seq1) 82 print(seq2) 83 84 # Perform the alignment. 85 score, align1, align2, gaps = needleman_wunsch_align(seq1, seq2, sub_matrix=NUC_4_4, sub_seq=NUC_4_4_SEQ, gap_open_penalty=5, gap_extend_penalty=1) 86 print("\nOut:") 87 print(score) 88 print(align1) 89 print(align2) 90 print(gaps) 91 print("\n") 92 93 # Check the alignment. 94 self.assertEqual(align1, 'GAAAAAAT') 95 self.assertEqual(align2, 'G----AAT') 96 97 # The gap matrix. 98 real_gaps = [ 99 [0, 0, 0, 0, 0, 0, 0, 0], 100 [0, 1, 1, 1, 1, 0, 0, 0] 101 ] 102 for i in range(2): 103 for j in range(8): 104 self.assertEqual(gaps[i, j], real_gaps[i][j])
105 106
108 """Test the Needleman-Wunsch sequence alignment for two DNA sequences using the NUC 4.4 matrix. 109 110 From online servers, the results with a gap open penalty of 5 and gap extend of 1 should be:: 111 112 https://www.ebi.ac.uk/Tools/psa/emboss_needle/ 113 EMBOSS_001 1 GACAGAAT- 8 114 |||| 115 EMBOSS_001 1 ----GAATA 5 116 """ 117 118 # The sequences. 119 seq1 = 'GACAGAAT' 120 seq2 = 'GAATA' 121 print("\nIn:") 122 print(seq1) 123 print(seq2) 124 125 # Perform the alignment. 126 score, align1, align2, gaps = needleman_wunsch_align(seq1, seq2, sub_matrix=NUC_4_4, sub_seq=NUC_4_4_SEQ, gap_open_penalty=5, gap_extend_penalty=1) 127 print("\nOut:") 128 print(score) 129 print(align1) 130 print(align2) 131 print(gaps) 132 print("\n") 133 134 # Check the alignment. 135 self.assertEqual(align1, 'GACAGAAT-') 136 self.assertEqual(align2, '----GAATA') 137 138 # The gap matrix. 139 real_gaps = [ 140 [0, 0, 0, 0, 0, 0, 0, 0, 1], 141 [1, 1, 1, 1, 0, 0, 0, 0, 0] 142 ] 143 for i in range(2): 144 for j in range(8): 145 self.assertEqual(gaps[i, j], real_gaps[i][j])
146