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: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.application;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.forester.io.parsers.PhylogenyParser;
34 import org.forester.io.parsers.util.ParserUtils;
35 import org.forester.io.writers.PhylogenyWriter;
36 import org.forester.phylogeny.Phylogeny;
37 import org.forester.phylogeny.PhylogenyMethods;
38 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
39 import org.forester.phylogeny.factories.PhylogenyFactory;
40 import org.forester.util.CommandLineArguments;
41 import org.forester.util.ForesterUtil;
43 public class nhx_too {
45 final static private String PRG_NAME = "nhx_too";
46 final static private String PRG_VERSION = "0.1";
47 final static private String PRG_DATE = "2008.03.04";
48 final static private String INT_NODE_NAME_IS_SUPPORT = "is";
50 public static void main( final String args[] ) {
51 ForesterUtil.printProgramInformation( nhx_too.PRG_NAME, nhx_too.PRG_VERSION, nhx_too.PRG_DATE );
52 if ( ( args.length < 3 ) || ( args.length > 3 ) ) {
54 System.out.println( nhx_too.PRG_NAME + ": wrong number of arguments" );
56 System.out.println( "Usage: \"" + nhx_too.PRG_NAME + " [options] <infile> <outfile>\n" );
57 System.out.println( " Options: -" + nhx_too.INT_NODE_NAME_IS_SUPPORT
58 + ": internal node names are support values (i.e. MrBayes output)" );
62 CommandLineArguments cla = null;
64 cla = new CommandLineArguments( args );
66 catch ( final Exception e ) {
67 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
69 final List<String> allowed_options = new ArrayList<String>();
70 allowed_options.add( nhx_too.INT_NODE_NAME_IS_SUPPORT );
71 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
72 if ( dissallowed_options.length() > 0 ) {
73 ForesterUtil.fatalError( nhx_too.PRG_NAME, "Unknown option(s): " + dissallowed_options );
75 final File phylogeny_infile = cla.getFile( 0 );
76 final File phylogeny_outfile = cla.getFile( 1 );
77 boolean int_node_name_is_support = false;
78 if ( cla.isOptionSet( nhx_too.INT_NODE_NAME_IS_SUPPORT ) ) {
79 int_node_name_is_support = true;
83 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
84 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( phylogeny_infile, true );
85 p = factory.create( phylogeny_infile, pp )[ 0 ];
87 catch ( final Exception e ) {
88 ForesterUtil.fatalError( nhx_too.PRG_NAME, "Could not read \"" + phylogeny_infile + "\" [" + e.getMessage()
91 if ( int_node_name_is_support ) {
93 PhylogenyMethods.transferInternalNodeNamesToConfidence( p );
95 catch ( final Exception e ) {
96 ForesterUtil.unexpectedFatalError( nhx_too.PRG_NAME,
97 "Failure during moving of internal names to support values ["
98 + e.getMessage() + "]" );
102 final PhylogenyWriter w = new PhylogenyWriter();
103 w.toNewHampshireX( p, phylogeny_outfile );
105 catch ( final IOException e ) {
106 ForesterUtil.fatalError( nhx_too.PRG_NAME, "Failure to write output [" + e.getMessage() + "]" );
108 System.out.println();
109 System.out.println( "Done [wrote \"" + phylogeny_outfile + "\"]." );
110 System.out.println();