Beispiel #1
0
 def setUp(self):
     """
     fragment attached at 5' end of model.
     """
     self.m = RnaModel(data_type='file',data=MINI_TEMPLATE, seq=Sequence("GCGGAUUUALCUCAG"))
     self.s1 = ModernaStructure('file', SMALL_FRAGMENT, seq=Sequence("GCGG"))
     self.s2 = ModernaStructure('file',SMALL_FRAGMENT, seq=Sequence("GCGG"))
 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)
Beispiel #3
0
 def __init__(self, template_data, template_data_type='file', \
              template_chain_name='A', seq=None):
     #TODO: same order of arguments as in ModernaStructure
     ModernaStructure.__init__(self, data_type= template_data_type, \
                         data=template_data, chain_name=template_chain_name, seq=seq)
     self.template_residues = {}
     self.set_template_numeration()
 def setUp(self):
     """Initializes class instances used for testing."""
     self.rna = ModernaStructure('file', RNA_TWO_PIECES)
     self.example1 = ModernaStructure('file', AC_BASEPAIR, '0')
     self.example1_dist = ModernaStructure('file', DISTANT_AC_BASEPAIR, '0')
     self.ehz = ModernaStructure('file', RNA_1EHZ, 'A')
     self.hb = HBondCalculator()
Beispiel #5
0
 def test_missing_phosphates2(self):
     """Messy residues with missing phosphates are not delted."""
     st2 = ModernaStructure('file',  MISSING_PHOSPHATES2)
     pc = PdbController(st2)
     self.assertEqual(st2.get_sequence(), Sequence('C_C_G_A_C_C_U_U_C_G_G_C_C_A_C_C_U_G'))
     pc.clean_structure()
     self.assertEqual(st2.get_sequence(), Sequence('CCGACCUUCGGCCACC_UG'))
Beispiel #6
0
 def test_ligand_removal(self):
     """Should remove RNA ligand from 3FU2 when there is no ribose and phosphate group."""
     st2 = ModernaStructure('file',  PDB_WITH_LIGAND)
     pc2 = PdbController(st2)
     self.assertEqual(st2.get_sequence(), Sequence('AGAGGUUCUAG_._CACCCUCUAUAAAAAACUAA_x_._._._._._._._._._._._._.'))
     pc2.clean_structure()
     self.assertEqual(st2.get_sequence(), Sequence('AGAGGUUCUAG_CACCCUCUAUAAAAAACUAA'))
Beispiel #7
0
 def test_fill_doublegap(self):
     """Should insert fragments into correct sites."""
     # prepare model
     t = Template(DOUBLEGAP, 'file', 'A')
     m = RnaModel()
     for r in t:
         m.copy_residue(r)
     # insert first fragment
     struc = ModernaStructure('file', FRAGMENT1)
     f1 = ModernaFragment53(struc, anchor5=m['20'], anchor3=m['24'], \
         new_sequence=Sequence('AUA'), keep=keep_first_last)
     m.insert_fragment(f1)
     resids = [r.identifier for r in m]
     expected_resids1 = [
         '18', '19', '20', '21', '21A', '23', '24', '27', '28', '29', '30',
         '31', '32', '33', '34', '35'
     ]
     self.assertEqual(resids, expected_resids1)
     # insert second fragment
     struc = ModernaStructure('file', FRAGMENT2)
     f2 = ModernaFragment53(struc, anchor5=m['23'], anchor3=m['28'], \
         new_sequence=Sequence('AUUA'), keep=keep_first_last)
     m.insert_fragment(f2)
     resids = [r.identifier for r in m]
     expected_resids2 = [
         '18', '19', '20', '21', '21A', '23', '24', '24A', '24B', '27',
         '28', '29', '30', '31', '32', '33', '34', '35'
     ]
     self.assertEqual(resids, expected_resids2)
 def test_helix(self):
     struc = ModernaStructure('file', BROKEN_HELIX_EXAMPLE)
     resi1 = struc['0Z']
     resi2 = struc['1']
     bb = BackboneBuilder(resi1, resi2, struc)
     struc.write_pdb_file('out.pdb')
     self.assertTrue(bb.is_intact())
 def test_fccd(self):
     struc = ModernaStructure('file',FCCD_EXAMPLE)
     resi1 = struc['5']
     resi2 = struc['6']
     struc.remove_residue('5A')
     bb = BackboneBuilder(resi1, resi2, struc)
     self.assertTrue(bb.is_intact())
    def test_clash_recognition_moderna_structure(self):
        """Should find clashes in ModernaStructure object"""
        s = ModernaStructure('file', CLASH)
        self.assertEqual(str(self.cr.find_clashes_in_residues(s)), \
        "[(<Residue 3 G>, <Residue 4 G>)]")

        s = ModernaStructure('file', NOCLASH)
        self.assertFalse(self.cr.find_clashes_in_residues(s))
 def test_renumber_residue_letter(self):
     s = ModernaStructure('file', MINI_TEMPLATE)
     self.assertTrue(s['3'])
     self.assertRaises(RNAChainError, s.__getitem__, '3A')
     s.renumber_residue('3', '3A')
     self.assertTrue(s['3A'])
     self.assertRaises(RNAChainError, s.__getitem__, '3')
     self.assertEqual(s['3A'].identifier, '3A')
 def setUp(self):
     t = ModernaStructure('file', MINI_TEMPLATE)
     self.ga = GeometryAnalyzer(t)
     t = ModernaStructure('file',
                          BAD_TEMPLATE,
                          chain_name='A',
                          seq=t.get_sequence())
     self.bad_ga = GeometryAnalyzer(t)
 def test_get_base_pairs(self):
     """Calculates one canonical and two noncanonicals correctly."""
     m = ModernaStructure('file', RNA_HAIRPIN, 'D')
     result = m.get_base_pairs()
     result = map(str, result['31'])
     self.assertTrue('31 +/+ 39' in result)
     self.assertTrue('31 HS 32' in result)
     self.assertTrue('31 SS 30' in result)
 def setUp(self):
     """Loads the A residue to start with."""
     self.struc = ModernaStructure('file', A_RESIDUE)
     self.adenosine = self.struc['1']
     struc = ModernaStructure('file', C_RESIDUE, '0')
     self.cytosine = struc['494']
     self.chain = PDBParser().get_structure('test_struc',
                                            MINI_TEMPLATE)[0].child_list[0]
     self.unk = ModernaStructure('file', PDB_UNK)
Beispiel #15
0
 def test_AMP_detection_and_removal(self):
     """Should detect AMP in the structure and remove it while cleaning."""
     st4 = ModernaStructure('file',  PDB_WITH_AMP)
     self.assertEqual(st4.get_sequence(), Sequence('GGGAAGGGAAGAAACUGCGGCUUCGGCCGGCUUCCC_H'))
     pc4 = PdbController(st4)
     self.assertEqual(len(pc4.rna_ligand), 1)
     pc4.clean_structure()
     self.assertEqual(len(pc4.rna_ligand), 0)
     self.assertEqual(st4.get_sequence(), Sequence('GGGAAGGGAAGAAACUGCGGCUUCGGCCGGCUUCCC'))
Beispiel #16
0
 def test_missing_phosphates(self):
     """residues with missing phosphates are fixed."""
     st2 = ModernaStructure('file', MISSING_PHOSPHATES)
     pc = PdbController(st2)
     self.assertEqual(len(pc.P_missing), 2)
     self.assertEqual(st2.get_sequence(), Sequence('GCG_GAUUUALCUCAG'))
     pc.clean_structure()
     self.assertEqual(st2.get_sequence(), Sequence('GCG_GAUUUALCUCAG'))
     pc = PdbController(st2)
     self.assertEqual(len(pc.P_missing), 0)
Beispiel #17
0
 def setUp(self):
     self.m = RnaModel(data_type='file',
                       data=MINI_TEMPLATE,
                       seq=Sequence("GCGGAUUUALCUCAG"))
     self.s1 = ModernaStructure('file',
                                SMALL_FRAGMENT,
                                seq=Sequence("GCGG"))
     self.s2 = ModernaStructure('file',
                                SMALL_FRAGMENT,
                                seq=Sequence("GCGG"))
 def test_wc_pairs_hairpin(self):
     """Exactly two W-C pairs in a hairpin are recognized."""
     m = ModernaStructure('file', RNA_HAIRPIN, 'D')
     result = m.get_base_pairs()
     # calc number of +/+ pairs
     count = 0
     for val in result.values():
         for bpair in val:
             if bpair.type == '+/+':
                 count += 1
     self.assertEqual(count, 4)
 def check_example(self, fn):
     ll = open(fn).readlines()
     ll = [l for l in ll if l.startswith('ATOM')]
     chain1 = ll[3][21]
     chain2 = ll[-3][21]
     bp1 = ModernaStructure('file', fn, chain1)
     bp2 = ModernaStructure('file', fn, chain2)
     resi1 = [r for r in bp1][0]
     resi2 = [r for r in bp2][-1]
     hbonds = self.hb.calc_hbond_list(resi1, resi2)
     return hbonds
 def test_chain_renumbering(self):
     """Chain should be renumbered"""
     m = ModernaStructure('file', RNA_1EHZ)
     m.renumber_chain('100')
     # check residues
     self.assertEqual(m['100'].long_abbrev, 'G')
     self.assertEqual(m['107'].long_abbrev, 'U')
     self.assertEqual(m['109'].long_abbrev, 'm2G')
     self.assertEqual(m['175'].long_abbrev, 'A')
     self.assertEqual(m['115'].long_abbrev, 'D')
     self.assertRaises(RNAChainError, m.renumber_chain, '77A')
 def test_bad_insertion(self):
     """Should fix at least some breaks in a disastrous case"""
     struc = ModernaStructure('file', BAD_LOOP_INSERTION)
     breaks_before = str(struc.get_sequence()).count('_')
     self.assertEqual(breaks_before, 3)
     prev = None
     for resi in struc:
         if prev:
             bb = BackboneBuilder(prev, resi, struc)
         prev = resi
     breaks_after = str(struc.get_sequence()).count('_')
     self.assertTrue(breaks_after < breaks_before)
Beispiel #22
0
 def test_create_long_fragment(self):
     """Fragments with 26+ residues should be OK."""
     t = load_template(RNA_1C0A, 'B')
     resis = t['5':'45']
     long_seq = Sequence("AUAUAUAUAUGCGCGCGCGCAUAUAUAUAUGCGCGCGCG")
     struc = ModernaStructure('residues', resis)
     frag = ModernaFragment53(struc, anchor5=t['5'],anchor3=t['45'], new_sequence=long_seq)
     frag.superimpose()
     frag.prepare_anchor_residues()
     frag.renumber()
     frag.apply_seq()
     self.assertEqual(struc.get_sequence(), Sequence("CAUAUAUAUAUGCGCGCGCGCAUAUAUAUAUGCGCGCGCGG"))
 def _test_repair_congested(self):
     """Should avoid clashes between atoms."""
     #TODO: reactivate test
     struc = ModernaStructure('file',BB_MESSED_UP)
     self.assertFalse(struc['33'].is_phosphate_intact())
     bb = BackboneBuilder(struc['32'], struc['33'], struc)
     struc.write_pdb_file('out.pdb')
     self.assertTrue(bb.is_intact())
     #TODO: criteria are now more strict, therefore test fails.
     self.assertTrue(struc['32'].is_backbone_intact())
     self.assertTrue(struc['33'].is_backbone_intact())
     self.assertTrue(struc['33'].is_phosphate_intact())
     self.assertFalse(struc['33'].is_backbone_congested())
     self.assertFalse(struc['32'].is_backbone_congested())
Beispiel #24
0
 def test_phosphate_detection_and_removal(self):
     """Should detect pfosphate group (P, OP1, OP2, O5') in 3FU2 (resi 12) and remove it."""
     st5 = ModernaStructure('file', PDB_WITH_PHOSPHATE)
     pc5 = PdbController(st5)
     self.assertEqual(len(pc5.phosphate), 1)
     pc5.clean_structure()
     self.assertEqual(len(pc5.phosphate), 0)
Beispiel #25
0
 def test_double_coordinates_identification(self):
     """Should remove RNA ligand when there is no ribose and phosphate group."""
     st3 = ModernaStructure('file', PDB_WITH_DOUBLE_COORDINATES)
     pc3 = PdbController(st3)
     self.assertEqual(len(pc3.disordered), 3)
     pc3.clean_structure()
     self.assertEqual(len(pc3.disordered), 3)
Beispiel #26
0
    def merge_region(self):
        """Merges the optimized residues with the memorized ones."""
        residues = [r for r in self.model]
        if self.model_passive:
            # apply old residue numbers
            print '\nRestoring original numeration in the optimized region.'
            for num, resi in zip(self.model_resnumbers, residues):
                #print resi, num
                #self.model.renumber_residue(resi.identifier, num)
                resi.change_number(num)
            self.model = ModernaStructure('residues',residues)
            # do the superposition
            print '\nSuperimposing the optimized part onto the rest of the model.'
            all_atoms = self.model.get_all_atoms()
            sup = ModernaSuperimposer(moved_atoms = all_atoms)
            sup.get_atoms([self.stem5, self.stem3], BACKBONE_ATOMS, 'fixed')
            resi5, resi3 = self.model[self.residues[0]], self.model[self.residues[1]]
            sup.get_atoms([resi5, resi3], BACKBONE_ATOMS, 'moved')
            sup.superimpose()

            # merge residues
            print '\nMerging the optimized part with the rest of the model.'
            resi = [r for r in self.model]
            for r in self.model_passive:
                if r.identifier not in self.residues:
                    resi.append(r)
            self.model = RnaModel(None, None, self.options.chain_name, 'residues', resi)
Beispiel #27
0
    def check_disconnected_residues(self):
        """
        Looks for residues that belong to the chain, are not connected to the chain 
        and represents synthetic residues, ligands or stereoisomers.
        """
        temp = []
        st = ModernaStructure('residues',
                              self.standard + self.unidentified_rna)
        all_resi = [x for x in st]
        if len(all_resi) == 1: temp.append(all_resi[0].identifier)
        elif not self.continuous:
            for x in range(len(all_resi) - 1):
                if not are_residues_connected(all_resi[x], all_resi[x + 1]):
                    if len(all_resi) == 2:
                        temp += [y.identifier for y in all_resi]
                    elif x + 1 == len(all_resi) - 1:
                        temp.append(all_resi[x + 1].identifier)
                    elif not are_residues_connected(all_resi[x + 1],
                                                    all_resi[x + 2]):
                        temp.append(all_resi[x + 1].identifier)

        # checking whether disconnected residues are not sandard or modified ones
        for resi in temp:
            if not self.is_typical_category_residue(st[resi]):
                self.disconnected_residues.append(st[resi])
Beispiel #28
0
 def test_validate_resi_list(self):
     m = ModernaStructure('file', MINI_TEMPLATE)
     expected = list(m)
     self.assertEqual(validate_resi_list(m), expected)
     self.assertEqual(validate_resi_list([m['2'], m['3']]), expected[1:3])
     self.assertRaises(ParameterError, validate_resi_list, ['not a residue'])
     self.assertRaises(ParameterError, validate_resi_list, 123)
 def test_multi(self):
     "Memory should not run full - this test should not terminate!"
     print 'THIS TEST RUNS FOREVER IF OK! - WATCH MEMORY'
     s = ModernaStructure('file', FIRST)
     while 1:
         cr = ClashRecognizer()
         cr.find_clashes_in_residues(s)
Beispiel #30
0
    def force_superimpose(self, old_bp, new_bp):
        """
        Superimposes base pairs if there is no interaction between old_bp and force mode is True
        """
        min_rmsd = 100.0
        pdb_name = ''
        base_pair = None
        path = DATA_PATH+'base_pairs/'

        for pdb in os.listdir(path):
            if new_bp in pdb:
                moved_residues = ModernaStructure('file', path+pdb).moderna_residues
                moved, fixed, to_move = self.create_atoms_lists(moved_residues)
                rmsd = ModernaSuperimposer(fixed, moved, to_move).rmsd
                if rmsd < min_rmsd:
                    pdb_name = pdb      
                    min_rmsd = rmsd
                    base_pair = moved_residues

        log.write_message("The best RMSD ("+str(min_rmsd)+") with structure: "+pdb_name)  
        if min_rmsd <= self.cutoff:
            log.write_message("RMSD <= cutoff (" + str(self.cutoff) + ")")
            self.assign_residue_numbers(base_pair['1'], base_pair['2'])
        else:
            log.write_message("RMSD > cutoff (" + str(self.cutoff) + ") - starting backbone builder")
            self.run_backbone_builder()