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
25 // javac -cp ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester/java/forester.jar
26 // ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester_applications/src/org/forester/applications/simple_node_processor.java
28 // /home/czmasek/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester_applications/src/:/home/czmasek/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester/java/forester.jar
29 // org.forester.applications.simple_node_processor
31 package org.forester.applications;
35 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
36 import org.forester.io.writers.PhylogenyWriter;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyNode;
39 import org.forester.phylogeny.data.Taxonomy;
40 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
41 import org.forester.phylogeny.factories.PhylogenyFactory;
42 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
43 import org.forester.util.CommandLineArguments;
44 import org.forester.util.ForesterUtil;
46 public class simple_node_processor {
48 public static void main( final String args[] ) {
50 final File out = null;
52 CommandLineArguments cla = null;
53 cla = new CommandLineArguments( args );
54 in = cla.getFile( 0 );
55 // in = new File( "");
56 //out = cla.getFile( 1 );
57 // if ( out.exists() ) {
58 // System.out.println( out + " already exists" );
61 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
62 final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
63 final Phylogeny[] phylogenies_0 = factory.create( in, xml_parser );
64 final Phylogeny phylogeny_0 = phylogenies_0[ 0 ];
65 final PhylogenyNodeIterator it = phylogeny_0.iteratorPostorder();
67 while ( it.hasNext() ) {
68 final PhylogenyNode node = it.next();
69 processNode( node, i, phylogeny_0 );
72 final PhylogenyWriter writer = new PhylogenyWriter();
73 //writer.toPhyloXML( out, phylogeny_0, 0 );
75 catch ( final Exception e ) {
76 System.out.println( e.getLocalizedMessage() );
82 // private static void processNode( final PhylogenyNode node, final int i ) {
83 // node.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
84 // if ( !node.isExternal() ) {
85 // if ( ( node.getName() == null ) || node.getName().isEmpty() ) {
86 // node.setName( BASE + i );
90 private static void processNode( final PhylogenyNode node, final int i, final Phylogeny phy ) {
91 //if ( node.isExternal() ) {
92 // final String c = "" + node.getNodeData().getBinaryCharacters().getPresentCount();
93 // final String s = node.getNodeData().getTaxonomy().getScientificName();
94 // System.out.println( s + "\t" + c );
96 // if ( !node.isExternal() ) {
97 // if ( !node.getNodeData().isHasTaxonomy() ) {
98 // if ( !ForesterUtil.isEmpty( node.getName() ) ) {
99 // if ( ( node.getName().indexOf( "_" ) < 0 ) && ( node.getName().indexOf( "&" ) < 0 )
100 // && ( node.getName().indexOf( " " ) < 0 ) ) {
101 // Taxonomy t = new Taxonomy();
102 // t.setScientificName( node.getName() );
103 // node.getNodeData().addTaxonomy( t );
104 // node.setName( "" );
109 if ( node.isExternal() ) {
110 //final Taxonomy t = node.getNodeData().getTaxonomy();
111 //System.out.println( t.getTaxonomyCode() + "\t" + t.getScientificName() + "\t" + t.getCommonName()
113 // if ( node.getNodeData().isHasTaxonomy() ) {
114 // final Taxonomy t = node.getNodeData().getTaxonomy();
115 // if ( !ForesterUtil.isEmpty( t.getTaxonomyCode() ) && ( t.getTaxonomyCode().length() == 5 ) ) {
116 // if ( node.getName().equalsIgnoreCase( t.getTaxonomyCode() ) ) {
117 // node.setName( "" );
121 if ( node.getNodeData().isHasTaxonomy() ) {
122 final Taxonomy t = node.getNodeData().getTaxonomy();
123 if ( !ForesterUtil.isEmpty( t.getTaxonomyCode() ) ) {
124 final String c = t.getTaxonomyCode();
125 if ( c.indexOf( "XX" ) == 3 ) {
126 System.out.println( "FAKE_CODE_TO_ID_MAP.put( \"" + c + "\", " + t.getIdentifier().getValue()
129 // SurfacingUtil.obtainHexColorStringDependingOnTaxonomyGroup( t.getTaxonomyCode(), phy );