Ticket #627: moveNextTo_replacement.patch

File moveNextTo_replacement.patch, 10.3 KB (added by westram, 10 years ago)

like moveNextTo_original.patch, but use new, compare with old (changes test results)

  • PARSIMONY/AP_tree_nlen.cxx

     
    604604    AP_tree::set_root();
    605605}
    606606
    607 void AP_tree_nlen::moveNextTo(AP_tree_nlen *newBrother, AP_FLOAT rel_pos) {
     607void AP_tree_nlen::moveNextToOld(AP_tree_nlen *newBrother, AP_FLOAT rel_pos) {
    608608    ap_assert(father);
    609609    ap_assert(newBrother);
    610610    ap_assert(newBrother->father);
     
    781781    ap_assert(get_brother() == newBrother);
    782782}
    783783
     784void AP_tree_nlen::moveNextToNew(AP_tree_nlen *newBrother, AP_FLOAT rel_pos) {
     785    ap_assert(father);
     786    ap_assert(newBrother);
     787    ap_assert(newBrother->father);
     788    ap_assert(newBrother->father != father); // already there
     789
     790    ASSERT_VALID_TREE(rootNode());
     791
     792    ap_assert(rel_pos == 0.5); // only works for 0.5 (hardcoded in insert)
     793
     794    if (father->leftson != this) get_father()->swap_sons();
     795
     796    ap_assert(newBrother != father);
     797
     798    GBT_LEN oldLen = get_branchlength();
     799
     800    REMOVE();
     801    insert(newBrother);
     802
     803    set_branchlength(oldLen);
     804
     805    if (!is_leftson()) {
     806        get_father()->swap_sons();
     807    }
     808
     809    ASSERT_VALID_TREE(this);
     810    ASSERT_VALID_TREE(rootNode());
     811
     812    ap_assert(is_leftson());
     813    ap_assert(get_brother() == newBrother);
     814}
     815
     816// #define USE_OLD_MOVENEXTTO
     817// USE_OLD_MOVENEXTTO defined   -> try new method, revert, use old method, compare resulting topologies
     818// USE_OLD_MOVENEXTTO undefined -> try old method, revert, use new method, compare resulting topologies
     819// topologies are equal in both cases.
     820
     821void AP_tree_nlen::moveNextTo(AP_tree_nlen *newBrother, AP_FLOAT rel_pos) {
     822    NewickFormat format = NewickFormat(nLENGTH|nWRAP);
     823
     824    char *newick_this = GBT_tree_2_newick(this, format, false);;
     825    char *newick_brot = GBT_tree_2_newick(newBrother, format, false);;
     826    char *newick_prev = GBT_tree_2_newick(get_tree_root()->get_root_node(), format, false);;
     827
     828    // test other (=not "used") moveNextTo
     829    ap_main->remember();
     830#if defined(USE_OLD_MOVENEXTTO)
     831    moveNextToNew(newBrother, rel_pos);
     832    char *newick_new = GBT_tree_2_newick(get_tree_root()->get_root_node(), format, false);
     833#else // !defined(USE_OLD_MOVENEXTTO)
     834    moveNextToOld(newBrother, rel_pos);
     835    char *newick_old = GBT_tree_2_newick(get_tree_root()->get_root_node(), format, false);
     836#endif
     837    ap_main->revert();
     838
     839    // now really use moveNextTo
     840#if defined(USE_OLD_MOVENEXTTO)
     841    moveNextToOld(newBrother, rel_pos);
     842    char *newick_old = GBT_tree_2_newick(get_tree_root()->get_root_node(), format, false);
     843#else // !defined(USE_OLD_MOVENEXTTO)
     844    moveNextToNew(newBrother, rel_pos);
     845    char *newick_new = GBT_tree_2_newick(get_tree_root()->get_root_node(), format, false);
     846#endif
     847
     848    if (strcmp(newick_old, newick_new) != 0) {
     849        fprintf(stderr, "this=%s\n", newick_this);
     850        fprintf(stderr, "target=%s\n", newick_brot);
     851        fprintf(stderr, "prev=%s\n", newick_prev);
     852        fprintf(stderr, "old=%s\n", newick_old);
     853        fprintf(stderr, "new=%s\n", newick_new);
     854
     855        ap_assert(0);
     856    }
     857
     858    free(newick_new);
     859    free(newick_old);
     860    free(newick_prev);
     861    free(newick_brot);
     862    free(newick_this);
     863}
     864
    784865void AP_tree_nlen::unhash_sequence() {
    785866    /*! removes the parsimony sequence from an inner node
    786867     * (has no effect for leafs)
  • PARSIMONY/ap_tree_nlen.hxx

     
    145145    void swap_sons() OVERRIDE;
    146146    void swap_assymetric(AP_TREE_SIDE mode) OVERRIDE;
    147147    void moveNextTo(AP_tree_nlen *new_brother, AP_FLOAT rel_pos); // if unsure, use cantMoveNextTo to test if possible
     148private:
     149    void moveNextToOld(AP_tree_nlen *new_brother, AP_FLOAT rel_pos);
     150    void moveNextToNew(AP_tree_nlen *new_brother, AP_FLOAT rel_pos);
     151public:
    148152    void set_root() OVERRIDE;
    149153
    150154    // overload virtual methods from AP_tree:
  • PARSIMONY/PARS_main.cxx

     
    19211921    TEST_EXPECT_EQUAL(env.combines_performed(), 3);
    19221922
    19231923    TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_ADD,     "nucl-add-quick", PARSIMONY_ORG-23, env, true)); // test quick-add
    1924     TEST_EXPECT_EQUAL(env.combines_performed(), 591);
     1924    TEST_EXPECT_EQUAL(env.combines_performed(), 587);
    19251925
    1926     TEST_EXPECTATION(modifyingTopoResultsIn(MOD_ADD_NNI,       "nucl-add-NNI",   PARSIMONY_ORG-25, env, true)); // test add + NNI
    1927     TEST_EXPECT_EQUAL(env.combines_performed(), 776);
     1926    TEST_EXPECTATION(modifyingTopoResultsIn(MOD_ADD_NNI,       "nucl-add-NNI",   PARSIMONY_ORG-24, env, true)); // test add + NNI
     1927    TEST_EXPECT_EQUAL(env.combines_performed(), 781);
    19281928
    19291929    TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_ADD_CALC_LENS, "nucl-add-quick-cl", PARSIMONY_ORG-23, env, true)); // test quick-add + calc_branchlengths
    1930     TEST_EXPECT_EQUAL(env.combines_performed(), 727);
     1930    TEST_EXPECT_EQUAL(env.combines_performed(), 726);
    19311931
    1932     TEST_EXPECTATION(modifyingTopoResultsIn(MOD_ADD_NNI_CALC_LENS,   "nucl-add-NNI-cl",   PARSIMONY_ORG-25, env, true)); // test add + NNI + calc_branchlengths
    1933     TEST_EXPECT_EQUAL(env.combines_performed(), 914);
     1932    TEST_EXPECTATION(modifyingTopoResultsIn(MOD_ADD_NNI_CALC_LENS,   "nucl-add-NNI-cl",   PARSIMONY_ORG-24, env, true)); // test add + NNI + calc_branchlengths
     1933    TEST_EXPECT_EQUAL(env.combines_performed(), 922);
    19341934
    19351935    // test partial-add
    19361936    {
     
    19771977            }
    19781978
    19791979            TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_ADD, "nucl-addPartialAsFull-CorGlutP", PARSIMONY_ORG, env, false));
    1980             TEST_EXPECT_EQUAL(env.combines_performed(), 254);
     1980            TEST_EXPECT_EQUAL(env.combines_performed(), 256);
    19811981            TEST_EXPECT_EQUAL(is_partial(CorGlutP), 0); // check CorGlutP was added as full sequence
    19821982            TEST_EXPECTATION(addedAsBrotherOf("CorGlutP", "CorGluta", env)); // partial created from CorGluta gets inserted next to CorGluta
    19831983
     
    20912091    TEST_EXPECT_EQUAL(env.combines_performed(), 5);
    20922092
    20932093    TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_ADD,     "prot-add-quick", PARSIMONY_ORG,     env, true)); // test quick-add
    2094     TEST_EXPECT_EQUAL(env.combines_performed(), 306);
     2094    TEST_EXPECT_EQUAL(env.combines_performed(), 304);
    20952095
    20962096    TEST_EXPECTATION(modifyingTopoResultsIn(MOD_ADD_NNI,       "prot-add-NNI",   PARSIMONY_ORG,     env, true)); // test add + NNI
    2097     TEST_EXPECT_EQUAL(env.combines_performed(), 442);
     2097    TEST_EXPECT_EQUAL(env.combines_performed(), 449);
    20982098
    20992099    // test partial-add
    21002100    {
     
    21392139            }
    21402140
    21412141            TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_ADD, "prot-addPartialAsFull-MucRaceP", PARSIMONY_ORG+6, env, false));
    2142             TEST_EXPECT_EQUAL(env.combines_performed(), 175);
     2142            TEST_EXPECT_EQUAL(env.combines_performed(), 182);
    21432143            TEST_EXPECT_EQUAL(is_partial(MucRaceP), 0); // check MucRaceP was added as full sequence
    21442144            // TEST_EXPECTATION(addedAsBrotherOf("MucRaceP", "MucRacem", env)); // partial created from MucRacem gets inserted next to MucRacem
    21452145            // TEST_EXPECTATION(addedAsBrotherOf("MucRaceP", "AbdGlauc", env)); // partial created from MucRacem gets inserted next to MucRacem
     
    25492549        TEST_EXPECT_VALID_TREE(env.root_node());
    25502550    }
    25512551
    2552     TEST_EXPECT_EQUAL(env.combines_performed(), 4444); // @@@ distribute
     2552    TEST_EXPECT_EQUAL(env.combines_performed(), 4455); // @@@ distribute
    25532553}
    25542554
    25552555void TEST_node_edge_resources() {
  • UNIT_TESTER/run/pars/nucl-add-NNI-cl.tree.expected

     
    55    (
    66     (
    77      (
    8        CorGluta:0.329,
    9        CytAquat:0.333
    10       ):0.088,
    11       CloBifer:0.190
    12      ):0.050,
     8       (
     9        (
     10         CloTyro3:1.000,
     11         CloTyro4:0.027
     12        ):0.049,
     13        CloTyrob:0.013
     14       ):0.000,
     15       CloTyro2:0.013
     16      ):0.317,
     17      CloInnoc:0.384
     18     ):0.179,
     19     CloPaste:0.224
     20    ):0.016,
     21    CloCarni:0.171
     22   ):0.029,
     23   (
     24    (
    1325     (
    1426      CloButy2:0.000,
    1527      CloButyr:0.000
    16      ):0.058
    17     ):0.277,
     28     ):0.087,
     29     CloBifer:0.204
     30    ):0.066,
    1831    (
    19      CloCarni:0.118,
    20      CloPaste:0.224
    21     ):0.031
    22    ):0.044,
    23    (
    24     (
    25      (
    26       (
    27        CloTyro3:1.000,
    28        CloTyro4:0.027
    29       ):0.049,
    30       CloTyrob:0.013
    31      ):0.000,
    32      CloTyro2:0.013
    33     ):0.366,
    34     CloInnoc:0.370
    35    ):0.211
    36   ):0.165,
     32     CorGluta:0.274,
     33     CytAquat:0.333
     34    ):0.053
     35   ):0.274
     36  ):0.088,
    3737  (
    38    CorAquat:0.076,
     38   CorAquat:0.089,
    3939   CurCitre:0.086
    40   ):0.026
    41  ):0.076,
    42  CelBiazo:0.076);
    43  No newline at end of file
     40  ):0.052
     41 ):0.057,
     42 CelBiazo:0.057);
     43 No newline at end of file
  • UNIT_TESTER/run/pars/nucl-add-NNI.tree.expected

     
    55    (
    66     (
    77      (
    8        CorGluta:0.329,
    9        CytAquat:0.333
    10       ):0.088,
    11       CloBifer:0.190
    12      ):0.050,
     8       (
     9        (
     10         CloTyro3:1.000,
     11         CloTyro4:0.027
     12        ):0.049,
     13        CloTyrob:0.013
     14       ):0.000,
     15       CloTyro2:0.013
     16      ):0.317,
     17      CloInnoc:0.384
     18     ):0.179,
     19     CloPaste:0.224
     20    ):0.016,
     21    CloCarni:0.171
     22   ):0.029,
     23   (
     24    (
    1325     (
    1426      CloButy2:0.000,
    1527      CloButyr:0.000
    16      ):0.058
    17     ):0.277,
     28     ):0.087,
     29     CloBifer:0.204
     30    ):0.066,
    1831    (
    19      CloCarni:0.118,
    20      CloPaste:0.224
    21     ):0.031
    22    ):0.044,
    23    (
    24     (
    25      (
    26       (
    27        CloTyro3:1.000,
    28        CloTyro4:0.027
    29       ):0.049,
    30       CloTyrob:0.013
    31      ):0.000,
    32      CloTyro2:0.013
    33     ):0.366,
    34     CloInnoc:0.370
    35    ):0.211
    36   ):0.165,
     32     CorGluta:0.274,
     33     CytAquat:0.333
     34    ):0.053
     35   ):0.274
     36  ):0.088,
    3737  (
    38    CorAquat:0.076,
     38   CorAquat:0.089,
    3939   CurCitre:0.086
    40   ):0.029
    41  ):0.076,
    42  CelBiazo:0.076);
    43  No newline at end of file
     40  ):0.057
     41 ):0.057,
     42 CelBiazo:0.057);
     43 No newline at end of file