in progress
[jalview.git] / forester / java / src / org / forester / application / simple_node_processor.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
25
26 package org.forester.application;
27
28 import java.io.File;
29
30 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
31 import org.forester.phylogeny.Phylogeny;
32 import org.forester.phylogeny.PhylogenyNode;
33 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
34 import org.forester.phylogeny.factories.PhylogenyFactory;
35 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
36 import org.forester.util.CommandLineArguments;
37
38 public class simple_node_processor {
39
40     private final static String BASE = "b_";
41
42     public static void main( final String args[] ) {
43         File in = null;
44         final File out = null;
45         try {
46             CommandLineArguments cla = null;
47             cla = new CommandLineArguments( args );
48             in = cla.getFile( 0 );
49             // out = cla.getFile( 1 );
50             // if ( out.exists() ) {
51             //      System.out.println( out + " already exists" );
52             //      System.exit( -1 );
53             //  }
54             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
55             final PhyloXmlParser xml_parser = new PhyloXmlParser();
56             final Phylogeny[] phylogenies_0 = factory.create( in, xml_parser );
57             final Phylogeny phylogeny_0 = phylogenies_0[ 0 ];
58             final PhylogenyNodeIterator it = phylogeny_0.iteratorPostorder();
59             int i = 0;
60             while ( it.hasNext() ) {
61                 final PhylogenyNode node = it.next();
62                 processNode( node, i );
63                 i++;
64             }
65             //  final PhylogenyWriter writer = new PhylogenyWriter();
66             //  writer.toPhyloXML( out, phylogeny_0, 0 );
67         }
68         catch ( final Exception e ) {
69             System.out.println( e.getLocalizedMessage() );
70             e.printStackTrace();
71             System.exit( -1 );
72         }
73     }
74
75     //    private static void processNode( final PhylogenyNode node, final int i ) {
76     //        node.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
77     //        if ( !node.isExternal() ) {
78     //            if ( ( node.getName() == null ) || node.getName().isEmpty() ) {
79     //                node.setName( BASE + i );
80     //            }
81     //        }
82     //    }
83     private static void processNode( final PhylogenyNode node, final int i ) {
84         if ( node.isExternal() ) {
85             final String c = "" + node.getNodeData().getBinaryCharacters().getPresentCount();
86             final String s = node.getNodeData().getTaxonomy().getScientificName();
87             System.out.println( s + "\t" + c );
88         }
89     }
90 }