84 <<
"BitMagic SNP Search Sample Utility (c) 2018" << std::endl
85 <<
"-isnp file-name -- input set file (SNP FASTA) to parse" << std::endl
86 <<
"-svout spase vector output -- sparse vector name to save" << std::endl
87 <<
"-rscout rs-compressed spase vector output -- name to save" << std::endl
88 <<
"-svin sparse vector input -- sparse vector file name to load " << std::endl
89 <<
"-rscin rs-compressed sparse vector input -- file name to load " << std::endl
90 <<
"-diag -- run diagnostics" << std::endl
91 <<
"-timing -- collect timings" << std::endl
112 for (
int i = 1; i < argc; ++i)
114 std::string arg = argv[i];
115 if ((arg ==
"-h") || (arg ==
"--help"))
121 if (arg ==
"-svout" || arg ==
"--svout")
129 std::cerr <<
"Error: -svout requires file name" << std::endl;
134 if (arg ==
"-rscout" || arg ==
"--rscout")
142 std::cerr <<
"Error: -rscout requires file name" << std::endl;
148 if (arg ==
"-svin" || arg ==
"--svin")
156 std::cerr <<
"Error: -svin requires file name" << std::endl;
162 if (arg ==
"-rscin" || arg ==
"--rscin")
170 std::cerr <<
"Error: -rscin requires file name" << std::endl;
176 if (arg ==
"-isnp" || arg ==
"--isnp" || arg ==
"-snp" || arg ==
"--snp")
184 std::cerr <<
"Error: -isnp requires file name" << std::endl;
190 if (arg ==
"-diag" || arg ==
"--diag" || arg ==
"-d" || arg ==
"--d")
192 if (arg ==
"-timing" || arg ==
"--timing" || arg ==
"-t" || arg ==
"--t")
194 if (arg ==
"-bench" || arg ==
"--bench" || arg ==
"-b" || arg ==
"--b")
222 std::ifstream fin(fname.c_str(), std::ios::in);
226 unsigned rs_id, rs_pos;
230 std::string delim =
" \t";
232 std::regex reg(
"\\s+");
233 std::sregex_token_iterator it_end;
239 for (
unsigned i = 0; std::getline(fin, line); ++i)
242 !isdigit(line.front())
247 std::sregex_token_iterator it(line.begin(), line.end(), reg, -1);
248 std::vector<std::string> line_vec(it, it_end);
249 if (line_vec.empty())
255 rs_id = unsigned(std::stoul(line_vec.at(0), &idx));
257 if (bv_rs.
test(rs_id))
261 rs_pos = unsigned(std::stoul(line_vec.at(11), &idx));
264 sv.
set(rs_pos, rs_id);
268 catch (std::exception& )
280 if (rs_cnt % (4 * 1024) == 0)
281 std::cout <<
"\r" << rs_cnt <<
" / " << i;
284 std::cout << std::endl;
285 std::cout <<
"SNP count=" << rs_cnt << std::endl;
298 rand_sampler.
sample(bv_sample, *bv_null, count);
301 for (; en.
valid(); ++en)
304 unsigned v = sv[idx];
317 for (; it != it_end; ++it)
321 std::pair<unsigned, unsigned> pos2rs = std::make_pair(it.pos(), it.value());
322 vp.push_back(pos2rs);
332 for (
unsigned i = 0; i < vp.size(); ++i)
334 if (vp[i].second == rs_id)
351 const unsigned rs_sample_count = 2000;
353 std::vector<unsigned> rs_vect;
357 std::cerr <<
"Benchmark subset empty!" << std::endl;
384 for (
unsigned i = 0; i < rs_vect.size(); ++i)
386 unsigned rs_id = rs_vect[i];
388 bool found = scanner.
find_eq(sv, rs_id, rs_pos);
396 std::cout <<
"Error: rs_id = " << rs_id <<
" not found!" << std::endl;
407 for (
unsigned i = 0; i < rs_vect.size(); ++i)
409 unsigned rs_id = rs_vect[i];
411 bool found = scanner.
find_eq(csv, rs_id, rs_pos);
419 std::cout <<
"rs_id = " << rs_id <<
" not found!" << std::endl;
428 for (
unsigned i = 0; i < rs_vect.size(); ++i)
430 unsigned rs_id = rs_vect[i];
440 std::cout <<
"rs_id = " << rs_id <<
" not found!" << std::endl;
446 int res = bv_found1.
compare(bv_found2);
449 std::cerr <<
"Error: search discrepancy (sparse search) detected!" << std::endl;
451 res = bv_found1.
compare(bv_found3);
454 std::cerr <<
"Error: search discrepancy (std::vector<>) detected!" << std::endl;
460int main(
int argc,
char *argv[])
513 std::cerr <<
"Error: rs-compressed vector check failed!" << std::endl;
538 std::cout << std::endl
539 <<
"sparse vector statistics:"
541 bm::print_svector_stat(std::cout, sv,
true);
545 std::cout << std::endl
546 <<
"RS compressed sparse vector statistics:"
548 bm::print_svector_stat(std::cout, csv,
true);
559 std::cout << std::endl <<
"Performance:" << std::endl;
563 catch (std::exception& ex)
565 std::cerr <<
"Error:" << ex.what() << std::endl;
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
Algorithms for bvector<> (main include)
Generation of random subset.
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
Algorithms for bm::sparse_vector.
Compressed sparse container rsc_sparse_vector<> for integer types.
Serialization for sparse_vector<>
Timing utilities for benchmarking (internal)
pre-processor un-defines to avoid global space pollution (internal)
const bvector_type * get_null_bvector() const BMNOEXCEPT
Get bit-vector of assigned values or NULL (if not constructed that way)
Constant iterator designed to enumerate "ON" bits.
bool valid() const BMNOEXCEPT
Checks if iterator is still valid.
Bitvector Bit-vector container with runtime compression of bits.
bool test(size_type n) const BMNOEXCEPT
returns true if bit n is set and false is bit n is 0.
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
void init()
Explicit post-construction initialization. Must be caled to make sure safe use of *_no_check() method...
int compare(const bvector< Alloc > &bvect) const BMNOEXCEPT
Lexicographical comparison with a bitvector.
void set_bit_no_check(size_type n)
Set bit without checking preconditions (size, etc)
Utility class to collect performance measurements and statistics.
std::map< std::string, statistics > duration_map_type
test name to duration map
static void print_duration_map(TOut &tout, const duration_map_type &dmap, format fmt=ct_time)
void sample(BV &bv_out, const BV &bv_in, size_type sample_count)
Get random subset of input vector.
void load_from(const sparse_vector_type &sv_src)
Load compressed vector from a sparse vector (with NULLs)
void load_to(sparse_vector_type &sv) const
Exort compressed vector to a sparse vector (with NULLs)
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, statistics *stat=0)
run memory optimization for all vector slices
bool empty() const BMNOEXCEPT
return true if vector is empty
algorithms for sparse_vector scan/search
void find_eq(const SV &sv, value_type value, bvector_type &bv_out)
find all sparse vector elements EQ to search value
succinct sparse vector with runtime compression using bit-slicing / transposition method
bool equal(const sparse_vector< Val, BV > &sv, bm::null_support null_able=bm::use_null) const BMNOEXCEPT
check if another sparse vector has the same content and size
void push_back(value_type v)
push value back into vector
void set(size_type idx, value_type v)
set specified element with bounds checking and automatic resize
const_iterator end() const BMNOEXCEPT
Provide const iterator access to the end
bool empty() const BMNOEXCEPT
return true if vector is empty
const_iterator begin() const BMNOEXCEPT
Provide const iterator access to container content
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename sparse_vector< Val, BV >::statistics *stat=0)
run memory optimization for all vector planes
@ use_null
support "non-assigned" or "NULL" logic
int main(int argc, char *argv[])
static int parse_args(int argc, char *argv[])
std::vector< std::pair< unsigned, unsigned > > vector_pairs
static void build_vector_pairs(const sparse_vector_u32 &sv, vector_pairs &vp)
bm::sparse_vector< unsigned, bm::bvector<> > sparse_vector_u32
static bool search_vector_pairs(const vector_pairs &vp, unsigned rs_id, unsigned &pos)
bm::chrono_taker ::duration_map_type timing_map
bm::rsc_sparse_vector< unsigned, sparse_vector_u32 > rsc_sparse_vector_u32
static void generate_random_subset(const sparse_vector_u32 &sv, std::vector< unsigned > &vect, unsigned count)
static int load_snp_report(const std::string &fname, sparse_vector_u32 &sv)
static void run_benchmark(const sparse_vector_u32 &sv, const rsc_sparse_vector_u32 &csv)