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