forked from Illumina/manta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSVLocusSerializeTest.cpp
155 lines (122 loc) · 4.19 KB
/
SVLocusSerializeTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// Manta - Structural Variant and Indel Caller
// Copyright (c) 2013-2019 Illumina, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
#include "boost/test/unit_test.hpp"
#include "svgraph/SVLocus.hpp"
#include "test/testFileMakers.hpp"
#include "test/testSVLocusUtil.hpp"
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "boost/archive/text_iarchive.hpp"
#include "boost/archive/text_oarchive.hpp"
#include <fstream>
using namespace boost::archive;
BOOST_AUTO_TEST_SUITE(test_SVLocusSerialize)
// test serialization with a very simple class first:
//
template <typename InputArchiver, typename OutputArchiver>
static void GenomeIntervalSerializeTest()
{
// construct a simple two-node locus
GenomeInterval gi(1, 10, 20);
TestFilenameMaker testFilenameMaker;
const char* testFilenamePtr(testFilenameMaker.getFilename().c_str());
// serialize
{
std::ofstream ofs(testFilenamePtr, std::ios::binary);
OutputArchiver oa(ofs);
oa << gi;
}
GenomeInterval gi_copy;
// deserialize
{
std::ifstream ifs(testFilenamePtr, std::ios::binary);
InputArchiver ia(ifs);
ia >> gi_copy;
}
BOOST_REQUIRE_EQUAL(gi, gi_copy);
}
BOOST_AUTO_TEST_CASE(test_GenomeIntervalSerializeText)
{
GenomeIntervalSerializeTest<text_iarchive, text_oarchive>();
}
BOOST_AUTO_TEST_CASE(test_GenomeIntervalSerializeBinary)
{
GenomeIntervalSerializeTest<binary_iarchive, binary_oarchive>();
}
BOOST_AUTO_TEST_CASE(test_SVLocusNodeSerialize)
{
// construct a simple two-node locus
SVLocus locus1;
locusAddPair(locus1, 1, 10, 20, 1, 30, 40);
TestFilenameMaker testFilenameMaker;
const char* testFilenamePtr(testFilenameMaker.getFilename().c_str());
const SVLocusNode& node1(static_cast<const SVLocus&>(locus1).getNode(0));
// serialize
{
std::ofstream ofs(testFilenamePtr, std::ios::binary);
binary_oarchive oa(ofs);
oa << node1;
}
SVLocusNode node_copy1;
// deserialize
{
std::ifstream ifs(testFilenamePtr, std::ios::binary);
binary_iarchive ia(ifs);
ia >> node_copy1;
}
BOOST_REQUIRE_EQUAL(node1.outCount(), node_copy1.outCount());
BOOST_REQUIRE_EQUAL(node1.getInterval(), node_copy1.getInterval());
BOOST_REQUIRE_EQUAL(node1.size(), node_copy1.size());
const SVLocusEdgeManager node1Manager(node1.getEdgeManager());
const SVLocusEdgeManager node1CopyManager(node_copy1.getEdgeManager());
SVLocusEdgesType::const_iterator ibegin(node1Manager.getMap().begin());
SVLocusNode::const_iterator copy_ibegin(node1CopyManager.getMap().begin());
BOOST_REQUIRE_EQUAL(ibegin->second.getCount(), copy_ibegin->second.getCount());
BOOST_REQUIRE_EQUAL(ibegin->first, copy_ibegin->first);
}
BOOST_AUTO_TEST_CASE(test_SVLocusSerialize)
{
// construct a simple two-node locus
SVLocus locus1;
locusAddPair(locus1, 1, 10, 20, 1, 30, 40);
TestFilenameMaker testFilenameMaker;
const char* testFilenamePtr(testFilenameMaker.getFilename().c_str());
// serialize
{
std::ofstream ofs(testFilenamePtr, std::ios::binary);
binary_oarchive oa(ofs);
oa << locus1;
}
SVLocus locus1_copy;
// deserialize
{
std::ifstream ifs(testFilenamePtr, std::ios::binary);
binary_iarchive ia(ifs);
ia >> locus1_copy;
}
BOOST_REQUIRE_EQUAL(locus1.size(), locus1_copy.size());
const SVLocus& clocus1(locus1);
const SVLocus& clocus1_copy(locus1_copy);
bool isMatchFound(false);
for (const SVLocusNode& node : clocus1_copy) {
if (node.getInterval() == (clocus1.begin())->getInterval()) isMatchFound = true;
}
BOOST_REQUIRE(isMatchFound);
}
BOOST_AUTO_TEST_SUITE_END()