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