2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.archaeopteryx;
28 import java.awt.Color;
29 import java.awt.Component;
30 import java.awt.Graphics2D;
31 import java.awt.GraphicsEnvironment;
32 import java.awt.Rectangle;
33 import java.awt.RenderingHints;
34 import java.awt.image.BufferedImage;
35 import java.io.ByteArrayOutputStream;
37 import java.io.FileNotFoundException;
38 import java.io.IOException;
39 import java.lang.reflect.InvocationTargetException;
40 import java.lang.reflect.Method;
43 import java.text.ParseException;
44 import java.util.Arrays;
45 import java.util.HashMap;
46 import java.util.HashSet;
47 import java.util.Iterator;
48 import java.util.List;
49 import java.util.Locale;
52 import java.util.SortedSet;
53 import java.util.TreeSet;
54 import java.util.regex.Matcher;
55 import java.util.regex.Pattern;
57 import javax.imageio.IIOImage;
58 import javax.imageio.ImageIO;
59 import javax.imageio.ImageWriteParam;
60 import javax.imageio.ImageWriter;
61 import javax.imageio.stream.ImageOutputStream;
62 import javax.swing.JApplet;
63 import javax.swing.JOptionPane;
64 import javax.swing.text.MaskFormatter;
66 import org.forester.analysis.TaxonomyDataManager;
67 import org.forester.io.parsers.PhylogenyParser;
68 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
69 import org.forester.io.parsers.nhx.NHXParser;
70 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
71 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
72 import org.forester.io.parsers.tol.TolParser;
73 import org.forester.io.parsers.util.ParserUtils;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyMethods;
76 import org.forester.phylogeny.PhylogenyNode;
77 import org.forester.phylogeny.data.Accession;
78 import org.forester.phylogeny.data.BranchColor;
79 import org.forester.phylogeny.data.Taxonomy;
80 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
81 import org.forester.phylogeny.factories.PhylogenyFactory;
82 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
83 import org.forester.phylogeny.iterators.PreorderTreeIterator;
84 import org.forester.util.AsciiHistogram;
85 import org.forester.util.DescriptiveStatistics;
86 import org.forester.util.ForesterUtil;
87 import org.forester.ws.seqdb.UniProtTaxonomy;
89 public final class AptxUtil {
91 private final static Pattern seq_identifier_pattern_1 = Pattern
92 .compile( "^([A-Za-z]{2,5})[|=:]([0-9A-Za-z_\\.]{5,40})\\s*$" );
93 private final static Pattern seq_identifier_pattern_2 = Pattern
94 .compile( "^([A-Za-z]{2,5})[|=:]([0-9A-Za-z_\\.]{5,40})[|,; ].*$" );
95 private final static String[] AVAILABLE_FONT_FAMILIES_SORTED = GraphicsEnvironment.getLocalGraphicsEnvironment()
96 .getAvailableFontFamilyNames();
98 Arrays.sort( AVAILABLE_FONT_FAMILIES_SORTED );
101 public static MaskFormatter createMaskFormatter( final String s ) {
102 MaskFormatter formatter = null;
104 formatter = new MaskFormatter( s );
106 catch ( final ParseException e ) {
107 throw new IllegalArgumentException( e );
112 final static public boolean isHasAtLeastNodeWithEvent( final Phylogeny phy ) {
113 final PhylogenyNodeIterator it = phy.iteratorPostorder();
114 while ( it.hasNext() ) {
115 if ( it.next().getNodeData().isHasEvent() ) {
123 * Returns true if at least one branch has a length larger than zero.
128 final static public boolean isHasAtLeastOneBranchLengthLargerThanZero( final Phylogeny phy ) {
129 final PhylogenyNodeIterator it = phy.iteratorPostorder();
130 while ( it.hasNext() ) {
131 if ( it.next().getDistanceToParent() > 0.0 ) {
138 final static public boolean isHasAtLeastOneBranchWithSupportValues( final Phylogeny phy ) {
139 final PhylogenyNodeIterator it = phy.iteratorPostorder();
140 while ( it.hasNext() ) {
141 if ( it.next().getBranchData().isHasConfidences() ) {
148 final public static void launchWebBrowser( final URI uri,
149 final boolean is_applet,
150 final JApplet applet,
151 final String frame_name ) throws IOException {
153 applet.getAppletContext().showDocument( uri.toURL(), frame_name );
156 // This requires Java 1.6:
157 // =======================
158 // boolean no_desktop = false;
160 // if ( Desktop.isDesktopSupported() ) {
161 // System.out.println( "desktop supported" );
162 // final Desktop dt = Desktop.getDesktop();
166 // no_desktop = true;
169 // catch ( final Exception ex ) {
170 // ex.printStackTrace();
171 // no_desktop = true;
173 // catch ( final Error er ) {
174 // er.printStackTrace();
175 // no_desktop = true;
177 // if ( no_desktop ) {
178 // System.out.println( "desktop not supported" );
180 openUrlInWebBrowser( uri.toString() );
182 catch ( final Exception e ) {
183 throw new IOException( e );
189 public static Set<Taxonomy> obtainAllDistinctTaxonomies( final PhylogenyNode node ) {
190 final List<PhylogenyNode> descs = node.getAllExternalDescendants();
191 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
192 for( final PhylogenyNode n : descs ) {
193 if ( n.getNodeData().isHasTaxonomy() && !n.getNodeData().getTaxonomy().isEmpty() ) {
194 tax_set.add( n.getNodeData().getTaxonomy() );
201 * Returns the set of distinct taxonomies of
202 * all external nodes of node.
203 * If at least one the external nodes has no taxonomy,
207 public static Set<Taxonomy> obtainDistinctTaxonomies( final PhylogenyNode node ) {
208 final List<PhylogenyNode> descs = node.getAllExternalDescendants();
209 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
210 for( final PhylogenyNode n : descs ) {
211 if ( !n.getNodeData().isHasTaxonomy() || n.getNodeData().getTaxonomy().isEmpty() ) {
214 tax_set.add( n.getNodeData().getTaxonomy() );
219 public final static Accession obtainSequenceAccessionFromName( final String sequence_name ) {
220 final String n = sequence_name.trim();
221 final Matcher matcher1 = seq_identifier_pattern_1.matcher( n );
224 if ( matcher1.matches() ) {
225 group1 = matcher1.group( 1 );
226 group2 = matcher1.group( 2 );
229 final Matcher matcher2 = seq_identifier_pattern_2.matcher( n );
230 if ( matcher2.matches() ) {
231 group1 = matcher2.group( 1 );
232 group2 = matcher2.group( 2 );
235 if ( ForesterUtil.isEmpty( group1 ) || ForesterUtil.isEmpty( group2 ) ) {
238 return new Accession( group2, group1 );
241 public final static void printWarningMessage( final String name, final String message ) {
242 System.out.println( "[" + name + "] > " + message );
245 final public static void showErrorMessage( final Component parent, final String error_msg ) {
246 printAppletMessage( Constants.PRG_NAME, error_msg );
247 JOptionPane.showMessageDialog( parent, error_msg, "[" + Constants.PRG_NAME + " " + Constants.VERSION
248 + "] Error", JOptionPane.ERROR_MESSAGE );
251 public final static void showExtDescNodeDataUserSelectedHelper( final ControlPanel cp,
252 final PhylogenyNode node,
253 final List<String> data ) {
254 final StringBuilder sb = new StringBuilder();
255 if ( cp.isShowNodeNames() && !ForesterUtil.isEmpty( node.getName() ) ) {
256 showExtDescNodeDataUserSelectedHelperHelper( node.getName(), sb );
258 if ( cp.isShowGeneNames() && node.getNodeData().isHasSequence()
259 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) {
260 showExtDescNodeDataUserSelectedHelperHelper( node.getNodeData().getSequence().getName(), sb );
262 if ( cp.isShowGeneSymbols() && node.getNodeData().isHasSequence()
263 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) {
264 showExtDescNodeDataUserSelectedHelperHelper( node.getNodeData().getSequence().getSymbol(), sb );
266 if ( cp.isShowSequenceAcc() && node.getNodeData().isHasSequence()
267 && ( node.getNodeData().getSequence().getAccession() != null )
268 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().toString() ) ) {
269 showExtDescNodeDataUserSelectedHelperHelper( node.getNodeData().getSequence().getAccession().toString(), sb );
271 if ( cp.isShowTaxonomyCode() && node.getNodeData().isHasTaxonomy()
272 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
273 showExtDescNodeDataUserSelectedHelperHelper( node.getNodeData().getTaxonomy().getTaxonomyCode(), sb );
275 if ( cp.isShowTaxonomyScientificNames() && node.getNodeData().isHasTaxonomy()
276 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) {
277 showExtDescNodeDataUserSelectedHelperHelper( node.getNodeData().getTaxonomy().getScientificName(), sb );
279 if ( ( cp.isShowGeneNames() || cp.isShowGeneSymbols() || cp.isShowSequenceAcc() )
280 && node.getNodeData().isHasSequence()
281 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
282 showExtDescNodeDataUserSelectedHelperHelper( node.getNodeData().getSequence().getMolecularSequence(), sb );
284 final String s = sb.toString().trim();
285 if ( !ForesterUtil.isEmpty( s ) ) {
290 public final static void showExtDescNodeDataUserSelectedHelperHelper( final String s, final StringBuilder sb ) {
291 if ( sb.length() > 0 ) {
297 final public static void showInformationMessage( final Component parent, final String title, final String msg ) {
298 JOptionPane.showMessageDialog( parent, msg, title, JOptionPane.INFORMATION_MESSAGE );
301 public static void writePhylogenyToGraphicsFile( final File intree,
305 final GraphicsExportType type,
306 final Configuration config ) throws IOException {
307 final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType( intree, true );
308 Phylogeny[] phys = null;
309 phys = PhylogenyMethods.readPhylogenies( parser, intree );
310 writePhylogenyToGraphicsFile( phys[ 0 ], outfile, width, height, type, config );
313 public static void writePhylogenyToGraphicsFile( final Phylogeny phy,
317 final GraphicsExportType type,
318 final Configuration config ) throws IOException {
319 final Phylogeny[] phys = new Phylogeny[ 1 ];
321 final MainFrameApplication mf = MainFrameApplication.createInstance( phys, config );
322 AptxUtil.writePhylogenyToGraphicsFileNonInteractive( outfile, width, height, mf.getMainPanel()
323 .getCurrentTreePanel(), mf.getMainPanel().getControlPanel(), type, mf.getOptions() );
327 public final static void writePhylogenyToGraphicsFileNonInteractive( final File outfile,
330 final TreePanel tree_panel,
331 final ControlPanel ac,
332 final GraphicsExportType type,
333 final Options options ) throws IOException {
334 tree_panel.calcParametersForPainting( width, height, true );
335 tree_panel.resetPreferredSize();
336 tree_panel.repaint();
337 final RenderingHints rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
338 RenderingHints.VALUE_RENDER_QUALITY );
339 rendering_hints.put( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY );
340 if ( options.isAntialiasPrint() ) {
341 rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
342 rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
345 rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
346 rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
348 final Phylogeny phylogeny = tree_panel.getPhylogeny();
349 if ( ( phylogeny == null ) || phylogeny.isEmpty() ) {
352 if ( outfile.isDirectory() ) {
353 throw new IOException( "\"" + outfile + "\" is a directory" );
355 final BufferedImage buffered_img = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
356 final Graphics2D g2d = buffered_img.createGraphics();
357 g2d.setRenderingHints( rendering_hints );
358 tree_panel.paintPhylogeny( g2d, false, true, width, height, 0, 0 );
359 if ( type == GraphicsExportType.TIFF ) {
360 writeToTiff( outfile, buffered_img );
363 ImageIO.write( buffered_img, type.toString(), outfile );
368 final static void addPhylogeniesToTabs( final Phylogeny[] phys,
369 final String default_name,
370 final String full_path,
371 final Configuration configuration,
372 final MainPanel main_panel ) {
373 if ( phys.length > Constants.MAX_TREES_TO_LOAD ) {
374 JOptionPane.showMessageDialog( main_panel, "Attempt to load " + phys.length
375 + " phylogenies,\ngoing to load only the first " + Constants.MAX_TREES_TO_LOAD, Constants.PRG_NAME
376 + " more than " + Constants.MAX_TREES_TO_LOAD + " phylogenies", JOptionPane.WARNING_MESSAGE );
379 for( final Phylogeny phy : phys ) {
380 if ( !phy.isEmpty() ) {
381 if ( i <= Constants.MAX_TREES_TO_LOAD ) {
383 String my_name_for_file = "";
384 if ( phys.length > 1 ) {
385 if ( !ForesterUtil.isEmpty( default_name ) ) {
386 my_name = new String( default_name );
388 if ( !ForesterUtil.isEmpty( full_path ) ) {
389 my_name_for_file = new String( full_path );
391 else if ( !ForesterUtil.isEmpty( default_name ) ) {
392 my_name_for_file = new String( default_name );
395 if ( my_name_for_file.indexOf( '.' ) > 0 ) {
396 suffix = my_name_for_file.substring( my_name_for_file.lastIndexOf( '.' ),
397 my_name_for_file.length() );
398 my_name_for_file = my_name_for_file.substring( 0, my_name_for_file.lastIndexOf( '.' ) );
400 if ( !ForesterUtil.isEmpty( my_name_for_file ) ) {
401 my_name_for_file += "_";
403 if ( !ForesterUtil.isEmpty( phy.getName() ) ) {
404 my_name_for_file += phy.getName().replaceAll( " ", "_" );
406 else if ( phy.getIdentifier() != null ) {
407 final StringBuffer sb = new StringBuffer();
408 if ( !ForesterUtil.isEmpty( phy.getIdentifier().getProvider() ) ) {
409 sb.append( phy.getIdentifier().getProvider() );
412 sb.append( phy.getIdentifier().getValue() );
413 my_name_for_file += sb;
416 my_name_for_file += i;
418 if ( !ForesterUtil.isEmpty( my_name ) && ForesterUtil.isEmpty( phy.getName() )
419 && ( phy.getIdentifier() == null ) ) {
420 my_name = my_name + " [" + i + "]";
422 if ( !ForesterUtil.isEmpty( suffix ) ) {
423 my_name_for_file += suffix;
427 if ( !ForesterUtil.isEmpty( default_name ) ) {
428 my_name = new String( default_name );
430 my_name_for_file = "";
431 if ( !ForesterUtil.isEmpty( full_path ) ) {
432 my_name_for_file = new String( full_path );
434 else if ( !ForesterUtil.isEmpty( default_name ) ) {
435 my_name_for_file = new String( default_name );
437 if ( ForesterUtil.isEmpty( my_name_for_file ) ) {
438 if ( !ForesterUtil.isEmpty( phy.getName() ) ) {
439 my_name_for_file = new String( phy.getName() ).replaceAll( " ", "_" );
441 else if ( phy.getIdentifier() != null ) {
442 final StringBuffer sb = new StringBuffer();
443 if ( !ForesterUtil.isEmpty( phy.getIdentifier().getProvider() ) ) {
444 sb.append( phy.getIdentifier().getProvider() );
447 sb.append( phy.getIdentifier().getValue() );
448 my_name_for_file = new String( sb.toString().replaceAll( " ", "_" ) );
452 main_panel.addPhylogenyInNewTab( phy, configuration, my_name, full_path );
453 main_panel.getCurrentTreePanel().setTreeFile( new File( my_name_for_file ) );
454 lookAtSomeTreePropertiesForAptxControlSettings( phy, main_panel.getControlPanel(), configuration );
461 final static void addPhylogenyToPanel( final Phylogeny[] phys,
462 final Configuration configuration,
463 final MainPanel main_panel ) {
464 final Phylogeny phy = phys[ 0 ];
465 main_panel.addPhylogenyInPanel( phy, configuration );
466 lookAtSomeTreePropertiesForAptxControlSettings( phy, main_panel.getControlPanel(), configuration );
469 final static Color calculateColorFromString( final String str ) {
470 final String species_uc = str.toUpperCase();
471 char first = species_uc.charAt( 0 );
474 if ( species_uc.length() > 1 ) {
475 second = species_uc.charAt( 1 );
476 if ( species_uc.length() > 2 ) {
477 if ( species_uc.indexOf( " " ) > 0 ) {
478 third = species_uc.charAt( species_uc.indexOf( " " ) + 1 );
481 third = species_uc.charAt( 2 );
485 first = AptxUtil.normalizeCharForRGB( first );
486 second = AptxUtil.normalizeCharForRGB( second );
487 third = AptxUtil.normalizeCharForRGB( third );
488 if ( ( first > 235 ) && ( second > 235 ) && ( third > 235 ) ) {
491 else if ( ( first < 80 ) && ( second < 80 ) && ( third < 80 ) ) {
494 return new Color( first, second, third );
497 // Returns true if the specified format name can be written
498 final static boolean canWriteFormat( final String format_name ) {
499 final Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName( format_name );
500 return iter.hasNext();
503 final static void collapseSpeciesSpecificSubtrees( final Phylogeny phy ) {
504 boolean inferred = false;
505 for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
506 final PhylogenyNode n = it.next();
507 if ( !n.isExternal() && !n.isCollapse() && ( n.getNumberOfDescendants() > 1 ) ) {
508 final Set<Taxonomy> taxs = obtainDistinctTaxonomies( n );
509 if ( ( taxs != null ) && ( taxs.size() == 1 ) ) {
510 AptxUtil.collapseSubtree( n, true );
511 if ( !n.getNodeData().isHasTaxonomy() ) {
512 n.getNodeData().setTaxonomy( ( Taxonomy ) n.getAllExternalDescendants().get( 0 ).getNodeData()
513 .getTaxonomy().copy() );
518 n.setCollapse( false );
523 phy.setRerootable( false );
527 final static void collapseSubtree( final PhylogenyNode node, final boolean collapse ) {
528 node.setCollapse( collapse );
529 if ( node.isExternal() ) {
532 final PhylogenyNodeIterator it = new PreorderTreeIterator( node );
533 while ( it.hasNext() ) {
534 it.next().setCollapse( collapse );
538 final static void colorPhylogenyAccordingToConfidenceValues( final Phylogeny tree, final TreePanel tree_panel ) {
539 double max_conf = 0.0;
540 for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
541 final PhylogenyNode n = it.next();
542 n.getBranchData().setBranchColor( null );
543 if ( n.getBranchData().isHasConfidences() ) {
544 final double conf = PhylogenyMethods.getConfidenceValue( n );
545 if ( conf > max_conf ) {
550 if ( max_conf > 0.0 ) {
551 final Color bg = tree_panel.getTreeColorSet().getBackgroundColor();
552 final Color br = tree_panel.getTreeColorSet().getBranchColor();
553 for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
554 final PhylogenyNode n = it.next();
555 if ( n.getBranchData().isHasConfidences() ) {
556 final double conf = PhylogenyMethods.getConfidenceValue( n );
557 final BranchColor c = new BranchColor( ForesterUtil.calcColor( conf, 0.0, max_conf, bg, br ) );
558 colorizeSubtree( n, c );
564 final static void colorPhylogenyAccordingToExternalTaxonomy( final Phylogeny tree, final TreePanel tree_panel ) {
565 for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
566 it.next().getBranchData().setBranchColor( null );
568 for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
569 final PhylogenyNode n = it.next();
570 if ( !n.getBranchData().isHasBranchColor() ) {
571 final Taxonomy tax = PhylogenyMethods.getExternalDescendantsTaxonomy( n );
573 n.getBranchData().setBranchColor( new BranchColor( tree_panel.calculateTaxonomyBasedColor( tax ) ) );
574 final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( n );
575 for( final PhylogenyNode desc : descs ) {
577 .setBranchColor( new BranchColor( tree_panel.calculateTaxonomyBasedColor( tax ) ) );
584 final static int colorPhylogenyAccordingToRanks( final Phylogeny tree, final String rank, final TreePanel tree_panel ) {
585 final Map<String, Color> true_lineage_to_color_map = new HashMap<String, Color>();
586 int colorizations = 0;
587 for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
588 final PhylogenyNode n = it.next();
589 if ( n.getNodeData().isHasTaxonomy()
590 && ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() )
591 || !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) || !ForesterUtil
592 .isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
593 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() )
594 && n.getNodeData().getTaxonomy().getRank().equalsIgnoreCase( rank ) ) {
595 final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( n.getNodeData()
597 colorizeSubtree( n, c );
599 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
600 true_lineage_to_color_map.put( n.getNodeData().getTaxonomy().getScientificName(), c.getValue() );
605 for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
606 final PhylogenyNode node = it.next();
607 if ( ( node.getBranchData().getBranchColor() == null ) && node.getNodeData().isHasTaxonomy()
608 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getLineage() ) ) {
609 boolean success = false;
610 if ( !true_lineage_to_color_map.isEmpty() ) {
611 for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) {
612 if ( true_lineage_to_color_map.containsKey( lin ) ) {
613 colorizeSubtree( node, new BranchColor( true_lineage_to_color_map.get( lin ) ) );
621 final Map<String, String> lineage_to_rank_map = MainPanel.getLineageToRankMap();
622 for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) {
623 final Taxonomy temp_tax = new Taxonomy();
624 temp_tax.setScientificName( lin );
625 if ( lineage_to_rank_map.containsKey( lin )
626 && !ForesterUtil.isEmpty( lineage_to_rank_map.get( lin ) )
627 && lineage_to_rank_map.get( lin ).equalsIgnoreCase( rank ) ) {
628 final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) );
629 colorizeSubtree( node, c );
631 true_lineage_to_color_map.put( lin, c.getValue() );
635 UniProtTaxonomy up = null;
637 up = TaxonomyDataManager.obtainUniProtTaxonomy( temp_tax, null, null );
639 catch ( final Exception e ) {
642 if ( ( up != null ) && !ForesterUtil.isEmpty( up.getRank() ) ) {
643 lineage_to_rank_map.put( lin, up.getRank() );
644 if ( up.getRank().equalsIgnoreCase( rank ) ) {
645 final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) );
646 colorizeSubtree( node, c );
648 true_lineage_to_color_map.put( lin, c.getValue() );
657 return colorizations;
660 final static String createBasicInformation( final Phylogeny phy ) {
661 final StringBuilder desc = new StringBuilder();
662 if ( ( phy != null ) && !phy.isEmpty() ) {
663 if ( !ForesterUtil.isEmpty( phy.getName() ) ) {
664 desc.append( "Name: " );
665 desc.append( phy.getName() );
668 if ( phy.getIdentifier() != null ) {
669 desc.append( "Id: " );
670 desc.append( phy.getIdentifier().toString() );
673 if ( !ForesterUtil.isEmpty( phy.getDescription() ) ) {
674 desc.append( "Description: " );
675 desc.append( phy.getDescription() );
678 if ( !ForesterUtil.isEmpty( phy.getDistanceUnit() ) ) {
679 desc.append( "Distance Unit: " );
680 desc.append( phy.getDistanceUnit() );
683 if ( !ForesterUtil.isEmpty( phy.getType() ) ) {
684 desc.append( "Type: " );
685 desc.append( phy.getType() );
688 desc.append( "Rooted: " );
689 desc.append( phy.isRooted() );
691 desc.append( "Rerootable: " );
692 desc.append( phy.isRerootable() );
694 desc.append( "Nodes: " );
695 desc.append( phy.getNodeCount() );
697 desc.append( "External nodes: " );
698 desc.append( phy.getNumberOfExternalNodes() );
700 desc.append( "Internal nodes: " );
701 desc.append( phy.getNodeCount() - phy.getNumberOfExternalNodes() );
703 desc.append( "Internal nodes with polytomies: " );
704 desc.append( PhylogenyMethods.countNumberOfPolytomies( phy ) );
706 desc.append( "Branches: " );
707 desc.append( phy.getNumberOfBranches() );
709 desc.append( "Depth: " );
710 desc.append( PhylogenyMethods.calculateMaxDepth( phy ) );
712 desc.append( "Maximum distance to root: " );
713 desc.append( ForesterUtil.round( PhylogenyMethods.calculateMaxDistanceToRoot( phy ), 6 ) );
715 final Set<Taxonomy> taxs = obtainAllDistinctTaxonomies( phy.getRoot() );
716 if ( taxs != null ) {
717 desc.append( "Distinct external taxonomies: " );
718 desc.append( taxs.size() );
721 final DescriptiveStatistics bs = PhylogenyMethods.calculatBranchLengthStatistics( phy );
722 if ( bs.getN() > 3 ) {
724 desc.append( "Branch-length statistics: " );
726 desc.append( " Number of branches with non-negative branch-lengths: " + bs.getN() );
728 desc.append( " Median: " + ForesterUtil.round( bs.median(), 6 ) );
730 desc.append( " Mean: " + ForesterUtil.round( bs.arithmeticMean(), 6 ) );
732 desc.append( " SD: " + ForesterUtil.round( bs.sampleStandardDeviation(), 6 ) );
734 desc.append( " Minimum: " + ForesterUtil.round( bs.getMin(), 6 ) );
736 desc.append( " Maximum: " + ForesterUtil.round( bs.getMax(), 6 ) );
738 if ( Math.abs( bs.getMax() - bs.getMin() ) > 0.0001 ) {
740 final AsciiHistogram histo = new AsciiHistogram( bs );
741 desc.append( histo.toStringBuffer( 12, '#', 40, 7, " " ) );
744 final DescriptiveStatistics ds = PhylogenyMethods.calculatNumberOfDescendantsPerNodeStatistics( phy );
745 if ( ds.getN() > 2 ) {
747 desc.append( "Descendants per node statistics: " );
749 desc.append( " Median: " + ForesterUtil.round( ds.median(), 2 ) );
751 desc.append( " Mean: " + ForesterUtil.round( ds.arithmeticMean(), 2 ) );
753 desc.append( " SD: " + ForesterUtil.round( ds.sampleStandardDeviation(), 2 ) );
755 desc.append( " Minimum: " + ForesterUtil.roundToInt( ds.getMin() ) );
757 desc.append( " Maximum: " + ForesterUtil.roundToInt( ds.getMax() ) );
760 List<DescriptiveStatistics> css = null;
762 css = PhylogenyMethods.calculatConfidenceStatistics( phy );
764 catch ( final IllegalArgumentException e ) {
765 ForesterUtil.printWarningMessage( Constants.PRG_NAME, e.getMessage() );
767 if ( ( css != null ) && ( css.size() > 0 ) ) {
769 for( int i = 0; i < css.size(); ++i ) {
770 final DescriptiveStatistics cs = css.get( i );
771 if ( ( cs != null ) && ( cs.getN() > 1 ) ) {
772 if ( css.size() > 1 ) {
773 desc.append( "Support statistics " + ( i + 1 ) + ": " );
776 desc.append( "Support statistics: " );
778 if ( !ForesterUtil.isEmpty( cs.getDescription() ) ) {
780 desc.append( " Type: " + cs.getDescription() );
783 desc.append( " Branches with support: " + cs.getN() );
785 desc.append( " Median: " + ForesterUtil.round( cs.median(), 6 ) );
787 desc.append( " Mean: " + ForesterUtil.round( cs.arithmeticMean(), 6 ) );
789 if ( cs.getN() > 2 ) {
790 desc.append( " SD: " + ForesterUtil.round( cs.sampleStandardDeviation(), 6 ) );
793 desc.append( " Minimum: " + ForesterUtil.roundToInt( cs.getMin() ) );
795 desc.append( " Maximum: " + ForesterUtil.roundToInt( cs.getMax() ) );
801 return desc.toString();
809 * to message to be printed
811 final static void dieWithSystemError( final String message ) {
812 System.out.println();
813 System.out.println( Constants.PRG_NAME + " encountered the following system error: " + message );
814 System.out.println( "Please contact the authors." );
815 System.out.println( Constants.PRG_NAME + " needs to close." );
816 System.out.println();
820 final static String[] getAllPossibleRanks() {
821 final String[] str_array = new String[ PhyloXmlUtil.TAXONOMY_RANKS_LIST.size() - 2 ];
823 for( final String e : PhyloXmlUtil.TAXONOMY_RANKS_LIST ) {
824 if ( !e.equals( PhyloXmlUtil.UNKNOWN ) && !e.equals( PhyloXmlUtil.OTHER ) ) {
825 str_array[ i++ ] = e;
831 final static String[] getAllRanks( final Phylogeny tree ) {
832 final SortedSet<String> ranks = new TreeSet<String>();
833 for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
834 final PhylogenyNode n = it.next();
835 if ( n.getNodeData().isHasTaxonomy() && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() ) ) {
836 ranks.add( n.getNodeData().getTaxonomy().getRank() );
839 return ForesterUtil.stringSetToArray( ranks );
842 final static String[] getAvailableFontFamiliesSorted() {
843 return AVAILABLE_FONT_FAMILIES_SORTED;
846 final static boolean isHasAssignedEvent( final PhylogenyNode node ) {
847 if ( !node.getNodeData().isHasEvent() ) {
850 if ( ( node.getNodeData().getEvent() ).isUnassigned() ) {
856 final static boolean isMac() {
858 final String s = ForesterUtil.OS_NAME.toLowerCase();
859 return s.startsWith( "mac" );
861 catch ( final Exception e ) {
862 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "minor error: " + e );
867 final static boolean isUsOrCanada() {
869 if ( ( Locale.getDefault().equals( Locale.CANADA ) ) || ( Locale.getDefault().equals( Locale.US ) ) ) {
873 catch ( final Exception e ) {
879 final static boolean isWindows() {
881 final String s = ForesterUtil.OS_NAME.toLowerCase();
882 return s.indexOf( "win" ) > -1;
884 catch ( final Exception e ) {
885 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "minor error: " + e );
890 final static void lookAtSomeTreePropertiesForAptxControlSettings( final Phylogeny t,
891 final ControlPanel atv_control,
892 final Configuration configuration ) {
893 if ( ( t != null ) && !t.isEmpty() ) {
894 if ( !AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( t ) ) {
895 atv_control.setDrawPhylogram( false );
896 atv_control.setDrawPhylogramEnabled( false );
898 if ( configuration.doGuessCheckOption( Configuration.display_as_phylogram ) ) {
899 if ( atv_control.getDisplayAsPhylogramCb() != null ) {
900 if ( AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( t ) ) {
901 atv_control.setDrawPhylogram( true );
902 atv_control.setDrawPhylogramEnabled( true );
905 atv_control.setDrawPhylogram( false );
909 if ( configuration.doGuessCheckOption( Configuration.write_confidence_values ) ) {
910 if ( atv_control.getWriteConfidenceCb() != null ) {
911 if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( t ) ) {
912 atv_control.setCheckbox( Configuration.write_confidence_values, true );
915 atv_control.setCheckbox( Configuration.write_confidence_values, false );
919 if ( configuration.doGuessCheckOption( Configuration.write_events ) ) {
920 if ( atv_control.getShowEventsCb() != null ) {
921 if ( AptxUtil.isHasAtLeastNodeWithEvent( t ) ) {
922 atv_control.setCheckbox( Configuration.write_events, true );
925 atv_control.setCheckbox( Configuration.write_events, false );
932 final static void openWebsite( final String url, final boolean is_applet, final JApplet applet ) throws IOException {
934 AptxUtil.launchWebBrowser( new URI( url ), is_applet, applet, Constants.PRG_NAME );
936 catch ( final Exception e ) {
937 throw new IOException( e );
941 final static void outOfMemoryError( final OutOfMemoryError e ) {
942 System.err.println();
943 System.err.println( "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option" );
944 System.err.println();
946 System.err.println();
947 JOptionPane.showMessageDialog( null,
948 "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option"
949 + "\n\nError: " + e.getLocalizedMessage(),
950 "Out of Memory Error [" + Constants.PRG_NAME + " " + Constants.VERSION + "]",
951 JOptionPane.ERROR_MESSAGE );
955 final static void printAppletMessage( final String applet_name, final String message ) {
956 System.out.println( "[" + applet_name + "] > " + message );
959 final static Phylogeny[] readPhylogeniesFromUrl( final URL url,
960 final boolean phyloxml_validate_against_xsd,
961 final boolean replace_underscores,
962 final boolean internal_numbers_are_confidences,
963 final TAXONOMY_EXTRACTION taxonomy_extraction )
964 throws FileNotFoundException, IOException {
965 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
966 final PhylogenyParser parser;
967 boolean nhx_or_nexus = false;
968 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
969 parser = new TolParser();
972 parser = ParserUtils.createParserDependingOnUrlContents( url, phyloxml_validate_against_xsd );
973 if ( parser instanceof NHXParser ) {
975 final NHXParser nhx = ( NHXParser ) parser;
976 nhx.setReplaceUnderscores( replace_underscores );
977 nhx.setIgnoreQuotes( false );
978 nhx.setTaxonomyExtraction( taxonomy_extraction );
980 else if ( parser instanceof NexusPhylogeniesParser ) {
982 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
983 nex.setReplaceUnderscores( replace_underscores );
984 nex.setIgnoreQuotes( false );
987 final Phylogeny[] phys = factory.create( url.openStream(), parser );
988 if ( nhx_or_nexus && internal_numbers_are_confidences ) {
989 for( final Phylogeny phy : phys ) {
990 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
996 final static void removeBranchColors( final Phylogeny phy ) {
997 for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
998 it.next().getBranchData().setBranchColor( null );
1002 final static void unexpectedError( final Error e ) {
1003 System.err.println();
1004 e.printStackTrace( System.err );
1005 System.err.println();
1006 final StringBuffer sb = new StringBuffer();
1007 for( final StackTraceElement s : e.getStackTrace() ) {
1008 sb.append( s + "\n" );
1011 .showMessageDialog( null,
1012 "An unexpected (possibly severe) error has occured - terminating. \nPlease contact: "
1013 + Constants.AUTHOR_EMAIL + " \nError: " + e.getLocalizedMessage() + "\n"
1015 "Unexpected Severe Error [" + Constants.PRG_NAME + " " + Constants.VERSION + "]",
1016 JOptionPane.ERROR_MESSAGE );
1020 final static void unexpectedException( final Exception e ) {
1021 System.err.println();
1022 e.printStackTrace( System.err );
1023 System.err.println();
1024 final StringBuffer sb = new StringBuffer();
1025 for( final StackTraceElement s : e.getStackTrace() ) {
1026 sb.append( s + "\n" );
1028 JOptionPane.showMessageDialog( null,
1029 "An unexpected exception has occured. \nPlease contact: "
1030 + Constants.AUTHOR_EMAIL + " \nException: " + e.getLocalizedMessage()
1032 "Unexpected Exception [" + Constants.PRG_NAME + Constants.VERSION + "]",
1033 JOptionPane.ERROR_MESSAGE );
1036 final static String writePhylogenyToGraphicsByteArrayOutputStream( final ByteArrayOutputStream baos,
1039 final TreePanel tree_panel,
1040 final ControlPanel ac,
1041 final GraphicsExportType type,
1042 final Options options ) throws IOException {
1043 if ( !options.isGraphicsExportUsingActualSize() ) {
1044 if ( options.isGraphicsExportVisibleOnly() ) {
1045 throw new IllegalArgumentException( "cannot export visible rectangle only without exporting in actual size" );
1047 tree_panel.calcParametersForPainting( options.getPrintSizeX(), options.getPrintSizeY(), true );
1048 tree_panel.resetPreferredSize();
1049 tree_panel.repaint();
1051 final RenderingHints rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
1052 RenderingHints.VALUE_RENDER_QUALITY );
1053 rendering_hints.put( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY );
1054 if ( options.isAntialiasPrint() ) {
1055 rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1056 rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1059 rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1060 rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1062 final Phylogeny phylogeny = tree_panel.getPhylogeny();
1063 if ( ( phylogeny == null ) || phylogeny.isEmpty() ) {
1066 Rectangle visible = null;
1067 if ( !options.isGraphicsExportUsingActualSize() ) {
1068 width = options.getPrintSizeX();
1069 height = options.getPrintSizeY();
1071 else if ( options.isGraphicsExportVisibleOnly() ) {
1072 visible = tree_panel.getVisibleRect();
1073 width = visible.width;
1074 height = visible.height;
1076 final BufferedImage buffered_img = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
1077 Graphics2D g2d = buffered_img.createGraphics();
1078 g2d.setRenderingHints( rendering_hints );
1081 if ( options.isGraphicsExportVisibleOnly() ) {
1082 g2d = ( Graphics2D ) g2d.create( -visible.x, -visible.y, visible.width, visible.height );
1083 g2d.setClip( null );
1087 tree_panel.paintPhylogeny( g2d, false, true, width, height, x, y );
1088 ImageIO.write( buffered_img, type.toString(), baos );
1091 if ( !options.isGraphicsExportUsingActualSize() ) {
1092 tree_panel.getMainPanel().getControlPanel().showWhole();
1094 String msg = baos.toString();
1095 if ( ( width > 0 ) && ( height > 0 ) ) {
1096 msg += " [size: " + width + ", " + height + "]";
1101 final static String writePhylogenyToGraphicsFile( final String file_name,
1104 final TreePanel tree_panel,
1105 final ControlPanel ac,
1106 final GraphicsExportType type,
1107 final Options options ) throws IOException {
1108 if ( !options.isGraphicsExportUsingActualSize() ) {
1109 if ( options.isGraphicsExportVisibleOnly() ) {
1110 throw new IllegalArgumentException( "cannot export visible rectangle only without exporting in actual size" );
1112 tree_panel.calcParametersForPainting( options.getPrintSizeX(), options.getPrintSizeY(), true );
1113 tree_panel.resetPreferredSize();
1114 tree_panel.repaint();
1116 final RenderingHints rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
1117 RenderingHints.VALUE_RENDER_QUALITY );
1118 rendering_hints.put( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY );
1119 if ( options.isAntialiasPrint() ) {
1120 rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1121 rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1124 rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1125 rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1127 final Phylogeny phylogeny = tree_panel.getPhylogeny();
1128 if ( ( phylogeny == null ) || phylogeny.isEmpty() ) {
1131 final File file = new File( file_name );
1132 if ( file.isDirectory() ) {
1133 throw new IOException( "\"" + file_name + "\" is a directory" );
1135 Rectangle visible = null;
1136 if ( !options.isGraphicsExportUsingActualSize() ) {
1137 width = options.getPrintSizeX();
1138 height = options.getPrintSizeY();
1140 else if ( options.isGraphicsExportVisibleOnly() ) {
1141 visible = tree_panel.getVisibleRect();
1142 width = visible.width;
1143 height = visible.height;
1145 final BufferedImage buffered_img = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
1146 Graphics2D g2d = buffered_img.createGraphics();
1147 g2d.setRenderingHints( rendering_hints );
1150 if ( options.isGraphicsExportVisibleOnly() ) {
1151 g2d = ( Graphics2D ) g2d.create( -visible.x, -visible.y, visible.width, visible.height );
1152 g2d.setClip( null );
1156 tree_panel.paintPhylogeny( g2d, false, true, width, height, x, y );
1157 if ( type == GraphicsExportType.TIFF ) {
1158 writeToTiff( file, buffered_img );
1161 ImageIO.write( buffered_img, type.toString(), file );
1165 if ( !options.isGraphicsExportUsingActualSize() ) {
1166 tree_panel.getMainPanel().getControlPanel().showWhole();
1168 String msg = file.toString();
1169 if ( ( width > 0 ) && ( height > 0 ) ) {
1170 msg += " [size: " + width + ", " + height + "]";
1175 final static void writeToTiff( final File file, final BufferedImage image ) throws IOException {
1176 // See: http://log.robmeek.com/2005/08/write-tiff-in-java.html
1177 ImageWriter writer = null;
1178 ImageOutputStream ios = null;
1179 // Find an appropriate writer:
1180 final Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName( "TIF" );
1181 if ( it.hasNext() ) {
1185 throw new IOException( "failed to get TIFF image writer" );
1188 ios = ImageIO.createImageOutputStream( file );
1189 writer.setOutput( ios );
1190 final ImageWriteParam image_write_param = new ImageWriteParam( Locale.getDefault() );
1191 image_write_param.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
1192 // see writeParam.getCompressionTypes() for available compression type
1194 image_write_param.setCompressionType( "PackBits" );
1195 final String t[] = image_write_param.getCompressionTypes();
1196 for( final String string : t ) {
1197 System.out.println( string );
1199 // Convert to an IIOImage:
1200 final IIOImage iio_image = new IIOImage( image, null, null );
1201 writer.write( null, iio_image, image_write_param );
1204 private static void colorizeSubtree( final PhylogenyNode node, final BranchColor c ) {
1205 node.getBranchData().setBranchColor( c );
1206 final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( node );
1207 for( final PhylogenyNode desc : descs ) {
1208 desc.getBranchData().setBranchColor( c );
1212 final private static char normalizeCharForRGB( char c ) {
1215 c = c > 255 ? 255 : c;
1220 final private static void openUrlInWebBrowser( final String url ) throws IOException, ClassNotFoundException,
1221 SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
1222 InvocationTargetException, InterruptedException {
1223 final String os = System.getProperty( "os.name" );
1224 final Runtime runtime = Runtime.getRuntime();
1225 if ( os.toLowerCase().startsWith( "win" ) ) {
1226 Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + url );
1228 else if ( isMac() ) {
1229 final Class<?> file_mgr = Class.forName( "com.apple.eio.FileManager" );
1230 final Method open_url = file_mgr.getDeclaredMethod( "openURL", new Class[] { String.class } );
1231 open_url.invoke( null, new Object[] { url } );
1234 final String[] browsers = { "firefox", "opera", "konqueror", "mozilla", "netscape", "epiphany" };
1235 String browser = null;
1236 for( int i = 0; ( i < browsers.length ) && ( browser == null ); ++i ) {
1237 if ( runtime.exec( new String[] { "which", browsers[ i ] } ).waitFor() == 0 ) {
1238 browser = browsers[ i ];
1241 if ( browser == null ) {
1242 throw new IOException( "could not find a web browser to open [" + url + "] in" );
1245 runtime.exec( new String[] { browser, url } );
1250 // See: http://www.xml.nig.ac.jp/tutorial/rest/index.html#2.2
1251 // static void openDDBJRest() throws IOException {
1253 // URL url = new URL( "http://xml.nig.ac.jp/rest/Invoke" );
1255 // String query = "service=GetEntry&method=getDDBJEntry&accession=AB000100";
1256 // //make connection
1257 // URLConnection urlc = url.openConnection();
1259 // urlc.setDoOutput( true );
1260 // urlc.setAllowUserInteraction( false );
1262 // PrintStream ps = new PrintStream( urlc.getOutputStream() );
1263 // ps.print( query );
1266 // BufferedReader br = new BufferedReader( new InputStreamReader(
1267 // urlc.getInputStream() ) );
1269 // while ( ( l = br.readLine() ) != null ) {
1270 // System.out.println( l );
1274 public static enum GraphicsExportType {
1275 GIF( "gif" ), JPG( "jpg" ), PDF( "pdf" ), PNG( "png" ), TIFF( "tif" ), BMP( "bmp" );
1277 private final String _suffix;
1279 private GraphicsExportType( final String suffix ) {
1284 public String toString() {