forked from sbenz/Paradigm
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pathwaytab.h
189 lines (160 loc) · 5.63 KB
/
pathwaytab.h
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
183
184
185
186
187
188
189
/********************************************************************************/
/* Copyright 2009-2011 -- The Regents of the University of California */
/* This code is provided for research purposes to scientists at non-profit */
/* organizations. All other use is strictly prohibited. For further */
/* details please contact University of California, Santa Cruz or */
/* Five3 Genomics, LLC (http://five3genomics.com). */
/********************************************************************************/
#ifndef HEADER_PATHWAYTAB_H
#define HEADER_PATHWAYTAB_H
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <dai/util.h>
#include <dai/var.h>
#include <dai/factor.h>
#include <dai/emalg.h>
#include "configuration.h"
using namespace std;
using namespace dai;
class FactorGenerator {
public:
virtual void generateValues(const vector< string >& edge_types,
vector< Real >& outVals) const = 0;
virtual ~FactorGenerator() {}
};
class RepressorDominatesVoteFactorGenerator : public FactorGenerator{
private:
Real _epsilon;
public:
RepressorDominatesVoteFactorGenerator(double epsilon=0.001) :
_epsilon(epsilon) {}
~RepressorDominatesVoteFactorGenerator() {}
void generateValues(const vector< string >& edge_types,
vector< Real >& outVals) const;
};
class SingleMemberNeededFactorGenerator : public FactorGenerator{
private:
Real _epsilon;
public:
SingleMemberNeededFactorGenerator(double epsilon=0.001) :
_epsilon(epsilon) {}
~SingleMemberNeededFactorGenerator() {}
void generateValues(const vector< string >& edge_types,
vector< Real >& outVals) const;
};
class AllMembersNeededFactorGenerator : public FactorGenerator{
private:
Real _epsilon;
public:
AllMembersNeededFactorGenerator(double epsilon=0.001) :
_epsilon(epsilon) {}
~AllMembersNeededFactorGenerator() {}
void generateValues(const vector< string >& edge_types,
vector< Real >& outVals) const;
};
class PathwayTab;
void readInteractionMap(istream& is, map< string, vector< string > >& out_imap);
class GeneProteinExpressionModel {
private:
set< string > _states;
set< string > _steps;
public:
GeneProteinExpressionModel(istream& is);
void addGeneDogma(const string& genename, PathwayTab& pathway_graph);
};
class PathwayTab {
public:
typedef pair< string, string > Node;
static const size_t VARIABLE_DIMENSION; // = 3
static const std::string DEFAULT_INTERACTION_MAP;
static const std::string CENTRAL_DOGMA;
private:
static const string OBSERVATION_INTERACTION;
map< Node, size_t > _nodemap;
vector< Node > _nodevector;
map< Node, map< Node, string > > _parents;
map< string, string > _entities;
GeneProteinExpressionModel _dogma;
map< string, vector< string > > _imap;
PropertySet _props;
map< pair<string, string>, FactorGenerator* > _factorGenLookup;
FactorGenerator* _defaultFactorGen;
PathwayTab(istream& pathway_stream,
istream& imap_stream,
istream& dogma_stream,
const PropertySet& props);
public:
static PathwayTab create(istream& pathway_stream,
const PropertySet& props,
istream* imap_stream=NULL,
istream* dogma_stream=NULL) {
istringstream is(DEFAULT_INTERACTION_MAP);
istringstream ds(CENTRAL_DOGMA);
if (imap_stream == NULL) {
imap_stream = &is;
}
if (dogma_stream == NULL) {
dogma_stream = &ds;
}
return PathwayTab(pathway_stream, *imap_stream, *dogma_stream, props);
}
~PathwayTab() {
delete _defaultFactorGen;
map< pair<string, string>, FactorGenerator* >::iterator i;
i= _factorGenLookup.begin();
for ( ; i != _factorGenLookup.end(); ++i) {
delete i->second;
}
}
void addEntity(const string& entity, const string& type="protein");
Var addObservationNode(const string& entity, const string& on_type,
const string& obstype);
void addInteraction(const string& entity_from, const string& entity_to,
const string& interaction);
void addNode(Node nodename); // see also addEntity
void addEdge(const Node& from, const Node& to, const string& label);
void getAppropriateEntityNode(const string& entity, const string& species,
Node& out_node);
Node getNode(size_t i) const { return _nodevector[i]; }
size_t getNodeIndex(const Node& n) const {
map< Node, size_t >::const_iterator i = _nodemap.find(n);
return i->second;
}
string getEntityType(const string& entity) {
return _entities[entity];
}
void dumpNodeIndexMap() const;
string getInteraction(size_t child_i, size_t parent_i) const {
Node c = getNode(child_i);
Node p = getNode(parent_i);
string result = "";
map< Node, map< Node, string > >::const_iterator ci = _parents.find(c);
if (ci != _parents.end()) {
map< Node, string >::const_iterator pi = ci->second.find(p);
if (pi != ci->second.end()) {
result = pi->second;
}
}
return result;
}
void addFactorGenerator(const string& entity_type,
const string& node_type,
FactorGenerator* factor_gen);
int debugPrintParents(size_t node_i);
void printNodeMap(ostream& to=cout, const string& prefix="# ");
void printDaiFactorSection(ostream& to=cout);
void splitNodeParents(const Node& n, const size_t maxParents);
void splitHighInDegree(const int maxParents);
void generateFactorValues(const Node& child,
const vector< string >& edge_types,
vector< Real >& outValues) const;
vector< vector < SharedParameters::FactorOrientations > >
constructFactors(const RunConfiguration::EMSteps& sp,
vector< Factor >& outFactors,
vector< MaximizationStep >& outMsteps) const;
map< long, string > getOutputNodeMap();
};
#endif