X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Fgsdi.java;h=17dbf7e08f26ded6b6759017b46b0d07f0b03438;hb=8f8bbd46b51ab6778da479b6fa2a444b46ac3a60;hp=eab52df09d22bdf1d1ea05a4ec5df41ee039438a;hpb=6005bacbd8aecc0d320b70568a24d321a30bc85c;p=jalview.git diff --git a/forester/java/src/org/forester/application/gsdi.java b/forester/java/src/org/forester/application/gsdi.java index eab52df..17dbf7e 100644 --- a/forester/java/src/org/forester/application/gsdi.java +++ b/forester/java/src/org/forester/application/gsdi.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.application; @@ -36,11 +36,9 @@ 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.nhx.NHXParser.TAXONOMY_EXTRACTION; 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; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; @@ -48,11 +46,11 @@ import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.sdi.GSDI; +import org.forester.sdi.GSDII; import org.forester.sdi.GSDIR; -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.SDIutil; +import org.forester.sdi.SDIutil.ALGORITHM; import org.forester.util.CommandLineArguments; import org.forester.util.EasyWriter; import org.forester.util.ForesterConstants; @@ -60,12 +58,8 @@ import org.forester.util.ForesterUtil; public final class gsdi { - private enum BASE_ALGORITHM { - GSDIR, 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 SDISE_OPTION = "b"; final static private String GSDIR_OPTION = "r"; final static private String MOST_PARSIMONIOUS_OPTION = "m"; final static private String GUESS_FORMAT_OF_SPECIES_TREE = "q"; @@ -110,7 +104,6 @@ public final class gsdi { System.exit( -1 ); } final List allowed_options = new ArrayList(); - allowed_options.add( gsdi.SDISE_OPTION ); allowed_options.add( gsdi.GSDIR_OPTION ); allowed_options.add( gsdi.GUESS_FORMAT_OF_SPECIES_TREE ); allowed_options.add( gsdi.MOST_PARSIMONIOUS_OPTION ); @@ -127,23 +120,20 @@ public final class gsdi { } private static void execute( final CommandLineArguments cla ) throws IOException { - BASE_ALGORITHM base_algorithm = BASE_ALGORITHM.GSDI; + ALGORITHM base_algorithm = ALGORITHM.GSDI; boolean most_parsimonous_duplication_model = false; boolean allow_stripping_of_gene_tree = false; if ( cla.isOptionSet( gsdi.GSDIR_OPTION ) ) { - base_algorithm = BASE_ALGORITHM.GSDIR; - } - else if ( cla.isOptionSet( gsdi.SDISE_OPTION ) ) { - base_algorithm = BASE_ALGORITHM.SDI; + base_algorithm = ALGORITHM.GSDIR; } if ( cla.isOptionSet( gsdi.MOST_PARSIMONIOUS_OPTION ) ) { - if ( base_algorithm == BASE_ALGORITHM.SDI ) { + if ( base_algorithm == ALGORITHM.SDI ) { ForesterUtil.fatalError( gsdi.PRG_NAME, "Cannot use most parsimonious duplication mode with SDI" ); } most_parsimonous_duplication_model = true; } if ( cla.isOptionSet( gsdi.ALLOW_STRIPPING_OF_GENE_TREE_OPTION ) ) { - if ( base_algorithm == BASE_ALGORITHM.SDI ) { + if ( base_algorithm == ALGORITHM.SDI ) { ForesterUtil.fatalError( gsdi.PRG_NAME, "Cannot allow stripping of gene tree with SDI" ); } allow_stripping_of_gene_tree = true; @@ -187,65 +177,27 @@ public final class gsdi { gene_tree = factory.create( gene_tree_file, new PhyloXmlParser() )[ 0 ]; } catch ( final IOException e ) { - fatalError( "ERROR", - "Failed to read gene tree from [" + gene_tree_file + "]: " + e.getMessage(), + fatalError( "error", + "failed to read gene tree from [" + gene_tree_file + "]: " + e.getMessage(), log_writer ); } try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( species_tree_file, true ); - if ( p instanceof PhyloXmlParser ) { - species_tree = factory.create( species_tree_file, p )[ 0 ]; - } - else { - if ( REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE && ( p instanceof NHXParser ) ) { - ( ( NHXParser ) p ).setReplaceUnderscores( true ); - } - species_tree = factory.create( species_tree_file, p )[ 0 ]; - final TaxonomyComparisonBase comp_base = GSDI.determineTaxonomyComparisonBase( gene_tree ); - switch ( comp_base ) { - case SCIENTIFIC_NAME: - try { - PhylogenyMethods - .transferNodeNameToField( species_tree, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME, - true ); - } - catch ( final PhyloXmlDataFormatException e ) { - fatalError( "USER ERROR", "Failed to transfer general node name to scientific name, in [" - + species_tree_file + "]: " + e.getMessage(), log_writer ); - } - break; - case CODE: - try { - PhylogenyMethods - .transferNodeNameToField( species_tree, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_CODE, - true ); - } - catch ( final PhyloXmlDataFormatException e ) { - fatalError( "USER ERROR", "Failed to transfer general node name to taxonomy code, in [" - + species_tree_file + "]: " + e.getMessage(), log_writer ); - } - break; - case ID: - try { - PhylogenyMethods.transferNodeNameToField( species_tree, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_ID, - true ); - } - catch ( final PhyloXmlDataFormatException e ) { - fatalError( "USER ERROR", "Failed to transfer general node name to taxonomy id, in [" - + species_tree_file + "]: " + e.getMessage(), log_writer ); - } - break; - default: - fatalError( "UNEXPECTED ERROR", "unable to determine comparison base", log_writer ); - } - } + species_tree = SDIutil.parseSpeciesTree( gene_tree, + species_tree_file, + REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE, + true, + TAXONOMY_EXTRACTION.NO ); + } + catch ( final PhyloXmlDataFormatException e ) { + fatalError( "user error", + "failed to transfer general node name, in [" + species_tree_file + "]: " + e.getMessage(), + log_writer ); + } + catch ( final SDIException e ) { + fatalError( "user error", e.getMessage(), log_writer ); } catch ( final IOException e ) { - fatalError( "ERROR", + fatalError( "error", "Failed to read species tree from [" + species_tree_file + "]: " + e.getMessage(), log_writer ); } @@ -254,7 +206,7 @@ public final class gsdi { if ( !gene_tree.isCompletelyBinary() ) { fatalError( "user error", "gene tree is not completely binary", log_writer ); } - if ( base_algorithm == BASE_ALGORITHM.SDI ) { + if ( base_algorithm == ALGORITHM.SDI ) { if ( !species_tree.isCompletelyBinary() ) { fatalError( "user error", "species tree is not completely binary, use GSDI or GSDIR instead", @@ -282,40 +234,31 @@ public final class gsdi { + ( ForesterUtil.isEmpty( species_tree.getName() ) ? "" : gene_tree.getName() ) ); System.out.println( "Species tree name : " + ( ForesterUtil.isEmpty( species_tree.getName() ) ? "" : gene_tree.getName() ) ); - SDI sdi = null; + GSDII gsdii = null; final long start_time = new Date().getTime(); try { - if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) || ( base_algorithm == BASE_ALGORITHM.GSDIR ) ) { - if ( base_algorithm == BASE_ALGORITHM.GSDI ) { - System.out.println( "Algorithm : GSDI" ); - log_writer.println( "Algorithm : GSDI" ); - } - else if ( base_algorithm == BASE_ALGORITHM.GSDIR ) { - System.out.println( "Algorithm : GSDIR" ); - log_writer.println( "Algorithm : GSDIR" ); - } - 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(); - if ( base_algorithm == BASE_ALGORITHM.GSDI ) { - sdi = new GSDI( gene_tree, - species_tree, - most_parsimonous_duplication_model, - allow_stripping_of_gene_tree, - true ); - } - else if ( base_algorithm == BASE_ALGORITHM.GSDIR ) { - sdi = new GSDIR( gene_tree, species_tree, allow_stripping_of_gene_tree, 1 ); - } + if ( base_algorithm == ALGORITHM.GSDI ) { + System.out.println( "Algorithm : GSDI" ); + log_writer.println( "Algorithm : GSDI" ); } - else { - System.out.println(); - System.out.println( "Algorithm : SDI" ); - log_writer.println( "Algorithm : SDI" ); - log_writer.flush(); - sdi = new SDIse( gene_tree, species_tree ); + else if ( base_algorithm == ALGORITHM.GSDIR ) { + System.out.println( "Algorithm : GSDIR" ); + log_writer.println( "Algorithm : GSDIR" ); + } + 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(); + if ( base_algorithm == ALGORITHM.GSDI ) { + gsdii = new GSDI( gene_tree, + species_tree, + most_parsimonous_duplication_model, + allow_stripping_of_gene_tree, + true ); + } + else if ( base_algorithm == ALGORITHM.GSDIR ) { + gsdii = new GSDIR( gene_tree, species_tree, allow_stripping_of_gene_tree, true ); } } catch ( final SDIException e ) { @@ -324,6 +267,9 @@ public final class gsdi { catch ( final IOException e ) { fatalError( "error", e.toString(), log_writer ); } + catch ( final OutOfMemoryError e ) { + ForesterUtil.outOfMemoryError( e ); + } catch ( final Exception e ) { e.printStackTrace(); fatalError( "unexpected error", e.toString(), log_writer ); @@ -332,27 +278,17 @@ public final class gsdi { + "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() ); - } - if ( ( base_algorithm == BASE_ALGORITHM.GSDIR ) ) { - final GSDIR gsdir = ( GSDIR ) sdi; - System.out.println( "Mapping based on : " + gsdir.getTaxCompBase() ); - log_writer.println( "Mapping based on : " + gsdir.getTaxCompBase() ); - System.out.println( "Minimal duplications sum : " + gsdir.getMinDuplicationsSum() ); - log_writer.println( "Minimal duplications sum : " + gsdir.getMinDuplicationsSum() ); + System.out.println( "Mapping based on : " + gsdii.getTaxCompBase() ); + log_writer.println( "Mapping based on : " + gsdii.getTaxCompBase() ); + if ( ( base_algorithm == ALGORITHM.GSDIR ) ) { + final GSDIR gsdir = ( GSDIR ) gsdii; System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); log_writer.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); } try { final PhylogenyWriter writer = new PhylogenyWriter(); - if ( base_algorithm == BASE_ALGORITHM.GSDIR ) { - writer.toPhyloXML( out_file, - ( ( GSDIR ) sdi ).getMinDuplicationsSumGeneTrees(), - 0, - ForesterUtil.LINE_SEPARATOR ); + if ( base_algorithm == ALGORITHM.GSDIR ) { + writer.toPhyloXML( out_file, ( ( GSDIR ) gsdii ).getMinDuplicationsSumGeneTree(), 0 ); } else { writer.toPhyloXML( out_file, gene_tree, 0 ); @@ -364,103 +300,67 @@ public final class gsdi { } 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.println( "Mapping cost : " + sdi.computeMappingCostL() ); - } - else if ( ( base_algorithm == BASE_ALGORITHM.GSDI ) || ( base_algorithm == BASE_ALGORITHM.GSDIR ) ) { - 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() ); - if ( ( gsdi.getReMappedScientificNamesFromGeneTree() != null ) - && !gsdi.getReMappedScientificNamesFromGeneTree().isEmpty() ) { - System.out.println( "Number of gene tree species remapped : " - + gsdi.getReMappedScientificNamesFromGeneTree().size() ); - log_writer.println( "Number of gene tree species remapped : " - + gsdi.getReMappedScientificNamesFromGeneTree().size() ); - writeToRemappedFile( out_file, gsdi.getReMappedScientificNamesFromGeneTree(), log_writer ); - } + 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, species_tree, 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() ); + if ( ( gsdii.getReMappedScientificNamesFromGeneTree() != null ) + && !gsdii.getReMappedScientificNamesFromGeneTree().isEmpty() ) { + System.out.println( "Number of gene tree species remapped : " + + gsdii.getReMappedScientificNamesFromGeneTree().size() ); + log_writer.println( "Number of gene tree species remapped : " + + gsdii.getReMappedScientificNamesFromGeneTree().size() ); + writeToRemappedFile( out_file, gsdii.getReMappedScientificNamesFromGeneTree(), log_writer ); } 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 external nodes in species tree : " + species_tree.getNumberOfExternalNodes() ); + log_writer.println( "Number of external nodes in species tree : " + species_tree.getNumberOfExternalNodes() ); + final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree ); + 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 : " + + gsdii.getStrippedExternalGeneTreeNodes().size() ); + log_writer.println( "External nodes stripped from gene tree : " + + gsdii.getStrippedExternalGeneTreeNodes().size() ); + System.out.println( "External nodes stripped from species tree: " + gsdii.getStrippedSpeciesTreeNodes().size() ); + log_writer.println( "External nodes stripped from species tree: " + gsdii.getStrippedSpeciesTreeNodes().size() ); 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; + System.out.println( "Number of speciations : " + gsdii.getSpeciationsSum() ); + log_writer.println( "Number of speciations : " + gsdii.getSpeciationsSum() ); + if ( ( base_algorithm == ALGORITHM.GSDIR ) ) { + final GSDIR gsdir = ( GSDIR ) gsdii; + System.out.println( "Minimal number of duplications : " + gsdir.getMinDuplicationsSum() ); + log_writer.println( "Minimal number of duplications : " + gsdir.getMinDuplicationsSum() ); + } + else if ( ( base_algorithm == ALGORITHM.GSDI ) ) { + final GSDI gsdi = ( GSDI ) gsdii; + System.out.println( "Number of duplications : " + gsdi.getDuplicationsSum() ); + log_writer.println( "Number of duplications : " + gsdi.getDuplicationsSum() ); if ( !most_parsimonous_duplication_model ) { 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(); + printMappedNodesToLog( log_writer, gsdii ); + log_writer.println(); + printStrippedGeneTreeNodesToLog( log_writer, gsdii ); System.out.println(); System.out.println( "Wrote log to : " + log_file.getCanonicalPath() ); System.out.println(); log_writer.close(); } - private static void writeToRemappedFile( final File out_file, - final SortedSet remapped, - final EasyWriter log_writer ) throws IOException { - final File file = new File( ForesterUtil.removeSuffix( out_file.toString() ) + REMAPPED_SUFFIX ); - final EasyWriter remapped_writer = ForesterUtil.createEasyWriter( file ); - for( final String s : remapped ) { - remapped_writer.println( s ); - } - remapped_writer.close(); - System.out.println( "Wrote remapped gene tree species to : " + file.getCanonicalPath() ); - log_writer.println( "Wrote remapped gene tree species to : " + file.getCanonicalPath() ); - } - - 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 fatalError( final String type, final String msg, final EasyWriter log_writer ) { try { log_writer.flush(); @@ -475,30 +375,6 @@ public final class gsdi { ForesterUtil.fatalError( gsdi.PRG_NAME, msg ); } - 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 print_help() { System.out.println( "Usage: " + gsdi.PRG_NAME + " [-options] " ); @@ -512,8 +388,6 @@ public final class gsdi { System.out.println( " as potential duplications due to 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( " -" + gsdi.SDISE_OPTION - + ": to use SDIse algorithm instead of GSDI algorithm (for binary species trees)" ); System.out.println( " -" + gsdi.GSDIR_OPTION + ": to use GSDIR algorithm instead of GSDI algorithm (re-rooting)" ); System.out.println(); @@ -527,4 +401,52 @@ public final class gsdi { + " gene_tree.xml tree_of_life.xml out.xml" ); System.out.println(); } + + private static void printMappedNodesToLog( final EasyWriter log_writer, final GSDII 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 GSDII 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 writeToRemappedFile( final File out_file, + final SortedSet remapped, + final EasyWriter log_writer ) throws IOException { + final File file = new File( ForesterUtil.removeSuffix( out_file.toString() ) + REMAPPED_SUFFIX ); + final EasyWriter remapped_writer = ForesterUtil.createEasyWriter( file ); + for( final String s : remapped ) { + remapped_writer.println( s ); + } + remapped_writer.close(); + System.out.println( "Wrote remapped gene tree species to : " + file.getCanonicalPath() ); + log_writer.println( "Wrote remapped gene tree species to : " + file.getCanonicalPath() ); + } }