JWS-112 Bumping version of Mafft to version 7.310.
[jabaws.git] / binaries / src / mafft / core / treeOperation.c
index 2738fc1..5413daa 100644 (file)
@@ -223,7 +223,7 @@ void treeCnv( Node *stopol, int locnseq, int ***topol, double **len, double **bw
 
        if     ( stopol[locnseq-2].children[0] == &stopol[locnseq-3] ) i = 1;
        else if( stopol[locnseq-2].children[1] == &stopol[locnseq-3] ) i = 0;
-       else ErrorExit( "?\n" );
+       else ErrorExit( "ERROR in stopol ?\n" );
 
        stopol[locnseq-3].length[2] = len[locnseq-2][0] + len[locnseq-2][1];
        stopol[locnseq-3].weightptr[2] = &bw[locnseq-2][0];
@@ -475,12 +475,96 @@ void branchWeightToPairWeight( int locnseq, int ***topol, double **pw, double **
        }
 }
 
-void weightFromABranch_rec( double *result, Node *ob, Node *op )
+static void distFromABranch_rec( double *result, Node *ob, Node *op )
 {
        int i, n, count;
        int dir_ch[3], dir_pa;
 
 #if DEBUG
+       fprintf( stderr, "In distFromABranch_rec, ob = %d\n", ob - stopol_g );
+#endif
+       if( isLeaf( *ob ) ) return;
+       for( i=0, count=0; i<3; i++ ) 
+       {
+               if( ob->children[i] != op ) dir_ch[count++] = i;
+               else dir_pa = i;
+       }
+       if( count != 2 ) 
+       {
+#if DEBUG
+               fprintf( stderr, "Node No.%d has no child like No.%d \n", ob-stopol_g, op-stopol_g );
+#endif
+               ErrorExit( "Incorrect call of distFromABranch_rec" );
+       }
+       for( i=0; (n=ob->members[dir_ch[0]][i])!=-1; i++ ) 
+       {
+               result[n] += ob->length[dir_ch[0]];
+       }
+       distFromABranch_rec( result, ob->children[dir_ch[0]], ob );
+
+       for( i=0; (n=ob->members[dir_ch[1]][i])!=-1; i++ ) 
+       {
+               result[n] += ob->length[dir_ch[1]];
+       }
+       distFromABranch_rec( result, ob->children[dir_ch[1]], ob );
+}
+
+void distFromABranch( int nseq, double *result, Node *stopol, int ***topol, double **len, int step, int LorR )
+{
+       Node *topNode, *btmNode;
+       int i;
+
+       if( nseq == 2 )
+       {
+               result[0] = len[0][0];
+               result[1] = len[0][1];
+//             reporterr( "result[0] = %f\n", result[0] );
+//             reporterr( "result[1] = %f\n", result[1] );
+               return;
+       }
+
+       if( step == nseq - 2 )
+       {
+               topNode = stopol[nseq-2].children[0];
+               btmNode = stopol + nseq-3;
+#if DEBUG
+               fprintf( stderr, "Now step == nseq-3, topNode = %d, btmNode = %d\n", topNode - stopol_g, btmNode-stopol_g );
+#endif
+       }
+               
+       else
+       {
+               for( i=0; i<3; i++ ) 
+               {
+                       if( stopol[step].members[i][0] == topol[step][LorR][0] )
+                       break;
+               }
+               if( i== 3 ) ErrorExit( "Incorrect call of distFromABranch." );
+               btmNode = stopol[step].children[i];
+               topNode = stopol+step;
+       }
+
+       for( i=0; i<nseq; i++ ) result[i] = 0.0;
+       distFromABranch_rec( result, btmNode, topNode ); 
+       distFromABranch_rec( result, topNode, btmNode ); 
+#if 0
+       for( i=0; i<nseq; i++ )
+               fprintf( stdout, "w[%d] = %30.20f\n", i, result[i] );
+#endif
+//     fprintf( stderr, "new weight!\n" );
+//     for( i=0; i<nseq; i++ )
+//             result[i] *= result[i];
+
+
+}
+
+static void weightFromABranch_rec( double *result, Node *ob, Node *op )
+{
+       int i, n, count;
+       int dir_ch[3], dir_pa;
+
+
+#if DEBUG
        fprintf( stderr, "In weightFromABranch_rec, ob = %d\n", ob - stopol_g );
 #endif
        if( isLeaf( *ob ) ) return;
@@ -536,7 +620,7 @@ void weightFromABranch( int nseq, double *result, Node *stopol, int ***topol, in
        weightFromABranch_rec( result, topNode, btmNode ); 
 #if 0
        for( i=0; i<nseq; i++ )
-               fprintf( stdout, "w[%d] = %f\n", i, result[i] );
+               fprintf( stdout, "w[%d] = %30.20f\n", i, result[i] );
 #endif
 //     fprintf( stderr, "new weight!\n" );
 //     for( i=0; i<nseq; i++ )