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
}, { 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
}
identifier = id + "";
}
+ boolean exception = false;
try {
String url_str = client.getUrl();
url_str = url_str.replaceFirst( PhylogeniesWebserviceClient.QUERY_PLACEHOLDER, identifier );
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 );
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(),
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 );
}
}
}
+ 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 {
}
_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();
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;
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<PhylogeniesWebserviceClient> createDefaultClients() {
final List<PhylogeniesWebserviceClient> clients = new ArrayList<PhylogeniesWebserviceClient>();
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,
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 ) );
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 ) ) {
}
}
- 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 );
}
}
}
}
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
}
}
private Map<String, String> _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;
@Override
public final Phylogeny[] parse() throws IOException {
- reset();
final List<Phylogeny> l = new ArrayList<Phylogeny>();
while ( hasNext() ) {
l.add( next() );
for( int i = 0; i < l.size(); ++i ) {
p[ i ] = l.get( i );
}
+ reset();
return 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 );
}
}
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 );
- // }
}
}
}
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();
}
private final void init() {
- setTaxonomyExtraction( TAXONOMY_EXTRACTION_DEFAULT );
+ setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
setReplaceUnderscores( REPLACE_UNDERSCORES_DEFAULT );
setGuessRootedness( GUESS_ROOTEDNESS_DEFAULT );
setIgnoreQuotes( IGNORE_QUOTES_DEFAULT );
.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
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;
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";
if ( phy != null ) {
return false;
}
- ////
+ //
p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
if ( !p.hasNext() ) {
return false;
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;
return false;
}
if ( phy.getNumberOfExternalNodes() != 3 ) {
+ System.out.println( phy.toString() );
return false;
}
if ( !phy.getName().equals( "" ) ) {