File: indelCoderOptions.cpp

package info (click to toggle)
fastml 3.11-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,772 kB
  • sloc: cpp: 48,522; perl: 3,588; ansic: 819; makefile: 386; python: 83; sh: 55
file content (169 lines) | stat: -rw-r--r-- 6,580 bytes parent folder | download | duplicates (5)
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
/********************************************************************************************
indelCoderOptions - a class that contains all the parameters for the indelCoderProjest as static
use the 'Parameters' class to read info from txt file.
initDefault. (+Parameters::addParameter)
getParamsFromFile. ->with alterations of defults for consistancy
verifyConsistParams.
*********************************************************************************************/
#include "indelCoderOptions.h"
#include "errorMsg.h"
#include "someUtil.h"
#include "Parameters.h"
#include <iostream>
#include <cmath>

using namespace std;

// recognize all the static members defined at .h
string indelCoderOptions::_seqFile;
string indelCoderOptions::_logFile;
int indelCoderOptions::_logValue;
//string indelCoderOptions::_outDir;
string indelCoderOptions::_indelOutputInfoFile;	
string indelCoderOptions::_indelOutputFastaFile;
string indelCoderOptions::_nexusFileName;

indelCoderOptions::codingType indelCoderOptions::_codingType;
//bool indelCoderOptions::_isMCIC2;

bool indelCoderOptions::_isCheckForTriangleInequality;
bool indelCoderOptions::_isOmitLeadingAndEndingGaps;




/********************************************************************************************
*********************************************************************************************/
void indelCoderOptions::initOptions(const string& paramFileName)
{	
	//getOutDirFromFile(paramFileName);	// first set _outDir to be used next
	//createDir("", indelCoderOptions::_outDir);
	ifstream params(paramFileName.c_str());
	if(params.good())
		Parameters::readParameters(params);
	params.close();
	initDefault();
	getParamsFromFile(paramFileName);
	//verifyConsistParams();
}



/********************************************************************************************
*********************************************************************************************/
//void indelCoderOptions::getOutDirFromFile(const string& paramFileName)
//{
//	_outDir = "INDEL_CODER_RES";
//	Parameters::addParameter("_outDir", _outDir);
//	
//	_outDir = Parameters::getString("_outDir");
//}

/********************************************************************************************
initDefault
*********************************************************************************************/
void indelCoderOptions::initDefault()
{
// all the default values are stored in the gainLossOptions:: static members
//################### Basic parameters:
// input (general)
	_seqFile = "";				// essential - fasta file with presence(1)/absence(0) for each species over all gene families (positions)
	_indelOutputInfoFile= "";
	_indelOutputFastaFile="";
	_nexusFileName="";
// output
//_outDir = "RESULTS";		// concatenated after current dir location 'pwd'
	_logFile = "log.txt";		// print-outs of the running progress including the estimated parameters optimization
	_logValue = 4;				// verbosity level - ~4 - normal, >7 - load of info
	//_isMCIC2 = true;
	_codingType =SIC;
	_isCheckForTriangleInequality = false;
	_isOmitLeadingAndEndingGaps = true;	// The typical approach is to omit (SeqState)

	Parameters::addParameter("_seqFile", _seqFile);
	Parameters::addParameter("_logFile", _logFile);
	Parameters::addParameter("_indelOutputInfoFile", _indelOutputInfoFile);
	Parameters::addParameter("_indelOutputFastaFile", _indelOutputFastaFile);
	Parameters::addParameter("_nexusFileName", _nexusFileName);

	Parameters::addParameter("_logValue", _logValue);
	Parameters::addParameter("_codingType", getCodingType(_codingType));
	//Parameters::addParameter("_isMCIC2", (_isMCIC2 == true) ? 1 : 0);
	Parameters::addParameter("_isCheckForTriangleInequality", (_isCheckForTriangleInequality == true) ? 1 : 0);
	Parameters::addParameter("_isOmitLeadingAndEndingGaps", (_isOmitLeadingAndEndingGaps == true) ? 1 : 0);

}


/********************************************************************************************
getParamsFromFile
*********************************************************************************************/
void indelCoderOptions::readParameters(const string& paramFileName)
{
	ifstream params(paramFileName.c_str());
	if(params.good())
		Parameters::readParameters(params);		// only place where params are read, updateParameter(paramName, param.c_str()) used
	params.close();
}
/********************************************************************************************
getParamsFromFile
*********************************************************************************************/
void indelCoderOptions::getParamsFromFile(const string& paramFileName)
{	
	readParameters(paramFileName);
	_logFile = Parameters::getString("_logFile");
	_seqFile = Parameters::getString("_seqFile");
	_indelOutputFastaFile = Parameters::getString("_indelOutputFastaFile");
	_nexusFileName = Parameters::getString("_nexusFileName");
	_indelOutputInfoFile = Parameters::getString("_indelOutputInfoFile");
	if(_seqFile=="") errorMsg::reportError("_seqFile is needed");
	if(_indelOutputFastaFile=="") errorMsg::reportError("_indelOutputFastaFile is needed");
	if(_nexusFileName=="") errorMsg::reportError("_nexusFileName is needed");

	if(_indelOutputInfoFile=="") errorMsg::reportError("_indelOutputInfoFile is needed");
	//_isMCIC2 = (Parameters::getInt("_isMCIC2") == 1) ? true : false;
	_codingType = getCodingType(Parameters::getString("_codingType"));

	_isCheckForTriangleInequality = (Parameters::getInt("_isCheckForTriangleInequality") == 1) ? true : false;
	_isOmitLeadingAndEndingGaps = (Parameters::getInt("_isOmitLeadingAndEndingGaps") == 1) ? true : false;
	_logValue = Parameters::getInt("_logValue");
}

/********************************************************************************************
enum distributionType {SIC, MCIC, MCIC2};
*********************************************************************************************/
string indelCoderOptions::getCodingType(codingType type) 
{
	string res = "";
	switch (type)
	{
	case SIC:
		res = "SIC";
		break;
	case MCIC:
		res = "MCIC";
		break;
	case MCIC2:
		res = "MCIC2";
		break;
	default:
		errorMsg::reportError("unknown type in codingType - {SIC, MCIC, MCIC2}");
	}
	return res;
}
//////////////////////////////////////////////////////////////////////////
indelCoderOptions::codingType indelCoderOptions::getCodingType(const string& str) 
{
	if (str == "SIC")
		return SIC;
	if (str == "MCIC")
		return MCIC;
	if (str == "MCIC2")
		return MCIC2;
	else
		errorMsg::reportError("unknown type in codingType - {SIC, MCIC, MCIC2}");
	return SIC;
}