spellmaptools.cc 2.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#define SPELL_PEDIGREE_MAIN spell_pedigree
#define SPELL_BAYES_MAIN spell_marker

#include "eigen.h"
#include <vector>
#include <string>

#include "RWrap.h"

// Load and initialize data

// LL (order)

// Try (order, marker)

// Flips (order)

// LOD2pt (order, order)

typedef std::vector<std::string> marker_vec;


class Spell2PtMatrix;


class SpellMapTools {
private:
public:
    SpellMapTools(const std::string& wd, const std::string& name) {}
    double LL(const marker_vec& order);
    double Try(const marker_vec& order, const std::string& marker);
    double Flips(const marker_vec& order, int window_size);
    Spell2PtMatrix* LOD2pt(const marker_vec& rows, const marker_vec& cols);
};


class Spell2PtMatrix {
private:
    std::vector<std::string> rownames, colnames;
    std::map<std::string, int> row_indices, col_indices;
    SpellMapTools* instance;
    std::map<std::pair<std::string, std::string>, double> cache;
public:
    Spell2PtMatrix(SpellMapTools* smt, const std::vector<std::string>& r, const std::vector<std::string>& c)
        : instance(smt), rownames(r), colnames(c), row_indices(), col_indices(), cache()
    {
        for (const auto& m: rownames) {
            row_indices.emplace(m, row_indices.size());
        }
        for (const auto& m: colnames) {
            col_indices.emplace(m, col_indices.size());
        }
    }

    std::vector<int>
    dim() const
    {
        return {rownames.size(), colnames.size()};
    }
    
    double get(int i, int j)
    {
        std::pair<std::string, std::string> key = {rownames[i], colnames[j]};
        if (key.first == key.second) {
            return 0;
        }
        if (key.first > key.second) {
            std::swap(key.first, key.second);
        }
        auto it = cache.find(key);
        if (it == cache.end()) {
            double value = 0; /* TODO */
            cache.emplace(key, value);
            return value;
        } else {
            return it->second;
        }
    }
};


double
SpellMapTools::LL(const marker_vec& order)
{
    return 0;
}

double
SpellMapTools::Try(const marker_vec& order, const std::string& marker)
{
    return 0;
}

double
SpellMapTools::Flips(const marker_vec& order, int window_size)
{
    return 0;
}

Spell2PtMatrix*
SpellMapTools::LOD2pt(const marker_vec& row_order, const marker_vec& col_order)
{
    return NULL;
}



CLASS(Spell2PtMatrix)
    .method(Spell2PtMatrix, get).arg("i").arg("j").auto_glue()
    ;

CLASS(SpellMapTools)
    .ctor<const std::string&, const std::string&>("directory", "name")
    .method(SpellMapTools, LL).arg("order").auto_glue()
    .method(SpellMapTools, Try).arg("order").arg("marker").auto_glue()
    .method(SpellMapTools, Flips).arg("order").arg("window_size").auto_glue()
    .method(SpellMapTools, LOD2pt).arg("row_order").arg("col_order").auto_glue()
    ;


MODULE(spellmaptools)
    .add_class(SpellMapTools)
    .add_class(Spell2PtMatrix)
    .add_s3method("'['", "Spell2PtMatrix")
    .add_s3method("dim", "Spell2PtMatrix")
    .add_s3method("print", "Spell2PtMatrix")
    ;