def test_number_generator(self): """Increase a number stepwise""" r = Renumerator(['A']*7, ['5', '6', None, None, None, '7', '8']) gen = r.number_generator('42') self.assertEqual(gen.next(), '43') self.assertEqual(gen.next(), '44') self.assertEqual(gen.next(), '45')
def test_letter_generator(self): """Append to a number A, B, C, ...""" r = Renumerator(['A']*7, ['5', '6', None, None, None, '7', '8']) gen = r.letter_generator('42') self.assertEqual(gen.next(), '42A') self.assertEqual(gen.next(), '42B') self.assertEqual(gen.next(), '42C')
def test_twin_segments(self): r = Renumerator(['A'] * 13, [ '1', '2', None, None, None, '3', '4', '5', None, None, None, '6', '7' ]) result = r.get_identifiers_list() self.assertEqual(result, [ '1', '2', '2A', '2B', '2C', '3', '4', '5', '5A', '5B', '5C', '6', '7' ])
def test_prepare_identifiers(self): """Should generate a list of identifiers.""" r = Renumerator([], []) # letters result = r.prepare_identifiers(['10'], [None]*5, ['20']) self.assertEqual(result, ['10A', '10B', '10C', '10D', '10E']) # numbers result = r.prepare_identifiers(['10'], [None]*50, ['100']) self.assertEqual(result[:5], ['11', '12', '13', '14', '15']) # Exception when there is not enough room self.assertRaises(RenumeratorError, r.prepare_identifiers, ['10'], [None]*50, ['20'])
def test_divide_identifiers(self): """Splits a list of identifiers.""" r = Renumerator(['A']*5, [None, None, None, '2', '3']) self.assertEqual(str(r.divide_identifiers()), "[[None, None, None], ['2', '3']]") r = Renumerator(['A']*7, ['5', '6', None, None, None, '7', '8']) self.assertEqual(str(r.divide_identifiers()), "[['5', '6'], [None, None, None], ['7', '8']]") r = Renumerator(['A']*13, ['1', '2', None, None, None, '3', '4', '5', None, None, None, '6', '7']) self.assertEqual(str(r.divide_identifiers()),"[['1', '2'], [None, None, None], ['3', '4', '5'], [None, None, None], ['6', '7']]")
def renumber(self, struc=None): """ changes anchor and all numeration of all residues, takes care about numbers that should be kept from model. """ new_resi = self._get_resis_to_renumber() new_ids = self._get_numbers_to_renumber(struc) new_ids = self._keep_func(self, new_ids, struc) # remove all residues for resi in list(self.struc): self.struc.remove_residue(resi.identifier) # renumerate renumerator = Renumerator(new_resi, new_ids) new_ids = renumerator.get_identifiers_list() for new_id, resi in zip(new_ids, new_resi): self.struc.add_residue(resi, number=new_id)
def test_numbers_from_scratch(self): r = Renumerator(['A']*3, [None, None, None]) result = r.get_identifiers_list() self.assertEqual(result, ['1A', '1B', '1C'])
def test_53_insert(self): r = Renumerator(['A']*7, ['5', '6', None, None, None, '7', '8']) result = r.get_identifiers_list() self.assertEqual(result, ['5', '6', '6A', '6B', '6C', '7', '8'])
def test_3_prime(self): r = Renumerator(['A']*5, ['5', '6', None, None, None]) result = r.get_identifiers_list() self.assertEqual(result, ['5', '6', '6A', '6B', '6C'])
def test_5_prime_long(self): r = Renumerator(['A']*52, [None]*50+['2', '3']) self.assertRaises(RenumeratorError, r.get_identifiers_list) r = Renumerator(['A']*52, [None]*50+['200', '201']) result = r.get_identifiers_list() self.assertEqual(result[0], '150')
def test_5_prime(self): r = Renumerator(['A']*5, [None, None, None, '2', '3']) result = r.get_identifiers_list() self.assertEqual(result, ['1A', '1B', '1C', '2', '3'])