コード例 #1
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)
コード例 #2
0
class ModernaFragment5Tests(TestCase):
    """fragment attached at 3' end of model"""
    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_attributes(self):
        five = ModernaFragment5(self.s1, anchor5=self.m['15'])
        self.assertEqual(len(five.anchor_residues), 1)
        self.assertEqual(len(five.nonanchor_residues), 3)
        self.assertTrue(str(five))

    def test_add_on_3_end(self):
        """Model sequence should change accordingly."""
        five = ModernaFragment5(self.s1, anchor5=self.m['15'])
        self.m.insert_fragment(five)
        self.assertEqual(self.m.get_sequence(), Sequence("GCGGAUUUALCUCAGCGG"))
        self.assertTrue(five.rmsd <= 1.00)

    def test_add_on_3_end_replace(self):
        """Model sequence should change accordingly."""
        five_overwrite = ModernaFragment5(self.s2, anchor5=self.m['9'])
        self.m.insert_fragment(five_overwrite)
        self.assertEqual(self.m.get_sequence(), Sequence("GCGGAUUUACGG"))
        self.assertTrue(five_overwrite.rmsd <= 1.00, 0)
コード例 #3
0
 def test_insert_eliminate(self):
     """Inserts a 2D fragment into a model."""
     helix = load_model(HELIX, 'A')
     helix = RnaModel(None, None, 'A', 'residues',
                      helix['1':'8'] + helix['73':'80'])
     mf = ModernaFragment2D(self.motif, \
                     anchor5=helix['7'], anchor3=helix['74'], \
                     anchor5_upper=helix['8'], anchor3_upper=helix['73'], \
                     frag5_upper=self.motif['196'], frag3_upper=self.motif['217'], \
                     new_sequence=Sequence('C'), \
                     model=helix)
     helix.insert_fragment(mf)
     self.assertEqual(helix.get_sequence(), Sequence('AAAAAAAA_UCUUUUUUU'))
     self.assertEqual(helix.get_secstruc(), '(((((((().)))))))')
コード例 #4
0
 def test_fill_gap_numbering(self):
     """Should insert fragment with correct numbering."""
     t = Template(DOUBLEGAP, 'file', 'A')
     m = RnaModel()
     for r in t:
         m.copy_residue(r)
     struc = ModernaStructure('file', FRAGMENT1)
     f1 = ModernaFragment53(struc,
                            anchor5=m['20'],
                            anchor3=m['24'],
                            new_sequence=Sequence('AUA'))
     m.insert_fragment(f1)
     resids = [r.identifier for r in m]
     expected_resids1 = [
         '18', '19', '20', '20A', '20B', '20C', '24', '27', '28', '29',
         '30', '31', '32', '33', '34', '35'
     ]
     self.assertEqual(resids, expected_resids1)
コード例 #5
0
class ModernaFragment3Tests(TestCase):
    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_attributes(self):
        """Attributes of fragment are accessible."""
        three = ModernaFragment3(self.s1, anchor3=self.m['1'])
        self.assertEqual(len(three.anchor_residues), 1)
        self.assertEqual(len(three.nonanchor_residues), 3)
        self.assertTrue(str(three))

    def test_add_on_5_end(self):
        """Model sequence should change accordingly."""
        three = ModernaFragment3(self.s1, anchor3=self.m['1'])
        self.m.insert_fragment(three)
        self.assertEqual(self.m.get_sequence(), Sequence("GCGGCGGAUUUALCUCAG"))
        self.assertTrue(three.rmsd <= 1.00)

    def test_add_on_5_end_exact(self):
        """Model sequence should change accordingly."""
        # exactly fitting example replacing original residues.
        three_overwrite = ModernaFragment3(self.s2, anchor3=self.m['6'])
        self.m.insert_fragment(three_overwrite)
        self.assertEqual(self.m.get_sequence(), Sequence("GCGUUUALCUCAG"))
        self.assertTrue(three_overwrite.rmsd <= 1.00)

    def test_add_discontinuous(self):
        """Tries to add a helix to an end."""
        helix = ModernaStructure('file', 'test_data/rna_structures/helix.pdb')
        helix_frag = ModernaFragment3(helix, anchor3=self.m['1'], strict=False)
        self.m.insert_fragment(helix_frag)
        self.assertEqual(self.m.get_sequence(),
                         Sequence('CCGACCUUCGGCC_GGUGGCCGAAGGGCGGAUUUALCUCAG'))
コード例 #6
0
class ModernaFragment53Tests(TestCase):
    """
    Checks basic functionality of the ModernaFragment class.
    """
    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"))
        self.s3 = ModernaStructure('file',
                                   MINI_TEMPLATE,
                                   seq=Sequence("GCGGAUUUALCUCAG"))

    def test_attributes(self):
        """object attributes are set up correctly."""
        f1 = ModernaFragment53(self.s1,
                               anchor5=self.m['10'],
                               anchor3=self.m['13'])
        self.assertEqual(len(f1.struc), 4)
        self.assertEqual(f1.anchor5.fixed_resi, self.m['10'])
        self.assertEqual(f1.anchor3.fixed_resi, self.m['13'])
        self.assertEqual(f1.struc.get_sequence(), Sequence("GCGG"))
        self.assertTrue(str(f1))
        # anchor residues
        self.assertEqual(len(f1.anchor_residues), 2)
        self.assertEqual(f1.anchor_residues[0].mobile_resi.identifier, '1')
        self.assertEqual(f1.anchor_residues[1].mobile_resi.identifier, '4')
        f1.prepare_anchor_residues()
        self.assertEqual(f1.anchor_residues[0].mobile_resi.identifier, '1')
        self.assertEqual(f1.anchor_residues[1].mobile_resi.identifier, '4')
        # non-anchors
        self.assertEqual(len(f1.nonanchor_residues), 2)
        # second example
        f2 = ModernaFragment53(self.s2,
                               anchor5=self.m['1'],
                               anchor3=self.m['4'],
                               new_sequence=Sequence('GL'))
        self.assertEqual(len(f2.struc), 4)
        self.assertEqual(f2.struc.get_sequence(), Sequence("GCGG"))
        self.assertEqual(f2.new_sequence, Sequence("GL"))

    def test_get_resi_to_remove(self):
        """Should return resi identifiers between anchors and of anchors itself."""
        f1 = ModernaFragment53(self.s1,
                               anchor5=self.m['10'],
                               anchor3=self.m['13'])
        result = f1.get_resi_to_remove(self.m)
        self.assertEqual(result, ['10', '11', '12', '13'])

    def test_renumber(self):
        """New numbering should start at anchor5, and then go through alphabet."""
        f1 = ModernaFragment53(self.s1,
                               anchor5=self.m['10'],
                               anchor3=self.m['13'])
        f1.prepare_anchor_residues()
        f1.renumber()
        self.assertEqual([r.identifier for r in self.s1],
                         ['10', '10A', '10B', '13'])
        # second example
        f2 = ModernaFragment53(self.s2,
                               anchor5=self.m['1'],
                               anchor3=self.m['4'],
                               new_sequence=Sequence('GL'))
        f2.prepare_anchor_residues()
        f2.renumber()
        self.assertEqual([r.identifier for r in self.s2],
                         ['1', '1A', '1B', '4'])

    def test_superimpose_fragment(self):
        """Should apply superimposition and return RMSD"""
        f1 = ModernaFragment53(self.s1,
                               anchor5=self.m['10'],
                               anchor3=self.m['13'])
        rmsd = f1.superimpose()
        self.assertAlmostEqual(rmsd, 1.0, 0)  # MM: ? 1.1253267913922658
        # second fragment should fit perfectly
        f2 = ModernaFragment53(self.s2,
                               anchor5=self.m['1'],
                               anchor3=self.m['4'],
                               new_sequence=Sequence('GL'))
        rmsd = f2.superimpose()
        self.assertAlmostEqual(rmsd, 0.00)

    def test_refine(self):
        """Should change both numbers and sequence, and superimpose."""
        f2 = ModernaFragment53(self.s2,
                               anchor5=self.m['1'],
                               anchor3=self.m['4'],
                               new_sequence=Sequence('GL'))
        f2.superimpose()
        f2.prepare_anchor_residues()
        f2.renumber()
        f2.apply_seq()
        numbers = [r.identifier for r in self.s2]
        self.assertEqual(numbers, ['1', '1A', '1B', '4'])
        self.assertEqual(self.s2.get_sequence(), Sequence('GGLG'))

    def test_clash(self):
        """Should not clash with a given piece of structure."""
        f1 = ModernaFragment53(self.s1,
                               anchor5=self.m['10'],
                               anchor3=self.m['13'])
        self.assertFalse(f1.has_clashes(self.m['8':'10']))
        f2 = ModernaFragment53(self.s2,
                               anchor5=self.m['1'],
                               anchor3=self.m['4'],
                               new_sequence=Sequence('GL'))
        self.assertTrue(f2.has_clashes(self.m['1':'4']))

    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_add_numbering_letters(self):
        """Model numbers should change accordingly."""
        middle1 = ModernaFragment53(self.s1,
                                    anchor5=self.m['9'],
                                    anchor3=self.m['14'],
                                    keep=keep_nothing)
        middle1.prepare_anchor_residues()
        middle1.renumber(self.m)
        self.m.insert_fragment(middle1)
        numbers = [r.identifier for r in self.m]
        expected = [
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '9A', '9B', '14', '15'
        ]
        self.assertEqual(numbers, expected)

    def test_add_keep_numbers(self):
        """Model numbers should change accordingly."""
        middle1 = ModernaFragment53(self.s1,
                                    anchor5=self.m['9'],
                                    anchor3=self.m['14'],
                                    keep=keep_first_last)
        middle1.prepare_anchor_residues()
        middle1.renumber(self.m)
        self.m.insert_fragment(middle1)
        numbers = [r.identifier for r in self.m]
        expected = [
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '13', '14', '15'
        ]
        self.assertEqual(numbers, expected)

    def test_add_continuous_exact(self):
        """Model sequence should change accordingly."""
        f2 = ModernaFragment53(self.s2,
                               anchor5=self.m['1'],
                               anchor3=self.m['4'],
                               new_sequence=Sequence('GL'))
        self.m.insert_fragment(f2)
        self.assertEqual(self.m.get_sequence(), Sequence("GGLGAUUUALCUCAG"))
        self.assertAlmostEqual(f2.rmsd, 0.000, 2)