From: cmzmasek Date: Tue, 8 Nov 2016 23:05:17 +0000 (-0800) Subject: in progress... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c31fca8b235625db6186410c2244ffcef10efa1c;p=jalview.git in progress... --- diff --git a/forester/java/src/org/forester/archaeopteryx/AptxConstants.java b/forester/java/src/org/forester/archaeopteryx/AptxConstants.java index 775f5e6..a86d4e1 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxConstants.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxConstants.java @@ -38,8 +38,8 @@ public final class AptxConstants { 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" }; diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index ec258ba..d6824e9 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -62,7 +62,7 @@ import javax.imageio.stream.ImageOutputStream; 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; @@ -800,13 +800,13 @@ public final class AptxUtil { 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 ) { @@ -821,7 +821,7 @@ public final class AptxUtil { 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 @@ -841,13 +841,13 @@ public final class AptxUtil { 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 ); } } } diff --git a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java index 3183972..d89204e 100644 --- a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java +++ b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java @@ -76,12 +76,6 @@ import org.forester.util.ForesterUtil; final class ControlPanel extends JPanel implements ActionListener { - enum TreeDisplayType { - CLADOGRAM, - ALIGNED_PHYLOGRAM, - UNALIGNED_PHYLOGRAM - }; - enum NodeClickAction { ADD_NEW_NODE, BLAST, @@ -150,7 +144,7 @@ final class ControlPanel extends JPanel implements ActionListener { private JTextField _domain_structure_evalue_thr_tf; private JTextField _depth_collapse_depth_tf; private JTextField _rank_collapse_depth_tf; - private List _tree_display_types; + private List _tree_display_types; private JCheckBox _dynamically_hide_data; private int _edit_node_data_item; private int _get_ext_desc_data; @@ -276,15 +270,15 @@ final class ControlPanel extends JPanel implements ActionListener { } 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 @@ -639,7 +633,7 @@ final class ControlPanel extends JPanel implements ActionListener { }// addSequenceRelationBlock /* GUILHEM_END */ - private List getTreeDisplayTypes() { + private List getTreeDisplayTypes() { return _tree_display_types; } @@ -648,13 +642,13 @@ final class ControlPanel extends JPanel implements ActionListener { } private void init() { - _tree_display_types = new ArrayList(); + _tree_display_types = new ArrayList(); setSpeciesColors( new HashMap() ); setSequenceColors( new HashMap() ); setAnnotationColors( new HashMap() ); } - private TreeDisplayType getTreeDisplayType( final int index ) { + private Options.PHYLOGENY_DISPLAY_TYPE getTreeDisplayType( final int index ) { return getTreeDisplayTypes().get( index ); } @@ -794,7 +788,7 @@ final class ControlPanel extends JPanel implements ActionListener { } } - 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 ); } @@ -1263,7 +1257,7 @@ final class ControlPanel extends JPanel implements ActionListener { _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]" ); @@ -1642,8 +1636,8 @@ final class ControlPanel extends JPanel implements ActionListener { } 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() { @@ -1741,10 +1735,10 @@ final class ControlPanel extends JPanel implements ActionListener { 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); } } @@ -2068,7 +2062,7 @@ final class ControlPanel extends JPanel implements ActionListener { _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 ); @@ -2153,9 +2147,9 @@ final class ControlPanel extends JPanel implements ActionListener { } 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 ); @@ -2597,7 +2591,7 @@ final class ControlPanel extends JPanel implements ActionListener { } else { setDrawPhylogramEnabled( false ); - setTreeDisplayType( TreeDisplayType.CLADOGRAM ); + setTreeDisplayType( Options.PHYLOGENY_DISPLAY_TYPE.CLADOGRAM ); } getMainPanel().getMainFrame() @@ -2802,8 +2796,8 @@ final class ControlPanel extends JPanel implements ActionListener { } 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)); } @@ -2838,13 +2832,13 @@ final class ControlPanel extends JPanel implements ActionListener { 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; } } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 3c939e4..780dcc3 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -761,10 +761,7 @@ public final class MainFrameApplication extends MainFrame { l.add( d ); } if ( !l.isEmpty() ) { - if ( node.getNodeData().getProperties() != null ) { - node.getNodeData().getProperties() - .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF ); - } + node.getNodeData().setVector( l ); } } diff --git a/forester/java/src/org/forester/archaeopteryx/NodePanel.java b/forester/java/src/org/forester/archaeopteryx/NodePanel.java index 0c1aa5b..b3df423 100644 --- a/forester/java/src/org/forester/archaeopteryx/NodePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/NodePanel.java @@ -60,7 +60,7 @@ import org.forester.phylogeny.data.Event; 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; @@ -370,13 +370,13 @@ class NodePanel extends JPanel implements TreeSelectionListener { } private static void addProperties( final DefaultMutableTreeNode top, - final PropertiesMap properties, + final PropertiesList properties, final String string ) { - final SortedMap properties_map = properties.getProperties(); + final List 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() + "]" ) ); } diff --git a/forester/java/src/org/forester/archaeopteryx/Options.java b/forester/java/src/org/forester/archaeopteryx/Options.java index 184e795..a228d29 100644 --- a/forester/java/src/org/forester/archaeopteryx/Options.java +++ b/forester/java/src/org/forester/archaeopteryx/Options.java @@ -51,6 +51,12 @@ final public class Options { 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" ), @@ -73,6 +79,7 @@ final public class Options { return toString().replaceAll( " ", "_" ); } } + static final double MIN_CONFIDENCE_DEFAULT = 0.0; private boolean _abbreviate_scientific_names; private boolean _allow_errors_in_distance_to_parent; diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index ccd3652..0b07a70 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -96,10 +96,10 @@ import javax.swing.PopupFactory; 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; @@ -122,7 +122,7 @@ import org.forester.phylogeny.data.NodeVisualData; 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; @@ -383,7 +383,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee init(); // if ( !_phylogeny.isEmpty() ) { _phylogeny.recalculateNumberOfExternalDescendants( true ); - checkForVectorProperties( _phylogeny ); + // } setBackground( getTreeColorSet().getBackgroundColor() ); final MouseListener mouse_listener = new MouseListener( this ); @@ -1741,7 +1741,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee 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 ) { @@ -2919,7 +2920,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee 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() @@ -2935,7 +2936,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee 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() ) { @@ -3307,7 +3308,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee 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(); @@ -3642,7 +3643,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee 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 ); @@ -3882,25 +3883,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } 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, @@ -4453,17 +4437,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } 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() ) { @@ -4859,66 +4837,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } - 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 vector_l = new ArrayList( 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() ); diff --git a/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlHandler.java b/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlHandler.java index 3e2f6a7..e2750da 100644 --- a/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlHandler.java +++ b/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlHandler.java @@ -57,7 +57,7 @@ import org.forester.phylogeny.data.Event; 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; @@ -334,7 +334,7 @@ public final class PhyloXmlHandler extends DefaultHandler { } else { if ( !node.getNodeData().isHasProperties() ) { - node.getNodeData().setProperties( new PropertiesMap() ); + node.getNodeData().setProperties( new PropertiesList() ); } node.getNodeData().getProperties().addProperty( prop ); } diff --git a/forester/java/src/org/forester/io/parsers/phyloxml/data/AnnotationParser.java b/forester/java/src/org/forester/io/parsers/phyloxml/data/AnnotationParser.java index 66023d4..9394788 100644 --- a/forester/java/src/org/forester/io/parsers/phyloxml/data/AnnotationParser.java +++ b/forester/java/src/org/forester/io/parsers/phyloxml/data/AnnotationParser.java @@ -31,7 +31,7 @@ import org.forester.io.parsers.phyloxml.XmlElement; 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; @@ -81,7 +81,7 @@ public class AnnotationParser implements PhylogenyDataPhyloXmlParser { } 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 ) ); diff --git a/forester/java/src/org/forester/phylogeny/data/Annotation.java b/forester/java/src/org/forester/phylogeny/data/Annotation.java index 652a034..b78f5b7 100644 --- a/forester/java/src/org/forester/phylogeny/data/Annotation.java +++ b/forester/java/src/org/forester/phylogeny/data/Annotation.java @@ -39,7 +39,7 @@ public class Annotation implements PhylogenyData, MultipleUris, Comparable _distributions; private Date _date; private BinaryCharacters _binary_characters; - private PropertiesMap _properties; + private PropertiesList _properties; private List _references; private List _vector; private NodeVisualData _node_visual_data; @@ -155,7 +155,7 @@ public class NodeData implements PhylogenyData { new_data.setDate( ( Date ) getDate().copy() ); } if ( isHasProperties() ) { - new_data.setProperties( ( PropertiesMap ) getProperties().copy() ); + new_data.setProperties( ( PropertiesList ) getProperties().copy() ); } return new_data; } @@ -192,7 +192,7 @@ public class NodeData implements PhylogenyData { return _event; } - public PropertiesMap getProperties() { + public PropertiesList getProperties() { return _properties; } @@ -348,7 +348,7 @@ public class NodeData implements PhylogenyData { _event = event; } - public void setProperties( final PropertiesMap custom_data ) { + public void setProperties( final PropertiesList custom_data ) { _properties = custom_data; } diff --git a/forester/java/src/org/forester/phylogeny/data/PropertiesList.java b/forester/java/src/org/forester/phylogeny/data/PropertiesList.java new file mode 100644 index 0000000..4b2d961 --- /dev/null +++ b/forester/java/src/org/forester/phylogeny/data/PropertiesList.java @@ -0,0 +1,143 @@ +// $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 _properties; + private final Comparator comp = new Comparator() { + + @Override + public int compare( final Property p1, final Property p2 ) { + return p2.getRef().compareTo( p1.getRef() ); + } + }; + + public PropertiesList() { + _properties = new ArrayList(); + } + + 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 getProperties() { + return _properties; + } + + public List 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 props = new ArrayList(); + for( final Property p : getProperties() ) { + if ( p.getRef().startsWith( my_ref_prefix ) ) { + props.add( p ); + } + } + return props; + } + + public List getProperties( final String ref ) throws IllegalArgumentException { + final List props = new ArrayList(); + 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(); + } +} diff --git a/forester/java/src/org/forester/phylogeny/data/PropertiesMap.java b/forester/java/src/org/forester/phylogeny/data/PropertiesMap.java deleted file mode 100644 index 4b404be..0000000 --- a/forester/java/src/org/forester/phylogeny/data/PropertiesMap.java +++ /dev/null @@ -1,199 +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: 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 _properties; - - public PropertiesMap() { - _properties = new TreeMap(); - } - - 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 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 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 props = new ArrayList(); - 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 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 to_remove = new ArrayList(); - 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(); - } -} diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 75000a9..c147844 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -88,7 +88,7 @@ import org.forester.phylogeny.data.Identifier; 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; @@ -136,8 +136,8 @@ public final class Test { 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; @@ -2213,27 +2213,27 @@ public final class Test { 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() @@ -2408,27 +2408,27 @@ public final class Test { 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() @@ -10805,7 +10805,7 @@ public final class Test { 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", @@ -10816,10 +10816,10 @@ public final class Test { 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 ) { @@ -10834,16 +10834,7 @@ public final class Test { 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 );