X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Frio.java;h=ad0c33abc464ad6be03c0ceed00a63bd4a8ec303;hb=293498c7e9e58d3ec6e4f99c12ab6561943287af;hp=7610fc5ed46b35e4994c304d373937b797288ab0;hpb=5309073b8da93adc2ece844bb84ff2735805b38c;p=jalview.git diff --git a/forester/java/src/org/forester/application/rio.java b/forester/java/src/org/forester/application/rio.java index 7610fc5..ad0c33a 100644 --- a/forester/java/src/org/forester/application/rio.java +++ b/forester/java/src/org/forester/application/rio.java @@ -40,6 +40,8 @@ import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.sdi.RIO; +import org.forester.sdi.RIOException; +import org.forester.sdi.SDIException; import org.forester.util.CommandLineArguments; import org.forester.util.EasyWriter; import org.forester.util.ForesterUtil; @@ -47,8 +49,8 @@ import org.forester.util.ForesterUtil; public class rio { final static private String PRG_NAME = "rio"; - final static private String PRG_VERSION = "3.00 beta 1"; - final static private String PRG_DATE = "2012.11.27"; + final static private String PRG_VERSION = "3.00 beta 3"; + final static private String PRG_DATE = "2012.12.05"; final static private String E_MAIL = "czmasek@burnham.org"; final static private String WWW = "www.phylosoft.org/forester/"; final static private String HELP_OPTION_1 = "help"; @@ -103,7 +105,7 @@ public class rio { } ForesterUtil.fatalErrorIfFileNotReadable( PRG_NAME, gene_trees_file ); ForesterUtil.fatalErrorIfFileNotReadable( PRG_NAME, species_tree_file ); - if ( outfile.exists() ) { + if ( ( outfile != null ) && outfile.exists() ) { ForesterUtil.fatalError( PRG_NAME, "[" + outfile + "] already exists" ); } String query = null; @@ -123,16 +125,20 @@ public class rio { } double cutoff_for_orthologs = 50; double cutoff_for_ultra_paralogs = 50; - int sort = 2; + int sort = 1; try { if ( cla.isOptionSet( CUTOFF_ORTHO_OPTION ) ) { cutoff_for_orthologs = cla.getOptionValueAsDouble( CUTOFF_ORTHO_OPTION ); + if ( query == null ) { + ForesterUtil.fatalError( PRG_NAME, "missing query name, type \"rio -h\" for help" ); + } + if ( outfile == null ) { + ForesterUtil.fatalError( PRG_NAME, "missing outfile, type \"rio -h\" for help" ); + } } if ( cla.isOptionSet( CUTOFF_ULTRA_P_OPTION ) ) { cutoff_for_ultra_paralogs = cla.getOptionValueAsDouble( CUTOFF_ULTRA_P_OPTION ); - if ( !output_ultraparalogs ) { - printHelp(); - } + output_ultraparalogs = true; } if ( cla.isOptionSet( SORT_OPTION ) ) { sort = cla.getOptionValueAsInt( SORT_OPTION ); @@ -142,13 +148,13 @@ public class rio { ForesterUtil.fatalError( PRG_NAME, "error in command line: " + e.getLocalizedMessage() ); } if ( ( cutoff_for_orthologs < 0 ) || ( cutoff_for_ultra_paralogs < 0 ) || ( sort < 0 ) || ( sort > 2 ) ) { - printHelp(); + ForesterUtil.fatalError( PRG_NAME, "numberical option out of range, type \"rio -h\" for help" ); } - if ( ( ( query == null ) && ( outfile != null ) ) || ( ( query != null ) && ( outfile == null ) ) ) { - printHelp(); + if ( ( ( query == null ) && ( ( outfile != null ) || output_ultraparalogs ) ) ) { + ForesterUtil.fatalError( PRG_NAME, "missing query name, type \"rio -h\" for help" ); } - if ( output_ultraparalogs && ( outfile == null ) ) { - printHelp(); + if ( ( output_ultraparalogs && ( outfile == null ) ) || ( ( query != null ) && ( outfile == null ) ) ) { + ForesterUtil.fatalError( PRG_NAME, "missing outfile, type \"rio -h\" for help" ); } long time = 0; System.out.println( "Gene trees : " + gene_trees_file ); @@ -177,15 +183,13 @@ public class rio { System.exit( -1 ); } if ( !species_tree.isRooted() ) { - ForesterUtil.printErrorMessage( PRG_NAME, "species tree is not rooted" ); - System.exit( -1 ); + ForesterUtil.fatalError( PRG_NAME, "species tree is not rooted" ); } if ( !species_tree.isCompletelyBinary() ) { - ForesterUtil.printErrorMessage( PRG_NAME, "species tree is not completely binary" ); - System.exit( -1 ); + ForesterUtil.fatalError( PRG_NAME, "species tree is not completely binary" ); } try { - RIO rio; + final RIO rio; if ( ForesterUtil.isEmpty( query ) ) { rio = new RIO( gene_trees_file, species_tree ); } @@ -210,10 +214,17 @@ public class rio { tableOutput( table_outfile, rio ); } } + catch ( final RIOException e ) { + ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() ); + } + catch ( final SDIException e ) { + ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() ); + } + catch ( final IOException e ) { + ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() ); + } catch ( final Exception e ) { - ForesterUtil.printErrorMessage( PRG_NAME, e.getLocalizedMessage() ); - e.printStackTrace(); - System.exit( -1 ); + ForesterUtil.unexpectedFatalError( PRG_NAME, e ); } if ( outfile != null ) { ForesterUtil.programMessage( PRG_NAME, "wrote results to \"" + outfile + "\"" ); @@ -224,7 +235,7 @@ public class rio { System.exit( 0 ); } - private static void tableOutput( final File table_outfile, final RIO rio ) throws IOException { + private static void tableOutput( final File table_outfile, final RIO rio ) throws IOException, RIOException { final IntMatrix m = RIO.calculateOrthologTable( rio.getAnalyzedGeneTrees() ); writeTable( table_outfile, rio, m ); } @@ -233,7 +244,6 @@ public class rio { final EasyWriter w = ForesterUtil.createEasyWriter( table_outfile ); final java.text.DecimalFormat df = new java.text.DecimalFormat( "0.###" ); df.setDecimalSeparatorAlwaysShown( false ); - w.print( "\t" ); for( int i = 0; i < m.size(); ++i ) { w.print( "\t" ); w.print( m.getLabel( i ) ); @@ -241,7 +251,6 @@ public class rio { w.println(); for( int x = 0; x < m.size(); ++x ) { w.print( m.getLabel( x ) ); - w.print( "\t" ); for( int y = 0; y < m.size(); ++y ) { w.print( "\t" ); if ( x == y ) { @@ -261,25 +270,39 @@ public class rio { } private final static void printHelp() { - System.out.println( "usage:" ); + System.out.println( "Usage" ); System.out.println(); System.out.println( PRG_NAME + " [options] [outfile]" ); System.out.println(); - System.out.println( " options:" ); - System.out.println(); - System.out.println( " -" + CUTOFF_ORTHO_OPTION + " : cutoff for ortholog output (default: 50)" ); - System.out.println( " -" + TABLE_OUTPUT_OPTION + " : file-name for output table" ); - System.out.println( " -" + QUERY_OPTION + " : name for query (sequence/node)" ); - System.out.println( " -" + SORT_OPTION + " : sort (default: 2)" ); - System.out.println( " -" + OUTPUT_ULTRA_P_OPTION + System.out.println( " Options" ); + System.out.println( " -" + CUTOFF_ORTHO_OPTION + " : cutoff for ortholog output (default: 50)" ); + System.out.println( " -" + TABLE_OUTPUT_OPTION + + " : file-name for output table of all vs. all ortholgy support" ); + System.out.println( " -" + QUERY_OPTION + + " : name for query (sequence/node), if this is used, [outfile] is required as well" ); + System.out.println( " -" + SORT_OPTION + " : sort (default: 1)" ); + System.out.println( " -" + OUTPUT_ULTRA_P_OPTION + " : to output ultra-paralogs (species specific expansions/paralogs)" ); - System.out.println( " -" + CUTOFF_ULTRA_P_OPTION + " : cutoff for ultra-paralog output (default: 50)" ); + System.out.println( " -" + CUTOFF_ULTRA_P_OPTION + " : cutoff for ultra-paralog output (default: 50)" ); System.out.println(); - System.out.println( " sort:" ); - System.out.println( RIO.getOrderHelp().toString() ); + System.out.println( " Note" ); + System.out.println( " Either output of all vs. all ortholgy support with -t= and/or output for" ); + System.out.println( " one query sequence with -q= and a [outfile] are required." ); System.out.println(); + System.out.println( " Sort" ); + System.out.println( RIO.getOrderHelp().toString() ); + System.out.println( " Formats" ); + System.out.println( " The species tree is expected to be in phyloXML format." ); System.out - .println( " example: \"rio gene_trees.nh species.xml outfile -q=D_HUMAN -t=outtable -u -cu=60 -co=60\"" ); + .println( " The gene trees ideally are in phyloXML as well, but can also be in New Hamphshire (Newick)" ); + System.out.println( " or Nexus format as long as species information can be extracted from the gene names" ); + System.out.println( " (e.g. \"HUMAN\" from \"BCL2_HUMAN\")." ); + System.out.println(); + System.out.println( " Examples" ); + System.out.println( " \"rio gene_trees.nh species.xml outfile -q=BCL2_HUMAN -t=outtable -u -cu=60 -co=60\"" ); + System.out.println( " \"rio gene_trees.nh species.xml -t=outtable\"" ); + System.out.println(); + System.out.println( " More information: http://code.google.com/p/forester/wiki/RIO" ); System.out.println(); System.exit( -1 ); }