3750 |
17 Oct 18 |
peter |
// $Id$ |
3750 |
17 Oct 18 |
peter |
2 |
|
3750 |
17 Oct 18 |
peter |
3 |
/* |
4308 |
10 Feb 23 |
peter |
Copyright (C) 2018, 2020, 2023 Peter Johansson |
3750 |
17 Oct 18 |
peter |
5 |
|
3750 |
17 Oct 18 |
peter |
This program is free software; you can redistribute it and/or modify |
3750 |
17 Oct 18 |
peter |
it under the terms of the GNU General Public License as published by |
3750 |
17 Oct 18 |
peter |
the Free Software Foundation; either version 3 of the License, or |
3750 |
17 Oct 18 |
peter |
(at your option) any later version. |
3750 |
17 Oct 18 |
peter |
10 |
|
3750 |
17 Oct 18 |
peter |
This program is distributed in the hope that it will be useful, but |
3750 |
17 Oct 18 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
3750 |
17 Oct 18 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3750 |
17 Oct 18 |
peter |
General Public License for more details. |
3750 |
17 Oct 18 |
peter |
15 |
|
3750 |
17 Oct 18 |
peter |
You should have received a copy of the GNU General Public License |
3750 |
17 Oct 18 |
peter |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
3750 |
17 Oct 18 |
peter |
18 |
*/ |
3750 |
17 Oct 18 |
peter |
19 |
|
3750 |
17 Oct 18 |
peter |
20 |
#include <config.h> |
3750 |
17 Oct 18 |
peter |
21 |
|
3750 |
17 Oct 18 |
peter |
22 |
#include "Suite.h" |
3750 |
17 Oct 18 |
peter |
23 |
|
3750 |
17 Oct 18 |
peter |
24 |
#include "yat/omic/VcfHeader.h" |
3750 |
17 Oct 18 |
peter |
25 |
|
4308 |
10 Feb 23 |
peter |
26 |
#include "yat/utility/split.h" |
4308 |
10 Feb 23 |
peter |
27 |
#include "yat/utility/utility.h" |
4308 |
10 Feb 23 |
peter |
28 |
|
3750 |
17 Oct 18 |
peter |
29 |
#include <iostream> |
3750 |
17 Oct 18 |
peter |
30 |
#include <sstream> |
3750 |
17 Oct 18 |
peter |
31 |
#include <string> |
3750 |
17 Oct 18 |
peter |
32 |
|
3750 |
17 Oct 18 |
peter |
33 |
using namespace theplu::yat; |
3750 |
17 Oct 18 |
peter |
34 |
|
3750 |
17 Oct 18 |
peter |
35 |
int main(int argc, char* argv[]) |
3750 |
17 Oct 18 |
peter |
36 |
{ |
3750 |
17 Oct 18 |
peter |
37 |
test::Suite suite(argc, argv); |
3750 |
17 Oct 18 |
peter |
38 |
|
3750 |
17 Oct 18 |
peter |
39 |
std::stringstream ss; |
3750 |
17 Oct 18 |
peter |
40 |
ss << "##fileformat=VCFv4.1\n" |
3750 |
17 Oct 18 |
peter |
41 |
<< "##fileDate=20090805\n" |
3750 |
17 Oct 18 |
peter |
42 |
<< "##source=myImputationProgramV3.1\n" |
3750 |
17 Oct 18 |
peter |
43 |
<< "##reference=file:///seq/references/1000GenomesPilot-NCBI36.fasta\n" |
3750 |
17 Oct 18 |
peter |
44 |
<< "##INFO=<ID=NS,Number=1,Type=Integer,Description=" |
3750 |
17 Oct 18 |
peter |
45 |
<< "\"Number of Samples With Data\">\n" |
3750 |
17 Oct 18 |
peter |
46 |
<< "##INFO=<ID=DB,Number=0,Type=Flag," |
3750 |
17 Oct 18 |
peter |
47 |
<< "Description=\"dbSNP membership, build 129\">\n" |
3750 |
17 Oct 18 |
peter |
48 |
<< "#CHROM POS ID REF ALT QUAL FILTER INFO\n"; |
3750 |
17 Oct 18 |
peter |
49 |
|
3750 |
17 Oct 18 |
peter |
50 |
omic::VcfHeader hdr(ss); |
3750 |
17 Oct 18 |
peter |
51 |
std::ostringstream os; |
3750 |
17 Oct 18 |
peter |
52 |
os << hdr; |
3750 |
17 Oct 18 |
peter |
53 |
|
3750 |
17 Oct 18 |
peter |
54 |
for (size_t i=0; i<hdr.size(); ++i) { |
3750 |
17 Oct 18 |
peter |
55 |
if (hdr.key(i)!="INFO") |
3750 |
17 Oct 18 |
peter |
56 |
continue; |
3750 |
17 Oct 18 |
peter |
57 |
std::string id = hdr.value(i, "ID"); |
3750 |
17 Oct 18 |
peter |
58 |
suite.out() << "ID: " << id << "\n"; |
3750 |
17 Oct 18 |
peter |
59 |
suite.add(!id.empty()); |
3750 |
17 Oct 18 |
peter |
60 |
std::string d = hdr.value(i, "Description"); |
3750 |
17 Oct 18 |
peter |
61 |
std::cout << d << "\n"; |
3750 |
17 Oct 18 |
peter |
62 |
suite.add(!d.empty()); |
3750 |
17 Oct 18 |
peter |
63 |
suite.add(!(id=="DB" && d!="\"dbSNP membership, build 129\"")); |
3750 |
17 Oct 18 |
peter |
64 |
} |
3891 |
26 Mar 20 |
peter |
65 |
|
3891 |
26 Mar 20 |
peter |
// testing erase |
3891 |
26 Mar 20 |
peter |
67 |
{ |
3891 |
26 Mar 20 |
peter |
68 |
size_t n_pre = hdr.size(); |
3891 |
26 Mar 20 |
peter |
69 |
std::string pre = hdr.line(4); |
3891 |
26 Mar 20 |
peter |
70 |
hdr.erase(4); |
3891 |
26 Mar 20 |
peter |
71 |
size_t n_post = hdr.size(); |
3891 |
26 Mar 20 |
peter |
72 |
if (n_post != n_pre - 1) { |
3891 |
26 Mar 20 |
peter |
73 |
suite.add(false); |
3891 |
26 Mar 20 |
peter |
74 |
suite.err() << "error: erase(): size did decrement\n" |
3891 |
26 Mar 20 |
peter |
75 |
<< "N pre: " << n_pre << "\n" |
3891 |
26 Mar 20 |
peter |
76 |
<< "N post: " << n_post << "\n"; |
3891 |
26 Mar 20 |
peter |
77 |
} |
3891 |
26 Mar 20 |
peter |
78 |
std::string post = hdr.line(4); |
3891 |
26 Mar 20 |
peter |
79 |
if (pre == post) { |
3891 |
26 Mar 20 |
peter |
80 |
suite.add(false); |
3891 |
26 Mar 20 |
peter |
81 |
suite.err() << "error: pre and post identical\n" |
3891 |
26 Mar 20 |
peter |
82 |
<< "pre: " << pre << "\n" |
3891 |
26 Mar 20 |
peter |
83 |
<< "post: " << post << "\n"; |
3891 |
26 Mar 20 |
peter |
84 |
} |
3891 |
26 Mar 20 |
peter |
85 |
} |
3891 |
26 Mar 20 |
peter |
86 |
suite.out() << hdr.line(4) << "\n"; |
3891 |
26 Mar 20 |
peter |
87 |
|
4308 |
10 Feb 23 |
peter |
// test VcfHeader::add_program_command |
4308 |
10 Feb 23 |
peter |
89 |
suite.out() << "test ::add_program_command:\n"; |
4308 |
10 Feb 23 |
peter |
90 |
hdr.add_program_command(argc, argv); |
4308 |
10 Feb 23 |
peter |
91 |
bool found_command=false; |
4308 |
10 Feb 23 |
peter |
92 |
for (size_t i=0; i<hdr.size(); ++i) { |
4308 |
10 Feb 23 |
peter |
93 |
if (utility::contains(hdr.line(i), "vcf_header.testCommand")) { |
4308 |
10 Feb 23 |
peter |
94 |
suite.out() << hdr.line(i) << "\n"; |
4308 |
10 Feb 23 |
peter |
95 |
std::vector<std::string> vec; |
4308 |
10 Feb 23 |
peter |
96 |
utility::split(vec, hdr.line(i), ';'); |
4308 |
10 Feb 23 |
peter |
97 |
for (size_t j=0; j<vec.size(); ++j) { |
4308 |
10 Feb 23 |
peter |
98 |
if (utility::contains(vec[j], "Date")) { |
4308 |
10 Feb 23 |
peter |
99 |
found_command = true; |
4308 |
10 Feb 23 |
peter |
100 |
suite.out() << "date: '" << vec[j] << "'\n"; |
4308 |
10 Feb 23 |
peter |
101 |
if (vec[j].size() < 20) { |
4308 |
10 Feb 23 |
peter |
102 |
suite.err() << "date value too short\n"; |
4308 |
10 Feb 23 |
peter |
103 |
suite.add(false); |
4308 |
10 Feb 23 |
peter |
104 |
} |
4308 |
10 Feb 23 |
peter |
105 |
} |
4308 |
10 Feb 23 |
peter |
106 |
} |
4308 |
10 Feb 23 |
peter |
107 |
} |
4308 |
10 Feb 23 |
peter |
108 |
} |
4308 |
10 Feb 23 |
peter |
109 |
suite.add(found_command); |
4308 |
10 Feb 23 |
peter |
110 |
|
3750 |
17 Oct 18 |
peter |
111 |
return suite.return_value(); |
3750 |
17 Oct 18 |
peter |
112 |
} |