rio
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Sun, 25 Nov 2012 05:02:34 +0000 (05:02 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Sun, 25 Nov 2012 05:02:34 +0000 (05:02 +0000)
forester/java/src/org/forester/datastructures/IntMatrix.java
forester/java/src/org/forester/io/parsers/nhx/NHXParser.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java
forester/java/src/org/forester/sdi/RIO.java
forester/java/src/org/forester/test/Test.java

index f23c5e9..e8707b1 100644 (file)
@@ -31,6 +31,10 @@ public final class IntMatrix {
     final public void set( final int x, final int y, final int value ) {
         _data[ x ][ y ] = value;
     }
+    
+    final public void inreaseByOne( final int x, final int y ) {
+        _data[ x ][ y ]++;
+    }
 
     final public String getLabel( final int x ) {
         return _labels[ x ];
index c1cfa40..d078f83 100644 (file)
@@ -616,7 +616,7 @@ public final class NHXParser implements PhylogenyParser {
             return Double.valueOf( str ).doubleValue();
         }
         catch ( final NumberFormatException ex ) {
-            throw new NHXFormatException( "error in NH/NHX formatted data: failed to parse number from :" + "\"" + str
+            throw new NHXFormatException( "error in NH/NHX formatted data: failed to parse number from " + "\"" + str
                     + "\"" );
         }
     }
index e64d72a..3c6b3cd 100644 (file)
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -248,6 +249,15 @@ public class PhylogenyMethods {
         return nodes;
     }
 
+    public static final HashMap<String, PhylogenyNode> createNameToExtNodeMap( final Phylogeny phy ) {
+        final HashMap<String, PhylogenyNode> nodes = new HashMap<String, PhylogenyNode>();
+        for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
+            final PhylogenyNode n = iter.next();
+            nodes.put( n.getName(), n );
+        }
+        return nodes;
+    }
+
     public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException {
         final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
         final Phylogeny[] trees = factory.create( file, parser );
index da0ba6e..ff5e3e9 100644 (file)
@@ -77,7 +77,7 @@ public final class RIO {
         reset();
     }
 
-    public IntMatrix calculateOrthologTable( final Phylogeny[] gene_trees ) {
+    public static IntMatrix calculateOrthologTable( final Phylogeny[] gene_trees ) {
         final List<String> labels = new ArrayList<String>();
         final Set<String> labels_set = new HashSet<String>();
         String label;
@@ -107,13 +107,12 @@ public final class RIO {
             System.out.println( counter );
             counter++;
             PhylogenyMethods.preOrderReId( gt );
+            final HashMap<String, PhylogenyNode> map = PhylogenyMethods.createNameToExtNodeMap( gt );
             for( int x = 0; x < m.size(); ++x ) {
-                final PhylogenyNode nx = gt.getNode( m.getLabel( x ) );
+                final PhylogenyNode nx = map.get( m.getLabel( x ) );
                 for( int y = 0; y < m.size(); ++y ) {
-                    final PhylogenyNode ny = gt.getNode( m.getLabel( y ) );
-                    if ( !PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( nx, ny ).isDuplication() ) {
-                        m.set( x, y, m.get( x, y ) + 1 );
-                        //System.out.println( x + " " + y );
+                    if ( !PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( nx, map.get( m.getLabel( y ) ) ).isDuplication() ) {
+                        m.inreaseByOne( x, y );
                     }
                 }
             }
index 4592bdf..f20c0b3 100644 (file)
@@ -38,6 +38,7 @@ import java.util.Locale;
 import java.util.Set;
 
 import org.forester.application.support_transfer;
+import org.forester.datastructures.IntMatrix;
 import org.forester.development.DevelopmentTools;
 import org.forester.evoinference.TestPhylogenyReconstruction;
 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
@@ -63,6 +64,7 @@ import org.forester.pccx.TestPccx;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyBranch;
 import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.TAXONOMY_EXTRACTION;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.BinaryCharacters;
@@ -84,6 +86,8 @@ import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
 import org.forester.phylogeny.factories.PhylogenyFactory;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.protein.Protein;
+import org.forester.sdi.GSDI;
+import org.forester.sdi.RIO;
 import org.forester.sdi.SDI;
 import org.forester.sdi.SDIR;
 import org.forester.sdi.SDIse;
@@ -522,6 +526,15 @@ public final class Test {
             System.out.println( "failed." );
             failed++;
         }
+        System.out.print( "Ortholog table: " );
+        if ( Test.testOrthologTable() ) {
+            System.out.println( "OK." );
+            succeeded++;
+        }
+        else {
+            System.out.println( "failed." );
+            failed++;
+        }
         System.out.print( "Descriptive statistics: " );
         if ( Test.testDescriptiveStatistics() ) {
             System.out.println( "OK." );
@@ -2027,7 +2040,6 @@ public final class Test {
                     .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
                              new NHXParser() );
             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
-            // Archaeopteryx.createApplication( t_b ); //TODO use me again me working here...
             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
                 return false;
             }
@@ -6933,6 +6945,28 @@ public final class Test {
         return true;
     }
 
+    private static boolean testOrthologTable() {
+        try {
+            final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+            final Phylogeny s1 = factory.create( Test.PATH_TO_TEST_DATA + "rio_species.xml", new PhyloXmlParser() )[ 0 ];
+            final NHXParser p = new NHXParser();
+            p.setTaxonomyExtraction( TAXONOMY_EXTRACTION.YES );
+            final Phylogeny g1[] = factory.create( new File( Test.PATH_TO_TEST_DATA
+                    + "rio_Bcl-2_e1_20_mafft_05_40_fme.mlt" ), p );
+            for( final Phylogeny gt : g1 ) {
+                gt.setRooted( true );
+                final GSDI sdi = new GSDI( gt, s1, true, true, true );
+            }
+            final IntMatrix m = RIO.calculateOrthologTable( g1 );
+            System.out.println( m.toString() );
+        }
+        catch ( final Exception e ) {
+            e.printStackTrace();
+            return false;
+        }
+        return true;
+    }
+
     private static boolean testSplit() {
         try {
             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();