File: character.h

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 (159 lines) | stat: -rw-r--r-- 4,924 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
#ifndef ___CHARACTER__
#define ___CHARACTER__

#include "definitions.h"
#include "gaps.h"
#include "matrixUtils.h"
#include "indelCoderOptions.h"


using namespace std;


class character {
public:

	explicit character(int coord_5p, int coord_3p, int numOfSquencs, int numOfStates=0):_coord_5p(coord_5p), _coord_3p(coord_3p), _numOfSequences(numOfSquencs)
	{
		_numOfStates = 1;
		_isTriangleInequalityCorrectionNeeded = false;
		//_sc_states.resize(numOfSquencs);	// No need - done later
	};

	~character() {};
	
	int getCoord5(){return _coord_5p;}
	int getCoord3(){return _coord_3p;}	
	void setCoord3(int coord_3p){ _coord_3p = coord_3p;}
	int getNumOfGaps(){return _gaps.numOfGaps();}	
	int getNumOfStates(){return _numOfStates;}
	vector<int> getGapsIndices() const {return _gapsIndices;}


	void addGap(gaps::gap* gap_p, int gapIndex){
		_gaps.insertNewGap(gap_p);
		_gapsIndices.push_back(gapIndex);
	}
	
	void addZeroState(){
		vector<int> zeroState((int)(_coord_3p-_coord_5p+1),1);	// vector of ones, length of character
		_states.push_back(zeroState);
	};
	
	void addState(vector<int> state){
		_states.push_back(state);
		++_numOfStates;
	};

	void resizeSc_states(){resizeMatrix(_sc_states,_numOfSequences,(int)(_coord_3p-_coord_5p+1)); oneMatrix(_sc_states); };
	void resizeStepMatrix(){resizeMatrix(_stepmatrix,_numOfStates,_numOfStates); };
	void setGapsInSc_states(int seqId, int coord5, int coord3){
		for (int i = coord5; i<=coord3; ++i){
			_sc_states[seqId][i-_coord_5p] = 0;
		}
	};
	vector< vector<int> > getScStates(){return _sc_states;};
	
	vector< vector<int> > getStates(){return _states;};

	
	//********************************************************************************************
	//isTriangleInequalityCorrectionNeeded
	//********************************************************************************************
	bool isTriangleInequalityCorrectionNeeded(){return _isTriangleInequalityCorrectionNeeded;};
	void checkForTriangleInequality(int st1, int st2);
	int getLongestGapStIndex();


	int computeNumOfSteps(int st1, int st2);
	
	
	//*******************************************************************************************
	//printScStates
	//*******************************************************************************************
	void printScStates(){
		cout<<"ScStates:"<<endl;
		for(int s=0; s<_sc_states.size(); ++s){
			for(int alp=0; alp<_sc_states[0].size(); ++alp){
				cout<<_sc_states[s][alp];
			}
			cout<<endl;
		}			
	}
	
	//********************************************************************************************
	//printStates
	//*********************************************************************************************
	void printStates(){
		cout<<"States:"<<endl;
		for(int st=0; st<_numOfStates; ++st){
			for(int alp=0; alp<_states[0].size(); ++alp){
				cout<<_states[st][alp];
			}
			cout<<endl;
		}			
	}


	//********************************************************************************************
	//determinationStepsMatrix
	//*********************************************************************************************
	void determinationStepsMatrix(){		
		resizeStepMatrix();
		for(int st1 = 0; st1< _numOfStates; ++st1){
			for(int st2= st1; st2< _numOfStates; ++st2){
				if(st1==st2)
					_stepmatrix[st1][st2] = 0;
				else{
					_stepmatrix[st1][st2] = computeNumOfSteps(st1,st2);
					_stepmatrix[st2][st1] = _stepmatrix[st1][st2];
				}
				if(indelCoderOptions::_isCheckForTriangleInequality)
					checkForTriangleInequality(st1,st2);
			}
		}		
	}
	
	//********************************************************************************************
	//printStepsMatrix
	//*********************************************************************************************
	void printStepsMatrix(ostream& out = cout, bool isCorrectdForTriangleInEq = false){
		out<<"    ";
		for(int st1 = 0; st1< _numOfStates; ++st1){
			out<<st1<<" ";
		}
		out<<endl;

		for(int st1 = 0; st1< _numOfStates; ++st1){
			out<<"["<<st1<<"] ";
			for(int st2= 0; st2< _numOfStates; ++st2){
				if(isCorrectdForTriangleInEq)
					out<<_stepmatrixTriagleInCorrected[st1][st2]<<" ";
				else
                    out<<_stepmatrix[st1][st2]<<" ";
			}
			out<<endl;
		}		
	}




private:
	int _coord_5p; 
	int _coord_3p;	
	int _numOfStates;
	int _numOfSequences;
	
	gaps _gaps;							// gaps included in this character	
	vector<int> _gapsIndices;			// since all gaps are indexed, here you find the indices of the gaps included in this character
	vector< vector<int> > _stepmatrix;
	vector< vector<int> > _sc_states;	// matrix - species X lengthOfCharacter
	vector< vector<int> > _states;

	bool _isTriangleInequalityCorrectionNeeded;
	vector< vector<int> > _stepmatrixTriagleInCorrected;

};

#endif