inprogress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / AptxUtil.java
index 42e7ab1..0e217c4 100644 (file)
@@ -48,8 +48,6 @@ import java.util.Locale;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import javax.imageio.IIOImage;
 import javax.imageio.ImageIO;
@@ -71,7 +69,6 @@ import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
 import org.forester.phylogeny.PhylogenyNode;
-import org.forester.phylogeny.data.Accession;
 import org.forester.phylogeny.data.Taxonomy;
 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
 import org.forester.phylogeny.factories.PhylogenyFactory;
@@ -84,10 +81,6 @@ public final class AptxUtil {
 
     private final static String[] AVAILABLE_FONT_FAMILIES_SORTED = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                                                          .getAvailableFontFamilyNames();
-    private final static Pattern  seq_identifier_pattern_1       = Pattern
-                                                                         .compile( "^([A-Za-z]{2,5})[|=:]([0-9A-Za-z_\\.]{5,40})\\s*$" );
-    private final static Pattern  seq_identifier_pattern_2       = Pattern
-                                                                         .compile( "^([A-Za-z]{2,5})[|=:]([0-9A-Za-z_\\.]{5,40})[|,; ].*$" );
     static {
         Arrays.sort( AVAILABLE_FONT_FAMILIES_SORTED );
     }
@@ -191,28 +184,6 @@ public final class AptxUtil {
         return tax_set;
     }
 
-    public final static Accession obtainSequenceAccessionFromName( final String sequence_name ) {
-        final String n = sequence_name.trim();
-        final Matcher matcher1 = seq_identifier_pattern_1.matcher( n );
-        String group1 = "";
-        String group2 = "";
-        if ( matcher1.matches() ) {
-            group1 = matcher1.group( 1 );
-            group2 = matcher1.group( 2 );
-        }
-        else {
-            final Matcher matcher2 = seq_identifier_pattern_2.matcher( n );
-            if ( matcher2.matches() ) {
-                group1 = matcher2.group( 1 );
-                group2 = matcher2.group( 2 );
-            }
-        }
-        if ( ForesterUtil.isEmpty( group1 ) || ForesterUtil.isEmpty( group2 ) ) {
-            return null;
-        }
-        return new Accession( group2, group1 );
-    }
-
     public final static void printWarningMessage( final String name, final String message ) {
         System.out.println( "[" + name + "] > " + message );
     }
@@ -397,9 +368,23 @@ public final class AptxUtil {
         return iter.hasNext();
     }
 
-    final static String createBasicInformation( final Phylogeny phy ) {
+    final static String createBasicInformation( final Phylogeny phy, final File treefile ) {
         final StringBuilder desc = new StringBuilder();
         if ( ( phy != null ) && !phy.isEmpty() ) {
+            String f = null;
+            if ( treefile != null ) {
+                try {
+                    f = treefile.getCanonicalPath();
+                }
+                catch ( final IOException e ) {
+                    //Not important, ignore.
+                }
+                if ( !ForesterUtil.isEmpty( f ) ) {
+                    desc.append( "Path: " );
+                    desc.append( f );
+                    desc.append( "\n" );
+                }
+            }
             if ( !ForesterUtil.isEmpty( phy.getName() ) ) {
                 desc.append( "Name: " );
                 desc.append( phy.getName() );
@@ -488,10 +473,10 @@ public final class AptxUtil {
                 desc.append( "\n" );
                 desc.append( "Descendants per node statistics: " );
                 desc.append( "\n" );
-                desc.append( "    Median: " + ForesterUtil.round( ds.median(), 2 ) );
+                desc.append( "    Median: " + ForesterUtil.round( ds.median(), 6 ) );
                 desc.append( "\n" );
-                desc.append( "    Mean: " + ForesterUtil.round( ds.arithmeticMean(), 2 ) + " (stdev: "
-                        + ForesterUtil.round( ds.sampleStandardDeviation(), 2 ) + ")" );
+                desc.append( "    Mean: " + ForesterUtil.round( ds.arithmeticMean(), 6 ) + " (stdev: "
+                        + ForesterUtil.round( ds.sampleStandardDeviation(), 6 ) + ")" );
                 desc.append( "\n" );
                 desc.append( "    Minimum: " + ForesterUtil.roundToInt( ds.getMin() ) );
                 desc.append( "\n" );
@@ -530,9 +515,9 @@ public final class AptxUtil {
                             desc.append( " (stdev: " + ForesterUtil.round( cs.sampleStandardDeviation(), 6 ) + ")" );
                         }
                         desc.append( "\n" );
-                        desc.append( "    Minimum: " + ForesterUtil.roundToInt( cs.getMin() ) );
+                        desc.append( "    Minimum: " + ForesterUtil.round( cs.getMin(), 6 ) );
                         desc.append( "\n" );
-                        desc.append( "    Maximum: " + ForesterUtil.roundToInt( cs.getMax() ) );
+                        desc.append( "    Maximum: " + ForesterUtil.round( cs.getMax(), 6 ) );
                         desc.append( "\n" );
                     }
                 }
@@ -693,16 +678,19 @@ public final class AptxUtil {
                 nex.setIgnoreQuotes( false );
             }
         }
+        AptxUtil.printAppletMessage( "Archaeopteryx", "parser is " + parser.getName() );
         final Phylogeny[] phys = factory.create( url.openStream(), parser );
-        if ( nhx_or_nexus && internal_numbers_are_confidences ) {
-            for( final Phylogeny phy : phys ) {
-                PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
+        if ( phys != null ) {
+            if ( nhx_or_nexus && internal_numbers_are_confidences ) {
+                for( final Phylogeny phy : phys ) {
+                    PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
+                }
             }
-        }
-        if ( midpoint_reroot ) {
-            for( final Phylogeny phy : phys ) {
-                PhylogenyMethods.midpointRoot( phy );
-                PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
+            if ( midpoint_reroot ) {
+                for( final Phylogeny phy : phys ) {
+                    PhylogenyMethods.midpointRoot( phy );
+                    PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
+                }
             }
         }
         return phys;