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
|
"""Tests for Clustal sequence format writer.
"""
from unittest import TestCase
from cogent3.core.alignment import Alignment
from cogent3.format.clustal import clustal_from_alignment
class ClustalTests(TestCase):
"""Tests for Clustal writer."""
def setUp(self):
"""Setup for Clustal 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.clustal_with_label = """CLUSTAL
1st AAAA
2nd CCCC
3rd GGGG
4th UUUU
"""
self.clustal_with_label_lw2 = """CLUSTAL
1st AA
2nd CC
3rd GG
4th UU
1st AA
2nd CC
3rd GG
4th UU
"""
self.clustal_with_label_reordered = """CLUSTAL
2nd CCCC
4th UUUU
3rd GGGG
1st AAAA
"""
self.clustal_with_label_lw2_reordered = """CLUSTAL
2nd CC
4th UU
3rd GG
1st AA
2nd CC
4th UU
3rd GG
1st AA
"""
def test_clustal_from_alignment_unaligned(self):
"""should raise error with unaligned seqs."""
self.assertRaises(ValueError, clustal_from_alignment, self.unaligned_dict)
def test_clustal_from_alignment(self):
"""should return correct clustal string."""
self.assertEqual(clustal_from_alignment({}), "")
self.assertEqual(
clustal_from_alignment(self.alignment_dict), self.clustal_with_label
)
self.assertEqual(
clustal_from_alignment(self.alignment_dict, wrap=2),
self.clustal_with_label_lw2,
)
def test_clustal_from_alignment_reordered(self):
"""should return correct clustal string."""
self.assertEqual(
clustal_from_alignment(self.alignment_object),
self.clustal_with_label_reordered,
)
self.assertEqual(
clustal_from_alignment(self.alignment_object, wrap=2),
self.clustal_with_label_lw2_reordered,
)
|