Example on intervals and how to use it for layout calculation.As a use case this example uses genomics visualization for features mapped into genomic coordinates.
It is also illustartes vector model using coordinate ranges or feature vectors. Various properties of the initial model acn be dropped (sliced) to improve memory efficiency, better storage or network transfer.
This example does NOT do serialization of models (which is possible) for the clarity of the sample code.
#include <iostream>
#include <utility>
#include <vector>
#include <memory>
#include <cassert>
using namespace std;
{
void optimize();
};
{
for (size_t i = 0; i < layout_v.size(); ++i)
{
auto bv = layout_v[i].get();
if (bv)
bv->optimize(tb);
}
for (size_t i = 0; i < strand_v.size(); ++i)
{
auto strand_plane = strand_v[i].get();
if (strand_plane)
{
strand_plane->optimize(tb);
strand_plane->sync();
}
}
}
{
unique_ptr<bm::bvector<> > ap(bv);
if (layout_v.size() == plane)
{
layout_v.emplace_back(move(ap));
}
else
{
while (layout_v.size() < plane)
layout_v[plane] = std::move(ap);
}
}
{
unique_ptr<rsc_vector_u8 > ap(strand);
if (strand_v.size() == plane)
{
strand_v.emplace_back(move(ap));
}
else
{
while (strand_v.size() < plane)
strand_v[plane] = std::move(ap);
}
}
unsigned char strand)
{
if (!strand)
return;
{
}
if (!strand_plane)
{
dm.
strand_v[plane] = unique_ptr<rsc_vector_u8 >(strand_plane);
}
assert(strand_plane->
is_null(pos));
strand_plane->
set(pos, strand);
}
unsigned start, unsigned end,
unsigned char strand)
{
assert(start <= end);
for (
size_t i = 0; i < dm.
layout_v.size(); ++i)
{
if (!bv)
{
dm.
layout_v[i] = unique_ptr<bm::bvector<> >(bv);
return;
}
{
return;
}
}
}
bool copy_strands)
{
size_t t_plane = 0;
for (
size_t i = 0; i < dm.
layout_v.size(); ++i)
{
if (bv)
{
if (!found)
start_pos = start;
if (!found)
end_pos = end;
bv_ptr->copy_range(*bv, start_pos, end_pos);
if (bv_ptr->any())
{
if (copy_strands)
{
{
if (strand_plane)
{
strand_ptr->copy_range(*strand_plane, start_pos, end_pos);
dm_target.
add_strand(t_plane, strand_ptr.release());
}
}
}
++t_plane;
}
}
}
}
{
cout <<
"-------------------------------------------------------------------------"
<< endl <<
"ATGTTAGCCCGCGCATATTATATATGTAGCGTATTAAGCGDGGAGATTACCCTTGCATTAGGTTANNNNNNNN"
<< endl <<
"-------------------------------------------------------------------------"
<< endl;
for (
size_t i = 0; i < dm.
layout_v.size(); ++i)
{
if (bv)
{
if (ien.valid())
{
do
{
auto st = ien.start();
auto end = ien.
end();
char ch_strand = '?';
if (strand_plane)
{
auto strand = strand_plane->
get(st);
switch (strand)
{
case 0: ch_strand = '>'; break;
case 1: ch_strand = '<'; break;
default: break;
}
}
for (; spaces < st; ++spaces)
cout << " ";
for (bool first = true; st <= end; ++st, first = false)
{
if (st == end)
cout << ch_strand;
else
cout << (first ? ch_strand : '.');
}
spaces = end+1;
} while (ien.advance());
cout << endl;
}
}
}
}
{
try
{
{
cout << endl;
}
{
cout << endl;
}
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}