inprogress
[jalview.git] / forester / java / src / org / forester / phylogeny / data / Accession.java
index 6e9f158..8d9739a 100644 (file)
@@ -34,13 +34,39 @@ import org.forester.util.ForesterUtil;
 
 public final class Accession implements PhylogenyData, Comparable<Accession> {
 
-    final private String _value;
-    final private String _source;
-    final private String _source_value;
+    final private String       _comment;
+    final private String       _source;
+    final private String       _source_value;
+    final private String       _value;
+    final public static String NCBI    = "ncbi";
+    final public static String REFSEQ  = "refseq";
+    final public static String UNIPROT = "uniprot";
+    final public static String GI      = "gi";
+    public static final String EMBL    = "embl";
+
+    public Accession( final String value ) {
+        _value = value;
+        _source = "";
+        _comment = "";
+        _source_value = value;
+    }
 
     public Accession( final String value, final String source ) {
         _value = value;
         _source = source;
+        _comment = "";
+        if ( source != null ) {
+            _source_value = source + value;
+        }
+        else {
+            _source_value = value;
+        }
+    }
+
+    public Accession( final String value, final String source, final String comment ) {
+        _value = value;
+        _source = source;
+        _comment = comment;
         if ( source != null ) {
             _source_value = source + value;
         }
@@ -58,15 +84,27 @@ public final class Accession implements PhylogenyData, Comparable<Accession> {
     public StringBuffer asText() {
         final StringBuffer sb = new StringBuffer();
         if ( !ForesterUtil.isEmpty( getSource() ) ) {
-            sb.append( "[" );
             sb.append( getSource() );
-            sb.append( "] " );
+            sb.append( ": " );
         }
         sb.append( getValue() );
+        if ( !ForesterUtil.isEmpty( getComment() ) ) {
+            sb.append( " (" );
+            sb.append( getComment() );
+            sb.append( ")" );
+        }
         return sb;
     }
 
     @Override
+    public int compareTo( final Accession o ) {
+        if ( equals( o ) ) {
+            return 0;
+        }
+        return _source_value.compareTo( o._source_value );
+    }
+
+    @Override
     public PhylogenyData copy() {
         return new Accession( getValue(), getSource() );
     }
@@ -88,6 +126,10 @@ public final class Accession implements PhylogenyData, Comparable<Accession> {
         }
     }
 
+    public String getComment() {
+        return _comment;
+    }
+
     public String getSource() {
         return _source;
     }
@@ -98,7 +140,6 @@ public final class Accession implements PhylogenyData, Comparable<Accession> {
 
     @Override
     public int hashCode() {
-      
         return _source_value.hashCode();
     }
 
@@ -129,20 +170,44 @@ public final class Accession implements PhylogenyData, Comparable<Accession> {
     @Override
     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
         if ( ForesterUtil.isEmpty( getSource() ) ) {
-            PhylogenyDataUtil.appendElement( writer,
-                                             PhyloXmlMapping.ACCESSION,
-                                             getValue(),
-                                             PhyloXmlMapping.ACCESSION_SOURCE_ATTR,
-                                             "unknown",
-                                             indentation );
+            if ( ForesterUtil.isEmpty( getComment() ) ) {
+                PhylogenyDataUtil.appendElement( writer,
+                                                 PhyloXmlMapping.ACCESSION,
+                                                 getValue(),
+                                                 PhyloXmlMapping.ACCESSION_SOURCE_ATTR,
+                                                 "unknown",
+                                                 indentation );
+            }
+            else {
+                PhylogenyDataUtil.appendElement( writer,
+                                                 PhyloXmlMapping.ACCESSION,
+                                                 getValue(),
+                                                 PhyloXmlMapping.ACCESSION_SOURCE_ATTR,
+                                                 "unknown",
+                                                 PhyloXmlMapping.ACCESSION_COMMENT_ATTR,
+                                                 getComment(),
+                                                 indentation );
+            }
         }
         else {
-            PhylogenyDataUtil.appendElement( writer,
-                                             PhyloXmlMapping.ACCESSION,
-                                             getValue(),
-                                             PhyloXmlMapping.ACCESSION_SOURCE_ATTR,
-                                             getSource(),
-                                             indentation );
+            if ( ForesterUtil.isEmpty( getComment() ) ) {
+                PhylogenyDataUtil.appendElement( writer,
+                                                 PhyloXmlMapping.ACCESSION,
+                                                 getValue(),
+                                                 PhyloXmlMapping.ACCESSION_SOURCE_ATTR,
+                                                 getSource(),
+                                                 indentation );
+            }
+            else {
+                PhylogenyDataUtil.appendElement( writer,
+                                                 PhyloXmlMapping.ACCESSION,
+                                                 getValue(),
+                                                 PhyloXmlMapping.ACCESSION_SOURCE_ATTR,
+                                                 getSource(),
+                                                 PhyloXmlMapping.ACCESSION_COMMENT_ATTR,
+                                                 getComment(),
+                                                 indentation );
+            }
         }
     }
 
@@ -150,12 +215,4 @@ public final class Accession implements PhylogenyData, Comparable<Accession> {
     public String toString() {
         return asText().toString();
     }
-
-    @Override
-    public int compareTo( Accession o ) {
-        if ( equals( o ) ) {
-            return 0;
-        }
-        return  _source_value.compareTo( o._source_value );
-    }
 }