1 | // $Id: gff.cc 2482 2011-04-24 22:17:19Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2011 Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 3 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include "Suite.h" |
---|
23 | |
---|
24 | #include "yat/omic/GFF2.h" |
---|
25 | #include "yat/omic/GFF3.h" |
---|
26 | |
---|
27 | #include <fstream> |
---|
28 | |
---|
29 | using namespace theplu::yat; |
---|
30 | using namespace omic; |
---|
31 | |
---|
32 | template<typename T> |
---|
33 | void avoid_pedantic_warning(T t) {} |
---|
34 | |
---|
35 | void gff2(test::Suite&); |
---|
36 | void gff3(test::Suite&); |
---|
37 | |
---|
38 | template<class T> |
---|
39 | void test_gff(test::Suite&, GFF&); |
---|
40 | |
---|
41 | int main(int argc, char* argv[]) |
---|
42 | { |
---|
43 | test::Suite suite(argc, argv); |
---|
44 | |
---|
45 | gff2(suite); |
---|
46 | gff3(suite); |
---|
47 | |
---|
48 | return suite.return_value(); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | void test_gff(test::Suite& suite, GFF& gff) |
---|
53 | { |
---|
54 | std::string seqid = gff.seqid(); |
---|
55 | std::string source = gff.source(); |
---|
56 | std::string type = gff.type(); |
---|
57 | avoid_pedantic_warning<const std::string&>(gff.start()); |
---|
58 | avoid_pedantic_warning<const std::string&>(gff.end()); |
---|
59 | avoid_pedantic_warning<const std::string&>(gff.score()); |
---|
60 | avoid_pedantic_warning<const std::string&>(gff.strand()); |
---|
61 | avoid_pedantic_warning<const std::string&>(gff.phase()); |
---|
62 | const std::map<std::string, std::string>& m = gff.attributes(); |
---|
63 | avoid_pedantic_warning(m); |
---|
64 | } |
---|
65 | |
---|
66 | void gff2(test::Suite& suite) |
---|
67 | { |
---|
68 | suite.out() << "testing GFF2\n"; |
---|
69 | std::ifstream is(test::filename("data/small.gff2").c_str()); |
---|
70 | assert(is); |
---|
71 | GFF2 gff2; |
---|
72 | suite.add(getline(is, gff2)); |
---|
73 | test_gff(suite, gff2); |
---|
74 | const std::string& a = gff2.attribute("genotype"); |
---|
75 | if (!suite.add(a=="T or C")) |
---|
76 | suite.err() << "incorrect genotype value: `" << a << "'\n" |
---|
77 | << "expected: `T or C'\n"; |
---|
78 | is.close(); |
---|
79 | } |
---|
80 | |
---|
81 | void gff3(test::Suite& suite) |
---|
82 | { |
---|
83 | suite.out() << "testing GFF3\n"; |
---|
84 | std::ifstream is(test::filename("data/small.gff3").c_str()); |
---|
85 | assert(is); |
---|
86 | GFF3 gff3; |
---|
87 | if (!suite.add(getline(is, gff3))) |
---|
88 | suite.err() << "getline failed\n"; |
---|
89 | test_gff(suite, gff3); |
---|
90 | const std::string& a = gff3.attribute("genotype"); |
---|
91 | if (!suite.add(a=="T")) |
---|
92 | suite.err() << "incorrect genotype value: `" << a << "'\n" |
---|
93 | << "expected: `T'\n"; |
---|
94 | is.close(); |
---|
95 | } |
---|