Augustus 3.4.0
Loading...
Searching...
No Matches
properties.hh
1/*
2 * properties.hh
3 *
4 * License: Artistic License, see file LICENSE.TXT or
5 * https://opensource.org/licenses/artistic-license-1.0
6 *
7 * Description: Declaration of the Properties class.
8 */
9
10#ifndef _PROPERTIES_HH
11#define _PROPERTIES_HH
12
13// project includes
14#include "types.hh"
15
16// json support include
17#include "json.hpp"
18
19// standard C/C++ includes
20#include <map>
21
22#ifdef __APPLE__
23#include <mach-o/dyld.h> // for _NSGetExecutablePath
24#endif
25
26
27#define GENEMODEL_KEY "genemodel"
28#define NONCODING_KEY "nc"
29#define SINGLESTRAND_KEY "singlestrand"
30#define SPECIES_KEY "species"
31#define CFGPATH_KEY "AUGUSTUS_CONFIG_PATH"
32#define INPUTFILE_KEY "queryfile"
33#define SPECIESDIR_KEY "speciesdir"
34#define UTR_KEY "UTR"
35#define TRANSFILE_KEY "transfile"
36#define EXTRINSIC_KEY "extrinsic"
37#define EXTRFILE_KEY "extrinsicCfgFile"
38#define EXTERNAL_KEY "optCfgFile"
39#define HINTSFILE_KEY "hintsfile"
40#define ALN_KEY "alnfile"
41#define TREE_KEY "treefile"
42#define DB_KEY "dbaccess"
43#define SEQ_KEY "speciesfilenames"
44#define CODONALN_KEY "codonAlignmentFile"
45#define REF_EXON_KEY "referenceFile"
46
47#define OVLPLENFILE "ovlp_len.pbl"
48
49using json = nlohmann::json;
50
62 PropertiesError( string msg ) : ProjectError( msg ) { }
63};
64
69 KeyNotFoundError( string key ) :
70 PropertiesError("Properties::getProperty(): no such key \"" + key + "\".")
71 {}
72};
73
75 SpecifiedTypeError(string name, string type) :
76 PropertiesError("Properties::getProperty(): property \"" + name + "\" is not defined as \"" + type + "\" in configuration file.")
77 {}
78};
79
80struct ValueError : public PropertiesError {
81 ValueError(string name, string value) :
82 PropertiesError("Properties::getProperty(): the given value \"" + value + "\" of property \"" + name + "\" is not one of the possible values according to the configuration file.")
83 {}
84};
85
90 ValueFormatError( string key, string value, string type ) :
91 PropertiesError( "Properties::getProperty(): cannot convert value \""
92 + value + "\" of key \"" + key + "\" into " + type + "." )
93 {}
94};
95
100 string message;
101 HelpException(string s) : message(s) {}
102}; // no error
103
183{
184public:
198 static void readFile ( string file );
209 static void init ( int argc, char* argv[] );
213 static Boolean hasProperty( string name);
214
221 static void addProperty ( string name, string value );
225 static Integer getIntProperty ( string name );
226
230 static Double getDoubleProperty ( string name );
234 static double getdoubleProperty ( string name );
238 static Boolean getBoolProperty ( string name );
242 static const char* getProperty ( string name );
246 static const char* getProperty(string name, int index);
252 static string getConfigFilename(string name)
253 {
254 if (name != "") {
255 return properties[CFGPATH_KEY] + getProperty(name);
256 } else {
257 return properties[CFGPATH_KEY];
258 }
259 }
260
261 // assign value only if key is present
262 static bool assignProperty(string name, Integer& target)
263 {
264 try {
265 target = getIntProperty(name);
266 } catch (KeyNotFoundError &e) {
267 return false;
268 }
269 return true;
270 }
271 static bool assignProperty(string name, unsigned& target)
272 {
273 try {
274 target = (unsigned) getIntProperty(name);
275 } catch (KeyNotFoundError &e) {
276 return false;
277 }
278 return true;
279 }
280 static bool assignProperty(string name, Double& target)
281 {
282 try {
283 target = getDoubleProperty(name);
284 } catch (KeyNotFoundError &e) {
285 return false;
286 }
287 return true;
288 }
289 static bool assignProperty(string name, double& target)
290 {
291 try {
292 target = getdoubleProperty(name);
293 } catch (KeyNotFoundError &e) {
294 return false;
295 }
296 return true;
297 }
298 static bool assignProperty(string name, Boolean& target)
299 {
300 try {
301 target = getBoolProperty(name);
302 } catch (KeyNotFoundError &e) {
303 return false;
304 }
305 return true;
306 }
307 static bool assignProperty(string name, string& target)
308 {
309 try {
310 target = getProperty(name);
311 } catch (KeyNotFoundError &e) {
312 return false;
313 }
314 return true;
315 }
316 static bool assignProperty(string name, const char*& target)
317 {
318 try {
319 target = getProperty(name);
320 } catch (KeyNotFoundError &e) {
321 return false;
322 }
323 return true;
324 }
325
326
327private:
328 Properties() {} // do not construct objects!
332 static void readLine(istream& strm );
333 static bool hasValue(const json& list, const string value);
334 static bool isDefinedType(const string typeName, const string paramName);
335 static bool isPossibleValue(const string value, const string paramName);
336 static void setDefaultValues();
337
338private:
339 static map<string, string> properties;
340 static json allowedParameters;
341};
342
343/*
344 * Find the path to the executable, e.g. /opt/augustus/bin/augustus, /home/mario/augustus/bin/augustus
345 * code contributed by Bastien Chevreux
346 */
347string findLocationOfSelfBinary();
348
349#endif // _PROPERTIES_HH
This class implements a double object with a very large range.
Definition lldouble.hh:31
Definition types.hh:449
The Properties class.
Definition properties.hh:183
static void addProperty(string name, string value)
Definition properties.cc:457
static void init(int argc, char *argv[])
Definition properties.cc:66
static void readFile(string file)
Definition properties.cc:35
a class to store JSON values
Definition json.hpp:16658
basic_json<> json
default JSON class
Definition json.hpp:2933
Definition properties.hh:99
Definition properties.hh:68
The base exception class for Properties.
Definition properties.hh:56
PropertiesError(string msg)
Definition properties.hh:62
Definition properties.hh:74
Definition properties.hh:80
Definition properties.hh:89