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.AnalysisMulti;
35 import org.forester.clade_analysis.AnalysisSingle;
36 import org.forester.clade_analysis.Prefix;
37 import org.forester.clade_analysis.ResultMulti;
38 import org.forester.clade_analysis.ResultSingle;
39 import org.forester.io.parsers.PhylogenyParser;
40 import org.forester.io.parsers.util.ParserUtils;
41 import org.forester.phylogeny.Phylogeny;
42 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
43 import org.forester.phylogeny.factories.PhylogenyFactory;
44 import org.forester.util.CommandLineArguments;
45 import org.forester.util.ForesterUtil;
47 public final class cladinator {
49 final static private String PRG_NAME = "cladinator";
50 final static private String PRG_VERSION = "0.100";
51 final static private String PRG_DATE = "170823";
52 final static private String PRG_DESC = "clades within clades -- analysis of pplacer type outputs";
53 final static private String E_MAIL = "phyloxml@gmail.com";
54 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester";
55 final static private String HELP_OPTION_1 = "help";
56 final static private String HELP_OPTION_2 = "h";
57 final static private String SEP_OPTION = "s";
58 private final static DecimalFormat df2 = new DecimalFormat( "0.0#" );
60 public static void main( final String args[] ) {
62 ForesterUtil.printProgramInformation( PRG_NAME,
68 ForesterUtil.getForesterLibraryInformation() );
69 CommandLineArguments cla = null;
71 cla = new CommandLineArguments( args );
73 catch ( final Exception e ) {
74 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
76 if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) ) {
81 else if ( ( args.length != 2 && args.length != 3 ) ) {
83 System.out.println( "Wrong number of arguments." );
88 final List<String> allowed_options = new ArrayList<String>();
89 allowed_options.add( SEP_OPTION );
90 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
91 if ( dissallowed_options.length() > 0 ) {
92 ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options );
94 final String separator;
95 if ( cla.isOptionSet( SEP_OPTION ) ) {
96 separator = cla.getOptionValue( SEP_OPTION );
101 final File intreefile = cla.getFile( 0 );
102 final String query = cla.getName( 1 );
103 System.out.println( "Input tree: " + intreefile );
104 System.out.println( "Query : " + query );
105 if ( !ForesterUtil.isEmpty( separator ) ) {
106 System.out.println( "Separator : " + separator );
109 System.out.println( "Separator : none" );
113 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
114 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile, true );
115 p = factory.create( intreefile, pp )[ 0 ];
117 catch ( final IOException e ) {
118 System.out.println( "\nCould not read \"" + intreefile + "\" [" + e.getMessage() + "]\n" );
122 final ResultMulti res = AnalysisMulti.execute( p, query, separator, 0.5 );
124 System.out.println();
125 System.out.println( "Result:" );
126 System.out.println( "Query : " + query );
132 System.out.println( "Collapsed:" );
134 for( final Prefix prefix : res.getCollapsedMultiHitPrefixes() ) {
135 System.out.println( prefix );
137 if ( _has_specifics ) {
139 System.out.println( "Specifics:" );
141 for( final Prefix prefix : _cleaned_spec ) {
142 System.out.println( prefix );
146 System.out.println( "Collapsed With Specifics:" );
148 for( final Prefix prefix : _collapsed ) {
149 System.out.println( prefix );
151 for( final Prefix spec : _cleaned_spec ) {
152 if ( spec.getPrefix().startsWith( prefix.getPrefix() ) ) {
153 System.out.println( " " + spec );
159 if ( !ForesterUtil.isEmpty( _all_down ) ) {
161 System.out.println( "Collapsed Down:" );
163 for( final Prefix prefix : _collapsed_down ) {
164 System.out.println( prefix );
169 if ( !ForesterUtil.isEmpty( _all_up ) ) {
172 System.out.println( "Collapsed Up:" );
174 for( final Prefix prefix : _collapsed_up ) {
175 System.out.println( prefix );
184 System.out.print( "Greatest Common Prefix : " + res.getGreatestCommonPrefix() );
185 if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefix() )
186 && !ForesterUtil.isEmpty( res.getGreatestCommonCladeSubtreeConfidence() ) ) {
187 System.out.println( "\t(" + res.getGreatestCommonCladeSubtreeConfidence() + ")" );
190 System.out.println();
192 System.out.print( "Greatest Common Prefix Up : " + res.getGreatestCommonPrefixUp() );
193 if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefixUp() )
194 && !ForesterUtil.isEmpty( res.getGreatestCommonCladeUpSubtreeConfidence() ) ) {
195 System.out.println( "\t(" + res.getGreatestCommonCladeUpSubtreeConfidence() + ")" );
198 System.out.println();
200 System.out.print( "Greatest Common Prefix Down : " + res.getGreatestCommonPrefixDown() );
201 if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefixDown() )
202 && !ForesterUtil.isEmpty( res.getGreatestCommonCladeDownSubtreeConfidence() ) ) {
203 System.out.println( "\t(" + res.getGreatestCommonCladeDownSubtreeConfidence() + ")" );
206 System.out.println();
208 System.out.println( "Least Encompassing Clade size: " + res.getLeastEncompassingCladeSize()
209 + " external nodes" );
210 final double lec_ratio = ( 100.0 * res.getLeastEncompassingCladeSize() ) / res.getTreeSize();
211 System.out.println( "Least Encompassing Clade size: " + df2.format( lec_ratio ) + "%" );
212 System.out.println( "Total tree size : " + res.getTreeSize() + " external nodes" );
213 if ( res.getWarnings().size() > 0 ) {
214 System.out.println( "Warnings:" );
215 for( final String s : res.getWarnings() ) {
216 System.out.println( s );
219 System.out.println();
221 catch ( final IllegalArgumentException e ) {
222 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
224 catch ( final Exception e ) {
226 ForesterUtil.fatalError( PRG_NAME, "Unexpected errror!" );
230 private final static void print_help() {
231 System.out.println( "Usage:" );
232 System.out.println();
233 System.out.println( PRG_NAME + " [options] <gene tree file> <query>" );
234 System.out.println();
235 System.out.println( " options:" );
236 System.out.println( " -" + SEP_OPTION + "=<separator>: the separator to be used" );
237 System.out.println();
238 System.out.println( "Example:" );
239 System.out.println();
240 System.out.println( " " + PRG_NAME + " -s=. my_tree.xml A.1.1.1" );
241 System.out.println();