4044 |
01 Mar 21 |
peter |
// $Id$ |
4044 |
01 Mar 21 |
peter |
2 |
|
4044 |
01 Mar 21 |
peter |
3 |
/* |
4252 |
18 Nov 22 |
peter |
Copyright (C) 2021, 2022 Peter Johansson |
4044 |
01 Mar 21 |
peter |
5 |
|
4044 |
01 Mar 21 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
4044 |
01 Mar 21 |
peter |
7 |
|
4044 |
01 Mar 21 |
peter |
The yat library is free software; you can redistribute it and/or |
4044 |
01 Mar 21 |
peter |
modify it under the terms of the GNU General Public License as |
4044 |
01 Mar 21 |
peter |
published by the Free Software Foundation; either version 3 of the |
4044 |
01 Mar 21 |
peter |
License, or (at your option) any later version. |
4044 |
01 Mar 21 |
peter |
12 |
|
4044 |
01 Mar 21 |
peter |
The yat library is distributed in the hope that it will be useful, |
4044 |
01 Mar 21 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4044 |
01 Mar 21 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4044 |
01 Mar 21 |
peter |
General Public License for more details. |
4044 |
01 Mar 21 |
peter |
17 |
|
4044 |
01 Mar 21 |
peter |
You should have received a copy of the GNU General Public License |
4044 |
01 Mar 21 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
4044 |
01 Mar 21 |
peter |
20 |
*/ |
4044 |
01 Mar 21 |
peter |
21 |
|
4044 |
01 Mar 21 |
peter |
22 |
#include <config.h> |
4044 |
01 Mar 21 |
peter |
23 |
|
4044 |
01 Mar 21 |
peter |
24 |
#include "Suite.h" |
4044 |
01 Mar 21 |
peter |
25 |
|
4044 |
01 Mar 21 |
peter |
26 |
#include "yat/omic/VCF.h" |
4044 |
01 Mar 21 |
peter |
27 |
#include "yat/omic/VcfCompare.h" |
4044 |
01 Mar 21 |
peter |
28 |
#include "yat/omic/VcfFile.h" |
4044 |
01 Mar 21 |
peter |
29 |
#include "yat/omic/VcfHeader.h" |
4044 |
01 Mar 21 |
peter |
30 |
#include "yat/omic/VcfIterator.h" |
4044 |
01 Mar 21 |
peter |
31 |
|
4044 |
01 Mar 21 |
peter |
32 |
#include "yat/utility/multiprocess.h" |
4044 |
01 Mar 21 |
peter |
33 |
|
4044 |
01 Mar 21 |
peter |
34 |
#include <algorithm> |
4044 |
01 Mar 21 |
peter |
35 |
#include <iterator> |
4044 |
01 Mar 21 |
peter |
36 |
|
4044 |
01 Mar 21 |
peter |
37 |
using namespace theplu::yat; |
4044 |
01 Mar 21 |
peter |
38 |
|
4044 |
01 Mar 21 |
peter |
39 |
struct Processor |
4044 |
01 Mar 21 |
peter |
40 |
{ |
4044 |
01 Mar 21 |
peter |
41 |
bool operator()(omic::VCF& vcf) const |
4044 |
01 Mar 21 |
peter |
42 |
{ |
4044 |
01 Mar 21 |
peter |
43 |
if (vcf.n_alleles() != 1) |
4044 |
01 Mar 21 |
peter |
44 |
return false; |
4044 |
01 Mar 21 |
peter |
45 |
vcf.id("."); |
4044 |
01 Mar 21 |
peter |
46 |
return true; |
4044 |
01 Mar 21 |
peter |
47 |
} |
4044 |
01 Mar 21 |
peter |
48 |
}; |
4044 |
01 Mar 21 |
peter |
49 |
|
4044 |
01 Mar 21 |
peter |
50 |
|
4044 |
01 Mar 21 |
peter |
51 |
struct IntFunction |
4044 |
01 Mar 21 |
peter |
52 |
{ |
4044 |
01 Mar 21 |
peter |
53 |
bool operator()(int s) const |
4044 |
01 Mar 21 |
peter |
54 |
{ |
4044 |
01 Mar 21 |
peter |
55 |
return true; |
4044 |
01 Mar 21 |
peter |
56 |
} |
4044 |
01 Mar 21 |
peter |
57 |
}; |
4044 |
01 Mar 21 |
peter |
58 |
|
4044 |
01 Mar 21 |
peter |
59 |
|
4044 |
01 Mar 21 |
peter |
60 |
int main(int argc, char* argv[]) |
4044 |
01 Mar 21 |
peter |
61 |
{ |
4044 |
01 Mar 21 |
peter |
62 |
test::Suite suite(argc, argv); |
4252 |
18 Nov 22 |
peter |
63 |
suite.require_foo_vcf_gz(); |
4044 |
01 Mar 21 |
peter |
64 |
omic::VcfFile file("../../data/foo.vcf.gz"); |
4044 |
01 Mar 21 |
peter |
65 |
omic::VcfCompare compare(file.header()); |
4044 |
01 Mar 21 |
peter |
66 |
omic::VcfIterator vcf(file); |
4044 |
01 Mar 21 |
peter |
67 |
omic::VcfIterator end; |
4044 |
01 Mar 21 |
peter |
68 |
std::vector<omic::VCF> result; |
4044 |
01 Mar 21 |
peter |
69 |
Processor processor; |
4044 |
01 Mar 21 |
peter |
70 |
|
4044 |
01 Mar 21 |
peter |
71 |
utility::multiprocess(vcf, end, std::back_inserter(result), |
4044 |
01 Mar 21 |
peter |
72 |
100, 4, 100, processor, compare); |
4044 |
01 Mar 21 |
peter |
73 |
|
4044 |
01 Mar 21 |
peter |
74 |
if (result.size() != 7) { |
4044 |
01 Mar 21 |
peter |
75 |
suite.add(false); |
4044 |
01 Mar 21 |
peter |
76 |
suite.err() << "error: " << result.size() |
4044 |
01 Mar 21 |
peter |
77 |
<< " resulting entries; expected 8\n"; |
4044 |
01 Mar 21 |
peter |
78 |
} |
4044 |
01 Mar 21 |
peter |
79 |
if (std::is_sorted(result.begin(), result.end(), compare)==false) { |
4044 |
01 Mar 21 |
peter |
80 |
suite.add(false); |
4044 |
01 Mar 21 |
peter |
81 |
suite.err() << "result is not sorted\n"; |
4044 |
01 Mar 21 |
peter |
82 |
std::copy(result.begin(), result.end(), |
4044 |
01 Mar 21 |
peter |
83 |
std::ostream_iterator<omic::VCF>(suite.err(), "\n")); |
4044 |
01 Mar 21 |
peter |
84 |
} |
4044 |
01 Mar 21 |
peter |
85 |
|
4044 |
01 Mar 21 |
peter |
// test that shorter version compiles |
4044 |
01 Mar 21 |
peter |
87 |
std::vector<int> input; |
4044 |
01 Mar 21 |
peter |
88 |
std::vector<double> output; |
4044 |
01 Mar 21 |
peter |
89 |
IntFunction function; |
4044 |
01 Mar 21 |
peter |
90 |
utility::multiprocess(input.begin(), input.end(), output.begin(), |
4044 |
01 Mar 21 |
peter |
91 |
10, 2, 100, function); |
4044 |
01 Mar 21 |
peter |
92 |
|
4044 |
01 Mar 21 |
peter |
93 |
return suite.return_value(); |
4044 |
01 Mar 21 |
peter |
94 |
} |