main.cc 2.51 KB
Newer Older
Damien Leroux's avatar
Damien Leroux committed
1
2
3
#include "pedigree.h"
#include "bayes.h"
#include "cli.h"
4
#include "dispatch.h"
Damien Leroux's avatar
Damien Leroux committed
5
6
7
8
9
10
11
12
13
14

void print_usage();


int main(int argc, const char** argv)
{
    bn_settings_t* settings = bn_settings_t::from_args(argc, argv);
    if (!settings) {
        print_usage();
    } else {
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        auto pedigree = read_csv(settings->pedigree_filename);

        std::map<std::string, ObservationDomain> obs_gen;
        for (const auto& kv: settings->observed_mark) {
            obs_gen[kv.first] = settings->marker_observation_specs[kv.second.format_name].domain;
            MSG_DEBUG("OBSERVED GEN " << kv.first << ": " << obs_gen[kv.first]);
        }

        size_t n_alleles = 1;
        for (const auto& kv: settings->marker_observation_specs) {
            if (kv.second.domain == ODAllele) {
                if (n_alleles == 1) {
                    n_alleles = kv.second.domain_size;
                } else {
                    MSG_ERROR("Multiple and inconsistent formats (domain: allele)", "Consolidate your data and use at most ONE format per domain (alleles/ancestors) for your marker observations");
                }
            }
            settings->compiled_obs_specs[kv.first] = kv.second.compile();
        }
        for (const auto& kvfmt: settings->compiled_obs_specs) {
            MSG_DEBUG("COMPILED FORMAT " << kvfmt.first);
            for (const auto& kvscore: kvfmt.second) {
                MSG_DEBUG("  score '" << kvscore.first << "': " << kvscore.second.transpose());
            }
        }

        pedigree_bayesian_network bn = make_bn(pedigree, obs_gen, n_alleles, settings->noise, settings->tolerance);
        settings->bn = &bn;

        std::set<std::string> tmp;
        for (const auto& obs: settings->observed_mark) {
            for (const auto& kv: obs.second.observations.data) {
                tmp.insert(kv.first);
            }
        }
        settings->marker_names.assign(tmp.begin(), tmp.end());
Damien Leroux's avatar
Damien Leroux committed
51
        /*MSG_DEBUG("MARKER NAMES " << settings->marker_names);*/
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

        for (size_t mn = 0; mn < settings->marker_names.size(); ++mn) {
            settings->marker_index[settings->marker_names[mn]] = mn;
        }

        if (settings->is_master()) {
            do_the_job(settings, "compute-LV");
            do_the_job(settings, "reassemble-LV");
            /*do_the_job(settings, "dummy-one");*/
            /*do_the_job(settings, "dummy");*/
            /*do_the_job(settings, "dummy-one");*/
        } else {
            do_the_job(settings, settings->job_name);
        }

Damien Leroux's avatar
Damien Leroux committed
67
68
69
70
71
72
        delete settings;
    }
    return 0;
}