File: test_motifs.py

package info (click to toggle)
python-biopython 1.78%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 65,756 kB
  • sloc: python: 221,141; xml: 178,777; ansic: 13,369; sql: 1,208; makefile: 131; sh: 70
file content (2275 lines) | stat: -rw-r--r-- 134,981 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
# Copyright 2008 by Bartek Wilczynski.  All rights reserved.
# Revisions copyright 2019 by Victor Lin.
# Adapted from test_Mymodule.py by Jeff Chang.
# This file is part of the Biopython distribution and governed by your
# choice of the "Biopython License Agreement" or the "BSD 3-Clause License".
# Please see the LICENSE file that should have been included as part of this
# package.

"""Tests for motifs module."""

import os
import unittest
import math

from Bio import motifs
from Bio.Seq import Seq


class MotifTestsBasic(unittest.TestCase):
    """Basic motif tests."""

    def setUp(self):
        self.PFMin = open("motifs/SRF.pfm")
        self.SITESin = open("motifs/Arnt.sites")
        self.CLUSTERBUSTERin = open("motifs/clusterbuster.pfm")
        self.XMSin = open("motifs/abdb.xms")
        self.TFout = "motifs/tf.out"
        self.FAout = "motifs/fa.out"
        self.PFMout = "motifs/fa.out"
        instance = Seq("ATATA")
        instances = [instance]
        self.m = motifs.create(instances)

    def tearDown(self):
        self.PFMin.close()
        self.SITESin.close()
        if os.path.exists(self.TFout):
            os.remove(self.TFout)
        if os.path.exists(self.FAout):
            os.remove(self.FAout)

    def test_alignace_parsing(self):
        """Test if Bio.motifs can parse AlignAce output files."""
        with open("motifs/alignace.out") as handle:
            record = motifs.parse(handle, "AlignAce")
        self.assertEqual(record.version, "AlignACE 4.0 05/13/04")
        self.assertEqual(record.command, "./AlignACE -i test.fa")
        self.assertEqual(len(record.parameters), 7)
        self.assertEqual(record.parameters["expect"], "10")
        self.assertEqual(record.parameters["gcback"], "0.38")
        self.assertEqual(record.parameters["minpass"], "200")
        self.assertEqual(record.parameters["seed"], "1227623309")
        self.assertEqual(record.parameters["numcols"], "10")
        self.assertEqual(record.parameters["undersample"], "1")
        self.assertEqual(record.parameters["oversample"], "1")
        self.assertEqual(len(record.sequences), 10)
        self.assertEqual(record.sequences[0], "SEQ1; M: CTCAATCGTAGA at 52")
        self.assertEqual(record.sequences[1], "SEQ2; M: CTCAATCGTAGA at 172")
        self.assertEqual(record.sequences[2], "SEQ3; M: CTCAATCGTAGA at 112")
        self.assertEqual(record.sequences[3], "SEQ4; M: CTCAATCGTAGA at 173")
        self.assertEqual(record.sequences[4], "SEQ5; M: CTCAATCGTAGA at 185")
        self.assertEqual(record.sequences[5], "SEQ6; M: CTCAATCGTAGA at 105")
        self.assertEqual(record.sequences[6], "SEQ7; M: CTCAATCGTAGA at 177")
        self.assertEqual(record.sequences[7], "SEQ8; M: CTCAATCGTAGA at 172")
        self.assertEqual(record.sequences[8], "SEQ9; M: CTCAATCGTAGA at 93")
        self.assertEqual(record.sequences[9], "SEQ10; M: CTCAATCGTAGA at 3")
        self.assertEqual(len(record), 16)
        self.assertEqual(record[0].alphabet, "ACGT")
        self.assertEqual(len(record[0].instances), 11)
        self.assertEqual(str(record[0].instances[0]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[1]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[2]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[3]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[4]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[5]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[6]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[7]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[8]), "TCTACGATTGAG")
        self.assertEqual(str(record[0].instances[9]), "TCAAAGATAGAG")
        self.assertEqual(str(record[0].instances[10]), "TCTACGATTGAG")
        self.assertEqual(record[0].mask, (1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1))
        self.assertAlmostEqual(record[0].score, 57.9079)
        self.assertEqual(record[1].alphabet, "ACGT")
        self.assertEqual(len(record[1].instances), 22)
        self.assertEqual(str(record[1].instances[0]), "GCGAAGGAAGCAGCGCGTGTG")
        self.assertEqual(str(record[1].instances[1]), "GGCACCGCCTCTACGATTGAG")
        self.assertEqual(str(record[1].instances[2]), "CAGAGCTTAGCATTGAACGCG")
        self.assertEqual(str(record[1].instances[3]), "CTAATGAAAGCAATGAGAGTG")
        self.assertEqual(str(record[1].instances[4]), "CTTGTGCCCTCTAAGCGTCCG")
        self.assertEqual(str(record[1].instances[5]), "GAGCACGACGCTTTGTACCTG")
        self.assertEqual(str(record[1].instances[6]), "CGGCACTTAGCAGCGTATCGT")
        self.assertEqual(str(record[1].instances[7]), "CTGGTTTCATCTACGATTGAG")
        self.assertEqual(str(record[1].instances[8]), "GGGCCAATAGCGGCGCCGGAG")
        self.assertEqual(str(record[1].instances[9]), "GTGGAGTTATCTTAGTGCGCG")
        self.assertEqual(str(record[1].instances[10]), "GAGAGGTTATCTACGATTGAG")
        self.assertEqual(str(record[1].instances[11]), "CTGCTCCCCGCATACAGCGCG")
        self.assertEqual(str(record[1].instances[12]), "CAGAACCGAGGTCCGGTACGG")
        self.assertEqual(str(record[1].instances[13]), "GTGCCCCAAGCTTACCCAGGG")
        self.assertEqual(str(record[1].instances[14]), "CGCCTCTGATCTACGATTGAG")
        self.assertEqual(str(record[1].instances[15]), "GTGCTCATAGGGACGTCGCGG")
        self.assertEqual(str(record[1].instances[16]), "CTGCCCCCCGCATAGTAGGGG")
        self.assertEqual(str(record[1].instances[17]), "GTAAAGAAATCGATGTGCCAG")
        self.assertEqual(str(record[1].instances[18]), "CACCTGCAATTGCTGGCAGCG")
        self.assertEqual(str(record[1].instances[19]), "GGCGGGCCATCCCTGTATGAA")
        self.assertEqual(str(record[1].instances[20]), "CTCCAGGTCGCATGGAGAGAG")
        self.assertEqual(str(record[1].instances[21]), "CCTCGGATCGCTTGGGAAGAG")
        self.assertEqual(
            record[1].mask,
            (1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1),
        )
        self.assertAlmostEqual(record[1].score, 19.6235)

        self.assertEqual(record[2].alphabet, "ACGT")
        self.assertEqual(len(record[2].instances), 18)
        self.assertEqual(str(record[2].instances[0]), "GTGCGCGAAGGAAGCAGCGCG")
        self.assertEqual(str(record[2].instances[1]), "CAGAGCTTAGCATTGAACGCG")
        self.assertEqual(str(record[2].instances[2]), "GTGCCCGATGACCACCCGTCG")
        self.assertEqual(str(record[2].instances[3]), "GCCCTCTAAGCGTCCGCGGAT")
        self.assertEqual(str(record[2].instances[4]), "GAGCACGACGCTTTGTACCTG")
        self.assertEqual(str(record[2].instances[5]), "CGGCACTTAGCAGCGTATCGT")
        self.assertEqual(str(record[2].instances[6]), "GGGCCAATAGCGGCGCCGGAG")
        self.assertEqual(str(record[2].instances[7]), "GCGCACTAAGATAACTCCACG")
        self.assertEqual(str(record[2].instances[8]), "CGGCCCGTTGTCCAGCAGACG")
        self.assertEqual(str(record[2].instances[9]), "CTGCTCCCCGCATACAGCGCG")
        self.assertEqual(str(record[2].instances[10]), "GTGCCCCAAGCTTACCCAGGG")
        self.assertEqual(str(record[2].instances[11]), "GTGCTCATAGGGACGTCGCGG")
        self.assertEqual(str(record[2].instances[12]), "CTGCCCCCCGCATAGTAGGGG")
        self.assertEqual(str(record[2].instances[13]), "CGCCGCCATGCGACGCAGAGG")
        self.assertEqual(str(record[2].instances[14]), "AACCTCTAAGCATACTCTACG")
        self.assertEqual(str(record[2].instances[15]), "GACCTGGAGGCTTAGACTTGG")
        self.assertEqual(str(record[2].instances[16]), "GCGCTCTTCCCAAGCGATCCG")
        self.assertEqual(str(record[2].instances[17]), "GGGCCGTCAGCTCTCAAGTCT")
        self.assertEqual(
            record[2].mask,
            (1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1),
        )
        self.assertAlmostEqual(record[2].score, 19.1804)

        self.assertEqual(record[3].alphabet, "ACGT")
        self.assertEqual(len(record[3].instances), 16)
        self.assertEqual(str(record[3].instances[0]), "GCCCCAAGCTTACCCAGGGAC")
        self.assertEqual(str(record[3].instances[1]), "GCCGTCTGCTGGACAACGGGC")
        self.assertEqual(str(record[3].instances[2]), "GCCGACGGGTGGTCATCGGGC")
        self.assertEqual(str(record[3].instances[3]), "GCCAATAGCGGCGCCGGAGTC")
        self.assertEqual(str(record[3].instances[4]), "GCCCCCCGCATAGTAGGGGGA")
        self.assertEqual(str(record[3].instances[5]), "GCCCGTACCGGACCTCGGTTC")
        self.assertEqual(str(record[3].instances[6]), "GCCTCATGTACCGGAAGGGAC")
        self.assertEqual(str(record[3].instances[7]), "GACACGCGCCTGGGAGGGTTC")
        self.assertEqual(str(record[3].instances[8]), "GCCTTTGGCCTTGGATGAGAA")
        self.assertEqual(str(record[3].instances[9]), "GGCCCTCGGATCGCTTGGGAA")
        self.assertEqual(str(record[3].instances[10]), "GCATGTTGGGAATCCGCGGAC")
        self.assertEqual(str(record[3].instances[11]), "GACACGCGCTGTATGCGGGGA")
        self.assertEqual(str(record[3].instances[12]), "GCCAGGTACAAAGCGTCGTGC")
        self.assertEqual(str(record[3].instances[13]), "GCGATCAGCTTGTGGGCGTGC")
        self.assertEqual(str(record[3].instances[14]), "GACAAATCGGATACTGGGGCA")
        self.assertEqual(str(record[3].instances[15]), "GCACTTAGCAGCGTATCGTTA")
        self.assertEqual(
            record[3].mask,
            (1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1),
        )
        self.assertAlmostEqual(record[3].score, 18.0097)
        self.assertEqual(record[4].alphabet, "ACGT")
        self.assertEqual(len(record[4].instances), 15)
        self.assertEqual(str(record[4].instances[0]), "CGGCACAGAGCTT")
        self.assertEqual(str(record[4].instances[1]), "ATCCGCGGACGCT")
        self.assertEqual(str(record[4].instances[2]), "CGCCTGGGAGGGT")
        self.assertEqual(str(record[4].instances[3]), "CGGAAGGGACGTT")
        self.assertEqual(str(record[4].instances[4]), "ACACACAGACGGT")
        self.assertEqual(str(record[4].instances[5]), "TGCCAGAGAGGTT")
        self.assertEqual(str(record[4].instances[6]), "AGACTGAGACGTT")
        self.assertEqual(str(record[4].instances[7]), "AATCGTAGAGGAT")
        self.assertEqual(str(record[4].instances[8]), "CGTCTCGTAGGGT")
        self.assertEqual(str(record[4].instances[9]), "CGTCGCGGAGGAT")
        self.assertEqual(str(record[4].instances[10]), "CTTCTTAGACGCT")
        self.assertEqual(str(record[4].instances[11]), "CGACGCAGAGGAT")
        self.assertEqual(str(record[4].instances[12]), "ATGCTTAGAGGTT")
        self.assertEqual(str(record[4].instances[13]), "AGACTTGGGCGAT")
        self.assertEqual(str(record[4].instances[14]), "CGACCTGGAGGCT")
        self.assertEqual(record[4].mask, (1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1))
        self.assertAlmostEqual(record[4].score, 16.8287)
        self.assertEqual(record[5].alphabet, "ACGT")
        self.assertEqual(len(record[5].instances), 18)
        self.assertEqual(str(record[5].instances[0]), "GTGCGCGAAGGAAGCAGCGCGTG")
        self.assertEqual(str(record[5].instances[1]), "TTGAGCCGAGTAAAGGGCTGGTG")
        self.assertEqual(str(record[5].instances[2]), "CAATGCTAAGCTCTGTGCCGACG")
        self.assertEqual(str(record[5].instances[3]), "CAACTCTCTATGTAGTGCCCGAG")
        self.assertEqual(str(record[5].instances[4]), "CGACGCTTTGTACCTGGCTTGCG")
        self.assertEqual(str(record[5].instances[5]), "CGAGTCAATGACACGCGCCTGGG")
        self.assertEqual(str(record[5].instances[6]), "CGATACGCTGCTAAGTGCCGTCC")
        self.assertEqual(str(record[5].instances[7]), "CCGGGCCAATAGCGGCGCCGGAG")
        self.assertEqual(str(record[5].instances[8]), "CCACGCTTCGACACGTGGTATAG")
        self.assertEqual(str(record[5].instances[9]), "CCGAGCCTCATGTACCGGAAGGG")
        self.assertEqual(str(record[5].instances[10]), "CTGCTCCCCGCATACAGCGCGTG")
        self.assertEqual(str(record[5].instances[11]), "CCGAGGTCCGGTACGGGCAAGCC")
        self.assertEqual(str(record[5].instances[12]), "GTGCTCATAGGGACGTCGCGGAG")
        self.assertEqual(str(record[5].instances[13]), "CCCTACTATGCGGGGGGCAGGTC")
        self.assertEqual(str(record[5].instances[14]), "GCCAGCAATTGCAGGTGGTCGTG")
        self.assertEqual(str(record[5].instances[15]), "CTCTGCGTCGCATGGCGGCGTGG")
        self.assertEqual(str(record[5].instances[16]), "GGAGGCTTAGACTTGGGCGATAC")
        self.assertEqual(str(record[5].instances[17]), "GCATGGAGAGAGATCCGGAGGAG")
        self.assertEqual(
            record[5].mask,
            (1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1),
        )
        self.assertAlmostEqual(record[5].score, 15.0441)
        self.assertEqual(record[6].alphabet, "ACGT")
        self.assertEqual(len(record[6].instances), 20)
        self.assertEqual(str(record[6].instances[0]), "GCGCGTGTGTGTAAC")
        self.assertEqual(str(record[6].instances[1]), "GCACAGAGCTTAGCA")
        self.assertEqual(str(record[6].instances[2]), "GGTGGTCATCGGGCA")
        self.assertEqual(str(record[6].instances[3]), "GCGCGTGTCATTGAC")
        self.assertEqual(str(record[6].instances[4]), "GGACGGCACTTAGCA")
        self.assertEqual(str(record[6].instances[5]), "GCGCGTCCCGGGCCA")
        self.assertEqual(str(record[6].instances[6]), "GCTCGGCCCGTTGTC")
        self.assertEqual(str(record[6].instances[7]), "GCGCGTGTCCTTTAA")
        self.assertEqual(str(record[6].instances[8]), "GCTGATCGCTGCTCC")
        self.assertEqual(str(record[6].instances[9]), "GCCCGTACCGGACCT")
        self.assertEqual(str(record[6].instances[10]), "GGACGTCGCGGAGGA")
        self.assertEqual(str(record[6].instances[11]), "GCGGGGGGCAGGTCA")
        self.assertEqual(str(record[6].instances[12]), "GGACGTACTGGCACA")
        self.assertEqual(str(record[6].instances[13]), "GCAGGTGGTCGTGCA")
        self.assertEqual(str(record[6].instances[14]), "GCGCATACCTTAACA")
        self.assertEqual(str(record[6].instances[15]), "GCACGGGACTTCAAC")
        self.assertEqual(str(record[6].instances[16]), "GCACGTAGCTGGTAA")
        self.assertEqual(str(record[6].instances[17]), "GCTCGTCTATGGTCA")
        self.assertEqual(str(record[6].instances[18]), "GCGCATGCTGGATCC")
        self.assertEqual(str(record[6].instances[19]), "GGCCGTCAGCTCTCA")
        self.assertEqual(record[6].mask, (1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1))
        self.assertAlmostEqual(record[6].score, 13.3145)
        self.assertEqual(record[7].alphabet, "ACGT")
        self.assertEqual(len(record[7].instances), 20)
        self.assertEqual(str(record[7].instances[0]), "GAACCGAGGTCCGGTACGGGC")
        self.assertEqual(str(record[7].instances[1]), "GCCCCCCGCATAGTAGGGGGA")
        self.assertEqual(str(record[7].instances[2]), "GTCCCTGGGTAAGCTTGGGGC")
        self.assertEqual(str(record[7].instances[3]), "ACTCCACGCTTCGACACGTGG")
        self.assertEqual(str(record[7].instances[4]), "ATCCTCTGCGTCGCATGGCGG")
        self.assertEqual(str(record[7].instances[5]), "GTTCAATGCTAAGCTCTGTGC")
        self.assertEqual(str(record[7].instances[6]), "GCTCATAGGGACGTCGCGGAG")
        self.assertEqual(str(record[7].instances[7]), "GTCCCGGGCCAATAGCGGCGC")
        self.assertEqual(str(record[7].instances[8]), "GCACTTAGCAGCGTATCGTTA")
        self.assertEqual(str(record[7].instances[9]), "GGCCCTCGGATCGCTTGGGAA")
        self.assertEqual(str(record[7].instances[10]), "CTGCTGGACAACGGGCCGAGC")
        self.assertEqual(str(record[7].instances[11]), "GGGCACTACATAGAGAGTTGC")
        self.assertEqual(str(record[7].instances[12]), "AGCCTCCAGGTCGCATGGAGA")
        self.assertEqual(str(record[7].instances[13]), "AATCGTAGATCAGAGGCGAGA")
        self.assertEqual(str(record[7].instances[14]), "GAACTCCACTAAGACTTGAGA")
        self.assertEqual(str(record[7].instances[15]), "GAGCAGCGATCAGCTTGTGGG")
        self.assertEqual(str(record[7].instances[16]), "GCCAGGTACAAAGCGTCGTGC")
        self.assertEqual(str(record[7].instances[17]), "AGTCAATGACACGCGCCTGGG")
        self.assertEqual(str(record[7].instances[18]), "GGTCATGGAATCTTATGTAGC")
        self.assertEqual(str(record[7].instances[19]), "GTAGATAACAGAGGTCGGGGG")
        self.assertEqual(
            record[7].mask,
            (1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1),
        )
        self.assertAlmostEqual(record[7].score, 11.6098)
        self.assertEqual(record[8].alphabet, "ACGT")
        self.assertEqual(len(record[8].instances), 14)
        self.assertEqual(str(record[8].instances[0]), "CCGAGTAAAGGGCTG")
        self.assertEqual(str(record[8].instances[1]), "GTGGTCATCGGGCAC")
        self.assertEqual(str(record[8].instances[2]), "GATAACAGAGGTCGG")
        self.assertEqual(str(record[8].instances[3]), "CGGCGCCGGAGTCTG")
        self.assertEqual(str(record[8].instances[4]), "GCGCGTCCCGGGCCA")
        self.assertEqual(str(record[8].instances[5]), "CTGGACAACGGGCCG")
        self.assertEqual(str(record[8].instances[6]), "CGGATACTGGGGCAG")
        self.assertEqual(str(record[8].instances[7]), "GGGAGCAGCGATCAG")
        self.assertEqual(str(record[8].instances[8]), "CAGAACCGAGGTCCG")
        self.assertEqual(str(record[8].instances[9]), "GGGTCCCTGGGTAAG")
        self.assertEqual(str(record[8].instances[10]), "GTGCTCATAGGGACG")
        self.assertEqual(str(record[8].instances[11]), "GAGATCCGGAGGAGG")
        self.assertEqual(str(record[8].instances[12]), "GCGATCCGAGGGCCG")
        self.assertEqual(str(record[8].instances[13]), "GAGTTCACATGGCTG")
        self.assertEqual(record[8].mask, (1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1))
        self.assertAlmostEqual(record[8].score, 11.2943)
        self.assertEqual(record[9].alphabet, "ACGT")
        self.assertEqual(len(record[9].instances), 18)
        self.assertEqual(str(record[9].instances[0]), "TAGAGGCGGTG")
        self.assertEqual(str(record[9].instances[1]), "GCTAAGCTCTG")
        self.assertEqual(str(record[9].instances[2]), "TGGAAGCAGTG")
        self.assertEqual(str(record[9].instances[3]), "GCGAGGCTGTG")
        self.assertEqual(str(record[9].instances[4]), "ACGACGCTTTG")
        self.assertEqual(str(record[9].instances[5]), "GGGACGCGCAC")
        self.assertEqual(str(record[9].instances[6]), "TCGAAGCGTGG")
        self.assertEqual(str(record[9].instances[7]), "TGTATGCGGGG")
        self.assertEqual(str(record[9].instances[8]), "GGTAAGCTTGG")
        self.assertEqual(str(record[9].instances[9]), "TGTACGCTGGG")
        self.assertEqual(str(record[9].instances[10]), "ACTATGCGGGG")
        self.assertEqual(str(record[9].instances[11]), "GGTATGCGCTG")
        self.assertEqual(str(record[9].instances[12]), "GGTACCCGGAG")
        self.assertEqual(str(record[9].instances[13]), "GCGACGCAGAG")
        self.assertEqual(str(record[9].instances[14]), "TGGCGGCGTGG")
        self.assertEqual(str(record[9].instances[15]), "TCTAGGCGGGC")
        self.assertEqual(str(record[9].instances[16]), "AGTATGCTTAG")
        self.assertEqual(str(record[9].instances[17]), "TGGAGGCTTAG")
        self.assertEqual(record[9].mask, (1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1))
        self.assertAlmostEqual(record[9].score, 9.7924)
        self.assertEqual(record[10].alphabet, "ACGT")
        self.assertEqual(len(record[10].instances), 13)
        self.assertEqual(str(record[10].instances[0]), "GCACAGAGCTTAGCATTGAAC")
        self.assertEqual(str(record[10].instances[1]), "GTCCGCGGATTCCCAACATGC")
        self.assertEqual(str(record[10].instances[2]), "ATACACAGCCTCGCAAGCCAG")
        self.assertEqual(str(record[10].instances[3]), "GGCCCGGGACGCGCACTAAGA")
        self.assertEqual(str(record[10].instances[4]), "GCCCGTTGTCCAGCAGACGGC")
        self.assertEqual(str(record[10].instances[5]), "GAGCAGCGATCAGCTTGTGGG")
        self.assertEqual(str(record[10].instances[6]), "GAACCGAGGTCCGGTACGGGC")
        self.assertEqual(str(record[10].instances[7]), "GTCCCTGGGTAAGCTTGGGGC")
        self.assertEqual(str(record[10].instances[8]), "GACCTGCCCCCCGCATAGTAG")
        self.assertEqual(str(record[10].instances[9]), "AACCAGCGCATACCTTAACAG")
        self.assertEqual(str(record[10].instances[10]), "ATCCTCTGCGTCGCATGGCGG")
        self.assertEqual(str(record[10].instances[11]), "GACCATAGACGAGCATCAAAG")
        self.assertEqual(str(record[10].instances[12]), "GGCCCTCGGATCGCTTGGGAA")
        self.assertEqual(
            record[10].mask,
            (1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1),
        )
        self.assertAlmostEqual(record[10].score, 9.01393)
        self.assertEqual(record[11].alphabet, "ACGT")
        self.assertEqual(len(record[11].instances), 16)
        self.assertEqual(str(record[11].instances[0]), "GCCGTCCGTC")
        self.assertEqual(str(record[11].instances[1]), "GGCGTGCGCG")
        self.assertEqual(str(record[11].instances[2]), "GGCGCGTGTC")
        self.assertEqual(str(record[11].instances[3]), "AGCGCGTGTG")
        self.assertEqual(str(record[11].instances[4]), "GCGGTGCGTG")
        self.assertEqual(str(record[11].instances[5]), "AGCGCGTGTC")
        self.assertEqual(str(record[11].instances[6]), "AGCGTCCGCG")
        self.assertEqual(str(record[11].instances[7]), "ACCGTCTGTG")
        self.assertEqual(str(record[11].instances[8]), "GCCATGCGAC")
        self.assertEqual(str(record[11].instances[9]), "ACCACCCGTC")
        self.assertEqual(str(record[11].instances[10]), "GGCGCCGGAG")
        self.assertEqual(str(record[11].instances[11]), "ACCACGTGTC")
        self.assertEqual(str(record[11].instances[12]), "GGCTTGCGAG")
        self.assertEqual(str(record[11].instances[13]), "GCGATCCGAG")
        self.assertEqual(str(record[11].instances[14]), "AGTGCGCGTC")
        self.assertEqual(str(record[11].instances[15]), "AGTGCCCGAG")
        self.assertEqual(record[11].mask, (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
        self.assertAlmostEqual(record[11].score, 7.51121)
        self.assertEqual(record[12].alphabet, "ACGT")
        self.assertEqual(len(record[12].instances), 16)
        self.assertEqual(str(record[12].instances[0]), "GCCGACGGGTGGTCATCGGG")
        self.assertEqual(str(record[12].instances[1]), "GCACGACGCTTTGTACCTGG")
        self.assertEqual(str(record[12].instances[2]), "CCTGGGAGGGTTCAATAACG")
        self.assertEqual(str(record[12].instances[3]), "GCGCGTCCCGGGCCAATAGC")
        self.assertEqual(str(record[12].instances[4]), "GCCGTCTGCTGGACAACGGG")
        self.assertEqual(str(record[12].instances[5]), "GTCCCTTCCGGTACATGAGG")
        self.assertEqual(str(record[12].instances[6]), "GCTGCTCCCCGCATACAGCG")
        self.assertEqual(str(record[12].instances[7]), "GCCCCAAGCTTACCCAGGGA")
        self.assertEqual(str(record[12].instances[8]), "ACCGGCTGACGCTAATACGG")
        self.assertEqual(str(record[12].instances[9]), "GCGGGGGGCAGGTCATTACA")
        self.assertEqual(str(record[12].instances[10]), "GCTGGCAGCGTCTAAGAAGG")
        self.assertEqual(str(record[12].instances[11]), "GCAGGTGGTCGTGCAATACG")
        self.assertEqual(str(record[12].instances[12]), "GCTGGTTGAAGTCCCGTGCG")
        self.assertEqual(str(record[12].instances[13]), "GCACGTAGCTGGTAAATAGG")
        self.assertEqual(str(record[12].instances[14]), "GCGGCGTGGATTTCATACAG")
        self.assertEqual(str(record[12].instances[15]), "CCTGGAGGCTTAGACTTGGG")
        self.assertEqual(
            record[12].mask,
            (1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1),
        )
        self.assertAlmostEqual(record[12].score, 5.63667)
        self.assertEqual(record[13].alphabet, "ACGT")
        self.assertEqual(len(record[13].instances), 15)
        self.assertEqual(str(record[13].instances[0]), "GCCGACGGGTGGTCATCGGG")
        self.assertEqual(str(record[13].instances[1]), "ATCCGCGGACGCTTAGAGGG")
        self.assertEqual(str(record[13].instances[2]), "ACGCTTTGTACCTGGCTTGC")
        self.assertEqual(str(record[13].instances[3]), "ACGGACGGCACTTAGCAGCG")
        self.assertEqual(str(record[13].instances[4]), "GCCGTCTGCTGGACAACGGG")
        self.assertEqual(str(record[13].instances[5]), "ACACACAGACGGTTGAAAGG")
        self.assertEqual(str(record[13].instances[6]), "GCCGATAGTGCTTAAGTTCG")
        self.assertEqual(str(record[13].instances[7]), "CTTGCCCGTACCGGACCTCG")
        self.assertEqual(str(record[13].instances[8]), "ACCGGCTGACGCTAATACGG")
        self.assertEqual(str(record[13].instances[9]), "GCCCCCCGCATAGTAGGGGG")
        self.assertEqual(str(record[13].instances[10]), "GCTGGCAGCGTCTAAGAAGG")
        self.assertEqual(str(record[13].instances[11]), "GCAGGTGGTCGTGCAATACG")
        self.assertEqual(str(record[13].instances[12]), "ACGCACGGGACTTCAACCAG")
        self.assertEqual(str(record[13].instances[13]), "GCACGTAGCTGGTAAATAGG")
        self.assertEqual(str(record[13].instances[14]), "ATCCTCTGCGTCGCATGGCG")
        self.assertEqual(
            record[13].mask,
            (1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1),
        )
        self.assertAlmostEqual(record[13].score, 3.89842)
        self.assertEqual(record[14].alphabet, "ACGT")
        self.assertEqual(len(record[14].instances), 14)
        self.assertEqual(str(record[14].instances[0]), "GAGGCTGTGTAT")
        self.assertEqual(str(record[14].instances[1]), "GAGGTCGGGGGT")
        self.assertEqual(str(record[14].instances[2]), "GACGGACGGCAC")
        self.assertEqual(str(record[14].instances[3]), "TTGGCCCGGGAC")
        self.assertEqual(str(record[14].instances[4]), "GAGGCTCGGCCC")
        self.assertEqual(str(record[14].instances[5]), "CACGCGCTGTAT")
        self.assertEqual(str(record[14].instances[6]), "TAGGCCAGGTAT")
        self.assertEqual(str(record[14].instances[7]), "GAGGTCCGGTAC")
        self.assertEqual(str(record[14].instances[8]), "TACGCTGGGGAT")
        self.assertEqual(str(record[14].instances[9]), "GTCGCGGAGGAT")
        self.assertEqual(str(record[14].instances[10]), "TACGCACGGGAC")
        self.assertEqual(str(record[14].instances[11]), "TACTCCGGGTAC")
        self.assertEqual(str(record[14].instances[12]), "GACGCAGAGGAT")
        self.assertEqual(str(record[14].instances[13]), "TAGGCGGGCCAT")
        self.assertEqual(record[14].mask, (1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1))
        self.assertAlmostEqual(record[14].score, 3.33444)
        self.assertEqual(record[15].alphabet, "ACGT")
        self.assertEqual(len(record[15].instances), 21)
        self.assertEqual(str(record[15].instances[0]), "CGGCTCAATCGTAGAGGC")
        self.assertEqual(str(record[15].instances[1]), "CGACGGGTGGTCATCGGG")
        self.assertEqual(str(record[15].instances[2]), "CGCTTAGAGGGCACAAGC")
        self.assertEqual(str(record[15].instances[3]), "TGACACGCGCCTGGGAGG")
        self.assertEqual(str(record[15].instances[4]), "CGATACGCTGCTAAGTGC")
        self.assertEqual(str(record[15].instances[5]), "CGTCCCGGGCCAATAGCG")
        self.assertEqual(str(record[15].instances[6]), "CCACGCTTCGACACGTGG")
        self.assertEqual(str(record[15].instances[7]), "CGTCTGCTGGACAACGGG")
        self.assertEqual(str(record[15].instances[8]), "ACACAGACGGTTGAAAGG")
        self.assertEqual(str(record[15].instances[9]), "TGCTCCCCGCATACAGCG")
        self.assertEqual(str(record[15].instances[10]), "TGAGGCTTGCCCGTACCG")
        self.assertEqual(str(record[15].instances[11]), "TGCCCCAAGCTTACCCAG")
        self.assertEqual(str(record[15].instances[12]), "CGGCTGACGCTAATACGG")
        self.assertEqual(str(record[15].instances[13]), "CGCGACGTCCCTATGAGC")
        self.assertEqual(str(record[15].instances[14]), "TGCCCCCCGCATAGTAGG")
        self.assertEqual(str(record[15].instances[15]), "CGTTGCCTTCTTAGACGC")
        self.assertEqual(str(record[15].instances[16]), "TGACTCAATCGTAGACCC")
        self.assertEqual(str(record[15].instances[17]), "AGTCCCGTGCGTATGTGG")
        self.assertEqual(str(record[15].instances[18]), "AGGCTCGCACGTAGCTGG")
        self.assertEqual(str(record[15].instances[19]), "CCACGCCGCCATGCGACG")
        self.assertEqual(str(record[15].instances[20]), "AGCCTCCAGGTCGCATGG")
        self.assertEqual(
            record[15].mask, (1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1)
        )
        self.assertAlmostEqual(record[15].score, 1.0395)

    def test_clusterbuster_parsing_and_output(self):
        """Test if Bio.motifs can parse and output Cluster Buster PFM files."""
        record = motifs.parse(self.CLUSTERBUSTERin, "clusterbuster")
        self.assertEqual(len(record), 3)
        self.assertEqual(record[0].name, "MA0004.1")
        self.assertEqual(record[1].name, "MA0006.1")
        self.assertEqual(record[2].name, "MA0008.1")
        self.assertEqual(record[0].degenerate_consensus, "CACGTG")
        self.assertEqual(record[1].degenerate_consensus, "YGCGTG")
        self.assertEqual(record[2].degenerate_consensus, "CAATTATT")

        self.CLUSTERBUSTERin.seek(0)
        self.assertEqual(
            motifs.write(record, "clusterbuster").split(),
            self.CLUSTERBUSTERin.read().split(),
        )

    def test_xms_parsing(self):
        """Test if Bio.motifs can parse and output xms PFM files."""
        record = motifs.parse(self.XMSin, "xms")
        self.assertEqual(len(record), 1)
        self.assertEqual(record[0].name, "Abd-B")
        self.assertEqual(record[0].length, 14)

    def test_pfm_parsing(self):
        """Test if Bio.motifs can parse JASPAR-style pfm files."""
        m = motifs.read(self.PFMin, "pfm")
        self.assertEqual(m.length, 12)

    def test_sites_parsing(self):
        """Test if Bio.motifs can parse JASPAR-style sites files."""
        m = motifs.read(self.SITESin, "sites")
        self.assertEqual(m.length, 6)

    def test_TFoutput(self):
        """Ensure that we can write proper TransFac output files."""
        with open(self.TFout, "w") as output_handle:
            output_handle.write(format(self.m, "transfac"))

    def test_format(self):
        self.m.name = "Foo"
        s1 = format(self.m, "pfm")
        expected_pfm = """  1.00   0.00   1.00   0.00  1.00
  0.00   0.00   0.00   0.00  0.00
  0.00   0.00   0.00   0.00  0.00
  0.00   1.00   0.00   1.00  0.00
"""
        s2 = format(self.m, "jaspar")
        expected_jaspar = """>None Foo
A [  1.00   0.00   1.00   0.00   1.00]
C [  0.00   0.00   0.00   0.00   0.00]
G [  0.00   0.00   0.00   0.00   0.00]
T [  0.00   1.00   0.00   1.00   0.00]
"""
        self.assertEqual(s2, expected_jaspar)
        s3 = format(self.m, "transfac")
        expected_transfac = """P0      A      C      G      T
01      1      0      0      0      A
02      0      0      0      1      T
03      1      0      0      0      A
04      0      0      0      1      T
05      1      0      0      0      A
XX
//
"""
        self.assertEqual(s3, expected_transfac)
        self.assertRaises(ValueError, format, self.m, "foo_bar")

    def test_reverse_complement(self):
        """Test if motifs can be reverse-complemented."""
        background = {"A": 0.3, "C": 0.2, "G": 0.2, "T": 0.3}
        pseudocounts = 0.5
        m = self.m
        m.background = background
        m.pseudocounts = pseudocounts
        received_forward = format(self.m, "transfac")
        expected_forward = """\
P0      A      C      G      T
01      1      0      0      0      A
02      0      0      0      1      T
03      1      0      0      0      A
04      0      0      0      1      T
05      1      0      0      0      A
XX
//
"""
        self.assertEqual(received_forward, expected_forward)
        expected_forward_pwm = """\
        0      1      2      3      4
A:   0.50   0.17   0.50   0.17   0.50
C:   0.17   0.17   0.17   0.17   0.17
G:   0.17   0.17   0.17   0.17   0.17
T:   0.17   0.50   0.17   0.50   0.17
"""
        self.assertEqual(str(m.pwm), expected_forward_pwm)
        m = m.reverse_complement()
        received_reverse = format(m, "transfac")
        expected_reverse = """\
P0      A      C      G      T
01      0      0      0      1      T
02      1      0      0      0      A
03      0      0      0      1      T
04      1      0      0      0      A
05      0      0      0      1      T
XX
//
"""
        self.assertEqual(received_reverse, expected_reverse)
        expected_reverse_pwm = """\
        0      1      2      3      4
A:   0.17   0.50   0.17   0.50   0.17
C:   0.17   0.17   0.17   0.17   0.17
G:   0.17   0.17   0.17   0.17   0.17
T:   0.50   0.17   0.50   0.17   0.50
"""
        self.assertEqual(str(m.pwm), expected_reverse_pwm)
        # Same thing, but now start with a motif calculated from a count matrix
        counts = self.m.counts
        m = motifs.Motif(counts=counts)
        m.background = background
        m.pseudocounts = pseudocounts
        received_forward = format(m, "transfac")
        self.assertEqual(received_forward, expected_forward)
        self.assertEqual(str(m.pwm), expected_forward_pwm)
        m = m.reverse_complement()
        received_reverse = format(m, "transfac")
        self.assertEqual(received_reverse, expected_reverse)
        self.assertEqual(str(m.pwm), expected_reverse_pwm)


class TestMEME(unittest.TestCase):
    def test_meme_parser_1(self):
        """Parse motifs/meme.INO_up800.classic.oops.xml file."""
        with open("motifs/meme.INO_up800.classic.oops.xml") as handle:
            record = motifs.parse(handle, "meme")
        self.assertEqual(record.version, "5.0.1")
        self.assertEqual(record.datafile, "common/INO_up800.s")
        self.assertEqual(record.alphabet, "ACGT")
        self.assertEqual(len(record.sequences), 7)
        self.assertEqual(record.sequences[0], "sequence_0")
        self.assertEqual(record.sequences[1], "sequence_1")
        self.assertEqual(record.sequences[2], "sequence_2")
        self.assertEqual(record.sequences[3], "sequence_3")
        self.assertEqual(record.sequences[4], "sequence_4")
        self.assertEqual(record.sequences[5], "sequence_5")
        self.assertEqual(record.sequences[6], "sequence_6")
        self.assertEqual(
            record.command,
            "meme common/INO_up800.s -oc results/meme10 -mod oops -dna -revcomp -bfile common/yeast.nc.6.freq -nmotifs 2 -objfun classic -minw 8 -nostatus ",
        )
        self.assertEqual(len(record), 2)
        motif = record[0]
        self.assertEqual(motif.name, "GSKGCATGTGAAA")
        self.assertEqual(record["GSKGCATGTGAAA"], motif)
        self.assertEqual(motif.num_occurrences, 7)
        self.assertAlmostEqual(motif.evalue, 0.19)
        self.assertEqual(motif.alphabet, "ACGT")
        self.assertEqual(len(motif.instances), 7)
        self.assertAlmostEqual(motif.instances[0].pvalue, 1.21e-08)
        self.assertAlmostEqual(motif.instances[1].pvalue, 1.87e-08)
        self.assertAlmostEqual(motif.instances[2].pvalue, 6.62e-08)
        self.assertAlmostEqual(motif.instances[3].pvalue, 1.05e-07)
        self.assertAlmostEqual(motif.instances[4].pvalue, 1.69e-07)
        self.assertAlmostEqual(motif.instances[5].pvalue, 5.62e-07)
        self.assertAlmostEqual(motif.instances[6].pvalue, 1.08e-06)
        self.assertEqual(motif.instances[0].sequence_name, "INO1")
        self.assertEqual(motif.instances[1].sequence_name, "FAS1")
        self.assertEqual(motif.instances[2].sequence_name, "ACC1")
        self.assertEqual(motif.instances[3].sequence_name, "CHO2")
        self.assertEqual(motif.instances[4].sequence_name, "CHO1")
        self.assertEqual(motif.instances[5].sequence_name, "FAS2")
        self.assertEqual(motif.instances[6].sequence_name, "OPI3")
        self.assertEqual(motif.instances[0].sequence_id, "sequence_5")
        self.assertEqual(motif.instances[1].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[2].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[3].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[4].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[5].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[6].sequence_id, "sequence_6")
        self.assertEqual(motif.instances[0].strand, "+")
        self.assertEqual(motif.instances[1].strand, "-")
        self.assertEqual(motif.instances[2].strand, "-")
        self.assertEqual(motif.instances[3].strand, "-")
        self.assertEqual(motif.instances[4].strand, "-")
        self.assertEqual(motif.instances[5].strand, "-")
        self.assertEqual(motif.instances[6].strand, "+")
        self.assertEqual(motif.instances[0].length, 13)
        self.assertEqual(motif.instances[1].length, 13)
        self.assertEqual(motif.instances[2].length, 13)
        self.assertEqual(motif.instances[3].length, 13)
        self.assertEqual(motif.instances[4].length, 13)
        self.assertEqual(motif.instances[5].length, 13)
        self.assertEqual(motif.instances[6].length, 13)
        self.assertEqual(motif.instances[0].start, 620)
        self.assertEqual(motif.instances[1].start, 94)
        self.assertEqual(motif.instances[2].start, 82)
        self.assertEqual(motif.instances[3].start, 353)
        self.assertEqual(motif.instances[4].start, 639)
        self.assertEqual(motif.instances[5].start, 566)
        self.assertEqual(motif.instances[6].start, 585)
        self.assertEqual(str(motif.instances[0]), "GCGGCATGTGAAA")
        self.assertEqual(str(motif.instances[1]), "GCGGCATGTGAAG")
        self.assertEqual(str(motif.instances[2]), "GGGCCATGTGAAG")
        self.assertEqual(str(motif.instances[3]), "GCGGCATGAGAAA")
        self.assertEqual(str(motif.instances[4]), "GGTCCATGTGAAA")
        self.assertEqual(str(motif.instances[5]), "GTAGCATGTGAAA")
        self.assertEqual(str(motif.instances[6]), "AGTGCATGTGGAA")
        motif = record[1]
        self.assertEqual(motif.name, "TTGACWCYTGCYCWG")
        self.assertEqual(record["TTGACWCYTGCYCWG"], motif)
        self.assertEqual(motif.num_occurrences, 7)
        self.assertAlmostEqual(motif.evalue, 54)
        self.assertEqual(motif.alphabet, "ACGT")
        self.assertEqual(len(motif.instances), 7)
        self.assertAlmostEqual(motif.instances[0].pvalue, 7.2e-10)
        self.assertAlmostEqual(motif.instances[1].pvalue, 2.56e-08)
        self.assertAlmostEqual(motif.instances[2].pvalue, 1.59e-07)
        self.assertAlmostEqual(motif.instances[3].pvalue, 2.05e-07)
        self.assertAlmostEqual(motif.instances[4].pvalue, 3.85e-07)
        self.assertAlmostEqual(motif.instances[5].pvalue, 5.11e-07)
        self.assertAlmostEqual(motif.instances[6].pvalue, 8.01e-07)
        self.assertEqual(motif.instances[0].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[1].sequence_id, "sequence_6")
        self.assertEqual(motif.instances[2].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[3].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[4].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[5].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[6].sequence_id, "sequence_5")
        self.assertEqual(motif.instances[0].strand, "+")
        self.assertEqual(motif.instances[1].strand, "-")
        self.assertEqual(motif.instances[2].strand, "-")
        self.assertEqual(motif.instances[3].strand, "+")
        self.assertEqual(motif.instances[4].strand, "+")
        self.assertEqual(motif.instances[5].strand, "-")
        self.assertEqual(motif.instances[6].strand, "+")
        self.assertEqual(motif.instances[0].length, 15)
        self.assertEqual(motif.instances[1].length, 15)
        self.assertEqual(motif.instances[2].length, 15)
        self.assertEqual(motif.instances[3].length, 15)
        self.assertEqual(motif.instances[4].length, 15)
        self.assertEqual(motif.instances[5].length, 15)
        self.assertEqual(motif.instances[6].length, 15)
        self.assertEqual(motif.instances[0].start, 104)
        self.assertEqual(motif.instances[1].start, 566)
        self.assertEqual(motif.instances[2].start, 585)
        self.assertEqual(motif.instances[3].start, 30)
        self.assertEqual(motif.instances[4].start, 54)
        self.assertEqual(motif.instances[5].start, 272)
        self.assertEqual(motif.instances[6].start, 214)
        self.assertEqual(str(motif.instances[0]), "TTGACACCTGCCCAG")
        self.assertEqual(str(motif.instances[1]), "TTGACACCTACCCTG")
        self.assertEqual(str(motif.instances[2]), "TTGTCTCTTGCTCTG")
        self.assertEqual(str(motif.instances[3]), "TTGACACTTGATCAG")
        self.assertEqual(str(motif.instances[4]), "TTCACTACTCCCCTG")
        self.assertEqual(str(motif.instances[5]), "TTGACAACGGCTGGG")
        self.assertEqual(str(motif.instances[6]), "TTCACGCTTGCTACG")

    def test_meme_parser_2(self):
        """Parsing motifs/meme.adh.classic.oops.xml file."""
        with open("motifs/meme.adh.classic.oops.xml") as handle:
            record = motifs.parse(handle, "meme")
        self.assertEqual(record.version, "5.0.1")
        self.assertEqual(record.datafile, "common/adh.s")
        self.assertEqual(record.alphabet, "ACDEFGHIKLMNPQRSTVWY")
        self.assertEqual(len(record.sequences), 33)
        self.assertEqual(record.sequences[0], "sequence_0")
        self.assertEqual(record.sequences[1], "sequence_1")
        self.assertEqual(record.sequences[2], "sequence_2")
        self.assertEqual(record.sequences[3], "sequence_3")
        self.assertEqual(record.sequences[4], "sequence_4")
        self.assertEqual(record.sequences[5], "sequence_5")
        self.assertEqual(record.sequences[6], "sequence_6")
        self.assertEqual(record.sequences[7], "sequence_7")
        self.assertEqual(record.sequences[8], "sequence_8")
        self.assertEqual(record.sequences[9], "sequence_9")
        self.assertEqual(record.sequences[10], "sequence_10")
        self.assertEqual(record.sequences[11], "sequence_11")
        self.assertEqual(record.sequences[12], "sequence_12")
        self.assertEqual(record.sequences[13], "sequence_13")
        self.assertEqual(record.sequences[14], "sequence_14")
        self.assertEqual(record.sequences[15], "sequence_15")
        self.assertEqual(record.sequences[16], "sequence_16")
        self.assertEqual(record.sequences[17], "sequence_17")
        self.assertEqual(record.sequences[18], "sequence_18")
        self.assertEqual(record.sequences[19], "sequence_19")
        self.assertEqual(record.sequences[20], "sequence_20")
        self.assertEqual(record.sequences[21], "sequence_21")
        self.assertEqual(record.sequences[22], "sequence_22")
        self.assertEqual(record.sequences[23], "sequence_23")
        self.assertEqual(record.sequences[24], "sequence_24")
        self.assertEqual(record.sequences[25], "sequence_25")
        self.assertEqual(record.sequences[26], "sequence_26")
        self.assertEqual(record.sequences[27], "sequence_27")
        self.assertEqual(record.sequences[28], "sequence_28")
        self.assertEqual(record.sequences[29], "sequence_29")
        self.assertEqual(record.sequences[30], "sequence_30")
        self.assertEqual(record.sequences[31], "sequence_31")
        self.assertEqual(record.sequences[32], "sequence_32")
        self.assertEqual(
            record.command,
            "meme common/adh.s -oc results/meme4 -mod oops -protein -nmotifs 2 -objfun classic -minw 8 -nostatus ",
        )
        self.assertEqual(len(record), 2)
        motif = record[0]
        self.assertEqual(motif.id, "motif_1")
        self.assertEqual(motif.name, "GKVALVTGAASGJGKATAKAL")
        self.assertEqual(motif.alt_id, "MEME-1")
        self.assertEqual(record["GKVALVTGAASGJGKATAKAL"], motif)
        self.assertEqual(motif.num_occurrences, 33)
        self.assertAlmostEqual(motif.evalue, 3.6e-165)
        self.assertEqual(motif.alphabet, "ACDEFGHIKLMNPQRSTVWY")
        self.assertEqual(len(motif.instances), 33)
        self.assertAlmostEqual(motif.instances[0].pvalue, 8.78e-18)
        self.assertAlmostEqual(motif.instances[1].pvalue, 1.41e-17)
        self.assertAlmostEqual(motif.instances[2].pvalue, 1.42e-16)
        self.assertAlmostEqual(motif.instances[3].pvalue, 2.75e-16)
        self.assertAlmostEqual(motif.instances[4].pvalue, 3.55e-16)
        self.assertAlmostEqual(motif.instances[5].pvalue, 3.55e-16)
        self.assertAlmostEqual(motif.instances[6].pvalue, 1.74e-15)
        self.assertAlmostEqual(motif.instances[7].pvalue, 3.87e-15)
        self.assertAlmostEqual(motif.instances[8].pvalue, 4.84e-15)
        self.assertAlmostEqual(motif.instances[9].pvalue, 1.04e-14)
        self.assertAlmostEqual(motif.instances[10].pvalue, 1.58e-14)
        self.assertAlmostEqual(motif.instances[11].pvalue, 1.76e-14)
        self.assertAlmostEqual(motif.instances[12].pvalue, 2.16e-14)
        self.assertAlmostEqual(motif.instances[13].pvalue, 2.94e-14)
        self.assertAlmostEqual(motif.instances[14].pvalue, 3.25e-14)
        self.assertAlmostEqual(motif.instances[15].pvalue, 3.98e-14)
        self.assertAlmostEqual(motif.instances[16].pvalue, 4.39e-14)
        self.assertAlmostEqual(motif.instances[17].pvalue, 4.39e-14)
        self.assertAlmostEqual(motif.instances[18].pvalue, 4.85e-14)
        self.assertAlmostEqual(motif.instances[19].pvalue, 6.52e-14)
        self.assertAlmostEqual(motif.instances[20].pvalue, 1.41e-13)
        self.assertAlmostEqual(motif.instances[21].pvalue, 1.55e-13)
        self.assertAlmostEqual(motif.instances[22].pvalue, 3.07e-12)
        self.assertAlmostEqual(motif.instances[23].pvalue, 5.43e-12)
        self.assertAlmostEqual(motif.instances[24].pvalue, 6.91e-12)
        self.assertAlmostEqual(motif.instances[25].pvalue, 8.76e-12)
        self.assertAlmostEqual(motif.instances[26].pvalue, 9.48e-12)
        self.assertAlmostEqual(motif.instances[27].pvalue, 1.2e-11)
        self.assertAlmostEqual(motif.instances[28].pvalue, 1.19e-09)
        self.assertAlmostEqual(motif.instances[29].pvalue, 1.54e-09)
        self.assertAlmostEqual(motif.instances[30].pvalue, 1.99e-09)
        self.assertAlmostEqual(motif.instances[31].pvalue, 1.42e-06)
        self.assertAlmostEqual(motif.instances[32].pvalue, 3.43e-06)
        self.assertEqual(motif.instances[0].sequence_name, "BUDC_KLETE")
        self.assertEqual(motif.instances[1].sequence_name, "YINL_LISMO")
        self.assertEqual(motif.instances[2].sequence_name, "DHII_HUMAN")
        self.assertEqual(motif.instances[3].sequence_name, "HDE_CANTR")
        self.assertEqual(motif.instances[4].sequence_name, "YRTP_BACSU")
        self.assertEqual(motif.instances[5].sequence_name, "ENTA_ECOLI")
        self.assertEqual(motif.instances[6].sequence_name, "HDHA_ECOLI")
        self.assertEqual(motif.instances[7].sequence_name, "RIDH_KLEAE")
        self.assertEqual(motif.instances[8].sequence_name, "DHB2_HUMAN")
        self.assertEqual(motif.instances[9].sequence_name, "FIXR_BRAJA")
        self.assertEqual(motif.instances[10].sequence_name, "PCR_PEA")
        self.assertEqual(motif.instances[11].sequence_name, "DHCA_HUMAN")
        self.assertEqual(motif.instances[12].sequence_name, "BDH_HUMAN")
        self.assertEqual(motif.instances[13].sequence_name, "3BHD_COMTE")
        self.assertEqual(motif.instances[14].sequence_name, "DHGB_BACME")
        self.assertEqual(motif.instances[15].sequence_name, "DHMA_FLAS1")
        self.assertEqual(motif.instances[16].sequence_name, "FVT1_HUMAN")
        self.assertEqual(motif.instances[17].sequence_name, "BA72_EUBSP")
        self.assertEqual(motif.instances[18].sequence_name, "BPHB_PSEPS")
        self.assertEqual(motif.instances[19].sequence_name, "DHB3_HUMAN")
        self.assertEqual(motif.instances[20].sequence_name, "DHES_HUMAN")
        self.assertEqual(motif.instances[21].sequence_name, "AP27_MOUSE")
        self.assertEqual(motif.instances[22].sequence_name, "2BHD_STREX")
        self.assertEqual(motif.instances[23].sequence_name, "NODG_RHIME")
        self.assertEqual(motif.instances[24].sequence_name, "HMTR_LEIMA")
        self.assertEqual(motif.instances[25].sequence_name, "LIGD_PSEPA")
        self.assertEqual(motif.instances[26].sequence_name, "MAS1_AGRRA")
        self.assertEqual(motif.instances[27].sequence_name, "RFBB_NEIGO")
        self.assertEqual(motif.instances[28].sequence_name, "GUTD_ECOLI")
        self.assertEqual(motif.instances[29].sequence_name, "ADH_DROME")
        self.assertEqual(motif.instances[30].sequence_name, "FABI_ECOLI")
        self.assertEqual(motif.instances[31].sequence_name, "CSGA_MYXXA")
        self.assertEqual(motif.instances[32].sequence_name, "YURA_MYXXA")
        self.assertEqual(motif.instances[0].sequence_id, "sequence_7")
        self.assertEqual(motif.instances[1].sequence_id, "sequence_20")
        self.assertEqual(motif.instances[2].sequence_id, "sequence_10")
        self.assertEqual(motif.instances[3].sequence_id, "sequence_15")
        self.assertEqual(motif.instances[4].sequence_id, "sequence_21")
        self.assertEqual(motif.instances[5].sequence_id, "sequence_12")
        self.assertEqual(motif.instances[6].sequence_id, "sequence_16")
        self.assertEqual(motif.instances[7].sequence_id, "sequence_19")
        self.assertEqual(motif.instances[8].sequence_id, "sequence_23")
        self.assertEqual(motif.instances[9].sequence_id, "sequence_13")
        self.assertEqual(motif.instances[10].sequence_id, "sequence_30")
        self.assertEqual(motif.instances[11].sequence_id, "sequence_25")
        self.assertEqual(motif.instances[12].sequence_id, "sequence_5")
        self.assertEqual(motif.instances[13].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[14].sequence_id, "sequence_9")
        self.assertEqual(motif.instances[15].sequence_id, "sequence_11")
        self.assertEqual(motif.instances[16].sequence_id, "sequence_27")
        self.assertEqual(motif.instances[17].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[18].sequence_id, "sequence_6")
        self.assertEqual(motif.instances[19].sequence_id, "sequence_24")
        self.assertEqual(motif.instances[20].sequence_id, "sequence_8")
        self.assertEqual(motif.instances[21].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[22].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[23].sequence_id, "sequence_18")
        self.assertEqual(motif.instances[24].sequence_id, "sequence_28")
        self.assertEqual(motif.instances[25].sequence_id, "sequence_17")
        self.assertEqual(motif.instances[26].sequence_id, "sequence_29")
        self.assertEqual(motif.instances[27].sequence_id, "sequence_31")
        self.assertEqual(motif.instances[28].sequence_id, "sequence_14")
        self.assertEqual(motif.instances[29].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[30].sequence_id, "sequence_26")
        self.assertEqual(motif.instances[31].sequence_id, "sequence_22")
        self.assertEqual(motif.instances[32].sequence_id, "sequence_32")
        self.assertEqual(motif.instances[0].strand, "+")
        self.assertEqual(motif.instances[1].strand, "+")
        self.assertEqual(motif.instances[2].strand, "+")
        self.assertEqual(motif.instances[3].strand, "+")
        self.assertEqual(motif.instances[4].strand, "+")
        self.assertEqual(motif.instances[5].strand, "+")
        self.assertEqual(motif.instances[6].strand, "+")
        self.assertEqual(motif.instances[7].strand, "+")
        self.assertEqual(motif.instances[8].strand, "+")
        self.assertEqual(motif.instances[9].strand, "+")
        self.assertEqual(motif.instances[10].strand, "+")
        self.assertEqual(motif.instances[11].strand, "+")
        self.assertEqual(motif.instances[12].strand, "+")
        self.assertEqual(motif.instances[13].strand, "+")
        self.assertEqual(motif.instances[14].strand, "+")
        self.assertEqual(motif.instances[15].strand, "+")
        self.assertEqual(motif.instances[16].strand, "+")
        self.assertEqual(motif.instances[17].strand, "+")
        self.assertEqual(motif.instances[18].strand, "+")
        self.assertEqual(motif.instances[19].strand, "+")
        self.assertEqual(motif.instances[20].strand, "+")
        self.assertEqual(motif.instances[21].strand, "+")
        self.assertEqual(motif.instances[22].strand, "+")
        self.assertEqual(motif.instances[23].strand, "+")
        self.assertEqual(motif.instances[24].strand, "+")
        self.assertEqual(motif.instances[25].strand, "+")
        self.assertEqual(motif.instances[26].strand, "+")
        self.assertEqual(motif.instances[27].strand, "+")
        self.assertEqual(motif.instances[28].strand, "+")
        self.assertEqual(motif.instances[29].strand, "+")
        self.assertEqual(motif.instances[30].strand, "+")
        self.assertEqual(motif.instances[31].strand, "+")
        self.assertEqual(motif.instances[32].strand, "+")
        self.assertEqual(motif.instances[0].length, 21)
        self.assertEqual(motif.instances[1].length, 21)
        self.assertEqual(motif.instances[2].length, 21)
        self.assertEqual(motif.instances[3].length, 21)
        self.assertEqual(motif.instances[4].length, 21)
        self.assertEqual(motif.instances[5].length, 21)
        self.assertEqual(motif.instances[6].length, 21)
        self.assertEqual(motif.instances[7].length, 21)
        self.assertEqual(motif.instances[8].length, 21)
        self.assertEqual(motif.instances[9].length, 21)
        self.assertEqual(motif.instances[10].length, 21)
        self.assertEqual(motif.instances[11].length, 21)
        self.assertEqual(motif.instances[12].length, 21)
        self.assertEqual(motif.instances[13].length, 21)
        self.assertEqual(motif.instances[14].length, 21)
        self.assertEqual(motif.instances[15].length, 21)
        self.assertEqual(motif.instances[16].length, 21)
        self.assertEqual(motif.instances[17].length, 21)
        self.assertEqual(motif.instances[18].length, 21)
        self.assertEqual(motif.instances[19].length, 21)
        self.assertEqual(motif.instances[20].length, 21)
        self.assertEqual(motif.instances[21].length, 21)
        self.assertEqual(motif.instances[22].length, 21)
        self.assertEqual(motif.instances[23].length, 21)
        self.assertEqual(motif.instances[24].length, 21)
        self.assertEqual(motif.instances[25].length, 21)
        self.assertEqual(motif.instances[26].length, 21)
        self.assertEqual(motif.instances[27].length, 21)
        self.assertEqual(motif.instances[28].length, 21)
        self.assertEqual(motif.instances[29].length, 21)
        self.assertEqual(motif.instances[30].length, 21)
        self.assertEqual(motif.instances[31].length, 21)
        self.assertEqual(motif.instances[32].length, 21)
        self.assertEqual(motif.instances[0].start, 2)
        self.assertEqual(motif.instances[1].start, 5)
        self.assertEqual(motif.instances[2].start, 34)
        self.assertEqual(motif.instances[3].start, 322)
        self.assertEqual(motif.instances[4].start, 6)
        self.assertEqual(motif.instances[5].start, 5)
        self.assertEqual(motif.instances[6].start, 11)
        self.assertEqual(motif.instances[7].start, 14)
        self.assertEqual(motif.instances[8].start, 82)
        self.assertEqual(motif.instances[9].start, 36)
        self.assertEqual(motif.instances[10].start, 86)
        self.assertEqual(motif.instances[11].start, 4)
        self.assertEqual(motif.instances[12].start, 55)
        self.assertEqual(motif.instances[13].start, 6)
        self.assertEqual(motif.instances[14].start, 7)
        self.assertEqual(motif.instances[15].start, 14)
        self.assertEqual(motif.instances[16].start, 32)
        self.assertEqual(motif.instances[17].start, 6)
        self.assertEqual(motif.instances[18].start, 5)
        self.assertEqual(motif.instances[19].start, 48)
        self.assertEqual(motif.instances[20].start, 2)
        self.assertEqual(motif.instances[21].start, 7)
        self.assertEqual(motif.instances[22].start, 6)
        self.assertEqual(motif.instances[23].start, 6)
        self.assertEqual(motif.instances[24].start, 6)
        self.assertEqual(motif.instances[25].start, 6)
        self.assertEqual(motif.instances[26].start, 245)
        self.assertEqual(motif.instances[27].start, 6)
        self.assertEqual(motif.instances[28].start, 2)
        self.assertEqual(motif.instances[29].start, 6)
        self.assertEqual(motif.instances[30].start, 6)
        self.assertEqual(motif.instances[31].start, 13)
        self.assertEqual(motif.instances[32].start, 116)
        self.assertEqual(str(motif.instances[0]), "QKVALVTGAGQGIGKAIALRL")
        self.assertEqual(str(motif.instances[1]), "NKVIIITGASSGIGKATALLL")
        self.assertEqual(str(motif.instances[2]), "GKKVIVTGASKGIGREMAYHL")
        self.assertEqual(str(motif.instances[3]), "DKVVLITGAGAGLGKEYAKWF")
        self.assertEqual(str(motif.instances[4]), "HKTALITGGGRGIGRATALAL")
        self.assertEqual(str(motif.instances[5]), "GKNVWVTGAGKGIGYATALAF")
        self.assertEqual(str(motif.instances[6]), "GKCAIITGAGAGIGKEIAITF")
        self.assertEqual(str(motif.instances[7]), "GKVAAITGAASGIGLECARTL")
        self.assertEqual(str(motif.instances[8]), "QKAVLVTGGDCGLGHALCKYL")
        self.assertEqual(str(motif.instances[9]), "PKVMLLTGASRGIGHATAKLF")
        self.assertEqual(str(motif.instances[10]), "KGNVVITGASSGLGLATAKAL")
        self.assertEqual(str(motif.instances[11]), "IHVALVTGGNKGIGLAIVRDL")
        self.assertEqual(str(motif.instances[12]), "SKAVLVTGCDSGFGFSLAKHL")
        self.assertEqual(str(motif.instances[13]), "GKVALVTGGASGVGLEVVKLL")
        self.assertEqual(str(motif.instances[14]), "GKVVVITGSSTGLGKSMAIRF")
        self.assertEqual(str(motif.instances[15]), "GKAAIVTGAAGGIGRATVEAY")
        self.assertEqual(str(motif.instances[16]), "GAHVVVTGGSSGIGKCIAIEC")
        self.assertEqual(str(motif.instances[17]), "DKVTIITGGTRGIGFAAAKIF")
        self.assertEqual(str(motif.instances[18]), "GEAVLITGGASGLGRALVDRF")
        self.assertEqual(str(motif.instances[19]), "GQWAVITGAGDGIGKAYSFEL")
        self.assertEqual(str(motif.instances[20]), "RTVVLITGCSSGIGLHLAVRL")
        self.assertEqual(str(motif.instances[21]), "GLRALVTGAGKGIGRDTVKAL")
        self.assertEqual(str(motif.instances[22]), "GKTVIITGGARGLGAEAARQA")
        self.assertEqual(str(motif.instances[23]), "GRKALVTGASGAIGGAIARVL")
        self.assertEqual(str(motif.instances[24]), "VPVALVTGAAKRLGRSIAEGL")
        self.assertEqual(str(motif.instances[25]), "DQVAFITGGASGAGFGQAKVF")
        self.assertEqual(str(motif.instances[26]), "SPVILVSGSNRGVGKAIAEDL")
        self.assertEqual(str(motif.instances[27]), "KKNILVTGGAGFIGSAVVRHI")
        self.assertEqual(str(motif.instances[28]), "NQVAVVIGGGQTLGAFLCHGL")
        self.assertEqual(str(motif.instances[29]), "NKNVIFVAGLGGIGLDTSKEL")
        self.assertEqual(str(motif.instances[30]), "GKRILVTGVASKLSIAYGIAQ")
        self.assertEqual(str(motif.instances[31]), "VDVLINNAGVSGLWCALGDVD")
        self.assertEqual(str(motif.instances[32]), "IIDTNVTGAAATLSAVLPQMV")
        motif = record[1]
        self.assertEqual(motif.name, "VGNPGASAYSASKAAVRGLTESLALELAP")
        self.assertEqual(motif.alt_id, "MEME-2")
        self.assertEqual(record["VGNPGASAYSASKAAVRGLTESLALELAP"], motif)
        self.assertEqual(motif.num_occurrences, 33)
        self.assertAlmostEqual(motif.evalue, 3.1e-130)
        self.assertEqual(motif.alphabet, "ACDEFGHIKLMNPQRSTVWY")
        self.assertEqual(len(motif.instances), 33)
        self.assertAlmostEqual(motif.instances[0].pvalue, 2.09e-21)
        self.assertAlmostEqual(motif.instances[1].pvalue, 7.63e-20)
        self.assertAlmostEqual(motif.instances[2].pvalue, 6.49e-19)
        self.assertAlmostEqual(motif.instances[3].pvalue, 1.92e-18)
        self.assertAlmostEqual(motif.instances[4].pvalue, 5.46e-18)
        self.assertAlmostEqual(motif.instances[5].pvalue, 6.21e-18)
        self.assertAlmostEqual(motif.instances[6].pvalue, 4.52e-17)
        self.assertAlmostEqual(motif.instances[7].pvalue, 4.52e-17)
        self.assertAlmostEqual(motif.instances[8].pvalue, 9.21e-17)
        self.assertAlmostEqual(motif.instances[9].pvalue, 1.65e-16)
        self.assertAlmostEqual(motif.instances[10].pvalue, 2.07e-16)
        self.assertAlmostEqual(motif.instances[11].pvalue, 3.65e-16)
        self.assertAlmostEqual(motif.instances[12].pvalue, 5.7e-16)
        self.assertAlmostEqual(motif.instances[13].pvalue, 5.7e-16)
        self.assertAlmostEqual(motif.instances[14].pvalue, 7.93e-16)
        self.assertAlmostEqual(motif.instances[15].pvalue, 8.85e-16)
        self.assertAlmostEqual(motif.instances[16].pvalue, 1.1e-15)
        self.assertAlmostEqual(motif.instances[17].pvalue, 1.69e-15)
        self.assertAlmostEqual(motif.instances[18].pvalue, 3.54e-15)
        self.assertAlmostEqual(motif.instances[19].pvalue, 4.83e-15)
        self.assertAlmostEqual(motif.instances[20].pvalue, 7.27e-15)
        self.assertAlmostEqual(motif.instances[21].pvalue, 9.85e-15)
        self.assertAlmostEqual(motif.instances[22].pvalue, 2.41e-14)
        self.assertAlmostEqual(motif.instances[23].pvalue, 2.66e-14)
        self.assertAlmostEqual(motif.instances[24].pvalue, 1.22e-13)
        self.assertAlmostEqual(motif.instances[25].pvalue, 5.18e-13)
        self.assertAlmostEqual(motif.instances[26].pvalue, 1.24e-12)
        self.assertAlmostEqual(motif.instances[27].pvalue, 1.35e-12)
        self.assertAlmostEqual(motif.instances[28].pvalue, 5.59e-12)
        self.assertAlmostEqual(motif.instances[29].pvalue, 1.44e-10)
        self.assertAlmostEqual(motif.instances[30].pvalue, 1.61e-08)
        self.assertAlmostEqual(motif.instances[31].pvalue, 4.26e-08)
        self.assertAlmostEqual(motif.instances[32].pvalue, 1.16e-07)
        self.assertEqual(motif.instances[0].sequence_name, "BUDC_KLETE")
        self.assertEqual(motif.instances[1].sequence_name, "NODG_RHIME")
        self.assertEqual(motif.instances[2].sequence_name, "FVT1_HUMAN")
        self.assertEqual(motif.instances[3].sequence_name, "DHES_HUMAN")
        self.assertEqual(motif.instances[4].sequence_name, "DHB3_HUMAN")
        self.assertEqual(motif.instances[5].sequence_name, "YRTP_BACSU")
        self.assertEqual(motif.instances[6].sequence_name, "HMTR_LEIMA")
        self.assertEqual(motif.instances[7].sequence_name, "HDE_CANTR")
        self.assertEqual(motif.instances[8].sequence_name, "DHGB_BACME")
        self.assertEqual(motif.instances[9].sequence_name, "GUTD_ECOLI")
        self.assertEqual(motif.instances[10].sequence_name, "3BHD_COMTE")
        self.assertEqual(motif.instances[11].sequence_name, "DHII_HUMAN")
        self.assertEqual(motif.instances[12].sequence_name, "BPHB_PSEPS")
        self.assertEqual(motif.instances[13].sequence_name, "AP27_MOUSE")
        self.assertEqual(motif.instances[14].sequence_name, "BDH_HUMAN")
        self.assertEqual(motif.instances[15].sequence_name, "YINL_LISMO")
        self.assertEqual(motif.instances[16].sequence_name, "FIXR_BRAJA")
        self.assertEqual(motif.instances[17].sequence_name, "2BHD_STREX")
        self.assertEqual(motif.instances[18].sequence_name, "RFBB_NEIGO")
        self.assertEqual(motif.instances[19].sequence_name, "YURA_MYXXA")
        self.assertEqual(motif.instances[20].sequence_name, "RIDH_KLEAE")
        self.assertEqual(motif.instances[21].sequence_name, "DHMA_FLAS1")
        self.assertEqual(motif.instances[22].sequence_name, "DHB2_HUMAN")
        self.assertEqual(motif.instances[23].sequence_name, "HDHA_ECOLI")
        self.assertEqual(motif.instances[24].sequence_name, "ENTA_ECOLI")
        self.assertEqual(motif.instances[25].sequence_name, "LIGD_PSEPA")
        self.assertEqual(motif.instances[26].sequence_name, "CSGA_MYXXA")
        self.assertEqual(motif.instances[27].sequence_name, "BA72_EUBSP")
        self.assertEqual(motif.instances[28].sequence_name, "ADH_DROME")
        self.assertEqual(motif.instances[29].sequence_name, "MAS1_AGRRA")
        self.assertEqual(motif.instances[30].sequence_name, "PCR_PEA")
        self.assertEqual(motif.instances[31].sequence_name, "FABI_ECOLI")
        self.assertEqual(motif.instances[32].sequence_name, "DHCA_HUMAN")
        self.assertEqual(motif.instances[0].sequence_id, "sequence_7")
        self.assertEqual(motif.instances[1].sequence_id, "sequence_18")
        self.assertEqual(motif.instances[2].sequence_id, "sequence_27")
        self.assertEqual(motif.instances[3].sequence_id, "sequence_8")
        self.assertEqual(motif.instances[4].sequence_id, "sequence_24")
        self.assertEqual(motif.instances[5].sequence_id, "sequence_21")
        self.assertEqual(motif.instances[6].sequence_id, "sequence_28")
        self.assertEqual(motif.instances[7].sequence_id, "sequence_15")
        self.assertEqual(motif.instances[8].sequence_id, "sequence_9")
        self.assertEqual(motif.instances[9].sequence_id, "sequence_14")
        self.assertEqual(motif.instances[10].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[11].sequence_id, "sequence_10")
        self.assertEqual(motif.instances[12].sequence_id, "sequence_6")
        self.assertEqual(motif.instances[13].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[14].sequence_id, "sequence_5")
        self.assertEqual(motif.instances[15].sequence_id, "sequence_20")
        self.assertEqual(motif.instances[16].sequence_id, "sequence_13")
        self.assertEqual(motif.instances[17].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[18].sequence_id, "sequence_31")
        self.assertEqual(motif.instances[19].sequence_id, "sequence_32")
        self.assertEqual(motif.instances[20].sequence_id, "sequence_19")
        self.assertEqual(motif.instances[21].sequence_id, "sequence_11")
        self.assertEqual(motif.instances[22].sequence_id, "sequence_23")
        self.assertEqual(motif.instances[23].sequence_id, "sequence_16")
        self.assertEqual(motif.instances[24].sequence_id, "sequence_12")
        self.assertEqual(motif.instances[25].sequence_id, "sequence_17")
        self.assertEqual(motif.instances[26].sequence_id, "sequence_22")
        self.assertEqual(motif.instances[27].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[28].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[29].sequence_id, "sequence_29")
        self.assertEqual(motif.instances[30].sequence_id, "sequence_30")
        self.assertEqual(motif.instances[31].sequence_id, "sequence_26")
        self.assertEqual(motif.instances[32].sequence_id, "sequence_25")
        self.assertEqual(motif.instances[0].start, 144)
        self.assertEqual(motif.instances[1].start, 144)
        self.assertEqual(motif.instances[2].start, 178)
        self.assertEqual(motif.instances[3].start, 147)
        self.assertEqual(motif.instances[4].start, 190)
        self.assertEqual(motif.instances[5].start, 147)
        self.assertEqual(motif.instances[6].start, 185)
        self.assertEqual(motif.instances[7].start, 459)
        self.assertEqual(motif.instances[8].start, 152)
        self.assertEqual(motif.instances[9].start, 146)
        self.assertEqual(motif.instances[10].start, 143)
        self.assertEqual(motif.instances[11].start, 175)
        self.assertEqual(motif.instances[12].start, 145)
        self.assertEqual(motif.instances[13].start, 141)
        self.assertEqual(motif.instances[14].start, 200)
        self.assertEqual(motif.instances[15].start, 146)
        self.assertEqual(motif.instances[16].start, 181)
        self.assertEqual(motif.instances[17].start, 144)
        self.assertEqual(motif.instances[18].start, 157)
        self.assertEqual(motif.instances[19].start, 152)
        self.assertEqual(motif.instances[20].start, 152)
        self.assertEqual(motif.instances[21].start, 157)
        self.assertEqual(motif.instances[22].start, 224)
        self.assertEqual(motif.instances[23].start, 151)
        self.assertEqual(motif.instances[24].start, 136)
        self.assertEqual(motif.instances[25].start, 149)
        self.assertEqual(motif.instances[26].start, 80)
        self.assertEqual(motif.instances[27].start, 149)
        self.assertEqual(motif.instances[28].start, 144)
        self.assertEqual(motif.instances[29].start, 384)
        self.assertEqual(motif.instances[30].start, 18)
        self.assertEqual(motif.instances[31].start, 177)
        self.assertEqual(motif.instances[32].start, 144)
        self.assertEqual(str(motif.instances[0]), "VGNPELAVYSSSKFAVRGLTQTAARDLAP")
        self.assertEqual(str(motif.instances[1]), "IGNPGQTNYCASKAGMIGFSKSLAQEIAT")
        self.assertEqual(str(motif.instances[2]), "LGLFGFTAYSASKFAIRGLAEALQMEVKP")
        self.assertEqual(str(motif.instances[3]), "MGLPFNDVYCASKFALEGLCESLAVLLLP")
        self.assertEqual(str(motif.instances[4]), "FPWPLYSMYSASKAFVCAFSKALQEEYKA")
        self.assertEqual(str(motif.instances[5]), "RGAAVTSAYSASKFAVLGLTESLMQEVRK")
        self.assertEqual(str(motif.instances[6]), "QPLLGYTIYTMAKGALEGLTRSAALELAP")
        self.assertEqual(str(motif.instances[7]), "YGNFGQANYSSSKAGILGLSKTMAIEGAK")
        self.assertEqual(str(motif.instances[8]), "IPWPLFVHYAASKGGMKLMTETLALEYAP")
        self.assertEqual(str(motif.instances[9]), "VGSKHNSGYSAAKFGGVGLTQSLALDLAE")
        self.assertEqual(str(motif.instances[10]), "LPIEQYAGYSASKAAVSALTRAAALSCRK")
        self.assertEqual(str(motif.instances[11]), "VAYPMVAAYSASKFALDGFFSSIRKEYSV")
        self.assertEqual(str(motif.instances[12]), "YPNGGGPLYTAAKQAIVGLVRELAFELAP")
        self.assertEqual(str(motif.instances[13]), "VTFPNLITYSSTKGAMTMLTKAMAMELGP")
        self.assertEqual(str(motif.instances[14]), "MANPARSPYCITKFGVEAFSDCLRYEMYP")
        self.assertEqual(str(motif.instances[15]), "KAYPGGAVYGATKWAVRDLMEVLRMESAQ")
        self.assertEqual(str(motif.instances[16]), "VHPFAGSAYATSKAALASLTRELAHDYAP")
        self.assertEqual(str(motif.instances[17]), "MGLALTSSYGASKWGVRGLSKLAAVELGT")
        self.assertEqual(str(motif.instances[18]), "TPYAPSSPYSASKAAADHLVRAWQRTYRL")
        self.assertEqual(str(motif.instances[19]), "FRGLPATRYSASKAFLSTFMESLRVDLRG")
        self.assertEqual(str(motif.instances[20]), "VPVIWEPVYTASKFAVQAFVHTTRRQVAQ")
        self.assertEqual(str(motif.instances[21]), "MAEPEAAAYVAAKGGVAMLTRAMAVDLAR")
        self.assertEqual(str(motif.instances[22]), "APMERLASYGSSKAAVTMFSSVMRLELSK")
        self.assertEqual(str(motif.instances[23]), "NKNINMTSYASSKAAASHLVRNMAFDLGE")
        self.assertEqual(str(motif.instances[24]), "TPRIGMSAYGASKAALKSLALSVGLELAG")
        self.assertEqual(str(motif.instances[25]), "MGSALAGPYSAAKAASINLMEGYRQGLEK")
        self.assertEqual(str(motif.instances[26]), "NTDGGAYAYRMSKAALNMAVRSMSTDLRP")
        self.assertEqual(str(motif.instances[27]), "FGSLSGVGYPASKASVIGLTHGLGREIIR")
        self.assertEqual(str(motif.instances[28]), "NAIYQVPVYSGTKAAVVNFTSSLAKLAPI")
        self.assertEqual(str(motif.instances[29]), "RVLNPLVGYNMTKHALGGLTKTTQHVGWD")
        self.assertEqual(str(motif.instances[30]), "EGKIGASLKDSTLFGVSSLSDSLKGDFTS")
        self.assertEqual(str(motif.instances[31]), "MGPEGVRVNAISAGPIRTLAASGIKDFRK")
        self.assertEqual(str(motif.instances[32]), "RALKSCSPELQQKFRSETITEEELVGLMN")

    def test_meme_parser_3(self):
        """Parse motifs/meme.farntrans5.classic.anr.xml file."""
        with open("motifs/meme.farntrans5.classic.anr.xml") as handle:
            record = motifs.parse(handle, "meme")
        self.assertEqual(record.version, "5.0.1")
        self.assertEqual(record.datafile, "common/farntrans5.s")
        self.assertEqual(record.alphabet, "ACDEFGHIKLMNPQRSTVWY")
        self.assertEqual(len(record.sequences), 5)
        self.assertEqual(record.sequences[0], "sequence_0")
        self.assertEqual(record.sequences[1], "sequence_1")
        self.assertEqual(record.sequences[2], "sequence_2")
        self.assertEqual(record.sequences[3], "sequence_3")
        self.assertEqual(record.sequences[4], "sequence_4")
        self.assertEqual(
            record.command,
            "meme common/farntrans5.s -oc results/meme15 -mod anr -protein -nmotifs 2 -objfun classic -minw 8 -nostatus ",
        )
        self.assertEqual(len(record), 2)
        motif = record[0]
        self.assertEqual(motif.name, "GGFGGRPGKEVDLCYTYCALAALAJLGSLD")
        self.assertEqual(record["GGFGGRPGKEVDLCYTYCALAALAJLGSLD"], motif)
        self.assertEqual(motif.num_occurrences, 24)
        self.assertAlmostEqual(motif.evalue, 2.2e-94)
        self.assertEqual(motif.alphabet, "ACDEFGHIKLMNPQRSTVWY")
        self.assertEqual(len(motif.instances), 24)
        self.assertAlmostEqual(motif.instances[0].pvalue, 6.98e-22)
        self.assertAlmostEqual(motif.instances[1].pvalue, 4.67e-21)
        self.assertAlmostEqual(motif.instances[2].pvalue, 1.25e-19)
        self.assertAlmostEqual(motif.instances[3].pvalue, 1.56e-19)
        self.assertAlmostEqual(motif.instances[4].pvalue, 2.44e-19)
        self.assertAlmostEqual(motif.instances[5].pvalue, 6.47e-19)
        self.assertAlmostEqual(motif.instances[6].pvalue, 8.9e-19)
        self.assertAlmostEqual(motif.instances[7].pvalue, 2.53e-18)
        self.assertAlmostEqual(motif.instances[8].pvalue, 1.27e-17)
        self.assertAlmostEqual(motif.instances[9].pvalue, 2.77e-17)
        self.assertAlmostEqual(motif.instances[10].pvalue, 4.93e-17)
        self.assertAlmostEqual(motif.instances[11].pvalue, 7.19e-17)
        self.assertAlmostEqual(motif.instances[12].pvalue, 8.68e-17)
        self.assertAlmostEqual(motif.instances[13].pvalue, 2.62e-16)
        self.assertAlmostEqual(motif.instances[14].pvalue, 2.87e-16)
        self.assertAlmostEqual(motif.instances[15].pvalue, 7.66e-15)
        self.assertAlmostEqual(motif.instances[16].pvalue, 2.21e-14)
        self.assertAlmostEqual(motif.instances[17].pvalue, 3.29e-14)
        self.assertAlmostEqual(motif.instances[18].pvalue, 7.21e-14)
        self.assertAlmostEqual(motif.instances[19].pvalue, 1.14e-13)
        self.assertAlmostEqual(motif.instances[20].pvalue, 1.67e-13)
        self.assertAlmostEqual(motif.instances[21].pvalue, 4.42e-13)
        self.assertAlmostEqual(motif.instances[22].pvalue, 5.11e-13)
        self.assertAlmostEqual(motif.instances[23].pvalue, 2.82e-10)
        self.assertEqual(motif.instances[0].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[1].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[2].sequence_name, "CAL1_YEAST")
        self.assertEqual(motif.instances[3].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[4].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[5].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[6].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[7].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[8].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[9].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[10].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[11].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[12].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[13].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[14].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[15].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[16].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[17].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[18].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[19].sequence_name, "CAL1_YEAST")
        self.assertEqual(motif.instances[20].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[21].sequence_name, "CAL1_YEAST")
        self.assertEqual(motif.instances[22].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[23].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[0].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[1].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[2].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[3].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[4].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[5].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[6].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[7].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[8].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[9].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[10].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[11].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[12].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[13].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[14].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[15].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[16].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[17].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[18].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[19].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[20].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[21].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[22].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[23].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[0].strand, "+")
        self.assertEqual(motif.instances[1].strand, "+")
        self.assertEqual(motif.instances[2].strand, "+")
        self.assertEqual(motif.instances[3].strand, "+")
        self.assertEqual(motif.instances[4].strand, "+")
        self.assertEqual(motif.instances[5].strand, "+")
        self.assertEqual(motif.instances[6].strand, "+")
        self.assertEqual(motif.instances[7].strand, "+")
        self.assertEqual(motif.instances[8].strand, "+")
        self.assertEqual(motif.instances[9].strand, "+")
        self.assertEqual(motif.instances[10].strand, "+")
        self.assertEqual(motif.instances[11].strand, "+")
        self.assertEqual(motif.instances[12].strand, "+")
        self.assertEqual(motif.instances[13].strand, "+")
        self.assertEqual(motif.instances[14].strand, "+")
        self.assertEqual(motif.instances[15].strand, "+")
        self.assertEqual(motif.instances[16].strand, "+")
        self.assertEqual(motif.instances[17].strand, "+")
        self.assertEqual(motif.instances[18].strand, "+")
        self.assertEqual(motif.instances[19].strand, "+")
        self.assertEqual(motif.instances[20].strand, "+")
        self.assertEqual(motif.instances[21].strand, "+")
        self.assertEqual(motif.instances[22].strand, "+")
        self.assertEqual(motif.instances[23].strand, "+")
        self.assertEqual(motif.instances[0].length, 30)
        self.assertEqual(motif.instances[1].length, 30)
        self.assertEqual(motif.instances[2].length, 30)
        self.assertEqual(motif.instances[3].length, 30)
        self.assertEqual(motif.instances[4].length, 30)
        self.assertEqual(motif.instances[5].length, 30)
        self.assertEqual(motif.instances[6].length, 30)
        self.assertEqual(motif.instances[7].length, 30)
        self.assertEqual(motif.instances[8].length, 30)
        self.assertEqual(motif.instances[9].length, 30)
        self.assertEqual(motif.instances[10].length, 30)
        self.assertEqual(motif.instances[11].length, 30)
        self.assertEqual(motif.instances[12].length, 30)
        self.assertEqual(motif.instances[13].length, 30)
        self.assertEqual(motif.instances[14].length, 30)
        self.assertEqual(motif.instances[15].length, 30)
        self.assertEqual(motif.instances[16].length, 30)
        self.assertEqual(motif.instances[17].length, 30)
        self.assertEqual(motif.instances[18].length, 30)
        self.assertEqual(motif.instances[19].length, 30)
        self.assertEqual(motif.instances[20].length, 30)
        self.assertEqual(motif.instances[21].length, 30)
        self.assertEqual(motif.instances[22].length, 30)
        self.assertEqual(motif.instances[23].length, 30)
        self.assertEqual(motif.instances[0].start, 223)
        self.assertEqual(motif.instances[1].start, 227)
        self.assertEqual(motif.instances[2].start, 275)
        self.assertEqual(motif.instances[3].start, 237)
        self.assertEqual(motif.instances[4].start, 138)
        self.assertEqual(motif.instances[5].start, 179)
        self.assertEqual(motif.instances[6].start, 131)
        self.assertEqual(motif.instances[7].start, 172)
        self.assertEqual(motif.instances[8].start, 276)
        self.assertEqual(motif.instances[9].start, 124)
        self.assertEqual(motif.instances[10].start, 247)
        self.assertEqual(motif.instances[11].start, 272)
        self.assertEqual(motif.instances[12].start, 145)
        self.assertEqual(motif.instances[13].start, 286)
        self.assertEqual(motif.instances[14].start, 296)
        self.assertEqual(motif.instances[15].start, 348)
        self.assertEqual(motif.instances[16].start, 83)
        self.assertEqual(motif.instances[17].start, 189)
        self.assertEqual(motif.instances[18].start, 73)
        self.assertEqual(motif.instances[19].start, 205)
        self.assertEqual(motif.instances[20].start, 198)
        self.assertEqual(motif.instances[21].start, 327)
        self.assertEqual(motif.instances[22].start, 349)
        self.assertEqual(motif.instances[23].start, 24)
        self.assertEqual(str(motif.instances[0]), "GGLNGRPSKLPDVCYSWWVLSSLAIIGRLD")
        self.assertEqual(str(motif.instances[1]), "GGLNGRPEKLPDVCYSWWVLASLKIIGRLH")
        self.assertEqual(str(motif.instances[2]), "GGFQGRENKFADTCYAFWCLNSLHLLTKDW")
        self.assertEqual(str(motif.instances[3]), "GGIGGVPGMEAHGGYTFCGLAALVILKKER")
        self.assertEqual(str(motif.instances[4]), "GGFGGGPGQYPHLAPTYAAVNALCIIGTEE")
        self.assertEqual(str(motif.instances[5]), "GGFGCRPGSESHAGQIYCCTGFLAITSQLH")
        self.assertEqual(str(motif.instances[6]), "GSFAGDIWGEIDTRFSFCAVATLALLGKLD")
        self.assertEqual(str(motif.instances[7]), "GGFGLCPNAESHAAQAFTCLGALAIANKLD")
        self.assertEqual(str(motif.instances[8]), "GGFADRPGDMVDPFHTLFGIAGLSLLGEEQ")
        self.assertEqual(str(motif.instances[9]), "GSFQGDRFGEVDTRFVYTALSALSILGELT")
        self.assertEqual(str(motif.instances[10]), "GFGSCPHVDEAHGGYTFCATASLAILRSMD")
        self.assertEqual(str(motif.instances[11]), "GGISDRPENEVDVFHTVFGVAGLSLMGYDN")
        self.assertEqual(str(motif.instances[12]), "GPFGGGPGQLSHLASTYAAINALSLCDNID")
        self.assertEqual(str(motif.instances[13]), "GGFQGRCNKLVDGCYSFWQAGLLPLLHRAL")
        self.assertEqual(str(motif.instances[14]), "RGFCGRSNKLVDGCYSFWVGGSAAILEAFG")
        self.assertEqual(str(motif.instances[15]), "GGLLDKPGKSRDFYHTCYCLSGLSIAQHFG")
        self.assertEqual(str(motif.instances[16]), "GGVSASIGHDPHLLYTLSAVQILTLYDSIH")
        self.assertEqual(str(motif.instances[17]), "GSFLMHVGGEVDVRSAYCAASVASLTNIIT")
        self.assertEqual(str(motif.instances[18]), "GAFAPFPRHDAHLLTTLSAVQILATYDALD")
        self.assertEqual(str(motif.instances[19]), "YNGAFGAHNEPHSGYTSCALSTLALLSSLE")
        self.assertEqual(str(motif.instances[20]), "GFKTCLEVGEVDTRGIYCALSIATLLNILT")
        self.assertEqual(str(motif.instances[21]), "GGFSKNDEEDADLYHSCLGSAALALIEGKF")
        self.assertEqual(str(motif.instances[22]), "PGLRDKPGAHSDFYHTNYCLLGLAVAESSY")
        self.assertEqual(str(motif.instances[23]), "HNFEYWLTEHLRLNGIYWGLTALCVLDSPE")
        motif = record[1]
        self.assertEqual(motif.name, "JNKEKLLEYILSCQ")
        self.assertEqual(record["JNKEKLLEYILSCQ"], motif)
        self.assertEqual(motif.num_occurrences, 21)
        self.assertAlmostEqual(motif.evalue, 3.1e-19)
        self.assertEqual(motif.alphabet, "ACDEFGHIKLMNPQRSTVWY")
        self.assertEqual(len(motif.instances), 21)
        self.assertAlmostEqual(motif.instances[0].pvalue, 2.71e-12)
        self.assertAlmostEqual(motif.instances[1].pvalue, 5.7e-12)
        self.assertAlmostEqual(motif.instances[2].pvalue, 6.43e-12)
        self.assertAlmostEqual(motif.instances[3].pvalue, 2.61e-11)
        self.assertAlmostEqual(motif.instances[4].pvalue, 6.3e-11)
        self.assertAlmostEqual(motif.instances[5].pvalue, 2.7e-10)
        self.assertAlmostEqual(motif.instances[6].pvalue, 4.03e-10)
        self.assertAlmostEqual(motif.instances[7].pvalue, 1.27e-09)
        self.assertAlmostEqual(motif.instances[8].pvalue, 3.17e-09)
        self.assertAlmostEqual(motif.instances[9].pvalue, 6.39e-09)
        self.assertAlmostEqual(motif.instances[10].pvalue, 6.96e-09)
        self.assertAlmostEqual(motif.instances[11].pvalue, 1.06e-08)
        self.assertAlmostEqual(motif.instances[12].pvalue, 1.26e-08)
        self.assertAlmostEqual(motif.instances[13].pvalue, 1.37e-08)
        self.assertAlmostEqual(motif.instances[14].pvalue, 2.07e-08)
        self.assertAlmostEqual(motif.instances[15].pvalue, 4.96e-08)
        self.assertAlmostEqual(motif.instances[16].pvalue, 1.15e-07)
        self.assertAlmostEqual(motif.instances[17].pvalue, 1.44e-07)
        self.assertAlmostEqual(motif.instances[18].pvalue, 1.55e-07)
        self.assertAlmostEqual(motif.instances[19].pvalue, 1.93e-07)
        self.assertAlmostEqual(motif.instances[20].pvalue, 5.2e-07)
        self.assertEqual(motif.instances[0].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[1].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[2].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[3].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[4].sequence_name, "CAL1_YEAST")
        self.assertEqual(motif.instances[5].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[6].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[7].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[8].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[9].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[10].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[11].sequence_name, "CAL1_YEAST")
        self.assertEqual(motif.instances[12].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[13].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[14].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[15].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[16].sequence_name, "RATRABGERB")
        self.assertEqual(motif.instances[17].sequence_name, "RAM1_YEAST")
        self.assertEqual(motif.instances[18].sequence_name, "PFTB_RAT")
        self.assertEqual(motif.instances[19].sequence_name, "BET2_YEAST")
        self.assertEqual(motif.instances[20].sequence_name, "CAL1_YEAST")
        self.assertEqual(motif.instances[0].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[1].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[2].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[3].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[4].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[5].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[6].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[7].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[8].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[9].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[10].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[11].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[12].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[13].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[14].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[15].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[16].sequence_id, "sequence_3")
        self.assertEqual(motif.instances[17].sequence_id, "sequence_0")
        self.assertEqual(motif.instances[18].sequence_id, "sequence_1")
        self.assertEqual(motif.instances[19].sequence_id, "sequence_2")
        self.assertEqual(motif.instances[20].sequence_id, "sequence_4")
        self.assertEqual(motif.instances[0].strand, "+")
        self.assertEqual(motif.instances[1].strand, "+")
        self.assertEqual(motif.instances[2].strand, "+")
        self.assertEqual(motif.instances[3].strand, "+")
        self.assertEqual(motif.instances[4].strand, "+")
        self.assertEqual(motif.instances[5].strand, "+")
        self.assertEqual(motif.instances[6].strand, "+")
        self.assertEqual(motif.instances[7].strand, "+")
        self.assertEqual(motif.instances[8].strand, "+")
        self.assertEqual(motif.instances[9].strand, "+")
        self.assertEqual(motif.instances[10].strand, "+")
        self.assertEqual(motif.instances[11].strand, "+")
        self.assertEqual(motif.instances[12].strand, "+")
        self.assertEqual(motif.instances[13].strand, "+")
        self.assertEqual(motif.instances[14].strand, "+")
        self.assertEqual(motif.instances[15].strand, "+")
        self.assertEqual(motif.instances[16].strand, "+")
        self.assertEqual(motif.instances[17].strand, "+")
        self.assertEqual(motif.instances[18].strand, "+")
        self.assertEqual(motif.instances[19].strand, "+")
        self.assertEqual(motif.instances[20].strand, "+")
        self.assertEqual(motif.instances[0].length, 14)
        self.assertEqual(motif.instances[1].length, 14)
        self.assertEqual(motif.instances[2].length, 14)
        self.assertEqual(motif.instances[3].length, 14)
        self.assertEqual(motif.instances[4].length, 14)
        self.assertEqual(motif.instances[5].length, 14)
        self.assertEqual(motif.instances[6].length, 14)
        self.assertEqual(motif.instances[7].length, 14)
        self.assertEqual(motif.instances[8].length, 14)
        self.assertEqual(motif.instances[9].length, 14)
        self.assertEqual(motif.instances[10].length, 14)
        self.assertEqual(motif.instances[11].length, 14)
        self.assertEqual(motif.instances[12].length, 14)
        self.assertEqual(motif.instances[13].length, 14)
        self.assertEqual(motif.instances[14].length, 14)
        self.assertEqual(motif.instances[15].length, 14)
        self.assertEqual(motif.instances[16].length, 14)
        self.assertEqual(motif.instances[17].length, 14)
        self.assertEqual(motif.instances[18].length, 14)
        self.assertEqual(motif.instances[19].length, 14)
        self.assertEqual(motif.instances[20].length, 14)
        self.assertEqual(motif.instances[0].start, 66)
        self.assertEqual(motif.instances[1].start, 254)
        self.assertEqual(motif.instances[2].start, 258)
        self.assertEqual(motif.instances[3].start, 162)
        self.assertEqual(motif.instances[4].start, 190)
        self.assertEqual(motif.instances[5].start, 278)
        self.assertEqual(motif.instances[6].start, 172)
        self.assertEqual(motif.instances[7].start, 114)
        self.assertEqual(motif.instances[8].start, 7)
        self.assertEqual(motif.instances[9].start, 268)
        self.assertEqual(motif.instances[10].start, 414)
        self.assertEqual(motif.instances[11].start, 126)
        self.assertEqual(motif.instances[12].start, 220)
        self.assertEqual(motif.instances[13].start, 55)
        self.assertEqual(motif.instances[14].start, 229)
        self.assertEqual(motif.instances[15].start, 330)
        self.assertEqual(motif.instances[16].start, 18)
        self.assertEqual(motif.instances[17].start, 180)
        self.assertEqual(motif.instances[18].start, 73)
        self.assertEqual(motif.instances[19].start, 107)
        self.assertEqual(motif.instances[20].start, 36)
        self.assertEqual(str(motif.instances[0]), "MNKEEILVFIKSCQ")
        self.assertEqual(str(motif.instances[1]), "INYEKLTEFILKCQ")
        self.assertEqual(str(motif.instances[2]), "IDREKLRSFILACQ")
        self.assertEqual(str(motif.instances[3]), "INVEKAIEFVLSCM")
        self.assertEqual(str(motif.instances[4]), "IDTEKLLGYIMSQQ")
        self.assertEqual(str(motif.instances[5]), "INVEKLLEWSSARQ")
        self.assertEqual(str(motif.instances[6]), "INREKLLQYLYSLK")
        self.assertEqual(str(motif.instances[7]), "INVDKVVAYVQSLQ")
        self.assertEqual(str(motif.instances[8]), "LLKEKHIRYIESLD")
        self.assertEqual(str(motif.instances[9]), "LNLKSLLQWVTSRQ")
        self.assertEqual(str(motif.instances[10]), "ENVRKIIHYFKSNL")
        self.assertEqual(str(motif.instances[11]), "LDKRSLARFVSKCQ")
        self.assertEqual(str(motif.instances[12]), "DLFEGTAEWIARCQ")
        self.assertEqual(str(motif.instances[13]), "FVKEEVISFVLSCW")
        self.assertEqual(str(motif.instances[14]), "ELTEGVLNYLKNCQ")
        self.assertEqual(str(motif.instances[15]), "FNKHALRDYILYCC")
        self.assertEqual(str(motif.instances[16]), "LLLEKHADYIASYG")
        self.assertEqual(str(motif.instances[17]), "IDRKGIYQWLISLK")
        self.assertEqual(str(motif.instances[18]), "LQREKHFHYLKRGL")
        self.assertEqual(str(motif.instances[19]), "DRKVRLISFIRGNQ")
        self.assertEqual(str(motif.instances[20]), "VNRMAIIFYSISGL")

    def test_minimal_meme_parser(self):
        """Parse motifs/minimal_test.meme file."""
        with open("motifs/minimal_test.meme") as handle:
            record = motifs.parse(handle, "minimal")
        self.assertEqual(record.version, "4")
        self.assertEqual(record.alphabet, "ACGT")
        self.assertEqual(len(record.sequences), 0)
        self.assertEqual(record.command, "")
        self.assertEqual(len(record), 2)
        motif = record[0]
        self.assertEqual(motif.name, "KRP")
        self.assertEqual(record["KRP"], motif)
        self.assertEqual(motif.num_occurrences, 17)
        self.assertEqual(motif.length, 19)
        self.assertEqual(str(motif.consensus), "TGTGATCGAGGTCACACTT")
        self.assertAlmostEqual(motif.background["A"], 0.30269730269730266)
        self.assertAlmostEqual(motif.background["C"], 0.1828171828171828)
        self.assertAlmostEqual(motif.background["G"], 0.20879120879120877)
        self.assertAlmostEqual(motif.background["T"], 0.30569430569430567)
        self.assertAlmostEqual(motif.evalue, 4.1e-09)
        self.assertEqual(motif.alphabet, "ACGT")
        self.assertIsNone(motif.instances)

    def test_meme_parser_rna(self):
        """Test if Bio.motifs can parse MEME output files using RNA."""
        pass


class TestMAST(unittest.TestCase):
    """MAST format tests."""

    def test_mast_parser_1(self):
        """Parse motifs/mast.crp0.de.oops.txt.xml file."""
        with open("motifs/mast.crp0.de.oops.txt.xml") as handle:
            record = motifs.parse(handle, "MAST")
        self.assertEqual(record.version, "5.0.1")
        self.assertEqual(record.database, "common/crp0.s")
        self.assertEqual(record.alphabet, "DNA")
        self.assertEqual(len(record), 2)
        self.assertEqual(record["1"].name, "1")
        self.assertEqual(record["2"].name, "2")
        self.assertEqual(record[0].alphabet, "DNA")
        self.assertEqual(record[0].length, 12)
        self.assertEqual(record[0].name, "1")
        self.assertEqual(record[1].alphabet, "DNA")
        self.assertEqual(record[1].length, 12)
        self.assertEqual(record[1].name, "2")
        self.assertEqual(len(record.sequences), 18)
        self.assertEqual(record.sequences[0], "lac")
        self.assertEqual(record.sequences[1], "bglr1")
        self.assertEqual(record.sequences[2], "tdc")
        self.assertEqual(record.sequences[3], "deop2")
        self.assertEqual(record.sequences[4], "pbr322")
        self.assertEqual(record.sequences[5], "malk")
        self.assertEqual(record.sequences[6], "tnaa")
        self.assertEqual(record.sequences[7], "male")
        self.assertEqual(record.sequences[8], "ara")
        self.assertEqual(record.sequences[9], "cya")
        self.assertEqual(record.sequences[10], "ompa")
        self.assertEqual(record.sequences[11], "ilv")
        self.assertEqual(record.sequences[12], "gale")
        self.assertEqual(record.sequences[13], "malt")
        self.assertEqual(record.sequences[14], "crp")
        self.assertEqual(record.sequences[15], "ce1cg")
        self.assertEqual(record.sequences[16], "trn9cat")
        self.assertEqual(record.sequences[17], "uxu1")
        self.assertEqual(record.diagrams["lac"], "[+1]-2-[-2]-79")
        self.assertEqual(record.diagrams["bglr1"], "79-[+2]-14")
        self.assertEqual(record.diagrams["tdc"], "30-[+1]-39-[+2]-12")
        self.assertEqual(record.diagrams["deop2"], "19-[+1]-74")
        self.assertEqual(record.diagrams["pbr322"], "58-[-2]-35")
        self.assertEqual(record.diagrams["malk"], "32-[+2]-61")
        self.assertEqual(record.diagrams["tnaa"], "105")
        self.assertEqual(record.diagrams["male"], "105")
        self.assertEqual(record.diagrams["ara"], "105")
        self.assertEqual(record.diagrams["cya"], "105")
        self.assertEqual(record.diagrams["ompa"], "105")
        self.assertEqual(record.diagrams["ilv"], "105")
        self.assertEqual(record.diagrams["gale"], "105")
        self.assertEqual(record.diagrams["malt"], "105")
        self.assertEqual(record.diagrams["crp"], "105")
        self.assertEqual(record.diagrams["ce1cg"], "105")
        self.assertEqual(record.diagrams["trn9cat"], "105")
        self.assertEqual(record.diagrams["uxu1"], "105")

    def test_mast_parser_2(self):
        """Parse motifs/mast.adh.de.oops.html.xml file."""
        with open("motifs/mast.adh.de.oops.html.xml") as handle:
            record = motifs.parse(handle, "MAST")
        self.assertEqual(record.version, "5.0.1")
        self.assertEqual(record.database, "common/adh.s")
        self.assertEqual(record.alphabet, "Protein")
        self.assertEqual(len(record), 2)
        self.assertEqual(record["1"].name, "1")
        self.assertEqual(record["2"].name, "2")
        self.assertEqual(record[0].alphabet, "Protein")
        self.assertEqual(record[0].length, 12)
        self.assertEqual(record[0].name, "1")
        self.assertEqual(record[1].alphabet, "Protein")
        self.assertEqual(record[1].length, 12)
        self.assertEqual(record[1].name, "2")
        self.assertEqual(len(record.sequences), 33)
        self.assertEqual(record.sequences[0], "ENTA_ECOLI")
        self.assertEqual(record.sequences[1], "DHII_HUMAN")
        self.assertEqual(record.sequences[2], "YINL_LISMO")
        self.assertEqual(record.sequences[3], "FIXR_BRAJA")
        self.assertEqual(record.sequences[4], "HDHA_ECOLI")
        self.assertEqual(record.sequences[5], "BUDC_KLETE")
        self.assertEqual(record.sequences[6], "AP27_MOUSE")
        self.assertEqual(record.sequences[7], "FVT1_HUMAN")
        self.assertEqual(record.sequences[8], "YRTP_BACSU")
        self.assertEqual(record.sequences[9], "DHMA_FLAS1")
        self.assertEqual(record.sequences[10], "HDE_CANTR")
        self.assertEqual(record.sequences[11], "3BHD_COMTE")
        self.assertEqual(record.sequences[12], "BDH_HUMAN")
        self.assertEqual(record.sequences[13], "2BHD_STREX")
        self.assertEqual(record.sequences[14], "BA72_EUBSP")
        self.assertEqual(record.sequences[15], "RIDH_KLEAE")
        self.assertEqual(record.sequences[16], "DHGB_BACME")
        self.assertEqual(record.sequences[17], "PCR_PEA")
        self.assertEqual(record.sequences[18], "RFBB_NEIGO")
        self.assertEqual(record.sequences[19], "BPHB_PSEPS")
        self.assertEqual(record.sequences[20], "DHB2_HUMAN")
        self.assertEqual(record.sequences[21], "NODG_RHIME")
        self.assertEqual(record.sequences[22], "MAS1_AGRRA")
        self.assertEqual(record.sequences[23], "DHCA_HUMAN")
        self.assertEqual(record.sequences[24], "DHES_HUMAN")
        self.assertEqual(record.sequences[25], "DHB3_HUMAN")
        self.assertEqual(record.sequences[26], "HMTR_LEIMA")
        self.assertEqual(record.sequences[27], "ADH_DROME")
        self.assertEqual(record.sequences[28], "YURA_MYXXA")
        self.assertEqual(record.sequences[29], "LIGD_PSEPA")
        self.assertEqual(record.sequences[30], "FABI_ECOLI")
        self.assertEqual(record.sequences[31], "GUTD_ECOLI")
        self.assertEqual(record.sequences[32], "CSGA_MYXXA")
        self.assertEqual(record.diagrams["ENTA_ECOLI"], "[1]-[2]-224")
        self.assertEqual(record.diagrams["DHII_HUMAN"], "29-[1]-[2]-239")
        self.assertEqual(record.diagrams["YINL_LISMO"], "[1]-[2]-224")
        self.assertEqual(record.diagrams["FIXR_BRAJA"], "43-[2]-149-[1]-62")
        self.assertEqual(record.diagrams["HDHA_ECOLI"], "6-[1]-[2]-144-[1]-69")
        self.assertEqual(record.diagrams["BUDC_KLETE"], "9-[2]-53-[1]-81-[1]-62")
        self.assertEqual(record.diagrams["AP27_MOUSE"], "2-[1]-[2]-138-[1]-68")
        self.assertEqual(record.diagrams["FVT1_HUMAN"], "39-[2]-150-[1]-119")
        self.assertEqual(record.diagrams["YRTP_BACSU"], "1-[1]-[2]-145-[1]-56")
        self.assertEqual(record.diagrams["DHMA_FLAS1"], "9-[1]-[2]-147-[1]-78")
        self.assertEqual(record.diagrams["HDE_CANTR"], "3-[1]-[2]-290-[1]-[2]-565")
        self.assertEqual(record.diagrams["3BHD_COMTE"], "1-[1]-[2]-50-[1]-166")
        self.assertEqual(record.diagrams["BDH_HUMAN"], "50-[1]-[2]-269")
        self.assertEqual(record.diagrams["2BHD_STREX"], "1-[1]-[2]-142-[1]-76")
        self.assertEqual(record.diagrams["BA72_EUBSP"], "1-[1]-[2]-125-[2]-10-[1]-65")
        self.assertEqual(record.diagrams["RIDH_KLEAE"], "9-[1]-[2]-216")
        self.assertEqual(record.diagrams["DHGB_BACME"], "2-[1]-[2]-149-[1]-75")
        self.assertEqual(record.diagrams["PCR_PEA"], "81-[1]-[2]-108-[1]-174")
        self.assertEqual(record.diagrams["RFBB_NEIGO"], "1-[1]-[2]-321")
        self.assertEqual(record.diagrams["BPHB_PSEPS"], "[1]-[2]-251")
        self.assertEqual(record.diagrams["DHB2_HUMAN"], "77-[1]-[2]-286")
        self.assertEqual(record.diagrams["NODG_RHIME"], "1-[1]-[2]-142-[1]-66")
        self.assertEqual(record.diagrams["MAS1_AGRRA"], "252-[2]-36-[1]-164")
        self.assertEqual(record.diagrams["DHCA_HUMAN"], "11-[2]-54-[1]-101-[1]-74")
        self.assertEqual(record.diagrams["DHES_HUMAN"], "9-[2]-108-[1]-186")
        self.assertEqual(record.diagrams["DHB3_HUMAN"], "55-[2]-146-[1]-85")
        self.assertEqual(record.diagrams["HMTR_LEIMA"], "24-[2]-172-[1]-67")
        self.assertEqual(record.diagrams["ADH_DROME"], "13-[2]-217-[1]-1")
        self.assertEqual(record.diagrams["YURA_MYXXA"], "94-[2]-69-[1]-71")
        self.assertEqual(record.diagrams["LIGD_PSEPA"], "1-[1]-[2]-280")
        self.assertEqual(record.diagrams["FABI_ECOLI"], "1-[1]-161-[1]-76")
        self.assertEqual(record.diagrams["GUTD_ECOLI"], "147-[2]-10-[1]-78")
        self.assertEqual(record.diagrams["CSGA_MYXXA"], "12-[1]-53-[2]-77")

    def test_mast_parser_3(self):
        """Parse motifs/mast.Klf1-200.cd.oops.xml.xml file."""
        with open("motifs/mast.Klf1-200.cd.oops.xml.xml") as handle:
            record = motifs.parse(handle, "MAST")
        self.assertEqual(record.version, "5.0.1")
        self.assertEqual(record.database, "common/Klf1-200.fa")
        self.assertEqual(record.alphabet, "DNA")
        self.assertEqual(len(record), 2)
        self.assertEqual(record["1"].name, "1")
        self.assertEqual(record["2"].name, "2")
        self.assertEqual(record[0].alphabet, "DNA")
        self.assertEqual(record[0].length, 20)
        self.assertEqual(record[0].name, "1")
        self.assertEqual(record[1].alphabet, "DNA")
        self.assertEqual(record[1].length, 30)
        self.assertEqual(record[1].name, "2")
        self.assertEqual(len(record.sequences), 113)
        self.assertEqual(record.sequences[0], "chr3:104843905-104844405")
        self.assertEqual(record.sequences[1], "chr12:114390660-114391160")
        self.assertEqual(record.sequences[2], "chr12:27135944-27136444")
        self.assertEqual(record.sequences[3], "chr10:59256089-59256589")
        self.assertEqual(record.sequences[4], "chr4:135733850-135734350")
        self.assertEqual(record.sequences[5], "chr1:137838164-137838664")
        self.assertEqual(record.sequences[6], "chr17:47735006-47735506")
        self.assertEqual(record.sequences[7], "chr6:72223026-72223526")
        self.assertEqual(record.sequences[8], "chr13:3866266-3866766")
        self.assertEqual(record.sequences[9], "chr1:133343883-133344383")
        self.assertEqual(record.sequences[10], "chr11:117187372-117187872")
        self.assertEqual(record.sequences[11], "chr13:76003199-76003699")
        self.assertEqual(record.sequences[12], "chr5:65202593-65203093")
        self.assertEqual(record.sequences[13], "chr14:79702844-79703344")
        self.assertEqual(record.sequences[14], "chr12:112796794-112797294")
        self.assertEqual(record.sequences[15], "chr13:112863645-112864145")
        self.assertEqual(record.sequences[16], "chr7:111007530-111008030")
        self.assertEqual(record.sequences[17], "chr1:43307690-43308190")
        self.assertEqual(record.sequences[18], "chr14:47973722-47974222")
        self.assertEqual(record.sequences[19], "chr9:120025371-120025871")
        self.assertEqual(record.sequences[20], "chr7:105490727-105491227")
        self.assertEqual(record.sequences[21], "chr5:37127175-37127675")
        self.assertEqual(record.sequences[22], "chr5:45951565-45952065")
        self.assertEqual(record.sequences[23], "chr7:91033422-91033922")
        self.assertEqual(record.sequences[24], "chr4:154285745-154286245")
        self.assertEqual(record.sequences[25], "chr13:100518008-100518508")
        self.assertEqual(record.sequences[26], "chr1:36977019-36977519")
        self.assertEqual(record.sequences[27], "chr7:151917814-151918314")
        self.assertEqual(record.sequences[28], "chr7:110976195-110976695")
        self.assertEqual(record.sequences[29], "chr15:58719281-58719781")
        self.assertEqual(record.sequences[30], "chr11:57590460-57590960")
        self.assertEqual(record.sequences[31], "chr8:83025150-83025650")
        self.assertEqual(record.sequences[32], "chr13:54345922-54346422")
        self.assertEqual(record.sequences[33], "chr12:82044358-82044858")
        self.assertEqual(record.sequences[34], "chr11:105013714-105014214")
        self.assertEqual(record.sequences[35], "chr10:93585404-93585904")
        self.assertEqual(record.sequences[36], "chr7:19832207-19832707")
        self.assertEqual(record.sequences[37], "chr8:97323995-97324495")
        self.assertEqual(record.sequences[38], "chr10:126642277-126642777")
        self.assertEqual(record.sequences[39], "chr1:156887119-156887619")
        self.assertEqual(record.sequences[40], "chr15:81700367-81700867")
        self.assertEqual(record.sequences[41], "chr6:121187425-121187925")
        self.assertEqual(record.sequences[42], "chr4:43977111-43977611")
        self.assertEqual(record.sequences[43], "chr11:102236405-102236905")
        self.assertEqual(record.sequences[44], "chr17:5112057-5112557")
        self.assertEqual(record.sequences[45], "chr10:110604369-110604869")
        self.assertEqual(record.sequences[46], "chr1:169314208-169314708")
        self.assertEqual(record.sequences[47], "chr9:57618594-57619094")
        self.assertEqual(record.sequences[48], "chr10:128184604-128185104")
        self.assertEqual(record.sequences[49], "chr4:109112541-109113041")
        self.assertEqual(record.sequences[50], "chr3:97461668-97462168")
        self.assertEqual(record.sequences[51], "chr9:102674395-102674895")
        self.assertEqual(record.sequences[52], "chr17:24289205-24289705")
        self.assertEqual(record.sequences[53], "chr17:28960252-28960752")
        self.assertEqual(record.sequences[54], "chr2:73323093-73323593")
        self.assertEqual(record.sequences[55], "chr11:32150818-32151318")
        self.assertEqual(record.sequences[56], "chr7:103853792-103854292")
        self.assertEqual(record.sequences[57], "chr16:49839621-49840121")
        self.assertEqual(record.sequences[58], "chr6:135115628-135116128")
        self.assertEqual(record.sequences[59], "chr3:88305500-88306000")
        self.assertEqual(record.sequences[60], "chr18:57137388-57137888")
        self.assertEqual(record.sequences[61], "chr5:97380648-97381148")
        self.assertEqual(record.sequences[62], "chr15:91082416-91082916")
        self.assertEqual(record.sequences[63], "chr14:61272713-61273213")
        self.assertEqual(record.sequences[64], "chr5:33616214-33616714")
        self.assertEqual(record.sequences[65], "chr18:23982470-23982970")
        self.assertEqual(record.sequences[66], "chr9:24715045-24715545")
        self.assertEqual(record.sequences[67], "chr10:116195445-116195945")
        self.assertEqual(record.sequences[68], "chr11:77795184-77795684")
        self.assertEqual(record.sequences[69], "chr16:32508975-32509475")
        self.assertEqual(record.sequences[70], "chr18:80416880-80417380")
        self.assertEqual(record.sequences[71], "chr10:57252236-57252736")
        self.assertEqual(record.sequences[72], "chr5:34915767-34916267")
        self.assertEqual(record.sequences[73], "chr9:98389943-98390443")
        self.assertEqual(record.sequences[74], "chr19:5845899-5846399")
        self.assertEqual(record.sequences[75], "chr3:151777796-151778296")
        self.assertEqual(record.sequences[76], "chr4:76585120-76585620")
        self.assertEqual(record.sequences[77], "chr7:104332488-104332988")
        self.assertEqual(record.sequences[78], "chr5:138127197-138127697")
        self.assertEqual(record.sequences[79], "chr11:60988820-60989320")
        self.assertEqual(record.sequences[80], "chr8:19984030-19984530")
        self.assertEqual(record.sequences[81], "chr11:31712262-31712762")
        self.assertEqual(record.sequences[82], "chr15:41338514-41339014")
        self.assertEqual(record.sequences[83], "chr9:21362671-21363171")
        self.assertEqual(record.sequences[84], "chr18:58822702-58823202")
        self.assertEqual(record.sequences[85], "chr1:173447614-173448114")
        self.assertEqual(record.sequences[86], "chr6:81915769-81916269")
        self.assertEqual(record.sequences[87], "chr1:169322898-169323398")
        self.assertEqual(record.sequences[88], "chr12:70860461-70860961")
        self.assertEqual(record.sequences[89], "chr9:59598186-59598686")
        self.assertEqual(record.sequences[90], "chr3:19550495-19550995")
        self.assertEqual(record.sequences[91], "chr7:36132953-36133453")
        self.assertEqual(record.sequences[92], "chr7:38970375-38970875")
        self.assertEqual(record.sequences[93], "chr15:78243390-78243890")
        self.assertEqual(record.sequences[94], "chr7:87847381-87847881")
        self.assertEqual(record.sequences[95], "chr1:33631214-33631714")
        self.assertEqual(record.sequences[96], "chr4:135407873-135408373")
        self.assertEqual(record.sequences[97], "chr7:101244829-101245329")
        self.assertEqual(record.sequences[98], "chr10:60612190-60612690")
        self.assertEqual(record.sequences[99], "chr19:56465963-56466463")
        self.assertEqual(record.sequences[100], "chr4:41334759-41335259")
        self.assertEqual(record.sequences[101], "chr8:92969521-92970021")
        self.assertEqual(record.sequences[102], "chr6:145703215-145703715")
        self.assertEqual(record.sequences[103], "chr13:57679178-57679678")
        self.assertEqual(record.sequences[104], "chr19:45121628-45122128")
        self.assertEqual(record.sequences[105], "chr15:79757891-79758391")
        self.assertEqual(record.sequences[106], "chr1:134264178-134264678")
        self.assertEqual(record.sequences[107], "chr13:81067500-81068000")
        self.assertEqual(record.sequences[108], "chr11:69714224-69714724")
        self.assertEqual(record.sequences[109], "chr2:103728071-103728571")
        self.assertEqual(record.sequences[110], "chr5:105994747-105995247")
        self.assertEqual(record.sequences[111], "chr17:84209565-84210065")
        self.assertEqual(record.sequences[112], "chr7:16507689-16508189")
        self.assertEqual(
            record.diagrams["chr3:104843905-104844405"], "115-[-1]-209-[-2]-126"
        )
        self.assertEqual(
            record.diagrams["chr12:114390660-114391160"],
            "3-[+2]-[+2]-3-[+1]-173-[+1]-3-[-2]-188",
        )
        self.assertEqual(
            record.diagrams["chr12:27135944-27136444"], "275-[-1]-89-[+2]-4-[+2]-52"
        )
        self.assertEqual(
            record.diagrams["chr10:59256089-59256589"], "247-[+2]-17-[-1]-186"
        )
        self.assertEqual(
            record.diagrams["chr4:135733850-135734350"], "183-[-1]-263-[+2]-4"
        )
        self.assertEqual(
            record.diagrams["chr1:137838164-137838664"], "192-[-2]-1-[+1]-44-[-1]-193"
        )
        self.assertEqual(
            record.diagrams["chr17:47735006-47735506"], "203-[+2]-15-[+1]-97-[-1]-115"
        )
        self.assertEqual(
            record.diagrams["chr6:72223026-72223526"],
            "52-[-2]-7-[+2]-162-[-1]-42-[-1]-137",
        )
        self.assertEqual(
            record.diagrams["chr13:3866266-3866766"], "241-[+1]-2-[-1]-217"
        )
        self.assertEqual(
            record.diagrams["chr1:133343883-133344383"], "190-[+2]-15-[+1]-245"
        )
        self.assertEqual(
            record.diagrams["chr11:117187372-117187872"], "242-[+1]-46-[-2]-71-[+1]-71"
        )
        self.assertEqual(
            record.diagrams["chr13:76003199-76003699"], "230-[+2]-15-[+2]-60-[-1]-115"
        )
        self.assertEqual(
            record.diagrams["chr5:65202593-65203093"],
            "24-[-2]-36-[+2]-193-[-1]-11-[+1]-10-[+1]-106",
        )
        self.assertEqual(
            record.diagrams["chr14:79702844-79703344"], "247-[-1]-46-[-2]-157"
        )
        self.assertEqual(
            record.diagrams["chr12:112796794-112797294"], "232-[+1]-41-[+1]-187"
        )
        self.assertEqual(
            record.diagrams["chr13:112863645-112864145"], "228-[+1]-20-[-1]-212"
        )
        self.assertEqual(
            record.diagrams["chr7:111007530-111008030"], "217-[+1]-83-[+2]-150"
        )
        self.assertEqual(
            record.diagrams["chr1:43307690-43308190"], "164-[-2]-52-[-2]-224"
        )
        self.assertEqual(
            record.diagrams["chr14:47973722-47974222"], "21-[+1]-181-[+1]-20-[-2]-208"
        )
        self.assertEqual(
            record.diagrams["chr9:120025371-120025871"], "110-[-2]-58-[+1]-282"
        )
        self.assertEqual(
            record.diagrams["chr7:105490727-105491227"], "100-[-2]-111-[-1]-239"
        )
        self.assertEqual(
            record.diagrams["chr5:37127175-37127675"], "234-[-2]-24-[+1]-192"
        )
        self.assertEqual(record.diagrams["chr5:45951565-45952065"], "261-[-1]-219")
        self.assertEqual(record.diagrams["chr7:91033422-91033922"], "465-[-1]-15")
        self.assertEqual(
            record.diagrams["chr4:154285745-154286245"], "235-[+1]-20-[-2]-195"
        )
        self.assertEqual(
            record.diagrams["chr13:100518008-100518508"], "226-[-2]-18-[-1]-206"
        )
        self.assertEqual(
            record.diagrams["chr1:36977019-36977519"], "88-[+1]-187-[+2]-60-[-1]-95"
        )
        self.assertEqual(
            record.diagrams["chr7:151917814-151918314"], "219-[+1]-80-[+2]-151"
        )
        self.assertEqual(
            record.diagrams["chr7:110976195-110976695"], "287-[+2]-12-[+1]-151"
        )
        self.assertEqual(record.diagrams["chr15:58719281-58719781"], "212-[-2]-258")
        self.assertEqual(
            record.diagrams["chr11:57590460-57590960"], "56-[-1]-271-[-1]-75-[+2]-28"
        )
        self.assertEqual(
            record.diagrams["chr8:83025150-83025650"], "219-[+1]-87-[+2]-144"
        )
        self.assertEqual(
            record.diagrams["chr13:54345922-54346422"], "283-[-2]-161-[+1]-6"
        )
        self.assertEqual(
            record.diagrams["chr12:82044358-82044858"], "50-[+2]-160-[+1]-39-[+2]-171"
        )
        self.assertEqual(
            record.diagrams["chr11:105013714-105014214"],
            "115-[-2]-160-[+1]-26-[-1]-129",
        )
        self.assertEqual(
            record.diagrams["chr10:93585404-93585904"], "141-[+2]-48-[+1]-261"
        )
        self.assertEqual(record.diagrams["chr7:19832207-19832707"], "229-[-1]-251")
        self.assertEqual(
            record.diagrams["chr8:97323995-97324495"], "177-[-1]-40-[-2]-139-[+1]-74"
        )
        self.assertEqual(
            record.diagrams["chr10:126642277-126642777"], "252-[-1]-92-[-2]-106"
        )
        self.assertEqual(
            record.diagrams["chr1:156887119-156887619"], "189-[-2]-78-[-1]-183"
        )
        self.assertEqual(
            record.diagrams["chr15:81700367-81700867"], "109-[-1]-99-[-1]-252"
        )
        self.assertEqual(
            record.diagrams["chr6:121187425-121187925"], "29-[+2]-313-[-1]-108"
        )
        self.assertEqual(
            record.diagrams["chr4:43977111-43977611"], "60-[+1]-148-[+1]-252"
        )
        self.assertEqual(
            record.diagrams["chr11:102236405-102236905"],
            "10-[+2]-145-[-1]-3-[-1]-6-[+2]-60-[+1]-156",
        )
        self.assertEqual(record.diagrams["chr17:5112057-5112557"], "249-[+1]-231")
        self.assertEqual(record.diagrams["chr10:110604369-110604869"], "232-[+1]-248")
        self.assertEqual(
            record.diagrams["chr1:169314208-169314708"], "192-[-1]-[-1]-11-[-2]-227"
        )
        self.assertEqual(
            record.diagrams["chr9:57618594-57619094"], "125-[+2]-151-[-1]-4-[-1]-150"
        )
        self.assertEqual(
            record.diagrams["chr10:128184604-128185104"], "30-[-2]-128-[+1]-292"
        )
        self.assertEqual(
            record.diagrams["chr4:109112541-109113041"], "21-[-1]-13-[+1]-94-[+2]-302"
        )
        self.assertEqual(
            record.diagrams["chr3:97461668-97462168"],
            "18-[+2]-256-[-1]-81-[+1]-21-[+1]-34",
        )
        self.assertEqual(record.diagrams["chr9:102674395-102674895"], "372-[+2]-98")
        self.assertEqual(record.diagrams["chr17:24289205-24289705"], "262-[-1]-218")
        self.assertEqual(
            record.diagrams["chr17:28960252-28960752"], "221-[+1]-81-[+1]-158"
        )
        self.assertEqual(record.diagrams["chr2:73323093-73323593"], "49-[-2]-421")
        self.assertEqual(
            record.diagrams["chr11:32150818-32151318"], "151-[-1]-27-[-1]-118-[-2]-134"
        )
        self.assertEqual(
            record.diagrams["chr7:103853792-103854292"], "212-[-2]-42-[+1]-196"
        )
        self.assertEqual(
            record.diagrams["chr16:49839621-49840121"], "192-[+2]-47-[-1]-17-[+2]-164"
        )
        self.assertEqual(record.diagrams["chr6:135115628-135116128"], "231-[-1]-249")
        self.assertEqual(record.diagrams["chr3:88305500-88306000"], "229-[+1]-251")
        self.assertEqual(record.diagrams["chr18:57137388-57137888"], "296-[+2]-174")
        self.assertEqual(record.diagrams["chr5:97380648-97381148"], "188-[-2]-282")
        self.assertEqual(
            record.diagrams["chr15:91082416-91082916"], "239-[-1]-104-[-1]-73-[+2]-14"
        )
        self.assertEqual(
            record.diagrams["chr14:61272713-61273213"], "216-[+2]-104-[+1]-130"
        )
        self.assertEqual(record.diagrams["chr5:33616214-33616714"], "247-[-1]-233")
        self.assertEqual(record.diagrams["chr18:23982470-23982970"], "285-[-1]-195")
        self.assertEqual(
            record.diagrams["chr9:24715045-24715545"], "214-[-1]-153-[+1]-93"
        )
        self.assertEqual(record.diagrams["chr10:116195445-116195945"], "400-[+2]-70")
        self.assertEqual(
            record.diagrams["chr11:77795184-77795684"], "247-[+1]-42-[-2]-67-[-2]-64"
        )
        self.assertEqual(
            record.diagrams["chr16:32508975-32509475"], "213-[+2]-29-[-1]-208"
        )
        self.assertEqual(record.diagrams["chr18:80416880-80417380"], "239-[-1]-241")
        self.assertEqual(
            record.diagrams["chr10:57252236-57252736"], "155-[+1]-158-[+2]-137"
        )
        self.assertEqual(
            record.diagrams["chr5:34915767-34916267"], "179-[+2]-29-[-1]-242"
        )
        self.assertEqual(record.diagrams["chr9:98389943-98390443"], "252-[-1]-228")
        self.assertEqual(
            record.diagrams["chr19:5845899-5846399"], "136-[+1]-193-[+1]-131"
        )
        self.assertEqual(
            record.diagrams["chr3:151777796-151778296"], "30-[-2]-58-[-1]-362"
        )
        self.assertEqual(record.diagrams["chr4:76585120-76585620"], "329-[+2]-141")
        self.assertEqual(
            record.diagrams["chr7:104332488-104332988"], "164-[+2]-23-[-1]-222-[+1]-21"
        )
        self.assertEqual(record.diagrams["chr5:138127197-138127697"], "238-[+1]-242")
        self.assertEqual(
            record.diagrams["chr11:60988820-60989320"], "115-[+1]-68-[+1]-47-[+1]-210"
        )
        self.assertEqual(
            record.diagrams["chr8:19984030-19984530"], "103-[-1]-81-[+2]-266"
        )
        self.assertEqual(
            record.diagrams["chr11:31712262-31712762"], "118-[+2]-53-[+2]-269"
        )
        self.assertEqual(
            record.diagrams["chr15:41338514-41339014"], "173-[+2]-75-[+2]-192"
        )
        self.assertEqual(
            record.diagrams["chr9:21362671-21363171"], "105-[+1]-131-[+1]-224"
        )
        self.assertEqual(record.diagrams["chr18:58822702-58823202"], "467-[-2]-3")
        self.assertEqual(record.diagrams["chr1:173447614-173448114"], "369-[-1]-111")
        self.assertEqual(record.diagrams["chr6:81915769-81916269"], "197-[+1]-283")
        self.assertEqual(record.diagrams["chr1:169322898-169323398"], "253-[-1]-227")
        self.assertEqual(
            record.diagrams["chr12:70860461-70860961"], "197-[+2]-22-[-1]-231"
        )
        self.assertEqual(
            record.diagrams["chr9:59598186-59598686"], "163-[-2]-10-[-1]-277"
        )
        self.assertEqual(record.diagrams["chr3:19550495-19550995"], "452-[-2]-18")
        self.assertEqual(record.diagrams["chr7:36132953-36133453"], "157-[-1]-323")
        self.assertEqual(
            record.diagrams["chr7:38970375-38970875"], "49-[+1]-114-[+1]-297"
        )
        self.assertEqual(record.diagrams["chr15:78243390-78243890"], "234-[+1]-246")
        self.assertEqual(
            record.diagrams["chr7:87847381-87847881"], "99-[+2]-2-[-1]-230-[-1]-99"
        )
        self.assertEqual(record.diagrams["chr1:33631214-33631714"], "358-[-1]-122")
        self.assertEqual(
            record.diagrams["chr4:135407873-135408373"], "116-[-1]-64-[+2]-270"
        )
        self.assertEqual(record.diagrams["chr7:101244829-101245329"], "311-[-2]-159")
        self.assertEqual(record.diagrams["chr10:60612190-60612690"], "215-[+1]-265")
        self.assertEqual(
            record.diagrams["chr19:56465963-56466463"], "306-[+1]-36-[+1]-18-[+1]-80"
        )
        self.assertEqual(record.diagrams["chr4:41334759-41335259"], "204-[+1]-276")
        self.assertEqual(record.diagrams["chr8:92969521-92970021"], "453-[+2]-17")
        self.assertEqual(
            record.diagrams["chr6:145703215-145703715"], "154-[-2]-58-[+2]-228"
        )
        self.assertEqual(record.diagrams["chr13:57679178-57679678"], "217-[-1]-263")
        self.assertEqual(record.diagrams["chr19:45121628-45122128"], "35-[-2]-435")
        self.assertEqual(record.diagrams["chr15:79757891-79758391"], "310-[+1]-170")
        self.assertEqual(record.diagrams["chr1:134264178-134264678"], "23-[+2]-447")
        self.assertEqual(record.diagrams["chr13:81067500-81068000"], "252-[+1]-228")
        self.assertEqual(record.diagrams["chr11:69714224-69714724"], "145-[+2]-325")
        self.assertEqual(record.diagrams["chr2:103728071-103728571"], "369-[+1]-111")
        self.assertEqual(
            record.diagrams["chr5:105994747-105995247"], "93-[+2]-153-[-2]-194"
        )
        self.assertEqual(record.diagrams["chr17:84209565-84210065"], "64-[-2]-406")
        self.assertEqual(record.diagrams["chr7:16507689-16508189"], "231-[+2]-239")


class TestTransfac(unittest.TestCase):
    """Transfac format tests."""

    def test_transfac_parser(self):
        """Parse motifs/transfac.dat file."""
        with open("motifs/transfac.dat") as handle:
            record = motifs.parse(handle, "TRANSFAC")
        motif = record[0]
        self.assertEqual(motif["ID"], "motif1")
        self.assertEqual(len(motif.counts), 4)
        self.assertEqual(motif.counts.length, 12)
        self.assertEqual(motif.counts["A", 0], 1)
        self.assertEqual(motif.counts["A", 1], 2)
        self.assertEqual(motif.counts["A", 2], 3)
        self.assertEqual(motif.counts["A", 3], 0)
        self.assertEqual(motif.counts["A", 4], 5)
        self.assertEqual(motif.counts["A", 5], 0)
        self.assertEqual(motif.counts["A", 6], 0)
        self.assertEqual(motif.counts["A", 7], 0)
        self.assertEqual(motif.counts["A", 8], 0)
        self.assertEqual(motif.counts["A", 9], 0)
        self.assertEqual(motif.counts["A", 10], 0)
        self.assertEqual(motif.counts["A", 11], 1)
        self.assertEqual(motif.counts["C", 0], 2)
        self.assertEqual(motif.counts["C", 1], 1)
        self.assertEqual(motif.counts["C", 2], 0)
        self.assertEqual(motif.counts["C", 3], 5)
        self.assertEqual(motif.counts["C", 4], 0)
        self.assertEqual(motif.counts["C", 5], 0)
        self.assertEqual(motif.counts["C", 6], 1)
        self.assertEqual(motif.counts["C", 7], 0)
        self.assertEqual(motif.counts["C", 8], 0)
        self.assertEqual(motif.counts["C", 9], 1)
        self.assertEqual(motif.counts["C", 10], 2)
        self.assertEqual(motif.counts["C", 11], 0)
        self.assertEqual(motif.counts["G", 0], 2)
        self.assertEqual(motif.counts["G", 1], 2)
        self.assertEqual(motif.counts["G", 2], 1)
        self.assertEqual(motif.counts["G", 3], 0)
        self.assertEqual(motif.counts["G", 4], 0)
        self.assertEqual(motif.counts["G", 5], 4)
        self.assertEqual(motif.counts["G", 6], 4)
        self.assertEqual(motif.counts["G", 7], 0)
        self.assertEqual(motif.counts["G", 8], 5)
        self.assertEqual(motif.counts["G", 9], 2)
        self.assertEqual(motif.counts["G", 10], 0)
        self.assertEqual(motif.counts["G", 11], 3)
        self.assertEqual(motif.counts["T", 0], 0)
        self.assertEqual(motif.counts["T", 1], 0)
        self.assertEqual(motif.counts["T", 2], 1)
        self.assertEqual(motif.counts["T", 3], 0)
        self.assertEqual(motif.counts["T", 4], 0)
        self.assertEqual(motif.counts["T", 5], 1)
        self.assertEqual(motif.counts["T", 6], 0)
        self.assertEqual(motif.counts["T", 7], 5)
        self.assertEqual(motif.counts["T", 8], 0)
        self.assertEqual(motif.counts["T", 9], 2)
        self.assertEqual(motif.counts["T", 10], 3)
        self.assertEqual(motif.counts["T", 11], 1)
        self.assertEqual(str(motif.counts.degenerate_consensus), "SRACAGGTGKYG")
        motif = record[1]
        self.assertEqual(motif["ID"], "motif2")
        self.assertEqual(len(motif.counts), 4)
        self.assertEqual(motif.counts.length, 10)
        self.assertEqual(motif.counts["A", 0], 2)
        self.assertEqual(motif.counts["A", 1], 1)
        self.assertEqual(motif.counts["A", 2], 0)
        self.assertEqual(motif.counts["A", 3], 3)
        self.assertEqual(motif.counts["A", 4], 0)
        self.assertEqual(motif.counts["A", 5], 5)
        self.assertEqual(motif.counts["A", 6], 0)
        self.assertEqual(motif.counts["A", 7], 0)
        self.assertEqual(motif.counts["A", 8], 0)
        self.assertEqual(motif.counts["A", 9], 0)
        self.assertEqual(motif.counts["C", 0], 1)
        self.assertEqual(motif.counts["C", 1], 2)
        self.assertEqual(motif.counts["C", 2], 5)
        self.assertEqual(motif.counts["C", 3], 0)
        self.assertEqual(motif.counts["C", 4], 0)
        self.assertEqual(motif.counts["C", 5], 0)
        self.assertEqual(motif.counts["C", 6], 1)
        self.assertEqual(motif.counts["C", 7], 0)
        self.assertEqual(motif.counts["C", 8], 0)
        self.assertEqual(motif.counts["C", 9], 2)
        self.assertEqual(motif.counts["G", 0], 2)
        self.assertEqual(motif.counts["G", 1], 2)
        self.assertEqual(motif.counts["G", 2], 0)
        self.assertEqual(motif.counts["G", 3], 1)
        self.assertEqual(motif.counts["G", 4], 4)
        self.assertEqual(motif.counts["G", 5], 0)
        self.assertEqual(motif.counts["G", 6], 4)
        self.assertEqual(motif.counts["G", 7], 5)
        self.assertEqual(motif.counts["G", 8], 0)
        self.assertEqual(motif.counts["G", 9], 0)
        self.assertEqual(motif.counts["T", 0], 0)
        self.assertEqual(motif.counts["T", 1], 0)
        self.assertEqual(motif.counts["T", 2], 0)
        self.assertEqual(motif.counts["T", 3], 1)
        self.assertEqual(motif.counts["T", 4], 1)
        self.assertEqual(motif.counts["T", 5], 0)
        self.assertEqual(motif.counts["T", 6], 0)
        self.assertEqual(motif.counts["T", 7], 0)
        self.assertEqual(motif.counts["T", 8], 5)
        self.assertEqual(motif.counts["T", 9], 3)
        self.assertEqual(str(motif.counts.degenerate_consensus), "RSCAGAGGTY")

    def test_permissive_transfac_parser(self):
        """Parse the TRANSFAC-like file motifs/MA0056.1.transfac."""
        # The test file MA0056.1.transfac was provided by the JASPAR database
        # in a TRANSFAC-like format
        # Khan, A. et al. JASPAR 2018: update of the open-access database of
        # transcription factor binding profiles and its web framework.
        # Nucleic Acids Res. 2018; 46:D260-D266,
        path = "motifs/MA0056.1.transfac"
        with open(path) as handle:
            self.assertRaises(ValueError, motifs.parse, handle, "TRANSFAC")
        with open(path) as handle:
            records = motifs.parse(handle, "TRANSFAC", strict=False)
        motif = records[0]
        self.assertEqual(sorted(motif.keys()), ["AC", "DE", "ID"])
        self.assertEqual(motif["AC"], "MA0056.1")
        self.assertEqual(motif["DE"], "MA0056.1 MZF1 ; From JASPAR 2018")
        self.assertEqual(motif["ID"], "MZF1")
        self.assertEqual(motif.counts.length, 6)
        self.assertEqual(len(motif.counts), 4)
        self.assertEqual(motif.counts["A", 0], 3.0)
        self.assertEqual(motif.counts["A", 1], 0.0)
        self.assertEqual(motif.counts["A", 2], 2.0)
        self.assertEqual(motif.counts["A", 3], 0.0)
        self.assertEqual(motif.counts["A", 4], 0.0)
        self.assertEqual(motif.counts["A", 5], 18.0)
        self.assertEqual(motif.counts["C", 0], 5.0)
        self.assertEqual(motif.counts["C", 1], 0.0)
        self.assertEqual(motif.counts["C", 2], 0.0)
        self.assertEqual(motif.counts["C", 3], 0.0)
        self.assertEqual(motif.counts["C", 4], 0.0)
        self.assertEqual(motif.counts["C", 5], 0.0)
        self.assertEqual(motif.counts["G", 0], 4.0)
        self.assertEqual(motif.counts["G", 1], 19.0)
        self.assertEqual(motif.counts["G", 2], 18.0)
        self.assertEqual(motif.counts["G", 3], 19.0)
        self.assertEqual(motif.counts["G", 4], 20.0)
        self.assertEqual(motif.counts["G", 5], 2.0)
        self.assertEqual(motif.counts["T", 0], 8.0)
        self.assertEqual(motif.counts["T", 1], 1.0)
        self.assertEqual(motif.counts["T", 2], 0.0)
        self.assertEqual(motif.counts["T", 3], 1.0)
        self.assertEqual(motif.counts["T", 4], 0.0)
        self.assertEqual(motif.counts["T", 5], 0.0)


class MotifTestPWM(unittest.TestCase):
    """PWM motif tests."""

    def setUp(self):
        """Define motif and sequence for tests."""
        with open("motifs/SRF.pfm") as handle:
            self.m = motifs.read(handle, "pfm")
        self.s = Seq("ACGTGTGCGTAGTGCGT")

    def test_simple(self):
        """Test if Bio.motifs PWM scoring works."""
        counts = self.m.counts
        pwm = counts.normalize(pseudocounts=0.25)
        pssm = pwm.log_odds()
        result = pssm.calculate(self.s)
        self.assertEqual(6, len(result))
        # The fast C-code in Bio/motifs/_pwm.c stores all results as 32-bit
        # floats; the slower Python code in Bio/motifs/__init__.py uses 64-bit
        # doubles. The C-code and Python code results will therefore not be
        # exactly equal. Test the first 5 decimal places only to avoid either
        # the C-code or the Python code to inadvertently fail this test.
        self.assertAlmostEqual(result[0], -29.18363571, places=5)
        self.assertAlmostEqual(result[1], -38.3365097, places=5)
        self.assertAlmostEqual(result[2], -29.17756271, places=5)
        self.assertAlmostEqual(result[3], -38.04542542, places=5)
        self.assertAlmostEqual(result[4], -20.3014183, places=5)
        self.assertAlmostEqual(result[5], -25.18009186, places=5)

    def test_with_mixed_case(self):
        """Test if Bio.motifs PWM scoring works with mixed case."""
        counts = self.m.counts
        pwm = counts.normalize(pseudocounts=0.25)
        pssm = pwm.log_odds()
        result = pssm.calculate(Seq("AcGTgTGCGtaGTGCGT"))
        self.assertEqual(6, len(result))
        self.assertAlmostEqual(result[0], -29.18363571, places=5)
        self.assertAlmostEqual(result[1], -38.3365097, places=5)
        self.assertAlmostEqual(result[2], -29.17756271, places=5)
        self.assertAlmostEqual(result[3], -38.04542542, places=5)
        self.assertAlmostEqual(result[4], -20.3014183, places=5)
        self.assertAlmostEqual(result[5], -25.18009186, places=5)

    def test_with_bad_char(self):
        """Test if Bio.motifs PWM scoring works with unexpected letters like N."""
        counts = self.m.counts
        pwm = counts.normalize(pseudocounts=0.25)
        pssm = pwm.log_odds()
        result = pssm.calculate(Seq("ACGTGTGCGTAGTGCGTN"))
        self.assertEqual(7, len(result))
        self.assertAlmostEqual(result[0], -29.18363571, places=5)
        self.assertAlmostEqual(result[1], -38.3365097, places=5)
        self.assertAlmostEqual(result[2], -29.17756271, places=5)
        self.assertAlmostEqual(result[3], -38.04542542, places=5)
        self.assertAlmostEqual(result[4], -20.3014183, places=5)
        self.assertAlmostEqual(result[5], -25.18009186, places=5)
        self.assertTrue(math.isnan(result[6]), "Expected nan, not %r" % result[6])

    def test_calculate_pseudocounts(self):
        pseudocounts = motifs.jaspar.calculate_pseudocounts(self.m)
        self.assertAlmostEqual(pseudocounts["A"], 1.695582495781317, places=5)
        self.assertAlmostEqual(pseudocounts["C"], 1.695582495781317, places=5)
        self.assertAlmostEqual(pseudocounts["G"], 1.695582495781317, places=5)
        self.assertAlmostEqual(pseudocounts["T"], 1.695582495781317, places=5)


if __name__ == "__main__":
    runner = unittest.TextTestRunner(verbosity=2)
    unittest.main(testRunner=runner)