cli.h 5.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* Spell-QTL  Software suite for the QTL analysis of modern datasets.
 * Copyright (C) 2016,2017  Damien Leroux <damien.leroux@inra.fr>, Sylvain Jasson <sylvain.jasson@inra.fr>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

Damien Leroux's avatar
Damien Leroux committed
18
19
20
21
22
23
#ifndef _SPELL_BAYES_CLI_H_
#define _SPELL_BAYES_CLI_H_

#include "error.h"
#include <map>
#include <vector>
24
/*#include "generation_rs.h"*/
Damien Leroux's avatar
Damien Leroux committed
25
#include "commandline.h"
26
/*#include "bn.h"*/
27
/*#include "factor_var4.h"*/
28
#include "file.h"
Damien Leroux's avatar
Damien Leroux committed
29
30
31
32


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

33
void read_format(std::map<std::string, marker_observation_spec>& settings, const std::string& filename, file& is);
Damien Leroux's avatar
Damien Leroux committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#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 */
50
51
52
    std::string pop_name;
    std::string qtl_generation_name;
    std::string work_directory;
Damien Leroux's avatar
Damien Leroux committed
53
54
55
56
    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;
57
    double tolerance;
Damien Leroux's avatar
Damien Leroux committed
58
    /* Inputs */
59
    pedigree_type pedigree;
Damien Leroux's avatar
Damien Leroux committed
60
61
    std::string pedigree_filename;
    std::string design_filename;
62
    /* BN */
63
    /*pedigree_bayesian_network* bn;*/
64
    /* Management */
65
66
67
    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;*/
68
69
    std::vector<std::string> marker_names;
    std::map<std::string, size_t> marker_index;
Damien Leroux's avatar
Damien Leroux committed
70

71
72
    /* cleanup */
    std::set<std::string> job_filenames;
73
    std::mutex job_filenames_mutex;
74

75
76
77
    std::vector<std::string> input_generations;
    std::vector<std::string> output_generations;

78
79
80
81
82
83
    static const int OutputPopData = 1;
    static const int OutputOnePoint = 2;

    int output_mode;
    std::vector<std::string> closing_messages;

Damien Leroux's avatar
Damien Leroux committed
84
85
86
87
88
89
90
91
92
93
    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()
94
95
96
        , pop_name()
        , qtl_generation_name()
        , work_directory(".")
Damien Leroux's avatar
Damien Leroux committed
97
98
99
100
        , marker_observation_specs()
        , marker_observation_specs_filenames()
        , observed_mark()
        , noise(0.)
101
        , tolerance(1.e-10)
102
        , pedigree()
Damien Leroux's avatar
Damien Leroux committed
103
104
        , pedigree_filename()
        , design_filename()
105
106
        /*, bn(NULL)*/
        , alleles_per_marker()
107
108
        , marker_names()
        , marker_index()
109
        , job_filenames()
110
        , job_filenames_mutex()
111
112
        , input_generations()
        , output_generations()
113
114
        , output_mode(0)
        , closing_messages()
Damien Leroux's avatar
Damien Leroux committed
115
116
117
118
119
120
121
122
123
124
125
126
    {}

    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);
127
128

    std::string
129
        job_filename(const char* job_name, size_t job)
130
        {
131
132
133
134
            /*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.");*/
            /*}*/
135
            std::string ret = MESSAGE(work_directory << '/' << job_name << '.' << job << ".data");
136
137
            std::lock_guard<std::mutex> lock(/*unconst_this->*/job_filenames_mutex);
            /*unconst_this->*/job_filenames.insert(ret);
138
139
140
141
142
143
144
            return ret;
        }

    void
        cleanup_job_files() const
        {
            for (const auto& path: job_filenames) {
145
                unlink(path.c_str());
146
147
148
149
            }
        }

    void
150
        load_full_pedigree_data()
151
152
153
154
155
156
157
        {
            /* 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.
             */
158
159
            /*const_cast<pedigree_type&>(pedigree).load(pedigree_filename, false);*/
            pedigree.load(pedigree_filename, false);
Damien Leroux's avatar
Damien Leroux committed
160
161
162
163
164
165
166
            for (const auto& pg: pedigree.generations) {
                if (pg) {
                    MSG_DEBUG("Generation " << pg->name << " has " << pg->labels);
                } else {
                    MSG_DEBUG("NULL pg");
                }
            }
167
        }
Damien Leroux's avatar
Damien Leroux committed
168
169
170
171
};

#endif