예제 #1
0
 def test_add_write(self):
     """A modified base should be written to PDB."""
     s = ModernaStructure('file', A_RESIDUE)
     add_modification(s['1'], 'm1A')
     s.write_pdb_file(OUTPUT)
     t = ModernaStructure('file', OUTPUT)
     self.assertEqual(t['1'].long_abbrev, s['1'].long_abbrev)
예제 #2
0
 def add_one_modification_copy(self, residue, modification_long_abbrev,
                               number_in_model):
     """
     """
     temp_res = RNAResidue(residue)
     num = number_in_model or temp_res.identifier
     add_modification(temp_res, modification_long_abbrev)
     self.add_residue(temp_res, num, False)
     log.write_message('Residue %s: modification added (%s ---> %s).' %
                       (num, residue.long_abbrev, modification_long_abbrev))
예제 #3
0
 def test_mods_sanity(self):
     """Adding and removing many times should work as well."""
     #for mod in ['m1A','m66A','Am','t6A']:
     for mod in ['m1A', 'm6Am', 'Am', 't6A']:
         # there is no modification named m66A. There is m6Am
         self.assertEqual(BaseRecognizer().identify_resi(self.adenosine),
                          'A')
         add_modification(self.adenosine, mod)
         self.assertEqual(BaseRecognizer().identify_resi(self.adenosine),
                          mod)
         remove_modification(self.adenosine)
예제 #4
0
 def test_add_to_wrong_base(self):
     """Add modification to A that belongs to G should not work."""
     add_modification(self.adenosine, 'm1G')
     self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'm1G')
     atoms_m1G = [
         "C1'", 'C2', "C2'", "C3'", 'C4', "C4'", 'C5', "C5'", 'C6', 'C8',
         'CM1', 'N1', 'N2', 'N3', 'N7', 'N9', "O2'", "O3'", "O4'", "O5'",
         'O6', 'OP1', 'OP2', 'P'
     ]
     atoms = [at.name.strip() for at in self.adenosine.child_list]
     atoms.sort()
     self.assertEqual(atoms_m1G, atoms)
예제 #5
0
 def test_dna_exchange(self):
     """All combinations of DNA->DNA exchanges should work."""
     bases = ['dT', 'dA', 'dG', 'dC']
     br = BaseRecognizer()
     r = self.adenosine
     for b1 in bases:
         add_modification(r, b1)
         self.assertEqual(br.identify_resi(r), b1)
         for b2 in bases:
             remove_modification(r)
             add_modification(r, b2)
             self.assertEqual(br.identify_resi(r), b2)
예제 #6
0
 def add_all_modifications_copy(self):
     """
     """
     if self.alignment and self.template:
         for ap in self.recipe.add_modifications:
             temp_resi = RNAResidue(self.template.template_residues[str(
                 ap.template_position)])
             old_name = temp_resi.long_abbrev
             add_modification(temp_resi, ap.target_letter.long_abbrev)
             self.add_residue(temp_resi)
             log.write_message(
                 'Residue %s: modification added (%s ---> %s).' %
                 (temp_resi.identifier, old_name, temp_resi.long_abbrev))
     else:
         raise RnaModelError('There is no template or/and alignmnt')
예제 #7
0
def add_modification(residue, modification_name, model=None, residue_number=None):
    """*add_modification(residue, modification_name, model=None, residue_number=None)*

Adds a modification to a single residue. An RNAModel can be given optionally. If this is given, the modified residue is subsequently copied to it.

Note that deoxynucleotides count as modified bases as well.

:Arguments:
    * residue from a Template or RNAModel object
    * modification name (abbreviated as e.g. 'm6Am', 'm1G', 'm3U', 'mnm5s2U')
    * model (optional; if this is given, the residue is copied)
    * residue position in model (optional; by default the residue number is kept)
    """
    residue = validate_resi(residue)
    modification_name = validate_alphabet(modification_name)
    if model: model = validate_model(model)
    if residue_number: validate_resnum(residue_number)
    
    if model != None:
        model.add_one_modification_copy(residue, modification_name, residue_number)
    else:
        modifications.add_modification(residue, modification_name)
예제 #8
0
 def test_res_names_add_modif(self):
     """Names should be consistent after adding modifications."""
     add_modification(self.s['5'], 'm7G')
     self.s.write_pdb_file(TEST_OUTPUT)
     rn = self.get_resnames(TEST_OUTPUT)
     self.assertEqual(rn[4], '7MG')
예제 #9
0
    def test_all(self):
        """Adding should work for all modifications."""
        a = Alphabet()
        br = BaseRecognizer()
        not_working = []
        errors = []
        EXCLUDED = [
            'A',
            'G',
            'C',
            'U',
            '?A',
            '?G',
            '?C',
            '?U',  # exclude unknown
            'X',
            '?X',
            'Xm',
            'x',
            'preQ0base',
            'Qbase',
            'preQ1base',
            'galQtRNA',  # indistinguishable from ManQtRNA
            '-',
            '_',
            'yW-58',
            'yW-72',
            'yW-86',
            'm8A',
            'fa7d7G',  # new in Modomics 2009, not yet in ModeRNA.
            'm7Gpp_cap',  # not implemented yet
        ]
        SYNONYMS = {
            'm42C': 'm44C',
            'm42Cm': 'm44Cm',
            'm62A': 'm66A',
            'm62Am': 'm66Am'
        }
        for k in a:
            if k not in EXCLUDED and a[k].category not in [
                    'unknown', 'standard', 'ligand', 'synthetic',
                    'stereoisomer', 'insertion', 'missing', ' '
            ]:
                struc = ModernaStructure('file', A_RESIDUE)
                r = struc['1']
                try:
                    add_modification(r, k)
                    right = SYNONYMS.get(k, k)
                    if br.identify_resi(r) != right:
                        not_working.append(k + ',' + br.identify_resi(r))
                        # write file for checking
                        struc.write_pdb_file('dummies/' + k + '.pdb')
                except ModernaResidueError:
                    raise
                    errors.append(k)

        if not_working or errors:
            print '\nTest failed for modifications.'
            print 'Different base was recognized:'
            print ', '.join(not_working)
            print 'ERROR occured:'
            print ', '.join(errors)

        self.assertEqual(len(not_working) + len(errors), 0)
예제 #10
0
 def test_add_to_unk(self):
     """Should be possible to add modification to unknown residue when ribose is present"""
     m = load_model(PDB_UNK)
     for resi in m:
         add_modification(resi, 'm1G')
         self.assertEqual(resi.long_abbrev, 'm1G')
예제 #11
0
 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')
예제 #12
0
 def test_add_to_a(self):
     """Add modification to A."""
     add_modification(self.adenosine, 'm1A')
     self.assertEqual(BaseRecognizer().identify_resi(self.adenosine), 'm1A')