1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 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   
 32  from data_store import Relax_data_store; ds = Relax_data_store() 
 33  from pipe_control import pipes 
 34  from status import Status; status = Status() 
 35  from test_suite.unit_tests.base_classes import UnitTestCase 
 36   
 37   
 39      """Base class for the tests of both the 'prompt.sequence' and 'pipe_control.sequence' modules. 
 40   
 41      This base class also contains many shared unit tests. 
 42      """ 
 43   
 45          """Set up for all the molecule unit tests.""" 
 46   
 47           
 48          ds.add(pipe_name='orig', pipe_type='mf') 
 49   
 50           
 51          ds.tmpfile = mktemp() 
 52   
 53           
 54          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] 
 55          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'] 
  56   
 57   
 59          """Test the copying of an amino acid sequence. 
 60   
 61          The functions tested are pipe_control.sequence.copy() and prompt.sequence.copy(). 
 62          """ 
 63   
 64           
 65          dp_orig = pipes.get_pipe('orig') 
 66   
 67           
 68          dp_orig.mol[0].res[0].num = 1 
 69          dp_orig.mol[0].res[0].name = 'GLY' 
 70          dp_orig.mol[0].res.add_item('PRO', 2) 
 71          dp_orig.mol[0].res.add_item('LEU', 3) 
 72          dp_orig.mol[0].res.add_item('GLY', 4) 
 73          dp_orig.mol[0].res.add_item('SER', 5) 
 74   
 75           
 76          dp_orig.mol[0].res[2].spin[0].test = True 
 77   
 78           
 79          ds.add(pipe_name='new', pipe_type='mf') 
 80          dp_new = pipes.get_pipe('new') 
 81   
 82           
 83          self.sequence_fns.copy('orig') 
 84   
 85           
 86          self.assertEqual(dp_new.mol[0].res[0].num, 1) 
 87          self.assertEqual(dp_new.mol[0].res[0].name, 'GLY') 
 88          self.assertEqual(dp_new.mol[0].res[1].num, 2) 
 89          self.assertEqual(dp_new.mol[0].res[1].name, 'PRO') 
 90          self.assertEqual(dp_new.mol[0].res[2].num, 3) 
 91          self.assertEqual(dp_new.mol[0].res[2].name, 'LEU') 
 92          self.assertEqual(dp_new.mol[0].res[3].num, 4) 
 93          self.assertEqual(dp_new.mol[0].res[3].name, 'GLY') 
 94          self.assertEqual(dp_new.mol[0].res[4].num, 5) 
 95          self.assertEqual(dp_new.mol[0].res[4].name, 'SER') 
 96   
 97           
 98          self.assert_(not hasattr(dp_new.mol[0].res[2].spin[0], 'test')) 
  99   
100   
102          """Test the display of an amino acid sequence. 
103   
104          The functions tested are pipe_control.sequence.display() and prompt.sequence.display(). 
105          """ 
106   
107           
108          dp_orig = pipes.get_pipe('orig') 
109   
110           
111          dp_orig.mol[0].res[0].num = 1 
112          dp_orig.mol[0].res[0].name = 'GLY' 
113          dp_orig.mol[0].res.add_item('PRO', 2) 
114          dp_orig.mol[0].res.add_item('LEU', 3) 
115          dp_orig.mol[0].res.add_item('GLY', 4) 
116          dp_orig.mol[0].res.add_item('SER', 5) 
117   
118           
119          self.sequence_fns.display(res_num_flag=True, res_name_flag=True) 
 120   
121   
123          """Test the reading of the amino acid sequence out of a protein NOE data file. 
124   
125          The functions tested are pipe_control.sequence.read() and prompt.sequence.read(). 
126          """ 
127   
128           
129          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) 
130   
131           
132          dp = pipes.get_pipe('orig') 
133   
134           
135          for i in range(len(self.Ap4Aase_res_num)): 
136              self.assertEqual(dp.mol[0].res[i].num, self.Ap4Aase_res_num[i]) 
137              self.assertEqual(dp.mol[0].res[i].name, self.Ap4Aase_res_name[i]) 
 138   
139   
141          """Test the writing of an amino acid sequence. 
142   
143          The functions tested are pipe_control.sequence.write() and prompt.sequence.write(). 
144          """ 
145   
146           
147          dp_orig = pipes.get_pipe('orig') 
148   
149           
150          dp_orig.mol[0].res[0].num = 1 
151          dp_orig.mol[0].res[0].name = 'GLY' 
152          dp_orig.mol[0].res.add_item('PRO', 2) 
153          dp_orig.mol[0].res.add_item('LEU', 3) 
154          dp_orig.mol[0].res.add_item('GLY', 4) 
155          dp_orig.mol[0].res.add_item('SER', 5) 
156   
157           
158          self.sequence_fns.write(file=ds.tmpfile, res_num_flag=True, res_name_flag=True) 
159   
160           
161          file = open(ds.tmpfile) 
162   
163           
164          file_md5 = md5() 
165          text = file.read() 
166          if hasattr(text, 'encode'):     
167              text = text.encode() 
168          file_md5.update(text) 
169   
170           
171          digest = file_md5.digest() 
172          if sys.version_info[0] == 3: 
173              self.assertEqual(digest, eval("b'\\xc7\\xa0\\xd0i\\xa54|f\\xcc1\\xd6|\\xe7\\x82#:'")) 
174          else: 
175              self.assertEqual(digest, '\xc7\xa0\xd0i\xa54|f\xcc1\xd6|\xe7\x82#:') 
176   
177           
178          file.close() 
  179