Skip to content

Commit d2e8929

Browse files
committed
Add tests for rate variation
Basic tests for rate variation.
1 parent f4c5d53 commit d2e8929

File tree

4 files changed

+428
-0
lines changed

4 files changed

+428
-0
lines changed

model/model_dna_rate_variation.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,25 @@ void ModelDNARateVariation::updateCountsAndWaitingTimesAcrossRoot( PositionType
535535
waitingTimes[i][childState] += weight * distToRoot;
536536
}
537537
}
538+
}
539+
540+
void ModelDNARateVariation::setAllMatricesToDefault() {
541+
for(int i = 0; i < genomeSize; i++) {
542+
for(int stateA = 0; stateA < num_states_; stateA++) {
543+
RealNumType rowSum = 0;
544+
for(int stateB = 0; stateB < num_states_; stateB++) {
545+
mutationMatrices[i * matSize + (stateB + row_index[stateA])] = mutation_mat[stateB + row_index[stateA]];
546+
transposedMutationMatrices[i * matSize + (stateB + row_index[stateA])] = transposed_mut_mat[stateB + row_index[stateA]];
547+
freqiFreqjQijs[i * matSize + (stateB + row_index[stateA])] = freqi_freqj_qij[stateB + row_index[stateA]];
548+
}
549+
550+
diagonalMutationMatrices[i * num_states_ + stateA] = diagonal_mut_mat[stateA];
551+
552+
// pre-compute matrix to speedup
553+
const RealNumType* transposed_mut_mat_row = getTransposedMutationMatrixRow(stateA, i);
554+
RealNumType* freqjTransposedijsRow = freqjTransposedijs + (i * matSize) + row_index[stateA];
555+
setVecByProduct<4>(freqjTransposedijsRow, root_freqs, transposed_mut_mat_row);
556+
557+
}
558+
}
538559
}

model/model_dna_rate_variation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ModelDNARateVariation : public ModelDNA {
2626
};
2727

2828
virtual inline const cmaple::RealNumType *const getMutationMatrixRow(StateType row, PositionType i) const override {
29+
assert(i < genomeSize);
2930
return mutationMatrices + (i * matSize) + row_index[row];
3031
};
3132

@@ -70,6 +71,8 @@ class ModelDNARateVariation : public ModelDNA {
7071
*/
7172
virtual bool updateMutationMatEmpirical() override;
7273

74+
void setAllMatricesToDefault();
75+
7376
void printMatrix(const RealNumType* matrix, std::ostream* outStream);
7477
void printCountsAndWaitingTimes(const RealNumType* counts, const RealNumType* waitingTImes, std::ostream* outStream);
7578

unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_executable(
1010
model_test.cpp
1111
alignment_test.cpp
1212
matrix_test.cpp
13+
ratevariation_test.cpp
1314
sequence_test.cpp
1415
seqregion_test.cpp
1516
mutation_test.cpp

0 commit comments

Comments
 (0)