From 1a6e8795d5cd4c9b137069cc47121689b83377ed Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Tue, 4 Dec 2012 23:00:13 +0000 Subject: [PATCH] in progress --- .../forester/application/phyloxml_converter.java | 7 +- .../org/forester/application/printAllSpecies.java | 79 ----------------- .../org/forester/application/printSameOrder.java | 78 ----------------- .../org/forester/application/support_transfer.java | 2 +- .../org/forester/archaeopteryx/Archaeopteryx.java | 4 +- .../archaeopteryx/MainFrameApplication.java | 6 +- .../org/forester/archaeopteryx/UrlTreeReader.java | 10 +-- .../io/parsers/nexus/NexusPhylogeniesParser.java | 3 +- .../src/org/forester/io/parsers/nhx/NHXParser.java | 75 ++++++++-------- .../org/forester/io/parsers/util/ParserUtils.java | 5 +- .../org/forester/phylogeny/PhylogenyMethods.java | 4 - .../src/org/forester/phylogeny/PhylogenyNode.java | 8 +- forester/java/src/org/forester/sdi/RIO.java | 2 +- forester/java/src/org/forester/test/Test.java | 92 +++++++++----------- 14 files changed, 100 insertions(+), 275 deletions(-) delete mode 100644 forester/java/src/org/forester/application/printAllSpecies.java delete mode 100644 forester/java/src/org/forester/application/printSameOrder.java diff --git a/forester/java/src/org/forester/application/phyloxml_converter.java b/forester/java/src/org/forester/application/phyloxml_converter.java index 8951e18..24fe964 100644 --- a/forester/java/src/org/forester/application/phyloxml_converter.java +++ b/forester/java/src/org/forester/application/phyloxml_converter.java @@ -209,17 +209,16 @@ public class phyloxml_converter { && ( field != PhylogenyMethods.PhylogenyNodeField.TAXONOMY_COMMON_NAME ) && ( field != PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME ) ) { if ( extr_taxonomy_pf_only ) { - ( ( NHXParser ) parser ) - .setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); replace_underscores = false; } else if ( extr_taxonomy ) { - ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.YES ); replace_underscores = false; } } else { - ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); } ( ( NHXParser ) parser ).setReplaceUnderscores( replace_underscores ); ( ( NHXParser ) parser ).setIgnoreQuotes( ignore_quotes ); diff --git a/forester/java/src/org/forester/application/printAllSpecies.java b/forester/java/src/org/forester/application/printAllSpecies.java deleted file mode 100644 index df7ae17..0000000 --- a/forester/java/src/org/forester/application/printAllSpecies.java +++ /dev/null @@ -1,79 +0,0 @@ -// $Id: -// FORESTER -- software libraries and applications -// for evolutionary biology research and applications. -// -// 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 -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// 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 -// -// Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester - -package org.forester.application; - -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; - -import org.forester.io.parsers.PhylogenyParser; -import org.forester.io.parsers.util.ParserUtils; -import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyMethods; -import org.forester.phylogeny.PhylogenyNode; -import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; -import org.forester.phylogeny.factories.PhylogenyFactory; - -public class printAllSpecies { - - public static void main( final String args[] ) { - Phylogeny tree = null; - PhylogenyNode node = null; - PrintWriter out = null; - File infile = null, outfile = null; - if ( args.length != 2 ) { - System.err.println( "\nprintAllSpecies: Wrong number of arguments." ); - System.err.println( "Usage: \"java printAllSpecies \"\n" ); - System.exit( -1 ); - } - infile = new File( args[ 0 ] ); - outfile = new File( args[ 1 ] ); - try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( infile, true ); - tree = factory.create( infile, pp )[ 0 ]; - } - catch ( final Exception e ) { - System.err.println( e + "\nCould not read " + infile + "\n" ); - System.exit( -1 ); - } - node = tree.getFirstExternalNode(); - try { - out = new PrintWriter( new FileWriter( outfile ), true ); - while ( node != null ) { - out.println( PhylogenyMethods.getSpecies( node ) ); - node = node.getNextExternalNode(); - } - } - catch ( final Exception e ) { - System.err.println( e + "\nException during writing.\n" ); - System.exit( -1 ); - } - finally { - out.close(); - } - } -} diff --git a/forester/java/src/org/forester/application/printSameOrder.java b/forester/java/src/org/forester/application/printSameOrder.java deleted file mode 100644 index 9004046..0000000 --- a/forester/java/src/org/forester/application/printSameOrder.java +++ /dev/null @@ -1,78 +0,0 @@ -// $Id: -// FORESTER -- software libraries and applications -// for evolutionary biology research and applications. -// -// 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 -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// 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 -// -// Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester - -package org.forester.application; - -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; - -import org.forester.io.parsers.PhylogenyParser; -import org.forester.io.parsers.util.ParserUtils; -import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyNode; -import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; -import org.forester.phylogeny.factories.PhylogenyFactory; - -public class printSameOrder { - - public static void main( final String args[] ) { - Phylogeny tree = null; - PhylogenyNode node = null; - PrintWriter out = null; - File infile = null, outfile = null; - if ( args.length != 2 ) { - System.err.println( "\nprintSameOrder: Wrong number of arguments." ); - System.err.println( "Usage: \"java printSameOrder \"\n" ); - System.exit( -1 ); - } - infile = new File( args[ 0 ] ); - outfile = new File( args[ 1 ] ); - try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( infile, true ); - tree = factory.create( infile, pp )[ 0 ]; - } - catch ( final Exception e ) { - System.err.println( e + "\nCould not read " + infile + "\n" ); - System.exit( -1 ); - } - node = tree.getFirstExternalNode(); - try { - out = new PrintWriter( new FileWriter( outfile ), true ); - while ( node != null ) { - out.println( node.getName() ); - node = node.getNextExternalNode(); - } - } - catch ( final Exception e ) { - System.err.println( e + "\nException during writing.\n" ); - System.exit( -1 ); - } - finally { - out.close(); - } - } -} diff --git a/forester/java/src/org/forester/application/support_transfer.java b/forester/java/src/org/forester/application/support_transfer.java index 5eecf55..3f1af34 100644 --- a/forester/java/src/org/forester/application/support_transfer.java +++ b/forester/java/src/org/forester/application/support_transfer.java @@ -95,7 +95,7 @@ public final class support_transfer { final PhylogenyParser pp_bl = ParserUtils.createParserDependingOnFileType( infile_bl, true ); final PhylogenyParser pp_s = ParserUtils.createParserDependingOnFileType( infile_support_vals, true ); if ( pp_bl instanceof NHXParser ) { - ( ( NHXParser ) pp_bl ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + ( ( NHXParser ) pp_bl ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.YES ); } phylogeny_w_bl = factory.create( infile_bl, pp_bl )[ index_of_tree_w_bl ]; phylogeny_w_support_vals = factory.create( infile_support_vals, pp_s )[ 0 ]; diff --git a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java index 7f96bdd..6a28ef7 100644 --- a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java +++ b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java @@ -94,9 +94,9 @@ public final class Archaeopteryx { final NHXParser nhx = ( NHXParser ) p; nhx.setReplaceUnderscores( conf.isReplaceUnderscoresInNhParsing() ); nhx.setIgnoreQuotes( false ); - PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO; + NHXParser.TAXONOMY_EXTRACTION te = NHXParser.TAXONOMY_EXTRACTION.NO; if ( conf.isExtractPfamTaxonomyCodesInNhParsing() ) { - te = PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY; + te = NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY; } nhx.setTaxonomyExtraction( te ); } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index e6be588..709c621 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -1354,7 +1354,7 @@ public final class MainFrameApplication extends MainFrame { final String name = n.getName().trim(); if ( !ForesterUtil.isEmpty( name ) ) { final String code = ParserUtils - .extractTaxonomyCodeFromNodeName( name, PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + .extractTaxonomyCodeFromNodeName( name, NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !ForesterUtil.isEmpty( code ) ) { PhylogenyMethods.setTaxonomyCode( n, code ); } @@ -2253,9 +2253,9 @@ public final class MainFrameApplication extends MainFrame { private void setSpecialOptionsForNhxParser( final NHXParser nhx ) { nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() ); - PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO; + NHXParser.TAXONOMY_EXTRACTION te = NHXParser.TAXONOMY_EXTRACTION.NO; if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) { - te = PhylogenyMethods.TAXONOMY_EXTRACTION.YES; + te = NHXParser.TAXONOMY_EXTRACTION.YES; } nhx.setTaxonomyExtraction( te ); } diff --git a/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java b/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java index f96864f..432c2ac 100644 --- a/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java +++ b/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java @@ -103,27 +103,25 @@ public class UrlTreeReader implements Runnable { break; case NH: parser = new NHXParser(); - ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); ( ( NHXParser ) parser ).setReplaceUnderscores( true ); ( ( NHXParser ) parser ).setGuessRootedness( true ); break; case NH_EXTRACT_TAXONOMY: parser = new NHXParser(); - ( ( NHXParser ) parser ) - .setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); ( ( NHXParser ) parser ).setReplaceUnderscores( false ); ( ( NHXParser ) parser ).setGuessRootedness( true ); break; case PFAM: parser = new NHXParser(); - ( ( NHXParser ) parser ) - .setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); ( ( NHXParser ) parser ).setReplaceUnderscores( false ); ( ( NHXParser ) parser ).setGuessRootedness( true ); break; case NHX: parser = new NHXParser(); - ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO ); + ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); ( ( NHXParser ) parser ).setReplaceUnderscores( false ); ( ( NHXParser ) parser ).setGuessRootedness( true ); break; diff --git a/forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java b/forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java index 0abd855..6a51d8a 100644 --- a/forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java +++ b/forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java @@ -41,7 +41,6 @@ import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.util.ParserUtils; import org.forester.io.parsers.util.PhylogenyParserException; import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; @@ -73,7 +72,7 @@ public class NexusPhylogeniesParser implements PhylogenyParser { final boolean is_rooted ) throws IOException { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final NHXParser pars = new NHXParser(); - pars.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO ); + pars.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); pars.setReplaceUnderscores( isReplaceUnderscores() ); pars.setIgnoreQuotes( isIgnoreQuotes() ); if ( rooted_info_present ) { diff --git a/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java b/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java index dc34b0f..99a78bf 100644 --- a/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java +++ b/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java @@ -61,39 +61,34 @@ import org.forester.util.ForesterUtil; public final class NHXParser implements PhylogenyParser { - public static final PhylogenyMethods.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT = PhylogenyMethods.TAXONOMY_EXTRACTION.NO; - final static private boolean GUESS_ROOTEDNESS_DEFAULT = true; - final static private boolean GUESS_IF_SUPPORT_VALUES = true; - final static private boolean IGNORE_QUOTES_DEFAULT = false; - final static public boolean REPLACE_UNDERSCORES_DEFAULT = false; - private boolean _saw_closing_paren; - final static private byte STRING = 0; - final static private byte STRING_BUFFER = 1; - final static private byte CHAR_ARRAY = 2; - final static private byte BUFFERED_READER = 3; - private boolean _guess_rootedness; - private boolean _has_next; - private boolean _ignore_quotes; - private byte _input_type; - private int _source_length; - private PhylogenyNode _current_node; - private StringBuilder _current_anotation; - private Object _nhx_source; - private int _clade_level; - private List _phylogenies; - private Phylogeny _current_phylogeny; - private PhylogenyMethods.TAXONOMY_EXTRACTION _taxonomy_extraction; - private boolean _replace_underscores; - public final static Pattern UC_LETTERS_NUMBERS_PATTERN = Pattern - .compile( "^[A-Z0-9]+$" ); - public final static Pattern NUMBERS_ONLY_PATTERN = Pattern - .compile( "^[0-9\\.]+$" ); - public final static Pattern MB_PROB_PATTERN = Pattern - .compile( "prob=([^,]+)" ); - public final static Pattern MB_PROB_SD_PATTERN = Pattern - .compile( "prob_stddev=([^,]+)" ); - public final static Pattern MB_BL_PATTERN = Pattern - .compile( "length_median=([^,]+)" ); + public static final TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT = NHXParser.TAXONOMY_EXTRACTION.NO; + final static private boolean GUESS_ROOTEDNESS_DEFAULT = true; + final static private boolean GUESS_IF_SUPPORT_VALUES = true; + final static private boolean IGNORE_QUOTES_DEFAULT = false; + final static public boolean REPLACE_UNDERSCORES_DEFAULT = false; + private boolean _saw_closing_paren; + final static private byte STRING = 0; + final static private byte STRING_BUFFER = 1; + final static private byte CHAR_ARRAY = 2; + final static private byte BUFFERED_READER = 3; + private boolean _guess_rootedness; + private boolean _has_next; + private boolean _ignore_quotes; + private byte _input_type; + private int _source_length; + private PhylogenyNode _current_node; + private StringBuilder _current_anotation; + private Object _nhx_source; + private int _clade_level; + private List _phylogenies; + private Phylogeny _current_phylogeny; + private NHXParser.TAXONOMY_EXTRACTION _taxonomy_extraction; + private boolean _replace_underscores; + public final static Pattern UC_LETTERS_NUMBERS_PATTERN = Pattern.compile( "^[A-Z0-9]+$" ); + public final static Pattern NUMBERS_ONLY_PATTERN = Pattern.compile( "^[0-9\\.]+$" ); + public final static Pattern MB_PROB_PATTERN = Pattern.compile( "prob=([^,]+)" ); + public final static Pattern MB_PROB_SD_PATTERN = Pattern.compile( "prob_stddev=([^,]+)" ); + public final static Pattern MB_BL_PATTERN = Pattern.compile( "length_median=([^,]+)" ); public NHXParser() { init(); @@ -198,7 +193,7 @@ public final class NHXParser implements PhylogenyParser { return _source_length; } - public PhylogenyMethods.TAXONOMY_EXTRACTION getTaxonomyExtraction() { + public NHXParser.TAXONOMY_EXTRACTION getTaxonomyExtraction() { return _taxonomy_extraction; } @@ -605,7 +600,7 @@ public final class NHXParser implements PhylogenyParser { _source_length = source_length; } - public void setTaxonomyExtraction( final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) { + public void setTaxonomyExtraction( final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction ) { _taxonomy_extraction = taxonomy_extraction; } @@ -645,10 +640,10 @@ public final class NHXParser implements PhylogenyParser { public static void parseNHX( String s, final PhylogenyNode node_to_annotate, - final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction, + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, final boolean replace_underscores ) throws NHXFormatException, PhyloXmlDataFormatException { - if ( ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.NO ) && replace_underscores ) { + if ( ( taxonomy_extraction != NHXParser.TAXONOMY_EXTRACTION.NO ) && replace_underscores ) { throw new IllegalArgumentException( "cannot extract taxonomies and replace under scores at the same time" ); } if ( ( s != null ) && ( s.length() > 0 ) ) { @@ -688,7 +683,7 @@ public final class NHXParser implements PhylogenyParser { if ( !s.startsWith( ":" ) ) { node_to_annotate.setName( t.nextToken() ); if ( !replace_underscores - && ( !is_nhx && ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.NO ) ) ) { + && ( !is_nhx && ( taxonomy_extraction != NHXParser.TAXONOMY_EXTRACTION.NO ) ) ) { final String tax = ParserUtils.extractTaxonomyCodeFromNodeName( node_to_annotate.getName(), taxonomy_extraction ); if ( !ForesterUtil.isEmpty( tax ) ) { @@ -856,4 +851,8 @@ public final class NHXParser implements PhylogenyParser { final int blu = ForesterUtil.limitRangeForColor( Integer.parseInt( st.nextToken() ) ); return new Color( red, green, blu ); } + + public static enum TAXONOMY_EXTRACTION { + NO, YES, PFAM_STYLE_ONLY; + } } diff --git a/forester/java/src/org/forester/io/parsers/util/ParserUtils.java b/forester/java/src/org/forester/io/parsers/util/ParserUtils.java index 219f859..cd1627c 100644 --- a/forester/java/src/org/forester/io/parsers/util/ParserUtils.java +++ b/forester/java/src/org/forester/io/parsers/util/ParserUtils.java @@ -225,14 +225,13 @@ public final class ParserUtils { * @return */ public static String extractTaxonomyCodeFromNodeName( final String name, - final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) { + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction ) { if ( ( name.indexOf( "_" ) > 0 ) && ( name.length() < 31 ) // && ( name.lastIndexOf( "_" ) == name.indexOf( "_" ) ) && ( name.indexOf( "|" ) < 0 ) && ( name.indexOf( "." ) < 0 ) - && ( ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name - .indexOf( "/" ) >= 0 ) ) + && ( ( taxonomy_extraction != NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name.indexOf( "/" ) >= 0 ) ) && ( ( ( name.indexOf( "/" ) ) < 0 ) || ( name.indexOf( "/" ) > name.indexOf( "_" ) ) ) ) { final String[] s = name.split( "[_/]" ); if ( s.length > 1 ) { diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java index 67e9b52..d6949fb 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java @@ -1692,10 +1692,6 @@ public class PhylogenyMethods { TAXONOMY_ID; } - public static enum TAXONOMY_EXTRACTION { - NO, YES, PFAM_STYLE_ONLY; - } - public static enum DESCENDANT_SORT_PRIORITY { TAXONOMY, SEQUENCE, NODE_NAME; } diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index 625cf19..819ba7a 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -1147,24 +1147,24 @@ public final class PhylogenyNode implements Comparable { public static PhylogenyNode createInstanceFromNhxString( final String nhx ) throws NHXFormatException, PhyloXmlDataFormatException { - return new PhylogenyNode( nhx, PhylogenyMethods.TAXONOMY_EXTRACTION.NO, false ); + return new PhylogenyNode( nhx, NHXParser.TAXONOMY_EXTRACTION.NO, false ); } public static PhylogenyNode createInstanceFromNhxString( final String nhx, - final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction ) throws NHXFormatException, PhyloXmlDataFormatException { return new PhylogenyNode( nhx, taxonomy_extraction, false ); } public static PhylogenyNode createInstanceFromNhxString( final String nhx, - final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction, + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, final boolean replace_underscores ) throws NHXFormatException, PhyloXmlDataFormatException { return new PhylogenyNode( nhx, taxonomy_extraction, replace_underscores ); } private PhylogenyNode( final String nhx, - final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction, + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, final boolean replace_underscores ) throws NHXFormatException, PhyloXmlDataFormatException { // init(); NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores ); diff --git a/forester/java/src/org/forester/sdi/RIO.java b/forester/java/src/org/forester/sdi/RIO.java index c2402b3..2b51b69 100644 --- a/forester/java/src/org/forester/sdi/RIO.java +++ b/forester/java/src/org/forester/sdi/RIO.java @@ -382,7 +382,7 @@ public final class RIO { final NHXParser nhx = ( NHXParser ) p; nhx.setReplaceUnderscores( false ); nhx.setIgnoreQuotes( true ); - nhx.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + nhx.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.YES ); } final Phylogeny[] gene_trees = factory.create( gene_trees_file, p ); // Removes from species_tree all species not found in gene_tree. diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 547d9cd..66f883e 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -64,7 +64,6 @@ import org.forester.pccx.TestPccx; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyBranch; import org.forester.phylogeny.PhylogenyMethods; -import org.forester.phylogeny.PhylogenyMethods.TAXONOMY_EXTRACTION; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.BinaryCharacters; @@ -857,11 +856,11 @@ public final class Test { } final PhylogenyNode n1 = new PhylogenyNode(); final PhylogenyNode n2 = PhylogenyNode - .createInstanceFromNhxString( "", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); final PhylogenyNode n3 = PhylogenyNode - .createInstanceFromNhxString( "n3", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); final PhylogenyNode n4 = PhylogenyNode - .createInstanceFromNhxString( "n4:0.01", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( n1.isHasAssignedEvent() ) { return false; } @@ -4442,7 +4441,7 @@ public final class Test { return false; } final NHXParser nhxp = new NHXParser(); - nhxp.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO ); + nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); nhxp.setReplaceUnderscores( true ); final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ]; if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) { @@ -4819,8 +4818,7 @@ public final class Test { return false; } final PhylogenyNode n8 = PhylogenyNode - .createInstanceFromNhxString( "n8_ECOLI/12:0.01", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n8.getName().equals( "n8_ECOLI/12" ) ) { return false; } @@ -4828,8 +4826,7 @@ public final class Test { return false; } final PhylogenyNode n9 = PhylogenyNode - .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) { return false; } @@ -4837,20 +4834,20 @@ public final class Test { return false; } final PhylogenyNode n10 = PhylogenyNode - .createInstanceFromNhxString( "n10.ECOLI", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n10.getName().equals( "n10.ECOLI" ) ) { return false; } final PhylogenyNode n20 = PhylogenyNode - .createInstanceFromNhxString( "n20_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) { return false; } - final PhylogenyNode n20x = PhylogenyNode - .createInstanceFromNhxString( "n20_ECOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2", + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) { return false; } @@ -4858,7 +4855,7 @@ public final class Test { return false; } final PhylogenyNode n20xx = PhylogenyNode - .createInstanceFromNhxString( "n20_eCOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) { return false; } @@ -4866,7 +4863,7 @@ public final class Test { return false; } final PhylogenyNode n20xxx = PhylogenyNode - .createInstanceFromNhxString( "n20_ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) { return false; } @@ -4874,15 +4871,15 @@ public final class Test { return false; } final PhylogenyNode n20xxxx = PhylogenyNode - .createInstanceFromNhxString( "n20_Ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) { return false; } if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) { return false; } - final PhylogenyNode n21 = PhylogenyNode - .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG", + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !n21.getName().equals( "n21_PIG" ) ) { return false; } @@ -4890,7 +4887,7 @@ public final class Test { return false; } final PhylogenyNode n21x = PhylogenyNode - .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n21x.getName().equals( "n21_PIG" ) ) { return false; } @@ -4898,7 +4895,7 @@ public final class Test { return false; } final PhylogenyNode n22 = PhylogenyNode - .createInstanceFromNhxString( "n22/PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n22.getName().equals( "n22/PIG" ) ) { return false; } @@ -4906,7 +4903,7 @@ public final class Test { return false; } final PhylogenyNode n23 = PhylogenyNode - .createInstanceFromNhxString( "n23/PIG_1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n23.getName().equals( "n23/PIG_1" ) ) { return false; } @@ -4914,7 +4911,7 @@ public final class Test { return false; } final PhylogenyNode a = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) { return false; } @@ -4922,8 +4919,7 @@ public final class Test { return false; } final PhylogenyNode b = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI1/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { return false; } @@ -4932,7 +4928,7 @@ public final class Test { } final PhylogenyNode c = PhylogenyNode .createInstanceFromNhxString( "n10_RATAF12/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { return false; } @@ -4941,7 +4937,7 @@ public final class Test { } final PhylogenyNode c1 = PhylogenyNode .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) { return false; } @@ -4950,7 +4946,7 @@ public final class Test { } final PhylogenyNode c2 = PhylogenyNode .createInstanceFromNhxString( "n10_Bovin_1/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) { return false; } @@ -4958,7 +4954,7 @@ public final class Test { return false; } final PhylogenyNode d = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !d.getName().equals( "n10_RAT1/1-2" ) ) { return false; } @@ -4966,23 +4962,23 @@ public final class Test { return false; } final PhylogenyNode e = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !e.getName().equals( "n10_RAT1" ) ) { return false; } if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) { return false; } - final PhylogenyNode e2 = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + final PhylogenyNode e2 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT1", + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !e2.getName().equals( "n10_RAT1" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) { return false; } - final PhylogenyNode e3 = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT~", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + final PhylogenyNode e3 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT~", + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !e3.getName().equals( "n10_RAT~" ) ) { return false; } @@ -4991,7 +4987,7 @@ public final class Test { } final PhylogenyNode n11 = PhylogenyNode .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) { return false; } @@ -5003,7 +4999,7 @@ public final class Test { } final PhylogenyNode n12 = PhylogenyNode .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) { return false; } @@ -5013,16 +5009,16 @@ public final class Test { if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) { return false; } - final PhylogenyNode m = PhylogenyNode - .createInstanceFromNhxString( "n10_MOUSEa", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + final PhylogenyNode m = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSEa", + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !m.getName().equals( "n10_MOUSEa" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) { return false; } - final PhylogenyNode o = PhylogenyNode - .createInstanceFromNhxString( "n10_MOUSE_", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + final PhylogenyNode o = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSE_", + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !o.getName().equals( "n10_MOUSE_" ) ) { return false; } @@ -5108,8 +5104,7 @@ public final class Test { return false; } final PhylogenyNode n13 = PhylogenyNode - .createInstanceFromNhxString( "blah_12345/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n13.getName().equals( "blah_12345/1-2" ) ) { return false; } @@ -5117,8 +5112,7 @@ public final class Test { return false; } final PhylogenyNode n14 = PhylogenyNode - .createInstanceFromNhxString( "blah_12X45/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "blah_12X45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n14.getName().equals( "blah_12X45/1-2" ) ) { return false; } @@ -5127,7 +5121,7 @@ public final class Test { } final PhylogenyNode n15 = PhylogenyNode .createInstanceFromNhxString( "something_wicked[123]", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n15.getName().equals( "something_wicked" ) ) { return false; } @@ -5138,8 +5132,7 @@ public final class Test { return false; } final PhylogenyNode n16 = PhylogenyNode - .createInstanceFromNhxString( "something_wicked2[9]", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "something_wicked2[9]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n16.getName().equals( "something_wicked2" ) ) { return false; } @@ -5150,8 +5143,7 @@ public final class Test { return false; } final PhylogenyNode n17 = PhylogenyNode - .createInstanceFromNhxString( "something_wicked3[a]", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "something_wicked3[a]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n17.getName().equals( "something_wicked3" ) ) { return false; } @@ -5159,7 +5151,7 @@ public final class Test { return false; } final PhylogenyNode n18 = PhylogenyNode - .createInstanceFromNhxString( ":0.5[91]", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) { return false; } @@ -6842,7 +6834,7 @@ public final class Test { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny s1 = factory.create( Test.PATH_TO_TEST_DATA + "rio_species.xml", new PhyloXmlParser() )[ 0 ]; final NHXParser p = new NHXParser(); - p.setTaxonomyExtraction( TAXONOMY_EXTRACTION.YES ); + p.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.YES ); final Phylogeny g1[] = factory.create( new File( Test.PATH_TO_TEST_DATA + "rio_Bcl-2_e1_20_mafft_05_40_fme.mlt" ), p ); for( final Phylogeny gt : g1 ) { -- 1.7.10.2