regex validator for uniprot
[jalview.git] / src / jalview / ws / dbsources / Uniprot.java
index ab0b10c..3331756 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -76,7 +76,7 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
    */
   public Regex getAccessionValidator()
   {
-    return null;
+    return new Regex("([A-Z]+[0-9]+[A-Z0-9]+|[A-Z0-9]+_[A-Z0-9]+)");
   }
 
   /*
@@ -116,8 +116,10 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
       Unmarshaller unmar = new Unmarshaller(uni);
       unmar.setIgnoreExtraElements(true);
       unmar.setMapping(map);
-
-      uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
+      if (file!=null)
+      {
+        uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
+      }
     } catch (Exception e)
     {
       System.out.println("Error getUniprotEntries() " + e);
@@ -136,11 +138,13 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
     startQuery();
     try
     {
+      queries = queries.toUpperCase().replaceAll("(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)","");
       Alignment al = null;
       ebi = new EBIFetchClient();
       StringBuffer result = new StringBuffer();
       // uniprotxml parameter required since december 2007
-      File file = ebi.fetchDataAsFile("uniprot:" + queries, "uniprotxml",
+      // uniprotkb dbname changed introduced december 2008
+      File file = ebi.fetchDataAsFile("uniprotkb:" + queries, "uniprotxml",
               null);
       Vector entries = getUniprotEntries(file);
 
@@ -273,7 +277,8 @@ public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
    */
   public boolean isValidReference(String accession)
   {
-    return true;
+    // TODO: make the following a standard validator
+    return (accession==null || accession.length()<2) ? false : getAccessionValidator().search(accession);
   }
 
   /**