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;
33 import java.util.regex.Pattern;
35 import org.forester.clade_analysis.AnalysisMulti;
36 import org.forester.clade_analysis.Prefix;
37 import org.forester.clade_analysis.ResultMulti;
38 import org.forester.io.parsers.PhylogenyParser;
39 import org.forester.io.parsers.util.ParserUtils;
40 import org.forester.phylogeny.Phylogeny;
41 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
42 import org.forester.phylogeny.factories.PhylogenyFactory;
43 import org.forester.util.CommandLineArguments;
44 import org.forester.util.ForesterUtil;
46 public final class cladinator {
48 final static private String PRG_NAME = "cladinator";
49 final static private String PRG_VERSION = "0.100";
50 final static private String PRG_DATE = "170823";
51 final static private String PRG_DESC = "clades within clades -- analysis of pplacer type outputs";
52 final static private String E_MAIL = "phyloxml@gmail.com";
53 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester";
54 final static private String HELP_OPTION_1 = "help";
55 final static private String HELP_OPTION_2 = "h";
56 final static private String SEP_OPTION = "s";
57 private final static DecimalFormat df2 = new DecimalFormat( "0.0#" );
59 public static void main( final String args[] ) {
61 ForesterUtil.printProgramInformation( PRG_NAME,
67 ForesterUtil.getForesterLibraryInformation() );
68 CommandLineArguments cla = null;
70 cla = new CommandLineArguments( args );
72 catch ( final Exception e ) {
73 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
75 if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) ) {
80 else if ( ( ( args.length != 2 ) && ( args.length != 3 ) ) ) {
82 System.out.println( "Wrong number of arguments." );
87 final List<String> allowed_options = new ArrayList<>();
88 allowed_options.add( SEP_OPTION );
89 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
90 if ( dissallowed_options.length() > 0 ) {
91 ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options );
93 final String separator;
94 if ( cla.isOptionSet( SEP_OPTION ) ) {
95 separator = cla.getOptionValue( SEP_OPTION );
100 final File intreefile = cla.getFile( 0 );
101 final String query = cla.getName( 1 );
102 System.out.println( "Input tree: " + intreefile );
103 System.out.println( "Query : " + query );
104 if ( !ForesterUtil.isEmpty( separator ) ) {
105 System.out.println( "Separator : " + separator );
108 System.out.println( "Separator : none" );
112 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
113 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile, true );
114 p = factory.create( intreefile, pp )[ 0 ];
116 catch ( final IOException e ) {
117 System.out.println( "\nCould not read \"" + intreefile + "\" [" + e.getMessage() + "]\n" );
120 final Pattern pattern = Pattern.compile( query );
121 final ResultMulti res = AnalysisMulti.execute( p, pattern, separator, 0.5 );
122 System.out.println();
123 System.out.println( "Result:" );
124 System.out.println( "Query : " + query );
126 System.out.println( "Collapsed:" );
127 for( final Prefix prefix : res.getCollapsedMultiHitPrefixes() ) {
128 System.out.println( prefix );
130 if ( res.isHasSpecificMultiHitsPrefixes() ) {
131 System.out.println( "Specifics:" );
132 for( final Prefix prefix : res.getSpecificMultiHitPrefixes() ) {
133 System.out.println( prefix );
135 System.out.println( "Collapsed With Specifics:" );
136 for( final Prefix prefix : res.getCollapsedMultiHitPrefixes() ) {
137 System.out.println( prefix );
138 for( final Prefix spec : res.getSpecificMultiHitPrefixes() ) {
139 if ( spec.getPrefix().startsWith( prefix.getPrefix() ) ) {
140 System.out.println( " " + spec );
145 if ( !ForesterUtil.isEmpty( res.getAllMultiHitPrefixesDown() ) ) {
146 System.out.println( "Collapsed Down:" );
147 for( final Prefix prefix : res.getCollapsedMultiHitPrefixesDown() ) {
148 System.out.println( prefix );
151 if ( !ForesterUtil.isEmpty( res.getAllMultiHitPrefixesUp() ) ) {
152 System.out.println( "Collapsed Up:" );
153 for( final Prefix prefix : res.getAllMultiHitPrefixesUp() ) {
154 System.out.println( prefix );
158 System.out.println();
160 catch ( final IllegalArgumentException e ) {
161 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
163 catch ( final Exception e ) {
165 ForesterUtil.fatalError( PRG_NAME, "Unexpected errror!" );
169 private final static void print_help() {
170 System.out.println( "Usage:" );
171 System.out.println();
172 System.out.println( PRG_NAME + " [options] <gene tree file> <query>" );
173 System.out.println();
174 System.out.println( " options:" );
175 System.out.println( " -" + SEP_OPTION + "=<separator>: the separator to be used" );
176 System.out.println();
177 System.out.println( "Example:" );
178 System.out.println();
179 System.out.println( " " + PRG_NAME + " -s=. my_tree.xml A.1.1.1" );
180 System.out.println();