@@ -651,7 +651,10 @@ void test_unnormalized_weighted_unifrac() {
651
651
std::vector<double *> strides = su::make_strides (6 );
652
652
std::vector<double *> strides_total = su::make_strides (6 );
653
653
654
- su::unifrac (table, tree, su::weighted_unnormalized, strides, strides_total, 0 , 3 , 0 );
654
+ su::task_parameters task_p;
655
+ task_p.start = 0 ; task_p.stop = 3 ; task_p.tid = 0 ; task_p.n_samples = 6 ;
656
+
657
+ su::unifrac (table, tree, su::weighted_unnormalized, strides, strides_total, &task_p);
655
658
for (unsigned int i = 0 ; i < 3 ; i++) {
656
659
for (unsigned int j = 0 ; j < 6 ; j++) {
657
660
ASSERT (fabs (strides[i][j] - exp [i][j]) < 0.000001 );
@@ -661,6 +664,85 @@ void test_unnormalized_weighted_unifrac() {
661
664
SUITE_END ();
662
665
}
663
666
667
+ void test_generalized_unifrac () {
668
+ SUITE_START (" test generalized unifrac" );
669
+
670
+ std::vector<std::thread> threads (1 );
671
+ su::BPTree tree = su::BPTree (" (GG_OTU_1:1,(GG_OTU_2:1,GG_OTU_3:1):1,(GG_OTU_5:1,GG_OTU_4:1):1);" );
672
+ su::biom table = su::biom (" test.biom" );
673
+
674
+ // weighted normalized unifrac as computed above
675
+ std::vector<double *> w_exp;
676
+ double w_stride1[] = {0.38095238 , 0.33333333 , 0.73333333 , 0.33333333 , 0.5 , 0.26785714 };
677
+ double w_stride2[] = {0.58095238 , 0.66666667 , 0.86666667 , 0.25 , 0.28571429 , 0.45833333 };
678
+ double w_stride3[] = {0.47619048 , 0.66666667 , 0.46666667 , 0.47619048 , 0.66666667 , 0.46666667 };
679
+ w_exp.push_back (w_stride1);
680
+ w_exp.push_back (w_stride2);
681
+ w_exp.push_back (w_stride3);
682
+ std::vector<double *> w_strides = su::make_strides (6 );
683
+ std::vector<double *> w_strides_total = su::make_strides (6 );
684
+ su::task_parameters w_task_p;
685
+ w_task_p.start = 0 ; w_task_p.stop = 3 ; w_task_p.tid = 0 ; w_task_p.n_samples = 6 ;
686
+ w_task_p.g_unifrac_alpha = 1.0 ;
687
+ su::unifrac (table, tree, su::generalized, w_strides, w_strides_total, &w_task_p);
688
+
689
+ // as computed by GUniFrac v1.0
690
+ // Sample1 Sample2 Sample3 Sample4 Sample5 Sample6
691
+ // Sample1 0.0000000 0.4408392 0.6886965 0.7060606 0.5833333 0.3278410
692
+ // Sample2 0.4408392 0.0000000 0.5102041 0.7500000 0.8000000 0.5208125
693
+ // Sample3 0.6886965 0.5102041 0.0000000 0.8649351 0.9428571 0.5952381
694
+ // Sample4 0.7060606 0.7500000 0.8649351 0.0000000 0.5000000 0.4857143
695
+ // Sample5 0.5833333 0.8000000 0.9428571 0.5000000 0.0000000 0.7485714
696
+ // Sample6 0.3278410 0.5208125 0.5952381 0.4857143 0.7485714 0.0000000
697
+ std::vector<double *> d0_exp;
698
+ double d0_stride1[] = {0.4408392 , 0.5102041 , 0.8649351 , 0.5000000 , 0.7485714 , 0.3278410 };
699
+ double d0_stride2[] = {0.6886965 , 0.7500000 , 0.9428571 , 0.4857143 , 0.5833333 , 0.5208125 };
700
+ double d0_stride3[] = {0.7060606 , 0.8000000 , 0.5952381 , 0.7060606 , 0.8000000 , 0.5952381 };
701
+ d0_exp.push_back (d0_stride1);
702
+ d0_exp.push_back (d0_stride2);
703
+ d0_exp.push_back (d0_stride3);
704
+ std::vector<double *> d0_strides = su::make_strides (6 );
705
+ std::vector<double *> d0_strides_total = su::make_strides (6 );
706
+ su::task_parameters d0_task_p;
707
+ d0_task_p.start = 0 ; d0_task_p.stop = 3 ; d0_task_p.tid = 0 ; d0_task_p.n_samples = 6 ;
708
+ d0_task_p.g_unifrac_alpha = 0.0 ;
709
+ su::unifrac (table, tree, su::generalized, d0_strides, d0_strides_total, &d0_task_p);
710
+
711
+ // as computed by GUniFrac v1.0
712
+ // Sample1 Sample2 Sample3 Sample4 Sample5 Sample6
713
+ // Sample1 0.0000000 0.4040518 0.6285560 0.5869439 0.4082483 0.2995673
714
+ // Sample2 0.4040518 0.0000000 0.4160597 0.7071068 0.7302479 0.4860856
715
+ // Sample3 0.6285560 0.4160597 0.0000000 0.8005220 0.9073159 0.5218198
716
+ // Sample4 0.5869439 0.7071068 0.8005220 0.0000000 0.4117216 0.3485667
717
+ // Sample5 0.4082483 0.7302479 0.9073159 0.4117216 0.0000000 0.6188282
718
+ // Sample6 0.2995673 0.4860856 0.5218198 0.3485667 0.6188282 0.0000000
719
+ std::vector<double *> d05_exp;
720
+ double d05_stride1[] = {0.4040518 , 0.4160597 , 0.8005220 , 0.4117216 , 0.6188282 , 0.2995673 };
721
+ double d05_stride2[] = {0.6285560 , 0.7071068 , 0.9073159 , 0.3485667 , 0.4082483 , 0.4860856 };
722
+ double d05_stride3[] = {0.5869439 , 0.7302479 , 0.5218198 , 0.5869439 , 0.7302479 , 0.5218198 };
723
+ d05_exp.push_back (d05_stride1);
724
+ d05_exp.push_back (d05_stride2);
725
+ d05_exp.push_back (d05_stride3);
726
+ std::vector<double *> d05_strides = su::make_strides (6 );
727
+ std::vector<double *> d05_strides_total = su::make_strides (6 );
728
+ su::task_parameters d05_task_p;
729
+ d05_task_p.start = 0 ; d05_task_p.stop = 3 ; d05_task_p.tid = 0 ; d05_task_p.n_samples = 6 ;
730
+ d05_task_p.g_unifrac_alpha = 0.5 ;
731
+ su::unifrac (table, tree, su::generalized, d05_strides, d05_strides_total, &d05_task_p);
732
+
733
+ for (unsigned int i = 0 ; i < 3 ; i++) {
734
+ for (unsigned int j = 0 ; j < 6 ; j++) {
735
+ ASSERT (fabs (w_strides[i][j] - w_exp[i][j]) < 0.000001 );
736
+ ASSERT (fabs (d0_strides[i][j] - d0_exp[i][j]) < 0.000001 );
737
+ ASSERT (fabs (d05_strides[i][j] - d05_exp[i][j]) < 0.000001 );
738
+ }
739
+ free (w_strides[i]);
740
+ free (d0_strides[i]);
741
+ free (d05_strides[i]);
742
+ }
743
+ SUITE_END ();
744
+ }
745
+
664
746
void test_make_strides () {
665
747
SUITE_START (" test make stripes" );
666
748
std::vector<double *> exp ;
@@ -695,7 +777,10 @@ void test_unweighted_unifrac() {
695
777
std::vector<double *> strides = su::make_strides (6 );
696
778
std::vector<double *> strides_total = su::make_strides (6 );
697
779
698
- su::unifrac (table, tree, su::unweighted, strides, strides_total, 0 , 3 , 0 );
780
+ su::task_parameters task_p;
781
+ task_p.start = 0 ; task_p.stop = 3 ; task_p.tid = 0 ; task_p.n_samples = 6 ;
782
+
783
+ su::unifrac (table, tree, su::unweighted, strides, strides_total, &task_p);
699
784
700
785
for (unsigned int i = 0 ; i < 3 ; i++) {
701
786
for (unsigned int j = 0 ; j < 6 ; j++) {
@@ -722,8 +807,11 @@ void test_normalized_weighted_unifrac() {
722
807
exp .push_back (stride3);
723
808
std::vector<double *> strides = su::make_strides (6 );
724
809
std::vector<double *> strides_total = su::make_strides (6 );
725
-
726
- su::unifrac (table, tree, su::weighted_normalized, strides, strides_total, 0 , 3 , 0 );
810
+
811
+ su::task_parameters task_p;
812
+ task_p.start = 0 ; task_p.stop = 3 ; task_p.tid = 0 ; task_p.n_samples = 6 ;
813
+
814
+ su::unifrac (table, tree, su::weighted_normalized, strides, strides_total, &task_p);
727
815
for (unsigned int i = 0 ; i < 3 ; i++) {
728
816
for (unsigned int j = 0 ; j < 6 ; j++) {
729
817
ASSERT (fabs (strides[i][j] - exp [i][j]) < 0.000001 );
@@ -856,6 +944,7 @@ int main(int argc, char** argv) {
856
944
test_unweighted_unifrac ();
857
945
test_unnormalized_weighted_unifrac ();
858
946
test_normalized_weighted_unifrac ();
947
+ test_generalized_unifrac ();
859
948
test_unifrac_sample_counts ();
860
949
861
950
printf (" \n " );
0 commit comments