@@ -2618,6 +2618,150 @@ void genTestData(std::unique_ptr<SeqRegions>& seqregions1,
26182618 *seqregions_3, 13e-8 , tree.aln , tree.model , tree.cumulative_rate , threshold_prob);
26192619}
26202620
2621+ /*
2622+ Test integrateMutations(std::unique_ptr<SeqRegions>& output_regions,
2623+ const SeqRegions& mutations,
2624+ const Alignment* aln,
2625+ const bool inverse) const
2626+ */
2627+ TEST (SeqRegions, integrateMutations)
2628+ {
2629+ Alignment aln = loadAln5K ();
2630+ Model model (cmaple::ModelBase::GTR);
2631+ Tree tree (&aln, &model);
2632+ std::unique_ptr<Params>& params = tree.params ;
2633+ const PositionType seq_length = aln.ref_seq .size ();
2634+ const StateType num_states = aln.num_states ;
2635+
2636+ std::unique_ptr<SeqRegions> seqregions1 = nullptr ;
2637+ std::unique_ptr<SeqRegions> mutations = nullptr ;
2638+ std::unique_ptr<SeqRegions> output_regions_ptr = nullptr ;
2639+
2640+ // dummy variables
2641+ const RealNumType threshold_prob = params->threshold_prob ;
2642+
2643+ // ----- Test 1 -----
2644+ genTestData (seqregions1, mutations, tree, threshold_prob, 1 );
2645+
2646+ seqregions1->integrateMutations <4 >(output_regions_ptr,
2647+ *mutations, tree.aln , false );
2648+
2649+ std::string output = " " ;
2650+ for (auto i = 0 ; i < output_regions_ptr->size (); ++i)
2651+ {
2652+ output += " State: " + convertIntToString (output_regions_ptr->at (i).type ) + " ; Prev_state: " + convertIntToString (output_regions_ptr->at (i).prev_state ) + " ; Position: " + convertIntToString (output_regions_ptr->at (i).position ) + " ; " ;
2653+ }
2654+
2655+ std::string expected_output = "State: 250 ; Prev_state: 252 ; Position: 239; State: 250 ; Prev_state: 252 ; Position: 240; State: 250 ; Prev_state: 252 ; Position: 377; State: 250 ; Prev_state: 252 ; Position: 378; State: 250 ; Prev_state: 252 ; Position: 1705; State: 251 ; Prev_state: 252 ; Position: 1706; State: 250 ; Prev_state: 252 ; Position: 3035; State: 250 ; Prev_state: 252 ; Position: 3036; State: 250 ; Prev_state: 252 ; Position: 14406; State: 250 ; Prev_state: 252 ; Position: 14407; State: 250 ; Prev_state: 252 ; Position: 23401; State: 250 ; Prev_state: 252 ; Position: 23402; State: 250 ; Prev_state: 252 ; Position: 26445; State: 250 ; Prev_state: 252 ; Position: 26446; State: 250 ; Prev_state: 252 ; Position: 28142; State: 250 ; Prev_state: 252 ; Position: 28143; State: 250 ; Prev_state: 252 ; Position: 28248; State: 250 ; Prev_state: 252 ; Position: 28249; State: 250 ; Prev_state: 252 ; Position: 28252; State: 250 ; Prev_state: 252 ; Position: 28253; State: 250 ; Prev_state: 252 ; Position: 29890; ";
2656+
2657+ EXPECT_EQ (output, expected_output);
2658+ // ----- Test 1 -----
2659+
2660+ // ----- Test 2 -----
2661+ genTestData (seqregions1, mutations, tree, threshold_prob, 2 );
2662+
2663+ seqregions1->integrateMutations <4 >(output_regions_ptr,
2664+ *mutations, tree.aln , false );
2665+
2666+ output = " " ;
2667+ for (auto i = 0 ; i < output_regions_ptr->size (); ++i)
2668+ {
2669+ output += " State: " + convertIntToString (output_regions_ptr->at (i).type ) + " ; Prev_state: " + convertIntToString (output_regions_ptr->at (i).prev_state ) + " ; Position: " + convertIntToString (output_regions_ptr->at (i).position ) + " ; " ;
2670+ }
2671+
2672+ expected_output = "State: 250 ; Prev_state: 252 ; Position: 14; State: 250 ; Prev_state: 252 ; Position: 239; State: 250 ; Prev_state: 252 ; Position: 240; State: 250 ; Prev_state: 252 ; Position: 3035; State: 250 ; Prev_state: 252 ; Position: 3036; State: 250 ; Prev_state: 252 ; Position: 8780; State: 251 ; Prev_state: 3 ; Position: 8781; State: 250 ; Prev_state: 252 ; Position: 14406; State: 250 ; Prev_state: 252 ; Position: 14407; State: 250 ; Prev_state: 252 ; Position: 17745; State: 250 ; Prev_state: 252 ; Position: 17746; State: 250 ; Prev_state: 252 ; Position: 17856; State: 250 ; Prev_state: 252 ; Position: 17857; State: 250 ; Prev_state: 252 ; Position: 18058; State: 250 ; Prev_state: 252 ; Position: 18059; State: 250 ; Prev_state: 252 ; Position: 23401; State: 250 ; Prev_state: 252 ; Position: 23402; State: 250 ; Prev_state: 252 ; Position: 28142; State: 250 ; Prev_state: 252 ; Position: 28143; State: 250 ; Prev_state: 252 ; Position: 29887; State: 251 ; Prev_state: 252 ; Position: 29888; State: 250 ; Prev_state: 252 ; Position: 29890; ";
2673+
2674+ EXPECT_EQ (output, expected_output);
2675+ // ----- Test 2 -----
2676+
2677+ // ----- Test 3 -----
2678+ genTestData (seqregions1, mutations, tree, threshold_prob, 3 );
2679+ seqregions1->at (0 ).type = TYPE_N;
2680+ seqregions1->at (1 ).type = 3 ;
2681+ seqregions1->at (4 ).type = TYPE_N;
2682+
2683+ seqregions1->integrateMutations <4 >(output_regions_ptr,
2684+ *mutations, tree.aln , false );
2685+
2686+ output = " " ;
2687+ for (auto i = 0 ; i < output_regions_ptr->size (); ++i)
2688+ {
2689+ output += " State: " + convertIntToString (output_regions_ptr->at (i).type ) + " ; Prev_state: " + convertIntToString (output_regions_ptr->at (i).prev_state ) + " ; Position: " + convertIntToString (output_regions_ptr->at (i).position ) + " ; " ;
2690+ }
2691+
2692+ expected_output = " State: 252 ; Prev_state: 252 ; Position: 239; State: 3 ; Prev_state: 1 ; Position: 240; State: 250 ; Prev_state: 252 ; Position: 3035; State: 250 ; Prev_state: 252 ; Position: 3036; State: 252 ; Prev_state: 252 ; Position: 14406; State: 250 ; Prev_state: 252 ; Position: 14407; State: 250 ; Prev_state: 252 ; Position: 18623; State: 251 ; Prev_state: 252 ; Position: 18624; State: 250 ; Prev_state: 252 ; Position: 23401; State: 250 ; Prev_state: 252 ; Position: 23402; State: 250 ; Prev_state: 252 ; Position: 24032; State: 251 ; Prev_state: 252 ; Position: 24033; State: 250 ; Prev_state: 252 ; Position: 28075; State: 251 ; Prev_state: 252 ; Position: 28076; State: 250 ; Prev_state: 252 ; Position: 28142; State: 250 ; Prev_state: 252 ; Position: 28143; State: 250 ; Prev_state: 252 ; Position: 29843; State: 250 ; Prev_state: 252 ; Position: 29890; " ;
2693+
2694+ EXPECT_EQ (output, expected_output);
2695+ // ----- Test 3 -----
2696+
2697+ // ----- Test 4 -----
2698+ genTestData (seqregions1, mutations, tree, threshold_prob, 4 );
2699+ seqregions1->at (1 ).type = TYPE_N;
2700+ seqregions1->at (2 ).type = 3 ;
2701+ seqregions1->at (2 ).prev_state = 2 ;
2702+ seqregions1->at (4 ).type = TYPE_O;
2703+ seqregions1->at (8 ).type = 2 ;
2704+ seqregions1->at (9 ).type = TYPE_N;
2705+
2706+ seqregions1->integrateMutations <4 >(output_regions_ptr,
2707+ *mutations, tree.aln , true );
2708+
2709+ output = " " ;
2710+ for (auto i = 0 ; i < output_regions_ptr->size (); ++i)
2711+ {
2712+ output += " State: " + convertIntToString (output_regions_ptr->at (i).type ) + " ; Prev_state: " + convertIntToString (output_regions_ptr->at (i).prev_state ) + " ; Position: " + convertIntToString (output_regions_ptr->at (i).position ) + " ; " ;
2713+ }
2714+
2715+ expected_output = " State: 250 ; Prev_state: 252 ; Position: 0; State: 252 ; Prev_state: 252 ; Position: 239; State: 3 ; Prev_state: 252 ; Position: 240; State: 250 ; Prev_state: 252 ; Position: 3035; State: 251 ; Prev_state: 252 ; Position: 3036; State: 250 ; Prev_state: 252 ; Position: 8780; State: 251 ; Prev_state: 252 ; Position: 8781; State: 250 ; Prev_state: 252 ; Position: 14406; State: 2 ; Prev_state: 252 ; Position: 14407; State: 252 ; Prev_state: 252 ; Position: 23401; State: 0 ; Prev_state: 252 ; Position: 23402; State: 250 ; Prev_state: 252 ; Position: 28142; State: 1 ; Prev_state: 252 ; Position: 28143; State: 250 ; Prev_state: 252 ; Position: 29882; State: 250 ; Prev_state: 252 ; Position: 29890; " ;
2716+
2717+ EXPECT_EQ (output, expected_output);
2718+
2719+ // ----- Test 4 -----
2720+
2721+ // ----- Test 5 -----
2722+ genTestData (seqregions1, mutations, tree, threshold_prob, 5 );
2723+ seqregions1->at (9 ).type = TYPE_N;
2724+ seqregions1->at (2 ).type = TYPE_O;
2725+ seqregions1->at (2 ).prev_state = 2 ;
2726+ mutations->at (5 ).type = 3 ;
2727+ mutations->at (5 ).type = 2 ;
2728+
2729+ /* std::cout << "seqregions1: " << std::endl;
2730+ for (auto i = 0; i < seqregions1->size(); ++i)
2731+ {
2732+ std::cout << "State: " << seqregions1->at(i).type <<" ; Prev_state: " << seqregions1->at(i).prev_state << " ; Position: " << seqregions1->at(i).position << std::endl;
2733+ }
2734+
2735+ std::cout << "mutations: " << std::endl;
2736+ for (auto i = 0; i < mutations->size(); ++i)
2737+ {
2738+ std::cout << "State: " << mutations->at(i).type <<" ; Prev_state: " << mutations->at(i).prev_state << " ; Position: " << mutations->at(i).position << std::endl;
2739+ }*/
2740+
2741+ seqregions1->integrateMutations <4 >(output_regions_ptr,
2742+ *mutations, tree.aln , true );
2743+
2744+ /* std::cout << "output_regions_ptr: " << std::endl;
2745+ for (auto i = 0; i < output_regions_ptr->size(); ++i)
2746+ {
2747+ std::cout << "State: " << output_regions_ptr->at(i).type <<" ; Prev_state: " << output_regions_ptr->at(i).prev_state << " ; Position: " << output_regions_ptr->at(i).position << std::endl;
2748+ }*/
2749+
2750+ output = " " ;
2751+ for (auto i = 0 ; i < output_regions_ptr->size (); ++i)
2752+ {
2753+ output += " State: " + convertIntToString (output_regions_ptr->at (i).type ) + " ; Prev_state: " + convertIntToString (output_regions_ptr->at (i).prev_state ) + " ; Position: " + convertIntToString (output_regions_ptr->at (i).position ) + " ; " ;
2754+ }
2755+
2756+ // std::cout << std::endl << std::endl << output << std::endl;
2757+
2758+ expected_output = " State: 250 ; Prev_state: 252 ; Position: 1; State: 250 ; Prev_state: 252 ; Position: 16; State: 250 ; Prev_state: 252 ; Position: 239; State: 251 ; Prev_state: 252 ; Position: 240; State: 250 ; Prev_state: 252 ; Position: 3035; State: 1 ; Prev_state: 252 ; Position: 3036; State: 250 ; Prev_state: 252 ; Position: 8780; State: 251 ; Prev_state: 252 ; Position: 8781; State: 250 ; Prev_state: 252 ; Position: 14406; State: 1 ; Prev_state: 252 ; Position: 14407; State: 252 ; Prev_state: 252 ; Position: 23401; State: 0 ; Prev_state: 252 ; Position: 23402; State: 250 ; Prev_state: 252 ; Position: 28142; State: 1 ; Prev_state: 252 ; Position: 28143; State: 250 ; Prev_state: 252 ; Position: 29869; State: 250 ; Prev_state: 252 ; Position: 29875; State: 250 ; Prev_state: 252 ; Position: 29890; " ;
2759+
2760+ EXPECT_EQ (output, expected_output);
2761+
2762+ // ----- Test 5 -----
2763+ }
2764+
26212765/*
26222766 Test mergeUpperLower<4>(SeqRegions* &merged_regions, RealNumType upper_plength,
26232767 const SeqRegions& lower_regions, RealNumType lower_plength, const
0 commit comments