From 25c731fbc8a993c2084d364e6c6c8ca9e662ad73 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Wed, 11 Oct 2017 21:12:19 +0100 Subject: [PATCH] More generic uses of DistanceMatrix instead of concrete implementations --- .../forester/evoinference/distance/NeighborJoining.java | 12 ++++++------ .../forester/evoinference/distance/NeighborJoiningR.java | 12 ++++++------ .../src/org/forester/evoinference/distance/Sarray.java | 3 ++- .../evoinference/matrix/distance/DistanceMatrix.java | 2 ++ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/forester/java/src/org/forester/evoinference/distance/NeighborJoining.java b/forester/java/src/org/forester/evoinference/distance/NeighborJoining.java index f63af04..9860c1a 100644 --- a/forester/java/src/org/forester/evoinference/distance/NeighborJoining.java +++ b/forester/java/src/org/forester/evoinference/distance/NeighborJoining.java @@ -29,7 +29,7 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; -import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; +import org.forester.evoinference.matrix.distance.DistanceMatrix; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; import org.forester.util.ForesterUtil; @@ -37,7 +37,7 @@ import org.forester.util.ForesterUtil; public final class NeighborJoining { private final static DecimalFormat DF = new DecimalFormat( "0.00000" ); - private BasicSymmetricalDistanceMatrix _d; + private DistanceMatrix _d; private double[][] _d_values; private final DecimalFormat _df; private PhylogenyNode[] _external_nodes; @@ -64,7 +64,7 @@ public final class NeighborJoining { _df.setRoundingMode( RoundingMode.HALF_UP ); } - public final Phylogeny execute( final BasicSymmetricalDistanceMatrix distance ) { + public final Phylogeny execute( final DistanceMatrix distance ) { reset( distance ); final Phylogeny phylogeny = new Phylogeny(); while ( _n > 2 ) { @@ -119,9 +119,9 @@ public final class NeighborJoining { return phylogeny; } - public final List execute( final List distances_list ) { + public final List execute( final List distances_list ) { final List pl = new ArrayList(); - for( final BasicSymmetricalDistanceMatrix distances : distances_list ) { + for( final DistanceMatrix distances : distances_list ) { pl.add( execute( distances ) ); } return pl; @@ -221,7 +221,7 @@ public final class NeighborJoining { // only the values in the lower triangle are used. // !matrix values will be changed! - private final void reset( final BasicSymmetricalDistanceMatrix distances ) { + private final void reset( final DistanceMatrix distances ) { _n = distances.getSize(); _d = distances; _r = new double[ _n ]; diff --git a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java index 209b93f..050885d 100644 --- a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java +++ b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; -import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; +import org.forester.evoinference.matrix.distance.DistanceMatrix; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; import org.forester.util.ForesterUtil; @@ -38,7 +38,7 @@ import org.forester.util.ForesterUtil; public final class NeighborJoiningR { private final static DecimalFormat DF = new DecimalFormat( "0.00000" ); - private BasicSymmetricalDistanceMatrix _d; + private DistanceMatrix _d; private double[][] _d_values; private final DecimalFormat _df; private PhylogenyNode[] _external_nodes; @@ -70,7 +70,7 @@ public final class NeighborJoiningR { _df.setRoundingMode( RoundingMode.HALF_UP ); } - public final Phylogeny execute( final BasicSymmetricalDistanceMatrix distance ) { + public final Phylogeny execute( final DistanceMatrix distance ) { reset( distance ); final Phylogeny phylogeny = new Phylogeny(); while ( _n > 2 ) { @@ -145,9 +145,9 @@ public final class NeighborJoiningR { return phylogeny; } - public final List execute( final List distances_list ) { + public final List execute( final List distances_list ) { final List pl = new ArrayList(); - for( final BasicSymmetricalDistanceMatrix distances : distances_list ) { + for( final DistanceMatrix distances : distances_list ) { pl.add( execute( distances ) ); } return pl; @@ -266,7 +266,7 @@ public final class NeighborJoiningR { // only the values in the lower triangle are used. // !matrix values will be changed! - private final void reset( final BasicSymmetricalDistanceMatrix distances ) { + private final void reset( final DistanceMatrix distances ) { _n = distances.getSize(); _d = distances; _r = new double[ _n ]; diff --git a/forester/java/src/org/forester/evoinference/distance/Sarray.java b/forester/java/src/org/forester/evoinference/distance/Sarray.java index 2e961b8..0232363 100644 --- a/forester/java/src/org/forester/evoinference/distance/Sarray.java +++ b/forester/java/src/org/forester/evoinference/distance/Sarray.java @@ -10,6 +10,7 @@ import java.util.SortedMap; import java.util.TreeMap; import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; +import org.forester.evoinference.matrix.distance.DistanceMatrix; public final class Sarray { @@ -37,7 +38,7 @@ public final class Sarray { return getS( j ).get( key ); } - final public void initialize( final BasicSymmetricalDistanceMatrix d ) { + final public void initialize( final DistanceMatrix d ) { for( int j = 0; j < d.getSize(); ++j ) { final TreeMap map = new TreeMap(); _data.add( map ); diff --git a/forester/java/src/org/forester/evoinference/matrix/distance/DistanceMatrix.java b/forester/java/src/org/forester/evoinference/matrix/distance/DistanceMatrix.java index 2eeaca9..0a332b2 100644 --- a/forester/java/src/org/forester/evoinference/matrix/distance/DistanceMatrix.java +++ b/forester/java/src/org/forester/evoinference/matrix/distance/DistanceMatrix.java @@ -44,4 +44,6 @@ public interface DistanceMatrix { public static enum Format { PHYLIP } + + public double[][] getValues(); } -- 1.7.10.2