]> git.donarmstrong.com Git - bamtools.git/blob - src/test/api/SamHeader/SamHeaderValidatorTest.h
Post-merge cleanup
[bamtools.git] / src / test / api / SamHeader / SamHeaderValidatorTest.h
1 #ifndef SAMHEADER_VALIDATORTEST_H
2 #define SAMHEADER_VALIDATORTEST_H
3
4 #include "api/SamHeader.h"
5 #include <gtest/gtest.h>
6 #include <iostream>
7 #include <string>
8
9 TEST(SamHeader_ValidatorTest, EmptyHeader) {
10
11     BamTools::SamHeader header("");
12     std::string headerText = header.ToString();
13     ASSERT_TRUE(headerText.empty());
14     EXPECT_TRUE(header.IsValid());
15 }
16
17 TEST(SamHeader_ValidatorTest, Version) {
18
19     BamTools::SamHeader header("");
20
21     // empty - VALID HEADER
22     header.Version = "";
23     EXPECT_TRUE(header.IsValid());
24
25     // normal - VALID HEADER
26     header.Version = "1.1";
27     EXPECT_TRUE(header.IsValid());
28     header.Version = "11.1";
29     EXPECT_TRUE(header.IsValid());
30     header.Version = "1.11";
31
32     // no period - INVALID HEADER
33     header.Version = "11";
34     EXPECT_FALSE(header.IsValid());
35
36     // no major - INVALID HEADER
37     header.Version = ".1";
38     EXPECT_FALSE(header.IsValid());
39
40     // invalid major - INVALID HEADER
41     header.Version = "a.1";
42     EXPECT_FALSE(header.IsValid());
43
44     // no minor - INVALID HEADER
45     header.Version = "1.";
46     EXPECT_FALSE(header.IsValid());
47
48     // invalid minor - INVALID HEADER
49     header.Version = "1.a";
50     EXPECT_FALSE(header.IsValid());
51 }
52
53 TEST(SamHeader_ValidatorTest, GroupOrder) {
54
55     BamTools::SamHeader header("");
56
57     // empty - VALID HEADER
58     header.GroupOrder = "";
59     EXPECT_TRUE(header.IsValid());
60
61     // normal group order- VALID HEADER
62     header.GroupOrder = "none";
63     EXPECT_TRUE(header.IsValid());
64     header.GroupOrder = "query";
65     EXPECT_TRUE(header.IsValid());
66     header.GroupOrder = "reference";
67     EXPECT_TRUE(header.IsValid());
68
69     // invalid group order - INVALID HEADER
70     header.GroupOrder = "fake";
71     EXPECT_FALSE(header.IsValid());
72 }
73
74 TEST(SamHeader_ValidatorTest, SortOrder) {
75
76     BamTools::SamHeader header("");
77
78     // empty - VALID HEADER
79     header.SortOrder = "";
80     EXPECT_TRUE(header.IsValid());
81
82     // normal sort order- VALID HEADER
83     header.SortOrder = "coordinate";
84     EXPECT_TRUE(header.IsValid());
85     header.SortOrder = "queryname";
86     EXPECT_TRUE(header.IsValid());
87     header.SortOrder = "unsorted";
88     EXPECT_TRUE(header.IsValid());
89
90     // invalid sort order - INVALID HEADER
91     header.SortOrder = "fake";
92     EXPECT_FALSE(header.IsValid());
93 }
94
95 TEST(SamHeader_ValidatorTest, SequenceDictionary) {
96
97     BamTools::SamHeader header("");
98     BamTools::SamSequence sequence;
99
100     // --------------------------------
101     // empty - VALID HEADER
102
103     header.Sequences.Clear();
104     EXPECT_TRUE(header.IsValid());
105
106     // --------------------------------
107     // normal - VALID HEADER
108
109     sequence.Name   = "MT";
110     sequence.Length = "1000";
111     header.Sequences.Add(sequence);
112     EXPECT_TRUE(header.IsValid());
113
114     // normal ( length == MIN )
115     sequence.Name   = "MT";
116     sequence.Length = "1";
117     header.Sequences.Clear();
118     header.Sequences.Add(sequence);
119     EXPECT_TRUE(header.IsValid());
120
121     // normal ( length == MAX )
122     sequence.Name = "MT";
123     sequence.Length = "536870911";
124     header.Sequences.Clear();
125     header.Sequences.Add(sequence);
126     EXPECT_TRUE(header.IsValid());
127
128     // ---------------------------------
129     // missing required info - INVALID HEADER
130
131     // missing ID
132     sequence.Name = "";
133     sequence.Length = "1000";
134     header.Sequences.Clear();
135     header.Sequences.Add(sequence);
136     EXPECT_FALSE(header.IsValid());
137
138     // missing length
139     sequence.Name = "MT";
140     sequence.Length = "";
141     header.Sequences.Clear();
142     header.Sequences.Add(sequence);
143     EXPECT_FALSE(header.IsValid());
144
145     // -------------------------------------
146     // improper SN format - INVALID HEADER
147
148     // starts with *
149     sequence.Name = "*MT";
150     sequence.Length = "1000";
151     header.Sequences.Clear();
152     header.Sequences.Add(sequence);
153     EXPECT_FALSE(header.IsValid());
154
155     // starts with =
156     sequence.Name = "=MT";
157     sequence.Length = "1000";
158     header.Sequences.Clear();
159     header.Sequences.Add(sequence);
160     EXPECT_FALSE(header.IsValid());
161
162     // -----------------------------------------
163     // nonunique ID - INVALID HEADER
164
165     // this behavior is blocked by SamSequenceDictionary
166     // see SamSequenceDictionaryTest::AddDuplicateOk
167
168     // --------------------------------------------
169     // invalid length  - INVALID HEADER
170
171     // length = 0 (MIN == 1)
172     sequence.Name = "MT";
173     sequence.Length = "0";
174     header.Sequences.Clear();
175     header.Sequences.Add(sequence);
176     EXPECT_FALSE(header.IsValid());
177
178     // length = -1
179     sequence.Name = "MT";
180     sequence.Length = "-1";
181     header.Sequences.Clear();
182     header.Sequences.Add(sequence);
183     EXPECT_FALSE(header.IsValid());
184
185     // length = MAX + 1
186     sequence.Name ="MT";
187     sequence.Length = "536870912";
188     header.Sequences.Clear();
189     header.Sequences.Add(sequence);
190     EXPECT_FALSE(header.IsValid());
191 }
192
193 TEST(SamHeader_ValidatorTest, ReadGroupDictionary) {
194
195     BamTools::SamHeader header("");
196     BamTools::SamReadGroup readGroup;
197
198     // ---------------------------------
199     // empty - VALID HEADER
200
201     header.ReadGroups.Clear();
202     EXPECT_TRUE(header.IsValid());
203
204     // ---------------------------------
205     // normal - VALID HEADER
206
207     readGroup.ID = "Group123";
208     readGroup.PlatformUnit = "PU001";
209
210     // technology: none
211     header.ReadGroups.Clear();
212     header.ReadGroups.Add(readGroup);
213     EXPECT_TRUE(header.IsValid());
214
215     // technology: capillary
216     readGroup.SequencingTechnology = "CAPILLARY";
217     header.ReadGroups.Clear();
218     header.ReadGroups.Add(readGroup);
219     EXPECT_TRUE(header.IsValid());
220
221     // technology: Helicos
222     readGroup.SequencingTechnology = "HELICOS";
223     header.ReadGroups.Clear();
224     header.ReadGroups.Add(readGroup);
225     EXPECT_TRUE(header.IsValid());
226
227     // technology: Illumina
228     readGroup.SequencingTechnology = "ILLUMINA";
229     header.ReadGroups.Clear();
230     header.ReadGroups.Add(readGroup);
231     EXPECT_TRUE(header.IsValid());
232
233     // technology: IonTorrent
234     readGroup.SequencingTechnology = "IONTORRENT";
235     header.ReadGroups.Clear();
236     header.ReadGroups.Add(readGroup);
237     EXPECT_TRUE(header.IsValid());
238
239     // technology: 454
240     readGroup.SequencingTechnology = "LS454";
241     header.ReadGroups.Clear();
242     header.ReadGroups.Add(readGroup);
243     EXPECT_TRUE(header.IsValid());
244
245     // technology: Pacific Bio
246     readGroup.SequencingTechnology = "PACBIO";
247     header.ReadGroups.Clear();
248     header.ReadGroups.Add(readGroup);
249     EXPECT_TRUE(header.IsValid());
250
251     // technology: Solid
252     readGroup.SequencingTechnology = "SOLID";
253     header.ReadGroups.Clear();
254     header.ReadGroups.Add(readGroup);
255     EXPECT_TRUE(header.IsValid());
256
257     // ---------------------------------
258     // missing ID - INVALID HEADER
259
260     readGroup.ID = "";
261     header.ReadGroups.Clear();
262     header.ReadGroups.Add(readGroup);
263     EXPECT_FALSE(header.IsValid());
264
265     // -----------------------------------------
266     // nonunique ID - INVALID HEADER
267
268     // this behavior is blocked by SamReadGroupDictionary
269     // see SamReadGroupDictionaryTest::AddDuplicateOk
270
271     // ------------------------------------------
272     // nonunique platform unit - INVALID HEADER
273
274     BamTools::SamReadGroup dupPU("Group1");
275     BamTools::SamReadGroup dupPU2("Group2");
276     dupPU.PlatformUnit = "PU001";
277     dupPU2.PlatformUnit = "PU001";
278     header.ReadGroups.Clear();
279     header.ReadGroups.Add(dupPU);
280     header.ReadGroups.Add(dupPU2);
281     EXPECT_FALSE(header.IsValid());
282
283     // ------------------------------------------------
284     // invalid sequencing technology - INVALID HEADER
285
286     readGroup.SequencingTechnology = "fake";
287     header.ReadGroups.Clear();
288     header.ReadGroups.Add(readGroup);
289     EXPECT_FALSE(header.IsValid());
290 }
291
292 #endif // SAMHEADER_VALIDATORTEST_H