3763 |
19 Oct 18 |
peter |
// $Id$ |
3763 |
19 Oct 18 |
peter |
2 |
|
3763 |
19 Oct 18 |
peter |
3 |
/* |
3763 |
19 Oct 18 |
peter |
Copyright (C) 2018 Peter Johansson |
3763 |
19 Oct 18 |
peter |
5 |
|
3763 |
19 Oct 18 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3763 |
19 Oct 18 |
peter |
7 |
|
3763 |
19 Oct 18 |
peter |
The yat library is free software; you can redistribute it and/or |
3763 |
19 Oct 18 |
peter |
modify it under the terms of the GNU General Public License as |
3763 |
19 Oct 18 |
peter |
published by the Free Software Foundation; either version 3 of the |
3763 |
19 Oct 18 |
peter |
License, or (at your option) any later version. |
3763 |
19 Oct 18 |
peter |
12 |
|
3763 |
19 Oct 18 |
peter |
The yat library is distributed in the hope that it will be useful, |
3763 |
19 Oct 18 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3763 |
19 Oct 18 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3763 |
19 Oct 18 |
peter |
General Public License for more details. |
3763 |
19 Oct 18 |
peter |
17 |
|
3763 |
19 Oct 18 |
peter |
You should have received a copy of the GNU General Public License |
3763 |
19 Oct 18 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3763 |
19 Oct 18 |
peter |
20 |
*/ |
3763 |
19 Oct 18 |
peter |
21 |
|
3763 |
19 Oct 18 |
peter |
22 |
#include <config.h> |
3763 |
19 Oct 18 |
peter |
23 |
|
3763 |
19 Oct 18 |
peter |
24 |
#include "Suite.h" |
3763 |
19 Oct 18 |
peter |
25 |
|
3773 |
26 Oct 18 |
peter |
26 |
#include "yat/omic/VCF.h" |
3763 |
19 Oct 18 |
peter |
27 |
#include "yat/omic/VcfFile.h" |
3763 |
19 Oct 18 |
peter |
28 |
#include "yat/omic/VcfHeader.h" |
3774 |
26 Oct 18 |
peter |
29 |
#include "yat/omic/VcfIterator.h" |
3763 |
19 Oct 18 |
peter |
30 |
|
3774 |
26 Oct 18 |
peter |
31 |
#include "yat/random/random.h" |
3774 |
26 Oct 18 |
peter |
32 |
|
3774 |
26 Oct 18 |
peter |
33 |
#include <algorithm> |
3774 |
26 Oct 18 |
peter |
34 |
#include <iterator> |
3763 |
19 Oct 18 |
peter |
35 |
#include <sstream> |
3774 |
26 Oct 18 |
peter |
36 |
#include <vector> |
3763 |
19 Oct 18 |
peter |
37 |
|
3763 |
19 Oct 18 |
peter |
38 |
using namespace theplu::yat; |
3763 |
19 Oct 18 |
peter |
39 |
|
3763 |
19 Oct 18 |
peter |
40 |
int main(int argc, char* argv[]) |
3763 |
19 Oct 18 |
peter |
41 |
{ |
3763 |
19 Oct 18 |
peter |
42 |
test::Suite suite(argc, argv); |
3763 |
19 Oct 18 |
peter |
43 |
omic::VcfFile vcf(test::filename("data/foo.vcf")); |
3763 |
19 Oct 18 |
peter |
44 |
if (vcf.is_open()) { |
3763 |
19 Oct 18 |
peter |
45 |
std::ostringstream ss; |
3763 |
19 Oct 18 |
peter |
46 |
ss << vcf.header(); |
3763 |
19 Oct 18 |
peter |
47 |
} |
3763 |
19 Oct 18 |
peter |
48 |
else { |
3763 |
19 Oct 18 |
peter |
49 |
suite.add(false); |
3763 |
19 Oct 18 |
peter |
50 |
suite.err() << "error: failed open input file\n"; |
3763 |
19 Oct 18 |
peter |
51 |
} |
3763 |
19 Oct 18 |
peter |
52 |
vcf.close(); |
3763 |
19 Oct 18 |
peter |
53 |
|
3771 |
25 Oct 18 |
peter |
// try to reopen file |
3771 |
25 Oct 18 |
peter |
55 |
vcf.open(test::filename("data/foo.vcf")); |
3773 |
26 Oct 18 |
peter |
56 |
omic::VCF entry; |
3773 |
26 Oct 18 |
peter |
57 |
vcf.read(entry); |
3774 |
26 Oct 18 |
peter |
// create a vector VCFs from iterator range |
3774 |
26 Oct 18 |
peter |
59 |
omic::VcfIterator begin(vcf); |
3774 |
26 Oct 18 |
peter |
60 |
omic::VcfIterator end; |
3774 |
26 Oct 18 |
peter |
61 |
std::vector<omic::VCF> vec(begin, end); |
3774 |
26 Oct 18 |
peter |
62 |
if (vec.empty()) { |
3774 |
26 Oct 18 |
peter |
63 |
suite.add(false); |
3774 |
26 Oct 18 |
peter |
64 |
suite.err() << "error: vector is empty\n"; |
3774 |
26 Oct 18 |
peter |
65 |
} |
3774 |
26 Oct 18 |
peter |
66 |
|
3774 |
26 Oct 18 |
peter |
// randomise variants |
3774 |
26 Oct 18 |
peter |
68 |
random::random_shuffle(vec.begin(), vec.end()); |
3774 |
26 Oct 18 |
peter |
69 |
|
3774 |
26 Oct 18 |
peter |
// just illustrating how to output vcfs using ostream_iterator |
3774 |
26 Oct 18 |
peter |
71 |
std::stringstream os; |
3774 |
26 Oct 18 |
peter |
72 |
std::copy(vec.begin(), vec.end(),std::ostream_iterator<omic::VCF>(os, "\n")); |
3774 |
26 Oct 18 |
peter |
73 |
suite.out() << "output:\n" << os.str().substr(0, 100) |
3774 |
26 Oct 18 |
peter |
74 |
<< "--->8 cut\n"; |
3774 |
26 Oct 18 |
peter |
75 |
if (os.str().size() < 100) { |
3774 |
26 Oct 18 |
peter |
76 |
suite.add(false); |
3774 |
26 Oct 18 |
peter |
77 |
suite.err() << "error: too small output\n"; |
3774 |
26 Oct 18 |
peter |
78 |
} |
3774 |
26 Oct 18 |
peter |
79 |
|
3771 |
25 Oct 18 |
peter |
80 |
vcf.close(); |
3763 |
19 Oct 18 |
peter |
81 |
return suite.return_value(); |
3763 |
19 Oct 18 |
peter |
82 |
} |