3759 |
17 Oct 18 |
peter |
// $Id$ |
3759 |
17 Oct 18 |
peter |
2 |
|
3759 |
17 Oct 18 |
peter |
3 |
/* |
3759 |
17 Oct 18 |
peter |
Copyright (C) 2018 Peter Johansson |
3759 |
17 Oct 18 |
peter |
5 |
|
3759 |
17 Oct 18 |
peter |
The yat library is free software; you can redistribute it and/or |
3759 |
17 Oct 18 |
peter |
modify it under the terms of the GNU General Public License as |
3759 |
17 Oct 18 |
peter |
published by the Free Software Foundation; either version 3 of the |
3759 |
17 Oct 18 |
peter |
License, or (at your option) any later version. |
3759 |
17 Oct 18 |
peter |
10 |
|
3759 |
17 Oct 18 |
peter |
The yat library is distributed in the hope that it will be useful, |
3759 |
17 Oct 18 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3759 |
17 Oct 18 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3759 |
17 Oct 18 |
peter |
General Public License for more details. |
3759 |
17 Oct 18 |
peter |
15 |
|
3759 |
17 Oct 18 |
peter |
You should have received a copy of the GNU General Public License |
3759 |
17 Oct 18 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3759 |
17 Oct 18 |
peter |
18 |
*/ |
3759 |
17 Oct 18 |
peter |
19 |
|
3759 |
17 Oct 18 |
peter |
20 |
|
3759 |
17 Oct 18 |
peter |
21 |
#include <config.h> |
3759 |
17 Oct 18 |
peter |
22 |
|
3759 |
17 Oct 18 |
peter |
23 |
#include "VcfCompare.h" |
3759 |
17 Oct 18 |
peter |
24 |
|
3759 |
17 Oct 18 |
peter |
25 |
#include "VCF.h" |
3759 |
17 Oct 18 |
peter |
26 |
#include "VcfHeader.h" |
3759 |
17 Oct 18 |
peter |
27 |
|
3759 |
17 Oct 18 |
peter |
28 |
#include <yat/utility/Exception.h> |
3759 |
17 Oct 18 |
peter |
29 |
#include <yat/utility/stl_utility.h> |
3759 |
17 Oct 18 |
peter |
30 |
#include <yat/utility/split.h> |
3759 |
17 Oct 18 |
peter |
31 |
|
3759 |
17 Oct 18 |
peter |
32 |
#include <cassert> |
3759 |
17 Oct 18 |
peter |
33 |
#include <vector> |
3759 |
17 Oct 18 |
peter |
34 |
#include <sstream> |
3759 |
17 Oct 18 |
peter |
35 |
#include <string> |
3759 |
17 Oct 18 |
peter |
36 |
|
3759 |
17 Oct 18 |
peter |
37 |
namespace theplu { |
3759 |
17 Oct 18 |
peter |
38 |
namespace yat { |
3759 |
17 Oct 18 |
peter |
39 |
namespace omic { |
3759 |
17 Oct 18 |
peter |
40 |
|
3759 |
17 Oct 18 |
peter |
41 |
VcfCompare::VcfCompare(void) |
3759 |
17 Oct 18 |
peter |
42 |
{} |
3759 |
17 Oct 18 |
peter |
43 |
|
3759 |
17 Oct 18 |
peter |
44 |
|
3759 |
17 Oct 18 |
peter |
45 |
VcfCompare::VcfCompare(const VcfHeader& hdr) |
3759 |
17 Oct 18 |
peter |
46 |
{ |
3759 |
17 Oct 18 |
peter |
47 |
for (size_t i=0; i<hdr.size(); ++i) { |
3759 |
17 Oct 18 |
peter |
48 |
if (hdr.key(i) != "contig") |
3759 |
17 Oct 18 |
peter |
49 |
continue; |
3759 |
17 Oct 18 |
peter |
50 |
std::vector<std::string> vec; |
3759 |
17 Oct 18 |
peter |
51 |
utility::split(vec, hdr.value(i), "=,"); |
3759 |
17 Oct 18 |
peter |
52 |
assert(vec.size()>1); |
3759 |
17 Oct 18 |
peter |
53 |
int n = chr2tid_.size(); |
3759 |
17 Oct 18 |
peter |
54 |
chr2tid_[vec[1]] = n; |
3759 |
17 Oct 18 |
peter |
55 |
} |
3759 |
17 Oct 18 |
peter |
56 |
} |
3759 |
17 Oct 18 |
peter |
57 |
|
3759 |
17 Oct 18 |
peter |
58 |
|
3759 |
17 Oct 18 |
peter |
59 |
bool VcfCompare::operator()(const VCF& lhs, const VCF& rhs) const |
3759 |
17 Oct 18 |
peter |
60 |
{ |
3759 |
17 Oct 18 |
peter |
61 |
if (lhs.chromosome() != rhs.chromosome()) { |
3759 |
17 Oct 18 |
peter |
62 |
try { |
3759 |
17 Oct 18 |
peter |
63 |
return utility::get(chr2tid_, lhs.chromosome()) < |
3759 |
17 Oct 18 |
peter |
64 |
utility::get(chr2tid_, rhs.chromosome()); |
3759 |
17 Oct 18 |
peter |
65 |
} |
3759 |
17 Oct 18 |
peter |
66 |
catch (const utility::get_error<std::string>& e) { |
3759 |
17 Oct 18 |
peter |
67 |
std::ostringstream msg; |
3759 |
17 Oct 18 |
peter |
68 |
msg << "VcfCompare: unknown chromosome: " << e.key(); |
3759 |
17 Oct 18 |
peter |
69 |
throw utility::runtime_error(msg.str()); |
3759 |
17 Oct 18 |
peter |
70 |
} |
3759 |
17 Oct 18 |
peter |
71 |
} |
3759 |
17 Oct 18 |
peter |
72 |
|
3759 |
17 Oct 18 |
peter |
73 |
if (lhs.pos() != rhs.pos()) |
3759 |
17 Oct 18 |
peter |
74 |
return lhs.pos() < rhs.pos(); |
3759 |
17 Oct 18 |
peter |
75 |
|
3759 |
17 Oct 18 |
peter |
76 |
if (lhs.ref() != rhs.ref()) |
3759 |
17 Oct 18 |
peter |
77 |
return lhs.ref() < rhs.ref(); |
3759 |
17 Oct 18 |
peter |
78 |
|
3759 |
17 Oct 18 |
peter |
79 |
return lhs.alt() < rhs.alt(); |
3759 |
17 Oct 18 |
peter |
80 |
} |
3759 |
17 Oct 18 |
peter |
81 |
|
3759 |
17 Oct 18 |
peter |
82 |
}}} |