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/forester
25 // javac -cp ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester/java/forester.jar
26 // ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester_applications/src/org/forester/applications/get_loss_nodes.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.get_loss_nodes
31 package org.forester.applications;
34 import java.io.IOException;
35 import java.util.List;
37 import org.forester.io.parsers.PhylogenyParser;
38 import org.forester.phylogeny.Phylogeny;
39 import org.forester.phylogeny.PhylogenyNode;
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.ForesterUtil;
45 public class get_loss_nodes {
47 public static void main( final String args[] ) {
48 if ( args.length != 2 ) {
49 System.out.println( "get_loss_nodes: Wrong number of arguments" );
50 System.out.println( "Usage: \"get_loss_nodes <phylogeny file> <file with characters>\"" );
53 final File phylogeny_infile = new File( args[ 0 ] );
56 final PhylogenyParser pp = org.forester.io.parsers.util.ParserUtils
57 .createParserDependingOnFileType( phylogeny_infile, true );
58 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
59 p = factory.create( phylogeny_infile, pp )[ 0 ];
61 catch ( final Exception e ) {
65 List<String> chars = null;
67 chars = ForesterUtil.file2list( new File( args[ 1 ] ) );
69 catch ( final IOException e ) {
73 for( final String c : chars ) {
74 boolean found = false;
75 for( final PhylogenyNodeIterator it = p.iteratorPostorder(); it.hasNext(); ) {
76 final PhylogenyNode n = it.next();
77 if ( n.getNodeData().getBinaryCharacters().getLostCharacters().contains( c ) ) {
78 if ( n.getNodeData().isHasTaxonomy()
79 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
80 System.out.println( c + "\t" + n.getNodeData().getTaxonomy().getScientificName() );
83 System.out.println( c + "\t" + n.getName() );
89 System.out.println( c + "\t" + "never lost" );