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=4c17f0e0c3ac33ee348108f10782eef9769fb60d;hpb=0ee466206ea1e3ac3025df1110538e3815c160b4;p=jalview.git diff --git a/forester/java/src/org/forester/application/gsdi.java b/forester/java/src/org/forester/application/gsdi.java index 4c17f0e..0f77e5c 100644 --- a/forester/java/src/org/forester/application/gsdi.java +++ b/forester/java/src/org/forester/application/gsdi.java @@ -62,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 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.xml"; - final static private String SUFFIX_FOR_LIST_OF_STIPPED_GENE_TREE_NODES = "_stripped_gene_tree_nodes.txt"; - 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 = "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 { @@ -109,7 +108,7 @@ public final class gsdi { System.exit( -1 ); } final List allowed_options = new ArrayList(); - 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 ); @@ -127,9 +126,8 @@ public final class gsdi { private static void execute( final CommandLineArguments cla ) throws IOException { BASE_ALGORITHM base_algorithm = BASE_ALGORITHM.GSDI; boolean most_parsimonous_duplication_model = false; - boolean species_tree_in_phyloxml = true; boolean allow_stripping_of_gene_tree = false; - 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" ); @@ -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 ); } @@ -342,10 +337,11 @@ public final class gsdi { 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( "Wrote resulting gene tree to : " + out_file ); - log_writer.println( "Wrote resulting gene tree to : " + out_file ); + 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() ); @@ -353,17 +349,20 @@ public final class gsdi { } else if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) ) { final GSDI gsdi = ( GSDI ) sdi; - final File species_tree_used_file = new File( out_file + SUFFIX_FOR_SPECIES_TREE_USED ); + 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 + "]: " + e.getMessage() ); + 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 ); - log_writer.println( "Wrote (stripped) species tree to : " + species_tree_used_file ); + 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() ); @@ -405,7 +404,7 @@ public final class gsdi { printStrippedSpeciesTreeNodesToLog( log_writer, gsdi ); } System.out.println(); - System.out.println( "Wrote log to : " + log_file ); + System.out.println( "Wrote log to : " + log_file.getCanonicalPath() ); System.out.println(); log_writer.close(); } @@ -459,31 +458,28 @@ public final class gsdi { 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.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(); } }