Update tests.
[lightning.git] / tilelib_test.go
1 // Copyright (C) The Lightning Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package lightning
6
7 import (
8         "bytes"
9         "regexp"
10         "strings"
11
12         "gopkg.in/check.v1"
13 )
14
15 type tilelibSuite struct {
16         tag    []string
17         taglib tagLibrary
18 }
19
20 var _ = check.Suite(&tilelibSuite{})
21
22 func (s *tilelibSuite) SetUpSuite(c *check.C) {
23         fasta := `>0000.00
24 ggagaactgtgctccgccttcaga
25 acacatgctagcgcgtcggggtgg
26 gactctagcagagtggccagccac
27 cctcccgagccgagccacccgtca
28 gttattaataataacttatcatca
29 `
30         err := s.taglib.Load(bytes.NewBufferString(fasta))
31         c.Assert(err, check.IsNil)
32         for _, seq := range strings.Split(fasta, "\n") {
33                 if len(seq) > 0 && seq[0] != '>' {
34                         s.tag = append(s.tag, seq+"\n")
35                 }
36         }
37 }
38
39 func (s *tilelibSuite) TestSkipOOO(c *check.C) {
40         matchAllChromosomes := regexp.MustCompile(".")
41
42         // tags appear in seq: 4, 0, 2 (but skipOOO is false)
43         tilelib := &tileLibrary{taglib: &s.taglib, skipOOO: false}
44         tseq, _, err := tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
45                 s.tag[4]+
46                 "ggggggggggggggggggggggg\n"+
47                 s.tag[0]+
48                 "cccccccccccccccccccc\n"+
49                 s.tag[2]+
50                 "\n"), matchAllChromosomes, false)
51         c.Assert(err, check.IsNil)
52         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{4, 1}, {0, 1}, {2, 1}}})
53
54         // tags appear in seq: 0, 1, 2 -> don't skip
55         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
56         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
57                 s.tag[0]+
58                 "cccccccccccccccccccc\n"+
59                 s.tag[1]+
60                 "ggggggggggggggggggggggg\n"+
61                 s.tag[2]+
62                 "\n"), matchAllChromosomes, false)
63         c.Assert(err, check.IsNil)
64         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {2, 1}}})
65
66         // tags appear in seq: 2, 3, 4 -> don't skip
67         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
68         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
69                 s.tag[2]+
70                 "cccccccccccccccccccc\n"+
71                 s.tag[3]+
72                 "ggggggggggggggggggggggg\n"+
73                 s.tag[4]+
74                 "\n"), matchAllChromosomes, false)
75         c.Assert(err, check.IsNil)
76         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{2, 1}, {3, 1}, {4, 1}}})
77
78         // tags appear in seq: 4, 0, 2 -> skip 4
79         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
80         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
81                 s.tag[4]+
82                 "cccccccccccccccccccc\n"+
83                 s.tag[0]+
84                 "ggggggggggggggggggggggg\n"+
85                 s.tag[2]+
86                 "\n"), matchAllChromosomes, false)
87         c.Assert(err, check.IsNil)
88         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {2, 1}}})
89
90         // tags appear in seq: 0, 2, 1 -> skip 2
91         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
92         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
93                 s.tag[0]+
94                 "cccccccccccccccccccc\n"+
95                 s.tag[2]+
96                 "ggggggggggggggggggggggg\n"+
97                 s.tag[1]+
98                 "\n"), matchAllChromosomes, false)
99         c.Assert(err, check.IsNil)
100         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}}})
101
102         // tags appear in seq: 0, 1, 1, 2 -> skip second tag1
103         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true, useDups: true}
104         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
105                 s.tag[0]+
106                 "cccccccccccccccccccc\n"+
107                 s.tag[1]+
108                 "ggggggggggggggggggggggg\n"+
109                 s.tag[1]+
110                 "ggggggggggggggggggggggg\n"+
111                 s.tag[2]+
112                 "\n"), matchAllChromosomes, false)
113         c.Assert(err, check.IsNil)
114         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {2, 1}}})
115
116         // tags appear in seq: 0, 1, 3, 0, 4 -> skip second tag0
117         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true, useDups: true}
118         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
119                 s.tag[0]+
120                 "cccccccccccccccccccc\n"+
121                 s.tag[1]+
122                 "ggggggggggggggggggggggg\n"+
123                 s.tag[3]+
124                 "ggggggggggggggggggggggg\n"+
125                 s.tag[0]+
126                 "ggggggggggggggggggggggg\n"+
127                 s.tag[4]+
128                 "\n"), matchAllChromosomes, false)
129         c.Assert(err, check.IsNil)
130         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {3, 1}, {4, 1}}})
131
132         // tags appear in seq: 0, 1, 3 -> don't skip
133         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
134         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
135                 s.tag[0]+
136                 "cccccccccccccccccccc\n"+
137                 s.tag[1]+
138                 "ggggggggggggggggggggggg\n"+
139                 s.tag[3]+
140                 "\n"), matchAllChromosomes, false)
141         c.Assert(err, check.IsNil)
142         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {3, 1}}})
143 }