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.phylogeny.factories.ParserBasedPhylogenyFactory;
36 import org.forester.util.ForesterUtil;
39 // java -javaagent:shiftone-jrat.jar -cp
40 // $HOME/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester-atv/java/forester.jar:.
41 // org.forester.archaeopteryx.Archaeopteryx
42 // -c $HOME/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester-atv/_aptx_configuration_file
44 public final class Archaeopteryx {
46 private final static boolean TEST = false; //TODO remove me!
48 public static MainFrame createApplication( final Phylogeny phylogeny ) {
49 final Phylogeny[] phylogenies = new Phylogeny[ 1 ];
50 phylogenies[ 0 ] = phylogeny;
51 return createApplication( phylogenies, "", "" );
54 public static MainFrame createApplication( final Phylogeny[] phylogenies ) {
55 return createApplication( phylogenies, "", "" );
58 public static MainFrame createApplication( final Phylogeny[] phylogenies,
59 final String config_file_name,
60 final String title ) {
61 return MainFrameApplication.createInstance( phylogenies, config_file_name, title );
64 public static void main( final String args[] ) {
65 Phylogeny[] phylogenies = null;
66 String config_filename = null;
67 Configuration conf = null;
70 int filename_index = 0;
71 if ( args.length == 0 ) {
72 conf = new Configuration( null, false, false );
74 else if ( args.length > 0 ) {
75 // check for a config file
76 if ( args[ 0 ].startsWith( "-c" ) ) {
77 config_filename = args[ 1 ];
80 if ( args[ 0 ].startsWith( "-open" ) ) {
83 conf = new Configuration( config_filename, false, false );
84 if ( args.length > filename_index ) {
85 f = new File( args[ filename_index ] );
86 final String err = ForesterUtil.isReadableFile( f );
87 if ( !ForesterUtil.isEmpty( err ) ) {
88 ForesterUtil.fatalError( Constants.PRG_NAME, err );
90 boolean nhx_or_nexus = false;
91 final PhylogenyParser p = ForesterUtil.createParserDependingOnFileType( f, conf
92 .isValidatePhyloXmlAgainstSchema() );
93 if ( p instanceof NHXParser ) {
95 final NHXParser nhx = ( NHXParser ) p;
96 nhx.setReplaceUnderscores( conf.isReplaceUnderscoresInNhParsing() );
97 nhx.setIgnoreQuotes( false );
98 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
99 if ( conf.isExtractPfamTaxonomyCodesInNhParsing() ) {
100 te = ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY;
102 nhx.setTaxonomyExtraction( te );
104 else if ( p instanceof NexusPhylogeniesParser ) {
106 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) p;
107 nex.setReplaceUnderscores( conf.isReplaceUnderscoresInNhParsing() );
108 nex.setIgnoreQuotes( false );
110 else if ( p instanceof PhyloXmlParser ) {
111 MainFrameApplication.warnIfNotPhyloXmlValidation( conf );
113 phylogenies = ForesterUtil.readPhylogenies( p, f );
114 if ( nhx_or_nexus && conf.isInternalNumberAreConfidenceForNhParsing() ) {
115 for( final Phylogeny phy : phylogenies ) {
116 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
120 // Phylogeny py = phylogenies[ 0 ];
121 // for( final PhylogenyNodeIterator iter = py.iteratorExternalForward(); iter.hasNext(); ) {
122 // final PhylogenyNode node = iter.next();
123 // System.out.println( node.getNodeData().getTaxonomy().getScientificName() + "\t"
124 // + node.getNodeData().getBinaryCharacters().getPresentCount() );
126 // for( final PhylogenyNodeIterator iter = py.iteratorPreorder(); iter.hasNext(); ) {
127 // final PhylogenyNode node = iter.next();
128 // if ( !node.isExternal() ) {
129 // System.out.println( node.getNodeData().getTaxonomy().getScientificName() + "\t"
130 // + node.getNodeData().getBinaryCharacters().getPresentCount() );
137 catch ( final Exception e ) {
138 ForesterUtil.fatalError( Constants.PRG_NAME, "failed to start: " + e.getLocalizedMessage() );
147 s = "/home/czmasek/888.xml";
148 if ( ForesterUtil.isReadableFile( s ) != null ) {
149 s = "/Users/zma/888.xml";
150 if ( ForesterUtil.isReadableFile( s ) != null ) {
152 if ( ForesterUtil.isReadableFile( s ) != null ) {
153 s = "C:\\Documents and Settings\\czmasek\\";
159 MainFrameApplication.createInstance( phylogenies, conf, title );
162 MainFrameApplication.createInstance( ParserBasedPhylogenyFactory.getInstance()
163 .create( s, new PhyloXmlParser() ),
168 // catch ( final IOException ex ) {
169 // ForesterUtil.fatalError( Constants.PRG_NAME, "failed to start: " + ex.getLocalizedMessage() );
171 catch ( final Exception ex ) {
172 Util.unexpectedException( ex );
174 catch ( final Error err ) {
175 Util.unexpectedError( err );