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: www.phylosoft.org/forester
26 package org.forester.archaeopteryx;
30 import org.forester.io.parsers.PhylogenyParser;
31 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
32 import org.forester.io.parsers.nhx.NHXParser;
33 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
34 import org.forester.phylogeny.Phylogeny;
35 import org.forester.util.ForesterUtil;
38 // java -javaagent:shiftone-jrat.jar -cp
39 // $HOME/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester-atv/java/forester.jar:.
40 // org.forester.archaeopteryx.Archaeopteryx
41 // -c $HOME/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester-atv/_aptx_configuration_file
43 public final class Archaeopteryx {
45 public static MainFrame createApplication( final Phylogeny phylogeny ) {
46 final Phylogeny[] phylogenies = new Phylogeny[ 1 ];
47 phylogenies[ 0 ] = phylogeny;
48 return createApplication( phylogenies, "", "" );
51 public static MainFrame createApplication( final Phylogeny[] phylogenies ) {
52 return createApplication( phylogenies, "", "" );
55 public static MainFrame createApplication( final Phylogeny[] phylogenies,
56 final String config_file_name,
57 final String title ) {
58 return MainFrameApplication.createInstance( phylogenies, config_file_name, title );
61 public static void main( final String args[] ) {
62 Phylogeny[] phylogenies = null;
63 String config_filename = null;
64 Configuration conf = null;
67 int filename_index = 0;
68 if ( args.length == 0 ) {
69 conf = new Configuration( null, false, false );
71 else if ( args.length > 0 ) {
72 // check for a config file
73 if ( args[ 0 ].startsWith( "-c" ) ) {
74 config_filename = args[ 1 ];
77 if ( args[ 0 ].startsWith( "-open" ) ) {
80 conf = new Configuration( config_filename, false, false );
81 if ( args.length > filename_index ) {
82 f = new File( args[ filename_index ] );
83 final String err = ForesterUtil.isReadableFile( f );
84 if ( !ForesterUtil.isEmpty( err ) ) {
85 ForesterUtil.fatalError( Constants.PRG_NAME, err );
87 boolean nhx_or_nexus = false;
88 final PhylogenyParser p = ForesterUtil.createParserDependingOnFileType( f, conf
89 .isValidatePhyloXmlAgainstSchema() );
90 if ( p instanceof NHXParser ) {
92 final NHXParser nhx = ( NHXParser ) p;
93 nhx.setReplaceUnderscores( conf.isReplaceUnderscoresInNhParsing() );
94 nhx.setIgnoreQuotes( false );
95 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
96 if ( conf.isExtractPfamTaxonomyCodesInNhParsing() ) {
97 te = ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY;
99 nhx.setTaxonomyExtraction( te );
101 else if ( p instanceof NexusPhylogeniesParser ) {
103 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) p;
104 nex.setReplaceUnderscores( conf.isReplaceUnderscoresInNhParsing() );
105 nex.setIgnoreQuotes( false );
107 else if ( p instanceof PhyloXmlParser ) {
108 MainFrameApplication.warnIfNotPhyloXmlValidation( conf );
110 phylogenies = ForesterUtil.readPhylogenies( p, f );
111 if ( nhx_or_nexus && conf.isInternalNumberAreConfidenceForNhParsing() ) {
112 for( final Phylogeny phy : phylogenies ) {
113 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
119 catch ( final Exception e ) {
120 ForesterUtil.fatalError( Constants.PRG_NAME, "failed to start: " + e.getLocalizedMessage() );
127 MainFrameApplication.createInstance( phylogenies, conf, title );
129 catch ( final Exception ex ) {
130 Util.unexpectedException( ex );
132 catch ( final Error err ) {
133 Util.unexpectedError( err );