final static boolean __ALLOW_PHYLOGENETIC_INFERENCE = true;
public final static String PRG_NAME = "Archaeopteryx";
- final static String VERSION = "0.9918 beta";
- final static String PRG_DATE = "161019";
+ final static String VERSION = "0.9919 beta";
+ final static String PRG_DATE = "161021";
final static String DEFAULT_CONFIGURATION_FILE_NAME = "_aptx_configuration_file";
final static String[] DEFAULT_FONT_CHOICES = {
"Arial Unicode MS", "Dialog", "SansSerif", "Sans", "Arial", "Helvetica" };
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;
-import org.forester.archaeopteryx.ControlPanel.TreeDisplayType;
+import org.forester.archaeopteryx.Options.PHYLOGENY_DISPLAY_TYPE;
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
import org.forester.io.parsers.nhx.NHXParser;
final boolean has_bl = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( t );
if ( !has_bl ) {
- cp.setTreeDisplayType( TreeDisplayType.CLADOGRAM );
+ cp.setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM );
cp.setDrawPhylogramEnabled( false );
}
else {
final boolean has_all_bl = AptxUtil.isHasNoBranchLengthSmallerThanZero( t );
if (has_all_bl) {
- cp.setTreeDisplayType( TreeDisplayType.UNALIGNED_PHYLOGRAM );
+ cp.setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM );
}
if ( cp.getDisplayAsUnalignedPhylogramRb() != null ) {
if ( ( t != null ) && !t.isEmpty() ) {
final boolean has_bl = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( t );
if ( !has_bl ) {
- atv_control.setTreeDisplayType( TreeDisplayType.CLADOGRAM );
+ atv_control.setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM );
atv_control.setDrawPhylogramEnabled( false );
}
if ( t.getFirstExternalNode().getBranchData().getBranchColor() != null
if ( has_bl ) {
final boolean has_all_bl = AptxUtil.isHasNoBranchLengthSmallerThanZero( t );
if (has_all_bl) {
- atv_control.setTreeDisplayType( TreeDisplayType.UNALIGNED_PHYLOGRAM );
+ atv_control.setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM );
}
atv_control.setDrawPhylogramEnabled( true );
}
else {
- atv_control.setTreeDisplayType( TreeDisplayType.CLADOGRAM );
+ atv_control.setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM );
}
}
}
final class ControlPanel extends JPanel implements ActionListener {
- enum TreeDisplayType {
- CLADOGRAM,
- ALIGNED_PHYLOGRAM,
- UNALIGNED_PHYLOGRAM
- };
-
enum NodeClickAction {
ADD_NEW_NODE,
BLAST,
private JTextField _domain_structure_evalue_thr_tf;
private JTextField _depth_collapse_depth_tf;
private JTextField _rank_collapse_depth_tf;
- private List<TreeDisplayType> _tree_display_types;
+ private List<Options.PHYLOGENY_DISPLAY_TYPE> _tree_display_types;
private JCheckBox _dynamically_hide_data;
private int _edit_node_data_item;
private int _get_ext_desc_data;
}
else if ( ( tp != null ) && ( tp.getPhylogeny() != null ) ) {
if ( e.getSource() == getDisplayAsUnalignedPhylogramRb() ) {
- setTreeDisplayType( TreeDisplayType.UNALIGNED_PHYLOGRAM );
+ setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM );
showWhole();
}
if ( e.getSource() == getDisplayAsAlignedPhylogramRb() ) {
- setTreeDisplayType( TreeDisplayType.ALIGNED_PHYLOGRAM );
+ setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM );
showWhole();
}
if ( e.getSource() == getDisplayAsCladogramRb() ) {
- setTreeDisplayType( TreeDisplayType.CLADOGRAM );
+ setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM );
showWhole();
}
// Zoom buttons
}// addSequenceRelationBlock
/* GUILHEM_END */
- private List<TreeDisplayType> getTreeDisplayTypes() {
+ private List<Options.PHYLOGENY_DISPLAY_TYPE> getTreeDisplayTypes() {
return _tree_display_types;
}
}
private void init() {
- _tree_display_types = new ArrayList<TreeDisplayType>();
+ _tree_display_types = new ArrayList<Options.PHYLOGENY_DISPLAY_TYPE>();
setSpeciesColors( new HashMap<String, Color>() );
setSequenceColors( new HashMap<String, Color>() );
setAnnotationColors( new HashMap<String, Color>() );
}
- private TreeDisplayType getTreeDisplayType( final int index ) {
+ private Options.PHYLOGENY_DISPLAY_TYPE getTreeDisplayType( final int index ) {
return getTreeDisplayTypes().get( index );
}
}
}
- private void setTreeDisplayType( final int index, final TreeDisplayType t ) {
+ private void setTreeDisplayType( final int index, final Options.PHYLOGENY_DISPLAY_TYPE t ) {
getTreeDisplayTypes().set( index, t );
}
_zoom_in_y = new TypomaticJButton( "Y+" );
_zoom_out_y = new TypomaticJButton( "Y-" );
_show_whole = new JButton( "F" );
- _show_whole.setToolTipText( "fit and center to display [Alt+C or Home]" );
+ _show_whole.setToolTipText( "fit and center tree display [Alt+C, Home, or Esc]" );
_zoom_in_x.setToolTipText( "zoom in horizontally [Alt+Right or Shift+Alt+mousewheel]" );
_zoom_in_y.setToolTipText( "zoom in vertically [Alt+Up or Shift+mousewheel]" );
_zoom_out_x.setToolTipText( "zoom out horizontally [Alt+Left or Shift+Alt+mousewheel]" );
}
boolean isDrawPhylogram() {
- final TreeDisplayType t = getTreeDisplayType( getMainPanel().getCurrentTabIndex() );
- return ((t == TreeDisplayType.ALIGNED_PHYLOGRAM) ||( t == TreeDisplayType.UNALIGNED_PHYLOGRAM));
+ final Options.PHYLOGENY_DISPLAY_TYPE t = getTreeDisplayType( getMainPanel().getCurrentTabIndex() );
+ return ((t == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM) ||( t == Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM));
}
boolean isDynamicallyHideData() {
void phylogenyAdded( final Configuration configuration ) {
if (configuration.isDrawAsPhylogram()) {
- getTreeDisplayTypes().add( TreeDisplayType.UNALIGNED_PHYLOGRAM);
+ getTreeDisplayTypes().add( Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM);
}
else {
- getTreeDisplayTypes().add( TreeDisplayType.CLADOGRAM);
+ getTreeDisplayTypes().add( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM);
}
}
_color_branches = color_branches;
}
- void setTreeDisplayType( final TreeDisplayType t ) {
+ void setTreeDisplayType( final Options.PHYLOGENY_DISPLAY_TYPE t ) {
switch (t) {
case UNALIGNED_PHYLOGRAM:
getDisplayAsUnalignedPhylogramRb().setSelected( true );
}
void setupTreeDisplayTypeOptions() {
- _display_as_unaligned_phylogram_rb = new JRadioButton( "PH" );
- _display_as_aligned_phylogram_rb = new JRadioButton( "aPH" );
- _display_as_cladogram_rb = new JRadioButton( "CL" );
+ _display_as_unaligned_phylogram_rb = new JRadioButton( "P" );
+ _display_as_aligned_phylogram_rb = new JRadioButton( "A" );
+ _display_as_cladogram_rb = new JRadioButton( "C" );
_display_as_buttongroup = new ButtonGroup();
_display_as_buttongroup.add( _display_as_unaligned_phylogram_rb );
_display_as_buttongroup.add( _display_as_aligned_phylogram_rb );
}
else {
setDrawPhylogramEnabled( false );
- setTreeDisplayType( TreeDisplayType.CLADOGRAM );
+ setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM );
}
getMainPanel().getMainFrame()
}
private final boolean isDrawPhylogram( int currentTabIndex ) {
- TreeDisplayType t = getTreeDisplayType( currentTabIndex );
- return ((t==TreeDisplayType.ALIGNED_PHYLOGRAM)|(t==TreeDisplayType.UNALIGNED_PHYLOGRAM));
+ Options.PHYLOGENY_DISPLAY_TYPE t = getTreeDisplayType( currentTabIndex );
+ return ((t==Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM)|(t==Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM));
}
return _width_branches;
}
- public TreeDisplayType getTreeDisplayType() {
+ public Options.PHYLOGENY_DISPLAY_TYPE getTreeDisplayType() {
if (_display_as_unaligned_phylogram_rb.isSelected() ) {
- return TreeDisplayType.UNALIGNED_PHYLOGRAM;
+ return Options.PHYLOGENY_DISPLAY_TYPE.UNALIGNED_PHYLOGRAM;
}
else if (_display_as_aligned_phylogram_rb.isSelected() ) {
- return TreeDisplayType.ALIGNED_PHYLOGRAM;
+ return Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM;
}
- return TreeDisplayType.CLADOGRAM;
+ return Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM;
}
}
l.add( d );
}
if ( !l.isEmpty() ) {
- if ( node.getNodeData().getProperties() != null ) {
- node.getNodeData().getProperties()
- .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
- }
+
node.getNodeData().setVector( l );
}
}
import org.forester.phylogeny.data.PhylogenyData;
import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Point;
-import org.forester.phylogeny.data.PropertiesMap;
+import org.forester.phylogeny.data.PropertiesList;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Reference;
import org.forester.phylogeny.data.Sequence;
}
private static void addProperties( final DefaultMutableTreeNode top,
- final PropertiesMap properties,
+ final PropertiesList properties,
final String string ) {
- final SortedMap<String, Property> properties_map = properties.getProperties();
+ final List<Property> properties_map = properties.getProperties();
final DefaultMutableTreeNode category = new DefaultMutableTreeNode( "Properties " );
top.add( category );
- for( final String key : properties_map.keySet() ) {
- final Property prop = properties_map.get( key );
+ for( final Property prop : properties_map ) {
+
category.add( new DefaultMutableTreeNode( prop.getRef() + "=" + prop.getValue() + " " + prop.getUnit()
+ " [" + prop.getAppliesTo().toString() + "]" ) );
}
public static enum PHYLOGENY_GRAPHICS_TYPE {
CIRCULAR, CONVEX, CURVED, EURO_STYLE, RECTANGULAR, ROUNDED, TRIANGULAR, UNROOTED;
}
+
+ static enum PHYLOGENY_DISPLAY_TYPE {
+ CLADOGRAM,
+ ALIGNED_PHYLOGRAM,
+ UNALIGNED_PHYLOGRAM
+ }
static enum OVERVIEW_PLACEMENT_TYPE {
LOWER_LEFT( "lower left" ),
return toString().replaceAll( " ", "_" );
}
}
+
static final double MIN_CONFIDENCE_DEFAULT = 0.0;
private boolean _abbreviate_scientific_names;
private boolean _allow_errors_in_distance_to_parent;
import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
-import org.forester.archaeopteryx.ControlPanel.TreeDisplayType;
import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
+import org.forester.archaeopteryx.Options.PHYLOGENY_DISPLAY_TYPE;
import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
import org.forester.archaeopteryx.phylogeny.data.RenderableMsaSequence;
import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
import org.forester.phylogeny.data.NodeVisualData.NodeFill;
import org.forester.phylogeny.data.NodeVisualData.NodeShape;
import org.forester.phylogeny.data.PhylogenyDataUtil;
-import org.forester.phylogeny.data.PropertiesMap;
+import org.forester.phylogeny.data.PropertiesList;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.ProteinDomain;
import org.forester.phylogeny.data.Sequence;
init();
// if ( !_phylogeny.isEmpty() ) {
_phylogeny.recalculateNumberOfExternalDescendants( true );
- checkForVectorProperties( _phylogeny );
+
// }
setBackground( getTreeColorSet().getBackgroundColor() );
final MouseListener mouse_listener = new MouseListener( this );
decreaseOvSize();
}
}
- if ( e.getKeyCode() == KeyEvent.VK_HOME ) {
+ if ( e.getKeyCode() == KeyEvent.VK_HOME
+ || e.getKeyCode() == KeyEvent.VK_ESCAPE ) {
getControlPanel().showWhole();
}
else if ( e.getKeyCode() == KeyEvent.VK_PAGE_UP ) {
down_shift_factor = 1;
}
float pos_x;
- if ( getControlPanel().getTreeDisplayType() == TreeDisplayType.ALIGNED_PHYLOGRAM
+ if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
&& ( node.isExternal() || node.isCollapse() ) ) {
pos_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
+ ( getOptions().getDefaultNodeShapeSize() / 2 ) + x + ( 2 * TreePanel.MOVE ) + getXdistance()
else {
pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
}
- if ( getControlPanel().getTreeDisplayType() == TreeDisplayType.ALIGNED_PHYLOGRAM
+ if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
&& ( node.isExternal() || node.isCollapse() ) ) {
drawConnection( node.getXcoord(), pos_x - x, node.getYcoord(), 5, 20, g, to_pdf );
if ( node.isCollapse() ) {
if ( !node.isExternal() && !node.isCollapse() ) {
boolean first_child = true;
float y2 = 0.0f;
- final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
+ //final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
final PhylogenyNode child_node = node.getChildNode( i );
final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
- if ( getControlPanel().getTreeDisplayType() == TreeDisplayType.ALIGNED_PHYLOGRAM && node.isExternal() ) {
+ if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM && node.isExternal() ) {
start_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
+ ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift + ( 2 * TreePanel.MOVE ) + getXdistance()
+ 3 );
}
private final StringBuffer propertiesToString( final PhylogenyNode node ) {
- final PropertiesMap properties = node.getNodeData().getProperties();
- final StringBuffer sb = new StringBuffer();
- boolean first = true;
- for( final String ref : properties.getPropertyRefs() ) {
- if ( first ) {
- first = false;
- }
- else {
- sb.append( " " );
- }
- final Property p = properties.getProperty( ref );
- sb.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
- sb.append( "=" );
- sb.append( p.getValue() );
- if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
- sb.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
- }
- }
- return sb;
+
+ return node.getNodeData().getProperties().asText();
}
private void setColor( final Graphics2D g,
}
}
if ( node.getNodeData().isHasProperties() ) {
- final PropertiesMap properties = node.getNodeData().getProperties();
- for( final String ref : properties.getPropertyRefs() ) {
+ if ( _popup_buffer.length() > 0 ) {
_popup_buffer.append( "\n" );
- final Property p = properties.getProperty( ref );
- _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
- _popup_buffer.append( "=" );
- _popup_buffer.append( p.getValue() );
- if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
- _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
- }
}
+ _popup_buffer.append(node.getNodeData().getProperties().asText());
+
}
if ( _popup_buffer.length() > 0 ) {
if ( !getConfiguration().isUseNativeUI() ) {
}
}
- void checkForVectorProperties( final Phylogeny phy ) {
- final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
- for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
- final PhylogenyNode node = iter.next();
- if ( node.getNodeData().getProperties() != null ) {
- final PropertiesMap pm = node.getNodeData().getProperties();
- final double[] vector = new double[ pm.getProperties().size() ];
- int counter = 0;
- for( final String ref : pm.getProperties().keySet() ) {
- if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
- final Property p = pm.getProperty( ref );
- final String value_str = p.getValue();
- final String index_str = ref.substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(),
- ref.length() );
- double d = -100;
- try {
- d = Double.parseDouble( value_str );
- }
- catch ( final NumberFormatException e ) {
- JOptionPane.showMessageDialog( this,
- "Could not parse \"" + value_str + "\" into a decimal value",
- "Problem with Vector Data",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- int i = -1;
- try {
- i = Integer.parseInt( index_str );
- }
- catch ( final NumberFormatException e ) {
- JOptionPane.showMessageDialog( this,
- "Could not parse \"" + index_str
- + "\" into index for vector data",
- "Problem with Vector Data",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( i < 0 ) {
- JOptionPane.showMessageDialog( this,
- "Attempt to use negative index for vector data",
- "Problem with Vector Data",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- vector[ i ] = d;
- ++counter;
- stats.addValue( d );
- }
- }
- final List<Double> vector_l = new ArrayList<Double>( counter );
- for( int i = 0; i < counter; ++i ) {
- vector_l.add( vector[ i ] );
- }
- node.getNodeData().setVector( vector_l );
- }
- }
- if ( stats.getN() > 0 ) {
- _statistics_for_vector_data = stats;
- }
- }
+
void clearCurrentExternalNodesDataBuffer() {
setCurrentExternalNodesDataBuffer( new StringBuilder() );
import org.forester.phylogeny.data.Identifier;
import org.forester.phylogeny.data.NodeVisualData;
import org.forester.phylogeny.data.PhylogenyDataUtil;
-import org.forester.phylogeny.data.PropertiesMap;
+import org.forester.phylogeny.data.PropertiesList;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Property.AppliesTo;
import org.forester.phylogeny.data.Reference;
}
else {
if ( !node.getNodeData().isHasProperties() ) {
- node.getNodeData().setProperties( new PropertiesMap() );
+ node.getNodeData().setProperties( new PropertiesList() );
}
node.getNodeData().getProperties().addProperty( prop );
}
import org.forester.phylogeny.data.Annotation;
import org.forester.phylogeny.data.Confidence;
import org.forester.phylogeny.data.PhylogenyData;
-import org.forester.phylogeny.data.PropertiesMap;
+import org.forester.phylogeny.data.PropertiesList;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Uri;
}
else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.PROPERTY ) ) {
if ( annotation.getProperties() == null ) {
- annotation.setProperties( new PropertiesMap() );
+ annotation.setProperties( new PropertiesList() );
}
annotation.getProperties()
.addProperty( ( Property ) PropertyParser.getInstance().parse( child_element ) );
private Confidence _confidence;
private String _desc;
private String _evidence;
- private PropertiesMap _properties;
+ private PropertiesList _properties;
private final String _ref_source;
private final String _ref_value;
private String _source;
ann.setEvidence( getEvidence() );
ann.setSource( new String( getSource() ) );
if ( getProperties() != null ) {
- ann.setProperties( ( PropertiesMap ) getProperties().copy() );
+ ann.setProperties( ( PropertiesList ) getProperties().copy() );
}
else {
ann.setProperties( null );
return _evidence;
}
- public PropertiesMap getProperties() {
+ public PropertiesList getProperties() {
return _properties;
}
_evidence = evidence;
}
- public void setProperties( final PropertiesMap property ) {
+ public void setProperties( final PropertiesList property ) {
_properties = property;
}
private List<Distribution> _distributions;
private Date _date;
private BinaryCharacters _binary_characters;
- private PropertiesMap _properties;
+ private PropertiesList _properties;
private List<Reference> _references;
private List<Double> _vector;
private NodeVisualData _node_visual_data;
new_data.setDate( ( Date ) getDate().copy() );
}
if ( isHasProperties() ) {
- new_data.setProperties( ( PropertiesMap ) getProperties().copy() );
+ new_data.setProperties( ( PropertiesList ) getProperties().copy() );
}
return new_data;
}
return _event;
}
- public PropertiesMap getProperties() {
+ public PropertiesList getProperties() {
return _properties;
}
_event = event;
}
- public void setProperties( final PropertiesMap custom_data ) {
+ public void setProperties( final PropertiesList custom_data ) {
_properties = custom_data;
}
--- /dev/null
+// $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: https://sites.google.com/site/cmzmasek/home/software/forester
+
+package org.forester.phylogeny.data;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.forester.util.ForesterUtil;
+
+public class PropertiesList implements PhylogenyData {
+
+ private final List<Property> _properties;
+ private final Comparator<Property> comp = new Comparator<Property>() {
+
+ @Override
+ public int compare( final Property p1, final Property p2 ) {
+ return p2.getRef().compareTo( p1.getRef() );
+ }
+ };
+
+ public PropertiesList() {
+ _properties = new ArrayList<Property>();
+ }
+
+ public int size() {
+ return _properties.size();
+ }
+
+ public void addProperty( final Property property ) throws IllegalArgumentException {
+ _properties.add( property );
+ Collections.sort( _properties, comp );
+ }
+
+ @Override
+ public StringBuffer asSimpleText() {
+ final StringBuffer sb = new StringBuffer();
+ boolean first = true;
+ for( final Property p : getProperties() ) {
+ if ( first ) {
+ first = false;
+ }
+ else {
+ sb.append( "\n" );
+ }
+ sb.append( p.asText() );
+ }
+ return sb;
+ }
+
+ @Override
+ public StringBuffer asText() {
+ return asSimpleText();
+ }
+
+ @Override
+ public PhylogenyData copy() {
+ final PropertiesList new_one = new PropertiesList();
+ for( final Property r : getProperties() ) {
+ new_one.addProperty( r );
+ }
+ return new_one;
+ }
+
+ public List<Property> getProperties() {
+ return _properties;
+ }
+
+ public List<Property> getPropertiesWithGivenReferencePrefix( final String ref_prefix )
+ throws IllegalArgumentException {
+ if ( ForesterUtil.isEmpty( ref_prefix ) ) {
+ throw new IllegalArgumentException( "reference prefix is null or empty" );
+ }
+ final String my_ref_prefix = new String( ref_prefix.trim() );
+ final List<Property> props = new ArrayList<Property>();
+ for( final Property p : getProperties() ) {
+ if ( p.getRef().startsWith( my_ref_prefix ) ) {
+ props.add( p );
+ }
+ }
+ return props;
+ }
+
+ public List<Property> getProperties( final String ref ) throws IllegalArgumentException {
+ final List<Property> props = new ArrayList<Property>();
+ for( final Property p : getProperties() ) {
+ if ( p.getRef().equals( ref ) ) {
+ props.add( p );
+ }
+ }
+ return props;
+ }
+
+ @Override
+ public boolean isEqual( final PhylogenyData data ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public StringBuffer toNHX() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
+ if ( getProperties() != null ) {
+ for( final Property p : getProperties() ) {
+ p.toPhyloXML( writer, level, indentation );
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return asSimpleText().toString();
+ }
+}
+++ /dev/null
-// $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: https://sites.google.com/site/cmzmasek/home/software/forester
-
-package org.forester.phylogeny.data;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.forester.util.ForesterUtil;
-
-public class PropertiesMap implements PhylogenyData {
-
- private final SortedMap<String, Property> _properties;
-
- public PropertiesMap() {
- _properties = new TreeMap<String, Property>();
- }
-
- public int size() {
- return _properties.size();
- }
-
- public void addProperty( final Property property ) throws IllegalArgumentException {
- if ( getProperties().containsKey( property.getRef() ) ) {
- throw new IllegalArgumentException( "ref [" + property.getRef() + "] is already present" );
- }
- getProperties().put( property.getRef(), property );
- }
-
- @Override
- public StringBuffer asSimpleText() {
- final StringBuffer sb = new StringBuffer();
- boolean first = true;
- for( final String ref : getPropertyRefs() ) {
- if ( first ) {
- first = false;
- }
- else {
- sb.append( " " );
- }
- sb.append( getProperty( ref ).asText() );
- }
- return sb;
- }
-
- @Override
- public StringBuffer asText() {
- return asSimpleText();
- }
-
- @Override
- public PhylogenyData copy() {
- final PropertiesMap new_one = new PropertiesMap();
- for( final String r : getProperties().keySet() ) {
- new_one.addProperty( getProperties().get( r ) );
- }
- return new_one;
- }
-
- public SortedMap<String, Property> getProperties() {
- return _properties;
- }
-
- public Property[] getPropertiesArray() {
- final Property[] a = new Property[ getProperties().size() ];
- int i = 0;
- for( final String ref : getProperties().keySet() ) {
- a[ i++ ] = getProperties().get( ref );
- }
- return a;
- }
-
- public List<Property> getPropertiesWithGivenReferencePrefix( final String ref_prefix )
- throws IllegalArgumentException {
- if ( ForesterUtil.isEmpty( ref_prefix ) ) {
- throw new IllegalArgumentException( "reference prefix is null or empty" );
- }
- final String my_ref_prefix = new String( ref_prefix.trim() );
- final List<Property> props = new ArrayList<Property>();
- for( final String ref : getProperties().keySet() ) {
- if ( ref.startsWith( my_ref_prefix ) ) {
- props.add( getProperty( ref ) );
- }
- }
- return props;
- }
-
- public Property getProperty( final String ref ) throws IllegalArgumentException {
- if ( getProperties().containsKey( ref ) ) {
- return getProperties().get( ref );
- }
- else {
- throw new IllegalArgumentException( "reference [" + ref + "] is not present" );
- }
- }
-
- /**
- * Returns all property refs of this PhylogenyNode as String array.
- */
- public String[] getPropertyRefs() {
- if ( getProperties() == null ) {
- return new String[ 0 ];
- }
- final Property[] properties = getPropertiesArray();
- final String[] refs = new String[ properties.length ];
- for( int i = 0; i < properties.length; ++i ) {
- refs[ i ] = properties[ i ].getRef();
- }
- return refs;
- }
-
- @Override
- public boolean isEqual( final PhylogenyData data ) {
- throw new UnsupportedOperationException();
- }
-
- public boolean refExists( final String ref ) {
- if ( getProperties() != null ) {
- for( final String r : getProperties().keySet() ) {
- if ( r.equalsIgnoreCase( ref ) ) {
- return true;
- }
- }
- }
- return false;
- }
-
- public Property removeProperty( final String ref ) throws IllegalArgumentException {
- if ( getProperties().containsKey( ref ) ) {
- return getProperties().remove( ref );
- }
- else {
- throw new IllegalArgumentException( "reference [" + ref + "] is not present" );
- }
- }
-
- public List<String> removePropertiesWithGivenReferencePrefix( final String ref_prefix )
- throws IllegalArgumentException {
- if ( ForesterUtil.isEmpty( ref_prefix ) ) {
- throw new IllegalArgumentException( "reference prefix is null or empty" );
- }
- final String my_ref_prefix = new String( ref_prefix.trim() );
- final List<String> to_remove = new ArrayList<String>();
- for( final String ref : getProperties().keySet() ) {
- if ( ref.startsWith( my_ref_prefix ) ) {
- to_remove.add( ref );
- }
- }
- for( final String ref : to_remove ) {
- getProperties().remove( ref );
- }
- return to_remove;
- }
-
- @Override
- public StringBuffer toNHX() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
- if ( getProperties() != null ) {
- for( final String ref : getProperties().keySet() ) {
- getProperties().get( ref ).toPhyloXML( writer, level, indentation );
- }
- }
- }
-
- @Override
- public String toString() {
- return asSimpleText().toString();
- }
-}
import org.forester.phylogeny.data.PhylogenyData;
import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Polygon;
-import org.forester.phylogeny.data.PropertiesMap;
+import org.forester.phylogeny.data.PropertiesList;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Property.AppliesTo;
import org.forester.phylogeny.data.ProteinDomain;
private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
+ ForesterUtil.getFileSeparator() + "test_data"
+ ForesterUtil.getFileSeparator();
- private final static boolean PERFORM_DB_TESTS = true;
- private static final boolean PERFORM_WEB_TREE_ACCESS = true;
+ private final static boolean PERFORM_DB_TESTS = false;
+ private static final boolean PERFORM_WEB_TREE_ACCESS = false;
private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
+ ForesterConstants.PHYLO_XML_VERSION + "/"
+ ForesterConstants.PHYLO_XML_XSD;
return false;
}
if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
return false;
}
if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
return false;
}
if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
return false;
}
if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
return false;
}
if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
return false;
}
if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
+ .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
return false;
}
if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
return false;
}
if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
return false;
}
if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
return false;
}
if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
return false;
}
if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
return false;
}
if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
+ .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
return false;
}
if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
- .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
+ .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
return false;
}
if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
private static boolean testPropertiesMap() {
try {
- final PropertiesMap pm = new PropertiesMap();
+ final PropertiesList pm = new PropertiesList();
final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
final Property p2 = new Property( "something:else",
pm.addProperty( p0 );
pm.addProperty( p1 );
pm.addProperty( p2 );
- if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
+ if ( !pm.getProperties( "dimensions:diameter" ).get( 0 ).getValue().equals( "1" ) ) {
return false;
}
- if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
+ if ( !pm.getProperties( "dimensions:length" ).get( 0 ).getValue().equals( "2" ) ) {
return false;
}
if ( pm.getProperties().size() != 3 ) {
if ( pm.getProperties().size() != 3 ) {
return false;
}
- pm.removeProperty( "dimensions:diameter" );
- if ( pm.getProperties().size() != 2 ) {
- return false;
- }
- if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
- return false;
- }
- if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
- return false;
- }
+
}
catch ( final Exception e ) {
e.printStackTrace( System.out );