Commit 4cee4ee2 authored by Romain Feron's avatar Romain Feron
Browse files

Fixed popmap issue in depths

parent 49459e0a
......@@ -5,10 +5,9 @@ void depth(Parameters& parameters) {
std::chrono::steady_clock::time_point t_begin = std::chrono::steady_clock::now();
Popmap popmap = load_popmap(parameters);
Popmap popmap = load_popmap(parameters, false);
log("RADSex depth started");
Header header;
Depths depths(popmap.n_individuals);
......@@ -38,7 +37,7 @@ void depth(Parameters& parameters) {
const uint16_t min_depth = *start;
const uint16_t max_depth = *end;
const uint64_t total_depth = std::accumulate(depths[i].begin(), depths[i].end(), 0);
const uint64_t total_depth = static_cast<uint64_t>(std::accumulate(depths[i].begin(), depths[i].end(), 0));
uint16_t median_depth = 0;
if (depths[i].size() % 2 == 0) { // Find median for an even sized vector (average of two possible median points)
......
#include "popmap.h"
Popmap load_popmap(Parameters& parameters) {
Popmap load_popmap(Parameters& parameters, bool compare) {
/* Load a popmap file.
* Input: a tabulated file with columns Individual Group
......@@ -37,22 +37,22 @@ Popmap load_popmap(Parameters& parameters) {
exit(1);
}
if (popmap.counts.size() < 2) { // Fewer than two groups in the popmap
if (compare and popmap.counts.size() < 2) { // Fewer than two groups in the popmap
log("Found <" + std::to_string(popmap.counts.size()) + "> groups in the popmap file (" + print_groups(popmap) + ") but at least two are required", LOG_ERROR);
exit(1);
} else if (popmap.counts.size() > 2 and (parameters.group1 == "" or parameters.group2 == "")) { // More than two groups but groups to compare were not defined
} else if (compare and popmap.counts.size() > 2 and (parameters.group1 == "" or parameters.group2 == "")) { // More than two groups but groups to compare were not defined
log("Found <" + std::to_string(popmap.counts.size()) + "> groups in the popmap file (" + print_groups(popmap) + ") but groups to compare were not defined (use --groups group1,group2)", LOG_ERROR);
exit(1);
} else if (popmap.counts.size() > 2 and (popmap.counts.find(parameters.group1) == popmap.counts.end() or popmap.counts.find(parameters.group2) == popmap.counts.end())) { // More than two groups and groups to compare were not found
} else if (compare and popmap.counts.size() > 2 and (popmap.counts.find(parameters.group1) == popmap.counts.end() or popmap.counts.find(parameters.group2) == popmap.counts.end())) { // More than two groups and groups to compare were not found
log("Groups specified with --groups (\"" + parameters.group1 + "\", \"" + parameters.group2 + "\") were not found in popmap groups (" + print_groups(popmap) + ")", LOG_ERROR);
exit(1);
} else if (popmap.counts.size() == 2) { // If only two groups in popmap, use them (override user-specified groups for now)
} else if (compare and popmap.counts.size() == 2) { // If only two groups in popmap, use them (override user-specified groups for now)
auto i = std::begin(popmap.counts);
parameters.group1 = i->first;
......
......@@ -13,6 +13,6 @@ struct Popmap {
};
Popmap load_popmap(Parameters& parameters);
Popmap load_popmap(Parameters& parameters, bool compare = true);
std::string print_groups(Popmap& popmap, bool counts = false);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment