- try {
- final RIO rio = RIO.executeAnalysis( gene_trees_file,
- species_tree,
- algorithm,
- REROOTING.BY_ALGORITHM,
- outgroup,
- logfile != null,
- true );
- if ( algorithm == ALGORITHM.GSDIR ) {
- ForesterUtil.programMessage( PRG_NAME, "taxonomy linking based on: " + rio.getGSDIRtaxCompBase() );
- }
- tableOutput( orthology_outtable, rio );
- if ( ( algorithm != ALGORITHM.SDIR ) && ( logfile != null ) ) {
- writeLogFile( logfile,
- rio,
- species_tree_file,
- gene_trees_file,
- orthology_outtable,
- PRG_NAME,
- PRG_VERSION,
- PRG_DATE,
- ForesterUtil.getForesterLibraryInformation() );
- }
- final BasicDescriptiveStatistics stats = rio.getDuplicationsStatistics();
- final java.text.DecimalFormat df = new java.text.DecimalFormat( "0.#" );
- ForesterUtil.programMessage( PRG_NAME,
- "Mean number of duplications : " + df.format( stats.arithmeticMean() )
- + " (sd: " + df.format( stats.sampleStandardDeviation() ) + ")" );
- if ( stats.getN() > 3 ) {
- ForesterUtil.programMessage( PRG_NAME, "Median number of duplications: " + df.format( stats.median() ) );
- }
- ForesterUtil.programMessage( PRG_NAME, "Minimum duplications : " + ( int ) stats.getMin() );
- ForesterUtil.programMessage( PRG_NAME, "Maximum duplications : " + ( int ) stats.getMax() );
- }
- catch ( final RIOException e ) {
- ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
- }
- catch ( final SDIException e ) {
- ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
+ EasyWriter log = null;
+ if ( use_dir ) {
+ if ( outdir.exists() ) {
+ if ( !outdir.isDirectory() ) {
+ ForesterUtil.fatalError( PRG_NAME,
+ "out-directory [" + outdir + "] already exists but is not a directory" );
+ }
+ }
+ else {
+ final boolean success = outdir.mkdirs();
+ if ( !success ) {
+ ForesterUtil.fatalError( PRG_NAME, "could not create out-directory [" + outdir + "]" );
+ }
+ }
+ final String species_tree_file_name = species_tree_file.getName();
+ final File gene_trees_files[] = indir.listFiles( new FilenameFilter() {
+
+ @Override
+ public boolean accept( final File dir, final String name ) {
+ return ( ( name.endsWith( gene_trees_suffix ) ) && !( name.equals( species_tree_file_name ) ) );
+ }
+ } );
+ if ( gene_trees_files.length < 1 ) {
+ ForesterUtil.fatalError( PRG_NAME,
+ "in-directory [" + indir
+ + "] does not contain any gene tree files with suffix "
+ + gene_trees_suffix );
+ }
+ try {
+ log = ForesterUtil.createEasyWriter( logfile );
+ }
+ catch ( final IOException e ) {
+ ForesterUtil.fatalError( PRG_NAME, "could not create [" + logfile + "]" );
+ }
+ Arrays.sort( gene_trees_files );
+ try {
+ log.print( "# program" );
+ log.print( "\t" );
+ log.print( PRG_NAME );
+ log.println();
+ log.print( "# version" );
+ log.print( "\t" );
+ log.print( PRG_VERSION );
+ log.println();
+ log.print( "# date" );
+ log.print( "\t" );
+ log.print( PRG_DATE );
+ log.println();
+ log.print( "# Algorithm " );
+ log.print( "\t" );
+ log.print( algorithm.toString() );
+ log.println();
+ log.print( "# Gene trees in-dir" );
+ log.print( "\t" );
+ log.print( indir.getCanonicalPath() );
+ log.println();
+ log.print( "# Gene trees suffix" );
+ log.print( "\t" );
+ log.print( gene_trees_suffix );
+ log.println();
+ log.print( "# Species tree" );
+ log.print( "\t" );
+ log.print( species_tree_file.getCanonicalPath() );
+ log.println();
+ if ( perform_id_mapping ) {
+ log.print( "# Id mappings in-dir" );
+ log.print( "\t" );
+ log.print( id_mapping_dir.getCanonicalPath() );
+ log.println();
+ log.print( "# Id mappings suffix" );
+ log.print( "\t" );
+ log.print( id_mapping_suffix );
+ log.println();
+ }
+ if ( perform_gsdir_on_best_tree ) {
+ log.print( "# Consensus (\"best\") gene tree dir" );
+ log.print( "\t" );
+ log.print( best_trees_indir.getCanonicalPath() );
+ log.println();
+ log.print( "# Consensus (\"best\") gene tree suffix" );
+ log.print( "\t" );
+ log.print( best_trees_suffix );
+ log.println();
+ }
+ log.print( "# Out-dir" );
+ log.print( "\t" );
+ log.print( outdir.getCanonicalPath() );
+ log.println();
+ log.print( "# Logfile" );
+ log.print( "\t" );
+ log.print( logfile.getCanonicalPath() );
+ log.println();
+ log.print( "# Ortholog groups cutoff" );
+ log.print( "\t" );
+ log.print( Double.toString( ortholog_group_cutoff ) );
+ log.println();
+ if ( gt_first != RIO.DEFAULT_RANGE ) {
+ log.print( "# First gene tree to analyze" );
+ log.print( "\t" );
+ log.print( Integer.toString( gt_first ) );
+ log.println();
+ }
+ if ( gt_last != RIO.DEFAULT_RANGE ) {
+ log.print( "# Last gene tree to analyze" );
+ log.print( "\t" );
+ log.print( Integer.toString( gt_last ) );
+ log.println();
+ }
+ log.print( "# Re-rooting" );
+ log.print( "\t" );
+ log.print( rerooting_str );
+ log.println();
+ log.print( "# Non binary species tree" );
+ log.print( "\t" );
+ if ( !sdir ) {
+ log.print( "allowed" );
+ }
+ else {
+ log.print( "disallowed" );
+ }
+ log.println();
+ log.println();
+ log.print( "NAME" );
+ log.print( "\t" );
+ log.print( "EXT NODES" );
+ log.print( "\t" );
+ log.print( ortholog_group_cutoff + " O GROUPS" );
+ log.print( "\t" );
+ log.print( "0.05 O GROUPS" );
+ log.print( "\t" );
+ log.print( "0.25 O GROUPS" );
+ log.print( "\t" );
+ log.print( "0.5 O GROUPS" );
+ log.print( "\t" );
+ log.print( "0.75 O GROUPS" );
+ log.print( "\t" );
+ log.print( "0.95 O GROUPS" );
+ log.print( "\t" );
+ if ( perform_gsdir_on_best_tree ) {
+ log.print( "BEST TREE DUP" );
+ log.print( "\t" );
+ log.print( "MEDIAN DUP - BEST TREE DUP" );
+ log.print( "\t" );
+ }
+ log.print( "MEDIAN DUP" );
+ log.print( "\t" );
+ log.print( "MEAN DUP" );
+ log.print( "\t" );
+ log.print( "MEAN DUP SD" );
+ log.print( "\t" );
+ log.print( "MIN DUP" );
+ log.print( "\t" );
+ log.print( "MAX DUP" );
+ log.print( "\t" );
+ log.print( "REMOVED EXT NODES" );
+ log.print( "\t" );
+ log.print( "N" );
+ log.println();
+ }
+ catch ( IOException e ) {
+ ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
+ }
+ int counter = 1;
+ for( final File gf : gene_trees_files ) {
+ String outname = gf.getName();
+ System.out
+ .print( "\r " );
+ System.out.print( "\r" + counter + "/" + gene_trees_files.length + ": " + outname );
+ counter++;
+ if ( outname.indexOf( "." ) > 0 ) {
+ outname = outname.substring( 0, outname.lastIndexOf( "." ) );
+ }
+ try {
+ RIOUtil.executeAnalysis( gf,
+ species_tree_file,
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.ORTHO_OUTTABLE_SUFFIX ),
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.ORTHO_OUTTABLE_WITH_MAP_SUFFIX ),
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.ORTHOLOG_GROUPS_SUFFIX ),
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.LOGFILE_SUFFIX ),
+ outgroup,
+ rerooting,
+ gt_first,
+ gt_last,
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.STRIPPED_SPECIES_TREE_SUFFIX ),
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.OUT_MIN_DUP_GENE_TREE_SUFFIX ),
+ new File( outdir.getCanonicalFile() + "/" + outname
+ + RIOUtil.OUT_MED_DUP_GENE_TREE_SUFFIX ),
+ true,
+ algorithm,
+ true,
+ log,
+ ortholog_group_cutoff,
+ perform_id_mapping,
+ id_mapping_dir,
+ id_mapping_suffix,
+ perform_gsdir_on_best_tree,
+ outdir,
+ best_trees_indir,
+ best_trees_suffix );
+ }
+ catch ( IOException e ) {
+ ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
+ }
+ }
+ System.out
+ .print( "\r " );
+ System.out.println();