Skip to content

Commit

Permalink
Merge pull request #102 from vgteam/i99_odgi_bin_nuc_pos
Browse files Browse the repository at this point in the history
fixes #99
  • Loading branch information
subwaystation authored Apr 10, 2020
2 parents 5e18490 + 49acd60 commit c09c983
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/algorithms/bin_path_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/algorithms/bin_path_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ namespace odgi {
double mean_cov;
double mean_inv;
double mean_pos;
long int first_nucleotide;
long int last_nucleotide;
vector<std::pair<uint64_t,uint64_t>> ranges;
// long int first_nucleotide;
// long int last_nucleotide;
};

void bin_path_info(const PathHandleGraph &graph,
Expand Down
26 changes: 20 additions & 6 deletions src/subcommand/bin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(const uint64_t&, const uint64_t&)> write_header_tsv
= [&] (const uint64_t pangenome_length, const uint64_t bin_width) {
Expand Down Expand Up @@ -130,6 +130,20 @@ int main_bin(int argc, char** argv) {
}
};

std::function<void(const vector<std::pair<uint64_t , uint64_t >>&)> write_ranges_json
= [&](const vector<std::pair<uint64_t , uint64_t >>& ranges) {
std::cout << "[";
for (int i = 0; i < ranges.size(); i++) {
std::pair<uint64_t, uint64_t > range = ranges[i];
if (i == 0) {
std::cout << "[" << range.first << "," << range.second << "]";
} else {
std::cout << "," << "[" << range.first << "," << range.second << "]";
}
}
std::cout << "]";
};

std::function<void(const std::string&,
const std::vector<std::pair<uint64_t, uint64_t>>&,
const std::map<uint64_t, algorithms::path_info_t>&)> write_json
Expand All @@ -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 << ",";
}
Expand Down Expand Up @@ -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;
}
}
};
Expand Down

0 comments on commit c09c983

Please sign in to comment.