in progress
[jalview.git] / forester / java / src / org / forester / ws / uniprot / UniProtEntry.java
index 906473c..d5056e6 100644 (file)
@@ -27,7 +27,9 @@ package org.forester.ws.uniprot;
 
 import java.util.List;
 
-public final class UniProtEntry {
+import org.forester.util.ForesterUtil;
+
+public final class UniProtEntry implements SequenceDatabaseEntry {
 
     private String _ac;
     private String _rec_name;
@@ -38,50 +40,46 @@ public final class UniProtEntry {
     private UniProtEntry() {
     }
 
-    public static UniProtEntry createInstanceFromPlainText( final List<String> lines ) {
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        throw new CloneNotSupportedException();
+    }
+
+    public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
         final UniProtEntry e = new UniProtEntry();
         for( final String line : lines ) {
             if ( line.startsWith( "AC" ) ) {
-                e.setAc( extract( line, "AC", ";" ) );
+                e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
             }
             else if ( line.startsWith( "DE" ) ) {
                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
-                    e.setRecName( extract( line, "Full=", ";" ) );
+                    e.setRecName( DatabaseTools.extract( line, "Full=", ";" ) );
                 }
             }
             else if ( line.startsWith( "GN" ) ) {
                 if ( ( line.indexOf( "Name=" ) > 0 ) ) {
-                    e.setSymbol( extract( line, "Name=", ";" ) );
+                    e.setSymbol( DatabaseTools.extract( line, "Name=", ";" ) );
                 }
             }
             else if ( line.startsWith( "OS" ) ) {
                 if ( line.indexOf( "(" ) > 0 ) {
-                    e.setOsScientificName( extract( line, "OS", "(" ) );
+                    e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
                 }
                 else {
-                    e.setOsScientificName( extract( line, "OS", "." ) );
+                    e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
                 }
             }
             else if ( line.startsWith( "OX" ) ) {
                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
-                    e.setTaxId( extract( line, "NCBI_TaxID=", ";" ) );
+                    e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
                 }
             }
         }
         return e;
     }
 
-    private static String extract( final String target, final String a, final String b ) {
-        final int i_a = target.indexOf( a );
-        final int i_b = target.indexOf( b );
-        if ( ( i_a < 0 ) || ( i_b < i_a ) ) {
-            throw new IllegalArgumentException( "attempt to extract from [" + target + "] between [" + a + "] and ["
-                    + b + "]" );
-        }
-        return target.substring( i_a + a.length(), i_b ).trim();
-    }
-
-    public String getAc() {
+    @Override
+    public String getAccession() {
         return _ac;
     }
 
@@ -91,7 +89,8 @@ public final class UniProtEntry {
         }
     }
 
-    public String getRecName() {
+    @Override
+    public String getSequenceName() {
         return _rec_name;
     }
 
@@ -101,7 +100,8 @@ public final class UniProtEntry {
         }
     }
 
-    public String getOsScientificName() {
+    @Override
+    public String getTaxonomyScientificName() {
         return _os_scientific_name;
     }
 
@@ -111,7 +111,8 @@ public final class UniProtEntry {
         }
     }
 
-    public String getTaxId() {
+    @Override
+    public String getTaxonomyIdentifier() {
         return _tax_id;
     }
 
@@ -121,7 +122,8 @@ public final class UniProtEntry {
         }
     }
 
-    public String getSymbol() {
+    @Override
+    public String getSequenceSymbol() {
         return _symbol;
     }
 
@@ -130,4 +132,16 @@ public final class UniProtEntry {
             _symbol = symbol;
         }
     }
+
+    @Override
+    public boolean isEmpty() {
+        return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
+                && ForesterUtil.isEmpty( getTaxonomyScientificName() )
+                && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil.isEmpty( getSequenceSymbol() ) );
+    }
+
+    @Override
+    public String getProvider() {
+        return "uniprot";
+    }
 }