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
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 // Contact: phylosoft @ gmail . com
26 // WWW: www.phylosoft.org/forester
28 package org.forester.application;
31 import java.io.FileWriter;
32 import java.io.PrintWriter;
34 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
35 import org.forester.phylogeny.Phylogeny;
36 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
37 import org.forester.phylogeny.factories.PhylogenyFactory;
38 import org.forester.sdi.RIO;
39 import org.forester.util.ForesterUtil;
43 final static private String PRG_NAME = "RIO";
44 final static private String PRG_VERSION = "2.03 ALPHA";
45 final static private String PRG_DATE = "2010.01.15";
46 final static private String E_MAIL = "czmasek@burnham.org";
47 final static private String WWW = "www.phylosoft.org/forester/";
48 final static private boolean TIME = true;
49 final static private boolean VERBOSE = true;
51 private final static void errorInCommandLine() {
52 System.out.println( "\nrio: Error in command line.\n" );
57 public static void main( final String[] args ) {
58 ForesterUtil.printProgramInformation( PRG_NAME, PRG_VERSION, PRG_DATE, E_MAIL, WWW );
59 File species_tree_file = null;
60 File multiple_trees_file = null;
64 boolean output_ultraparalogs = false;
65 double t_orthologs = 0.0;
66 double t_orthologs_dc = 0.0;
67 double threshold_ultra_paralogs = 0.0;
69 Phylogeny species_tree = null;
70 RIO rio_instance = null;
71 PrintWriter out = null;
73 if ( args.length < 2 ) {
77 else if ( ( args.length < 3 ) || ( args.length > 18 ) ) {
80 for( final String arg2 : args ) {
81 if ( arg2.trim().charAt( 0 ) != 'p' ) {
82 if ( arg2.trim().length() < 3 ) {
86 arg = arg2.trim().substring( 2 );
90 switch ( arg2.trim().charAt( 0 ) ) {
92 multiple_trees_file = new File( arg );
98 species_tree_file = new File( arg );
101 outfile = new File( arg );
104 output_ultraparalogs = true;
107 sort = Integer.parseInt( arg );
108 if ( ( sort < 0 ) || ( sort > 17 ) ) {
109 errorInCommandLine();
113 t_orthologs = Double.parseDouble( arg );
116 threshold_ultra_paralogs = Double.parseDouble( arg );
119 errorInCommandLine();
122 catch ( final Exception e ) {
123 errorInCommandLine();
126 if ( ( seq_name == "" ) || ( species_tree_file == null ) || ( multiple_trees_file == null )
127 || ( outfile == null ) ) {
128 errorInCommandLine();
130 if ( ( sort < 0 ) || ( sort > 2 ) ) {
131 errorInCommandLine();
134 System.out.println( "\nMultiple trees file: " + multiple_trees_file );
135 System.out.println( "Seq name: " + seq_name );
136 System.out.println( "Species tree file: " + species_tree_file );
137 System.out.println( "Outfile: " + outfile );
138 System.out.println( "Sort: " + sort );
139 System.out.println( "Threshold orthologs: " + t_orthologs );
140 System.out.println( "Threshold orthologs for distance calc.: " + t_orthologs_dc );
141 if ( output_ultraparalogs ) {
142 System.out.println( "Threshold ultra paralogs: " + threshold_ultra_paralogs );
145 if ( TIME && VERBOSE ) {
146 time = System.currentTimeMillis();
149 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
150 species_tree = factory.create( species_tree_file, new PhyloXmlParser() )[ 0 ];
152 catch ( final Exception e ) {
156 if ( !species_tree.isRooted() ) {
157 ForesterUtil.printErrorMessage( PRG_NAME, "Species tree is not rooted" );
160 if ( !species_tree.isCompletelyBinary() ) {
161 ForesterUtil.printErrorMessage( PRG_NAME, "Species tree is not completely binary" );
164 rio_instance = new RIO();
165 final StringBuffer output = new StringBuffer();
167 rio_instance.inferOrthologs( multiple_trees_file, species_tree.copy(), seq_name );
168 output.append( rio_instance.inferredOrthologsToString( seq_name, sort, t_orthologs ) );
169 if ( output_ultraparalogs ) {
170 output.append( "\n\nUltra paralogs:\n" );
171 output.append( rio_instance.inferredUltraParalogsToString( seq_name, threshold_ultra_paralogs ) );
173 output.append( "\n\nSort priority: " + RIO.getOrder( sort ) );
174 output.append( "\nExt nodes : " + rio_instance.getExtNodesOfAnalyzedGeneTrees() );
175 output.append( "\nSamples : " + rio_instance.getNumberOfSamples() + "\n" );
176 out = new PrintWriter( new FileWriter( outfile ), true );
178 catch ( final Exception e ) {
179 ForesterUtil.printErrorMessage( PRG_NAME, e.getLocalizedMessage() );
183 out.println( output );
185 ForesterUtil.programMessage( PRG_NAME, "wrote results to \"" + outfile + "\"" );
186 if ( TIME && VERBOSE ) {
187 time = System.currentTimeMillis() - time;
188 ForesterUtil.programMessage( PRG_NAME, "time: " + time + "ms" );
190 ForesterUtil.programMessage( PRG_NAME, "OK." );
194 private final static void printHelp() {
195 System.out.println( "M= (String) Multiple gene tree file (mandatory)" );
196 System.out.println( "N= (String) Query sequence name (mandatory)" );
197 System.out.println( "S= (String) Species tree file (mandatory)" );
198 System.out.println( "O= (String) Output file name -- overwritten without warning! (mandatory)" );
199 System.out.println( "P= (int) Sort priority" );
200 System.out.println( "L= (double) Threshold orthologs for output" );
201 System.out.println( " Sort priority (\"P=\"):" );
202 System.out.println( RIO.getOrderHelp().toString() );
203 System.out.println();
205 .println( " Example: \"rio M=gene_trees.xml N=bcl2_NEMVE S=species_tree.xml D=distances P=13 p O=out\"" );
206 System.out.println();