Commit 4685f2c6 authored by damien's avatar damien
Browse files

Added output options for spell-marker. Untested.

parent 8fecadf0
This diff is collapsed.
......@@ -75,6 +75,12 @@ struct bn_settings_t {
std::vector<std::string> input_generations;
std::vector<std::string> output_generations;
static const int OutputPopData = 1;
static const int OutputOnePoint = 2;
int output_mode;
std::vector<std::string> closing_messages;
bn_settings_t()
: scheme(JDS_None)
, command_line()
......@@ -104,6 +110,8 @@ struct bn_settings_t {
, job_filenames_mutex()
, input_generations()
, output_generations()
, output_mode(0)
, closing_messages()
{}
size_t count_markers() const
......
......@@ -493,6 +493,28 @@ arguments = {
SAFE_IGNORE_CALLBACK_ARGS;
}},
}},
{"Outputs", "Set the output mode. By default, only the population data file will be written. If you specify -O1, only the 1-point Parental Origin Probabilities will be written, unless you also specify -Op.", false, {
{{"-Op", "--output-population-data"},
{},
"Output the population data file for use in spell-qtl. This is the default behaviour.",
false,
{},
[](CALLBACK_ARGS)
{
ensure(target)->output_mode |= bn_settings_t::OutputPopData;
SAFE_IGNORE_CALLBACK_ARGS;
}},
{{"-O1", "--output-one-point-prob"},
{},
"Output the 1-point Parental Origin Probabilities. This will disable the output of the population data file unless -Op is also used.",
false,
{},
[](CALLBACK_ARGS)
{
ensure(target)->output_mode |= bn_settings_t::OutputOnePoint;
SAFE_IGNORE_CALLBACK_ARGS;
}},
}},
};
......@@ -518,6 +540,9 @@ bn_settings_t* bn_settings_t::from_args(int argc, const char** argv)
for (const auto& kv: ret->observed_mark) {
ret->marker_observation_specs[kv.second.format_name] = marker_obs_formats::get_format(ret->pedigree, kv.second.format_name);
}
if (ret->output_mode == 0) {
ret->output_mode = bn_settings_t::OutputPopData;
}
}
return ret;
......
......@@ -326,9 +326,9 @@ job_registry = {
}
}
{
/* export pedigree+probas pour Sylvain */
std::ofstream ofs(MESSAGE(settings->work_directory << '/' << settings->pop_name << "_pedigree-and-probabilities." << mark << ".csv"));
if (settings->output_mode & bn_settings_t::OutputOnePoint){
std::string op_filename = MESSAGE(settings->work_directory << '/' << settings->pop_name << "_pedigree-and-probabilities." << mark << ".csv");
std::ofstream ofs(op_filename);
ofs << "Gen;Id;P1;P2;Prob" << std::endl;
for (const auto& pi: settings->pedigree.items) {
ofs << pi.gen_name << ';' << pi.id << ';' << pi.p1 << ';' << pi.p2 << ";{";
......@@ -339,42 +339,45 @@ job_registry = {
}
ofs << '}' << std::endl;
}
settings->closing_messages.push_back(MESSAGE(std::endl << std::endl << GREEN << "1-point Parental Origin Probabilities for marker `" << mark << "' written in file " << WHITE << op_filename << NORMAL << std::endl));
}
MSG_DEBUG("PROJECTED MARGINALS");
for (const auto& km: marginals) {
std::stringstream ss;
ss << " * " << km.first;
for (const auto& kv: km.second) {
ss << ' ' << kv.first << '=' << kv.second;
if (settings->output_mode & bn_settings_t::OutputPopData) {
MSG_DEBUG("PROJECTED MARGINALS");
for (const auto &km: marginals) {
std::stringstream ss;
ss << " * " << km.first;
for (const auto &kv: km.second) {
ss << ' ' << kv.first << '=' << kv.second;
}
MSG_DEBUG(ss.str());
}
MSG_DEBUG(ss.str());
}
// MSG_QUEUE_FLUSH();
std::map<size_t, std::vector<double>> state_prob, output_prob;
for (size_t ind = 1; ind < settings->pedigree.tree.m_ind_number_to_node_number.size(); ++ind) {
size_t node = settings->pedigree.tree.m_ind_number_to_node_number[ind];
auto gen = settings->pedigree.get_gen(ind);
const auto& labels = gen->labels;
const auto& LC = settings->pedigree.LC[node];
int variable = settings->pedigree.ind2id(ind);
dispatch_geno_probs(LC, labels, marginals[variable], node, state_prob);
if (std::find(settings->output_generations.begin(), settings->output_generations.end(), gen->name) != settings->output_generations.end()) {
output_prob[node] = state_prob[node];
// MSG_QUEUE_FLUSH();
std::map<size_t, std::vector<double>> state_prob, output_prob;
for (size_t ind = 1; ind < settings->pedigree.tree.m_ind_number_to_node_number.size(); ++ind) {
size_t node = settings->pedigree.tree.m_ind_number_to_node_number[ind];
auto gen = settings->pedigree.get_gen(ind);
const auto &labels = gen->labels;
const auto &LC = settings->pedigree.LC[node];
int variable = settings->pedigree.ind2id(ind);
dispatch_geno_probs(LC, labels, marginals[variable], node, state_prob);
if (std::find(settings->output_generations.begin(), settings->output_generations.end(),
gen->name) != settings->output_generations.end()) {
output_prob[node] = state_prob[node];
}
}
}
MSG_DEBUG("LOCUS VECTORS");
MSG_DEBUG("LOCUS VECTORS");
for (const auto& kv: state_prob) {
MSG_DEBUG(" * " << kv.first << ' ' << kv.second);
}
ofile ofs(settings->job_filename("compute-LV", mark));
rw_base() (ofs, output_prob);
for (const auto &kv: state_prob) {
MSG_DEBUG(" * " << kv.first << ' ' << kv.second);
}
ofile ofs(settings->job_filename("compute-LV", mark));
rw_base()(ofs, output_prob);
}
return true;
/*for (const auto& pop_obs: settings->observed_mark) {*/
/*MSG_DEBUG("Obs in generation " << pop_obs.first);*/
......
......@@ -107,18 +107,22 @@ int main(int argc, const char** argv)
if (do_the_job(settings, "compute-factor-graphs")
&& do_the_job(settings, "compute-LV")
&& do_the_job(settings, "collect-LV")) {
&& (!(settings->output_mode & bn_settings_t::OutputPopData)
|| do_the_job(settings, "collect-LV"))) {
ifile output(settings->job_filename("output", 0));
std::string filename;
rw_base() (output, filename);
CREATE_MESSAGE(msg_channel::Out, MESSAGE(std::endl << std::endl << GREEN << "Marker data for population `" << settings->pop_name << "' written in file " << WHITE << filename << NORMAL << std::endl));
MSG_QUEUE_FLUSH();
settings->closing_messages.push_back(MESSAGE(std::endl << std::endl << GREEN << "Marker data for population `" << settings->pop_name << "' written in file " << WHITE << filename << NORMAL << std::endl));
}
}
/*do_the_job(settings, "dummy-one");*/
/*do_the_job(settings, "dummy");*/
/*do_the_job(settings, "dummy-one");*/
settings->cleanup_job_files();
for (auto& msg: settings->closing_messages) {
CREATE_MESSAGE(msg_channel::Out, std::move(msg));
}
MSG_QUEUE_FLUSH();
} else {
(void) do_the_job(settings, settings->job_name);
}
......
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