X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Fsurf_paup.java;h=eff34257d2a76270a67be74acbfad4c80e93b846;hb=d30f8d155dee1fbfa17946cf80a203cc886ffdd6;hp=297e16f2b4a5616e85556d8b6dda40079af48cef;hpb=493e40b0c936b65da342134da37e8b856b9b80af;p=jalview.git diff --git a/forester/java/src/org/forester/application/surf_paup.java b/forester/java/src/org/forester/application/surf_paup.java index 297e16f..eff3425 100644 --- a/forester/java/src/org/forester/application/surf_paup.java +++ b/forester/java/src/org/forester/application/surf_paup.java @@ -6,7 +6,7 @@ // Copyright (C) 2008-2009 Christian M. Zmasek // Copyright (C) 2008-2009 Burnham Institute for Medical Research // All rights reserved -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -16,7 +16,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA @@ -38,8 +38,10 @@ import org.forester.io.parsers.nexus.NexusCharactersParser; import org.forester.io.parsers.nexus.NexusPhylogeniesParser; import org.forester.io.parsers.nexus.PaupLogParser; import org.forester.phylogeny.Phylogeny; +import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; +import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.surfacing.DomainParsimonyCalculator; import org.forester.surfacing.SurfacingUtil; import org.forester.util.CommandLineArguments; @@ -101,8 +103,9 @@ public class surf_paup { phylogenies = factory.create( surfacing_nexus_outfile, phylogeny_parser ); } catch ( final IOException e ) { - ForesterUtil.fatalError( PRG_NAME, "problem with parsing phylogeny [" + surfacing_nexus_outfile + "]: " - + e.getMessage() ); + ForesterUtil.fatalError( PRG_NAME, + "problem with parsing phylogeny [" + surfacing_nexus_outfile + "]: " + + e.getMessage() ); e.printStackTrace(); } if ( phylogenies.length != 1 ) { @@ -113,7 +116,7 @@ public class surf_paup { if ( !phylogeny.isRooted() ) { ForesterUtil.fatalError( PRG_NAME, "phylogeny from [" + surfacing_nexus_outfile + "] is not rooted" ); } - ForesterUtil.postOrderRelabelInternalNodes( phylogeny, phylogeny.getNumberOfExternalNodes() + 1 ); + postOrderRelabelInternalNodes( phylogeny, phylogeny.getNumberOfExternalNodes() + 1 ); CharacterStateMatrix matrix = null; final PaupLogParser paup_log_parser = new PaupLogParser(); try { @@ -121,11 +124,12 @@ public class surf_paup { matrix = paup_log_parser.parse(); } catch ( final IOException e ) { - ForesterUtil.fatalError( PRG_NAME, "failed to parse matrix from [" + paup_log_file + "]: " - + e.getMessage() ); + ForesterUtil.fatalError( PRG_NAME, + "failed to parse matrix from [" + paup_log_file + "]: " + e.getMessage() ); } - ForesterUtil.programMessage( PRG_NAME, "read in character state matrix of size " - + matrix.getNumberOfIdentifiers() + "x" + matrix.getNumberOfCharacters() ); + ForesterUtil.programMessage( PRG_NAME, + "read in character state matrix of size " + matrix.getNumberOfIdentifiers() + "x" + + matrix.getNumberOfCharacters() ); final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( phylogeny ); domain_parsimony.executeOnGivenBinaryStatesMatrix( matrix, labels ); final String sep = ForesterUtil.LINE_SEPARATOR + "###################" + ForesterUtil.LINE_SEPARATOR; @@ -156,6 +160,16 @@ public class surf_paup { ForesterUtil.programMessage( PRG_NAME, "OK" ); } + final private static void postOrderRelabelInternalNodes( final Phylogeny phylogeny, final int starting_number ) { + int i = starting_number; + for( final PhylogenyNodeIterator it = phylogeny.iteratorPostorder(); it.hasNext(); ) { + final PhylogenyNode node = it.next(); + if ( !node.isExternal() ) { + node.setName( String.valueOf( i++ ) ); + } + } + } + private static void printHelp() { System.out.println(); System.out.println( "Usage:" );