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

Source Code for Module test_suite.unit_tests.sequence_testing_base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2012 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 os import sep 
 24  import sys 
 25  from tempfile import mktemp 
 26  try: 
 27      from hashlib import md5 
 28  except ImportError: 
 29      from md5 import new as md5 
 30   
 31  # relax module imports. 
 32  from data import Relax_data_store; ds = Relax_data_store() 
 33  from generic_fns import pipes 
 34  from relax_io import delete 
 35  from status import Status; status = Status() 
 36  from test_suite.unit_tests.base_classes import UnitTestCase 
 37   
 38   
39 -class Sequence_base_class(UnitTestCase):
40 """Base class for the tests of both the 'prompt.sequence' and 'generic_fns.sequence' modules. 41 42 This base class also contains many shared unit tests. 43 """ 44
45 - def setUp(self):
46 """Set up for all the molecule unit tests.""" 47 48 # Add a data pipe to the data store. 49 ds.add(pipe_name='orig', pipe_type='mf') 50 51 # Get a temporary file name. 52 ds.tmpfile = mktemp() 53 54 # Ap4Aase residue sequence data. 55 self.Ap4Aase_res_num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165] 56 self.Ap4Aase_res_name = ['GLY', 'PRO', 'LEU', 'GLY', 'SER', 'MET', 'ASP', 'SER', 'PRO', 'PRO', 'GLU', 'GLY', 'TYR', 'ARG', 'ARG', 'ASN', 'VAL', 'GLY', 'ILE', 'CYS', 'LEU', 'MET', 'ASN', 'ASN', 'ASP', 'LYS', 'LYS', 'ILE', 'PHE', 'ALA', 'ALA', 'SER', 'ARG', 'LEU', 'ASP', 'ILE', 'PRO', 'ASP', 'ALA', 'TRP', 'GLN', 'MET', 'PRO', 'GLN', 'GLY', 'GLY', 'ILE', 'ASP', 'GLU', 'GLY', 'GLU', 'ASP', 'PRO', 'ARG', 'ASN', 'ALA', 'ALA', 'ILE', 'ARG', 'GLU', 'LEU', 'ARG', 'GLU', 'GLU', 'THR', 'GLY', 'VAL', 'THR', 'SER', 'ALA', 'GLU', 'VAL', 'ILE', 'ALA', 'GLU', 'VAL', 'PRO', 'TYR', 'TRP', 'LEU', 'THR', 'TYR', 'ASP', 'PHE', 'PRO', 'PRO', 'LYS', 'VAL', 'ARG', 'GLU', 'LYS', 'LEU', 'ASN', 'ILE', 'GLN', 'TRP', 'GLY', 'SER', 'ASP', 'TRP', 'LYS', 'GLY', 'GLN', 'ALA', 'GLN', 'LYS', 'TRP', 'PHE', 'LEU', 'PHE', 'LYS', 'PHE', 'THR', 'GLY', 'GLN', 'ASP', 'GLN', 'GLU', 'ILE', 'ASN', 'LEU', 'LEU', 'GLY', 'ASP', 'GLY', 'SER', 'GLU', 'LYS', 'PRO', 'GLU', 'PHE', 'GLY', 'GLU', 'TRP', 'SER', 'TRP', 'VAL', 'THR', 'PRO', 'GLU', 'GLN', 'LEU', 'ILE', 'ASP', 'LEU', 'THR', 'VAL', 'GLU', 'PHE', 'LYS', 'LYS', 'PRO', 'VAL', 'TYR', 'LYS', 'GLU', 'VAL', 'LEU', 'SER', 'VAL', 'PHE', 'ALA', 'PRO', 'HIS', 'LEU']
57 58
60 """Test the copying of an amino acid sequence. 61 62 The functions tested are generic_fns.sequence.copy() and prompt.sequence.copy(). 63 """ 64 65 # Get the data pipe. 66 dp_orig = pipes.get_pipe('orig') 67 68 # Create a simple animo acid sequence. 69 dp_orig.mol[0].res[0].num = 1 70 dp_orig.mol[0].res[0].name = 'GLY' 71 dp_orig.mol[0].res.add_item('PRO', 2) 72 dp_orig.mol[0].res.add_item('LEU', 3) 73 dp_orig.mol[0].res.add_item('GLY', 4) 74 dp_orig.mol[0].res.add_item('SER', 5) 75 76 # Add an object which should not be copied. 77 dp_orig.mol[0].res[2].spin[0].test = True 78 79 # Add a new data pipe to the data store. 80 ds.add(pipe_name='new', pipe_type='mf') 81 dp_new = pipes.get_pipe('new') 82 83 # Copy the residue sequence. 84 self.sequence_fns.copy('orig') 85 86 # Test the sequence. 87 self.assertEqual(dp_new.mol[0].res[0].num, 1) 88 self.assertEqual(dp_new.mol[0].res[0].name, 'GLY') 89 self.assertEqual(dp_new.mol[0].res[1].num, 2) 90 self.assertEqual(dp_new.mol[0].res[1].name, 'PRO') 91 self.assertEqual(dp_new.mol[0].res[2].num, 3) 92 self.assertEqual(dp_new.mol[0].res[2].name, 'LEU') 93 self.assertEqual(dp_new.mol[0].res[3].num, 4) 94 self.assertEqual(dp_new.mol[0].res[3].name, 'GLY') 95 self.assertEqual(dp_new.mol[0].res[4].num, 5) 96 self.assertEqual(dp_new.mol[0].res[4].name, 'SER') 97 98 # Test that the extra object was not copied. 99 self.assert_(not hasattr(dp_new.mol[0].res[2].spin[0], 'test'))
100 101
103 """Test the display of an amino acid sequence. 104 105 The functions tested are generic_fns.sequence.display() and prompt.sequence.display(). 106 """ 107 108 # Get the data pipe. 109 dp_orig = pipes.get_pipe('orig') 110 111 # Create a simple animo acid sequence. 112 dp_orig.mol[0].res[0].num = 1 113 dp_orig.mol[0].res[0].name = 'GLY' 114 dp_orig.mol[0].res.add_item('PRO', 2) 115 dp_orig.mol[0].res.add_item('LEU', 3) 116 dp_orig.mol[0].res.add_item('GLY', 4) 117 dp_orig.mol[0].res.add_item('SER', 5) 118 119 # Try displaying the residue sequence. 120 self.sequence_fns.display(res_num_flag=True, res_name_flag=True)
121 122
124 """Test the reading of the amino acid sequence out of a protein NOE data file. 125 126 The functions tested are generic_fns.sequence.read() and prompt.sequence.read(). 127 """ 128 129 # Read the residue sequence out of the Ap4Aase 600 MHz NOE data file. 130 self.sequence_fns.read(file='Ap4Aase.Noe.600.bz2', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'relaxation_data', res_num_col=1, res_name_col=2) 131 132 # Get the data pipe. 133 dp = pipes.get_pipe('orig') 134 135 # Test the entire sequence. 136 for i in range(len(self.Ap4Aase_res_num)): 137 self.assertEqual(dp.mol[0].res[i].num, self.Ap4Aase_res_num[i]) 138 self.assertEqual(dp.mol[0].res[i].name, self.Ap4Aase_res_name[i])
139 140
142 """Test the writing of an amino acid sequence. 143 144 The functions tested are generic_fns.sequence.write() and prompt.sequence.write(). 145 """ 146 147 # Get the data pipe. 148 dp_orig = pipes.get_pipe('orig') 149 150 # Create a simple animo acid sequence. 151 dp_orig.mol[0].res[0].num = 1 152 dp_orig.mol[0].res[0].name = 'GLY' 153 dp_orig.mol[0].res.add_item('PRO', 2) 154 dp_orig.mol[0].res.add_item('LEU', 3) 155 dp_orig.mol[0].res.add_item('GLY', 4) 156 dp_orig.mol[0].res.add_item('SER', 5) 157 158 # Write the residue sequence. 159 self.sequence_fns.write(file=ds.tmpfile, res_num_flag=True, res_name_flag=True) 160 161 # Open the temp file. 162 file = open(ds.tmpfile) 163 164 # Get the md5sum of the file. 165 file_md5 = md5() 166 text = file.read() 167 if hasattr(text, 'encode'): # Python 3 encoding fix. 168 text = text.encode() 169 file_md5.update(text) 170 171 # Test the md5sum. 172 digest = file_md5.digest() 173 if sys.version_info[0] == 3: 174 self.assertEqual(digest, eval("b'\\xc7\\xa0\\xd0i\\xa54|f\\xcc1\\xd6|\\xe7\\x82#:'")) 175 else: 176 self.assertEqual(digest, '\xc7\xa0\xd0i\xa54|f\xcc1\xd6|\xe7\x82#:') 177 178 # Close the file. 179 file.close()
180