From 8dbc83f2fcaa7e9cb0ebc88fa9205c8c385a6e08 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Sat, 8 Mar 2014 03:26:18 +0000 Subject: [PATCH] inprogress --- .../evoinference/TestPhylogenyReconstruction.java | 12 +++---- .../src/org/forester/evoinference/distance/S.java | 38 +++++++++++++++++--- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index 7c78c5c..b525c29 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 { - final NeighborJoiningR nj = NeighborJoiningR.createInstance(); + // final NeighborJoiningR nj0 = NeighborJoiningR.createInstance(); // final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 ); // m0.setIdentifier( 0, "A" ); // m0.setIdentifier( 1, "B" ); @@ -2239,7 +2239,7 @@ public class TestPhylogenyReconstruction { // m0.setRow( "5 ", 1 ); // m0.setRow( "3 6 ", 2 ); // m0.setRow( "7.5 10.5 5.5", 3 ); - // final Phylogeny p0 = nj.execute( m0 ); + // final Phylogeny p0 = nj0.execute( m0 ); // p0.reRoot( p0.getNode( "D" ) ); // // Archaeopteryx.createApplication( p0 ); // if ( isUnequal( p0.getNode( "A" ).getDistanceToParent(), 1 ) ) { @@ -2272,8 +2272,8 @@ public class TestPhylogenyReconstruction { // m.setIdentifier( 3, "D" ); // m.setIdentifier( 4, "E" ); // m.setIdentifier( 5, "F" ); - // nj = NeighborJoiningR.createInstance(); - // final Phylogeny p1 = nj.execute( m ); + // final NeighborJoiningR nj1 = NeighborJoiningR.createInstance(); + // final Phylogeny p1 = nj1.execute( m ); // p1.reRoot( p1.getNode( "F" ) ); // Archaeopteryx.createApplication( p1 ); // if ( isUnequal( p1.getNode( "A" ).getDistanceToParent(), 1 ) ) { @@ -2328,9 +2328,9 @@ 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 ); - final NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 ); + final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 ); //nj = NeighborJoining.createInstance( true, 6 ); - final Phylogeny p2 = njr.execute( m ); + final Phylogeny p2 = nj2.execute( m ); // Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { diff --git a/forester/java/src/org/forester/evoinference/distance/S.java b/forester/java/src/org/forester/evoinference/distance/S.java index 6c84598..e1593f4 100644 --- a/forester/java/src/org/forester/evoinference/distance/S.java +++ b/forester/java/src/org/forester/evoinference/distance/S.java @@ -1,6 +1,7 @@ package org.forester.evoinference.distance; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -20,8 +21,32 @@ public class S { _data = new ArrayList>>(); } + @Override + public String toString() { + final DecimalFormat df = new DecimalFormat( "0.00" ); + final StringBuilder sb = new StringBuilder(); + for( int j = 1; j < size(); ++j ) { + for( final Entry> entry : getSentrySet( j ) ) { + final double key = entry.getKey(); + final SortedSet values = entry.getValue(); + sb.append( df.format( key ) + "->" ); + boolean first = true; + for( final Integer v : values ) { + if ( !first ) { + sb.append( "," ); + } + first = false; + sb.append( v ); + } + sb.append( " " ); + } + sb.append( "\n" ); + } + return sb.toString(); + } + void addPairing( final double key, final int value, final int j ) { - final SortedMap> m = _data.get( j ); + final SortedMap> m = getS( j ); addPairing( key, value, m ); } @@ -30,7 +55,7 @@ public class S { } Set>> getSentrySet( final int j ) { - return _data.get( j ).entrySet(); + return getS( j ).entrySet(); } void initialize( final BasicSymmetricalDistanceMatrix d ) { @@ -41,6 +66,7 @@ public class S { addPairing( d.getValues()[ i ][ j ], i, map ); } } + System.out.println( toString() ); } void removePairing( final double key, final int value, final int j ) { @@ -49,7 +75,7 @@ public class S { if ( x.size() == 1 ) { if ( !x.contains( value ) ) { //TODO remove me later - throw new IllegalStateException( "!x.contains( value )" ); + throw new IllegalStateException( "pairing " + key + " -> " + value + " does not exist" ); } m.remove( key ); } @@ -57,7 +83,7 @@ public class S { final boolean removed = x.remove( value ); if ( !removed ) { //TODO remove me later - throw new IllegalStateException( value + " not found" ); + throw new IllegalStateException( "pairing " + key + " -> " + value + " does not exist/was not removed" ); } } else { @@ -66,6 +92,10 @@ public class S { } } + int size() { + return _data.size(); + } + private static void addPairing( final double key, final int value, final SortedMap> m ) { if ( !m.containsKey( key ) ) { final TreeSet x = new TreeSet(); -- 1.7.10.2