From 976d83968cc0bfa7b6edf927e1987bd3677871d3 Mon Sep 17 00:00:00 2001 From: dlcgold Date: Wed, 25 Jan 2023 16:28:13 +0100 Subject: [PATCH] minor fixes --- include/phi_ds.h | 74 +++++++++++++++++++------------------------- include/rlpbwt_int.h | 19 +++++++----- 2 files changed, 43 insertions(+), 50 deletions(-) diff --git a/include/phi_ds.h b/include/phi_ds.h index 2eee24ae..49bc82dc 100644 --- a/include/phi_ds.h +++ b/include/phi_ds.h @@ -32,47 +32,47 @@ class phi_ds { /** * @brief panel of sparse bitvectors for phi function */ - std::vector > phi_vec; + std::vector> phi_vec; /** * @brief panel of sparse bitvectors for phi_inv function */ - std::vector > phi_inv_vec; + std::vector> phi_inv_vec; /** * @brief panel of rank support for phi function */ - std::vector ::rank_1_type> phi_rank; + std::vector::rank_1_type> phi_rank; /** * @brief panel of rank support for phi_inv function */ - std::vector ::rank_1_type> phi_inv_rank; + std::vector::rank_1_type> phi_inv_rank; /** * @brief panel of select support for phi function */ - std::vector ::select_1_type> phi_select; + std::vector::select_1_type> phi_select; /** * @brief panel of select support for phi_inv function */ - std::vector ::select_1_type> phi_inv_select; + std::vector::select_1_type> phi_inv_select; /** * @brief compressed int vector for prefix samples used by phi function */ - std::vector > phi_supp; + std::vector> phi_supp; /** * @brief compressed int vector for prefix samples used by phi_inv function */ - std::vector > phi_inv_supp; + std::vector> phi_inv_supp; /** * @brief compressed int vector for prefix samples used by phi function */ - std::vector > phi_supp_l; + std::vector> phi_supp_l; /** @@ -92,12 +92,12 @@ class phi_ds { * @param last_pref last prefix array of the PBWT * @param verbose bool for extra prints */ - explicit phi_ds(std::vector &cols, unsigned int h, + explicit phi_ds(std::vector &cols, unsigned int h, unsigned int w, sdsl::int_vector<> &last_pref, sdsl::int_vector<> &last_div, - std::vector &supp_b, - std::vector &supp_e, + std::vector &supp_b, + std::vector &supp_e, bool verbose = false) { // default value is the panel height this->def = h; @@ -129,9 +129,9 @@ class phi_ds { this->phi_supp_l = std::vector>(h); // temporary vector for supports - std::vector > phi_supp_tmp(h); - std::vector > phi_inv_supp_tmp(h); - std::vector > phi_supp_tmp_l(h); + std::vector> phi_supp_tmp(h); + std::vector> phi_inv_supp_tmp(h); + std::vector> phi_supp_tmp_l(h); // build sparse bitvector for (unsigned int j = 0; j < def; j++) { @@ -289,8 +289,11 @@ class phi_ds { * @return previous prefix array value at current column (if exists) */ std::optional phi(unsigned int pref, unsigned int col) { - auto res = static_cast(this->phi_supp[pref][this->phi_rank[pref]( - col)]); + auto tmp_col = this->phi_rank[pref](col); + if(tmp_col == this->phi_supp[pref].size()){ + tmp_col--; + } + auto res = static_cast(this->phi_supp[pref][tmp_col]); if (res == this->def) { return std::nullopt; } else { @@ -305,8 +308,11 @@ class phi_ds { * @return next prefix array value at current column (if exists) */ std::optional phi_inv(unsigned int pref, unsigned int col) { - auto res = static_cast(this->phi_inv_supp[pref][this->phi_inv_rank[pref]( - col)]); + auto tmp_col = this->phi_inv_rank[pref](col); + if(tmp_col == this->phi_inv_supp[pref].size()){ + tmp_col--; + } + auto res = static_cast(this->phi_inv_supp[pref][tmp_col]); if (res == this->def) { return std::nullopt; } else { @@ -318,29 +324,12 @@ class phi_ds { if (col == 0 || !phi(pref, col).has_value()) { return 0; } -// unsigned int end_col = 1; -// std::cout << this->phi_vec[pref] << std::endl; -// std::cout << this->phi_rank[pref](col) << std::endl; -// std::cout << this->phi_select[pref](this->phi_rank[pref](col)+1) << std::endl; -// //std::cout << "make select\n"; -// if (col != 1) { -// end_col = this->phi_select[pref](col - 1); -// } - - auto end_col = this->phi_select[pref](this->phi_rank[pref](col) + 1); - //std::cout << "end col: " << end_col << "\n"; - auto tmp = static_cast(this->phi_supp_l[pref][this->phi_rank[pref]( - col)]); - //std::cout << "value at end: " << tmp << "\n"; - if (!phi(pref, end_col + 1).has_value()) { - //std::cout << "here\n"; - //tmp++; - } - if (end_col == w) { - + auto tmp_col = this->phi_rank[pref](col); + if(tmp_col == this->phi_supp[pref].size()){ + tmp_col--; } - //std::cout << "value at end: " << tmp << "\n"; - //std::cout << "diff: " << end_col - col << "\n"; + auto end_col = this->phi_select[pref](tmp_col + 1); + auto tmp = static_cast(this->phi_supp_l[pref][tmp_col]); auto plcp = tmp - (end_col - col); return plcp; } @@ -394,7 +383,8 @@ class phi_ds { if (verbose) { std::cout << "phi panels: " << size_panels << " megabytes\n"; std::cout << "phi support: " << size_supp << " megabytes\n"; - std::cout << "phi data structure (panels + support): " << size << " megabytes\n"; + std::cout << "phi data structure (panels + support): " << size + << " megabytes\n"; } return size; } diff --git a/include/rlpbwt_int.h b/include/rlpbwt_int.h index 84ac7c39..cc8b9cf8 100644 --- a/include/rlpbwt_int.h +++ b/include/rlpbwt_int.h @@ -515,6 +515,7 @@ class rlpbwt_int { // down while (check_down) { + // std::cout << "down\n"; auto phi_res = this->phi->phi_inv(start_row, curr_col + 1); @@ -522,19 +523,22 @@ class rlpbwt_int { break; } down_row = phi_res.value(); - //std::cout << "check d: " << down_row << " " << down_index << " " << curr_col << " " << start_row << "\n"; + // std::cout << "check d: " << down_row << " " << down_index << " " << curr_col << " " << start_row << "\n"; //std::cout << curr_len << " " - // << this->phi->plcp(down_row, curr_col) << "\n"; + // << this->phi->plcp(down_row, curr_col+1) << "\n"; if (this->phi->plcp(down_row, curr_col + 1) >= curr_len) { haplos.emplace_back(down_row); start_row = down_row; } else { check_down = false; } + //std::cout << "here " << check_down << "\n"; down_index++; } + start_row = std::get<0>(ms_matches.basic_matches[i]); + //std::cout << "jump " << up_index << " " << start_row << "\n"; // up while (check_up) { auto phi_res = this->phi->phi(start_row, @@ -819,7 +823,6 @@ class rlpbwt_int { this->cols.emplace_back(col); rlpbwt_int::update(new_column, pref, div); last_col = new_column; - count++; } std::cout << std::endl; @@ -828,18 +831,17 @@ class rlpbwt_int { this->last_pref[i] = pref[i]; this->last_div[i] = div[i]; } - auto col = rlpbwt_int::build_column(last_col, pref, div, supp_b, supp_e, count); this->cols.emplace_back(col); for (unsigned int i = 0; i < this->height; i++) { if (supp_b[i].v.size() == 0 || - supp_b[i].v[supp_b[i].v.size() - 1] != this->width) { + supp_b[i].v[supp_b[i].size - 1] != this->width) { supp_b[i].push_back(this->width); } supp_b[i].compress(); if (supp_e[i].v.size() == 0 || - supp_e[i].v[supp_e[i].v.size() - 1] != this->width) { + supp_e[i].v[supp_e[i].size - 1] != this->width) { supp_e[i].push_back(this->width); } supp_e[i].compress(); @@ -1156,10 +1158,10 @@ class rlpbwt_int { auto n_queries = queries.size(); std::vector matches_vec(n_queries); + #pragma omp parallel for default(none) \ shared(queries, matches_vec, n_queries, extend_matches, verbose) for (unsigned int i = 0; i < n_queries; i++) { - // std::cout << i << "\n"; matches_vec[i] = this->match_thr( queries[i], extend_matches, verbose); } @@ -1269,8 +1271,9 @@ class rlpbwt_int { std::vector matches_vec(n_queries); #pragma omp parallel for default(none) \ - shared(queries, matches_vec, n_queries, extend_matches, verbose) + shared(queries, matches_vec, n_queries, extend_matches, verbose, std::cout) for (unsigned int i = 0; i < n_queries; i++) { + //std::cout << "query: " << i << "\n"; matches_vec[i] = this->match_thr(queries[i], extend_matches, verbose);