-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbbi_test.cc
91 lines (68 loc) · 2.16 KB
/
bbi_test.cc
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
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <vector>
#include "main_header.h"
#include "zoom_header.h"
#include "records.h"
#include "total_summary_header.h"
#include "bp_tree.h"
#include "r_tree.h"
#include "chromosome_tree.h"
#include "bbi_file.h"
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: $ bbi-tools <filename>\n";
exit(EXIT_FAILURE);
}
std::string filename(argv[1]);
std::ifstream is(filename);
if (!is.good()) {
std::cerr << "couldn't open file " << filename << '\n';
exit(1);
}
bbi_file bbi(is);
// Prints the main headers.
//
bbi.print_headers(std::cout);
// Prints the main zoom headers.
//
for (auto& zh : bbi.z_hdrs)
zh.print(std::cout);
// Obtains any r-tree leaf nodes whose intervals contain our records in
// the main data section, (zoom level 0).
//
auto chrom_id = bbi.chrom_tree.chrom_id("chr21");
auto leaves = bbi.search_r_tree({chrom_id, 9500000, 45000000}, 0);
// Prints the r-tree leaf nodes.
//
for (auto& ln : leaves) {
std::cout << "\n**** r-tree leaf node ****\n";
ln.print(std::cout);
std::cout << '\n';
}
// Prints out the data blocks for the first leaf node if one was returned.
//
if (!leaves.empty()) {
std::cout << "\n**** data records ****\n";
r_tree::leaf_node ln = leaves.front();
auto bdrs = bbi.records_for_leaf<bed_record>(ln);
for (auto& bdr : bdrs)
bdr.print(std::cout);
}
// Obtains any r-tree leaf nodes whose intervals contain our records in
// the first zoom data section, (zoom level 1).
//
chrom_id = bbi.chrom_tree.chrom_id("chr21");
leaves = bbi.search_r_tree({chrom_id, 9500000, 45000000}, 1);
// Prints out the data blocks for the first leaf node if one was returned.
//
if (!leaves.empty()) {
std::cout << "\n**** data records ****\n";
r_tree::leaf_node ln = leaves.front();
auto zdrs = bbi.records_for_leaf<zoom_record>(ln);
for (auto& zdr : zdrs)
zdr.print(std::cout);
}
return 0;
}