forked from sbenz/Paradigm
-
Notifications
You must be signed in to change notification settings - Fork 5
/
configuration.cpp
79 lines (71 loc) · 2.64 KB
/
configuration.cpp
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
/********************************************************************************/
/* 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). */
/********************************************************************************/
#include "configuration.h"
const std::string RunConfiguration::INFERENCE_CONF_TOKEN("inference");
const std::string RunConfiguration::EVIDENCE_CONF_TOKEN("evidence");
const std::string RunConfiguration::PATHWAY_CONF_TOKEN("pathway");
const std::string RunConfiguration::EM_STEP_CONF_TOKEN("em_step");
const std::string RunConfiguration::EM_CONF_TOKEN("em");
const std::string RunConfiguration::INFERENCE_MATCH_TOKEN("pathway_match");
RunConfiguration::RunConfiguration(const std::string& configure_filename)
{
std::ifstream is(configure_filename.c_str());
if (!is.is_open())
THROW("couldn't open configuration file");
addConfigurations(is);
}
PropertySet&
RunConfiguration::getInferenceProperties(const std::string& pathway_filename)
{
for (size_t i = 0; i < _inferences.size(); i++)
{
if (!_inferences[i].hasKey(INFERENCE_MATCH_TOKEN))
{
return _inferences[i];
}
std::string m = _inferences[i].getAs<std::string>(INFERENCE_MATCH_TOKEN);
if (pathway_filename.find(m) != std::string::npos)
{
return _inferences[i];
}
}
THROW("No matching inference configurations");
}
void
RunConfiguration::addConfigurations(std::istream& is)
{
std::string type;
PropertySet conf;
while(is >> type)
{
is >> conf;
if (type == INFERENCE_CONF_TOKEN) {
_inferences.push_back(conf);
} else if (type == EVIDENCE_CONF_TOKEN) {
_evidences.push_back(conf);
} else if (type == EM_STEP_CONF_TOKEN) {
std::set<PropertyKey> keys = conf.keys();
std::set<PropertyKey>::iterator i = keys.begin();
EMStep e;
for ( ; i != keys.end(); ++i) {
std::vector< std::string > edges = tokenizeString(conf.getAs<std::string>(*i), true, ";");
SmallSet< std::string > s(edges.begin(), edges.end(), edges.size());
e[*i] = s;
}
_emsteps.push_back(e);
} else if (type == EM_CONF_TOKEN) {
_em = conf;
} else if (type == PATHWAY_CONF_TOKEN) {
_path = conf;
} else {
THROW("Expecting an inference or evidence token in conf file");
}
}
}
size_t RunConfiguration::evidenceSize() {return _evidences.size();}
PropertySet& RunConfiguration::evidence(size_t i) {return _evidences.at(i);}