Package test_suite :: Package unit_tests :: Package _data_store :: Module test_seq_align
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._data_store.test_seq_align

  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 data_store.seq_align import Sequence_alignments 
 27   
 28   
29 -class Test_seq_align(TestCase):
30 """Unit tests for the data.seq_align relax module.""" 31 32
33 - def setUp(self):
34 """Set 'self.seq_align' to an empty instance of the Sequence_alignments class.""" 35 36 self.seq_align = Sequence_alignments()
37 38
39 - def generate_ids(self, object_ids, models, molecules):
40 """Generate the expected IDs.""" 41 42 # Generate the IDs. 43 ids = [] 44 for i in range(len(object_ids)): 45 ids.append("Object '%s'" % object_ids[i]) 46 if models[i] != None: 47 ids[-1] += "; Model %i" % models[i] 48 ids[-1] += "; Molecule '%s'" % molecules[i] 49 50 # Return the IDs. 51 return ids
52 53
54 - def return_align_data(self):
55 """Return a data set for alignment testing.""" 56 57 # The data. 58 object_ids = ['frame_order', 'ensemble', 'ensemble', 'ensemble', 'ensemble', 'ensemble', 'ensemble', 'ensemble'] 59 models = [None, 1, 1, 1, 1, 1, 1, 1] 60 molecules = [ 61 'N-dom', 62 'ensemble 4M A', 63 'ensemble 4M B', 64 'ensemble 4M C', 65 'ensemble 4M D', 66 'CaM-IQ A', 67 'CaM-IQ B', 68 'CaM-IQ C' 69 ] 70 sequences = [ 71 'LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARK*****', 72 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****', 73 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****', 74 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****', 75 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****', 76 ' QLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMT*****', 77 ' LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMT*****', 78 ' LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMT*****', 79 80 'TEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADG', 81 'ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKM', 82 'LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMAR' 83 ] 84 strings = [ 85 '---LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARK------------------------------------------------------------------------*****----------------------------------------------------------------------------', 86 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARK----------------------------------------------------------------------------MKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****', 87 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****----------------------------------------------------------------------------', 88 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****----------------------------------------------------------------------------', 89 '*DQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTA*****----------------------------------------------------------------------------', 90 '--QLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARK----MKSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMT*****----------------------------------------------------------------------------', 91 '---LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARK----MKDEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMT*****----------------------------------------------------------------------------', 92 '---LTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTIDFPEFLTMMARK-------EEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMT*****----------------------------------------------------------------------------', 93 ] 94 gaps = [] 95 for i in range(len(strings)): 96 gaps.append([]) 97 for j in range(len(strings[0])): 98 if strings[i][j] == '-': 99 gaps[i].append(1) 100 else: 101 gaps[i].append(0) 102 msa_algorithm = 'Central Star' 103 pairwise_algorithm = 'NW70' 104 matrix = 'BLOSUM62' 105 gap_open_penalty = 10.0 106 gap_extend_penalty = 1.0 107 end_gap_open_penalty = 0.0 108 end_gap_extend_penalty = 0.0 109 110 # Return the data. 111 return object_ids, models, molecules, sequences, strings, gaps, msa_algorithm, pairwise_algorithm, matrix, gap_open_penalty, gap_extend_penalty, end_gap_open_penalty, end_gap_extend_penalty
112 113
114 - def test_alignment_addition(self):
115 """Test the creation of a new sequence alignment object.""" 116 117 # The data. 118 object_ids, models, molecules, sequences, strings, gaps, msa_algorithm, pairwise_algorithm, matrix, gap_open_penalty, gap_extend_penalty, end_gap_open_penalty, end_gap_extend_penalty = self.return_align_data() 119 120 # Add the alignment. 121 self.seq_align.add(object_ids=object_ids, models=models, molecules=molecules, sequences=sequences, strings=strings, gaps=gaps, msa_algorithm=msa_algorithm, pairwise_algorithm=pairwise_algorithm, matrix=matrix, gap_open_penalty=gap_open_penalty, gap_extend_penalty=gap_extend_penalty, end_gap_open_penalty=end_gap_open_penalty, end_gap_extend_penalty=end_gap_extend_penalty) 122 123 # Generate the expected IDs. 124 ids = self.generate_ids(object_ids, models, molecules) 125 126 # Check the data. 127 for i in range(8): 128 print("Checking \"%s\"" % ids[i]) 129 self.assertEqual(self.seq_align[0].ids[i], ids[i]) 130 self.assertEqual(self.seq_align[0].object_ids[i], object_ids[i]) 131 self.assertEqual(self.seq_align[0].models[i], models[i]) 132 self.assertEqual(self.seq_align[0].molecules[i], molecules[i]) 133 self.assertEqual(self.seq_align[0].sequences[i], sequences[i]) 134 self.assertEqual(self.seq_align[0].strings[i], strings[i]) 135 self.assertEqual(self.seq_align[0].gaps[i], gaps[i]) 136 self.assertEqual(self.seq_align[0].msa_algorithm, msa_algorithm) 137 self.assertEqual(self.seq_align[0].pairwise_algorithm, pairwise_algorithm) 138 self.assertEqual(self.seq_align[0].matrix, matrix) 139 self.assertEqual(self.seq_align[0].gap_open_penalty, gap_open_penalty) 140 self.assertEqual(self.seq_align[0].gap_extend_penalty, gap_extend_penalty) 141 self.assertEqual(self.seq_align[0].end_gap_open_penalty, end_gap_open_penalty) 142 self.assertEqual(self.seq_align[0].end_gap_extend_penalty, end_gap_extend_penalty)
143 144
145 - def test_find_alignment(self):
146 """Test the retrieval of pre-existing alignment.""" 147 148 # Execute the body of the test_alignment_addition() unit test to set up the object. 149 self.test_alignment_addition() 150 151 # The identifying data. 152 object_ids, models, molecules, sequences, strings, gaps, msa_algorithm, pairwise_algorithm, matrix, gap_open_penalty, gap_extend_penalty, end_gap_open_penalty, end_gap_extend_penalty = self.return_align_data() 153 154 # Retrieve the alignment. 155 align = self.seq_align.find_alignment(object_ids=object_ids, models=models, molecules=molecules, sequences=sequences, msa_algorithm=msa_algorithm, pairwise_algorithm=pairwise_algorithm, matrix=matrix, gap_open_penalty=gap_open_penalty, gap_extend_penalty=gap_extend_penalty, end_gap_open_penalty=end_gap_open_penalty, end_gap_extend_penalty=end_gap_extend_penalty) 156 157 # Check that something was returned. 158 self.assertNotEqual(align, None) 159 160 # Generate the expected IDs. 161 ids = self.generate_ids(object_ids, models, molecules) 162 163 # Check some of the data. 164 for i in range(8): 165 print("Checking \"%s\"" % ids[i]) 166 self.assertEqual(self.seq_align[0].object_ids[i], object_ids[i]) 167 self.assertEqual(self.seq_align[0].models[i], models[i]) 168 self.assertEqual(self.seq_align[0].molecules[i], molecules[i])
169 170
172 """Test the retrieval of non-existent alignment.""" 173 174 # Execute the body of the test_alignment_addition() unit test to set up the object. 175 self.test_alignment_addition() 176 177 # The identifying data. 178 object_ids, models, molecules, sequences, strings, gaps, msa_algorithm, pairwise_algorithm, matrix, gap_open_penalty, gap_extend_penalty, end_gap_open_penalty, end_gap_extend_penalty = self.return_align_data() 179 180 # Change a gap penalty. 181 gap_open_penalty = 0.5 182 183 # Retrieve the alignment. 184 align = self.seq_align.find_alignment(object_ids=object_ids, models=models, molecules=molecules, sequences=sequences, msa_algorithm=msa_algorithm, pairwise_algorithm=pairwise_algorithm, matrix=matrix, gap_open_penalty=gap_open_penalty, gap_extend_penalty=gap_extend_penalty, end_gap_open_penalty=end_gap_open_penalty, end_gap_extend_penalty=end_gap_extend_penalty) 185 186 # Check that nothing was returned. 187 self.assertEqual(align, None)
188