@@ -555,14 +555,14 @@ void test_bptree_rightsibling() {
555
555
556
556
void test_propstack_constructor () {
557
557
SUITE_START (" test propstack constructor" );
558
- su::PropStack ps = su::PropStack (10 );
558
+ su::PropStack< double > ps (10 );
559
559
// nothing to test directly...
560
560
SUITE_END ();
561
561
}
562
562
563
563
void test_propstack_push_and_pop () {
564
564
SUITE_START (" test propstack push and pop" );
565
- su::PropStack ps = su::PropStack (10 );
565
+ su::PropStack< double > ps (10 );
566
566
567
567
double *vec1 = ps.pop (1 );
568
568
double *vec2 = ps.pop (2 );
@@ -587,7 +587,7 @@ void test_propstack_push_and_pop() {
587
587
588
588
void test_propstack_get () {
589
589
SUITE_START (" test propstack get" );
590
- su::PropStack ps = su::PropStack (10 );
590
+ su::PropStack< double > ps (10 );
591
591
592
592
double *vec1 = ps.pop (1 );
593
593
double *vec2 = ps.pop (2 );
@@ -609,7 +609,7 @@ void test_unifrac_set_proportions() {
609
609
// ( ( ) ( ( ) ( ) ) ( ( ) ( ) ) )
610
610
su::BPTree tree = su::BPTree (" (GG_OTU_1,(GG_OTU_2,GG_OTU_3),(GG_OTU_5,GG_OTU_4));" );
611
611
su::biom table = su::biom (" test.biom" );
612
- su::PropStack ps = su::PropStack (table.n_samples );
612
+ su::PropStack< double > ps (table.n_samples );
613
613
614
614
double *obs = ps.pop (4 ); // GG_OTU_2
615
615
double exp4[] = {0.714285714286 , 0.333333333333 , 0.0 , 0.333333333333 , 1.0 , 0.25 };
@@ -631,6 +631,143 @@ void test_unifrac_set_proportions() {
631
631
SUITE_END ();
632
632
}
633
633
634
+ void test_unifrac_set_proportions_range () {
635
+ SUITE_START (" test unifrac set proportions range" );
636
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
637
+ // ( ( ) ( ( ) ( ) ) ( ( ) ( ) ) )
638
+ su::BPTree tree = su::BPTree (" (GG_OTU_1,(GG_OTU_2,GG_OTU_3),(GG_OTU_5,GG_OTU_4));" );
639
+ su::biom table = su::biom (" test.biom" );
640
+
641
+ const double exp4[] = {0.714285714286 , 0.333333333333 , 0.0 , 0.333333333333 , 1.0 , 0.25 };
642
+ const double exp6[] = {0.0 , 0.0 , 0.25 , 0.666666666667 , 0.0 , 0.5 };
643
+ const double exp3[] = {0.71428571 , 0.33333333 , 0.25 , 1.0 , 1.0 , 0.75 };
644
+
645
+
646
+ // first the whole table
647
+ {
648
+ su::PropStack<double > ps (table.n_samples );
649
+
650
+ double *obs = ps.pop (4 ); // GG_OTU_2
651
+ set_proportions_range (obs, tree, 4 , table, 0 , table.n_samples , ps);
652
+ for (unsigned int i = 0 ; i < table.n_samples ; i++)
653
+ ASSERT (fabs (obs[i] - exp4[i]) < 0.000001 );
654
+
655
+ obs = ps.pop (6 ); // GG_OTU_3
656
+ set_proportions_range (obs, tree, 6 , table, 0 , table.n_samples , ps);
657
+ for (unsigned int i = 0 ; i < table.n_samples ; i++)
658
+ ASSERT (fabs (obs[i] - exp6[i]) < 0.000001 );
659
+
660
+ obs = ps.pop (3 ); // node containing GG_OTU_2 and GG_OTU_3
661
+ set_proportions_range (obs, tree, 3 , table, 0 , table.n_samples , ps);
662
+ for (unsigned int i = 0 ; i < table.n_samples ; i++)
663
+ ASSERT (fabs (obs[i] - exp3[i]) < 0.000001 );
664
+ }
665
+
666
+ // beginning
667
+ {
668
+ su::PropStack<double > ps (3 );
669
+
670
+ double *obs = ps.pop (4 ); // GG_OTU_2
671
+ set_proportions_range (obs, tree, 4 , table, 0 , 3 , ps);
672
+ for (unsigned int i = 0 ; i < 3 ; i++)
673
+ ASSERT (fabs (obs[i] - exp4[i]) < 0.000001 );
674
+
675
+ obs = ps.pop (6 ); // GG_OTU_3
676
+ set_proportions_range (obs, tree, 6 , table, 0 , 3 , ps);
677
+ for (unsigned int i = 0 ; i < 3 ; i++)
678
+ ASSERT (fabs (obs[i] - exp6[i]) < 0.000001 );
679
+
680
+ obs = ps.pop (3 ); // node containing GG_OTU_2 and GG_OTU_3
681
+ set_proportions_range (obs, tree, 3 , table, 0 , 3 , ps);
682
+ for (unsigned int i = 0 ; i < 3 ; i++)
683
+ ASSERT (fabs (obs[i] - exp3[i]) < 0.000001 );
684
+ }
685
+
686
+
687
+ // end
688
+ {
689
+ su::PropStack<double > ps (4 );
690
+
691
+ double *obs = ps.pop (4 ); // GG_OTU_2
692
+ set_proportions_range (obs, tree, 4 , table, 2 , table.n_samples , ps);
693
+ for (unsigned int i = 2 ; i < table.n_samples ; i++)
694
+ ASSERT (fabs (obs[i-2 ] - exp4[i]) < 0.000001 );
695
+
696
+ obs = ps.pop (6 ); // GG_OTU_3
697
+ set_proportions_range (obs, tree, 6 , table, 2 , table.n_samples , ps);
698
+ for (unsigned int i = 2 ; i < table.n_samples ; i++)
699
+ ASSERT (fabs (obs[i-2 ] - exp6[i]) < 0.000001 );
700
+
701
+ obs = ps.pop (3 ); // node containing GG_OTU_2 and GG_OTU_3
702
+ set_proportions_range (obs, tree, 3 , table, 2 , table.n_samples , ps);
703
+ for (unsigned int i = 2 ; i < table.n_samples ; i++)
704
+ ASSERT (fabs (obs[i-2 ] - exp3[i]) < 0.000001 );
705
+ }
706
+
707
+
708
+ // middle
709
+ {
710
+ const unsigned int start = 1 ;
711
+ const unsigned int end = 4 ;
712
+ su::PropStack<double > ps (end-start);
713
+
714
+ double *obs = ps.pop (4 ); // GG_OTU_2
715
+ set_proportions_range (obs, tree, 4 , table, start, end, ps);
716
+ for (unsigned int i =start; i < end; i++)
717
+ ASSERT (fabs (obs[i-start] - exp4[i]) < 0.000001 );
718
+
719
+ obs = ps.pop (6 ); // GG_OTU_3
720
+ set_proportions_range (obs, tree, 6 , table, start, end, ps);
721
+ for (unsigned int i = start; i < end; i++)
722
+ ASSERT (fabs (obs[i-start] - exp6[i]) < 0.000001 );
723
+
724
+ obs = ps.pop (3 ); // node containing GG_OTU_2 and GG_OTU_3
725
+ set_proportions_range (obs, tree, 3 , table, start, end, ps);
726
+ for (unsigned int i = start; i < end; i++)
727
+ ASSERT (fabs (obs[i-start] - exp3[i]) < 0.000001 );
728
+ }
729
+
730
+ SUITE_END ();
731
+ }
732
+
733
+ void test_unifrac_set_proportions_range_float () {
734
+ SUITE_START (" test unifrac set proportions range float" );
735
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
736
+ // ( ( ) ( ( ) ( ) ) ( ( ) ( ) ) )
737
+ su::BPTree tree = su::BPTree (" (GG_OTU_1,(GG_OTU_2,GG_OTU_3),(GG_OTU_5,GG_OTU_4));" );
738
+ su::biom table = su::biom (" test.biom" );
739
+
740
+ const float exp4[] = {0.714285714286 , 0.333333333333 , 0.0 , 0.333333333333 , 1.0 , 0.25 };
741
+ const float exp6[] = {0.0 , 0.0 , 0.25 , 0.666666666667 , 0.0 , 0.5 };
742
+ const float exp3[] = {0.71428571 , 0.33333333 , 0.25 , 1.0 , 1.0 , 0.75 };
743
+
744
+ // just midle
745
+ {
746
+ const unsigned int start = 1 ;
747
+ const unsigned int end = 4 ;
748
+ su::PropStack<float > ps (end-start);
749
+
750
+ float *obs = ps.pop (4 ); // GG_OTU_2
751
+ set_proportions_range (obs, tree, 4 , table, start, end, ps);
752
+ for (unsigned int i =start; i < end; i++)
753
+ ASSERT (fabs (obs[i-start] - exp4[i]) < 0.000001 );
754
+
755
+ obs = ps.pop (6 ); // GG_OTU_3
756
+ set_proportions_range (obs, tree, 6 , table, start, end, ps);
757
+ for (unsigned int i = start; i < end; i++)
758
+ ASSERT (fabs (obs[i-start] - exp6[i]) < 0.000001 );
759
+
760
+ obs = ps.pop (3 ); // node containing GG_OTU_2 and GG_OTU_3
761
+ set_proportions_range (obs, tree, 3 , table, start, end, ps);
762
+ for (unsigned int i = start; i < end; i++)
763
+ ASSERT (fabs (obs[i-start] - exp3[i]) < 0.000001 );
764
+ }
765
+
766
+ SUITE_END ();
767
+ }
768
+
769
+
770
+
634
771
void test_unifrac_deconvolute_stripes () {
635
772
SUITE_START (" test deconvolute stripes" );
636
773
std::vector<double *> stripes;
@@ -1703,6 +1840,8 @@ int main(int argc, char** argv) {
1703
1840
test_propstack_get ();
1704
1841
1705
1842
test_unifrac_set_proportions ();
1843
+ test_unifrac_set_proportions_range ();
1844
+ test_unifrac_set_proportions_range_float ();
1706
1845
test_unifrac_deconvolute_stripes ();
1707
1846
test_unifrac_stripes_to_condensed_form_even ();
1708
1847
test_unifrac_stripes_to_condensed_form_odd ();
0 commit comments