JAL-1705 refactored code for dbsource reggae validator and added further refactoring...
[jalview.git] / src / jalview / util / DBRefUtils.java
index 123a4e1..d2be021 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;
@@ -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);
+    }
+  }
+
 }