class OuterLoopTest(unittest.TestCase):
    def setUp(self):
        self.structure = "...((..((..))....)).."
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()
        self.flanking = self.parser.indices(flanking=True)

    def test_hairpins(self):
        ans = [tuple([[9, 10]])]
        self.assertEqual(self.loops['hairpin'], ans)

    def test_flanking_hairpins(self):
        ans = [tuple([[8, 9, 10, 11]])]
        self.assertEqual(self.flanking['hairpin'], ans)

    def test_external(self):
        ans = [([0, 1, 2], [19, 20])]
        self.assertEqual(self.loops['external'], ans)

    def test_flanking_external(self):
        ans = [([0, 1, 2, 3], [18, 19, 20])]
        self.assertEqual(self.flanking['external'], ans)

    def test_internal(self):
        ans = [([5, 6], [13, 14, 15, 16])]
        self.assertEqual(self.loops['internal'], ans)

    def test_flanking_internal(self):
        ans = [([4, 5, 6, 7], [12, 13, 14, 15, 16, 17])]
        self.assertEqual(self.flanking['internal'], ans)
class NestedParserTest(unittest.TestCase):
    def setUp(self):
        self.structure = "...((..(((....)))...((((...))))...))..."
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()
        seq = "aaaccaacccuuuugggtttccccuuuggggtttggttt"
        self.sequences = self.parser.loops(seq)

    def test_hairpins(self):
        ans = [tuple([[24, 25, 26]]), tuple([[10, 11, 12, 13]])]
        self.assertEqual(self.loops['hairpin'], ans)

    def test_external_loop(self):
        ans = [([0, 1, 2], [36, 37, 38])]
        self.assertEqual(self.loops['external'], ans)

    def test_internal_loops(self):
        self.assertFalse('internal' in self.loops)

    # def test_junction_loops(self):
    #     ans = [([5, 6], [17, 18, 19], [31, 32, 33])]
    #     self.parser._tree.print_tree()
    #     self.assertEqual(self.loops['junction'], ans)

    def test_extract_hairpins(self):
        ans = ['uuu', 'uuuu']
        self.assertEqual(self.sequences['hairpin'], ans)
Пример #3
0
    def results(self, process, temp_dir, filename):
        """This will generate a list of size 1 because RNAalifold only
        generates a single structure. The result will be a Dot-Bracket parser
        with a sequence property set the consensus produced by RNAalifold and
        an energy property of the energy line given by RNAalifold.

        :process: The process object.
        :temp_dir: The directory all work was done in.
        :filename: Input filename.
        """
        self.raw = process.stdout.readlines()
        if len(self.raw) != 3 and len(self.raw) != 2:
            raise FoldingFailedError("No valid output")
        consensus = self.raw[0].rstrip()
        structure_line = self.raw[1].rstrip()
        parts = structure_line.split(' ', 1)
        parser = DotBracket(parts[0])
        parser.sequence = consensus
        parser.energy = parts[1]

        ps_parser = self._load_locations(temp_dir, filename)
        parser.locations = ps_parser.locations
        parser.box = ps_parser.box

        return [parser]
Пример #4
0
    def results(self, process, temp_dir, filename):
        """This will generate a list of size 1 because RNAalifold only
        generates a single structure. The result will be a Dot-Bracket parser
        with a sequence property set the consensus produced by RNAalifold and
        an energy property of the energy line given by RNAalifold.

        :process: The process object.
        :temp_dir: The directory all work was done in.
        :filename: Input filename.
        """
        self.raw = process.stdout.readlines()
        if len(self.raw) != 3 and len(self.raw) != 2:
            raise FoldingFailedError("No valid output")
        consensus = self.raw[0].rstrip()
        structure_line = self.raw[1].rstrip()
        parts = structure_line.split(' ', 1)
        parser = DotBracket(parts[0])
        parser.sequence = consensus
        parser.energy = parts[1]

        ps_parser = self._load_locations(temp_dir, filename)
        parser.locations = ps_parser.locations
        parser.box = ps_parser.box

        return [parser]
class OuterLoopTest(unittest.TestCase):
    def setUp(self):
        self.structure = "...((..((..))....)).."
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()
        self.flanking = self.parser.indices(flanking=True)

    def test_hairpins(self):
        ans = [tuple([[9, 10]])]
        self.assertEqual(self.loops['hairpin'], ans)

    def test_flanking_hairpins(self):
        ans = [tuple([[8, 9, 10, 11]])]
        self.assertEqual(self.flanking['hairpin'], ans)

    def test_external(self):
        ans = [([0, 1, 2], [19, 20])]
        self.assertEqual(self.loops['external'], ans)

    def test_flanking_external(self):
        ans = [([0, 1, 2, 3], [18, 19, 20])]
        self.assertEqual(self.flanking['external'], ans)

    def test_internal(self):
        ans = [([5, 6], [13, 14, 15, 16])]
        self.assertEqual(self.loops['internal'], ans)

    def test_flanking_internal(self):
        ans = [([4, 5, 6, 7], [12, 13, 14, 15, 16, 17])]
        self.assertEqual(self.flanking['internal'], ans)
class NestedParserTest(unittest.TestCase):

    def setUp(self):
        self.structure = "...((..(((....)))...((((...))))...))..."
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()
        seq = "aaaccaacccuuuugggtttccccuuuggggtttggttt"
        self.sequences = self.parser.loops(seq)

    def test_hairpins(self):
        ans = [tuple([[24, 25, 26]]), tuple([[10, 11, 12, 13]])]
        self.assertEqual(self.loops['hairpin'], ans)

    def test_external_loop(self):
        ans = [([0, 1, 2], [36, 37, 38])]
        self.assertEqual(self.loops['external'], ans)

    def test_internal_loops(self):
        self.assertFalse('internal' in self.loops)

    # def test_junction_loops(self):
    #     ans = [([5, 6], [17, 18, 19], [31, 32, 33])]
    #     self.parser._tree.print_tree()
    #     self.assertEqual(self.loops['junction'], ans)

    def test_extract_hairpins(self):
        ans = ['uuu', 'uuuu']
        self.assertEqual(self.sequences['hairpin'], ans)
class Ty1Test(unittest.TestCase):
    def setUp(self):
        self.structure = '(((((((.....((((((((...))))).)))......(((((((.........(((((.((.........(((((.(((((............(((.(((...((((....((..(((((....))))))).))))......((..(((...)))..)).))).)))........)))))))))).)).)))))..)))))))..)))).................(((.....))).((((....))))...((((((((.........(.(((((...((((..(((.........)))..))))....))))))))))))))........................((((((((....((((((..............))))))..............(((.(((((.((.......)).))))).)))....(((..(((((.((.((((........))))))((......))...........((((((((............))))))))......)))))..)))....(((((............))))).)))))..))).(((((......(((((((..........)))))))...)))))...................))).......'
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()

    def test_hairpins(self):
        ans = [
            tuple([[20, 21, 22]]),
            tuple([[121, 122, 123, 124]]),
            tuple([[150, 151, 152]]),
            tuple([[230, 231, 232, 233, 234]]),
            tuple([[243, 244, 245, 246]]),
            tuple([[290, 291, 292, 293, 294, 295, 296, 297, 298]]),
            tuple([[
                368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
                380, 381
            ]]),
            tuple([[414, 415, 416, 417, 418, 419, 420]]),
            tuple([[455, 456, 457, 458, 459, 460, 461, 462]]),
            tuple([[471, 472, 473, 474, 475, 476]]),
            tuple(
                [[498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508,
                  509]]),
            tuple(
                [[543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553,
                  554]]),
            tuple([[590, 591, 592, 593, 594, 595, 596, 597, 598, 599]])
        ]
        ans.reverse()
        self.assertEqual(self.loops['hairpin'], ans)
class EmptyLeftSideTest(unittest.TestCase):
    def setUp(self):
        self.structure = "((((..))....))"
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices(flanking=True)

    def test_internal_loops(self):
        val = self.loops['internal']
        ans = [tuple([[1, 2], [7, 8, 9, 10, 11, 12]])]
        self.assertEqual(val, ans)
class EmptyLeftSideTest(unittest.TestCase):
    def setUp(self):
        self.structure = "((((..))....))"
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices(flanking=True)

    def test_internal_loops(self):
        val = self.loops['internal']
        ans = [tuple([[1, 2], [7, 8, 9, 10, 11, 12]])]
        self.assertEqual(val, ans)
class RfamDialectTest(unittest.TestCase):
    def setUp(self):
        self.structure = '.AAA....<<<<aaa....>>>>'
        self.parser = Parser(self.structure, dialect='rfam')
        self.loops = self.parser.indices()

    def test_finds_hairpins(self):
        self.assertTrue('hairpin' in self.loops)

    def test_finds_no_internal(self):
        self.assertFalse('internal' in self.loops)
class RfamDialectTest(unittest.TestCase):
    def setUp(self):
        self.structure = '.AAA....<<<<aaa....>>>>'
        self.parser = Parser(self.structure, dialect='rfam')
        self.loops = self.parser.indices()

    def test_finds_hairpins(self):
        self.assertTrue('hairpin' in self.loops)

    def test_finds_no_internal(self):
        self.assertFalse('internal' in self.loops)
class SimpleParserTest(unittest.TestCase):
    def setUp(self):
        self.structure = "((..((..))....))..((...))"
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()
        self.flanking = self.parser.indices(flanking=True)

    def test_hairpins(self):
        ans = [tuple([[6, 7]]), tuple([[20, 21, 22]])]
        self.assertEqual(self.loops['hairpin'], ans)

    def test_flanking_hairpins(self):
        ans = [tuple([[5, 6, 7, 8]]), tuple([[19, 20, 21, 22, 23]])]
        self.assertEqual(self.flanking['hairpin'], ans)

    def test_internal(self):
        ans = [([2, 3], [10, 11, 12, 13])]
        print(self.parser._tree.print_tree())
        self.assertEqual(self.loops['internal'], ans)

    def test_flanking_internal(self):
        ans = [([1, 2, 3, 4], [9, 10, 11, 12, 13, 14])]
        self.assertEqual(self.flanking['internal'], ans)
class SimpleParserTest(unittest.TestCase):

    def setUp(self):
        self.structure = "((..((..))....))..((...))"
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()
        self.flanking = self.parser.indices(flanking=True)

    def test_hairpins(self):
        ans = [tuple([[6, 7]]), tuple([[20, 21, 22]])]
        self.assertEqual(self.loops['hairpin'], ans)

    def test_flanking_hairpins(self):
        ans = [tuple([[5, 6, 7, 8]]), tuple([[19, 20, 21, 22, 23]])]
        self.assertEqual(self.flanking['hairpin'], ans)

    def test_internal(self):
        ans = [([2, 3], [10, 11, 12, 13])]
        print(self.parser._tree.print_tree())
        self.assertEqual(self.loops['internal'], ans)

    def test_flanking_internal(self):
        ans = [([1, 2, 3, 4], [9, 10, 11, 12, 13, 14])]
        self.assertEqual(self.flanking['internal'], ans)
class Ty1Test(unittest.TestCase):
    def setUp(self):
        self.structure = '(((((((.....((((((((...))))).)))......(((((((.........(((((.((.........(((((.(((((............(((.(((...((((....((..(((((....))))))).))))......((..(((...)))..)).))).)))........)))))))))).)).)))))..)))))))..)))).................(((.....))).((((....))))...((((((((.........(.(((((...((((..(((.........)))..))))....))))))))))))))........................((((((((....((((((..............))))))..............(((.(((((.((.......)).))))).)))....(((..(((((.((.((((........))))))((......))...........((((((((............))))))))......)))))..)))....(((((............))))).)))))..))).(((((......(((((((..........)))))))...)))))...................))).......'
        self.parser = Parser(self.structure)
        self.loops = self.parser.indices()

    def test_hairpins(self):
        ans = [tuple([[20,21,22]]),
               tuple([[121,122,123,124]]),
               tuple([[150,151,152]]),
               tuple([[230,231,232,233,234]]),
               tuple([[243,244,245,246]]),
               tuple([[290,291,292,293,294,295,296,297,298]]),
               tuple([[368,369,370,371,372,373,374,375,376,377,378,379,380,381]]),
               tuple([[414,415,416,417,418,419,420]]),
               tuple([[455,456,457,458,459,460,461,462]]),
               tuple([[471,472,473,474,475,476]]),
               tuple([[498,499,500,501,502,503,504,505,506,507,508,509]]),
               tuple([[543,544,545,546,547,548,549,550,551,552,553,554]]),
               tuple([[590,591,592,593,594,595,596,597,598,599]])]
        ans.reverse()
        self.assertEqual(self.loops['hairpin'], ans)
 def setUp(self):
     self.structure = "...((..((..))....)).."
     self.parser = Parser(self.structure)
     self.formatter = Writer()
 def setUp(self):
     self.structure = '(((((((.....((((((((...))))).)))......(((((((.........(((((.((.........(((((.(((((............(((.(((...((((....((..(((((....))))))).))))......((..(((...)))..)).))).)))........)))))))))).)).)))))..)))))))..)))).................(((.....))).((((....))))...((((((((.........(.(((((...((((..(((.........)))..))))....))))))))))))))........................((((((((....((((((..............))))))..............(((.(((((.((.......)).))))).)))....(((..(((((.((.((((........))))))((......))...........((((((((............))))))))......)))))..)))....(((((............))))).)))))..))).(((((......(((((((..........)))))))...)))))...................))).......'
     self.parser = Parser(self.structure)
     self.loops = self.parser.indices()
import os
import sys

# Just mess with path a little so we can run this from anywhere.
here = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(here)

from rnastructure.secondary.pseudoknot import RemovePseudoknots
from rnastructure.secondary.dot_bracket import Parser as DotParser
from rnastructure.secondary.dot_bracket import Writer as DotWriter

rfam_pseudoknots = "<<<<<..AA..>>>>>aa"
rfam_sequence = "CCCCCAAGGUUGGGGGCC"

# Create a dot-bracket parser that can handle rfam's format.
parser = DotParser(rfam_pseudoknots, dialect="rfam")
parser.sequence = rfam_sequence

print(
    """
Note that RemovePseudoknots needs to have an enviroment variable DATAPATH set.
This must lead to the data tables provided with RNAstructure. Below is where
mine are, change as needed.
os.putenv('DATAPATH', '/Users/blake/lab/programs/RNAstructure/data_tables')
"""
)

# Remove all pseudoknots and return a new parser for the new structure.
remover = RemovePseudoknots()
stripped = remover(parser)
 def setUp(self):
     self.structure = "((..((..))....))..((...))"
     self.parser = Parser(self.structure)
     self.loops = self.parser.indices()
     self.flanking = self.parser.indices(flanking=True)
 def setUp(self):
     self.structure = '(((((((.....((((((((...))))).)))......(((((((.........(((((.((.........(((((.(((((............(((.(((...((((....((..(((((....))))))).))))......((..(((...)))..)).))).)))........)))))))))).)).)))))..)))))))..)))).................(((.....))).((((....))))...((((((((.........(.(((((...((((..(((.........)))..))))....))))))))))))))........................((((((((....((((((..............))))))..............(((.(((((.((.......)).))))).)))....(((..(((((.((.((((........))))))((......))...........((((((((............))))))))......)))))..)))....(((((............))))).)))))..))).(((((......(((((((..........)))))))...)))))...................))).......'
     self.parser = Parser(self.structure)
     self.loops = self.parser.indices()
 def setUp(self):
     self.structure = "((..((..))....))..((...))"
     self.parser = Parser(self.structure)
     self.loops = self.parser.indices()
     self.flanking = self.parser.indices(flanking=True)
 def setUp(self):
     self.structure = '.AAA....<<<<aaa....>>>>'
     self.parser = Parser(self.structure, dialect='rfam')
     self.loops = self.parser.indices()
 def setUp(self):
     self.structure = '.AAA....<<<<aaa....>>>>'
     self.parser = Parser(self.structure, dialect='rfam')
     self.loops = self.parser.indices()
 def setUp(self):
     self.structure = "...((..(((....)))...((((...))))...))..."
     self.parser = Parser(self.structure)
     self.loops = self.parser.indices()
     seq = "aaaccaacccuuuugggtttccccuuuggggtttggttt"
     self.sequences = self.parser.loops(seq)
 def setUp(self):
     self.structure = "...((..(((....)))...((((...))))...))..."
     self.parser = Parser(self.structure)
     self.loops = self.parser.indices()
     seq = "aaaccaacccuuuugggtttccccuuuggggtttggttt"
     self.sequences = self.parser.loops(seq)
import os
import sys

# Just mess with path a little so we can run this from anywhere.
here = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(here)

from rnastructure.secondary.pseudoknot import RemovePseudoknots
from rnastructure.secondary.dot_bracket import Parser as DotParser
from rnastructure.secondary.dot_bracket import Writer as DotWriter

rfam_pseudoknots = '<<<<<..AA..>>>>>aa'
rfam_sequence = 'CCCCCAAGGUUGGGGGCC'

# Create a dot-bracket parser that can handle rfam's format.
parser = DotParser(rfam_pseudoknots, dialect='rfam')
parser.sequence = rfam_sequence

print("""
Note that RemovePseudoknots needs to have an enviroment variable DATAPATH set.
This must lead to the data tables provided with RNAstructure. Below is where
mine are, change as needed.
os.putenv('DATAPATH', '/Users/blake/lab/programs/RNAstructure/data_tables')
""")

# Remove all pseudoknots and return a new parser for the new structure.
remover = RemovePseudoknots()
stripped = remover(parser)

# Show the indices
print(stripped.indices())