read_map.cc 2.66 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
#include "input.h"
damien's avatar
damien committed
19
#include "input/read_map.h"
20
#include "output_impl.h"
21
22
23
24

namespace read_data {


25
std::vector<chromosome> read_map(file& is) {
26
27
28
    if (!is.good()) {
        throw input_exception(is, "couldn't read from file");
    }
29
30
31
32
33
    std::vector<chromosome> ret;
    std::string s;
    double d;
    int n;
    is >> std::noskipws;
34
    while (is.good() && !is.eof()) {
35
36
37
38
39
40
41
42
        ret.emplace_back();
        ret.back().name = read_star_name(is);
        ws_nonl(is);
        n = 0;
        is >> n;
        if (n <= 0) {
            throw input_exception(is, "expected the number of markers after the marker name.");
        }
43
44
        ret.back().raw.marker_name.reserve(n);
        ret.back().raw.marker_locus.reserve(n);
45
46
47
48
49
50
51
        ws_nonl(is);
        d = 0;
        s.clear();
        is >> s;
        if (s.size() == 0) {
            throw input_exception(is, "expected a marker name");
        }
52
53
        ret.back().raw.marker_name.push_back(s);
        ret.back().raw.marker_locus.push_back(0);
54
55
56
57
58
59
60
61
62
63
64
65
66
        while (--n && !is.eof()) {
            ws_nonl(is);
            d = -1;
            is >> d;
            if (d < 0) {
                throw input_exception(is, "expected a positive distance");
            }
            ws_nonl(is);
            s.clear();
            is >> s;
            if (s.size() == 0) {
                throw input_exception(is, "expected a marker name");
            }
67
68
            ret.back().raw.marker_name.push_back(s);
            ret.back().raw.marker_locus.push_back(ret.back().raw.marker_locus.back() + d);
69
70
        }
        ws_nl(is);
71
        ret.back().compute_haplo_sizes();
72
73
74
75
76
77
78
    }
    return ret;
}


} /* namespace read_data */

79
#ifdef TEST_MAP
80
#include "file.h"
81
82
83
84

int main(int argc, char** argv)
{
    for (int i = 1; i < argc; ++i) {
85
        ifile ifs(argv[i]);
86
87
88
89
90
91
92
        std::cout << read_data::read_map(ifs) << std::endl;
    }
    return 0;
}

#endif