inprogress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 5 Mar 2014 04:28:38 +0000 (04:28 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 5 Mar 2014 04:28:38 +0000 (04:28 +0000)
forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java
forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java
forester/java/src/org/forester/evoinference/distance/NeighborJoining.java
forester/java/src/org/forester/evoinference/distance/NeighborJoiningF.java
forester/java/src/org/forester/evoinference/distance/NeighborJoiningX.java [deleted file]
forester/java/src/org/forester/evoinference/matrix/distance/BasicSymmetricalDistanceMatrix.java
forester/java/src/org/forester/msa_compactor/MsaCompactor.java

index e6fe009..20da0c3 100644 (file)
@@ -34,7 +34,7 @@ import java.util.List;
 import javax.swing.JOptionPane;
 
 import org.forester.archaeopteryx.MainFrameApplication;
-import org.forester.evoinference.distance.NeighborJoining;
+import org.forester.evoinference.distance.NeighborJoiningF;
 import org.forester.evoinference.distance.PairwiseDistanceCalculator;
 import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
 import org.forester.evoinference.tools.BootstrapResampler;
@@ -142,7 +142,7 @@ public class PhylogeneticInferrer extends RunnableProcess {
                 e.printStackTrace();
             }
         }
-        final NeighborJoining nj = NeighborJoining.createInstance();
+        final NeighborJoiningF nj = NeighborJoiningF.createInstance( false, 5 );
         final Phylogeny phy = nj.execute( m );
         PhylogenyMethods.extractFastaInformation( phy );
         return phy;
index 98880ac..39e1a20 100644 (file)
@@ -35,7 +35,6 @@ import java.util.List;
 
 import org.forester.evoinference.distance.NeighborJoining;
 import org.forester.evoinference.distance.NeighborJoiningF;
-import org.forester.evoinference.distance.NeighborJoiningX;
 import org.forester.evoinference.distance.PairwiseDistanceCalculator;
 import org.forester.evoinference.matrix.character.BasicCharacterStateMatrix;
 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
@@ -128,27 +127,6 @@ public class TestPhylogenyReconstruction {
         return true;
     }
 
-    private static boolean testDistanceCalculationMethods( final File test_dir ) {
-        try {
-            final Msa msa0 = GeneralMsaParser.parse( new FileInputStream( test_dir + ForesterUtil.FILE_SEPARATOR
-                    + "bcl.aln" ) );
-            final BasicSymmetricalDistanceMatrix pwd0 = PairwiseDistanceCalculator.calcKimuraDistances( msa0 );
-            if ( pwd0.getSize() != 120 ) {
-                return false;
-            }
-            for( int i = 0; i < pwd0.getSize(); ++i ) {
-                if ( !isEqual( pwd0.getValue( i, i ), 0.0 ) ) {
-                    return false;
-                }
-            }
-        }
-        catch ( final Exception e ) {
-            e.printStackTrace( System.out );
-            return false;
-        }
-        return true;
-    }
-
     private static boolean testBasicCharacterStateMatrix() {
         try {
             final CharacterStateMatrix<String> matrix_0 = new BasicCharacterStateMatrix<String>( 4, 8 );
@@ -424,6 +402,27 @@ public class TestPhylogenyReconstruction {
         return true;
     }
 
+    private static boolean testDistanceCalculationMethods( final File test_dir ) {
+        try {
+            final Msa msa0 = GeneralMsaParser.parse( new FileInputStream( test_dir + ForesterUtil.FILE_SEPARATOR
+                    + "bcl.aln" ) );
+            final BasicSymmetricalDistanceMatrix pwd0 = PairwiseDistanceCalculator.calcKimuraDistances( msa0 );
+            if ( pwd0.getSize() != 120 ) {
+                return false;
+            }
+            for( int i = 0; i < pwd0.getSize(); ++i ) {
+                if ( !isEqual( pwd0.getValue( i, i ), 0.0 ) ) {
+                    return false;
+                }
+            }
+        }
+        catch ( final Exception e ) {
+            e.printStackTrace( System.out );
+            return false;
+        }
+        return true;
+    }
+
     private static boolean testDolloParsimony() {
         try {
             final BinaryStates PRESENT = BinaryStates.PRESENT;
@@ -1923,36 +1922,6 @@ public class TestPhylogenyReconstruction {
 
     private static boolean testNeighborJoining() {
         try {
-            final NeighborJoiningF njf = NeighborJoiningF.createInstance();
-            final BasicSymmetricalDistanceMatrix m0f = new BasicSymmetricalDistanceMatrix( 4 );
-            m0f.setIdentifier( 0, "A" );
-            m0f.setIdentifier( 1, "B" );
-            m0f.setIdentifier( 2, "C" );
-            m0f.setIdentifier( 3, "D" );
-            m0f.setRow( "5 ", 1 );
-            m0f.setRow( "3 6 ", 2 );
-            m0f.setRow( "7.5 10.5 5.5", 3 );
-            final Phylogeny p0f = njf.execute( m0f );
-            p0f.reRoot( p0f.getNode( "D" ) );
-            if ( isUnequal( p0f.getNode( "A" ).getDistanceToParent(), 1 ) ) {
-                return false;
-            }
-            if ( isUnequal( p0f.getNode( "B" ).getDistanceToParent(), 4 ) ) {
-                return false;
-            }
-            if ( isUnequal( p0f.getNode( "C" ).getDistanceToParent(), 0.5 ) ) {
-                return false;
-            }
-            if ( isUnequal( p0f.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
-                return false;
-            }
-            if ( isUnequal( p0f.getNode( "A" ).getParent().getDistanceToParent(), 1.5 ) ) {
-                return false;
-            }
-            if ( isUnequal( p0f.getNode( "A" ).getParent().getParent().getDistanceToParent(), 2.5 ) ) {
-                return false;
-            }
-            //
             NeighborJoining nj = NeighborJoining.createInstance();
             final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 );
             m0.setIdentifier( 0, "A" );
@@ -2150,9 +2119,96 @@ public class TestPhylogenyReconstruction {
             if ( isUnequal( p3.getNode( "A" ).getParent().getParent().getDistanceToParent(), 0.05 ) ) {
                 return false;
             }
-            //if ( TIME ) {
-            //    timeNeighborJoining();
-            //}
+            //
+            NeighborJoiningF njf = NeighborJoiningF.createInstance();
+            final BasicSymmetricalDistanceMatrix m0f = new BasicSymmetricalDistanceMatrix( 4 );
+            m0f.setIdentifier( 0, "A" );
+            m0f.setIdentifier( 1, "B" );
+            m0f.setIdentifier( 2, "C" );
+            m0f.setIdentifier( 3, "D" );
+            m0f.setRow( "5 ", 1 );
+            m0f.setRow( "3 6 ", 2 );
+            m0f.setRow( "7.5 10.5 5.5", 3 );
+            final Phylogeny p0f = njf.execute( m0f );
+            p0f.reRoot( p0f.getNode( "D" ) );
+            if ( isUnequal( p0f.getNode( "A" ).getDistanceToParent(), 1 ) ) {
+                return false;
+            }
+            if ( isUnequal( p0f.getNode( "B" ).getDistanceToParent(), 4 ) ) {
+                return false;
+            }
+            if ( isUnequal( p0f.getNode( "C" ).getDistanceToParent(), 0.5 ) ) {
+                return false;
+            }
+            if ( isUnequal( p0f.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
+                return false;
+            }
+            if ( isUnequal( p0f.getNode( "A" ).getParent().getDistanceToParent(), 1.5 ) ) {
+                return false;
+            }
+            if ( isUnequal( p0f.getNode( "A" ).getParent().getParent().getDistanceToParent(), 2.5 ) ) {
+                return false;
+            }
+            //
+            m = new BasicSymmetricalDistanceMatrix( 7 );
+            m.setIdentifier( 0, "Bovine" );
+            m.setIdentifier( 1, "Mouse" );
+            m.setIdentifier( 2, "Gibbon" );
+            m.setIdentifier( 3, "Orang" );
+            m.setIdentifier( 4, "Gorilla" );
+            m.setIdentifier( 5, "Chimp" );
+            m.setIdentifier( 6, "Human" );
+            m.setRow( "0.00000 1.68660 1.71980 1.66060 1.52430 1.60430 1.59050", 0 );
+            m.setRow( "1.68660 0.00000 1.52320 1.48410 1.44650 1.43890 1.46290", 1 );
+            m.setRow( "1.71980 1.52320 0.00000 0.71150 0.59580 0.61790 0.55830", 2 );
+            m.setRow( "1.66060 1.48410 0.71150 0.00000 0.46310 0.50610 0.47100", 3 );
+            m.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 );
+            m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 );
+            m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 );
+            njf = NeighborJoiningF.createInstance( false, 5 );
+            final Phylogeny p2f = njf.execute( m );
+            p2f.reRoot( p2f.getNode( "Bovine" ) );
+            if ( isUnequal( p2f.getNode( "Chimp" ).getDistanceToParent(), 0.15168 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Human" ).getDistanceToParent(), 0.11752 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Gorilla" ).getDistanceToParent(), 0.15393 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Orang" ).getDistanceToParent(), 0.28469 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Gibbon" ).getDistanceToParent(), 0.35793 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Mouse" ).getDistanceToParent(), 0.76891 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Bovine" ).getDistanceToParent(), 0.458845 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getDistanceToParent(), 0.03982 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Human" ).getParent().getDistanceToParent(), 0.03982 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getDistanceToParent(), 0.02696 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getParent().getDistanceToParent(), 0.04648 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getParent().getParent()
+                    .getDistanceToParent(), 0.42027 ) ) {
+                return false;
+            }
+            if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getParent()
+                    .getDistanceToParent(), 0.458845 ) ) {
+                return false;
+            }
         }
         catch ( final Exception e ) {
             e.printStackTrace( System.out );
@@ -2523,43 +2579,22 @@ public class TestPhylogenyReconstruction {
 
     private static void timeNeighborJoining() {
         final NeighborJoiningF njf = NeighborJoiningF.createInstance();
-        for( int n = 3; n <= 10; ++n ) {
+        for( int n = 3; n <= 8; ++n ) {
             final int x = ( int ) Math.pow( 2, n );
             final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
             mt.randomize( new Date().getTime() );
-            //  for( int i = 0; i < mt.getSize(); i++ ) {
-            //      mt.setIdentifier( i, i + "i" );
-            //  }
-            //  System.out.println( mt.toStringBuffer( Format.PHYLIP ) );
             final long start_time = new Date().getTime();
             njf.execute( mt );
             System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );
         }
         final NeighborJoining nj = NeighborJoining.createInstance();
-        for( int n = 3; n <= 10; ++n ) {
+        for( int n = 3; n <= 8; ++n ) {
             final int x = ( int ) Math.pow( 2, n );
             final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
             mt.randomize( new Date().getTime() );
-            //  for( int i = 0; i < mt.getSize(); i++ ) {
-            //      mt.setIdentifier( i, i + "i" );
-            //  }
-            //  System.out.println( mt.toStringBuffer( Format.PHYLIP ) );
             final long start_time = new Date().getTime();
             nj.execute( mt );
             System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );
         }
-        final NeighborJoiningX njx = NeighborJoiningX.createInstance();
-        for( int n = 3; n <= 10; ++n ) {
-            final int x = ( int ) Math.pow( 2, n );
-            final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
-            mt.randomize( new Date().getTime() );
-            //  for( int i = 0; i < mt.getSize(); i++ ) {
-            //      mt.setIdentifier( i, i + "i" );
-            //  }
-            //  System.out.println( mt.toStringBuffer( Format.PHYLIP ) );
-            final long start_time = new Date().getTime();
-            njx.execute( mt );
-            System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );
-        }
     }
 }
index e3371c0..c0792a4 100644 (file)
@@ -201,30 +201,6 @@ public final class NeighborJoining {
         }
     }
 
-    private final void printD() {
-        System.out.println( "D:" );
-        for( final double[] _d_value : _d_values ) {
-            for( int j = 0; j < _d_values.length; j++ ) {
-                System.out.print( _d_value[ j ] );
-                System.out.print( " " );
-            }
-            System.out.println();
-        }
-        System.out.println();
-    }
-
-    private final void printM() {
-        System.out.println( "M:" );
-        for( final double[] _m_value : _m_values ) {
-            for( int j = 0; j < _m_values.length; j++ ) {
-                System.out.print( _m_value[ j ] );
-                System.out.print( " " );
-            }
-            System.out.println();
-        }
-        System.out.println();
-    }
-
     private final void printProgress( final int otu1, final int otu2 ) {
         final PhylogenyNode n1 = getExternalPhylogenyNode( otu1 );
         final PhylogenyNode n2 = getExternalPhylogenyNode( otu2 );
index a098ff9..dd984ae 100644 (file)
@@ -209,7 +209,6 @@ public final class NeighborJoiningF {
     }
 
     // only the values in the lower triangle are used.
-    // !matrix values will be changed!
     private final void reset( final BasicSymmetricalDistanceMatrix distances ) {
         _n = distances.getSize();
         _d = distances;
diff --git a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningX.java b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningX.java
deleted file mode 100644 (file)
index 8c4cc40..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-// $Id:
-// FORESTER -- software libraries and applications
-// for evolutionary biology research and applications.
-//
-// Copyright (C) 2008-2009 Christian M. Zmasek
-// Copyright (C) 2008-2009 Burnham Institute for Medical Research
-// All rights reserved
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-//
-// Contact: phylosoft @ gmail . com
-// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
-
-package org.forester.evoinference.distance;
-
-import java.math.RoundingMode;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
-import org.forester.phylogeny.Phylogeny;
-import org.forester.phylogeny.PhylogenyNode;
-import org.forester.util.ForesterUtil;
-
-public final class NeighborJoiningX {
-
-    private BasicSymmetricalDistanceMatrix _d;
-    private double[][]                     _d_values;
-    private final DecimalFormat            _df;
-    private PhylogenyNode[]                _external_nodes;
-    private double[][]                     _m_values;
-    private int[]                          _mappings;
-    private int                            _n;
-    private double[]                       _r;
-    private final boolean                  _verbose;
-
-    private NeighborJoiningX() {
-        _verbose = false;
-        _df = null;
-    }
-
-    private NeighborJoiningX( final boolean verbose, final int maximum_fraction_digits_for_distances ) {
-        if ( ( maximum_fraction_digits_for_distances < 1 ) || ( maximum_fraction_digits_for_distances > 9 ) ) {
-            throw new IllegalArgumentException( "maximum fraction digits for distances is out of range: "
-                    + maximum_fraction_digits_for_distances );
-        }
-        _verbose = verbose;
-        _df = new DecimalFormat();
-        _df.setMaximumFractionDigits( maximum_fraction_digits_for_distances );
-        _df.setRoundingMode( RoundingMode.HALF_UP );
-    }
-
-    public final Phylogeny execute( final BasicSymmetricalDistanceMatrix distance ) {
-        reset( distance );
-        final Phylogeny phylogeny = new Phylogeny();
-        while ( _n > 2 ) {
-            updateM();
-            // Calculates the minimal distance.
-            // If more than one minimal distances, always the first found is used
-            // could randomize this, so that any would be returned in a randomized fashion...
-            double minimum = _m_values[ 0 ][ 1 ];
-            int otu1 = 0;
-            int otu2 = 1;
-            for( int j = 1; j < _n; ++j ) {
-                for( int i = 0; i < j; ++i ) {
-                    if ( _m_values[ i ][ j ] < minimum ) {
-                        minimum = _m_values[ i ][ j ];
-                        otu1 = i;
-                        otu2 = j;
-                    }
-                }
-            }
-            // It is a condition that otu1 < otu2.
-            final PhylogenyNode node = new PhylogenyNode();
-            final double d = getValueFromD( otu1, otu2 );
-            final double d1 = ( d / 2 ) + ( ( _r[ otu1 ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) );
-            final double d2 = d - d1;
-            if ( _df == null ) {
-                getExternalPhylogenyNode( otu1 ).setDistanceToParent( d1 );
-                getExternalPhylogenyNode( otu2 ).setDistanceToParent( d2 );
-            }
-            else {
-                // yes, yes, slow but only grows with n (and not n^2 or worse)...
-                getExternalPhylogenyNode( otu1 ).setDistanceToParent( Double.parseDouble( _df.format( d1 ) ) );
-                getExternalPhylogenyNode( otu2 ).setDistanceToParent( Double.parseDouble( _df.format( d2 ) ) );
-            }
-            node.addAsChild( getExternalPhylogenyNode( otu1 ) );
-            node.addAsChild( getExternalPhylogenyNode( otu2 ) );
-            if ( _verbose ) {
-                printProgress( otu1, otu2 );
-            }
-            calculateDistancesFromNewNode( otu1, otu2, d );
-            _external_nodes[ _mappings[ otu1 ] ] = node;
-            updateMappings( otu2 );
-            --_n;
-        }
-        final double d = getValueFromD( 0, 1 ) / 2;
-        if ( _df == null ) {
-            getExternalPhylogenyNode( 0 ).setDistanceToParent( d );
-            getExternalPhylogenyNode( 1 ).setDistanceToParent( d );
-        }
-        else {
-            final double dd = Double.parseDouble( _df.format( d ) );
-            getExternalPhylogenyNode( 0 ).setDistanceToParent( dd );
-            getExternalPhylogenyNode( 1 ).setDistanceToParent( dd );
-        }
-        final PhylogenyNode root = new PhylogenyNode();
-        root.addAsChild( getExternalPhylogenyNode( 0 ) );
-        root.addAsChild( getExternalPhylogenyNode( 1 ) );
-        if ( _verbose ) {
-            printProgress( 0, 1 );
-        }
-        phylogeny.setRoot( root );
-        phylogeny.setRooted( false );
-        return phylogeny;
-    }
-
-    public final List<Phylogeny> execute( final List<BasicSymmetricalDistanceMatrix> distances_list ) {
-        final List<Phylogeny> pl = new ArrayList<Phylogeny>();
-        for( final BasicSymmetricalDistanceMatrix distances : distances_list ) {
-            pl.add( execute( distances ) );
-        }
-        return pl;
-    }
-
-    private final void calculateDistancesFromNewNode( final int otu1, final int otu2, final double d ) {
-        for( int i = 0; i < _n; ++i ) {
-            if ( ( i == otu1 ) || ( i == otu2 ) ) {
-                continue;
-            }
-            if ( otu1 < i ) {
-                _d_values[ _mappings[ otu1 ] ][ _mappings[ i ] ] = ( getValueFromD( otu1, i ) + getValueFromD( i, otu2 ) - d ) / 2;
-            }
-            else {
-                _d_values[ _mappings[ i ] ][ _mappings[ otu1 ] ] = ( getValueFromD( otu1, i ) + getValueFromD( i, otu2 ) - d ) / 2;
-            }
-        }
-    }
-
-    private final void calculateNetDivergences() {
-        double d;
-        for( int i = 0; i < _n; ++i ) {
-            d = 0;
-            for( int n = 0; n < _n; ++n ) {
-                if ( i != n ) {
-                    d += getValueFromD( i, n );
-                }
-            }
-            _r[ i ] = d;
-        }
-    }
-
-    private final PhylogenyNode getExternalPhylogenyNode( final int i ) {
-        return _external_nodes[ _mappings[ i ] ];
-    }
-
-    private final double getValueFromD( final int otu1, final int otu2 ) {
-        if ( otu1 > otu2 ) {
-            return _d_values[ _mappings[ otu2 ] ][ _mappings[ otu1 ] ];
-        }
-        return _d_values[ _mappings[ otu1 ] ][ _mappings[ otu2 ] ];
-    }
-
-    private final void initExternalNodes() {
-        _external_nodes = new PhylogenyNode[ _n ];
-        String id;
-        for( int i = 0; i < _n; ++i ) {
-            _external_nodes[ i ] = new PhylogenyNode();
-            id = _d.getIdentifier( i );
-            if ( id != null ) {
-                _external_nodes[ i ].setName( id );
-            }
-            else {
-                _external_nodes[ i ].setName( "" + i );
-            }
-            _mappings[ i ] = i;
-        }
-    }
-
-    private final void printProgress( final int otu1, final int otu2 ) {
-        final PhylogenyNode n1 = getExternalPhylogenyNode( otu1 );
-        final PhylogenyNode n2 = getExternalPhylogenyNode( otu2 );
-        System.out.println( "Node " + ( ForesterUtil.isEmpty( n1.getName() ) ? n1.getId() : n1.getName() ) + " joins "
-                + ( ForesterUtil.isEmpty( n2.getName() ) ? n2.getId() : n2.getName() ) );
-    }
-
-    // only the values in the lower triangle are used.
-    // !matrix values will be changed!
-    private final void reset( final BasicSymmetricalDistanceMatrix distances ) {
-        _n = distances.getSize();
-        _d = distances;
-        _r = new double[ _n ];
-        _mappings = new int[ _n ];
-        _d_values = _d.getValues();
-        _m_values = new double[ _n ][ _n ];
-        initExternalNodes();
-    }
-
-    private final void updateM() {
-        calculateNetDivergences();
-        for( int j = 1; j < _n; ++j ) {
-            for( int i = 0; i < j; ++i ) {
-                _m_values[ i ][ j ] = getValueFromD( i, j ) - ( ( _r[ i ] + _r[ j ] ) / ( _n - 2 ) );
-            }
-        }
-    }
-
-    // otu2 will, in effect, be "deleted" from the matrix.
-    private final void updateMappings( final int otu2 ) {
-        for( int i = otu2; i < ( _mappings.length - 1 ); ++i ) {
-            _mappings[ i ] = _mappings[ i + 1 ];
-        }
-    }
-
-    public final static NeighborJoiningX createInstance() {
-        return new NeighborJoiningX();
-    }
-
-    public final static NeighborJoiningX createInstance( final boolean verbose,
-                                                         final int maximum_fraction_digits_for_distances ) {
-        return new NeighborJoiningX( verbose, maximum_fraction_digits_for_distances );
-    }
-}
index fdf2ec4..14d7e97 100644 (file)
@@ -39,18 +39,14 @@ public final class BasicSymmetricalDistanceMatrix implements DistanceMatrix {
 
     // NumberFormat                      nf1              = NumberFormat.getInstance();
     private final static NumberFormat PHYLIP_FORMATTER = new DecimalFormat( "0.000000" );
-    final double[][]                  _values;
     final String[]                    _identifiers;
+    final double[][]                  _values;
 
     public BasicSymmetricalDistanceMatrix( final int size ) {
         _values = new double[ size ][ size ];
         _identifiers = new String[ size ];
     }
 
-    public final double[][] getValues() {
-        return _values;
-    }
-
     @Override
     public final String getIdentifier( final int i ) {
         return _identifiers[ i ];
@@ -85,6 +81,10 @@ public final class BasicSymmetricalDistanceMatrix implements DistanceMatrix {
         return _values[ col ][ row ];
     }
 
+    public final double[][] getValues() {
+        return _values;
+    }
+
     public final void randomize( final long seed ) {
         final java.util.Random r = new java.util.Random( seed );
         for( int j = 0; j < getSize(); ++j ) {
@@ -122,6 +122,21 @@ public final class BasicSymmetricalDistanceMatrix implements DistanceMatrix {
         _values[ col ][ row ] = d;
     }
 
+    @Override
+    public final String toString() {
+        return toPhylip().toString();
+    }
+
+    @Override
+    public final StringBuffer toStringBuffer( final Format format ) {
+        switch ( format ) {
+            case PHYLIP:
+                return toPhylip();
+            default:
+                throw new IllegalArgumentException( "Unknown format:" + format );
+        }
+    }
+
     public final void write( final Writer w ) throws IOException {
         w.write( "    " );
         w.write( getSize() + "" );
@@ -179,19 +194,4 @@ public final class BasicSymmetricalDistanceMatrix implements DistanceMatrix {
         }
         return sb;
     }
-
-    @Override
-    public final String toString() {
-        return toPhylip().toString();
-    }
-
-    @Override
-    public final StringBuffer toStringBuffer( final Format format ) {
-        switch ( format ) {
-            case PHYLIP:
-                return toPhylip();
-            default:
-                throw new IllegalArgumentException( "Unknown format:" + format );
-        }
-    }
 }
index 35d524c..fb0d0fe 100644 (file)
@@ -14,7 +14,7 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.forester.archaeopteryx.Archaeopteryx;
-import org.forester.evoinference.distance.NeighborJoining;
+import org.forester.evoinference.distance.NeighborJoiningF;
 import org.forester.evoinference.distance.PairwiseDistanceCalculator;
 import org.forester.evoinference.distance.PairwiseDistanceCalculator.PWD_DISTANCE_METHOD;
 import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
@@ -258,7 +258,7 @@ public class MsaCompactor {
                 e.printStackTrace();
             }
         }
-        final NeighborJoining nj = NeighborJoining.createInstance();
+        final NeighborJoiningF nj = NeighborJoiningF.createInstance( false, 5 );
         final Phylogeny phy = nj.execute( m );
         return phy;
     }