def exchange_some_bases(residue_list, new_names, model=None, new_numbers=None): """*exchange_some_bases(residue_list, new_names, model=None, new_numbers=None)* Exchanges standard RNA bases in a set of residues. This can be used to modify residues already in a model, or to exchange and copy them in one step, if a RNAModel is given. It is also possible to modify the template this way! The residue numbers are not changed by default, but a list of new one can be given. :Arguments: * Residues from a Template or RnaModel * List of names of the new bases ('A', 'G', 'C' or 'U') * RnaModel object (optional) * New residue number in the model """ residue_list = validate_resi_list(residue_list) new_names = validate_alphabet_list(new_names, len(residue_list)) if model: model = validate_model(model) if new_numbers: new_numbers = validate_resnum_list(new_numbers, len(residue_list)) if model: model.exchange_list_of_bases(residue_list, new_names, new_numbers) else: for resi, newname in zip(residue_list, new_names): modifications.exchange_base(resi, newname)
def test_same_dihedral(self): """The dihedral of the glycosidic bond before and after substitution should be the same.""" # error in dihedral angle is 1.0 degrees. # before (A) a1 = self.adenosine["C2'"].get_vector() a2 = self.adenosine["C1'"].get_vector() a3 = self.adenosine["N9"].get_vector() a4 = self.adenosine["C4"].get_vector() a_dihedral = calc_dihedral(a1, a2, a3, a4) # for G exchange_base(self.adenosine, 'G') g = self.adenosine g1 = g["C2'"].get_vector() g2 = g["C1'"].get_vector() g3 = g["N9"].get_vector() g4 = g["C4"].get_vector() g_dihedral = calc_dihedral(g1, g2, g3, g4) self.assertAlmostEqual(g_dihedral, a_dihedral, 2) # for U exchange_base(self.adenosine, 'U') u = self.adenosine u1 = u["C2'"].get_vector() u2 = u["C1'"].get_vector() u3 = u["N1"].get_vector() u4 = u["C2"].get_vector() u_dihedral = calc_dihedral(u1, u2, u3, u4) self.assertAlmostEqual(u_dihedral, a_dihedral, 2)
def exchange_single_base(residue, new_name, model=None, new_number=None): """*exchange_single_base(residue, new_name, model=None, new_number=None)* Exchanges standard RNA bases in a residue. This can be used to modify residues already in a model, or to exchange and copy them in one step, if an RnaModel is given. It is also possible to modify the template this way! The residue number does not change by default, but a new one can be given. :Arguments: * Residues from a Template or RnaModel * Abbreviation of the new base ('A', 'G', 'C' or 'U') * RnaModel object (optional) * New residue number in the model (optional) """ residue = validate_resi(residue) new_name = validate_alphabet(new_name) if model: model = validate_model(model) if new_number: new_number = validate_resnum(new_number) if model: model.copy_residue(residue, new_number) number = new_number or residue.identifier modifications.exchange_base(model[number], new_name) else: modifications.exchange_base(residue, new_name)
def exchange_all_bases(self): """ Exchanges all bases according to given alignment. """ if self.alignment and self.template: for ap in self.recipe.exchange: res = self.template.template_residues[str( ap.template_position)] name = ap.target_letter.original_base temp_resi = RNAResidue( res) #TODO: check whether defensive copy is neccessary exchange_base(temp_resi, name) self.add_residue(temp_resi, res.identifier) else: raise RnaModelError('There is no template or/and alignmnt')
def remove_all_modifications_copy(self): """ Removes all unnecessary modifications from model acordong given alignment. Copies all this residues without modification into model. """ if self.alignment and self.template: for ap in self.recipe.remove_modifications: res = self.template.template_residues[str( ap.template_position)] temp_resi = RNAResidue(res) remove_modification(temp_resi) if temp_resi != ap.target_letter: exchange_base(temp_resi, ap.target_letter.original_base) self.add_residue(temp_resi) log.write_message( 'Residue %s: modification removed (%s ---> %s).' % (temp_resi.identifier, res.long_abbrev, temp_resi.long_abbrev)) else: raise RnaModelError('There is no template or/and alignmnt')
def test_substitute(self): """Exchange must produce G,C, and U.""" exchange_base(self.adenosine, 'G') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'G') exchange_base(self.adenosine, 'C') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'C') exchange_base(self.adenosine, 'U') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'U')
def exchange_list_of_bases(self, residues, new_names, numbers_in_model=None): """ Exchanges bases in given residues list. Arguments: - list of residues - list with new names for residues - list with numbers that indicates new positions for residues in a model (by default old residues positions) """ if not numbers_in_model: numbers_in_model = [resi.identifier for resi in residues] if len(residues) != len(new_names) or len(new_names) != len( numbers_in_model): raise RnaModelError( 'Number of given residues is different than number of given positions.' ) for resi, num, name in zip(residues, numbers_in_model, new_names): self.copy_residue(resi, num) exchange_base(self[num], name)
def test_exchange_single_base_retain_template(self): """Exchanging standard base should not change the template""" self.m.copy_residue(self.t['1'], '1') exchange_base(self.m['1'], 'U') self.assertEqual(self.t.get_sequence(), self.seq_before) self.assertEqual(self.br.identify_resi(self.t['1']), 'G')
def test_res_names_exchanged(self): """Names should be consistent after base exchanges.""" exchange_base(self.s['5'], 'C') self.s.write_pdb_file(TEST_OUTPUT) rn = self.get_resnames(TEST_OUTPUT) self.assertEqual(rn[4], ' C')
def test_resubstitute(self): """Substituting A by U and U by A should give A again.""" exchange_base(self.adenosine, 'G') exchange_base(self.adenosine, 'A') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'A') # exchange_base(self.adenosine, 'C') exchange_base(self.adenosine, 'A') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'A') # exchange_base(self.adenosine, 'U') exchange_base(self.adenosine, 'A') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'A')
def test_add_to_u(self): """Add modification to U.""" exchange_base(self.adenosine, 'U') add_modification(self.adenosine, 'Y') self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'Y')