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;
{
};
{
for (
size_t i = 0; i <
layout_v.size(); ++i)
{
if (bv)
bv->optimize(tb);
}
for (
size_t i = 0; i <
strand_v.size(); ++i)
{
if (strand_plane)
{
strand_plane->optimize(tb);
strand_plane->sync();
}
}
}
{
unique_ptr<bm::bvector<> > ap(bv);
{
}
else
{
}
}
{
unique_ptr<rsc_vector_u8 > ap(strand);
{
}
else
{
}
}
static
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);
}
static
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;
}
}
}
static
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;
}
}
}
}
static
{
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;
}
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
#define BM_DECLARE_TEMP_BLOCK(x)
Algorithms for bit ranges and intervals.
Compressed sparse container rsc_sparse_vector<> for integer types.
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
bool any_range(size_type left, size_type right) const BMNOEXCEPT
Returns true if any bits in the range are 1s (non-empty interval) Function uses closed interval [left...
bvector_size_type size_type
enumerator end() const
Returns enumerator pointing on the next bit after the last.
bvector< Alloc > & set_range(size_type left, size_type right, bool value=true)
Sets all bits in the specified closed interval [left,right] Interval must be inside the bvector's siz...
forward iterator class to traverse bit-vector as ranges
Rank-Select compressed sparse vector.
void set(size_type idx, value_type v)
set specified element with bounds checking and automatic resize
value_type get(size_type idx) const BMNOEXCEPT
get specified element without bounds checking
bool is_null(size_type idx) const BMNOEXCEPT
test if specified element is NULL
succinct sparse vector with runtime compression using bit-slicing / transposition method
@ BM_GAP
GAP compression is ON.
bool find_interval_end(const BV &bv, typename BV::size_type from, typename BV::size_type &pos) BMNOEXCEPT
Reverse find index of first 1 bit gap (01110) starting from position Reverse scan for the first 1 in ...
bool find_interval_start(const BV &bv, typename BV::size_type from, typename BV::size_type &pos) BMNOEXCEPT
Reverse find index of first 1 bit gap (01110) starting from position Reverse scan for the first 1 in ...
Data frame object, sued to buid succinct data model.
void optimize()
Optimize memory layoput, build index for faster read access.
void add_strand(size_t plane, rsc_vector_u8 *strand)
void add_layout(size_t plane, bm::bvector<> *bv)
layout_vector_type layout_v
layout vector
starnds_vector_type strand_v
strand planes vector
bm::sparse_vector< unsigned char, bm::bvector<> > sparse_vector_u8
bm::interval_enumerator< bm::bvector<> > interval_enumerator_type
std::vector< std::unique_ptr< rsc_vector_u8 > > starnds_vector_type
bm::rsc_sparse_vector< unsigned char, sparse_vector_u8 > rsc_vector_u8
static void add_object(data_model &dm, unsigned start, unsigned end, unsigned char strand)
Register new object in the data model: [start..end] + strand.
static void set_feature_strand(data_model &dm, size_t plane, bm::bvector<>::size_type pos, unsigned char strand)
static void splice_model(data_model &dm_target, const data_model &dm, bm::bvector<>::size_type start, bm::bvector<>::size_type end, bool copy_strands)
Data model splicer.
static void print_model(const data_model &dm)
This is ASCII art "renderer" for the data model.
std::vector< std::unique_ptr< bm::bvector<> > > layout_vector_type