• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jlab / fold-grammars / 13575009990

27 Feb 2025 08:11PM UTC coverage: 36.409% (+36.4%) from 0.0%
13575009990

Pull #90

github

web-flow
Merge 2912168c2 into 0ad54ba86
Pull Request #90: Rnahybrid add targetbreaking

350 of 410 new or added lines in 9 files covered. (85.37%)

1472 of 4043 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.91
/Misc/Applications/RNAhybrid/tests/test_input.py
1
import sys
1✔
2
from os.path import dirname, join
1✔
3
sys.path.append(dirname(__file__) + '/../')
1✔
4

5
from io import StringIO
1✔
6
from unittest import TestCase, main
1✔
7

8
from input import read_fasta, read_CT_file, disentangle_knots, nested_pairs_to_dotBracket, get_minimal_valid_substructure
1✔
9

10
def getFP(filepath):
1✔
11
    return join(dirname(__file__), filepath)
1✔
12

13
class TestExecute(TestCase):
1✔
14
    def setUp(self):
1✔
15
        self.fp_fasta_mirna = getFP('data/mirnas.fasta')
1✔
16
        self.fp_multiCT = getFP('data/multi.ct')
1✔
17
        self.fp_sars = getFP('data/SARS-CoV-2_Full_Length_Secondary_Structure_Map.ct')
1✔
18
        self.pairs1 = {14292: 14269, 14293: 14268, 14307: 14437, 14308: 14436, 14309: 14323}
1✔
19
        self.pairs2 = {27149: 27127, 27150: 27126, 27164: 27330, 27165: 27329}
1✔
20
        self.pairs3 = {28395: 28379, 28396: 28377, 28397: 28376, 28398: 28375, 28399: 28374, 28410: 28404, 28411: 28403}
1✔
21
        self.pairs4 = {4060: 4053, 4061: 4052, 4062: 4051, 4063: 4050, 4067: 4048, 4068: 4047, 4069: 4046, 4071: 4144, 4072: 4143, 4073: 4142, 4074: 4141, 4075: 4140, 4076: 4139}
1✔
22

23
    def tearDown(self):
1✔
24
        pass
1✔
25

26
    def test_read_fasta(self):
1✔
27
        exp = [
1✔
28
            ('hsa-miR-21-5p::NC_000017.11:59841273-59841295(+)', 'AGCTTATCAGACTGATGTTGAC'),
29
            ('hsa-let-7i-5p::NC_000012.12:62603691-62603713(+)', 'GAGGTAGTAGTTTGTGCTGTTG'),
30
            ('hsa-miR-192-5p::NC_000011.10:64891203-64891224(-)', 'TCTGACCTATGAATTGACAGC'),
31
            ('hsa-miR-151a-3p::NC_000008.11:140732587-140732608(-)', 'ACTAGACtgaagctccttgag'),
32
            ('hsa-miR-27b-3p::NC_000009.12:95085505-95085526(+)', 'TCACAGTGGCTAAGTTCTGCA')]
33
        obs = read_fasta(self.fp_fasta_mirna)
1✔
34
        self.assertEqual(exp, list(obs))
1✔
35

36
    def test_read_CT_file(self):
1✔
37
        with self.assertRaises(ValueError) as e:
1✔
38
            obs = list(read_CT_file(getFP('data/broken.ct')))
1✔
39
        with self.assertRaises(ValueError) as e:
1✔
40
            obs = list(read_CT_file(getFP('data/broken_missing.ct')))
1✔
41

42
        exp = [
1✔
43
            ('A stem-loop structure (with a bulge)',
44
             'GGGCAAUCCUCUUCGGGCCC',
45
             {1: 20, 2: 19, 3: 18, 4: 17, 8: 16, 9: 15, 15: 9, 16: 8, 17: 4, 18: 3, 19: 2, 20: 1}),
46
            ('A pseudo-knot structure',
47
             'GAUGGCACUCCCAUCAAUUGGAGC',
48
             {1: 15, 2: 14, 3: 13, 4: 12, 5: 11, 8: 23, 9: 22, 10: 21, 11: 5, 12: 4, 13: 3, 14: 2, 15: 1, 21: 10, 22: 9, 23: 8})]
49
        obs = read_CT_file(self.fp_multiCT)
1✔
50

51
        obs = list(read_CT_file(getFP('data/SARS-CoV-2_Full_Length_Secondary_Structure_Map.ct')))[0]
1✔
52
        self.assertEqual('finalStructure wPKs', obs[0])
1✔
53
        self.assertEqual(29903, len(obs[1]))
1✔
54
        self.assertTrue(obs[1].endswith('ACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'))
1✔
55
        self.assertTrue(len(obs[1]) > len(obs[2]))
1✔
56

57
    def test_disentangle_knots(self):
1✔
58
        obs = disentangle_knots(next(read_CT_file(getFP('data/earlyKnot.ct')))[2], verbose=None)
1✔
59
        self.assertEqual(len(obs['nested']), 6*2)
1✔
60
        self.assertEqual(len(obs['knotted']), 3*2)
1✔
61

62
        obs = disentangle_knots(next(read_CT_file(getFP('data/lateKnot.ct')))[2], verbose=None)
1✔
63
        self.assertEqual(len(obs['nested']), 6*2)
1✔
64
        self.assertEqual(len(obs['knotted']), 3*2)
1✔
65

66
        obs = disentangle_knots(next(read_CT_file(self.fp_sars))[2], verbose=None)
1✔
67
        self.assertEqual(len(obs['nested']), 8681*2)
1✔
68
        self.assertEqual(len(obs['knotted']), 7*2)
1✔
69

70
        errFile = StringIO("")
1✔
71
        obs = disentangle_knots({1: 4, 2: 5}, errFile)
1✔
72
        self.assertEqual(len(obs['nested']), 1*2)
1✔
73
        self.assertEqual(len(obs['knotted']), 1*2)
1✔
74
        self.assertEqual(errFile.getvalue(), "Warning: 1 of 2 base-pairs in your structure are pseudoknotted, i.e. crossing.\n")
1✔
75

76
    def test_nested_pairs_to_dotBracket(self):
1✔
77
        exp = '((......................)).............(((.............)................................................................................................................))'
1✔
78
        obs = nested_pairs_to_dotBracket(self.pairs1)
1✔
79
        self.assertEqual(exp, obs)
1✔
80

81
        exp = '((.....................)).............((...................................................................................................................................................................))'
1✔
82
        obs = nested_pairs_to_dotBracket(self.pairs2)
1✔
83
        self.assertEqual(exp, obs)
1✔
84

85
        exp = '((((.(...............)))))...((.....))'
1✔
86
        obs = nested_pairs_to_dotBracket(self.pairs3)
1✔
87
        self.assertEqual(exp, obs)
1✔
88

89
        exp = '(((.((((......))))...))).((((((..............................................................))))))'
1✔
90
        obs = nested_pairs_to_dotBracket(self.pairs4)
1✔
91
        self.assertEqual(exp, obs)
1✔
92

93
        exp = '....(....)..............((...(((....)))..))...............'
1✔
94
        obs = nested_pairs_to_dotBracket(
1✔
95
            {24728: 24741, 24729: 24740, 24730: 24739, 24731: 24738, 24732: 24737, 24742: 24785, 24743: 24784, 24744: 24783, 24745: 24781, 24746: 24780, 24747: 24779, 24748: 24776, 24749: 24775, 24750: 24772, 24751: 24771, 24752: 24770, 24753: 24769, 24757: 24766, 24758: 24765, 24759: 24764},
96
            [24738, 24739, 24740, 24741, 24742, 24743, 24744, 24745, 24746, 24747, 24748, 24749, 24750, 24751])
97
        self.assertEqual(exp, obs)
1✔
98

99
        with self.assertRaises(ValueError):
1✔
100
            obs = nested_pairs_to_dotBracket({1: 4, 2: 5})
1✔
101

102
    def test_get_minimal_valid_substructure(self):
1✔
103
        fullSARS = list(read_CT_file(getFP('data/SARS-CoV-2_Full_Length_Secondary_Structure_Map.ct')))[0]
1✔
104

105
        obs = get_minimal_valid_substructure(fullSARS[2], self.pairs1)
1✔
106
        self.assertEqual(nested_pairs_to_dotBracket(obs), '((((.((((((.......))))))..))))......(((((((((...........))..((((((.((....)).))))))..(...(((((.....)))))...).(((......)))...(((((.((((((.(((..............))).)))).))))))).)))))))')
1✔
107

108
        obs = get_minimal_valid_substructure(fullSARS[2], self.pairs2)
1✔
109
        self.assertEqual(nested_pairs_to_dotBracket(obs), '(((((.(((.(((.....................))).))).)))))((((((...(((((((((((.((((...((((..(((((((((...))))).))))))))....).)))...))))))).......)))).(((((((((.......(((.((((....)))).)))..............)))))))))...............))))))')
1✔
110

111
        obs = get_minimal_valid_substructure(fullSARS[2], self.pairs3)
1✔
112
        self.assertEqual(nested_pairs_to_dotBracket(obs), '((((((.((((.........)))))))))).((.....))')
1✔
113

114
        obs = get_minimal_valid_substructure(fullSARS[2], self.pairs4)
1✔
115
        self.assertEqual(nested_pairs_to_dotBracket(obs), '(((((((((......))))..)))))((((((.....(((...((((((((((.((......................)).)))))))))))))))))))')
1✔
116

117
        exp_db = '((((((.....))))))((((..((((((((..(((..((((((((....)))))..)))))).)))))))).((((........))))..............))))' # 31 pairs
1✔
118
        exp_pairs = {
1✔
119
            839: 851, 840: 850, 841: 849, 842: 848, 848: 842, 850: 840,
120
            852: 838, 853: 837, 854: 943, 855: 942, 856: 941, 857: 940,
121
            862: 906, 837: 853, 838: 852, 851: 839, 849: 841, 943: 854,
122
            942: 855, 941: 856, 940: 857, 860: 908, 908: 860, 861: 907,
123
            907: 861, 906: 862, 863: 905, 905: 863, 864: 904, 904: 864,
124
            865: 903, 903: 865, 866: 902, 902: 866, 867: 901, 901: 867,
125
            870: 899, 899: 870, 871: 898, 898: 871, 872: 897, 897: 872,
126
            875: 896, 896: 875, 876: 895, 895: 876, 877: 894, 894: 877,
127
            878: 891, 891: 878, 879: 890, 890: 879, 880: 889, 889: 880,
128
            881: 888, 888: 881, 882: 887, 887: 882, 910: 925, 925: 910,
129
            911: 924, 924: 911, 912: 923, 923: 912, 913: 922, 922: 913}
130
        novel_target_pairing_partners = [int(x) for x in '839,840,841,842,843,845,846,847,848,850,852,853,854,855,856,857,858,859,862'.split(',')]
1✔
131
        original_target_pairs = {o: c for o, c in {x: fullSARS[2].get(x, -1) for x in novel_target_pairing_partners}.items() if c != -1}
1✔
132

133
        obs_ext_pairs = get_minimal_valid_substructure(fullSARS[2], original_target_pairs)
1✔
134
        self.assertEqual(exp_pairs, obs_ext_pairs)
1✔
135

136
        obs = nested_pairs_to_dotBracket(obs_ext_pairs)
1✔
137
        self.assertEqual(exp_db, obs)
1✔
138

139
        pair_subset = {28395: 28379, 28396: 28377, 28397: 28376, 28398: 28375, 28399: 28374, 28410: 28404, 28411: 28403}
1✔
140
        exp = {28395: 28379, 28396: 28377, 28397: 28376, 28398: 28375, 28399: 28374, 28410: 28404, 28411: 28403, 28374: 28399, 28375: 28398, 28376: 28397, 28377: 28396, 28379: 28395, 28380: 28394, 28394: 28380, 28381: 28393, 28393: 28381, 28382: 28392, 28392: 28382, 28400: 28373, 28373: 28400, 28401: 28372, 28372: 28401, 28403: 28411, 28404: 28410}
1✔
141
        obs = get_minimal_valid_substructure(fullSARS[2], pair_subset)
1✔
142
        self.assertEqual(exp, obs)
1✔
143

144
if __name__ == '__main__':
1✔
NEW
145
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc