From 9a7395cfe0de3a3405ac9e6105d0577bc45d30ff Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Sat, 5 Apr 2014 01:38:38 +0000 Subject: [PATCH] inprogress --- .../org/forester/archaeopteryx/TreeColorSet.java | 4 +- .../org/forester/archaeopteryx/UrlTreeReader.java | 23 ++-- .../archaeopteryx/webservices/WebserviceUtil.java | 120 +++++--------------- .../webservices/WebservicesManager.java | 2 +- .../io/parsers/nexus/NexusPhylogeniesParser.java | 19 +--- .../src/org/forester/io/parsers/nhx/NHXParser.java | 89 +++++++-------- .../org/forester/io/parsers/util/ParserUtils.java | 1 - forester/java/src/org/forester/test/Test.java | 37 +++++- 8 files changed, 119 insertions(+), 176 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/TreeColorSet.java b/forester/java/src/org/forester/archaeopteryx/TreeColorSet.java index 201b460..fdbfc8d 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreeColorSet.java +++ b/forester/java/src/org/forester/archaeopteryx/TreeColorSet.java @@ -67,7 +67,7 @@ public final class TreeColorSet { private final Color[][] _color_schemes = { { new Color( 0, 0, 0 ), // background_color new Color( 0, 100, 100 ), // background_color_gradient_bottom new Color( 230, 230, 230 ), // sequence __ Default (same as Black) - new Color( 255, 220, 220 ), // taxonomy + new Color( 180, 180, 180 ), // taxonomy new Color( 56, 176, 255 ), // support new Color( 140, 140, 140 ), // branch_length_color new Color( 255, 255, 255 ), // branch_color @@ -86,7 +86,7 @@ public final class TreeColorSet { }, { new Color( 0, 0, 0 ), // background_color new Color( 0, 255, 255 ), // background_color_gradient_bottom new Color( 230, 230, 230 ), // sequence __ Black - new Color( 255, 220, 220 ), // taxonomy + new Color( 180, 180, 180 ), // taxonomy new Color( 56, 176, 255 ), // support new Color( 140, 140, 140 ), // branch_length_color new Color( 255, 255, 255 ), // branch_color diff --git a/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java b/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java index b08fa24..dad02df 100644 --- a/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java +++ b/forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java @@ -93,6 +93,7 @@ public class UrlTreeReader implements Runnable { } identifier = id + ""; } + boolean exception = false; try { String url_str = client.getUrl(); url_str = url_str.replaceFirst( PhylogeniesWebserviceClient.QUERY_PLACEHOLDER, identifier ); @@ -106,6 +107,11 @@ public class UrlTreeReader implements Runnable { parser = new NexusPhylogeniesParser(); ( ( NexusPhylogeniesParser ) parser ).setReplaceUnderscores( true ); break; + case TREEBASE: + parser = new NexusPhylogeniesParser(); + ( ( NexusPhylogeniesParser ) parser ).setReplaceUnderscores( true ); + ( ( NexusPhylogeniesParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); + break; case NH: parser = new NHXParser(); ( ( NHXParser ) parser ).setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); @@ -147,24 +153,28 @@ public class UrlTreeReader implements Runnable { trees = factory.create( url.openStream(), parser ); } catch ( final MalformedURLException e ) { + exception = true; JOptionPane.showMessageDialog( _main_frame, "Malformed URL: " + url + "\n" + e.getLocalizedMessage(), "Malformed URL", JOptionPane.ERROR_MESSAGE ); } catch ( final IOException e ) { + exception = true; JOptionPane.showMessageDialog( _main_frame, "Could not read from " + url + "\n" + e.getLocalizedMessage(), "Failed to read tree from " + client.getName() + " for " + identifier, JOptionPane.ERROR_MESSAGE ); } catch ( final NumberFormatException e ) { + exception = true; JOptionPane.showMessageDialog( _main_frame, "Could not read from " + url + "\n" + e.getLocalizedMessage(), "Failed to read tree from " + client.getName() + " for " + identifier, JOptionPane.ERROR_MESSAGE ); } catch ( final Exception e ) { + exception = true; e.printStackTrace(); JOptionPane.showMessageDialog( _main_frame, e.getLocalizedMessage(), @@ -186,11 +196,6 @@ public class UrlTreeReader implements Runnable { phylogeny.setRerootable( false ); phylogeny.setRooted( true ); } - if ( client.getName().equals( WebserviceUtil.PFAM_NAME ) ) { - phylogeny.setRerootable( false ); - phylogeny.setRooted( true ); - PhylogenyMethods.transferInternalNodeNamesToConfidence( phylogeny ); - } if ( client.getProcessingInstructions() != null ) { try { WebserviceUtil.processInstructions( client, phylogeny ); @@ -240,6 +245,10 @@ public class UrlTreeReader implements Runnable { } } } + else if ( !exception ) { + JOptionPane.showMessageDialog( null, ForesterUtil.wordWrap( "Failed to read in tree(s) from [" + url + + "]", 80 ), "Error", JOptionPane.ERROR_MESSAGE ); + } _main_frame.getContentPane().repaint(); if ( ( ( trees != null ) && ( trees.length > 0 ) ) && ( ( new Date().getTime() - start_time ) > 20000 ) ) { try { @@ -254,10 +263,6 @@ public class UrlTreeReader implements Runnable { } _main_frame.getContentPane().repaint(); } - else { - JOptionPane.showMessageDialog( null, ForesterUtil.wordWrap( "Failed to read in tree(s) from [" + url - + "]", 80 ), "Error", JOptionPane.ERROR_MESSAGE ); - } } _main_frame.activateSaveAllIfNeeded(); System.gc(); diff --git a/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java b/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java index d619022..58fb1e0 100644 --- a/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java @@ -29,7 +29,6 @@ import java.util.List; import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat; import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; -import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; @@ -42,22 +41,21 @@ import org.forester.util.ForesterUtil; public final class WebserviceUtil { - public static final String TAX_CODE_TO_SCI_NAME = "tax_code_to_sci_name"; - public static final String TREE_FAM_INST = "tree_fam"; - public static final String PFAM_INST = "pfam"; - public static final String TOL_WEBSERVER = "http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id=" - + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER; - public static final String TOL_NAME = "Tree of Life"; - public static final String TREE_BASE_NAME = "TreeBASE"; - public static final String TREE_FAM_NAME = "TreeFam"; - public static final String PFAM_NAME = "Pfam"; - public static final String PFAM_SERVER = "http://pfam.janelia.org"; + public static final String TREE_FAM_INST = "tree_fam"; + public static final String PFAM_INST = "pfam"; + public static final String TOL_WEBSERVER = "http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id=" + + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER; + public static final String TOL_NAME = "Tree of Life"; + public static final String TREE_BASE_NAME = "TreeBASE"; + public static final String TREE_FAM_NAME = "TreeFam"; + public static final String PFAM_NAME = "Pfam"; + public static final String PFAM_SERVER = "http://pfam.janelia.org"; public static List createDefaultClients() { final List clients = new ArrayList(); clients.add( new BasicPhylogeniesWebserviceClient( TOL_NAME, "Read Tree from Tree of Life...", - "Use ToL webservice to obtain a phylogeny", + "Use ToL webservice to obtain a evolutionary tree", "Please enter a Tree of Life node identifier\n(Examples: " + "19386 for Cephalopoda, 2461 for Cnidaria, 2466 for Deuterostomia)", WsPhylogenyFormat.TOL_XML_RESPONSE, @@ -68,48 +66,37 @@ public final class WebserviceUtil { null ) ); clients.add( new BasicPhylogeniesWebserviceClient( TREE_BASE_NAME, "Read Tree from TreeBASE...", - "Use TreeBASE to obtain a phylogeny", + "Use TreeBASE to obtain a evolutionary tree", "Please enter a TreeBASE tree identifier\n(Examples: 2654, 825, 4931, 2518, 2406, 4934)", - WsPhylogenyFormat.NEXUS, - PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME, + WsPhylogenyFormat.TREEBASE, + null, "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr" + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER + "?format=nexus", true, - "http://treebase.nescent.org", + "http://www.treebase.org", null ) ); clients.add( new BasicPhylogeniesWebserviceClient( PFAM_NAME, "Read Gene Tree from Pfam...", - "Use Pfam to obtain a (full) gene tree", + "Use Pfam to obtain gene trees for seed alignments", "Please enter a Pfam (PF) accession number\n(Examples: 01849 for NAC, 00452 for Bcl-2, 00046 for Homeobox)", WsPhylogenyFormat.PFAM, null, - PFAM_SERVER + "/family/tree/download?alnType=full&acc=PF" - + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER, + PFAM_SERVER + "/family/PF" + + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER + + "/tree/download", false, PFAM_SERVER, PFAM_INST ) ); clients.add( new BasicPhylogeniesWebserviceClient( TREE_FAM_NAME, - "Read Full Gene Tree from TreeFam...", - "Use TreeFam to obtain a (full) gene tree", - "Please enter a TreeFam (TF) accession number\n(Examples: 101004 for Cyclin D, 315938 for Hox, 105310 for Wnt)", - WsPhylogenyFormat.NHX, - null, - "http://www.treefam.org/cgi-bin/getdata.pl?ac=TF" - + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER - + "&f=full.nhx", - true, - "http://www.treefam.org", - TREE_FAM_INST ) ); - clients.add( new BasicPhylogeniesWebserviceClient( TREE_FAM_NAME, - "Read Clean Gene Tree from TreeFam...", - "Use TreeFam to obtain a (\"clean\") gene tree", + "Read Gene Tree from TreeFam...", + "Use TreeFam to obtain a gene tree", "Please enter a TreeFam (TF) accession number\n(Examples: 101004 for Cyclin D, 315938 for Hox, 105310 for Wnt)", WsPhylogenyFormat.NHX, null, - "http://www.treefam.org/cgi-bin/getdata.pl?ac=TF" + "http://www.treefam.org/family/TF" + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER - + "&f=clean.nhx", + + "/tree/newick", true, "http://www.treefam.org", TREE_FAM_INST ) ); @@ -138,13 +125,8 @@ public final class WebserviceUtil { public static void processInstructions( final PhylogeniesWebserviceClient client, final Phylogeny phylogeny ) throws PhyloXmlDataFormatException { - if ( client.getProcessingInstructions().equals( WebserviceUtil.TAX_CODE_TO_SCI_NAME ) ) { - WebserviceUtil.transferTaxonomyCodeToScientificName( phylogeny ); - } - else if ( client.getProcessingInstructions().equals( WebserviceUtil.TREE_FAM_INST ) ) { - WebserviceUtil.transferInternalTaxonomyCodeToScientificName( phylogeny ); - WebserviceUtil.transferExternalScientificNameToTaxonomyCode( phylogeny ); - WebserviceUtil.transferSequenceNameToSequenceAccession( phylogeny, "ensembl" ); + if ( client.getProcessingInstructions().equals( WebserviceUtil.TREE_FAM_INST ) ) { + WebserviceUtil.removeEventsInExternalNodes( phylogeny ); WebserviceUtil.setTaxonomyIdentifierType( phylogeny, "ncbi" ); } else if ( client.getProcessingInstructions().equals( WebserviceUtil.PFAM_INST ) ) { @@ -164,59 +146,11 @@ public final class WebserviceUtil { } } - static void transferExternalScientificNameToTaxonomyCode( final Phylogeny phy ) throws PhyloXmlDataFormatException { - final PhylogenyNodeIterator it = phy.iteratorPostorder(); + static void removeEventsInExternalNodes( final Phylogeny phy ) { + final PhylogenyNodeIterator it = phy.iteratorExternalForward(); while ( it.hasNext() ) { final PhylogenyNode n = it.next(); - if ( n.isExternal() && n.getNodeData().isHasTaxonomy() ) { - final String name = n.getNodeData().getTaxonomy().getScientificName(); - if ( !ForesterUtil.isEmpty( name ) && PhyloXmlUtil.TAXOMONY_CODE_PATTERN.matcher( name ).matches() ) { - n.getNodeData().getTaxonomy().setScientificName( "" ); - n.getNodeData().getTaxonomy().setTaxonomyCode( name ); - } - } - } - } - - static void transferInternalTaxonomyCodeToScientificName( final Phylogeny phy ) throws PhyloXmlDataFormatException { - final PhylogenyNodeIterator it = phy.iteratorPostorder(); - while ( it.hasNext() ) { - final PhylogenyNode n = it.next(); - if ( !n.isExternal() && n.getNodeData().isHasTaxonomy() ) { - final String name = n.getNodeData().getTaxonomy().getTaxonomyCode(); - if ( !ForesterUtil.isEmpty( name ) ) { - n.getNodeData().getTaxonomy().setScientificName( name ); - n.getNodeData().getTaxonomy().setTaxonomyCode( "" ); - } - } - } - } - - static void transferSequenceNameToSequenceAccession( final Phylogeny phy, final String source ) { - final PhylogenyNodeIterator it = phy.iteratorPostorder(); - while ( it.hasNext() ) { - final PhylogenyNode n = it.next(); - if ( n.getNodeData().isHasSequence() ) { - final String name = n.getNodeData().getSequence().getName(); - if ( !ForesterUtil.isEmpty( name ) ) { - n.getNodeData().getSequence().setName( "" ); - n.getNodeData().getSequence().setAccession( new Accession( name, source ) ); - } - } - } - } - - static void transferTaxonomyCodeToScientificName( final Phylogeny phy ) throws PhyloXmlDataFormatException { - final PhylogenyNodeIterator it = phy.iteratorPostorder(); - while ( it.hasNext() ) { - final PhylogenyNode n = it.next(); - if ( n.getNodeData().isHasTaxonomy() ) { - final String name = n.getNodeData().getTaxonomy().getTaxonomyCode(); - if ( !ForesterUtil.isEmpty( name ) ) { - n.getNodeData().getTaxonomy().setScientificName( name ); - n.getNodeData().getTaxonomy().setTaxonomyCode( "" ); - } - } + n.getNodeData().setEvent( null ); } } } diff --git a/forester/java/src/org/forester/archaeopteryx/webservices/WebservicesManager.java b/forester/java/src/org/forester/archaeopteryx/webservices/WebservicesManager.java index 95e03c2..e60528d 100644 --- a/forester/java/src/org/forester/archaeopteryx/webservices/WebservicesManager.java +++ b/forester/java/src/org/forester/archaeopteryx/webservices/WebservicesManager.java @@ -58,6 +58,6 @@ public final class WebservicesManager { } public enum WsPhylogenyFormat { - NH, NHX, NEXUS, TOL_XML_RESPONSE, PHYLOXML, NH_EXTRACT_TAXONOMY, PFAM + NH, NHX, NEXUS, TOL_XML_RESPONSE, PHYLOXML, NH_EXTRACT_TAXONOMY, PFAM, TREEBASE } } 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 0f21364..46f6548 100644 --- a/forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java +++ b/forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java @@ -65,7 +65,7 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P private Map _translate_map; private boolean _replace_underscores = NHXParser.REPLACE_UNDERSCORES_DEFAULT; private boolean _ignore_quotes_in_nh_data = Constants.NH_PARSING_IGNORE_QUOTES_DEFAULT; - private TAXONOMY_EXTRACTION _taxonomy_extraction = NHXParser.TAXONOMY_EXTRACTION_DEFAULT; + private TAXONOMY_EXTRACTION _taxonomy_extraction = TAXONOMY_EXTRACTION.NO; private Phylogeny _next; private BufferedReader _br; private boolean _in_trees_block; @@ -92,7 +92,6 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P @Override public final Phylogeny[] parse() throws IOException { - reset(); final List l = new ArrayList(); while ( hasNext() ) { l.add( next() ); @@ -101,6 +100,7 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P for( int i = 0; i < l.size(); ++i ) { p[ i ] = l.get( i ); } + reset(); return p; } @@ -149,16 +149,9 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P final boolean is_rooted ) throws IOException { _next = null; final NHXParser pars = new NHXParser(); - // if ( ( _taxlabels.size() < 1 ) && ( _translate_map.size() < 1 ) ) { pars.setTaxonomyExtraction( _taxonomy_extraction ); pars.setReplaceUnderscores( _replace_underscores ); pars.setIgnoreQuotes( _ignore_quotes_in_nh_data ); - //} - //else { - // pars.setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO ); - // pars.setReplaceUnderscores( false ); - // pars.setIgnoreQuotes( false ); - //} if ( rooted_info_present ) { pars.setGuessRootedness( false ); } @@ -192,14 +185,6 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P } if ( !_replace_underscores && ( ( _taxonomy_extraction != TAXONOMY_EXTRACTION.NO ) ) ) { ParserUtils.extractTaxonomyDataFromNodeName( node, _taxonomy_extraction ); - // final String tax = ParserUtils.extractTaxonomyCodeFromNodeName( node.getName(), - // getTaxonomyExtraction() ); - // if ( !ForesterUtil.isEmpty( tax ) ) { - // if ( !node.getNodeData().isHasTaxonomy() ) { - // node.getNodeData().setTaxonomy( new Taxonomy() ); - // } - // node.getNodeData().getTaxonomy().setTaxonomyCode( tax ); - // } } } } 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 55f0285..f54602f 100644 --- a/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java +++ b/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java @@ -56,52 +56,47 @@ import org.forester.util.ForesterUtil; public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParser { - public final static Pattern MB_BL_PATTERN = Pattern - .compile( "length_median=([^,]+)" ); - 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 NUMBERS_ONLY_PATTERN = Pattern - .compile( "^[0-9\\.]+$" ); - final static public boolean REPLACE_UNDERSCORES_DEFAULT = false; - public static final TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT = TAXONOMY_EXTRACTION.NO; - private static final boolean ALLOW_ERRORS_IN_DISTANCE_TO_PARENT_DEFAULT = false; - final static private byte BUFFERED_READER = 3; - final static private byte CHAR_ARRAY = 2; - final static private boolean GUESS_IF_SUPPORT_VALUES = true; - final static private boolean GUESS_ROOTEDNESS_DEFAULT = true; - final static private boolean IGNORE_QUOTES_DEFAULT = false; - final static private byte STRING = 0; - final static private byte STRING_BUFFER = 1; - final static private byte STRING_BUILDER = 4; - private boolean _allow_errors_in_distance_to_parent; - private int _clade_level; - private StringBuilder _current_anotation; - private PhylogenyNode _current_node; - private Phylogeny _current_phylogeny; - private boolean _guess_rootedness; - private int _i; - private boolean _ignore_quotes; - private boolean _in_comment = false; - private boolean _in_double_quote = false; - private boolean _in_open_bracket = false; - private boolean _in_single_quote = false; - private byte _input_type; - private BufferedReader _my_source_br = null; - private char[] _my_source_charary = null; - private StringBuffer _my_source_sbuff = null; - private StringBuilder _my_source_sbuil = null; - private String _my_source_str = null; - private Phylogeny _next; - private Object _nhx_source; - private boolean _replace_underscores; - private boolean _saw_closing_paren; - private boolean _saw_colon = false; - private boolean _saw_open_bracket = false; - private Object _source; - private int _source_length; - private TAXONOMY_EXTRACTION _taxonomy_extraction; + public final static Pattern MB_BL_PATTERN = Pattern.compile( "length_median=([^,]+)" ); + 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 NUMBERS_ONLY_PATTERN = Pattern.compile( "^[0-9\\.]+$" ); + final static public boolean REPLACE_UNDERSCORES_DEFAULT = false; + private static final boolean ALLOW_ERRORS_IN_DISTANCE_TO_PARENT_DEFAULT = false; + final static private byte BUFFERED_READER = 3; + final static private byte CHAR_ARRAY = 2; + final static private boolean GUESS_IF_SUPPORT_VALUES = true; + final static private boolean GUESS_ROOTEDNESS_DEFAULT = true; + final static private boolean IGNORE_QUOTES_DEFAULT = false; + final static private byte STRING = 0; + final static private byte STRING_BUFFER = 1; + final static private byte STRING_BUILDER = 4; + private boolean _allow_errors_in_distance_to_parent; + private int _clade_level; + private StringBuilder _current_anotation; + private PhylogenyNode _current_node; + private Phylogeny _current_phylogeny; + private boolean _guess_rootedness; + private int _i; + private boolean _ignore_quotes; + private boolean _in_comment = false; + private boolean _in_double_quote = false; + private boolean _in_open_bracket = false; + private boolean _in_single_quote = false; + private byte _input_type; + private BufferedReader _my_source_br = null; + private char[] _my_source_charary = null; + private StringBuffer _my_source_sbuff = null; + private StringBuilder _my_source_sbuil = null; + private String _my_source_str = null; + private Phylogeny _next; + private Object _nhx_source; + private boolean _replace_underscores; + private boolean _saw_closing_paren; + private boolean _saw_colon = false; + private boolean _saw_open_bracket = false; + private Object _source; + private int _source_length; + private TAXONOMY_EXTRACTION _taxonomy_extraction; public NHXParser() { init(); @@ -333,7 +328,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse } private final void init() { - setTaxonomyExtraction( TAXONOMY_EXTRACTION_DEFAULT ); + setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO ); setReplaceUnderscores( REPLACE_UNDERSCORES_DEFAULT ); setGuessRootedness( GUESS_ROOTEDNESS_DEFAULT ); setIgnoreQuotes( IGNORE_QUOTES_DEFAULT ); 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 76f2a18..1b0655c 100644 --- a/forester/java/src/org/forester/io/parsers/util/ParserUtils.java +++ b/forester/java/src/org/forester/io/parsers/util/ParserUtils.java @@ -66,7 +66,6 @@ public final class ParserUtils { .compile( "\\b([A-Z][a-z]+_[a-z]{2,}(?:_[a-z][a-z0-9_]+)?)(?:\\b|_)" ); final private static Pattern TAXOMONY_CODE_PATTERN_PFS = Pattern.compile( "(?:\\b|_)[A-Z0-9]{4,}_(" + TAX_CODE + ")/\\d+-\\d+\\b" ); - // final private static Pattern TAXOMONY_UNIPROT_ID_PATTERN_A = Pattern.compile( "(?:\\b|(?:[A-Z]_))(\\d{1,7})\\b" ); final private static Pattern TAXOMONY_UNIPROT_ID_PATTERN_PFR = Pattern .compile( "(?:\\b|_)[A-Z0-9]{1,}_(\\d{1,7})\\b" ); final private static Pattern TAXOMONY_UNIPROT_ID_PATTERN_PFS = Pattern diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 4023539..5103e7d 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -967,6 +967,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "TreeBase parsing from URL: " ); + if ( Test.testTreeBaseReading() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.println(); final Runtime rt = java.lang.Runtime.getRuntime(); final long free_memory = rt.freeMemory() / 1000000; @@ -1100,6 +1109,24 @@ public final class Test { return true; } + public static final boolean testTreeBaseReading() { + try { + final String s = "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr825?format=nexus"; + final URL u = new URL( s ); + final NexusPhylogeniesParser parser = new NexusPhylogeniesParser(); + parser.setReplaceUnderscores( true ); + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys = factory.create( u.openStream(), parser ); + if ( ( phys == null ) || ( phys.length != 1 ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + } + return true; + } + public static final boolean testNHXparsingFromURL() { try { final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh"; @@ -6727,7 +6754,7 @@ public final class Test { if ( phy != null ) { return false; } - //// + // p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" ); if ( !p.hasNext() ) { return false; @@ -6774,15 +6801,12 @@ public final class Test { if ( phy != null ) { return false; } - //// + // p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" ); - // if ( phylogenies.length != 18 ) { - // return false; - // } - //0 if ( !p.hasNext() ) { return false; } + //0 phy = p.next(); if ( phy == null ) { return false; @@ -6816,6 +6840,7 @@ public final class Test { return false; } if ( phy.getNumberOfExternalNodes() != 3 ) { + System.out.println( phy.toString() ); return false; } if ( !phy.getName().equals( "" ) ) { -- 1.7.10.2