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 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 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)