cli.h 4 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
/*#include "bn.h"*/
10
#include "factor_var4.h"
11
#include "file.h"
Damien Leroux's avatar
Damien Leroux committed
12
13
14
15


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

16
void read_format(std::map<std::string, marker_observation_spec>& settings, const std::string& filename, file& is);
Damien Leroux's avatar
Damien Leroux committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#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 */
33
34
35
    std::string pop_name;
    std::string qtl_generation_name;
    std::string work_directory;
Damien Leroux's avatar
Damien Leroux committed
36
37
38
39
    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;
40
    double tolerance;
Damien Leroux's avatar
Damien Leroux committed
41
    /* Inputs */
42
    pedigree_type pedigree;
Damien Leroux's avatar
Damien Leroux committed
43
44
    std::string pedigree_filename;
    std::string design_filename;
45
    /* BN */
46
    /*pedigree_bayesian_network* bn;*/
47
    /* Management */
48
49
50
    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;*/
51
52
    std::vector<std::string> marker_names;
    std::map<std::string, size_t> marker_index;
Damien Leroux's avatar
Damien Leroux committed
53

54
55
    /* cleanup */
    std::set<std::string> job_filenames;
56
    std::mutex job_filenames_mutex;
57

Damien Leroux's avatar
Damien Leroux committed
58
59
60
61
62
63
64
65
66
67
    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()
68
69
70
        , pop_name()
        , qtl_generation_name()
        , work_directory(".")
Damien Leroux's avatar
Damien Leroux committed
71
72
73
74
        , marker_observation_specs()
        , marker_observation_specs_filenames()
        , observed_mark()
        , noise(0.)
75
        , tolerance(1.e-10)
76
        , pedigree()
Damien Leroux's avatar
Damien Leroux committed
77
78
        , pedigree_filename()
        , design_filename()
79
80
        /*, bn(NULL)*/
        , alleles_per_marker()
81
82
        , marker_names()
        , marker_index()
83
        , job_filenames()
84
        , job_filenames_mutex()
Damien Leroux's avatar
Damien Leroux committed
85
86
87
88
89
90
91
92
93
94
95
96
    {}

    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);
97
98

    std::string
99
        job_filename(const char* job_name, size_t job)
100
        {
101
102
103
104
            /*bn_settings_t* unconst_this = const_cast<bn_settings_t*>(this);*/
            /*if (!unconst_this) {*/
                /*MSG_ERROR("Couldn't unconst the pointer to settings.", "Sacrifice a goat and hope for the best.");*/
            /*}*/
105
            std::string ret = MESSAGE(work_directory << '/' << job_name << '.' << job << ".data");
106
107
            std::lock_guard<std::mutex> lock(/*unconst_this->*/job_filenames_mutex);
            /*unconst_this->*/job_filenames.insert(ret);
108
109
110
111
112
113
114
            return ret;
        }

    void
        cleanup_job_files() const
        {
            for (const auto& path: job_filenames) {
115
                unlink(path.c_str());
116
117
118
119
            }
        }

    void
120
        load_full_pedigree_data()
121
122
123
124
125
126
127
        {
            /* 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.
             */
128
129
            /*const_cast<pedigree_type&>(pedigree).load(pedigree_filename, false);*/
            pedigree.load(pedigree_filename, false);
130
        }
Damien Leroux's avatar
Damien Leroux committed
131
132
133
134
};

#endif