From: cmzmasek@gmail.com Date: Sat, 8 Mar 2014 02:49:03 +0000 (+0000) Subject: inprogress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3dc1b0bab30025b34753df4325b60cb47ee5bdff;p=jalview.git inprogress --- diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index 44423b1..7c78c5c 100644 --- a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java +++ b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java @@ -2230,7 +2230,7 @@ public class TestPhylogenyReconstruction { private static boolean testNeighborJoiningR() { try { - NeighborJoiningR nj = NeighborJoiningR.createInstance(); + final NeighborJoiningR nj = NeighborJoiningR.createInstance(); // final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 ); // m0.setIdentifier( 0, "A" ); // m0.setIdentifier( 1, "B" ); @@ -2328,7 +2328,7 @@ public class TestPhylogenyReconstruction { 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 ); - NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 ); + final NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 ); //nj = NeighborJoining.createInstance( true, 6 ); final Phylogeny p2 = njr.execute( m ); // Archaeopteryx.createApplication( p2 ); diff --git a/forester/java/src/org/forester/evoinference/distance/S.java b/forester/java/src/org/forester/evoinference/distance/S.java index 1ea6f9b..6c84598 100644 --- a/forester/java/src/org/forester/evoinference/distance/S.java +++ b/forester/java/src/org/forester/evoinference/distance/S.java @@ -20,9 +20,9 @@ public class S { _data = new ArrayList>>(); } - void addValue( final double key, final int value, final int j ) { + void addPairing( final double key, final int value, final int j ) { final SortedMap> m = _data.get( j ); - addValue( key, value, m ); + addPairing( key, value, m ); } SortedMap> getS( final int j ) { @@ -38,18 +38,45 @@ public class S { final TreeMap> map = new TreeMap>(); _data.add( map ); for( int i = 0; i < j; ++i ) { - addValue( d.getValues()[ i ][ j ], i, map ); + addPairing( d.getValues()[ i ][ j ], i, map ); } } } - static void addValue( final double key, final int value, final SortedMap> m ) { + void removePairing( final double key, final int value, final int j ) { + final SortedMap> m = _data.get( j ); + final SortedSet x = m.get( key ); + if ( x.size() == 1 ) { + if ( !x.contains( value ) ) { + //TODO remove me later + throw new IllegalStateException( "!x.contains( value )" ); + } + m.remove( key ); + } + else if ( x.size() > 1 ) { + final boolean removed = x.remove( value ); + if ( !removed ) { + //TODO remove me later + throw new IllegalStateException( value + " not found" ); + } + } + else { + //TODO remove me later + throw new IllegalStateException( "empty" ); + } + } + + private static void addPairing( final double key, final int value, final SortedMap> m ) { if ( !m.containsKey( key ) ) { final TreeSet x = new TreeSet(); x.add( value ); m.put( key, x ); } else { + if ( m.get( key ).contains( value ) ) { + //TODO remove me later + throw new IllegalStateException( "pairing " + key + " -> " + value + " already exists" ); + } m.get( key ).add( value ); } }