diff --git a/src/algorithms/bin_path_info.cpp b/src/algorithms/bin_path_info.cpp index e73c0c23..4f81a17a 100644 --- a/src/algorithms/bin_path_info.cpp +++ b/src/algorithms/bin_path_info.cpp @@ -71,10 +71,13 @@ void bin_path_info(const PathHandleGraph& graph, } bins[curr_bin].mean_pos += path_pos++; nucleotide_count += 1; - if(bins[curr_bin].first_nucleotide == 0){ - bins[curr_bin].first_nucleotide = nucleotide_count; - } - bins[curr_bin].last_nucleotide = nucleotide_count; + if((bins[curr_bin].ranges.size() == 0) || + ((nucleotide_count - bins[curr_bin].ranges.back().second) > 1)){ + bins[curr_bin].ranges.push_back(std::make_pair(nucleotide_count, nucleotide_count)); + // bins[curr_bin].first_nucleotide = nucleotide_count; + } else { + bins[curr_bin].ranges.back().second = nucleotide_count; + } last_bin = curr_bin; last_is_rev = is_rev; last_pos_in_bin = curr_pos_in_bin; diff --git a/src/algorithms/bin_path_info.hpp b/src/algorithms/bin_path_info.hpp index 1b16b8ca..f7d8fa41 100644 --- a/src/algorithms/bin_path_info.hpp +++ b/src/algorithms/bin_path_info.hpp @@ -23,8 +23,9 @@ namespace odgi { double mean_cov; double mean_inv; double mean_pos; - long int first_nucleotide; - long int last_nucleotide; + vector> ranges; + // long int first_nucleotide; + // long int last_nucleotide; }; void bin_path_info(const PathHandleGraph &graph, diff --git a/src/subcommand/bin_main.cpp b/src/subcommand/bin_main.cpp index 01aaf088..bd0a519e 100644 --- a/src/subcommand/bin_main.cpp +++ b/src/subcommand/bin_main.cpp @@ -83,7 +83,7 @@ int main_bin(int argc, char** argv) { } // ODGI JSON VERSION - const uint64_t ODGI_JSON_VERSION = 10; + const uint64_t ODGI_JSON_VERSION = 12; // this brings the exact nucleotide positions for each bin for each path referred to as ranges std::function write_header_tsv = [&] (const uint64_t pangenome_length, const uint64_t bin_width) { @@ -130,6 +130,20 @@ int main_bin(int argc, char** argv) { } }; + std::function>&)> write_ranges_json + = [&](const vector>& ranges) { + std::cout << "["; + for (int i = 0; i < ranges.size(); i++) { + std::pair range = ranges[i]; + if (i == 0) { + std::cout << "[" << range.first << "," << range.second << "]"; + } else { + std::cout << "," << "[" << range.first << "," << range.second << "]"; + } + } + std::cout << "]"; + }; + std::function>&, const std::map&)> write_json @@ -151,9 +165,9 @@ int main_bin(int argc, char** argv) { std::cout << "[" << bin_id << "," << info.mean_cov << "," << info.mean_inv << "," - << info.mean_pos << "," - << info.first_nucleotide << "," - << info.last_nucleotide << "]"; + << info.mean_pos << ","; + write_ranges_json(info.ranges); + std::cout << "]"; if (i+1 != bins.size()) { std::cout << ","; } @@ -193,8 +207,8 @@ int main_bin(int argc, char** argv) { << info.mean_cov << "\t" << info.mean_inv << "\t" << info.mean_pos << "\t" - << info.first_nucleotide << "\t" - << info.last_nucleotide << std::endl; + << info.ranges[0].first << "\t" + << info.ranges[info.ranges.size() - 1].second << std::endl; } } };