+ else {
+ if ( getSeqs() != null ) {
+ final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
+ getPhylogeneticInferenceOptions()
+ .copy(), this );
+ new Thread( inferrer ).start();
+ }
+ else {
+ JOptionPane.showMessageDialog( this,
+ "No input sequences selected",
+ "Phylogenetic Inference Not Launched",
+ JOptionPane.WARNING_MESSAGE );
+ }
+ }
+ }
+ }
+
+ private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
+ final StringBuilder sb = new StringBuilder();
+ final StringBuilder sb_failed = new StringBuilder();
+ int counter = 0;
+ int counter_failed = 0;
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final PhylogenyNodeIterator it = phy.iteratorExternalForward();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ final String name = n.getName().trim();
+ if ( !ForesterUtil.isEmpty( name ) ) {
+ final String nt = ParserUtils.extractTaxonomyDataFromNodeName( n,
+ TAXONOMY_EXTRACTION.AGGRESSIVE );
+ if ( !ForesterUtil.isEmpty( nt ) ) {
+ if ( counter < 15 ) {
+ sb.append( name + ": " + nt + "\n" );
+ }
+ else if ( counter == 15 ) {
+ sb.append( "...\n" );
+ }
+ counter++;
+ }
+ else {
+ if ( counter_failed < 15 ) {
+ sb_failed.append( name + "\n" );
+ }
+ else if ( counter_failed == 15 ) {
+ sb_failed.append( "...\n" );
+ }
+ counter_failed++;
+ }
+ }
+ }
+ if ( counter > 0 ) {
+ String failed = "";
+ String all = "all ";
+ if ( counter_failed > 0 ) {
+ all = "";
+ failed = "\nCould not extract taxonomic data for " + counter_failed
+ + " named external nodes:\n" + sb_failed;
+ }
+ JOptionPane.showMessageDialog( this,
+ "Extracted taxonomic data from " + all + counter
+ + " named external nodes:\n" + sb.toString() + failed,
+ "Taxonomic Data Extraction Completed",
+ counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
+ : JOptionPane.INFORMATION_MESSAGE );
+ }
+ else {
+ JOptionPane
+ .showMessageDialog( this,
+ "Could not extract any taxonomic data.\nMaybe node names are empty\n"
+ + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
+ + "or nodes already have taxonomic data?\n",
+ "No Taxonomic Data Extracted",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+
+ private ControlPanel getControlPanel() {
+ return getMainPanel().getControlPanel();
+ }
+
+ private File getCurrentDir() {
+ if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
+ if ( ForesterUtil.isWindows() ) {
+ try {
+ _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
+ }
+ catch ( final Exception e ) {
+ _current_dir = null;
+ }
+ }
+ }
+ if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
+ if ( System.getProperty( "user.home" ) != null ) {
+ _current_dir = new File( System.getProperty( "user.home" ) );
+ }
+ else if ( System.getProperty( "user.dir" ) != null ) {
+ _current_dir = new File( System.getProperty( "user.dir" ) );
+ }
+ }
+ return _current_dir;
+ }
+
+ private double getMinNotCollapseConfidenceValue() {
+ return _min_not_collapse;
+ }
+
+ private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
+ if ( _phylogenetic_inference_options == null ) {
+ _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
+ }
+ return _phylogenetic_inference_options;
+ }
+
+ private boolean isUnsavedDataPresent() {
+ final List<TreePanel> tps = getMainPanel().getTreePanels();
+ for( final TreePanel tp : tps ) {
+ if ( tp.isEdited() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ PhylogenyMethods
+ .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
+ }
+ }
+ }
+
+ private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ PhylogenyMethods.transferNodeNameToField( phy,
+ PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
+ false );
+ }
+ }
+ }
+
+ private void newTree() {
+ final Phylogeny[] phys = new Phylogeny[ 1 ];
+ final Phylogeny phy = new Phylogeny();
+ final PhylogenyNode node = new PhylogenyNode();
+ phy.setRoot( node );
+ phy.setRooted( true );
+ phys[ 0 ] = phy;
+ AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
+ _mainpanel.getControlPanel().showWhole();
+ _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
+ _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
+ if ( getMainPanel().getMainFrame() == null ) {
+ // Must be "E" applet version.
+ ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
+ .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
+ }
+ else {
+ getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
+ }
+ activateSaveAllIfNeeded();
+ System.gc();
+ }
+
+ private void obtainDetailedTaxonomicInformation() {
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final TaxonomyDataManager t = new TaxonomyDataManager( this,
+ _mainpanel.getCurrentTreePanel(),
+ phy.copy(),
+ false,
+ true );
+ new Thread( t ).start();
+ }
+ }
+ }
+
+ private void obtainDetailedTaxonomicInformationDelete() {
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final TaxonomyDataManager t = new TaxonomyDataManager( this,
+ _mainpanel.getCurrentTreePanel(),
+ phy.copy(),
+ true,
+ true );
+ new Thread( t ).start();
+ }
+ }
+ }
+
+ private void obtainSequenceInformation() {
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final SequenceDataRetriver u = new SequenceDataRetriver( this,
+ _mainpanel.getCurrentTreePanel(),
+ phy.copy() );
+ new Thread( u ).start();
+ }
+ }
+ }
+
+ private void print() {
+ if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
+ || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
+ return;
+ }
+ if ( !getOptions().isPrintUsingActualSize() ) {
+ getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80,
+ getOptions().getPrintSizeY() - 140,
+ true );
+ getCurrentTreePanel().resetPreferredSize();
+ getCurrentTreePanel().repaint();
+ }
+ final String job_name = Constants.PRG_NAME;
+ boolean error = false;
+ String printer_name = null;
+ try {
+ printer_name = Printer.print( getCurrentTreePanel(), job_name );
+ }
+ catch ( final Exception e ) {
+ error = true;
+ JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
+ }
+ if ( !error && ( printer_name != null ) ) {
+ String msg = "Printing data sent to printer";
+ if ( printer_name.length() > 1 ) {
+ msg += " [" + printer_name + "]";
+ }
+ JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
+ }
+ if ( !getOptions().isPrintUsingActualSize() ) {
+ getControlPanel().showWhole();
+ }
+ }
+
+ private void printPhylogenyToPdf( final String file_name ) {
+ if ( !getOptions().isPrintUsingActualSize() ) {
+ getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(),
+ getOptions().getPrintSizeY(),
+ true );
+ getCurrentTreePanel().resetPreferredSize();
+ getCurrentTreePanel().repaint();
+ }
+ String pdf_written_to = "";
+ boolean error = false;
+ try {
+ if ( getOptions().isPrintUsingActualSize() ) {
+ pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
+ getCurrentTreePanel(),
+ getCurrentTreePanel().getWidth(),
+ getCurrentTreePanel().getHeight() );
+ }
+ else {
+ pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
+ .getPrintSizeX(), getOptions().getPrintSizeY() );
+ }
+ }
+ catch ( final IOException e ) {
+ error = true;
+ JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
+ }
+ if ( !error ) {
+ if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
+ JOptionPane.showMessageDialog( this,
+ "Wrote PDF to: " + pdf_written_to,
+ "Information",
+ JOptionPane.INFORMATION_MESSAGE );
+ }
+ else {
+ JOptionPane.showMessageDialog( this,
+ "There was an unknown problem when attempting to write to PDF file: \""
+ + file_name + "\"",
+ "Error",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ if ( !getOptions().isPrintUsingActualSize() ) {
+ getControlPanel().showWhole();
+ }
+ }
+
+ private void readPhylogeniesFromFile() {
+ boolean exception = false;
+ Phylogeny[] phys = null;
+ // Set an initial directory if none set yet
+ final File my_dir = getCurrentDir();
+ _open_filechooser.setMultiSelectionEnabled( true );
+ // Open file-open dialog and set current directory
+ if ( my_dir != null ) {
+ _open_filechooser.setCurrentDirectory( my_dir );
+ }
+ final int result = _open_filechooser.showOpenDialog( _contentpane );
+ // All done: get the file
+ final File[] files = _open_filechooser.getSelectedFiles();
+ setCurrentDir( _open_filechooser.getCurrentDirectory() );
+ boolean nhx_or_nexus = false;
+ if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
+ for( final File file : files ) {
+ if ( ( file != null ) && !file.isDirectory() ) {
+ if ( _mainpanel.getCurrentTreePanel() != null ) {
+ _mainpanel.getCurrentTreePanel().setWaitCursor();
+ }
+ else {
+ _mainpanel.setWaitCursor();
+ }
+ if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
+ || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
+ try {
+ final NHXParser nhx = new NHXParser();
+ setSpecialOptionsForNhxParser( nhx );
+ phys = PhylogenyMethods.readPhylogenies( nhx, file );
+ nhx_or_nexus = true;
+ }
+ catch ( final Exception e ) {
+ exception = true;
+ exceptionOccuredDuringOpenFile( e );
+ }
+ }
+ else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
+ warnIfNotPhyloXmlValidation( getConfiguration() );
+ try {
+ final PhyloXmlParser xml_parser = createPhyloXmlParser();
+ phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
+ }
+ catch ( final Exception e ) {
+ exception = true;
+ exceptionOccuredDuringOpenFile( e );
+ }
+ }
+ else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
+ try {
+ phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
+ }
+ catch ( final Exception e ) {
+ exception = true;
+ exceptionOccuredDuringOpenFile( e );
+ }
+ }
+ else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
+ try {
+ final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
+ setSpecialOptionsForNexParser( nex );
+ phys = PhylogenyMethods.readPhylogenies( nex, file );
+ nhx_or_nexus = true;
+ }
+ catch ( final Exception e ) {
+ exception = true;
+ exceptionOccuredDuringOpenFile( e );
+ }
+ }
+ // "*.*":
+ else {
+ try {
+ final PhylogenyParser parser = ParserUtils
+ .createParserDependingOnFileType( file, getConfiguration()
+ .isValidatePhyloXmlAgainstSchema() );
+ if ( parser instanceof NexusPhylogeniesParser ) {
+ final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
+ setSpecialOptionsForNexParser( nex );
+ nhx_or_nexus = true;
+ }
+ else if ( parser instanceof NHXParser ) {
+ final NHXParser nhx = ( NHXParser ) parser;
+ setSpecialOptionsForNhxParser( nhx );
+ nhx_or_nexus = true;
+ }
+ else if ( parser instanceof PhyloXmlParser ) {
+ warnIfNotPhyloXmlValidation( getConfiguration() );
+ }
+ phys = PhylogenyMethods.readPhylogenies( parser, file );
+ }
+ catch ( final Exception e ) {
+ exception = true;
+ exceptionOccuredDuringOpenFile( e );
+ }
+ }
+ if ( _mainpanel.getCurrentTreePanel() != null ) {
+ _mainpanel.getCurrentTreePanel().setArrowCursor();
+ }
+ else {
+ _mainpanel.setArrowCursor();
+ }
+ if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
+ boolean one_desc = false;
+ if ( nhx_or_nexus ) {
+ for( final Phylogeny phy : phys ) {
+ if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
+ }
+ if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
+ one_desc = true;
+ break;
+ }
+ }
+ }
+ AptxUtil.addPhylogeniesToTabs( phys,
+ file.getName(),
+ file.getAbsolutePath(),
+ getConfiguration(),
+ getMainPanel() );
+ _mainpanel.getControlPanel().showWhole();
+ if ( nhx_or_nexus && one_desc ) {
+ JOptionPane
+ .showMessageDialog( this,
+ "One or more trees contain (a) node(s) with one descendant, "
+ + ForesterUtil.LINE_SEPARATOR
+ + "possibly indicating illegal parentheses within node names.",
+ "Warning: Possible Error in New Hampshire Formatted Data",
+ JOptionPane.WARNING_MESSAGE );
+ }