2453 |
29 Mar 11 |
peter |
// $Id$ |
2453 |
29 Mar 11 |
peter |
2 |
|
2453 |
29 Mar 11 |
peter |
3 |
/* |
3875 |
05 Mar 20 |
peter |
Copyright (C) 2011, 2012, 2019, 2020 Peter Johansson |
2453 |
29 Mar 11 |
peter |
5 |
|
2453 |
29 Mar 11 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2453 |
29 Mar 11 |
peter |
7 |
|
2453 |
29 Mar 11 |
peter |
The yat library is free software; you can redistribute it and/or |
2453 |
29 Mar 11 |
peter |
modify it under the terms of the GNU General Public License as |
2453 |
29 Mar 11 |
peter |
published by the Free Software Foundation; either version 3 of the |
2453 |
29 Mar 11 |
peter |
License, or (at your option) any later version. |
2453 |
29 Mar 11 |
peter |
12 |
|
2453 |
29 Mar 11 |
peter |
The yat library is distributed in the hope that it will be useful, |
2453 |
29 Mar 11 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2453 |
29 Mar 11 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2453 |
29 Mar 11 |
peter |
General Public License for more details. |
2453 |
29 Mar 11 |
peter |
17 |
|
2453 |
29 Mar 11 |
peter |
You should have received a copy of the GNU General Public License |
2453 |
29 Mar 11 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2453 |
29 Mar 11 |
peter |
20 |
*/ |
2453 |
29 Mar 11 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2453 |
29 Mar 11 |
peter |
24 |
#include "Suite.h" |
2453 |
29 Mar 11 |
peter |
25 |
|
2482 |
24 Apr 11 |
peter |
26 |
#include "yat/omic/GFF2.h" |
2482 |
24 Apr 11 |
peter |
27 |
#include "yat/omic/GFF3.h" |
2482 |
24 Apr 11 |
peter |
28 |
|
3840 |
13 Aug 19 |
peter |
29 |
#include "yat/utility/Exception.h" |
3840 |
13 Aug 19 |
peter |
30 |
|
2483 |
25 Apr 11 |
peter |
31 |
#include <cassert> |
2482 |
24 Apr 11 |
peter |
32 |
#include <fstream> |
2482 |
24 Apr 11 |
peter |
33 |
|
2453 |
29 Mar 11 |
peter |
34 |
using namespace theplu::yat; |
2482 |
24 Apr 11 |
peter |
35 |
using namespace omic; |
2453 |
29 Mar 11 |
peter |
36 |
|
2482 |
24 Apr 11 |
peter |
37 |
template<typename T> |
2482 |
24 Apr 11 |
peter |
38 |
void avoid_pedantic_warning(T t) {} |
2482 |
24 Apr 11 |
peter |
39 |
|
2482 |
24 Apr 11 |
peter |
40 |
void gff2(test::Suite&); |
2482 |
24 Apr 11 |
peter |
41 |
void gff3(test::Suite&); |
2482 |
24 Apr 11 |
peter |
42 |
|
2482 |
24 Apr 11 |
peter |
43 |
template<class T> |
2482 |
24 Apr 11 |
peter |
44 |
void test_gff(test::Suite&, GFF&); |
2703 |
12 Mar 12 |
peter |
45 |
void test_ticket697(test::Suite&); |
3870 |
24 Feb 20 |
peter |
46 |
void test_ticket937(test::Suite&); |
3870 |
24 Feb 20 |
peter |
47 |
void test_value_without_quote(test::Suite&); |
2482 |
24 Apr 11 |
peter |
48 |
|
2453 |
29 Mar 11 |
peter |
49 |
int main(int argc, char* argv[]) |
2453 |
29 Mar 11 |
peter |
50 |
{ |
2453 |
29 Mar 11 |
peter |
51 |
test::Suite suite(argc, argv); |
2453 |
29 Mar 11 |
peter |
52 |
|
2482 |
24 Apr 11 |
peter |
53 |
gff2(suite); |
2482 |
24 Apr 11 |
peter |
54 |
gff3(suite); |
2703 |
12 Mar 12 |
peter |
55 |
test_ticket697(suite); |
3870 |
24 Feb 20 |
peter |
56 |
test_ticket937(suite); |
3870 |
24 Feb 20 |
peter |
57 |
test_value_without_quote(suite); |
2482 |
24 Apr 11 |
peter |
58 |
|
2453 |
29 Mar 11 |
peter |
59 |
return suite.return_value(); |
2453 |
29 Mar 11 |
peter |
60 |
} |
2482 |
24 Apr 11 |
peter |
61 |
|
2482 |
24 Apr 11 |
peter |
62 |
|
2482 |
24 Apr 11 |
peter |
63 |
void test_gff(test::Suite& suite, GFF& gff) |
2482 |
24 Apr 11 |
peter |
64 |
{ |
2482 |
24 Apr 11 |
peter |
65 |
std::string seqid = gff.seqid(); |
2482 |
24 Apr 11 |
peter |
66 |
std::string source = gff.source(); |
2482 |
24 Apr 11 |
peter |
67 |
std::string type = gff.type(); |
2482 |
24 Apr 11 |
peter |
68 |
avoid_pedantic_warning<const std::string&>(gff.start()); |
2482 |
24 Apr 11 |
peter |
69 |
avoid_pedantic_warning<const std::string&>(gff.end()); |
2482 |
24 Apr 11 |
peter |
70 |
avoid_pedantic_warning<const std::string&>(gff.score()); |
2482 |
24 Apr 11 |
peter |
71 |
avoid_pedantic_warning<const std::string&>(gff.strand()); |
2482 |
24 Apr 11 |
peter |
72 |
avoid_pedantic_warning<const std::string&>(gff.phase()); |
2482 |
24 Apr 11 |
peter |
73 |
const std::map<std::string, std::string>& m = gff.attributes(); |
2482 |
24 Apr 11 |
peter |
74 |
avoid_pedantic_warning(m); |
2482 |
24 Apr 11 |
peter |
75 |
} |
2482 |
24 Apr 11 |
peter |
76 |
|
2482 |
24 Apr 11 |
peter |
77 |
void gff2(test::Suite& suite) |
2482 |
24 Apr 11 |
peter |
78 |
{ |
2482 |
24 Apr 11 |
peter |
79 |
suite.out() << "testing GFF2\n"; |
2482 |
24 Apr 11 |
peter |
80 |
std::ifstream is(test::filename("data/small.gff2").c_str()); |
2482 |
24 Apr 11 |
peter |
81 |
assert(is); |
2482 |
24 Apr 11 |
peter |
82 |
GFF2 gff2; |
2482 |
24 Apr 11 |
peter |
83 |
suite.add(getline(is, gff2)); |
2482 |
24 Apr 11 |
peter |
84 |
test_gff(suite, gff2); |
2482 |
24 Apr 11 |
peter |
85 |
const std::string& a = gff2.attribute("genotype"); |
2482 |
24 Apr 11 |
peter |
86 |
if (!suite.add(a=="T or C")) |
2482 |
24 Apr 11 |
peter |
87 |
suite.err() << "incorrect genotype value: `" << a << "'\n" |
2482 |
24 Apr 11 |
peter |
88 |
<< "expected: `T or C'\n"; |
2482 |
24 Apr 11 |
peter |
89 |
is.close(); |
2482 |
24 Apr 11 |
peter |
90 |
} |
2482 |
24 Apr 11 |
peter |
91 |
|
2482 |
24 Apr 11 |
peter |
92 |
void gff3(test::Suite& suite) |
2482 |
24 Apr 11 |
peter |
93 |
{ |
2482 |
24 Apr 11 |
peter |
94 |
suite.out() << "testing GFF3\n"; |
2482 |
24 Apr 11 |
peter |
95 |
std::ifstream is(test::filename("data/small.gff3").c_str()); |
2482 |
24 Apr 11 |
peter |
96 |
assert(is); |
2482 |
24 Apr 11 |
peter |
97 |
GFF3 gff3; |
2482 |
24 Apr 11 |
peter |
98 |
if (!suite.add(getline(is, gff3))) |
2482 |
24 Apr 11 |
peter |
99 |
suite.err() << "getline failed\n"; |
2482 |
24 Apr 11 |
peter |
100 |
test_gff(suite, gff3); |
2482 |
24 Apr 11 |
peter |
101 |
const std::string& a = gff3.attribute("genotype"); |
2482 |
24 Apr 11 |
peter |
102 |
if (!suite.add(a=="T")) |
2482 |
24 Apr 11 |
peter |
103 |
suite.err() << "incorrect genotype value: `" << a << "'\n" |
2482 |
24 Apr 11 |
peter |
104 |
<< "expected: `T'\n"; |
2482 |
24 Apr 11 |
peter |
105 |
is.close(); |
2482 |
24 Apr 11 |
peter |
106 |
} |
2703 |
12 Mar 12 |
peter |
107 |
|
2703 |
12 Mar 12 |
peter |
108 |
|
2703 |
12 Mar 12 |
peter |
109 |
void test_ticket697(test::Suite& suite) |
2703 |
12 Mar 12 |
peter |
110 |
{ |
2703 |
12 Mar 12 |
peter |
111 |
suite.out() << "test ticket 697\n"; |
2703 |
12 Mar 12 |
peter |
112 |
GFF2 gff; |
2703 |
12 Mar 12 |
peter |
113 |
std::ifstream is(test::filename("data/small.gff2").c_str()); |
2703 |
12 Mar 12 |
peter |
114 |
assert(is); |
2703 |
12 Mar 12 |
peter |
115 |
getline(is, gff); |
2703 |
12 Mar 12 |
peter |
116 |
if (gff.attribute("genotype")!="T or C") { |
2703 |
12 Mar 12 |
peter |
117 |
suite.add(false); |
2703 |
12 Mar 12 |
peter |
118 |
suite.err() << "error: incorrect genotype: '" << gff.attribute("genotype") |
2703 |
12 Mar 12 |
peter |
119 |
<< "'; expected: 'T or C'\n"; |
2703 |
12 Mar 12 |
peter |
120 |
} |
2703 |
12 Mar 12 |
peter |
121 |
getline(is, gff); |
2703 |
12 Mar 12 |
peter |
122 |
if (gff.attribute("genotype")!="T") { |
2703 |
12 Mar 12 |
peter |
123 |
suite.add(false); |
2703 |
12 Mar 12 |
peter |
124 |
suite.err() << "error: incorrect genotype: '" << gff.attribute("genotype") |
2703 |
12 Mar 12 |
peter |
125 |
<< "'; expected: 'T'\n"; |
2703 |
12 Mar 12 |
peter |
126 |
} |
3840 |
13 Aug 19 |
peter |
127 |
try { |
3840 |
13 Aug 19 |
peter |
128 |
if (gff.attribute("reference")!="C") { |
3840 |
13 Aug 19 |
peter |
129 |
suite.add(false); |
3840 |
13 Aug 19 |
peter |
130 |
suite.err() << "error: incorrect genotype: '" << gff.attribute("genotype") |
3840 |
13 Aug 19 |
peter |
131 |
<< "'; expected: 'T'\n"; |
3840 |
13 Aug 19 |
peter |
132 |
} |
3840 |
13 Aug 19 |
peter |
133 |
} |
3840 |
13 Aug 19 |
peter |
134 |
catch (utility::runtime_error& e) { |
3840 |
13 Aug 19 |
peter |
135 |
suite.add(false); |
3840 |
13 Aug 19 |
peter |
136 |
suite.err() << "unexpected exception thrown: what: " << e.what() << "\n"; |
3840 |
13 Aug 19 |
peter |
137 |
} |
2703 |
12 Mar 12 |
peter |
138 |
is.close(); |
2703 |
12 Mar 12 |
peter |
139 |
} |
3870 |
24 Feb 20 |
peter |
140 |
|
3870 |
24 Feb 20 |
peter |
141 |
|
3870 |
24 Feb 20 |
peter |
142 |
void test_ticket937(test::Suite& suite) |
3870 |
24 Feb 20 |
peter |
143 |
{ |
3870 |
24 Feb 20 |
peter |
144 |
suite.out() << "test ticket 937\n"; |
3870 |
24 Feb 20 |
peter |
145 |
|
3870 |
24 Feb 20 |
peter |
146 |
std::stringstream ss; |
3870 |
24 Feb 20 |
peter |
147 |
ss << "1\tStringTie\ttranscript\t134901\t139379\t1000\t-\t.\t" |
3870 |
24 Feb 20 |
peter |
148 |
<< "gene_id \"ENSG00000237683.5\"; transcript_id \"ENST00000423372.3\"; " |
3870 |
24 Feb 20 |
peter |
149 |
<< "ref_gene_name \"AL627309.1\"; cov \"7.649971\"; FPKM \"3.057291\"; " |
3870 |
24 Feb 20 |
peter |
150 |
<< "TPM \"7.858644\";"; |
3870 |
24 Feb 20 |
peter |
151 |
|
3870 |
24 Feb 20 |
peter |
152 |
GFF2 gff; |
3870 |
24 Feb 20 |
peter |
153 |
getline(ss, gff); |
3870 |
24 Feb 20 |
peter |
154 |
std::string id = gff.attribute("transcript_id"); |
3870 |
24 Feb 20 |
peter |
155 |
if (id != "ENST00000423372.3") { |
3870 |
24 Feb 20 |
peter |
156 |
suite.err() << "error: incorrect ID: " |
3870 |
24 Feb 20 |
peter |
157 |
<< "transcript_id: " << id << "\n"; |
3870 |
24 Feb 20 |
peter |
158 |
suite.add(false); |
3870 |
24 Feb 20 |
peter |
159 |
} |
3870 |
24 Feb 20 |
peter |
160 |
} |
3870 |
24 Feb 20 |
peter |
161 |
|
3870 |
24 Feb 20 |
peter |
162 |
|
3870 |
24 Feb 20 |
peter |
163 |
void test_value_without_quote(test::Suite& suite) |
3870 |
24 Feb 20 |
peter |
164 |
{ |
3870 |
24 Feb 20 |
peter |
165 |
suite.out() << "test value without quote\n"; |
3870 |
24 Feb 20 |
peter |
166 |
std::stringstream ss; |
3870 |
24 Feb 20 |
peter |
167 |
ss << "1\tStringTie\ttranscript\t134901\t139379\t1000\t-\t.\tlevel 1;"; |
3870 |
24 Feb 20 |
peter |
168 |
|
3870 |
24 Feb 20 |
peter |
169 |
GFF2 gff; |
3870 |
24 Feb 20 |
peter |
170 |
getline(ss, gff); |
3870 |
24 Feb 20 |
peter |
171 |
try { |
3870 |
24 Feb 20 |
peter |
172 |
std::string val = gff.attribute("level"); |
3870 |
24 Feb 20 |
peter |
173 |
if (val != "1") { |
3870 |
24 Feb 20 |
peter |
174 |
suite.err() << "error: incorrect value: " << val << "\n"; |
3870 |
24 Feb 20 |
peter |
175 |
suite.add(false); |
3870 |
24 Feb 20 |
peter |
176 |
} |
3870 |
24 Feb 20 |
peter |
177 |
} |
3870 |
24 Feb 20 |
peter |
178 |
catch (std::exception& e) { |
3870 |
24 Feb 20 |
peter |
179 |
suite.err() << "error: exception thrown: what(): " << e.what() << "\n"; |
3870 |
24 Feb 20 |
peter |
180 |
suite.add(false); |
3870 |
24 Feb 20 |
peter |
181 |
} |
3870 |
24 Feb 20 |
peter |
182 |
} |