Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dlcgold committed Jan 25, 2023
1 parent e48513d commit 976d839
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 50 deletions.
74 changes: 32 additions & 42 deletions include/phi_ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,47 @@ class phi_ds {
/**
* @brief panel of sparse bitvectors for phi function
*/
std::vector <sdsl::sd_vector<>> phi_vec;
std::vector<sdsl::sd_vector<>> phi_vec;

/**
* @brief panel of sparse bitvectors for phi_inv function
*/
std::vector <sdsl::sd_vector<>> phi_inv_vec;
std::vector<sdsl::sd_vector<>> phi_inv_vec;

/**
* @brief panel of rank support for phi function
*/
std::vector <sdsl::sd_vector<>::rank_1_type> phi_rank;
std::vector<sdsl::sd_vector<>::rank_1_type> phi_rank;

/**
* @brief panel of rank support for phi_inv function
*/
std::vector <sdsl::sd_vector<>::rank_1_type> phi_inv_rank;
std::vector<sdsl::sd_vector<>::rank_1_type> phi_inv_rank;

/**
* @brief panel of select support for phi function
*/
std::vector <sdsl::sd_vector<>::select_1_type> phi_select;
std::vector<sdsl::sd_vector<>::select_1_type> phi_select;

/**
* @brief panel of select support for phi_inv function
*/
std::vector <sdsl::sd_vector<>::select_1_type> phi_inv_select;
std::vector<sdsl::sd_vector<>::select_1_type> phi_inv_select;

/**
* @brief compressed int vector for prefix samples used by phi function
*/
std::vector <sdsl::int_vector<>> phi_supp;
std::vector<sdsl::int_vector<>> phi_supp;

/**
* @brief compressed int vector for prefix samples used by phi_inv function
*/
std::vector <sdsl::int_vector<>> phi_inv_supp;
std::vector<sdsl::int_vector<>> phi_inv_supp;

/**
* @brief compressed int vector for prefix samples used by phi function
*/
std::vector <sdsl::int_vector<>> phi_supp_l;
std::vector<sdsl::int_vector<>> phi_supp_l;


/**
Expand All @@ -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 <rl_column> &cols, unsigned int h,
explicit phi_ds(std::vector<rl_column> &cols, unsigned int h,
unsigned int w,
sdsl::int_vector<> &last_pref,
sdsl::int_vector<> &last_div,
std::vector <intv> &supp_b,
std::vector <intv> &supp_e,
std::vector<intv> &supp_b,
std::vector<intv> &supp_e,
bool verbose = false) {
// default value is the panel height
this->def = h;
Expand Down Expand Up @@ -129,9 +129,9 @@ class phi_ds {
this->phi_supp_l = std::vector<sdsl::int_vector<>>(h);

// temporary vector for supports
std::vector <std::vector<unsigned int>> phi_supp_tmp(h);
std::vector <std::vector<unsigned int>> phi_inv_supp_tmp(h);
std::vector <std::vector<unsigned int>> phi_supp_tmp_l(h);
std::vector<std::vector<unsigned int>> phi_supp_tmp(h);
std::vector<std::vector<unsigned int>> phi_inv_supp_tmp(h);
std::vector<std::vector<unsigned int>> phi_supp_tmp_l(h);

// build sparse bitvector
for (unsigned int j = 0; j < def; j++) {
Expand Down Expand Up @@ -289,8 +289,11 @@ class phi_ds {
* @return previous prefix array value at current column (if exists)
*/
std::optional<unsigned int> phi(unsigned int pref, unsigned int col) {
auto res = static_cast<unsigned int>(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<unsigned int>(this->phi_supp[pref][tmp_col]);
if (res == this->def) {
return std::nullopt;
} else {
Expand All @@ -305,8 +308,11 @@ class phi_ds {
* @return next prefix array value at current column (if exists)
*/
std::optional<unsigned int> phi_inv(unsigned int pref, unsigned int col) {
auto res = static_cast<unsigned int>(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<unsigned int>(this->phi_inv_supp[pref][tmp_col]);
if (res == this->def) {
return std::nullopt;
} else {
Expand All @@ -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<int>(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<int>(this->phi_supp_l[pref][tmp_col]);
auto plcp = tmp - (end_col - col);
return plcp;
}
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 11 additions & 8 deletions include/rlpbwt_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,26 +515,30 @@ class rlpbwt_int {

// down
while (check_down) {
// std::cout << "down\n";
auto phi_res = this->phi->phi_inv(start_row,
curr_col + 1);

if (!phi_res.has_value()) {
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,
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -1156,10 +1158,10 @@ class rlpbwt_int {

auto n_queries = queries.size();
std::vector <ms_matches> 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);
}
Expand Down Expand Up @@ -1269,8 +1271,9 @@ class rlpbwt_int {
std::vector <ms_matches> 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);
Expand Down

0 comments on commit 976d839

Please sign in to comment.