1 #ifndef SAMHEADER_VALIDATORTEST_H
2 #define SAMHEADER_VALIDATORTEST_H
4 #include "api/SamHeader.h"
5 #include <gtest/gtest.h>
9 TEST(SamHeader_ValidatorTest, EmptyHeader) {
11 BamTools::SamHeader header("");
12 std::string headerText = header.ToString();
13 ASSERT_TRUE(headerText.empty());
14 EXPECT_TRUE(header.IsValid());
17 TEST(SamHeader_ValidatorTest, Version) {
19 BamTools::SamHeader header("");
21 // empty - VALID HEADER
23 EXPECT_TRUE(header.IsValid());
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";
32 // no period - INVALID HEADER
33 header.Version = "11";
34 EXPECT_FALSE(header.IsValid());
36 // no major - INVALID HEADER
37 header.Version = ".1";
38 EXPECT_FALSE(header.IsValid());
40 // invalid major - INVALID HEADER
41 header.Version = "a.1";
42 EXPECT_FALSE(header.IsValid());
44 // no minor - INVALID HEADER
45 header.Version = "1.";
46 EXPECT_FALSE(header.IsValid());
48 // invalid minor - INVALID HEADER
49 header.Version = "1.a";
50 EXPECT_FALSE(header.IsValid());
53 TEST(SamHeader_ValidatorTest, GroupOrder) {
55 BamTools::SamHeader header("");
57 // empty - VALID HEADER
58 header.GroupOrder = "";
59 EXPECT_TRUE(header.IsValid());
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());
69 // invalid group order - INVALID HEADER
70 header.GroupOrder = "fake";
71 EXPECT_FALSE(header.IsValid());
74 TEST(SamHeader_ValidatorTest, SortOrder) {
76 BamTools::SamHeader header("");
78 // empty - VALID HEADER
79 header.SortOrder = "";
80 EXPECT_TRUE(header.IsValid());
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());
90 // invalid sort order - INVALID HEADER
91 header.SortOrder = "fake";
92 EXPECT_FALSE(header.IsValid());
95 TEST(SamHeader_ValidatorTest, SequenceDictionary) {
97 BamTools::SamHeader header("");
98 BamTools::SamSequence sequence;
100 // --------------------------------
101 // empty - VALID HEADER
103 header.Sequences.Clear();
104 EXPECT_TRUE(header.IsValid());
106 // --------------------------------
107 // normal - VALID HEADER
109 sequence.Name = "MT";
110 sequence.Length = "1000";
111 header.Sequences.Add(sequence);
112 EXPECT_TRUE(header.IsValid());
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());
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());
128 // ---------------------------------
129 // missing required info - INVALID HEADER
133 sequence.Length = "1000";
134 header.Sequences.Clear();
135 header.Sequences.Add(sequence);
136 EXPECT_FALSE(header.IsValid());
139 sequence.Name = "MT";
140 sequence.Length = "";
141 header.Sequences.Clear();
142 header.Sequences.Add(sequence);
143 EXPECT_FALSE(header.IsValid());
145 // -------------------------------------
146 // improper SN format - INVALID HEADER
149 sequence.Name = "*MT";
150 sequence.Length = "1000";
151 header.Sequences.Clear();
152 header.Sequences.Add(sequence);
153 EXPECT_FALSE(header.IsValid());
156 sequence.Name = "=MT";
157 sequence.Length = "1000";
158 header.Sequences.Clear();
159 header.Sequences.Add(sequence);
160 EXPECT_FALSE(header.IsValid());
162 // -----------------------------------------
163 // nonunique ID - INVALID HEADER
165 // this behavior is blocked by SamSequenceDictionary
166 // see SamSequenceDictionaryTest::AddDuplicateOk
168 // --------------------------------------------
169 // invalid length - INVALID HEADER
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());
179 sequence.Name = "MT";
180 sequence.Length = "-1";
181 header.Sequences.Clear();
182 header.Sequences.Add(sequence);
183 EXPECT_FALSE(header.IsValid());
187 sequence.Length = "536870912";
188 header.Sequences.Clear();
189 header.Sequences.Add(sequence);
190 EXPECT_FALSE(header.IsValid());
193 TEST(SamHeader_ValidatorTest, ReadGroupDictionary) {
195 BamTools::SamHeader header("");
196 BamTools::SamReadGroup readGroup;
198 // ---------------------------------
199 // empty - VALID HEADER
201 header.ReadGroups.Clear();
202 EXPECT_TRUE(header.IsValid());
204 // ---------------------------------
205 // normal - VALID HEADER
207 readGroup.ID = "Group123";
208 readGroup.PlatformUnit = "PU001";
211 header.ReadGroups.Clear();
212 header.ReadGroups.Add(readGroup);
213 EXPECT_TRUE(header.IsValid());
215 // technology: capillary
216 readGroup.SequencingTechnology = "CAPILLARY";
217 header.ReadGroups.Clear();
218 header.ReadGroups.Add(readGroup);
219 EXPECT_TRUE(header.IsValid());
221 // technology: Helicos
222 readGroup.SequencingTechnology = "HELICOS";
223 header.ReadGroups.Clear();
224 header.ReadGroups.Add(readGroup);
225 EXPECT_TRUE(header.IsValid());
227 // technology: Illumina
228 readGroup.SequencingTechnology = "ILLUMINA";
229 header.ReadGroups.Clear();
230 header.ReadGroups.Add(readGroup);
231 EXPECT_TRUE(header.IsValid());
233 // technology: IonTorrent
234 readGroup.SequencingTechnology = "IONTORRENT";
235 header.ReadGroups.Clear();
236 header.ReadGroups.Add(readGroup);
237 EXPECT_TRUE(header.IsValid());
240 readGroup.SequencingTechnology = "LS454";
241 header.ReadGroups.Clear();
242 header.ReadGroups.Add(readGroup);
243 EXPECT_TRUE(header.IsValid());
245 // technology: Pacific Bio
246 readGroup.SequencingTechnology = "PACBIO";
247 header.ReadGroups.Clear();
248 header.ReadGroups.Add(readGroup);
249 EXPECT_TRUE(header.IsValid());
252 readGroup.SequencingTechnology = "SOLID";
253 header.ReadGroups.Clear();
254 header.ReadGroups.Add(readGroup);
255 EXPECT_TRUE(header.IsValid());
257 // ---------------------------------
258 // missing ID - INVALID HEADER
261 header.ReadGroups.Clear();
262 header.ReadGroups.Add(readGroup);
263 EXPECT_FALSE(header.IsValid());
265 // -----------------------------------------
266 // nonunique ID - INVALID HEADER
268 // this behavior is blocked by SamReadGroupDictionary
269 // see SamReadGroupDictionaryTest::AddDuplicateOk
271 // ------------------------------------------
272 // nonunique platform unit - INVALID HEADER
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());
283 // ------------------------------------------------
284 // invalid sequencing technology - INVALID HEADER
286 readGroup.SequencingTechnology = "fake";
287 header.ReadGroups.Clear();
288 header.ReadGroups.Add(readGroup);
289 EXPECT_FALSE(header.IsValid());
292 #endif // SAMHEADER_VALIDATORTEST_H