inprogress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / NodeEditPanel.java
index 81e869d..f593a78 100644 (file)
@@ -21,7 +21,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 //
 // Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
 
 package org.forester.archaeopteryx;
 
@@ -52,6 +52,7 @@ import org.forester.archaeopteryx.tools.ImageLoader;
 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.data.Accession;
+import org.forester.phylogeny.data.BranchWidth;
 import org.forester.phylogeny.data.Confidence;
 import org.forester.phylogeny.data.Date;
 import org.forester.phylogeny.data.Distribution;
@@ -59,6 +60,7 @@ import org.forester.phylogeny.data.Event;
 import org.forester.phylogeny.data.Identifier;
 import org.forester.phylogeny.data.MultipleUris;
 import org.forester.phylogeny.data.PhylogenyData;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
 import org.forester.phylogeny.data.Point;
 import org.forester.phylogeny.data.Reference;
 import org.forester.phylogeny.data.Sequence;
@@ -152,7 +154,7 @@ class NodeEditPanel extends JPanel {
         top.add( category );
         addSubelementEditable( category, NodePanel.NODE_NAME, phylogeny_node.getName(), PHYLOXML_TAG.NODE_NAME );
         String bl = "";
-        if ( phylogeny_node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+        if ( phylogeny_node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
             bl = ForesterUtil.FORMATTER_6.format( phylogeny_node.getDistanceToParent() );
         }
         addSubelementEditable( category, NodePanel.NODE_BRANCH_LENGTH, bl, PHYLOXML_TAG.NODE_BRANCH_LENGTH );
@@ -183,6 +185,12 @@ class NodeEditPanel extends JPanel {
                                "",
                                PHYLOXML_TAG.CONFIDENCE_TYPE,
                                counter );
+        String bw = "1";
+        if ( ( phylogeny_node.getBranchData().getBranchWidth() != null )
+                && ( phylogeny_node.getBranchData().getBranchWidth().getValue() != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) ) {
+            bw = ForesterUtil.FORMATTER_3.format( phylogeny_node.getBranchData().getBranchWidth().getValue() );
+        }
+        addSubelementEditable( category, NodePanel.NODE_BRANCH_WIDTH, bw, PHYLOXML_TAG.NODE_BRANCH_WIDTH );
     }
 
     //    private void addAnnotation( final DefaultMutableTreeNode top, final Annotation ann, final String name ) {
@@ -329,6 +337,7 @@ class NodeEditPanel extends JPanel {
         }
         addSubelementEditable( category, NodePanel.SEQ_NAME, seq.getName(), PHYLOXML_TAG.SEQ_NAME );
         addSubelementEditable( category, NodePanel.SEQ_SYMBOL, seq.getSymbol(), PHYLOXML_TAG.SEQ_SYMBOL );
+        addSubelementEditable( category, NodePanel.SEQ_GENE_NAME, seq.getGeneName(), PHYLOXML_TAG.SEQ_GENE_NAME );
         addSubelementEditable( category,
                                NodePanel.SEQ_ACCESSION,
                                acc.getValue(),
@@ -644,7 +653,7 @@ class NodeEditPanel extends JPanel {
                 break;
             case NODE_BRANCH_LENGTH:
                 if ( ForesterUtil.isEmpty( value ) ) {
-                    getMyNode().setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
+                    getMyNode().setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
                 }
                 else {
                     try {
@@ -659,6 +668,28 @@ class NodeEditPanel extends JPanel {
                     }
                 }
                 break;
+            case NODE_BRANCH_WIDTH:
+                if ( ForesterUtil.isEmpty( value ) || value.equals( "1" ) ) {
+                    if ( getMyNode().getBranchData().getBranchWidth() != null ) {
+                        getMyNode().getBranchData().setBranchWidth( new BranchWidth() );
+                    }
+                }
+                else {
+                    try {
+                        final double bw = ForesterUtil.parseDouble( value );
+                        if ( bw >= 0 ) {
+                            getMyNode().getBranchData().setBranchWidth( new BranchWidth( bw ) );
+                        }
+                    }
+                    catch ( final ParseException e ) {
+                        JOptionPane.showMessageDialog( this,
+                                                       "failed to parse branch width from: " + value,
+                                                       "Error",
+                                                       JOptionPane.ERROR_MESSAGE );
+                        mtn.setUserObject( "" );
+                    }
+                }
+                break;
             case CONFIDENCE_VALUE:
                 double confidence = Confidence.CONFIDENCE_DEFAULT_VALUE;
                 if ( !ForesterUtil.isEmpty( value ) ) {
@@ -684,7 +715,8 @@ class NodeEditPanel extends JPanel {
                 }
                 else {
                     final String type = getMyNode().getBranchData().getConfidences().get( number ).getType();
-                    getMyNode().getBranchData().getConfidences().set( number, new Confidence( confidence, type ) );
+                    final double sd = getMyNode().getBranchData().getConfidences().get( number ).getStandardDeviation();
+                    getMyNode().getBranchData().getConfidences().set( number, new Confidence( confidence, type, sd ) );
                 }
                 break;
             case CONFIDENCE_TYPE:
@@ -698,7 +730,8 @@ class NodeEditPanel extends JPanel {
                 }
                 else {
                     final double v = getMyNode().getBranchData().getConfidences().get( number ).getValue();
-                    getMyNode().getBranchData().getConfidences().set( number, new Confidence( v, value ) );
+                    final double sd = getMyNode().getBranchData().getConfidences().get( number ).getStandardDeviation();
+                    getMyNode().getBranchData().getConfidences().set( number, new Confidence( v, value, sd ) );
                 }
                 break;
             case TAXONOMY_CODE:
@@ -793,7 +826,7 @@ class NodeEditPanel extends JPanel {
                 break;
             case SEQ_MOL_SEQ:
                 ForesterUtil.ensurePresenceOfSequence( getMyNode() );
-                getMyNode().getNodeData().getSequence().setMolecularSequence( value );
+                getMyNode().getNodeData().getSequence().setMolecularSequence( value.replaceAll( "[^a-zA-Z-]", "" ) );
                 break;
             case SEQ_NAME:
                 ForesterUtil.ensurePresenceOfSequence( getMyNode() );
@@ -809,6 +842,10 @@ class NodeEditPanel extends JPanel {
                     break;
                 }
                 break;
+            case SEQ_GENE_NAME:
+                ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+                getMyNode().getNodeData().getSequence().setGeneName( value );
+                break;
             case SEQ_TYPE:
                 ForesterUtil.ensurePresenceOfSequence( getMyNode() );
                 try {
@@ -1020,6 +1057,7 @@ class NodeEditPanel extends JPanel {
     private enum PHYLOXML_TAG {
         NODE_NAME,
         NODE_BRANCH_LENGTH,
+        NODE_BRANCH_WIDTH,
         TAXONOMY_CODE,
         TAXONOMY_SCIENTIFIC_NAME,
         TAXONOMY_AUTHORITY,
@@ -1029,6 +1067,7 @@ class NodeEditPanel extends JPanel {
         TAXONOMY_URI,
         SEQ_SYMBOL,
         SEQ_NAME,
+        SEQ_GENE_NAME,
         SEQ_LOCATION,
         SEQ_TYPE,
         SEQ_MOL_SEQ,