2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2017 Christian M. Zmasek
6 // Copyright (C) 2017 J. Craig Venter Institute
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: phyloxml @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.application;
29 import java.io.IOException;
30 import java.text.DecimalFormat;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.forester.clade_analysis.Analysis;
35 import org.forester.clade_analysis.Result;
36 import org.forester.io.parsers.PhylogenyParser;
37 import org.forester.io.parsers.util.ParserUtils;
38 import org.forester.phylogeny.Phylogeny;
39 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
40 import org.forester.phylogeny.factories.PhylogenyFactory;
41 import org.forester.util.CommandLineArguments;
42 import org.forester.util.ForesterUtil;
44 public final class cladinator {
46 final static private String PRG_NAME = "cladinator";
47 final static private String PRG_VERSION = "0.101";
48 final static private String PRG_DATE = "170810";
49 final static private String PRG_DESC = "clades within clades -- analysis of pplacer type outputs";
50 final static private String E_MAIL = "phyloxml@gmail.com";
51 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester";
52 final static private String HELP_OPTION_1 = "help";
53 final static private String HELP_OPTION_2 = "h";
54 final static private String SEP_OPTION = "s";
55 private final static DecimalFormat df2 = new DecimalFormat( ".##" );
57 public static void main( final String args[] ) {
59 ForesterUtil.printProgramInformation( PRG_NAME,
65 ForesterUtil.getForesterLibraryInformation() );
66 CommandLineArguments cla = null;
68 cla = new CommandLineArguments( args );
70 catch ( final Exception e ) {
71 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
73 if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) ) {
78 else if ( ( args.length != 2 && args.length != 3 ) ) {
80 System.out.println( "Wrong number of arguments." );
85 final List<String> allowed_options = new ArrayList<String>();
86 allowed_options.add( SEP_OPTION );
87 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
88 if ( dissallowed_options.length() > 0 ) {
89 ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options );
91 final String separator;
92 if ( cla.isOptionSet( SEP_OPTION ) ) {
93 separator = cla.getOptionValue( SEP_OPTION );
98 final File intreefile = cla.getFile( 0 );
99 final String query = cla.getName( 1 );
100 System.out.println( "Input tree: " + intreefile );
101 System.out.println( "Query : " + query );
102 if ( !ForesterUtil.isEmpty( separator ) ) {
103 System.out.println( "Separator : " + separator );
106 System.out.println( "Separator : none" );
110 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
111 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile, true );
112 p = factory.create( intreefile, pp )[ 0 ];
114 catch ( final IOException e ) {
115 System.out.println( "\nCould not read \"" + intreefile + "\" [" + e.getMessage() + "]\n" );
118 final Result res = Analysis.execute( p, query, separator );
119 System.out.println();
120 System.out.println( "Result:" );
121 System.out.println( "Query : " + query );
122 System.out.print( "Greatest Common Prefix : " + res.getGreatestCommonPrefix() );
123 if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefix() )
124 && !ForesterUtil.isEmpty( res.getGreatestCommonCladeSubtreeConfidence() ) ) {
125 System.out.println( "\t(" + res.getGreatestCommonCladeSubtreeConfidence() + ")" );
128 System.out.println();
130 System.out.print( "Greatest Common Prefix Up : " + res.getGreatestCommonPrefixUp() );
131 if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefixUp() )
132 && !ForesterUtil.isEmpty( res.getGreatestCommonCladeUpSubtreeConfidence() ) ) {
133 System.out.println( "\t(" + res.getGreatestCommonCladeUpSubtreeConfidence() + ")" );
136 System.out.println();
138 System.out.print( "Greatest Common Prefix Down : " + res.getGreatestCommonPrefixDown() );
139 if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefixDown() )
140 && !ForesterUtil.isEmpty( res.getGreatestCommonCladeDownSubtreeConfidence() ) ) {
141 System.out.println( "\t(" + res.getGreatestCommonCladeDownSubtreeConfidence() + ")" );
144 System.out.println();
146 System.out.println( "Least Encompassing Clade size: " + res.getLeastEncompassingCladeSize()
147 + " external nodes" );
148 final double lec_ratio = ( 100.0 * res.getLeastEncompassingCladeSize() ) / res.getTreeSize();
149 System.out.println( "Least Encompassing Clade size: " + df2.format( lec_ratio ) + "%" );
150 System.out.println( "Total tree size : " + res.getTreeSize() + " external nodes" );
151 if ( res.getWarnings().size() > 0 ) {
152 System.out.println( "Warnings:" );
153 for( final String s : res.getWarnings() ) {
154 System.out.println( s );
157 System.out.println();
159 catch ( final IllegalArgumentException e ) {
160 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
162 catch ( final Exception e ) {
164 ForesterUtil.fatalError( PRG_NAME, "Unexpected errror!" );
168 private final static void print_help() {
169 System.out.println( "Usage:" );
170 System.out.println();
171 System.out.println( PRG_NAME + " [options] <gene tree file> <query>" );
172 System.out.println();
173 System.out.println( " options:" );
174 System.out.println( " -" + SEP_OPTION + "=<separator>: the separator to be used" );
175 System.out.println();
176 System.out.println( "Example:" );
177 System.out.println();
178 System.out.println( " " + PRG_NAME + " -s=. my_tree.xml A.1.1.1" );
179 System.out.println();