- 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() ) {
- ForesterUtil.transferInternalNodeNamesToConfidence( phy );
- }
- if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
- one_desc = true;
- break;
- }
- }
- }
- Util.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 );
- }
- }
- }
- }
- }
- activateSaveAllIfNeeded();
- System.gc();
- }
-
- public void readSeqsFromFile() {
- // Set an initial directory if none set yet
- final File my_dir = getCurrentDir();
- _seqs_filechooser.setMultiSelectionEnabled( false );
- // Open file-open dialog and set current directory
- if ( my_dir != null ) {
- _seqs_filechooser.setCurrentDirectory( my_dir );
- }
- final int result = _seqs_filechooser.showOpenDialog( _contentpane );
- // All done: get the seqs
- final File file = _seqs_filechooser.getSelectedFile();
- setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
- if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
- setSeqsFile( null );
- setSeqs( null );
- List<Sequence> seqs = null;
- try {
- if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
- seqs = FastaParser.parse( new FileInputStream( file ) );
- for( final Sequence seq : seqs ) {
- System.out.println( SequenceWriter.toFasta( seq, 60 ) );
- }
- }
- else {
- //TODO error
- }
- }
- catch ( final MsaFormatException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Multiple sequence file format error",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IOException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Failed to read multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IllegalArgumentException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final Exception e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- e.printStackTrace();
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence file is empty",
- "Illegal multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( seqs.size() < 4 ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence file needs to contain at least 3 sequences",
- "Illegal multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- // if ( msa.getLength() < 2 ) {
- // JOptionPane.showMessageDialog( this,
- // "Multiple sequence alignment needs to contain at least 2 residues",
- // "Illegal multiple sequence file",
- // JOptionPane.ERROR_MESSAGE );
- // return;
- // }
- System.gc();
- setSeqsFile( _seqs_filechooser.getSelectedFile() );
- setSeqs( seqs );
- }
- }
-
- public void readMsaFromFile() {
- // Set an initial directory if none set yet
- final File my_dir = getCurrentDir();
- _msa_filechooser.setMultiSelectionEnabled( false );
- // Open file-open dialog and set current directory
- if ( my_dir != null ) {
- _msa_filechooser.setCurrentDirectory( my_dir );
- }
- final int result = _msa_filechooser.showOpenDialog( _contentpane );
- // All done: get the msa
- final File file = _msa_filechooser.getSelectedFile();
- setCurrentDir( _msa_filechooser.getCurrentDirectory() );
- if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
- setMsaFile( null );
- setMsa( null );
- Msa msa = null;
- try {
- if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
- msa = FastaParser.parseMsa( new FileInputStream( file ) );
- System.out.println( msa.toString() );
- }
- else {
- msa = GeneralMsaParser.parse( new FileInputStream( file ) );
- }
- }
- catch ( final MsaFormatException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Multiple sequence alignment format error",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IOException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Failed to read multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IllegalArgumentException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final Exception e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- e.printStackTrace();
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment is empty",
- "Illegal Multiple Sequence Alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( msa.getNumberOfSequences() < 4 ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment needs to contain at least 3 sequences",
- "Illegal multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( msa.getLength() < 2 ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment needs to contain at least 2 residues",
- "Illegal multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- System.gc();
- setMsaFile( _msa_filechooser.getSelectedFile() );
- setMsa( msa );
- }
- }
-
- @Override
- void readPhylogeniesFromURL() {
- URL url = null;
- Phylogeny[] phys = null;
- final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
- final String url_string = JOptionPane.showInputDialog( this,
- message,
- "Use URL/webservice to obtain a phylogeny",
- JOptionPane.QUESTION_MESSAGE );
- boolean nhx_or_nexus = false;
- if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
- try {
- url = new URL( url_string );
- PhylogenyParser parser = null;
- if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
- parser = new TolParser();
- }
- else {
- parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
- .isValidatePhyloXmlAgainstSchema() );
- }
- if ( parser instanceof NexusPhylogeniesParser ) {
- nhx_or_nexus = true;
- }
- else if ( parser instanceof NHXParser ) {
- nhx_or_nexus = true;
- }
- if ( _mainpanel.getCurrentTreePanel() != null ) {
- _mainpanel.getCurrentTreePanel().setWaitCursor();
- }
- else {
- _mainpanel.setWaitCursor();
- }
- final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- phys = factory.create( url.openStream(), parser );
- }
- catch ( final MalformedURLException e ) {
- JOptionPane.showMessageDialog( this,
- "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
- "Malformed URL",
- JOptionPane.ERROR_MESSAGE );
- }
- catch ( final IOException e ) {
- JOptionPane.showMessageDialog( this,
- "Could not read from " + url + "\n"
- + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
- "Failed to read URL",
- JOptionPane.ERROR_MESSAGE );
- }
- catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this,
- ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
- "Unexpected Exception",
- JOptionPane.ERROR_MESSAGE );
- }
- finally {
- if ( _mainpanel.getCurrentTreePanel() != null ) {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- else {
- _mainpanel.setArrowCursor();
- }
- }
- if ( ( phys != null ) && ( phys.length > 0 ) ) {
- if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
- for( final Phylogeny phy : phys ) {
- ForesterUtil.transferInternalNodeNamesToConfidence( phy );