sequence db fetcher and db reference validation/annotation transfer
[jalview.git] / src / jalview / ws / dbsources / Uniprot.java
index 23bfbca..a889ac9 100644 (file)
@@ -4,11 +4,14 @@
 package jalview.ws.dbsources;\r
 \r
 import java.io.File;\r
+import java.io.FileReader;\r
 import java.io.IOException;\r
 import java.util.Enumeration;\r
 import java.util.Hashtable;\r
 import java.util.Vector;\r
 \r
+import org.exolab.castor.xml.Unmarshaller;\r
+\r
 import com.stevesoft.pat.Regex;\r
 \r
 import jalview.datamodel.Alignment;\r
@@ -19,6 +22,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceFeature;\r
 import jalview.datamodel.SequenceI;\r
 import jalview.datamodel.UniprotEntry;\r
+import jalview.datamodel.UniprotFile;\r
 import jalview.io.FormatAdapter;\r
 import jalview.io.IdentifyFile;\r
 import jalview.ws.DBRefFetcher;\r
@@ -36,7 +40,7 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
     super();\r
     addDbSourceProperty(DBRefSource.SEQDB, DBRefSource.SEQDB);\r
     addDbSourceProperty(DBRefSource.PROTSEQDB);\r
-    addDbSourceProperty(DBRefSource.MULTIACC);\r
+    addDbSourceProperty(DBRefSource.MULTIACC, new Integer(50));\r
   }\r
 \r
   /*\r
@@ -81,6 +85,31 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
 \r
   private EBIFetchClient ebi = null;\r
 \r
+  public Vector getUniprotEntries(File file)\r
+  {\r
+    UniprotFile uni = new UniprotFile();\r
+    try\r
+    {\r
+      // 1. Load the mapping information from the file\r
+      org.exolab.castor.mapping.Mapping map = new org.exolab.castor.mapping.Mapping(uni.getClass().getClassLoader());\r
+      java.net.URL url = getClass().getResource("/uniprot_mapping.xml");\r
+      map.loadMapping(url);\r
+\r
+      // 2. Unmarshal the data\r
+      Unmarshaller unmar = new Unmarshaller(uni);\r
+      unmar.setIgnoreExtraElements(true);\r
+      unmar.setMapping(map);\r
+\r
+      uni = (UniprotFile) unmar.unmarshal(new FileReader(file));\r
+    }\r
+    catch (Exception e)\r
+    {\r
+      System.out.println("Error getUniprotEntries() " + e);\r
+    }\r
+\r
+    return uni.getUniprotEntries();\r
+  }\r
+\r
   /*\r
    * (non-Javadoc)\r
    * \r
@@ -94,9 +123,8 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
       Alignment al=null;\r
       ebi = new EBIFetchClient();\r
       StringBuffer result=new StringBuffer();\r
-      File file = ebi.fetchDataAsFile("uniprot:" + queries, "xml", null);\r
-      DBRefFetcher dbref = new DBRefFetcher();\r
-      Vector entries = dbref.getUniprotEntries(file);\r
+      File file = ebi.fetchDataAsFile("uniprot:" + queries, "uniprotxml", null);\r
+      Vector entries = getUniprotEntries(file);\r
 \r
       if (entries != null)\r
       {\r
@@ -183,8 +211,9 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
       Enumeration en2 = entry.getAccession().elements();\r
       while (en2.hasMoreElements())\r
       {\r
+        // we always add as uniprot if we retrieved from uniprot or uniprot name\r
         sq.addDBRef(\r
-                new DBRefEntry(getDbSource(), getDbVersion(), en2.nextElement()\r
+                new DBRefEntry(DBRefSource.UNIPROT, getDbVersion(), en2.nextElement()\r
                         .toString()));\r
       }\r
       sq.setPDBId(onlyPdbEntries);\r
@@ -217,4 +246,8 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
   {\r
     return "P00340";\r
   }\r
+  public String getDbName()\r
+  {\r
+    return getDbSource();\r
+  }\r
 }\r