rio - gsdir work...
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrameApplication.java
index 80c3b5b..babcf6d 100644 (file)
@@ -36,6 +36,7 @@ import java.awt.event.WindowEvent;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -59,17 +60,18 @@ import javax.swing.event.ChangeListener;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.plaf.synth.SynthLookAndFeel;
 
+import org.forester.analysis.TaxonomyDataManager;
+import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
-import org.forester.archaeopteryx.Util.GraphicsExportType;
 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
 import org.forester.archaeopteryx.tools.GoAnnotation;
+import org.forester.archaeopteryx.tools.InferenceManager;
 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
-import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
 import org.forester.archaeopteryx.webservices.WebservicesManager;
 import org.forester.io.parsers.FastaParser;
@@ -77,9 +79,12 @@ import org.forester.io.parsers.GeneralMsaParser;
 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.PhyloXmlDataFormatException;
 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
 import org.forester.io.parsers.tol.TolParser;
+import org.forester.io.parsers.util.ParserUtils;
 import org.forester.io.writers.PhylogenyWriter;
 import org.forester.io.writers.SequenceWriter;
 import org.forester.msa.Msa;
@@ -87,23 +92,21 @@ import org.forester.msa.MsaFormatException;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyNode;
+import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.Confidence;
 import org.forester.phylogeny.data.Taxonomy;
 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
 import org.forester.phylogeny.factories.PhylogenyFactory;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.sdi.GSDI;
-import org.forester.sdi.SDI;
+import org.forester.sdi.GSDIR;
 import org.forester.sdi.SDIR;
-import org.forester.sdi.SDIse;
 import org.forester.sequence.Sequence;
 import org.forester.util.BasicDescriptiveStatistics;
 import org.forester.util.BasicTable;
 import org.forester.util.BasicTableParser;
 import org.forester.util.DescriptiveStatistics;
 import org.forester.util.ForesterUtil;
-import org.forester.util.ForesterUtil.PhylogenyNodeField;
-import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
 import org.forester.util.WindowsUtils;
 
 class DefaultFilter extends FileFilter {
@@ -174,20 +177,22 @@ class SequencesFileFilter extends FileFilter {
 
 public final class MainFrameApplication extends MainFrame {
 
-    private final static int                 FRAME_X_SIZE                    = 800;
-    private final static int                 FRAME_Y_SIZE                    = 800;
+    static final String                      INFER_ANCESTOR_TAXONOMIES             = "Infer Ancestor Taxonomies";
+    static final String                      OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
+    private final static int                 FRAME_X_SIZE                          = 800;
+    private final static int                 FRAME_Y_SIZE                          = 800;
     // Filters for the file-open dialog (classes defined in this file)
-    private final static NHFilter            nhfilter                        = new NHFilter();
-    private final static NHXFilter           nhxfilter                       = new NHXFilter();
-    private final static XMLFilter           xmlfilter                       = new XMLFilter();
-    private final static TolFilter           tolfilter                       = new TolFilter();
-    private final static NexusFilter         nexusfilter                     = new NexusFilter();
-    private final static PdfFilter           pdffilter                       = new PdfFilter();
-    private final static GraphicsFileFilter  graphicsfilefilter              = new GraphicsFileFilter();
-    private final static MsaFileFilter       msafilter                       = new MsaFileFilter();
-    private final static SequencesFileFilter seqsfilter                      = new SequencesFileFilter();
-    private final static DefaultFilter       defaultfilter                   = new DefaultFilter();
-    private static final long                serialVersionUID                = -799735726778865234L;
+    private final static NHFilter            nhfilter                              = new NHFilter();
+    private final static NHXFilter           nhxfilter                             = new NHXFilter();
+    private final static XMLFilter           xmlfilter                             = new XMLFilter();
+    private final static TolFilter           tolfilter                             = new TolFilter();
+    private final static NexusFilter         nexusfilter                           = new NexusFilter();
+    private final static PdfFilter           pdffilter                             = new PdfFilter();
+    private final static GraphicsFileFilter  graphicsfilefilter                    = new GraphicsFileFilter();
+    private final static MsaFileFilter       msafilter                             = new MsaFileFilter();
+    private final static SequencesFileFilter seqsfilter                            = new SequencesFileFilter();
+    private final static DefaultFilter       defaultfilter                         = new DefaultFilter();
+    private static final long                serialVersionUID                      = -799735726778865234L;
     private final JFileChooser               _values_filechooser;
     private final JFileChooser               _open_filechooser;
     private final JFileChooser               _msa_filechooser;
@@ -199,8 +204,8 @@ public final class MainFrameApplication extends MainFrame {
     // Analysis menu
     private JMenu                            _analysis_menu;
     private JMenuItem                        _load_species_tree_item;
-    private JMenuItem                        _sdi_item;
     private JMenuItem                        _gsdi_item;
+    private JMenuItem                        _gsdir_item;
     private JMenuItem                        _root_min_dups_item;
     private JMenuItem                        _root_min_cost_l_item;
     private JMenuItem                        _lineage_inference;
@@ -216,22 +221,31 @@ public final class MainFrameApplication extends MainFrame {
     private Phylogeny                        _species_tree;
     private File                             _current_dir;
     private ButtonGroup                      _radio_group_1;
+    private ButtonGroup                      _radio_group_2;
     // Others:
-    double                                   _min_not_collapse               = Constants.MIN_NOT_COLLAPSE_DEFAULT;
+    double                                   _min_not_collapse                     = Constants.MIN_NOT_COLLAPSE_DEFAULT;
     // Phylogeny Inference menu
     private JMenu                            _inference_menu;
     private JMenuItem                        _inference_from_msa_item;
     private JMenuItem                        _inference_from_seqs_item;
     // Phylogeny Inference
-    private PhylogeneticInferenceOptions     _phylogenetic_inference_options = null;
-    private Msa                              _msa                            = null;
-    private File                             _msa_file                       = null;
-    private List<Sequence>                   _seqs                           = null;
-    private File                             _seqs_file                      = null;
+    private PhylogeneticInferenceOptions     _phylogenetic_inference_options       = null;
+    private Msa                              _msa                                  = null;
+    private File                             _msa_file                             = null;
+    private List<Sequence>                   _seqs                                 = null;
+    private File                             _seqs_file                            = null;
     // expression values menu:
     JMenuItem                                _read_values_jmi;
 
     private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
+        this( phys, config, title, null );
+    }
+
+    private MainFrameApplication( final Phylogeny[] phys,
+                                  final Configuration config,
+                                  final String title,
+                                  final File current_dir ) {
+        super();
         _configuration = config;
         if ( _configuration == null ) {
             throw new IllegalArgumentException( "configuration is null" );
@@ -245,7 +259,7 @@ public final class MainFrameApplication extends MainFrame {
                                 MainFrameApplication.class );
                     UIManager.setLookAndFeel( synth );
                 }
-                catch ( Exception ex ) {
+                catch ( final Exception ex ) {
                     synth_exception = true;
                     ForesterUtil.printWarningMessage( Constants.PRG_NAME,
                                                       "could not create synth look and feel: "
@@ -263,25 +277,29 @@ public final class MainFrameApplication extends MainFrame {
             //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
         }
         catch ( final UnsupportedLookAndFeelException e ) {
-            Util.dieWithSystemError( "unsupported look and feel: " + e.toString() );
+            AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
         }
         catch ( final ClassNotFoundException e ) {
-            Util.dieWithSystemError( "class not found exception: " + e.toString() );
+            AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
         }
         catch ( final InstantiationException e ) {
-            Util.dieWithSystemError( "instantiation exception: " + e.toString() );
+            AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
         }
         catch ( final IllegalAccessException e ) {
-            Util.dieWithSystemError( "illegal access exception: " + e.toString() );
+            AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
         }
         catch ( final Exception e ) {
-            Util.dieWithSystemError( e.toString() );
+            AptxUtil.dieWithSystemError( e.toString() );
+        }
+        if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
+            setCurrentDir( current_dir );
         }
         // hide until everything is ready
         setVisible( false );
         setOptions( Options.createInstance( _configuration ) );
+        setInferenceManager( InferenceManager.createInstance( _configuration ) );
         setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
-        _textframe = null;
+        //     _textframe = null; #~~~~
         _species_tree = null;
         // set title
         setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
@@ -408,7 +426,7 @@ public final class MainFrameApplication extends MainFrame {
         // addKeyListener( this );
         setVisible( true );
         if ( ( phys != null ) && ( phys.length > 0 ) ) {
-            Util.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
+            AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
             validate();
             getMainPanel().getControlPanel().showWholeAll();
             getMainPanel().getControlPanel().showWhole();
@@ -419,9 +437,54 @@ public final class MainFrameApplication extends MainFrame {
         System.gc();
     }
 
+    private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
+        _configuration = config;
+        if ( _configuration == null ) {
+            throw new IllegalArgumentException( "configuration is null" );
+        }
+        setVisible( false );
+        setOptions( Options.createInstance( _configuration ) );
+        _mainpanel = new MainPanel( _configuration, this );
+        _open_filechooser = null;
+        _open_filechooser_for_species_tree = null;
+        _save_filechooser = null;
+        _writetopdf_filechooser = null;
+        _writetographics_filechooser = null;
+        _msa_filechooser = null;
+        _seqs_filechooser = null;
+        _values_filechooser = null;
+        _jmenubar = new JMenuBar();
+        buildFileMenu();
+        buildTypeMenu();
+        _contentpane = getContentPane();
+        _contentpane.setLayout( new BorderLayout() );
+        _contentpane.add( _mainpanel, BorderLayout.CENTER );
+        // App is this big
+        setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
+        // The window listener
+        setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
+        addWindowListener( new WindowAdapter() {
+
+            @Override
+            public void windowClosing( final WindowEvent e ) {
+                exit();
+            }
+        } );
+        //   setVisible( true );
+        if ( ( phys != null ) && ( phys.length > 0 ) ) {
+            AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
+            validate();
+            getMainPanel().getControlPanel().showWholeAll();
+            getMainPanel().getControlPanel().showWhole();
+        }
+        //activateSaveAllIfNeeded();
+        // ...and its children
+        _contentpane.repaint();
+    }
+
     private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
         // Reads the config file (false, false => not url, not applet):
-        this( phys, new Configuration( config_file, false, false ), title );
+        this( phys, new Configuration( config_file, false, false, true ), title );
     }
 
     @Override
@@ -471,12 +534,6 @@ public final class MainFrameApplication extends MainFrame {
             else if ( o == _load_species_tree_item ) {
                 readSpeciesTreeFromFile();
             }
-            else if ( o == _sdi_item ) {
-                if ( isSubtreeDisplayed() ) {
-                    return;
-                }
-                executeSDI();
-            }
             else if ( o == _lineage_inference ) {
                 if ( isSubtreeDisplayed() ) {
                     JOptionPane.showMessageDialog( this,
@@ -502,8 +559,8 @@ public final class MainFrameApplication extends MainFrame {
                 }
                 obtainDetailedTaxonomicInformationDelete();
             }
-            else if ( o == _obtain_uniprot_seq_information_jmi ) {
-                obtainUniProtSequenceInformation();
+            else if ( o == _obtain_seq_information_jmi ) {
+                obtainSequenceInformation();
             }
             else if ( o == _read_values_jmi ) {
                 if ( isSubtreeDisplayed() ) {
@@ -526,6 +583,12 @@ public final class MainFrameApplication extends MainFrame {
                 }
                 executeGSDI();
             }
+            else if ( o == _gsdir_item ) {
+                if ( isSubtreeDisplayed() ) {
+                    return;
+                }
+                executeGSDIR();
+            }
             else if ( o == _root_min_dups_item ) {
                 if ( isSubtreeDisplayed() ) {
                     return;
@@ -563,8 +626,8 @@ public final class MainFrameApplication extends MainFrame {
                 updateOptions( getOptions() );
             }
             else if ( o == _replace_underscores_cbmi ) {
-                if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
-                    _extract_pfam_style_tax_codes_cbmi.setSelected( false );
+                if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
+                    _extract_taxonomy_no_rbmi.setSelected( true );
                 }
                 updateOptions( getOptions() );
             }
@@ -574,8 +637,8 @@ public final class MainFrameApplication extends MainFrame {
                 }
                 collapseBelowThreshold();
             }
-            else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
-                if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
+            else if ( ( o == _extract_taxonomy_pfam_rbmi ) || ( o == _extract_taxonomy_yes_rbmi ) ) {
+                if ( _replace_underscores_cbmi != null ) {
                     _replace_underscores_cbmi.setSelected( false );
                 }
                 updateOptions( getOptions() );
@@ -589,46 +652,52 @@ public final class MainFrameApplication extends MainFrame {
             _contentpane.repaint();
         }
         catch ( final Exception ex ) {
-            Util.unexpectedException( ex );
+            AptxUtil.unexpectedException( ex );
         }
         catch ( final Error err ) {
-            Util.unexpectedError( err );
+            AptxUtil.unexpectedError( err );
         }
     }
 
     void buildAnalysisMenu() {
         _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
-        _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
-        if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
-            _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
-        }
+        _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
+        _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (re-rooting)" ) );
         _analysis_menu.addSeparator();
         _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
         _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
         _analysis_menu.addSeparator();
         _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
-        customizeJMenuItem( _sdi_item );
         customizeJMenuItem( _gsdi_item );
+        customizeJMenuItem( _gsdir_item );
         customizeJMenuItem( _root_min_dups_item );
         customizeJMenuItem( _root_min_cost_l_item );
         customizeJMenuItem( _load_species_tree_item );
         _analysis_menu.addSeparator();
-        _analysis_menu.add( _lineage_inference = new JMenuItem( "Infer Ancestor Taxonomies" ) );
+        _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
         customizeJMenuItem( _lineage_inference );
         _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
         _jmenubar.add( _analysis_menu );
     }
 
     void buildPhylogeneticInferenceMenu() {
+        final InferenceManager im = getInferenceManager();
         _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
-        _inference_menu
-                .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
+        _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
         customizeJMenuItem( _inference_from_msa_item );
         _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
-        _inference_menu
-                .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
-        customizeJMenuItem( _inference_from_seqs_item );
-        _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
+        if ( im.canDoMsa() ) {
+            _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
+            customizeJMenuItem( _inference_from_seqs_item );
+            _inference_from_seqs_item
+                    .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
+        }
+        else {
+            _inference_menu
+                    .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
+            customizeJMenuItem( _inference_from_seqs_item );
+            _inference_from_seqs_item.setEnabled( false );
+        }
         _jmenubar.add( _inference_menu );
     }
 
@@ -659,15 +728,15 @@ public final class MainFrameApplication extends MainFrame {
         _save_all_item.setEnabled( false );
         _file_jmenu.addSeparator();
         _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
-        if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
+        if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
             _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
         }
         _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
         _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
-        if ( Util.canWriteFormat( "gif" ) ) {
+        if ( AptxUtil.canWriteFormat( "gif" ) ) {
             _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
         }
-        if ( Util.canWriteFormat( "bmp" ) ) {
+        if ( AptxUtil.canWriteFormat( "bmp" ) ) {
             _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
         }
         _file_jmenu.addSeparator();
@@ -738,16 +807,17 @@ public final class MainFrameApplication extends MainFrame {
         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
         _radio_group_1.add( _uniform_cladograms_rbmi );
         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
+        _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
+        _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
+        _options_jmenu
+                .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
+        _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
         _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
         _options_jmenu
                 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
-        _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
-        _options_jmenu
-                .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
-        _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
         _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
         _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
@@ -781,13 +851,32 @@ public final class MainFrameApplication extends MainFrame {
         _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
         _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
         _options_jmenu.addSeparator();
+        _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
         _options_jmenu
-                .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
-        _options_jmenu
-                .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
+                .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
         _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
+        //
+        _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
+        _options_jmenu
+                .add( _extract_taxonomy_pfam_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Pfam-style Node Names" ) );
+        _extract_taxonomy_pfam_rbmi
+                .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE/134-298\"" );
+        _options_jmenu
+                .add( _extract_taxonomy_yes_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Node Names" ) );
+        _extract_taxonomy_yes_rbmi
+                .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE\" or \"BCL2_MOUSE B-cell lymphoma 2...\"" );
+        _radio_group_2 = new ButtonGroup();
+        _radio_group_2.add( _extract_taxonomy_no_rbmi );
+        _radio_group_2.add( _extract_taxonomy_pfam_rbmi );
+        _radio_group_2.add( _extract_taxonomy_yes_rbmi );
+        // 
+        _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
         _options_jmenu
-                .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
+                .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
+        _use_brackets_for_conf_in_nh_export_cbmi
+                .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
+        _options_jmenu
+                .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
         customizeJMenuItem( _choose_font_mi );
         customizeJMenuItem( _choose_minimal_confidence_mi );
         customizeJMenuItem( _switch_colors_mi );
@@ -820,8 +909,12 @@ public final class MainFrameApplication extends MainFrame {
         customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
         customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
                 .isInternalNumberAreConfidenceForNhParsing() );
-        customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
-                .isExtractPfamTaxonomyCodesInNhParsing() );
+        customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
+                                      getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
+        customizeRadioButtonMenuItem( _extract_taxonomy_yes_rbmi,
+                                      getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.YES );
+        customizeRadioButtonMenuItem( _extract_taxonomy_pfam_rbmi,
+                                      getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
         customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
@@ -829,6 +922,11 @@ public final class MainFrameApplication extends MainFrame {
         customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
         customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
                 .isGraphicsExportUsingActualSize() );
+        customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
+        customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
+                .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
+        customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
+                .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
         _jmenubar.add( _options_jmenu );
     }
 
@@ -836,22 +934,28 @@ public final class MainFrameApplication extends MainFrame {
         _tools_menu = createMenu( "Tools", getConfiguration() );
         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
         customizeJMenuItem( _confcolor_item );
+        _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
+        customizeJMenuItem( _color_rank_jmi );
+        _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
         customizeJMenuItem( _taxcolor_item );
         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
         _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
         customizeJMenuItem( _remove_branch_color_item );
         _tools_menu.addSeparator();
+        _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
+        customizeJMenuItem( _annotate_item );
+        _tools_menu.addSeparator();
         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
         customizeJMenuItem( _midpoint_root_item );
         _tools_menu.addSeparator();
         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
         customizeJMenuItem( _collapse_species_specific_subtrees );
         _tools_menu
-                .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
+                .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
         customizeJMenuItem( _collapse_below_threshold );
         _collapse_below_threshold
-                .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
+                .setToolTipText( "To collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );
         _tools_menu.addSeparator();
         _tools_menu
                 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
@@ -867,23 +971,18 @@ public final class MainFrameApplication extends MainFrame {
                 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
         _tools_menu.addSeparator();
         _tools_menu
-                .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
-        customizeJMenuItem( _infer_common_sn_names_item );
-        _tools_menu.addSeparator();
-        _tools_menu
-                .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
+                .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
         customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
         _obtain_detailed_taxonomic_information_jmi
                 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
         _tools_menu
-                .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (Delete Nodes)" ) );
+                .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
         customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
         _obtain_detailed_taxonomic_information_deleting_jmi
                 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
-        _tools_menu
-                .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
-        customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
-        _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
+        _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
+        customizeJMenuItem( _obtain_seq_information_jmi );
+        _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
         _tools_menu.addSeparator();
         if ( !Constants.__RELEASE ) {
             _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
@@ -1038,11 +1137,17 @@ public final class MainFrameApplication extends MainFrame {
             }
             if ( to_be_removed.size() > 0 ) {
                 phy.externalNodesHaveChanged();
-                phy.hashIDs();
+                phy.clearHashIdToNodeMap();
                 phy.recalculateNumberOfExternalDescendants( true );
                 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
+                getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
+                getCurrentTreePanel().calculateLongestExtNodeInfo();
+                getCurrentTreePanel().setNodeInPreorderToNull();
+                getCurrentTreePanel().recalculateMaxDistanceToRoot();
+                getCurrentTreePanel().resetPreferredSize();
                 getCurrentTreePanel().setEdited( true );
                 getCurrentTreePanel().repaint();
+                repaint();
             }
             if ( to_be_removed.size() > 0 ) {
                 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
@@ -1131,22 +1236,70 @@ public final class MainFrameApplication extends MainFrame {
         gene_tree.setAllNodesToNotCollapse();
         gene_tree.recalculateNumberOfExternalDescendants( false );
         GSDI gsdi = null;
-        int duplications = -1;
+        Phylogeny species_tree = _species_tree.copy();
         try {
-            gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
-            duplications = gsdi.getDuplicationsSum();
+            gsdi = new GSDI( gene_tree, species_tree, false, true, true );
         }
         catch ( final Exception e ) {
             JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
+            return;
         }
         gene_tree.setRerootable( false );
         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
+        _mainpanel.getCurrentPhylogeny().clearHashIdToNodeMap();
+        _mainpanel.getCurrentPhylogeny().recalculateNumberOfExternalDescendants( true );
+        _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap();
+        _mainpanel.getCurrentTreePanel().setEdited( true );
         getControlPanel().setShowEvents( true );
         showWhole();
+        final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
+        _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
+        showWhole();
+        _mainpanel.getTabbedPane().setSelectedIndex( selected );
+        showWhole();
+        _mainpanel.getCurrentTreePanel().setEdited( true );
+        JOptionPane.showMessageDialog( this, "Duplications: " + gsdi.getDuplicationsSum() + "\n"
+                + "Potential duplications: " + gsdi.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
+                + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
+    }
+
+    void executeGSDIR() {
+        if ( !isOKforSDI( false, true ) ) {
+            return;
+        }
+        final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
+        gene_tree.setAllNodesToNotCollapse();
+        gene_tree.recalculateNumberOfExternalDescendants( false );
+        GSDIR gsdir = null;
+        Phylogeny species_tree = _species_tree.copy();
+        try {
+            gsdir = new GSDIR( gene_tree, species_tree, true, true );
+        }
+        catch ( final Exception e ) {
+            JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTrees().get( 0 );
+        result_gene_tree.setRerootable( false );
+        result_gene_tree.clearHashIdToNodeMap();
+        result_gene_tree.recalculateNumberOfExternalDescendants( true );
+        _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
+        //_mainpanel.getCurrentTreePanel().setTree( gene_tree );
+        // _mainpanel.getCurrentTreePanel().setEdited( true );
+        getControlPanel().setShowEvents( true );
+        showWhole();
+        final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
+        _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
+        showWhole();
+        _mainpanel.getTabbedPane().setSelectedIndex( selected );
+        showWhole();
         _mainpanel.getCurrentTreePanel().setEdited( true );
         JOptionPane.showMessageDialog( this,
-                                       "Number of duplications: " + duplications,
-                                       "GSDI successfully completed",
+                                       "Duplications: " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: "
+                                               + gsdir.getSpeciationsSum() + "\n"
+                                               + "Number of root positions minimizing duplications sum: "
+                                               + gsdir.getMinDuplicationsSumGeneTrees().size(),
+                                       "GSDIR successfully completed",
                                        JOptionPane.INFORMATION_MESSAGE );
     }
 
@@ -1171,10 +1324,10 @@ public final class MainFrameApplication extends MainFrame {
                                            JOptionPane.ERROR_MESSAGE );
             return;
         }
-        final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
         final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
                                                                                   _mainpanel.getCurrentTreePanel(),
-                                                                                  phy );
+                                                                                  _mainpanel.getCurrentPhylogeny()
+                                                                                          .copy() );
         new Thread( inferrer ).start();
     }
 
@@ -1215,40 +1368,6 @@ public final class MainFrameApplication extends MainFrame {
         }
     }
 
-    void executeSDI() {
-        if ( !isOKforSDI( true, true ) ) {
-            return;
-        }
-        if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
-            JOptionPane.showMessageDialog( this,
-                                           "Gene tree is not rooted",
-                                           "Cannot execute SDI",
-                                           JOptionPane.ERROR_MESSAGE );
-            return;
-        }
-        final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
-        gene_tree.setAllNodesToNotCollapse();
-        gene_tree.recalculateNumberOfExternalDescendants( false );
-        SDI sdi = null;
-        int duplications = -1;
-        try {
-            sdi = new SDIse( gene_tree, _species_tree.copy() );
-            duplications = sdi.getDuplicationsSum();
-        }
-        catch ( final Exception e ) {
-            JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
-        }
-        gene_tree.setRerootable( false );
-        _mainpanel.getCurrentTreePanel().setTree( gene_tree );
-        getControlPanel().setShowEvents( true );
-        showWhole();
-        _mainpanel.getCurrentTreePanel().setEdited( true );
-        JOptionPane.showMessageDialog( this,
-                                       "Number of duplications: " + duplications,
-                                       "SDI successfully completed",
-                                       JOptionPane.INFORMATION_MESSAGE );
-    }
-
     void executeSDIR( final boolean minimize_cost ) {
         if ( !isOKforSDI( true, true ) ) {
             return;
@@ -1281,7 +1400,7 @@ public final class MainFrameApplication extends MainFrame {
     }
 
     void exit() {
-        removeTextFrame();
+        removeAllTextFrames();
         _mainpanel.terminate();
         _contentpane.removeAll();
         setVisible( false );
@@ -1289,7 +1408,14 @@ public final class MainFrameApplication extends MainFrame {
         System.exit( 0 );
     }
 
-    private void extractTaxCodeFromNodeNames() {
+    public void end() {
+        _mainpanel.terminate();
+        _contentpane.removeAll();
+        setVisible( false );
+        dispose();
+    }
+
+    private void extractTaxCodeFromNodeNames() throws PhyloXmlDataFormatException {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
@@ -1298,9 +1424,8 @@ public final class MainFrameApplication extends MainFrame {
                     final PhylogenyNode n = it.next();
                     final String name = n.getName().trim();
                     if ( !ForesterUtil.isEmpty( name ) ) {
-                        final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
-                                                                                          false,
-                                                                                          TAXONOMY_EXTRACTION.YES );
+                        final String code = ParserUtils
+                                .extractTaxonomyCodeFromNodeName( name, NHXParser.TAXONOMY_EXTRACTION.YES );
                         if ( !ForesterUtil.isEmpty( code ) ) {
                             PhylogenyMethods.setTaxonomyCode( n, code );
                         }
@@ -1316,7 +1441,7 @@ public final class MainFrameApplication extends MainFrame {
 
     private File getCurrentDir() {
         if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
-            if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
+            if ( ForesterUtil.isWindowns() ) {
                 try {
                     _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
                 }
@@ -1385,20 +1510,23 @@ public final class MainFrameApplication extends MainFrame {
         return false;
     }
 
-    private void moveNodeNamesToSeqNames() {
+    private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
-                ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
+                PhylogenyMethods
+                        .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
             }
         }
     }
 
-    private void moveNodeNamesToTaxSn() {
+    private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
-                ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
+                PhylogenyMethods.transferNodeNameToField( phy,
+                                                          PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
+                                                          false );
             }
         }
     }
@@ -1410,7 +1538,7 @@ public final class MainFrameApplication extends MainFrame {
         phy.setRoot( node );
         phy.setRooted( true );
         phys[ 0 ] = phy;
-        Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
+        AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
         _mainpanel.getControlPanel().showWhole();
         _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
         _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
@@ -1430,9 +1558,11 @@ public final class MainFrameApplication extends MainFrame {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
-                final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
-                                                                         _mainpanel.getCurrentTreePanel(),
-                                                                         phy.copy() );
+                final TaxonomyDataManager t = new TaxonomyDataManager( this,
+                                                                       _mainpanel.getCurrentTreePanel(),
+                                                                       phy.copy(),
+                                                                       false,
+                                                                       true );
                 new Thread( t ).start();
             }
         }
@@ -1442,16 +1572,17 @@ public final class MainFrameApplication extends MainFrame {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
-                final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
-                                                                         _mainpanel.getCurrentTreePanel(),
-                                                                         phy.copy(),
-                                                                         true );
+                final TaxonomyDataManager t = new TaxonomyDataManager( this,
+                                                                       _mainpanel.getCurrentTreePanel(),
+                                                                       phy.copy(),
+                                                                       true,
+                                                                       true );
                 new Thread( t ).start();
             }
         }
     }
 
-    private void obtainUniProtSequenceInformation() {
+    private void obtainSequenceInformation() {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
@@ -1684,7 +1815,7 @@ public final class MainFrameApplication extends MainFrame {
                         try {
                             final NHXParser nhx = new NHXParser();
                             setSpecialOptionsForNhxParser( nhx );
-                            phys = ForesterUtil.readPhylogenies( nhx, file );
+                            phys = PhylogenyMethods.readPhylogenies( nhx, file );
                             nhx_or_nexus = true;
                         }
                         catch ( final Exception e ) {
@@ -1696,7 +1827,7 @@ public final class MainFrameApplication extends MainFrame {
                         warnIfNotPhyloXmlValidation( getConfiguration() );
                         try {
                             final PhyloXmlParser xml_parser = createPhyloXmlParser();
-                            phys = ForesterUtil.readPhylogenies( xml_parser, file );
+                            phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
                         }
                         catch ( final Exception e ) {
                             exception = true;
@@ -1705,7 +1836,7 @@ public final class MainFrameApplication extends MainFrame {
                     }
                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
                         try {
-                            phys = ForesterUtil.readPhylogenies( new TolParser(), file );
+                            phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
                         }
                         catch ( final Exception e ) {
                             exception = true;
@@ -1716,7 +1847,7 @@ public final class MainFrameApplication extends MainFrame {
                         try {
                             final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
                             setSpecialOptionsForNexParser( nex );
-                            phys = ForesterUtil.readPhylogenies( nex, file );
+                            phys = PhylogenyMethods.readPhylogenies( nex, file );
                             nhx_or_nexus = true;
                         }
                         catch ( final Exception e ) {
@@ -1727,7 +1858,7 @@ public final class MainFrameApplication extends MainFrame {
                     // "*.*":
                     else {
                         try {
-                            final PhylogenyParser parser = ForesterUtil
+                            final PhylogenyParser parser = ParserUtils
                                     .createParserDependingOnFileType( file, getConfiguration()
                                             .isValidatePhyloXmlAgainstSchema() );
                             if ( parser instanceof NexusPhylogeniesParser ) {
@@ -1743,7 +1874,7 @@ public final class MainFrameApplication extends MainFrame {
                             else if ( parser instanceof PhyloXmlParser ) {
                                 warnIfNotPhyloXmlValidation( getConfiguration() );
                             }
-                            phys = ForesterUtil.readPhylogenies( parser, file );
+                            phys = PhylogenyMethods.readPhylogenies( parser, file );
                         }
                         catch ( final Exception e ) {
                             exception = true;
@@ -1761,7 +1892,7 @@ public final class MainFrameApplication extends MainFrame {
                         if ( nhx_or_nexus ) {
                             for( final Phylogeny phy : phys ) {
                                 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
-                                    ForesterUtil.transferInternalNodeNamesToConfidence( phy );
+                                    PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
                                 }
                                 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
                                     one_desc = true;
@@ -1769,11 +1900,11 @@ public final class MainFrameApplication extends MainFrame {
                                 }
                             }
                         }
-                        Util.addPhylogeniesToTabs( phys,
-                                                   file.getName(),
-                                                   file.getAbsolutePath(),
-                                                   getConfiguration(),
-                                                   getMainPanel() );
+                        AptxUtil.addPhylogeniesToTabs( phys,
+                                                       file.getName(),
+                                                       file.getAbsolutePath(),
+                                                       getConfiguration(),
+                                                       getMainPanel() );
                         _mainpanel.getControlPanel().showWhole();
                         if ( nhx_or_nexus && one_desc ) {
                             JOptionPane
@@ -1916,12 +2047,12 @@ public final class MainFrameApplication extends MainFrame {
             setMsa( null );
             Msa msa = null;
             try {
-                if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
-                    msa = FastaParser.parseMsa( new FileInputStream( file ) );
-                    System.out.println( msa.toString() );
+                final InputStream is = new FileInputStream( file );
+                if ( FastaParser.isLikelyFasta( file ) ) {
+                    msa = FastaParser.parseMsa( is );
                 }
                 else {
-                    msa = GeneralMsaParser.parse( new FileInputStream( file ) );
+                    msa = GeneralMsaParser.parse( is );
                 }
             }
             catch ( final MsaFormatException e ) {
@@ -2022,7 +2153,7 @@ public final class MainFrameApplication extends MainFrame {
                     parser = new TolParser();
                 }
                 else {
-                    parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
+                    parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
                             .isValidatePhyloXmlAgainstSchema() );
                 }
                 if ( parser instanceof NexusPhylogeniesParser ) {
@@ -2070,14 +2201,14 @@ public final class MainFrameApplication extends MainFrame {
             if ( ( phys != null ) && ( phys.length > 0 ) ) {
                 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
                     for( final Phylogeny phy : phys ) {
-                        ForesterUtil.transferInternalNodeNamesToConfidence( phy );
+                        PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
                     }
                 }
-                Util.addPhylogeniesToTabs( phys,
-                                           new File( url.getFile() ).getName(),
-                                           new File( url.getFile() ).toString(),
-                                           getConfiguration(),
-                                           getMainPanel() );
+                AptxUtil.addPhylogeniesToTabs( phys,
+                                               new File( url.getFile() ).getName(),
+                                               new File( url.getFile() ).toString(),
+                                               getConfiguration(),
+                                               getMainPanel() );
                 _mainpanel.getControlPanel().showWhole();
             }
         }
@@ -2098,7 +2229,7 @@ public final class MainFrameApplication extends MainFrame {
         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
             if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
                 try {
-                    final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
+                    final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
                     t = trees[ 0 ];
                 }
                 catch ( final Exception e ) {
@@ -2108,7 +2239,7 @@ public final class MainFrameApplication extends MainFrame {
             }
             else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
                 try {
-                    final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
+                    final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
                     t = trees[ 0 ];
                 }
                 catch ( final Exception e ) {
@@ -2119,7 +2250,7 @@ public final class MainFrameApplication extends MainFrame {
             // "*.*":
             else {
                 try {
-                    final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
+                    final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
                     t = trees[ 0 ];
                 }
                 catch ( final Exception e ) {
@@ -2193,11 +2324,7 @@ public final class MainFrameApplication extends MainFrame {
 
     private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
         nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
-        ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
-        if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
-            te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
-        }
-        nhx.setTaxonomyExtraction( te );
+        nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
     }
 
     private void writeAllToFile() {
@@ -2256,7 +2383,7 @@ public final class MainFrameApplication extends MainFrame {
     private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
         try {
             final PhylogenyWriter writer = new PhylogenyWriter();
-            writer.toNewHampshire( t, false, true, file );
+            writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
         }
         catch ( final Exception e ) {
             exception = true;
@@ -2268,7 +2395,7 @@ public final class MainFrameApplication extends MainFrame {
     private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
         try {
             final PhylogenyWriter writer = new PhylogenyWriter();
-            writer.toNexus( file, t );
+            writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
         }
         catch ( final Exception e ) {
             exception = true;
@@ -2301,20 +2428,20 @@ public final class MainFrameApplication extends MainFrame {
         return exception;
     }
 
-    private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
+    void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
                                                                    _mainpanel.getCurrentTreePanel().getHeight(),
                                                                    true );
         String file_written_to = "";
         boolean error = false;
         try {
-            file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
-                                                                 _mainpanel.getCurrentTreePanel().getWidth(),
-                                                                 _mainpanel.getCurrentTreePanel().getHeight(),
-                                                                 _mainpanel.getCurrentTreePanel(),
-                                                                 _mainpanel.getControlPanel(),
-                                                                 type,
-                                                                 getOptions() );
+            file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
+                                                                     _mainpanel.getCurrentTreePanel().getWidth(),
+                                                                     _mainpanel.getCurrentTreePanel().getHeight(),
+                                                                     _mainpanel.getCurrentTreePanel(),
+                                                                     _mainpanel.getControlPanel(),
+                                                                     type,
+                                                                     getOptions() );
         }
         catch ( final IOException e ) {
             error = true;
@@ -2526,10 +2653,21 @@ public final class MainFrameApplication extends MainFrame {
         return new MainFrameApplication( phys, config, title );
     }
 
+    public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
+        return new MainFrameApplication( phys, config );
+    }
+
     static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
         return new MainFrameApplication( phys, config_file_name, title );
     }
 
+    public static MainFrame createInstance( final Phylogeny[] phys,
+                                            final Configuration config,
+                                            final String title,
+                                            final File current_dir ) {
+        return new MainFrameApplication( phys, config, title, current_dir );
+    }
+
     static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
         mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
                 + o.getPrintSizeY() + ")" );