Commit daa92cfa authored by Damien Leroux's avatar Damien Leroux
Browse files

Closes #7.

parent 68898dde
...@@ -291,7 +291,7 @@ struct msg_handler_t { ...@@ -291,7 +291,7 @@ struct msg_handler_t {
/*std::cout << "Message handler instance created." << std::endl;*/ /*std::cout << "Message handler instance created." << std::endl;*/
} }
~state_t() { close_log_file(); } ~state_t() { close_log_file(); }
void check(bool fatal); bool check(bool fatal);
void reset(); void reset();
void run_hooks() { for (auto& f: hooks) { f(); } } void run_hooks() { for (auto& f: hooks) { f(); } }
void close_log_file() void close_log_file()
...@@ -321,7 +321,7 @@ struct msg_handler_t { ...@@ -321,7 +321,7 @@ struct msg_handler_t {
static const char* i() { return instance().info(); } static const char* i() { return instance().info(); }
static const char* n() { return instance().normal(); } static const char* n() { return instance().normal(); }
static void check(bool fatal) { instance().check(fatal); } static bool check(bool fatal) { return instance().check(fatal); }
static void reset() { instance().reset(); } static void reset() { instance().reset(); }
static void hook(std::function<void()>&& f) { instance().hooks.push_back(f); } static void hook(std::function<void()>&& f) { instance().hooks.push_back(f); }
...@@ -703,7 +703,7 @@ struct scoped_indent { ...@@ -703,7 +703,7 @@ struct scoped_indent {
}; };
inline void msg_handler_t::state_t::check(bool fatal) inline bool msg_handler_t::state_t::check(bool fatal)
{ {
msg_handler_t::scoped_lock_type _(msg_handler_t::mutex); msg_handler_t::scoped_lock_type _(msg_handler_t::mutex);
if (count > 0) { if (count > 0) {
...@@ -718,8 +718,10 @@ inline void msg_handler_t::state_t::check(bool fatal) ...@@ -718,8 +718,10 @@ inline void msg_handler_t::state_t::check(bool fatal)
exit(-count); exit(-count);
} else { } else {
reset(); reset();
return true;
} }
} }
return false;
} }
inline void msg_handler_t::state_t::reset() inline void msg_handler_t::state_t::reset()
......
...@@ -1473,6 +1473,18 @@ read_pedigree(const std::string& filename, char sep=';', size_t max_states=std:: ...@@ -1473,6 +1473,18 @@ read_pedigree(const std::string& filename, char sep=';', size_t max_states=std::
for (const auto& i: ret.items) { for (const auto& i: ret.items) {
msg_handler_t::cout() << "\rProcessing entry " << (++cur) << "/" << ret.items.size() << " [" << i.id << ':' << i.p1 << ':' << i.p2 << "]...\x1b[K"; msg_handler_t::cout() << "\rProcessing entry " << (++cur) << "/" << ret.items.size() << " [" << i.id << ':' << i.p1 << ':' << i.p2 << "]...\x1b[K";
MSG_QUEUE_FLUSH(); MSG_QUEUE_FLUSH();
bool fail = false;
if (i.p1 != 0 && ret.m_id.find(i.p1) == ret.m_id.end()) {
MSG_ERROR("Unknown ID #" << i.p1 << " in pedigree", SPELL_STRING("Add individual #" << i.p1 << " to the pedigree file"));
fail = true;
}
if (i.p2 != 0 && ret.m_id.find(i.p2) == ret.m_id.end()) {
MSG_ERROR("Unknown ID #" << i.p2 << " in pedigree", SPELL_STRING("Add individual #" << i.p2 << " to the pedigree file"));
fail = true;
}
if (fail) {
return {};
}
if (i.is_ancestor()) { if (i.is_ancestor()) {
ret.m_id[i.id] = ret.ancestor(i.gen_name); ret.m_id[i.id] = ret.ancestor(i.gen_name);
} else if (i.is_dh()) { } else if (i.is_dh()) {
......
...@@ -35,6 +35,9 @@ int SPELL_PEDIGREE_MAIN(int argc, const char** argv) ...@@ -35,6 +35,9 @@ int SPELL_PEDIGREE_MAIN(int argc, const char** argv)
print_usage(); print_usage();
} else { } else {
pedigree_type ped = read_pedigree(settings->pedigree_filename, settings->csv_sep, settings->max_states); pedigree_type ped = read_pedigree(settings->pedigree_filename, settings->csv_sep, settings->max_states);
if (!msg_handler_t::check(false)) {
return -1;
}
std::string ped_output; std::string ped_output;
if (settings->work_directory == "") { if (settings->work_directory == "") {
settings->work_directory = "."; settings->work_directory = ".";
......
...@@ -61,8 +61,8 @@ public: ...@@ -61,8 +61,8 @@ public:
EM(const marker_vec& order) EM(const marker_vec& order)
{ return gamete_LV.EM(order, m_convergence_threshold, m_max_iterations); } { return gamete_LV.EM(order, m_convergence_threshold, m_max_iterations); }
void init_2pt_tr_at_inf() { gamete_LV.init_2pt_tr_at_inf(); } // void init_2pt_tr_at_inf() { gamete_LV.init_2pt_tr_at_inf(); }
double twoMarkerLikelihood(int i, double r) { return gamete_LV.twoMarkerLikelihood(i, r); } double twoMarkerLikelihood() { return gamete_LV.twoMarkerLikelihoodAtInf(); }
int max_iterations(int n) int max_iterations(int n)
{ {
...@@ -129,7 +129,7 @@ public: ...@@ -129,7 +129,7 @@ public:
double best = em.likelihood; double best = em.likelihood;
// instance->init_2pt_tr_at_inf(); // instance->init_2pt_tr_at_inf();
// double inf_ref = instance->map_likelihood(minimap, at_worlds_end); // double inf_ref = instance->map_likelihood(minimap, at_worlds_end);
double inf_ref = instance->twoMarkerLikelihood(0, .5); double inf_ref = instance->twoMarkerLikelihood();
double value = best - inf_ref; double value = best - inf_ref;
// MSG_INFO("LOD(" << minimap[0] << " … " << minimap[1] << " => d=" << em.distances[0] << " best=" << best << " inf_ref=" << inf_ref << " value=" << value); // MSG_INFO("LOD(" << minimap[0] << " … " << minimap[1] << " => d=" << em.distances[0] << " best=" << best << " inf_ref=" << inf_ref << " value=" << value);
cache.emplace(key, value); cache.emplace(key, value);
...@@ -231,7 +231,11 @@ SpellMapTools::SpellMapTools(std::string ped_filename, Rwrap::DataFrame observat ...@@ -231,7 +231,11 @@ SpellMapTools::SpellMapTools(std::string ped_filename, Rwrap::DataFrame observat
// MSG_DEBUG(__FILE__ << ':' << __LINE__); // MSG_DEBUG(__FILE__ << ':' << __LINE__);
data_time = std::time(nullptr); data_time = std::time(nullptr);
std::vector<std::string> args = {"spell-pedigree", "-wd", wd, "-n", name, "-p", ped_filename}; std::vector<std::string> args = {"spell-pedigree", "-wd", wd, "-n", name, "-p", ped_filename};
invoke_spell(SPELL_PEDIGREE_MAIN, args); int ret = invoke_spell(SPELL_PEDIGREE_MAIN, args);
if (ret) {
MSG_ERROR("Something went wrong while loading the pedigree…", "");
return;
}
} else { } else {
// MSG_DEBUG(__FILE__ << ':' << __LINE__); // MSG_DEBUG(__FILE__ << ':' << __LINE__);
data_time = spell_ped_t; data_time = spell_ped_t;
...@@ -243,7 +247,7 @@ SpellMapTools::SpellMapTools(std::string ped_filename, Rwrap::DataFrame observat ...@@ -243,7 +247,7 @@ SpellMapTools::SpellMapTools(std::string ped_filename, Rwrap::DataFrame observat
// MSG_INFO("spell_mark_t=" << spell_mark_t); // MSG_INFO("spell_mark_t=" << spell_mark_t);
/* Run spell-marker if needed */ /* Run spell-marker if needed */
if (spell_mark_t < data_time) { if (spell_mark_t < data_time && obs_gen.size() > 0) {
// MSG_DEBUG(__FILE__ << ':' << __LINE__); // MSG_DEBUG(__FILE__ << ':' << __LINE__);
std::stringstream out; std::stringstream out;
std::vector<std::string> args = {"spell-marker", "-wd", wd, "-n", name, "-Og", "-Op"}; std::vector<std::string> args = {"spell-marker", "-wd", wd, "-n", name, "-Og", "-Op"};
......
Markdown is supported
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