JAL-3121 round trip GFF attributes including map-valued attributes
[jalview.git] / src / jalview / ws / dbsources / EmblXmlSource.java
index 8f55080..a420d9f 100644 (file)
@@ -52,7 +52,6 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.regex.Pattern;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -68,8 +67,6 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
    */
   private static final String EMBL_NOT_FOUND_REPLY = "ERROR 12 No entries found.";
 
-  private static final Pattern SPACE_PATTERN = Pattern.compile(" ");
-
   public EmblXmlSource()
   {
     super();
@@ -85,7 +82,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
    * @return
    * @throws Exception
    */
-  public AlignmentI getEmblSequenceRecords(String emprefx, String query)
+  protected AlignmentI getEmblSequenceRecords(String emprefx, String query)
           throws Exception
   {
     startQuery();
@@ -118,7 +115,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
    * @return
    * @throws Exception
    */
-  public AlignmentI getEmblSequenceRecords(String emprefx, String query,
+  protected AlignmentI getEmblSequenceRecords(String emprefx, String query,
           File reply) throws Exception
   {
     List<EntryType> entries = null;
@@ -244,14 +241,18 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     /*
      * add db references
      */
-    List<XrefType> dbRefs = entry.getXref();
-    if (dbRefs != null)
+    List<XrefType> xrefs = entry.getXref();
+    if (xrefs != null)
     {
-      for (XrefType dbref : dbRefs)
+      for (XrefType xref : xrefs)
       {
-        String acc = dbref.getId();
-        String source = DBRefUtils.getCanonicalName(dbref.getDb());
-        String version = dbref.getSecondaryId();
+        String acc = xref.getId();
+        String source = DBRefUtils.getCanonicalName(xref.getDb());
+        String version = xref.getSecondaryId();
+        if (version == null || "".equals(version))
+        {
+          version = "0";
+        }
         dna.addDBRef(new DBRefEntry(source, version, acc));
       }
     }
@@ -524,10 +525,14 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
          * ensure UniProtKB/Swiss-Prot converted to UNIPROT
          */
         String source = DBRefUtils.getCanonicalName(xref.getDb());
-        DBRefEntry dbref = new DBRefEntry(source, xref.getSecondaryId(),
-                xref.getId());
-        DBRefEntry proteinDbRef = new DBRefEntry(dbref.getSource(),
-                dbref.getVersion(), dbref.getAccessionId());
+        String version = xref.getSecondaryId();
+        if (version == null || "".equals(version))
+        {
+          version = "0";
+        }
+        DBRefEntry dbref = new DBRefEntry(source, version, xref.getId());
+        DBRefEntry proteinDbRef = new DBRefEntry(source, version,
+                dbref.getAccessionId());
         if (source.equals(DBRefSource.UNIPROT))
         {
           String proteinSeqName = DBRefSource.UNIPROT + "|"
@@ -695,19 +700,10 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     SequenceFeature sf = new SequenceFeature(type, desc, begin, end, group);
     if (!vals.isEmpty())
     {
-      StringBuilder sb = new StringBuilder();
-      boolean first = true;
       for (Entry<String, String> val : vals.entrySet())
       {
-        if (!first)
-        {
-          sb.append(";");
-        }
-        sb.append(val.getKey()).append("=").append(val.getValue());
-        first = false;
         sf.setValue(val.getKey(), val.getValue());
       }
-      sf.setAttributes(sb.toString());
     }
     return sf;
   }