X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FAptxUtil.java;h=c2dfc549b38b10317a3cae453db66a875bf4f554;hb=713d694ab9ab4e0701fd756af1ea2a892f96ade9;hp=1078656bd7ab1308f9819783c9bc82302df49b23;hpb=ebabb46561f996b5fcd59bd202defd7b189ea5b6;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index 1078656..c2dfc54 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx; @@ -64,6 +64,9 @@ import javax.swing.text.MaskFormatter; import org.forester.analysis.TaxonomyDataManager; import org.forester.io.parsers.PhylogenyParser; +import org.forester.io.parsers.nexus.NexusPhylogeniesParser; +import org.forester.io.parsers.nhx.NHXParser; +import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.io.parsers.tol.TolParser; import org.forester.io.parsers.util.ParserUtils; @@ -791,24 +794,6 @@ public final class AptxUtil { return AVAILABLE_FONT_FAMILIES_SORTED; } - final static void inferCommonPartOfScientificNames( final Phylogeny tree ) { - boolean inferred = false; - for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { - final PhylogenyNode n = it.next(); - if ( !n.getNodeData().isHasTaxonomy() && !n.isExternal() ) { - final String sn = PhylogenyMethods.inferCommonPartOfScientificNameOfDescendants( n ); - if ( !ForesterUtil.isEmpty( sn ) ) { - n.getNodeData().setTaxonomy( new Taxonomy() ); - n.getNodeData().getTaxonomy().setScientificName( sn ); - inferred = true; - } - } - } - if ( inferred ) { - tree.setRerootable( false ); - } - } - final static boolean isHasAssignedEvent( final PhylogenyNode node ) { if ( !node.getNodeData().isHasEvent() ) { return false; @@ -919,17 +904,41 @@ public final class AptxUtil { System.out.println( "[" + applet_name + "] > " + message ); } - final static Phylogeny[] readPhylogeniesFromUrl( final URL url, final boolean phyloxml_validate_against_xsd ) + final static Phylogeny[] readPhylogeniesFromUrl( final URL url, + final boolean phyloxml_validate_against_xsd, + final boolean replace_underscores, + final boolean internal_numbers_are_confidences, + final TAXONOMY_EXTRACTION taxonomy_extraction ) throws FileNotFoundException, IOException { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - PhylogenyParser parser = null; + final PhylogenyParser parser; + boolean nhx_or_nexus = false; if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) { parser = new TolParser(); } else { parser = ParserUtils.createParserDependingOnUrlContents( url, phyloxml_validate_against_xsd ); + if ( parser instanceof NHXParser ) { + nhx_or_nexus = true; + final NHXParser nhx = ( NHXParser ) parser; + nhx.setReplaceUnderscores( replace_underscores ); + nhx.setIgnoreQuotes( false ); + nhx.setTaxonomyExtraction( taxonomy_extraction ); + } + else if ( parser instanceof NexusPhylogeniesParser ) { + nhx_or_nexus = true; + final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser; + nex.setReplaceUnderscores( replace_underscores ); + nex.setIgnoreQuotes( false ); + } } - return factory.create( url.openStream(), parser ); + final Phylogeny[] phys = factory.create( url.openStream(), parser ); + if ( nhx_or_nexus && internal_numbers_are_confidences ) { + for( final Phylogeny phy : phys ) { + PhylogenyMethods.transferInternalNodeNamesToConfidence( phy ); + } + } + return phys; } final static void removeBranchColors( final Phylogeny phy ) { @@ -938,30 +947,52 @@ public final class AptxUtil { } } - final static void unexpectedError( final Error err ) { - err.printStackTrace(); + final static void unexpectedError( final Error e ) { + System.err.println(); + e.printStackTrace( System.err ); + System.err.println(); final StringBuffer sb = new StringBuffer(); - for( final StackTraceElement s : err.getStackTrace() ) { + for( final StackTraceElement s : e.getStackTrace() ) { sb.append( s + "\n" ); } JOptionPane .showMessageDialog( null, "An unexpected (possibly severe) error has occured - terminating. \nPlease contact: " - + Constants.AUTHOR_EMAIL + " \nError: " + err + "\n" + sb, + + Constants.AUTHOR_EMAIL + " \nError: " + e.getLocalizedMessage() + "\n" + + sb, "Unexpected Severe Error [" + Constants.PRG_NAME + " " + Constants.VERSION + "]", JOptionPane.ERROR_MESSAGE ); System.exit( -1 ); } - final static void unexpectedException( final Exception ex ) { - ex.printStackTrace(); + final static void outOfMemoryError( final OutOfMemoryError e ) { + System.err.println(); + System.err.println( "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option" ); + System.err.println(); + e.printStackTrace(); + System.err.println(); + JOptionPane.showMessageDialog( null, + "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option" + + "\n\nError: " + e.getLocalizedMessage(), + "Out of Memory Error [" + Constants.PRG_NAME + " " + Constants.VERSION + "]", + JOptionPane.ERROR_MESSAGE ); + System.exit( -1 ); + } + + final static void unexpectedException( final Exception e ) { + System.err.println(); + e.printStackTrace( System.err ); + System.err.println(); final StringBuffer sb = new StringBuffer(); - for( final StackTraceElement s : ex.getStackTrace() ) { + for( final StackTraceElement s : e.getStackTrace() ) { sb.append( s + "\n" ); } - JOptionPane.showMessageDialog( null, "An unexpected exception has occured. \nPlease contact: " - + Constants.AUTHOR_EMAIL + " \nException: " + ex + "\n" + sb, "Unexpected Exception [" - + Constants.PRG_NAME + Constants.VERSION + "]", JOptionPane.ERROR_MESSAGE ); + JOptionPane.showMessageDialog( null, + "An unexpected exception has occured. \nPlease contact: " + + Constants.AUTHOR_EMAIL + " \nException: " + e.getLocalizedMessage() + + "\n" + sb, + "Unexpected Exception [" + Constants.PRG_NAME + Constants.VERSION + "]", + JOptionPane.ERROR_MESSAGE ); } final static String writePhylogenyToGraphicsByteArrayOutputStream( final ByteArrayOutputStream baos,