JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / ws / dbsources / Uniprot.java
index 02da009..b6f53cd 100644 (file)
@@ -165,7 +165,7 @@ public class Uniprot extends DbSourceProxyImpl
       // uniprotxml parameter required since december 2007
       // uniprotkb dbname changed introduced december 2008
       File file = ebi.fetchDataAsFile("uniprotkb:" + queries, "uniprotxml",
-              null);
+              ".xml");
       Vector<UniprotEntry> entries = getUniprotEntries(new FileReader(file));
 
       if (entries != null)
@@ -193,7 +193,8 @@ public class Uniprot extends DbSourceProxyImpl
    *          UniprotEntry
    * @return SequenceI instance created from the UniprotEntry instance
    */
-  public SequenceI uniprotEntryToSequenceI(UniprotEntry entry){
+  public SequenceI uniprotEntryToSequenceI(UniprotEntry entry)
+  {
     String id = getUniprotEntryId(entry);
     SequenceI sequence = new Sequence(id, entry.getUniprotSequence()
             .getContent());
@@ -205,10 +206,10 @@ public class Uniprot extends DbSourceProxyImpl
     {
       DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion,
               accessionId);
+
+      // mark dbRef as a primary reference for this sequence
       dbRefs.add(dbRef);
     }
-    sequence.setSourceDBRef((dbRefs != null && dbRefs.size() > 0) ? dbRefs
-            .get(0) : null);
 
     Vector<PDBEntry> onlyPdbEntries = new Vector<PDBEntry>();
     for (PDBEntry pdb : entry.getDbReference())
@@ -222,6 +223,38 @@ public class Uniprot extends DbSourceProxyImpl
       {
         onlyPdbEntries.addElement(pdb);
       }
+      if ("EMBL".equals(pdb.getType()))
+      {
+        // look for a CDS reference and add it, too.
+        String cdsId = (String) pdb.getProperty("protein sequence ID");
+        if (cdsId != null && cdsId.trim().length() > 0)
+        {
+          // remove version
+          String[] vrs = cdsId.split("\\.");
+          dbr = new DBRefEntry(DBRefSource.EMBLCDS, vrs.length > 1 ? vrs[1]
+                  : DBRefSource.UNIPROT + ":" + dbVersion, vrs[0]);
+          dbRefs.add(dbr);
+        }
+      }
+      if ("Ensembl".equals(pdb.getType()))
+      {
+        /*UniprotXML
+         * <dbReference type="Ensembl" id="ENST00000321556">
+        * <molecule id="Q9BXM7-1"/>
+        * <property type="protein sequence ID" value="ENSP00000364204"/>
+        * <property type="gene ID" value="ENSG00000158828"/>
+        * </dbReference> 
+         */
+        String cdsId = (String) pdb.getProperty("protein sequence ID");
+        if (cdsId != null && cdsId.trim().length() > 0)
+        {
+          dbr = new DBRefEntry(DBRefSource.ENSEMBL, DBRefSource.UNIPROT
+                  + ":" + dbVersion, cdsId.trim());
+          dbRefs.add(dbr);
+
+        }
+      }
+
     }
 
     sequence.setPDBId(onlyPdbEntries);
@@ -233,7 +266,10 @@ public class Uniprot extends DbSourceProxyImpl
         sequence.addSequenceFeature(sf);
       }
     }
-    sequence.setDBRefs(dbRefs.toArray(new DBRefEntry[0]));
+    for (DBRefEntry dbr : dbRefs)
+    {
+      sequence.addDBRef(dbr);
+    }
     return sequence;
   }
 
@@ -248,9 +284,15 @@ public class Uniprot extends DbSourceProxyImpl
     StringBuilder desc = new StringBuilder(32);
     if (entry.getProtein() != null && entry.getProtein().getName() != null)
     {
+      boolean first = true;
       for (String nm : entry.getProtein().getName())
       {
-        desc.append(nm).append(" ");
+        if (!first)
+        {
+          desc.append(" ");
+        }
+        first = false;
+        desc.append(nm);
       }
     }
     return desc.toString();
@@ -265,7 +307,9 @@ public class Uniprot extends DbSourceProxyImpl
   public static String getUniprotEntryId(UniprotEntry entry)
   {
     StringBuilder name = new StringBuilder(32);
-    name.append("UniProt/Swiss-Prot");
+    // name.append("UniProt/Swiss-Prot");
+    // use 'canonicalised' name for optimal id matching
+    name.append(DBRefSource.UNIPROT);
     for (String accessionId : entry.getAccession())
     {
       name.append(BAR_DELIMITER);