File: computeSubstitutionCounts.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 (378 lines) | stat: -rw-r--r-- 20,444 bytes parent folder | download | duplicates (10)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#include "computeSubstitutionCounts.h"
#include "computePosteriorExpectationOfSubstitutions.h"
#include "computePosteriorExpectationOfSubstitutions_nonReversibleSp.h"
#include "multipleStochasticProcess.h"
#include "matrixUtils.h"
#include "simulateJumps.h"
#include "simulateCodonsJumps.h"
#include "simulateJumpsAbstract.h"
#include "treeIt.h"
#include "treeUtil.h"

/********************************************************************************************
computeSubstitutionCounts
*********************************************************************************************/
computeSubstitutionCounts::computeSubstitutionCounts(const sequenceContainer& sc, const tree& tr, multipleStochasticProcess* MultSpPtr, string& outDir, VVVdouble& LpostPerSpPerCat, const int simulationsIterNum, const MDOUBLE probCutOffSum, bool isSilent):
_tr(tr),_sc(sc),_pMSp(MultSpPtr),_outDir(outDir),_LpostPerSpPerCat(LpostPerSpPerCat), _simulationsIterNum(simulationsIterNum), _probCutOffSum(probCutOffSum),_isSilent(isSilent)
{
	if(!_pMSp->getSPVecSize()){
		errorMsg::reportError("Trying to call computeSubstitutionCounts with an empty multipleStochasticProcess object at computeSubstitutionCounts::computeSubstitutionCounts");
	}
	_alphabetSize = _pMSp->getSp(0)->alphabetSize();
}

computeSubstitutionCounts& computeSubstitutionCounts::operator=(const computeSubstitutionCounts &other){
	if (this != &other) {              // Check for self-assignment
	}
	return *this;
}


/********************************************************************************************
*********************************************************************************************/
void computeSubstitutionCounts::run()
{
	for(int fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
		for(int sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
			//if(sonStateIndex == fatherStateIndex) continue;
			_expMap_father2son[fatherStateIndex][sonStateIndex].resize(_sc.seqLen(),0);
			_probMap_father2son[fatherStateIndex][sonStateIndex].resize(_sc.seqLen(),0);
		}
	}

	resize_VVVV(_sc.seqLen(),_tr.getNodesNum(),_alphabetSize,_alphabetSize,_jointProb_PosNodeXY);
	resize_VVVV(_sc.seqLen(),_tr.getNodesNum(),_alphabetSize,_alphabetSize,_probChanges_PosNodeXY);
	resize_VVVV(_sc.seqLen(),_tr.getNodesNum(),_alphabetSize,_alphabetSize,_expChanges_PosNodeXY);

	computePosteriorOfChangeGivenTerminalsPerSpPerCat();	// GLM - multiple SPs
}

/********************************************************************************************
*********************************************************************************************/
void computeSubstitutionCounts::computePosteriorOfChangeGivenTerminalsPerSpPerCat()
{	
	int numOfSPs = _pMSp->getSPVecSize();

	// per Sp
	for (int spIndex=0; spIndex < numOfSPs; ++spIndex) {
		// Per RateCategory -- All the computations are done while looping over rate categories
		stochasticProcess * currentSp = _pMSp->getSp(spIndex);
		int numOfRateCategories = currentSp->categories();	
		for (int rateCategIndex=0 ; rateCategIndex < numOfRateCategories;++rateCategIndex)
		{
			tree copy_et = _tr;
			MDOUBLE rateCategVal = currentSp->rates(rateCategIndex);
			MDOUBLE  minimumRateCategVal = 0.0000001;
			MDOUBLE rate2multiply = max(rateCategVal,minimumRateCategVal);
			if(rateCategVal < minimumRateCategVal){
				LOGnOUT(4, <<" >>> NOTE: the rate category "<<rateCategVal<<" is too low for computePosteriorExpectationOfChangePerSite"<<endl);	}
			copy_et.multipleAllBranchesByFactor(rate2multiply);
			//if(!_isSilent) 
				//LOGnOUT(4, <<"running "<<gainLossOptions::_numOfSimulationsForPotExp<<" simulations for rate "<<rate2multiply<<endl);
			simulateJumpsAbstract* simPerRateCategory;
			if(_alphabetSize == 61)
				simPerRateCategory = new simulateCodonsJumps(copy_et,*currentSp,_alphabetSize);
			else
				simPerRateCategory = new simulateJumps(copy_et,*currentSp,_alphabetSize);
				
			simPerRateCategory->runSimulation(_simulationsIterNum);
			if(!_isSilent) 
				LOGnOUT(4,<<"finished simulations"<<endl);

			// Per POS		
			for (int pos = 0; pos <_sc.seqLen(); ++pos)
			{
				LOG(6,<<"pos "<<pos+1<<endl);
				// I) computePosteriorOfChangeGivenTerminals
				VVVdouble posteriorsGivenTerminalsPerRateCategoryPerPos;
				computePosteriorExpectationOfSubstitutions* cpesPerRateCategoryPerPos ;
				if(currentSp->isReversible())
					cpesPerRateCategoryPerPos = new computePosteriorExpectationOfSubstitutions(copy_et,_sc,currentSp);	// Per POS,CAT
				else
					cpesPerRateCategoryPerPos = new computePosteriorExpectationOfSubstitutions_nonReversibleSp(copy_et,_sc,currentSp);	// Per POS,CAT
				cpesPerRateCategoryPerPos->computePosteriorOfChangeGivenTerminals(posteriorsGivenTerminalsPerRateCategoryPerPos,pos);

				// II) Exp - take in account both: 1) simulations 2) posteriorsGivenTerminal
				VVVdouble expChangesForBranchPerRateCategoryPerPos;	// Sim+Exp
				resize_VVV(_tr.getNodesNum(),_alphabetSize,_alphabetSize,expChangesForBranchPerRateCategoryPerPos);

				VVdouble expVV = cpesPerRateCategoryPerPos->computeExpectationAcrossTree(*simPerRateCategory,posteriorsGivenTerminalsPerRateCategoryPerPos,
					expChangesForBranchPerRateCategoryPerPos);	// Per POS
				for(int fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
					for(int sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
						if(sonStateIndex == fatherStateIndex) continue;
						_expMap_father2son[fatherStateIndex][sonStateIndex][pos] += expVV[fatherStateIndex][sonStateIndex]*_LpostPerSpPerCat[spIndex][rateCategIndex][pos];
					}
				}

				// III) Sim - take in account both: 1) simulations 2) posteriorsGivenTerminal
				VVVdouble probChangesForBranchPerRateCategoryPerPos;	// Sim+Prob
				resize_VVV(_tr.getNodesNum(),_alphabetSize,_alphabetSize,probChangesForBranchPerRateCategoryPerPos);
				VVdouble probVV = cpesPerRateCategoryPerPos->computePosteriorAcrossTree(*simPerRateCategory,posteriorsGivenTerminalsPerRateCategoryPerPos,probChangesForBranchPerRateCategoryPerPos);
				for(int fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
					for(int sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
						if(sonStateIndex == fatherStateIndex) continue;
						_probMap_father2son[fatherStateIndex][sonStateIndex][pos] += probVV[fatherStateIndex][sonStateIndex]*_LpostPerSpPerCat[spIndex][rateCategIndex][pos];
					}
				}
				//	Store all information PerCat,PerPOS
				for(int i=0;i<_probChanges_PosNodeXY[pos].size();++i){	// nodeId
					for(int j=0;j<_probChanges_PosNodeXY[pos][i].size();++j){	// fatherState
						for(int k=0;k<_probChanges_PosNodeXY[pos][i][j].size();++k){	// sonState
							_jointProb_PosNodeXY[pos][i][j][k] += posteriorsGivenTerminalsPerRateCategoryPerPos[i][j][k]*_LpostPerSpPerCat[spIndex][rateCategIndex][pos];
							_probChanges_PosNodeXY[pos][i][j][k] += probChangesForBranchPerRateCategoryPerPos[i][j][k]*_LpostPerSpPerCat[spIndex][rateCategIndex][pos];
							_expChanges_PosNodeXY[pos][i][j][k] += expChangesForBranchPerRateCategoryPerPos[i][j][k]*_LpostPerSpPerCat[spIndex][rateCategIndex][pos];
						}
					}
				}
				delete(cpesPerRateCategoryPerPos);
			}
			delete(simPerRateCategory);
			// Per POS
		}
		// per rateCat
	}
	// Per Sp
}



/********************************************************************************************
printProbExp()
print perPos (over all branches)
use the members _expV01, _expV10 for basic 
*********************************************************************************************/
void computeSubstitutionCounts::printProbExp()
{

	string posteriorExpectationOfChangeString = _outDir + "//" + "posteriorExpectationOfChange.txt";
	ofstream posteriorExpectationStream(posteriorExpectationOfChangeString.c_str());
	string posteriorProbabilityOfChangeString = _outDir + "//" + "posteriorProbabilityOfChange.txt";
	ofstream posteriorProbabilityStream(posteriorProbabilityOfChangeString.c_str());

	int fatherStateIndex,sonStateIndex;
	posteriorExpectationStream<<"#POS"<<"\t";
	posteriorProbabilityStream<<"#POS"<<"\t";

	for (fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
		for (sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
			if(sonStateIndex == fatherStateIndex) continue;
			posteriorExpectationStream<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t";
			posteriorProbabilityStream<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t";
		}
	}
	posteriorExpectationStream<<endl;
	posteriorProbabilityStream<<endl;

	for (int pos = 0; pos <_sc.seqLen(); ++pos){
		posteriorExpectationStream<<pos+1<<"\t";
		posteriorProbabilityStream<<pos+1<<"\t";
		for (fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
			for (sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
				if(sonStateIndex == fatherStateIndex) continue;//ofir, note the change in print format
				posteriorExpectationStream<<_expMap_father2son[fatherStateIndex][sonStateIndex][pos]<<"\t";
				posteriorProbabilityStream<<_probMap_father2son[fatherStateIndex][sonStateIndex][pos]<<"\t";	
			}
		}
		posteriorExpectationStream<<endl;
		posteriorProbabilityStream<<endl;
	}
	posteriorExpectationStream.close();
	posteriorProbabilityStream.close();
}


/********************************************************************************************
printProbabilityPerPosPerBranch 1
produce 2 print files:
1. print detailed file (out)
2. print summary over all branches (outSum)
*********************************************************************************************/
void computeSubstitutionCounts::printProbabilityPerPosPerBranch()
{
	string probabilityPerPosPerBranch = _outDir + "//" + "probabilityPerPosPerBranch.txt"; 
	ofstream probabilityPerPosPerBranchStream(probabilityPerPosPerBranch.c_str());
	probabilityPerPosPerBranchStream<<"# print values over probCutOff "<<_probCutOffSum<<endl;
	probabilityPerPosPerBranchStream<<"#Event"<<"\t"<<"POS"<<"\t"<<"branch"<<"\t"<<"branchLength"<<"\t"<<"distance2root"<<"\t"<<"probability"<<endl;
	
	string countProbPerPos = _outDir + "//" + "probabilityPerPos.txt"; 
	ofstream countProbPerPosStream(countProbPerPos.c_str());
	countProbPerPosStream<<"# print values over probCutOff "<<_probCutOffSum<<endl;
	countProbPerPosStream<<"#POS"<<"\t";
	for(int fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
		for(int sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
			if(sonStateIndex == fatherStateIndex) continue;
			countProbPerPosStream<<"prob"<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t";
		}
	}
	countProbPerPosStream<<endl;
	
	for (int pos = 0; pos <_sc.seqLen(); ++pos){
		printProbabilityPerPosPerBranch(pos, _probChanges_PosNodeXY[pos],probabilityPerPosPerBranchStream,countProbPerPosStream);
	}
}
/********************************************************************************************
printGainLossProbabilityPerPosPerBranch 1.1
*********************************************************************************************/
void computeSubstitutionCounts::printProbabilityPerPosPerBranch(int pos, VVVdouble& probChanges, ostream& out, ostream& outCount)
{
	VVdouble countFromFather2Son;
	countFromFather2Son.resize(_alphabetSize);
	int fatherStateIndex,sonStateIndex;
	treeIterTopDownConst tIt(_tr);
	for (tree::nodeP mynode = tIt.first(); mynode != tIt.end(); mynode = tIt.next()) {
		for(fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
			countFromFather2Son[fatherStateIndex].resize(_alphabetSize,0);
			for(sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
				if(sonStateIndex == fatherStateIndex) continue;
				if(probChanges[mynode->id()][fatherStateIndex][sonStateIndex] > _probCutOffSum){//NIM
					out<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t"<<pos+1<<"\t"<<mynode->name()<<"\t"<<mynode->dis2father()<<"\t"<<getDistanceFromNode2ROOT(mynode)<<"\t"<<probChanges[mynode->id()][fatherStateIndex][sonStateIndex]<<endl;
					countFromFather2Son[fatherStateIndex][sonStateIndex] += probChanges[mynode->id()][fatherStateIndex][sonStateIndex];
				}
			}
		}
	}
	outCount<<pos+1<<"\t";
	for(fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
		for(sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
			if(sonStateIndex == fatherStateIndex) continue;
			//if(countFromFather2Son[fatherStateIndex][sonStateIndex] == 0) continue;//NIMROD
			outCount<<countFromFather2Son[fatherStateIndex][sonStateIndex]<<"\t";
		}
	}
	outCount<<endl;
}



/********************************************************************************************
*********************************************************************************************/
void computeSubstitutionCounts::printExpectationPerBranch()
{
	// ExpectationPerBranch
	VVVdouble posteriorsGivenTerminalsTotal;
	resize_VVV(_tr.getNodesNum(),_alphabetSize,_alphabetSize,posteriorsGivenTerminalsTotal);
	for (int pos = 0; pos <_sc.seqLen(); ++pos){
		for(int i=0;i<_expChanges_PosNodeXY[pos].size();++i){
			for(int j=0;j<_expChanges_PosNodeXY[pos][i].size();++j){
				for(int k=0;k<_expChanges_PosNodeXY[pos][i][j].size();++k){
					posteriorsGivenTerminalsTotal[i][j][k] += _expChanges_PosNodeXY[pos][i][j][k];
				}
			}
		}
	}
	string expectationPerBranch = _outDir + "//" + "ExpectationPerBranch.txt"; 
	ofstream expectationPerBranchStream(expectationPerBranch.c_str());
	printExpectationPerBranch(posteriorsGivenTerminalsTotal,expectationPerBranchStream);
}
/********************************************************************************************
*********************************************************************************************/
void computeSubstitutionCounts::printExpectationPerBranch(VVVdouble& expectChanges, ostream& out)
{
	treeIterTopDownConst tIt(_tr);
	out<<"#Event"<<"\t"<<"branch"<<"\t"<<"branchLength"<<"\t"<<"distance2root"<<"\t"<<"expectation"<<endl;
	for (tree::nodeP mynode = tIt.first(); mynode != tIt.end(); mynode = tIt.next()) {
		for(int fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
			for(int sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
				if(sonStateIndex == fatherStateIndex) continue;
				out<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t"<<
					mynode->name()<<"\t"<<mynode->dis2father()<<"\t"<<getDistanceFromNode2ROOT(mynode)<<"\t"<<expectChanges[mynode->id()][fatherStateIndex][sonStateIndex]<<endl;
			}
		}
	}
}


/********************************************************************************************
*********************************************************************************************/
void computeSubstitutionCounts::printTreesWithExpectationValuesAsBP(int from,int to)
{
	// ExpectationPerPosPerBranch - Print Trees
	Vstring Vnames;
	fillAllNodesNames(Vnames,_tr);
	createDir(_outDir, "TreesWithExpectationValuesAsBP");
	for (int pos = 0; pos <_sc.seqLen(); ++pos){
		string strTreeNum = _outDir + "//" + "TreesWithExpectationValuesAsBP" + "//" + "expTree" + int2string(pos+1) + ".ph";
		ofstream tree_out(strTreeNum.c_str());
		printTreeWithValuesAsBP(tree_out,_tr,Vnames,&_expChanges_PosNodeXY[pos],from,to);
	}
}

/********************************************************************************************
*********************************************************************************************/
void computeSubstitutionCounts::printTreesWithProbabilityValuesAsBP(int from,int to)
{
	// ProbabilityPerPosPerBranch - Print Trees
	Vstring Vnames;
	fillAllNodesNames(Vnames,_tr);
	createDir(_outDir, "TreesWithProbabilityValuesAsBP");
	for (int pos = 0; pos <_sc.seqLen(); ++pos){
		string strTreeNum = _outDir + "//" + "TreesWithProbabilityValuesAsBP"+ "//" + "probTree" + int2string(pos+1) + ".ph";
		ofstream tree_out(strTreeNum.c_str());
		printTreeWithValuesAsBP(tree_out,_tr,Vnames,&_probChanges_PosNodeXY[pos],from,to);
	}
}

/********************************************************************************************
printProbExpPerPosPerBranch 1
produce 2 print files:
1. print detailed file (out)
2. print summary over all branches (outSum)
*********************************************************************************************/
void computeSubstitutionCounts::printProbExpPerPosPerBranch(MDOUBLE probCutOff, MDOUBLE countsCutOff)
{
	string probExpPerPosPerBranch = _outDir + "//" + "expPerPosPerBranch.txt"; 
	ofstream probExpPerPosPerBranchStream(probExpPerPosPerBranch.c_str());
	probExpPerPosPerBranchStream<<"# print values over probCutOff "<<probCutOff<<endl;
	probExpPerPosPerBranchStream<<"#Event"<<"\t"<<"POS"<<"\t"<<"branch"<<"\t"<<"branchLength"<<"\t"<<"distance2root"<<"\t"<<"probability"<<"\t"<<"expectation"<<endl;

	string probExpPerPos = _outDir + "//" + "probExpCountPerPos.txt"; 
	ofstream countProbPerPosStream(probExpPerPos.c_str());
	countProbPerPosStream<<"# print count over probCutOff "<<countsCutOff<<endl;
	countProbPerPosStream<<"#POS"<<"\t"<<"Event"<<"\t"<<"EventProb"<<"\t"<<"EventExp"<<"\t"<<"EventCount"<<endl;
	
	for (int pos = 0; pos <_sc.seqLen(); ++pos){
		printProbExpPerPosPerBranch(pos, probCutOff,countsCutOff, _probChanges_PosNodeXY[pos],_expChanges_PosNodeXY[pos],probExpPerPosPerBranchStream,countProbPerPosStream);
	}
}
/********************************************************************************************
printGainLossProbExpPerPosPerBranch 1.1
Get pos, and iterate over all branches:
1. print detailed file (out)
2. print summary over all branches (outSum)
*********************************************************************************************/
void computeSubstitutionCounts::printProbExpPerPosPerBranch(int pos, MDOUBLE probCutOff, MDOUBLE countCutOff, VVVdouble& probChanges, VVVdouble& expChanges, ostream& out, ostream& outSum)
{
	VVdouble probFather2Son,expFather2Son;
	VVint countFather2Son;
	probFather2Son.resize(_alphabetSize);
	expFather2Son.resize(_alphabetSize);
	countFather2Son.resize(_alphabetSize);
	int fatherStateIndex,sonStateIndex; 

	treeIterTopDownConst tIt(_tr);
	for (tree::nodeP mynode = tIt.first(); mynode != tIt.end(); mynode = tIt.next()) {
		for(fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
			probFather2Son[fatherStateIndex].resize(_alphabetSize,0);
			expFather2Son[fatherStateIndex].resize(_alphabetSize,0);
			countFather2Son[fatherStateIndex].resize(_alphabetSize,0);
			for(sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
				if(sonStateIndex == fatherStateIndex) continue;
				out<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t"<<
					pos+1<<"\t"<<mynode->name()<<"\t"<<mynode->dis2father()<<"\t"<<getDistanceFromNode2ROOT(mynode)<<"\t"<<probChanges[mynode->id()][fatherStateIndex][sonStateIndex]<<"\t"<<expChanges[mynode->id()][fatherStateIndex][sonStateIndex]<<endl;
				probFather2Son[fatherStateIndex][sonStateIndex] += probChanges[mynode->id()][fatherStateIndex][sonStateIndex];
				expFather2Son[fatherStateIndex][sonStateIndex] += expChanges[mynode->id()][fatherStateIndex][sonStateIndex];
				if (probChanges[mynode->id()][fatherStateIndex][sonStateIndex] > countCutOff)
					countFather2Son[fatherStateIndex][sonStateIndex] += 1;
			}
		}
	}
	for(fatherStateIndex = 0;fatherStateIndex < _alphabetSize;++fatherStateIndex){
		for(sonStateIndex = 0;sonStateIndex < _alphabetSize;++sonStateIndex){
			if(sonStateIndex == fatherStateIndex) continue;
			outSum<<pos+1<<"\t"<<_sc.getAlphabet()->fromInt(fatherStateIndex)<<"->"<<_sc.getAlphabet()->fromInt(sonStateIndex)<<"\t"<<
				probFather2Son[fatherStateIndex][sonStateIndex]<<"\t"<<expFather2Son[fatherStateIndex][sonStateIndex]<<"\t"<<countFather2Son[fatherStateIndex][sonStateIndex]<<endl;
		}
	}
}