cli.h 3.57 KB
Newer Older
Damien Leroux's avatar
Damien Leroux committed
1
2
3
4
5
6
#ifndef _SPELL_BAYES_CLI_H_
#define _SPELL_BAYES_CLI_H_

#include "error.h"
#include <map>
#include <vector>
7
/*#include "generation_rs.h"*/
Damien Leroux's avatar
Damien Leroux committed
8
#include "commandline.h"
9
10
/*#include "bn.h"*/
#include "factor_var3.h"
Damien Leroux's avatar
Damien Leroux committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


enum JobDispatchScheme { JDS_None, JDS_MT, JDS_SGE, JDS_SSH };

void read_format(std::map<std::string, marker_observation_spec>& settings, const std::string& filename, std::istream& is);

#define SPELL_CASTER ((size_t) -1)

struct bn_settings_t {
    /* Job control */
    JobDispatchScheme scheme;
    std::vector<std::string> command_line;
    std::vector<std::string> ssh_hosts;
    std::string qsub_opts;
    std::string prg_name;
    size_t n_threads;
    size_t job_start;
    size_t job_end;
    std::string job_name;
    std::string fifo_path;
    /* Configuration */
32
33
34
    std::string pop_name;
    std::string qtl_generation_name;
    std::string work_directory;
Damien Leroux's avatar
Damien Leroux committed
35
36
37
38
    std::map<std::string, marker_observation_spec> marker_observation_specs;
    std::vector<std::string> marker_observation_specs_filenames;
    std::map<std::string, population_marker_observation> observed_mark;
    double noise;
39
    double tolerance;
Damien Leroux's avatar
Damien Leroux committed
40
    /* Inputs */
41
    pedigree_type pedigree;
Damien Leroux's avatar
Damien Leroux committed
42
43
    std::string pedigree_filename;
    std::string design_filename;
44
    /* BN */
45
    /*pedigree_bayesian_network* bn;*/
46
    /* Management */
47
48
49
    std::vector<std::map<char, int>> alleles_per_marker;
    std::vector<size_t> unique_n_alleles;
    /*std::map<std::string, std::map<char, VectorXd>> compiled_obs_specs;*/
50
51
    std::vector<std::string> marker_names;
    std::map<std::string, size_t> marker_index;
Damien Leroux's avatar
Damien Leroux committed
52

53
54
55
    /* cleanup */
    std::set<std::string> job_filenames;

Damien Leroux's avatar
Damien Leroux committed
56
57
58
59
60
61
62
63
64
65
    bn_settings_t()
        : scheme(JDS_None)
        , command_line()
        , ssh_hosts()
        , qsub_opts()
        , n_threads(0)
        , job_start(SPELL_CASTER)
        , job_end(SPELL_CASTER)
        , job_name()
        , fifo_path()
66
67
68
        , pop_name()
        , qtl_generation_name()
        , work_directory(".")
Damien Leroux's avatar
Damien Leroux committed
69
70
71
72
        , marker_observation_specs()
        , marker_observation_specs_filenames()
        , observed_mark()
        , noise(0.)
73
        , tolerance(1.e-10)
74
        , pedigree()
Damien Leroux's avatar
Damien Leroux committed
75
76
        , pedigree_filename()
        , design_filename()
77
78
        /*, bn(NULL)*/
        , alleles_per_marker()
79
80
        , marker_names()
        , marker_index()
81
        , job_filenames()
82

Damien Leroux's avatar
Damien Leroux committed
83
84
85
86
87
88
89
90
91
92
93
94
    {}

    size_t count_markers() const
    {
        return observed_mark.begin()->second.observations.data.size();
    }

    void post_init();

    bool is_master() const { return job_start == SPELL_CASTER; }

    static bn_settings_t* from_args(int argc, const char** argv);
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

    std::string
        job_filename(const char* job_name, size_t job) const
        {
            std::string ret = MESSAGE(work_directory << '/' << job_name << '.' << job << ".data");
            const_cast<bn_settings_t*>(this)->job_filenames.insert(ret);
            return ret;
        }

    void
        cleanup_job_files() const
        {
            for (const auto& path: job_filenames) {
                unlink(path.c_str());
            }
        }

    void
        load_full_pedigree_data() const
        {
            /* NOT const. But called in a const context (job "collect-LV").
             * It is just not possible in EVERY case to handle this before the job is scheduled,
             * depending on which job dispatch method is used. Maybe there should be some
             * refactoring later with some settings->prepare_job(job_name) just before the job
             * is started.
             */
            const_cast<pedigree_type&>(pedigree).load(pedigree_filename, false);
        }
Damien Leroux's avatar
Damien Leroux committed
123
124
125
126
};

#endif