Merge branch 'develop' into features/JAL-1705_ensembl
[jalview.git] / src / jalview / util / DBRefUtils.java
index 123a4e1..b8f1dd5 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -118,8 +119,7 @@ public class DBRefUtils
     {
       return false;
     }
-    String coordsys = dasCoordinateSystemsLookup.get(string
-            .toLowerCase());
+    String coordsys = dasCoordinateSystemsLookup.get(string.toLowerCase());
     return coordsys == null ? false : coordsys.equals(dBRefEntry
             .getSource());
   }
@@ -139,8 +139,7 @@ public class DBRefUtils
     {
       return null;
     }
-    String canonical = canonicalSourceNameLookup.get(source
-            .toLowerCase());
+    String canonical = canonicalSourceNameLookup.get(source.toLowerCase());
     return canonical == null ? source : canonical;
   }
 
@@ -436,7 +435,7 @@ public class DBRefUtils
         {
           String pdbid = r.stringMatched(1);
           String chaincode = r.stringMatched(2);
-          if (chaincode==null)
+          if (chaincode == null)
           {
             chaincode = " ";
           }
@@ -455,8 +454,10 @@ public class DBRefUtils
           pdbr.setChainCode(chaincode);
           // pdbr.getProperty().put("CHAIN", chaincode);
           seq.addPDBId(pdbr);
-        } else {
-          System.err.println("Malformed PDB DR line:"+acn);
+        }
+        else
+        {
+          System.err.println("Malformed PDB DR line:" + acn);
         }
       }
       else
@@ -472,4 +473,36 @@ public class DBRefUtils
     return ref;
   }
 
+  /**
+   * Extract valid accession strings from a query string. Used by the
+   * SequenceFetcher and DBRefFetcher to create valid accession strings from an
+   * ID string for database sources with a Regex validation field.
+   * 
+   * @param proxy
+   * @param q
+   * @return q if proxy.getAccessionValidator()==null, otherwise the matched
+   *         region or the first subgroup match from the matched region
+   */
+  public static String processQueryToAccessionFor(DbSourceProxy proxy,
+          String q)
+  {
+    if (proxy.getAccessionValidator() != null)
+    {
+      Regex vgr = proxy.getAccessionValidator();
+      vgr.search(q);
+      if (vgr.numSubs() > 0)
+      {
+        return (vgr.stringMatched(1));
+      }
+      else
+      {
+        return (vgr.stringMatched());
+      }
+    }
+    else
+    {
+      return (q);
+    }
+  }
+
 }