Ejemplo n.º 1
0
 def is_connected(self):
     if not self._pair_table:
         self._pair_table = make_pair_table(self.structure)
     if not self._loop_index:
         try :
             # make loop index raises error when disconnected.
             self._loop_index, self._exterior_loops = make_loop_index(self._pair_table)
         except SecondaryStructureError as e:
             return False
     return True
Ejemplo n.º 2
0
    def exterior_domains(self):
        """
        Returns all domains in exterior loops.
        """
        if not self._exterior_domains:
            if not self._pair_table:
                self._pair_table = make_pair_table(self.structure)
            if not self._loop_index or self._exterior_loops:
                self._loop_index, self._exterior_loops = make_loop_index(self._pair_table)

            self._exterior_domains = []
            self._enclosed_domains = []
            for si, strand in enumerate(self._loop_index):
                for di, domain in enumerate(strand):
                    if self._loop_index[si][di] in self._exterior_loops:
                        if self._pair_table[si][di] is None:
                            self._exterior_domains.append((si, di))
                    elif self._pair_table[si][di] is None:
                            self._enclosed_domains.append((si, di))
        return self._exterior_domains
    def test_make_loop_index(self):
        struct = '(((...)))'
        pt = utils.make_pair_table(struct)
        exp1 = [[1, 2, 3, 3, 3, 3, 3, 2, 1]]
        exp2 = set([0])
        out1, out2 = utils.make_loop_index(pt)
        self.assertEqual(out1, exp1)
        self.assertSetEqual(out2, exp2)

        struct = '..(((...)))..'
        pt = utils.make_pair_table(struct)
        exp1 = [[0, 0, 1, 2, 3, 3, 3, 3, 3, 2, 1, 0, 0]]
        exp2 = set([0])
        out1, out2 = utils.make_loop_index(pt)
        self.assertEqual(out1, exp1)
        self.assertSetEqual(out2, exp2)

        struct = '.((.((...))..((...).))).'
        pt = utils.make_pair_table(struct)
        exp1 = [[
            0, 1, 2, 2, 3, 4, 4, 4, 4, 4, 3, 2, 2, 5, 6, 6, 6, 6, 6, 5, 5, 2,
            1, 0
        ]]
        exp2 = set([0])
        out1, out2 = utils.make_loop_index(pt)
        self.assertEqual(out1, exp1)
        self.assertSetEqual(out2, exp2)

        struct = '.((.((...)).+.((...).))).'
        pt = utils.make_pair_table(struct)
        exp1 = [[0, 1, 2, 2, 3, 4, 4, 4, 4, 4, 3, 2],
                [2, 5, 6, 6, 6, 6, 6, 5, 5, 2, 1, 0]]
        exp2 = set([0, 2])
        out1, out2 = utils.make_loop_index(pt)
        self.assertEqual(out1, exp1)
        self.assertSetEqual(out2, exp2)

        struct = '.((.((...))+..((...).))).'
        pt = utils.make_pair_table(struct)
        exp1 = [[0, 1, 2, 2, 3, 4, 4, 4, 4, 4, 3],
                [2, 2, 5, 6, 6, 6, 6, 6, 5, 5, 2, 1, 0]]
        exp2 = set([0, 2])
        out1, out2 = utils.make_loop_index(pt)
        self.assertEqual(out1, exp1)
        self.assertSetEqual(out2, exp2)

        struct = '.((.((...))+((...).))).'
        pt = utils.make_pair_table(struct)
        exp1 = [[0, 1, 2, 2, 3, 4, 4, 4, 4, 4, 3],
                [5, 6, 6, 6, 6, 6, 5, 5, 2, 1, 0]]
        exp2 = set([0, 2])
        out1, out2 = utils.make_loop_index(pt)
        self.assertEqual(out1, exp1)
        self.assertSetEqual(out2, exp2)

        with self.assertRaises(SecondaryStructureError):
            struct = '..+..'
            pt = utils.make_pair_table(struct)
            out1, out2 = utils.make_loop_index(pt)

        with self.assertRaises(SecondaryStructureError):
            struct = '(.)+.(..)'
            pt = utils.make_pair_table(struct)
            out1, out2 = utils.make_loop_index(pt)

        with self.assertRaises(SecondaryStructureError):
            struct = '((..((.))+.(..).+((...))))'
            pt = utils.make_pair_table(struct)
            out1, out2 = utils.make_loop_index(pt)
Ejemplo n.º 4
0
 def get_loop_index(self, loc):
     if not self._pair_table:
         self._pair_table = make_pair_table(self.structure)
     if not self._loop_index:
         self._loop_index, self._exterior_loops = make_loop_index(self._pair_table)
     return self._loop_index[loc[0]][loc[1]]
Ejemplo n.º 5
0
 def loop_index(self):
     """ returns the loop index of a structure. """
     if not self._pair_table:
         self._pair_table = make_pair_table(self.structure)
     return make_loop_index(self._pair_table)