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.text.DecimalFormat;
31 import org.forester.clade_analysis.Analysis;
32 import org.forester.clade_analysis.Result;
33 import org.forester.io.parsers.PhylogenyParser;
34 import org.forester.io.parsers.util.ParserUtils;
35 import org.forester.phylogeny.Phylogeny;
36 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
37 import org.forester.phylogeny.factories.PhylogenyFactory;
38 import org.forester.util.CommandLineArguments;
39 import org.forester.util.ForesterUtil;
41 public final class cladinator {
43 final static private String PRG_NAME = "cladinator";
44 final static private String PRG_VERSION = "0.100";
45 final static private String PRG_DATE = "170721";
46 final static private String PRG_DESC = "clades within clades -- analysis of pplacer type outputs";
47 final static private String E_MAIL = "phyloxml@gmail.com";
48 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester";
49 final static private String HELP_OPTION_1 = "help";
50 final static private String HELP_OPTION_2 = "h";
51 private final static DecimalFormat df2 = new DecimalFormat( ".##" );
53 public static void main( final String args[] ) {
55 ForesterUtil.printProgramInformation( PRG_NAME,
61 ForesterUtil.getForesterLibraryInformation() );
62 CommandLineArguments cla = null;
64 cla = new CommandLineArguments( args );
66 catch ( final Exception e ) {
67 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
69 if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) ) {
74 else if ( ( args.length != 2 ) ) {
76 System.out.println( "Wrong number of arguments." );
81 //final List<String> allowed_options = new ArrayList<>();
82 final File intreefile = cla.getFile( 0 );
83 final String query = cla.getName( 1 );
84 System.out.println( "Input tree: " + intreefile );
85 System.out.println( "Query: " + query );
88 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
89 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile, true );
90 p = factory.create( intreefile, pp )[ 0 ];
92 catch ( final Exception e ) {
93 System.out.println( "\nCould not read \"" + intreefile + "\" [" + e.getMessage() + "]\n" );
96 final Result res = Analysis.execute( p, query );
98 System.out.println( "Result:" );
99 System.out.println( "Greatest common prefix a : " + res.getGreatestCommonPrefix() );
100 System.out.println( "Greatest common prefix a (up) : " + res.getGreatestCommonPrefixUp() );
101 System.out.println( "Greatest common prefix b (down): " + res.getGreatestCommonPrefixDown() );
102 final double lec_ratio = ( 100.0 * res.getLeastEncompassingCladeSize() ) / res.getTreeSize();
103 System.out.println( "Least Encompassing Clade has " + res.getLeastEncompassingCladeSize()
104 + " external nodes (" + df2.format( lec_ratio ) + "% of a total of " + res.getTreeSize() + ")" );
105 if ( res.getWarnings().size() > 0 ) {
106 System.out.println( "Warnings:" );
107 for( final String s : res.getWarnings() ) {
108 System.out.println( s );
112 catch ( final Exception e ) {
113 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
117 private final static void print_help() {
118 System.out.println( "Usage: " + PRG_NAME + " <gene tree file> <query>" );
119 System.out.println();