File: test_stockholm.py

package info (click to toggle)
python-cogent 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,424 kB
  • ctags: 24,343
  • sloc: python: 134,200; makefile: 100; ansic: 17; sh: 10
file content (136 lines) | stat: -rw-r--r-- 3,764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
 #!/usr/bin/env python
"""Tests for Stockholm sequence format writer.
"""
from cogent.util.unit_test import TestCase, main
from cogent.format.stockholm import stockholm_from_alignment
from cogent.core.alignment import Alignment
from cogent.core.sequence import Sequence
from cogent.core.info import Info

__author__ = "Jeremy Widmann"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__credits__ = ["Jeremy Widmann"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Jeremy Widmann"
__email__ = "jeremy.widmann@colorado.edu"
__status__ = "Production"

class StockholmTests(TestCase):
    """Tests for Stockholm writer.
    """
    def setUp(self):
        """Setup for Stockholm tests."""
        self.unaligned_dict = {'1st':'AAA','2nd':'CCCC','3rd':'GGGG',
            '4th':'UUUU'}
        self.alignment_dict = {'1st':'AAAA','2nd':'CCCC','3rd':'GGGG',
            '4th':'UUUU'}
        #create alignment change order.
        self.alignment_object = Alignment(self.alignment_dict)
        self.alignment_order = ['2nd','4th','3rd','1st']
        self.alignment_object.RowOrder=self.alignment_order
        
        self.gc_annotation = {'SS_cons':'....'}
        self.stockholm_with_label=\
"""# STOCKHOLM 1.0

1st    AAAA
2nd    CCCC
3rd    GGGG
4th    UUUU
//"""
        self.stockholm_with_label_lw2=\
"""# STOCKHOLM 1.0

1st    AA
2nd    CC
3rd    GG
4th    UU

1st    AA
2nd    CC
3rd    GG
4th    UU
//"""

        self.stockholm_with_label_struct=\
"""# STOCKHOLM 1.0

1st             AAAA
2nd             CCCC
3rd             GGGG
4th             UUUU
#=GC SS_cons    ....
//"""
        self.stockholm_with_label_struct_lw2=\
"""# STOCKHOLM 1.0

1st             AA
2nd             CC
3rd             GG
4th             UU
#=GC SS_cons    ..

1st             AA
2nd             CC
3rd             GG
4th             UU
#=GC SS_cons    ..
//"""

        self.stockholm_with_label_reordered=\
"""# STOCKHOLM 1.0

2nd    CCCC
4th    UUUU
3rd    GGGG
1st    AAAA
//"""

        self.stockholm_with_label_lw2_reordered=\
"""# STOCKHOLM 1.0

2nd    CC
4th    UU
3rd    GG
1st    AA

2nd    CC
4th    UU
3rd    GG
1st    AA
//"""

    def test_stockholm_from_alignment_unaligned(self):
        """should raise error with unaligned seqs."""
        self.assertRaises(ValueError,\
            stockholm_from_alignment,self.unaligned_dict)
    
    def test_stockholm_from_alignment(self):
        """should return correct stockholm string."""
        self.assertEqual(stockholm_from_alignment({}),'')
        self.assertEqual(stockholm_from_alignment(self.alignment_dict),\
            self.stockholm_with_label)
        self.assertEqual(stockholm_from_alignment(self.alignment_dict,
                interleave_len=2),self.stockholm_with_label_lw2)
    
    def test_stockholm_from_alignment_struct(self):
        """should return correct stockholm string."""
        self.assertEqual(stockholm_from_alignment({},\
            GC_annotation=self.gc_annotation),'')
        self.assertEqual(stockholm_from_alignment(self.alignment_dict,\
            GC_annotation=self.gc_annotation),\
            self.stockholm_with_label_struct)
        self.assertEqual(stockholm_from_alignment(self.alignment_dict,\
            GC_annotation=self.gc_annotation,\
            interleave_len=2),self.stockholm_with_label_struct_lw2)
    
    def test_stockholm_from_alignment_reordered(self):
        """should return correct stockholm string."""
        self.assertEqual(stockholm_from_alignment(self.alignment_object),\
            self.stockholm_with_label_reordered)
        self.assertEqual(stockholm_from_alignment(self.alignment_object,
                interleave_len=2),self.stockholm_with_label_lw2_reordered)

if __name__ == "__main__":
    main()