cli.cc 5.33 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/>.
 */

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "pedigree_settings.h"

#define PREDICATE CONSTRAINT_PREDICATE(ped_settings_t)
#define CALLBACK_ARGS ARGUMENT_CALLBACK_ARGS(ped_settings_t)


ped_settings_t* ensure(ped_settings_t*& t)
{
    if (t == NULL) {
        t = new ped_settings_t();
    }
    return t;
}


static
argument_section_list_t<ped_settings_t>
arguments = {
    {"Advanced (NOT INTENDED FOR USERS!)", "", true, {
        {{"--full-help", "--advanced-help"},
            {},
            "Display usage.",
            false,
            {false},
            [](CALLBACK_ARGS)
            {
                print_usage_impl(true, arguments);
                exit(0);
                SAFE_IGNORE_CALLBACK_ARGS;
            }},

        {{"-D", "--debug"},
            {},
            "Display debug messages",
            false,
            {false},
            [](CALLBACK_ARGS)
            {
                msg_handler_t::debug_enabled() = true;
                SAFE_IGNORE_CALLBACK_ARGS;
            }},

    }},
    {"Miscellaneous", "", false, {
        {{"-h", "--help"},
            {},
            "Display usage.",
            false,
            {false},
            [](CALLBACK_ARGS)
            {
                print_usage_impl(false, arguments);
                exit(0);
                SAFE_IGNORE_CALLBACK_ARGS;
            }},

74
75
76
77
78
79
80
81
82
83
84
         {{"-n", "--name"},
                 {"population name"},
                 "The name of this population (will also be used to create the output filename)",
                 false,
                 {true},
                 [](CALLBACK_ARGS) {
                     ensure(target)->pop_name = *++ai;
                     SAFE_IGNORE_CALLBACK_ARGS;
                 }},

         {{"-wd", "--work-directory"},
85
86
87
88
89
90
            {"path"},
            "Path to directory for output files",
            false,
            {&ped_settings_t::work_directory},
            [](CALLBACK_ARGS) {
                ensure(target)->work_directory = *++ai;
91
92
93
94
                if (!check_file(ensure(target)->work_directory, true, true, false)) {
                    ensure_directories_exist(ensure(target)->work_directory);
                    check_file(ensure(target)->work_directory, true, true, true);
                }
95
96
97
                SAFE_IGNORE_CALLBACK_ARGS;
            }},

98
99
100
101
102
103
104
105
106
//        {{"-ms", "--max-states"},
//            {"path"},
//            "Maximum number of states allowed in a generation",
//            false,
//            {"unlimited"},
//            [](CALLBACK_ARGS) {
//                ensure(target)->max_states = to<size_t>(*++ai);
//                SAFE_IGNORE_CALLBACK_ARGS;
//            }},
107
108

    }},
109
    {"Input", "The expected pedigree file must be a CSV file with each row in the following format:\nGENERATION_NAME;Individual number;Parent1 number;Parent2 number\nIndividual numbers are expected to increase and all GREATER than zero, and parent numbers for a given individual are expected to be LESSER than the individual number.\nBreeding lines are encoded with Parent1 = Parent2 = 0.\nSelfings are encoded with Parent1 = Parent2.\nDoubled haploids are encoded with Parent2 = 0.\nThe generation names will be used when specifying genotype and phenotype observations in the later steps.\nThe first line is expected to be a header line and will be ignored.", false, {
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
        {{"-p", "--pedigree-file"},
            {"path"},
            "Path to the genetic map file",
            false,
            {true},
            [](CALLBACK_ARGS)
            {
                ensure(target)->pedigree_filename = *++ai;
                SAFE_IGNORE_CALLBACK_ARGS;
            }},

        {{"-s", "--separator"},
            {"separator character"},
            "Column delimiter character used in the pedigree file",
            false,
            {&ped_settings_t::csv_sep},
            [](CALLBACK_ARGS)
            {
                ensure(target)->csv_sep = (*++ai)[0];
                SAFE_IGNORE_CALLBACK_ARGS;
            }},
    }},
};


argument_parser<ped_settings_t> arg_map(arguments);


ped_settings_t* ped_settings_t::from_args(int argc, const char** argv)
{
    std::vector<const char*> args(argv + 1, argv + argc);
    std::vector<const char*>::iterator ai = args.begin();
    std::vector<const char*>::iterator aj = args.end();

    ped_settings_t* ret = NULL;

146
147
    ::prg_name(basename(argv[0]));

148
149
150
151
152
153
154
155
156
157
158
159
160
161
    while (ai != aj && arg_map(ret, ai, aj)) {
        ++ai;
    }

    if (ret) {
        ret->prg_name = basename(argv[0]);
        ret->command_line.assign(argv, argv + argc);
    }

    return ret;
}

void print_usage() { print_usage_impl(false, arguments); }

162
#include "output_impl.h"