X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Fgsdi.java;h=0f77e5cd52e3e17eb00ad8f6936fe8bfbe73e516;hb=c933c93e4553a4f5979390d47b7d2763603a60d0;hp=3df2a743afa1fbed90ec3fde0e9fbb86c0e00972;hpb=6c0feb7d2e02c6287d1328e61353cecff062bcd3;p=jalview.git diff --git a/forester/java/src/org/forester/application/gsdi.java b/forester/java/src/org/forester/application/gsdi.java index 3df2a74..0f77e5c 100644 --- a/forester/java/src/org/forester/application/gsdi.java +++ b/forester/java/src/org/forester/application/gsdi.java @@ -27,14 +27,18 @@ package org.forester.application; import java.io.File; import java.io.IOException; -import java.io.Writer; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.nhx.NHXParser; +import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.io.parsers.util.ParserUtils; import org.forester.io.writers.PhylogenyWriter; @@ -46,9 +50,10 @@ import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.sdi.GSDI; import org.forester.sdi.SDI; import org.forester.sdi.SDI.TaxonomyComparisonBase; +import org.forester.sdi.SDIException; import org.forester.sdi.SDIse; -import org.forester.sdi.SdiException; import org.forester.util.CommandLineArguments; +import org.forester.util.EasyWriter; import org.forester.util.ForesterConstants; import org.forester.util.ForesterUtil; @@ -57,23 +62,22 @@ public final class gsdi { private enum BASE_ALGORITHM { GSDI, SDI } - final static public boolean REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE = true; - final static private String STRIP_OPTION = "s"; - final static private String ALLOW_STRIPPING_OF_GENE_TREE_OPTION = "g"; - final static private String SDI_OPTION = "b"; - final static private String MOST_PARSIMONIOUS_OPTION = "m"; - final static private String GUESS_FORMAT_OF_SPECIES_TREE = "q"; - final static private String HELP_OPTION_1 = "help"; - final static private String HELP_OPTION_2 = "h"; - final static private String DEFAULT_OUTFILE_SUFFIX = "_gsdi_out.phylo.xml"; - final static private String SUFFIX_FOR_LIST_OF_STIPPED_GENE_TREE_NODES = "_stripped_gene_tree_nodes.txt"; - final static private String LOGFILE_SUFFIX = "_gsdi_log.txt"; - final static private String PRG_NAME = "gsdi"; - final static private String PRG_VERSION = "0.901"; - final static private String PRG_DATE = "120608"; - final static private String PRG_DESC = "general speciation duplication inference"; - final static private String E_MAIL = "phylosoft@gmail.com"; - final static private String WWW = "www.phylosoft.org/forester"; + final static public boolean REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE = true; + final static private String ALLOW_STRIPPING_OF_GENE_TREE_OPTION = "g"; + final static private String SDISE_OPTION = "b"; + final static private String MOST_PARSIMONIOUS_OPTION = "m"; + final static private String GUESS_FORMAT_OF_SPECIES_TREE = "q"; + final static private String HELP_OPTION_1 = "help"; + final static private String HELP_OPTION_2 = "h"; + final static private String DEFAULT_OUTFILE_SUFFIX = "_gsdi_out.xml"; + final static private String SUFFIX_FOR_SPECIES_TREE_USED = "_species_tree_used.xml"; + final static private String LOGFILE_SUFFIX = "_gsdi_log.txt"; + final static private String PRG_NAME = "gsdi"; + final static private String PRG_VERSION = "1.000"; + final static private String PRG_DATE = "120608"; + final static private String PRG_DESC = "general speciation duplication inference"; + final static private String E_MAIL = "phylosoft@gmail.com"; + final static private String WWW = "www.phylosoft.org/forester"; public static void main( final String args[] ) { try { @@ -104,8 +108,7 @@ public final class gsdi { System.exit( -1 ); } final List allowed_options = new ArrayList(); - allowed_options.add( gsdi.STRIP_OPTION ); - allowed_options.add( gsdi.SDI_OPTION ); + allowed_options.add( gsdi.SDISE_OPTION ); allowed_options.add( gsdi.GUESS_FORMAT_OF_SPECIES_TREE ); allowed_options.add( gsdi.MOST_PARSIMONIOUS_OPTION ); allowed_options.add( gsdi.ALLOW_STRIPPING_OF_GENE_TREE_OPTION ); @@ -122,14 +125,9 @@ public final class gsdi { private static void execute( final CommandLineArguments cla ) throws IOException { BASE_ALGORITHM base_algorithm = BASE_ALGORITHM.GSDI; - boolean strip_species_tree = false; boolean most_parsimonous_duplication_model = false; - boolean species_tree_in_phyloxml = true; boolean allow_stripping_of_gene_tree = false; - if ( cla.isOptionSet( gsdi.STRIP_OPTION ) ) { - strip_species_tree = true; - } - if ( cla.isOptionSet( gsdi.SDI_OPTION ) ) { + if ( cla.isOptionSet( gsdi.SDISE_OPTION ) ) { base_algorithm = BASE_ALGORITHM.SDI; } if ( cla.isOptionSet( gsdi.MOST_PARSIMONIOUS_OPTION ) ) { @@ -138,9 +136,6 @@ public final class gsdi { } most_parsimonous_duplication_model = true; } - if ( cla.isOptionSet( gsdi.GUESS_FORMAT_OF_SPECIES_TREE ) ) { - species_tree_in_phyloxml = false; - } if ( cla.isOptionSet( gsdi.ALLOW_STRIPPING_OF_GENE_TREE_OPTION ) ) { if ( base_algorithm != BASE_ALGORITHM.GSDI ) { ForesterUtil.fatalError( gsdi.PRG_NAME, "Can only allow stripping of gene tree with GSDI" ); @@ -153,7 +148,7 @@ public final class gsdi { File species_tree_file = null; File out_file = null; File log_file = null; - Writer log_writer = null; + EasyWriter log_writer = null; try { gene_tree_file = cla.getFile( 0 ); species_tree_file = cla.getFile( 1 ); @@ -181,7 +176,7 @@ public final class gsdi { ForesterUtil.fatalError( gsdi.PRG_NAME, ForesterUtil.isWritableFile( log_file ) ); } try { - log_writer = ForesterUtil.createBufferedWriter( log_file ); + log_writer = ForesterUtil.createEasyWriter( log_file ); } catch ( final IOException e ) { ForesterUtil.fatalError( gsdi.PRG_NAME, "Failed to create [" + log_file + "]: " + e.getMessage() ); @@ -196,11 +191,11 @@ public final class gsdi { } try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - if ( species_tree_in_phyloxml ) { - species_tree = factory.create( species_tree_file, new PhyloXmlParser() )[ 0 ]; + final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( species_tree_file, true ); + if ( p instanceof PhyloXmlParser ) { + species_tree = factory.create( species_tree_file, p )[ 0 ]; } else { - final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( species_tree_file, true ); if ( REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE && ( p instanceof NHXParser ) ) { ( ( NHXParser ) p ).setReplaceUnderscores( true ); } @@ -208,17 +203,42 @@ public final class gsdi { final TaxonomyComparisonBase comp_base = GSDI.determineTaxonomyComparisonBase( gene_tree ); switch ( comp_base ) { case SCIENTIFIC_NAME: - PhylogenyMethods - .transferNodeNameToField( species_tree, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_ID_UNIPROT_1 ); + try { + PhylogenyMethods + .transferNodeNameToField( species_tree, + PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME, + true ); + } + catch ( final PhyloXmlDataFormatException e ) { + ForesterUtil.fatalError( gsdi.PRG_NAME, + "Failed to transfer general node name to scientific name, in [" + + species_tree_file + "]: " + e.getMessage() ); + } break; case CODE: - PhylogenyMethods.transferNodeNameToField( species_tree, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_CODE ); + try { + PhylogenyMethods + .transferNodeNameToField( species_tree, + PhylogenyMethods.PhylogenyNodeField.TAXONOMY_CODE, + true ); + } + catch ( final PhyloXmlDataFormatException e ) { + ForesterUtil.fatalError( gsdi.PRG_NAME, + "Failed to transfer general node name to taxonomy code, in [" + + species_tree_file + "]: " + e.getMessage() ); + } break; case ID: - PhylogenyMethods.transferNodeNameToField( species_tree, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_ID ); + try { + PhylogenyMethods.transferNodeNameToField( species_tree, + PhylogenyMethods.PhylogenyNodeField.TAXONOMY_ID, + true ); + } + catch ( final PhyloXmlDataFormatException e ) { + ForesterUtil.fatalError( gsdi.PRG_NAME, + "Failed to transfer general node name to taxonomy id, in [" + + species_tree_file + "]: " + e.getMessage() ); + } break; default: ForesterUtil.fatalError( gsdi.PRG_NAME, "unable to determine comparison base" ); @@ -226,193 +246,240 @@ public final class gsdi { } } catch ( final IOException e ) { - ForesterUtil.fatalError( gsdi.PRG_NAME, - "Failed to read species tree from [" + gene_tree_file + "]: " + e.getMessage() ); + ForesterUtil.fatalError( gsdi.PRG_NAME, "Failed to read species tree from [" + species_tree_file + "]: " + + e.getMessage() ); } gene_tree.setRooted( true ); species_tree.setRooted( true ); if ( !gene_tree.isCompletelyBinary() ) { - log_writer.write( "User Error: gene tree is not completely binary" ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + log_writer.println( "User Error: gene tree is not completely binary" ); log_writer.close(); ForesterUtil.fatalError( gsdi.PRG_NAME, "gene tree is not completely binary" ); } if ( base_algorithm != BASE_ALGORITHM.GSDI ) { if ( !species_tree.isCompletelyBinary() ) { - log_writer.write( "User Error: species tree is not completely binary, use GSDI instead" ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + log_writer.println( "User Error: species tree is not completely binary, use GSDI instead" ); log_writer.close(); ForesterUtil.fatalError( gsdi.PRG_NAME, "species tree is not completely binary, use GSDI instead" ); } } - // For timing. - // gene_tree = Helper.createBalancedTree( 10 ); - // species_tree = Helper.createBalancedTree( 13 ); - // species_tree = Helper.createUnbalancedTree( 1024 ); - // gene_tree = Helper.createUnbalancedTree( 8192 ); - // species_tree = gene_tree.copyTree(); - // gene_tree = species_tree.copyTree(); - // Helper.numberSpeciesInOrder( species_tree ); - // Helper.numberSpeciesInOrder( gene_tree ); - // Helper.randomizeSpecies( 1, 8192, gene_tree ); - // Helper.intervalNumberSpecies( gene_tree, 4096 ); - // Helper.numberSpeciesInDescOrder( gene_tree ); - log_writer.write( PRG_NAME + " - " + PRG_DESC ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( " version : " + PRG_VERSION ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( " date : " + PRG_DATE ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( " forester version: " + ForesterConstants.FORESTER_VERSION ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( "Start time: " + new SimpleDateFormat( "yyyyMMdd HH:mm:ss" ).format( new Date() ) ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( "Gene tree file: " + gene_tree_file.getCanonicalPath() ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( "Gene tree name: " + log_writer.println( PRG_NAME + " - " + PRG_DESC ); + log_writer.println( " version : " + PRG_VERSION ); + log_writer.println( " date : " + PRG_DATE ); + log_writer.println( " forester version: " + ForesterConstants.FORESTER_VERSION ); + log_writer.println(); + log_writer.println( "Start time : " + + new SimpleDateFormat( "yyyyMMdd HH:mm:ss" ).format( new Date() ) ); + System.out.println( "Start time : " + + new SimpleDateFormat( "yyyyMMdd HH:mm:ss" ).format( new Date() ) ); + log_writer.println( "Gene tree file : " + gene_tree_file.getCanonicalPath() ); + System.out.println( "Gene tree file : " + gene_tree_file.getCanonicalPath() ); + log_writer.println( "Gene tree name : " + + ( ForesterUtil.isEmpty( gene_tree.getName() ) ? "" : gene_tree.getName() ) ); + System.out.println( "Gene tree name : " + ( ForesterUtil.isEmpty( gene_tree.getName() ) ? "" : gene_tree.getName() ) ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( "Species tree file: " + species_tree_file.getCanonicalPath() ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( "Species tree name: " + log_writer.println( "Species tree file : " + species_tree_file.getCanonicalPath() ); + System.out.println( "Species tree file : " + species_tree_file.getCanonicalPath() ); + log_writer.println( "Species tree name : " + + ( ForesterUtil.isEmpty( species_tree.getName() ) ? "" : gene_tree.getName() ) ); + System.out.println( "Species tree name : " + ( ForesterUtil.isEmpty( species_tree.getName() ) ? "" : gene_tree.getName() ) ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - System.out.println(); - System.out.println( "Strip species tree: " + strip_species_tree ); - log_writer.write( "Strip species tree: " + strip_species_tree ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); SDI sdi = null; final long start_time = new Date().getTime(); try { if ( base_algorithm == BASE_ALGORITHM.GSDI ) { - System.out.println(); - System.out.println( "Use most parsimonous duplication model: " + most_parsimonous_duplication_model ); - System.out.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); - log_writer.write( "Use most parsimonous duplication model: " + most_parsimonous_duplication_model ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - log_writer.write( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + System.out.println( "Use most parsimonous duplication model : " + most_parsimonous_duplication_model ); + System.out.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); + log_writer.println( "Use most parsimonous duplication model : " + most_parsimonous_duplication_model ); + log_writer.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); log_writer.flush(); sdi = new GSDI( gene_tree, species_tree, most_parsimonous_duplication_model, allow_stripping_of_gene_tree, - strip_species_tree ); + true ); } else { System.out.println(); System.out.println( "Using SDIse algorithm" ); - log_writer.write( "Using SDIse algorithm" ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + log_writer.println( "Using SDIse algorithm" ); log_writer.flush(); sdi = new SDIse( gene_tree, species_tree ); } } - catch ( final SdiException e ) { - log_writer.write( "User Error: " + e.getLocalizedMessage() ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + catch ( final SDIException e ) { + log_writer.println( "User Error: " + e.getLocalizedMessage() ); log_writer.close(); ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() ); } catch ( final IOException e ) { - log_writer.write( "Error: " + e ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + log_writer.println( "Error: " + e ); log_writer.close(); ForesterUtil.fatalError( PRG_NAME, e.toString() ); } catch ( final Exception e ) { - log_writer.write( "Error: " + e ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + log_writer.println( "Error: " + e ); log_writer.close(); e.printStackTrace(); System.exit( -1 ); } - System.out.println(); - System.out.println( "Running time (excluding I/O): " + ( new Date().getTime() - start_time ) + "ms" ); - log_writer.write( "Running time (excluding I/O): " + ( new Date().getTime() - start_time ) + "ms" ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + System.out.println( "Running time (excluding I/O) : " + ( new Date().getTime() - start_time ) + + "ms" ); + log_writer.println( "Running time (excluding I/O) : " + ( new Date().getTime() - start_time ) + + "ms" ); + if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) ) { + final GSDI gsdi = ( GSDI ) sdi; + System.out.println( "Mapping based on : " + gsdi.getTaxCompBase() ); + log_writer.println( "Mapping based on : " + gsdi.getTaxCompBase() ); + } try { final PhylogenyWriter writer = new PhylogenyWriter(); writer.toPhyloXML( out_file, gene_tree, 0 ); } catch ( final IOException e ) { - ForesterUtil.fatalError( PRG_NAME, "Failed to write to [" + out_file + "]: " + e.getMessage() ); + ForesterUtil.fatalError( PRG_NAME, + "Failed to write to [" + out_file.getCanonicalPath() + "]: " + e.getMessage() ); } - System.out.println(); - System.out.println( "Successfully wrote resulting gene tree to: " + out_file ); - System.out.println(); - log_writer.write( "Wrote resulting gene tree to: " + out_file ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + System.out.println( "Wrote resulting gene tree to : " + out_file.getCanonicalPath() ); + log_writer.println( "Wrote resulting gene tree to : " + out_file.getCanonicalPath() ); if ( base_algorithm == BASE_ALGORITHM.SDI ) { sdi.computeMappingCostL(); - System.out.println( "Mapping cost : " + sdi.computeMappingCostL() ); - log_writer.write( "Mapping cost : " + sdi.computeMappingCostL() ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + System.out.println( "Mapping cost : " + sdi.computeMappingCostL() ); + log_writer.println( "Mapping cost : " + sdi.computeMappingCostL() ); + } + else if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) ) { + final GSDI gsdi = ( GSDI ) sdi; + final File species_tree_used_file = new File( ForesterUtil.removeSuffix( out_file.toString() ) + + SUFFIX_FOR_SPECIES_TREE_USED ); + try { + final PhylogenyWriter writer = new PhylogenyWriter(); + writer.toPhyloXML( species_tree_used_file, gsdi.getSpeciesTree(), 0 ); + } + catch ( final IOException e ) { + ForesterUtil.fatalError( PRG_NAME, "Failed to write to [" + species_tree_used_file.getCanonicalPath() + + "]: " + e.getMessage() ); + } + System.out.println( "Wrote (stripped) species tree to : " + + species_tree_used_file.getCanonicalPath() ); + log_writer.println( "Wrote (stripped) species tree to : " + + species_tree_used_file.getCanonicalPath() ); + } + System.out.println( "Number of external nodes in gene tree : " + gene_tree.getNumberOfExternalNodes() ); + log_writer.println( "Number of external nodes in gene tree : " + gene_tree.getNumberOfExternalNodes() ); + System.out.println( "Number of external nodes in species tree : " + + sdi.getSpeciesTree().getNumberOfExternalNodes() ); + log_writer.println( "Number of external nodes in species tree : " + + sdi.getSpeciesTree().getNumberOfExternalNodes() ); + if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) ) { + final GSDI gsdi = ( GSDI ) sdi; + final int poly = PhylogenyMethods.countNumberOfPolytomies( gsdi.getSpeciesTree() ); + System.out.println( "Number of polytomies in species tree : " + poly ); + log_writer.println( "Number of polytomies in species tree : " + poly ); + System.out.println( "External nodes stripped from gene tree : " + + gsdi.getStrippedExternalGeneTreeNodes().size() ); + log_writer.println( "External nodes stripped from gene tree : " + + gsdi.getStrippedExternalGeneTreeNodes().size() ); + System.out.println( "External nodes stripped from species tree: " + + gsdi.getStrippedSpeciesTreeNodes().size() ); + log_writer.println( "External nodes stripped from species tree: " + + gsdi.getStrippedSpeciesTreeNodes().size() ); } - System.out.println( "Number of duplications : " + sdi.getDuplicationsSum() ); - log_writer.write( "Number of duplications : " + sdi.getDuplicationsSum() ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); + System.out.println(); + System.out.println( "Number of duplications : " + sdi.getDuplicationsSum() ); + log_writer.println( "Number of duplications : " + sdi.getDuplicationsSum() ); if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) ) { final GSDI gsdi = ( GSDI ) sdi; if ( !most_parsimonous_duplication_model ) { - final int duplications = gsdi.getSpeciationOrDuplicationEventsSum(); - System.out.println( "Number of potential duplications: " + duplications ); - log_writer.write( "Number of potential duplications: " + duplications ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - } - final int spec = gsdi.getSpeciationsSum(); - System.out.println( "Number of speciations : " + spec ); - log_writer.write( "Number of speciations : " + spec ); - log_writer.write( ForesterUtil.LINE_SEPARATOR ); - for( PhylogenyNode n : gsdi.getMappedExternalSpeciesTreeNodes() ) { - System.out.println( n.toString() ); + final int u = gsdi.getSpeciationOrDuplicationEventsSum(); + System.out.println( "Number of potential duplications : " + u ); + log_writer.println( "Number of potential duplications : " + u ); } + System.out.println( "Number of speciations : " + gsdi.getSpeciationsSum() ); + log_writer.println( "Number of speciations : " + gsdi.getSpeciationsSum() ); + log_writer.println(); + printMappedNodesToLog( log_writer, gsdi ); + log_writer.println(); + printStrippedGeneTreeNodesToLog( log_writer, gsdi ); + log_writer.println(); + printStrippedSpeciesTreeNodesToLog( log_writer, gsdi ); } System.out.println(); + System.out.println( "Wrote log to : " + log_file.getCanonicalPath() ); + System.out.println(); log_writer.close(); - // some stat on gene tree: - // filename, name - // number of external nodes, strppided nodes - // some stats on sepcies tree, external nodes, - // filename, name - // internal nodes - // how many of which are polytomies - //wrote log file to - // if ( allow_stripping_of_gene_tree ) { - // stripped x nodes, y external nodes remain - // } + } + + private static void printMappedNodesToLog( final EasyWriter log_writer, final GSDI gsdi ) throws IOException { + final SortedSet ss = new TreeSet(); + for( final PhylogenyNode n : gsdi.getMappedExternalSpeciesTreeNodes() ) { + ss.add( n.toString() ); + } + log_writer.println( "The following " + ss.size() + " species were used: " ); + for( final String s : ss ) { + log_writer.println( " " + s ); + } + } + + private static void printStrippedGeneTreeNodesToLog( final EasyWriter log_writer, final GSDI gsdi ) + throws IOException { + final SortedMap sm = new TreeMap(); + for( final PhylogenyNode n : gsdi.getStrippedExternalGeneTreeNodes() ) { + final String s = n.toString(); + if ( sm.containsKey( s ) ) { + sm.put( s, sm.get( s ) + 1 ); + } + else { + sm.put( s, 1 ); + } + } + log_writer.println( "The following " + sm.size() + " nodes were stripped from the gene tree: " ); + for( final String s : sm.keySet() ) { + final int count = sm.get( s ); + if ( count == 1 ) { + log_writer.println( " " + s ); + } + else { + log_writer.println( " " + s + " [" + count + "]" ); + } + } + } + + private static void printStrippedSpeciesTreeNodesToLog( final EasyWriter log_writer, final GSDI gsdi ) + throws IOException { + final SortedSet ss = new TreeSet(); + for( final PhylogenyNode n : gsdi.getStrippedSpeciesTreeNodes() ) { + ss.add( n.toString() ); + } + log_writer.println( "The following " + ss.size() + " nodes were stripped from the species tree: " ); + for( final String n : ss ) { + log_writer.println( " " + n ); + } } private static void print_help() { System.out.println( "Usage: " + gsdi.PRG_NAME - + " [-options] [outfile]" ); + + " [-options] [outfile]" ); System.out.println(); System.out.println( "Options:" ); - // System.out.println( " -" + gsdi.ALLOW_STRIPPING_OF_GENE_TREE_OPTION + ": to allow stripping of gene tree nodes without a matching species in the species tree (writes list of stripped nodes to " + ); - System.out.println( " -" + gsdi.STRIP_OPTION - + ": to strip the species tree of unneeded species prior to duplication inference" ); - System.out.println( " -" + gsdi.SDI_OPTION + ": to use SDI algorithm instead of GSDI algorithm" );//TODO gsdi.ALLOW_STRIPPING_OF_GENE_TREE_OPTION not allowed + System.out.println( " -" + gsdi.ALLOW_STRIPPING_OF_GENE_TREE_OPTION + + ": to allow stripping of gene tree nodes without a matching species" ); System.out.println( " -" + gsdi.MOST_PARSIMONIOUS_OPTION + ": use most parimonious duplication model for GSDI: " ); System.out.println( " assign nodes as speciations which would otherwise be assiged" ); - System.out.println( " as unknown because of polytomies in the species tree" ); + System.out.println( " as potential duplications dueof polytomies in the species tree" ); System.out.println( " -" + gsdi.GUESS_FORMAT_OF_SPECIES_TREE + ": to allow species tree in other formats than phyloXML (i.e. Newick, NHX, Nexus)" ); - System.out.println(); - System.out.println( "Species tree:" ); - System.out - .println( " In phyloXML format (unless option -" - + gsdi.GUESS_FORMAT_OF_SPECIES_TREE - + " is used, in which case the species matching between gene tree and species tree must be via scientific name), with taxonomy data in appropriate fields" ); + System.out.println( " -" + gsdi.SDISE_OPTION + + ": to use SDIse algorithm instead of GSDI algorithm (for binary species trees)" ); System.out.println(); System.out.println( "Gene tree:" ); - System.out.println( " In phyloXM format, with taxonomy and sequence data in appropriate fields" ); + System.out.println( " in phyloXM format, with taxonomy and sequence data in appropriate fields" ); + System.out.println(); + System.out.println( "Species tree:" ); + System.out.println( " in phyloXML format (unless option -" + gsdi.GUESS_FORMAT_OF_SPECIES_TREE + " is used)" ); System.out.println(); - System.out.println( "Example:" ); - // System.out.println( "gsdi - // System.out.println(); - System.out.println( "Note -- GSDI algorithm is under development" ); + System.out.println( "Example: gsdi -" + ALLOW_STRIPPING_OF_GENE_TREE_OPTION + + " gene_tree.xml tree_of_life.xml out.xml" ); System.out.println(); } }