+ final static public boolean isHasAtLeastOneNodeWithScientificName( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( n.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final static public boolean isHasAtLeastOneNodeWithSequenceAnnotation( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( n.getNodeData().isHasSequence()
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAnnotations() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final public static void launchWebBrowser( final URI uri,
+ final boolean is_applet,
+ final JApplet applet,
+ final String frame_name ) throws IOException {
+ if ( is_applet ) {
+ applet.getAppletContext().showDocument( uri.toURL(), frame_name );
+ }
+ else {
+ // This requires Java 1.6:
+ // =======================
+ // boolean no_desktop = false;
+ // try {
+ // if ( Desktop.isDesktopSupported() ) {
+ // System.out.println( "desktop supported" );
+ // final Desktop dt = Desktop.getDesktop();
+ // dt.browse( uri );
+ // }
+ // else {
+ // no_desktop = true;
+ // }
+ // }
+ // catch ( final Exception ex ) {
+ // ex.printStackTrace();
+ // no_desktop = true;
+ // }
+ // catch ( final Error er ) {
+ // er.printStackTrace();
+ // no_desktop = true;
+ // }
+ // if ( no_desktop ) {
+ // System.out.println( "desktop not supported" );
+ try {
+ openUrlInWebBrowser( uri.toString() );
+ }
+ catch ( final Exception e ) {
+ throw new IOException( e );
+ }
+ // }
+ }
+ }
+
+ public static Set<Taxonomy> obtainAllDistinctTaxonomies( final PhylogenyNode node ) {
+ final List<PhylogenyNode> descs = node.getAllExternalDescendants();
+ final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
+ for( final PhylogenyNode n : descs ) {
+ if ( n.getNodeData().isHasTaxonomy() && !n.getNodeData().getTaxonomy().isEmpty() ) {
+ tax_set.add( n.getNodeData().getTaxonomy() );
+ }
+ }
+ return tax_set;
+ }
+
+ public final static void printWarningMessage( final String name, final String message ) {
+ System.out.println( "[" + name + "] > " + message );
+ }
+
+ final public 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,
+ final boolean midpoint_reroot )
+ throws FileNotFoundException, IOException {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ 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 );
+ }
+ }
+ AptxUtil.printAppletMessage( "Archaeopteryx", "parser is " + parser.getName() );
+ final URLConnection url_connection = url.openConnection();
+ url_connection.setDefaultUseCaches( false );
+ final InputStream i = url_connection.getInputStream();
+ final Phylogeny[] phys = factory.create( i, parser );
+ i.close();
+ 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 );
+ }
+ }
+ }
+ return phys;
+ }
+
+ final public static void showErrorMessage( final Component parent, final String error_msg ) {
+ printAppletMessage( Constants.PRG_NAME, error_msg );
+ JOptionPane.showMessageDialog( parent, error_msg, "[" + Constants.PRG_NAME + " " + Constants.VERSION
+ + "] Error", JOptionPane.ERROR_MESSAGE );
+ }
+