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
26 package org.forester.application;
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;
38 public class simple_node_processor {
40 private final static String BASE = "b_";
42 public static void main( final String args[] ) {
45 if ( ( args.length != 2 ) ) {
47 if ( ( args.length == 0 ) ) {
48 in = new File( "C:\\Users\\zma\\dollo.xml" );
53 System.out.println( "..." );
54 CommandLineArguments cla = null;
55 cla = new CommandLineArguments( args );
56 // in = cla.getFile( 0 );
57 // out = cla.getFile( 1 );
58 // if ( out.exists() ) {
59 // System.out.println( out + " already exists" );
62 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
63 final PhyloXmlParser xml_parser = new PhyloXmlParser();
64 final Phylogeny[] phylogenies_0 = factory.create( in, xml_parser );
65 final Phylogeny phylogeny_0 = phylogenies_0[ 0 ];
66 final PhylogenyNodeIterator it = phylogeny_0.iteratorPostorder();
68 while ( it.hasNext() ) {
69 final PhylogenyNode node = it.next();
70 processNode( node, i );
73 // final PhylogenyWriter writer = new PhylogenyWriter();
74 // writer.toPhyloXML( out, phylogeny_0, 0 );
76 catch ( final Exception e ) {
77 System.out.println( e.getLocalizedMessage() );
83 // private static void processNode( final PhylogenyNode node, final int i ) {
84 // node.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
85 // if ( !node.isExternal() ) {
86 // if ( ( node.getName() == null ) || node.getName().isEmpty() ) {
87 // node.setName( BASE + i );
91 private static void processNode( final PhylogenyNode node, final int i ) {
92 if ( node.isExternal() ) {
93 final String c = "" + node.getNodeData().getBinaryCharacters().getPresentCount();
94 final String s = node.getNodeData().getTaxonomy().getScientificName();
95 System.out.println( s + "\t" + c );