basic_data.h 4.92 KB
Newer Older
Damien Leroux's avatar
Damien Leroux committed
1
2
3
4
5
6
7
#ifndef _SPEL_COMPUTATIONS_BASIC_DATA_H_
#define _SPEL_COMPUTATIONS_BASIC_DATA_H_

#ifndef _SPEL_COMPUTATIONS_BASE_H_
#include "base.h"
#endif

8
9
10
11
typedef const generation_rs* generation_value;
typedef const population* population_value;
typedef const chromosome* chromosome_value;
typedef const qtl_chromosome* qtl_chromosome_value;
Damien Leroux's avatar
Damien Leroux committed
12
13
14
15

typedef std::vector<double> selected_qtls_on_chromosome_type;
typedef std::map<char, VectorXb> observation_vectors_type;
typedef labelled_matrix<MatrixXd, allele_pair, double> locus_probabilities_type;
16
typedef labelled_matrix<MatrixXd, allele_pair, int> geno_prob_type;
Damien Leroux's avatar
Damien Leroux committed
17
18
19
typedef labelled_matrix<MatrixXd, std::vector<char>, allele_pair> state_to_parental_origin_matrix_type;
typedef labelled_matrix<MatrixXd, std::vector<char>, double> parental_origin_type;
typedef labelled_matrix<MatrixXd, int, std::vector<char>> parental_origin_per_locus_type;
Damien Leroux's avatar
Damien Leroux committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
typedef Eigen::Matrix<bool, 1, Eigen::Dynamic> bool_row_type;

struct compare_row {
    bool operator () (const bool_row_type& r1, const bool_row_type& r2) const
    {
        for (int i = 0; i < r1.innerSize(); ++i) {
            if (r1(i) > r2(i)) {
                return true;
            } else if (r1(i) < r2(i)) {
                return false;
            }
        }
        return false;
    }
};

typedef std::set<bool_row_type, compare_row> bool_row_set;
Damien Leroux's avatar
Damien Leroux committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

std::vector<std::pair<const chromosome*, double>>
selected_qtls();

std::vector<double>
selected_qtls_on_chromosome(qtl_chromosome_value);

generation_value
generation_by_name(const std::string&);

generation_value
qtl_generation(const population_value&);

population_value
population_by_name(const std::string&);

53
54
55
collection<population_value>
all_populations();

Damien Leroux's avatar
Damien Leroux committed
56
57
58
59
60
61
62
63
64
65
66
67
chromosome_value
chromosome_by_name(const std::string&);

qtl_chromosome_value
qtl_chromosome_by_name(const std::string&);

collection<std::string>
all_observed_generation_names(population_value);

std::vector<char>
marker_observations(population_value, chromosome_value, generation_value, int);

68
69
/*collection<double>*/
value<std::vector<double>>
Damien Leroux's avatar
Damien Leroux committed
70
71
72
73
74
75
76
77
test_loci(chromosome_value);

generation_rs::segment_computer_t
genoprob_computer(population_value, generation_value, qtl_chromosome_value);

marker_observation_spec
marker_observation_specifications(generation_value);

78
79
80
labelled_matrix<MatrixXd, std::vector<char>, allele_pair>
compute_state_to_parental_origin(const context_key& ck, const locus_key& lk);

Damien Leroux's avatar
Damien Leroux committed
81
82
83
84

MatrixXb
get_contrast_groups(generation_value gen, const locus_key& lk);

85
86
/*observation_vectors_type*/
/*observation_vectors(const generation_rs*);*/
Damien Leroux's avatar
Damien Leroux committed
87

88
89
/*pedigree_type*/
/*pedigree(population_value, generation_value, int);*/
Damien Leroux's avatar
Damien Leroux committed
90
91
92
93

range<int>
individual_range(population_value);

94
95
/*observation_vectors_type*/
/*get_observation_vectors(generation_value gen);*/
96
97
98
99
100

struct pop_mgo_data {
    generation_value qtl_gen;
    collection<std::string> aogn;
    collection<generation_value> aog;
101
    /*collection<observation_vectors_type> aov;*/
102
103
104
105
    pop_mgo_data(population_value pop)
        : qtl_gen(generation_by_name(pop->qtl_generation_name))
        , aogn(all_observed_generation_names(pop))
        , aog(make_collection<Sync>(generation_by_name, aogn))
106
        /*, aov(make_collection<Sync>(get_observation_vectors, aog))*/
107
108
109
110
111
    {
        /*MSG_DEBUG("new pop_mgo_data");*/
    }
};

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

struct stpom_data {
    std::vector<std::vector<char>> row_labels;
    std::vector<allele_pair> col_labels;
    MatrixXb haplo1;
    MatrixXb haplo2;

    friend
        std::ostream&
        operator << (std::ostream& os, const stpom_data& sd)
        {
            os << "Row labels: " << sd.row_labels << std::endl;
            os << "Col labels: " << sd.col_labels << std::endl;
            os << "Haplo1: " << std::endl << sd.haplo1 << std::endl;
            os << "Haplo2: " << std::endl << sd.haplo2 << std::endl;
            return os;
        }
};

Damien Leroux's avatar
Damien Leroux committed
131
132
133
value<stpom_data>
get_stpom_data(const context_key& ck, const locus_key& lk);

134
135
136
137
138
139
140
141
142
143
144
template <typename CACHE_DIRECTION>
CACHE_DIRECTION& operator & (CACHE_DIRECTION& cd, stpom_data& sd)
{
    return cd & sd.row_labels & sd.col_labels & sd.haplo1 & sd.haplo2;
}

static inline md5_digest& operator << (md5_digest& md5, const stpom_data& sd)
{
    return md5 << sd.haplo1 << sd.haplo2;
}

145
146
147
148
149
static inline md5_digest& operator << (md5_digest& md5, const pop_mgo_data&)
{
    return md5;
}

150
151
152
/*multi_generation_observations*/
/*population_marker_obs(population_value, chromosome_value, int, const pop_mgo_data*);*/

Damien Leroux's avatar
Damien Leroux committed
153
multi_generation_observations
154
population_marker_obs(const context_key&, int);
Damien Leroux's avatar
Damien Leroux committed
155

156
157
collection<std::string>
all_traits();
Damien Leroux's avatar
Damien Leroux committed
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

static inline
cache_input& operator & (cache_input& ci, const population*& pop)
{
    std::string name;
    ci & name;
    pop = population_by_name(name);
    return ci;
}


static inline
cache_output& operator & (cache_output& co, const population*& pop)
{
    return co & pop->name;
}


template <typename CACHE_DIRECTION>
CACHE_DIRECTION& operator & (CACHE_DIRECTION& c, multi_generation_observations& mgo)
{
    return c & mgo.n_mark & mgo.LV & mgo.pop;
}

Damien Leroux's avatar
Damien Leroux committed
183
184
#endif