in progress
[jalview.git] / forester / java / src / org / forester / application / printSameOrder.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
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.
13 //
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.
18 //
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.application;
27
28 import java.io.File;
29 import java.io.FileWriter;
30 import java.io.PrintWriter;
31
32 import org.forester.io.parsers.PhylogenyParser;
33 import org.forester.io.parsers.util.ParserUtils;
34 import org.forester.phylogeny.Phylogeny;
35 import org.forester.phylogeny.PhylogenyNode;
36 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
37 import org.forester.phylogeny.factories.PhylogenyFactory;
38
39 public class printSameOrder {
40
41     public static void main( final String args[] ) {
42         Phylogeny tree = null;
43         PhylogenyNode node = null;
44         PrintWriter out = null;
45         File infile = null, outfile = null;
46         if ( args.length != 2 ) {
47             System.err.println( "\nprintSameOrder: Wrong number of arguments." );
48             System.err.println( "Usage: \"java printSameOrder <infile> <outfile>\"\n" );
49             System.exit( -1 );
50         }
51         infile = new File( args[ 0 ] );
52         outfile = new File( args[ 1 ] );
53         try {
54             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
55             final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( infile, true );
56             tree = factory.create( infile, pp )[ 0 ];
57         }
58         catch ( final Exception e ) {
59             System.err.println( e + "\nCould not read " + infile + "\n" );
60             System.exit( -1 );
61         }
62         node = tree.getFirstExternalNode();
63         try {
64             out = new PrintWriter( new FileWriter( outfile ), true );
65             while ( node != null ) {
66                 out.println( node.getName() );
67                 node = node.getNextExternalNode();
68             }
69         }
70         catch ( final Exception e ) {
71             System.err.println( e + "\nException during writing.\n" );
72             System.exit( -1 );
73         }
74         finally {
75             out.close();
76         }
77     }
78 }