JAL-1705 lenient DBRef matcher added (accession id only)
[jalview.git] / src / jalview / util / DBRefUtils.java
index e7053ed..424d40b 100755 (executable)
@@ -169,6 +169,25 @@ public class DBRefUtils
   }
 
   /**
+   * Returns an array of those references that match the given accession id
+   * <ul>
+   * <li>database sources are the same</li>
+   * <li>accession ids are the same</li>
+   * <li>both have no mapping, or the mappings are the same</li>
+   * </ul>
+   * 
+   * @param ref
+   *          Set of references to search
+   * @param entry
+   *          pattern to match
+   * @return
+   */
+  public static DBRefEntry[] searchRefs(DBRefEntry[] ref, String accId)
+  {
+    return searchRefs(ref, new DBRefEntry("", "", accId), matchId);
+  }
+
+  /**
    * Returns an array of those references that match the given entry, according
    * to the given comparator. Returns null if no matches.
    * 
@@ -397,6 +416,23 @@ public class DBRefUtils
   };
 
   /**
+   * accession ID only must be identical.
+   */
+  public static DbRefComp matchId = new DbRefComp()
+  {
+    @Override
+    public boolean matches(DBRefEntry refa, DBRefEntry refb)
+    {
+      if (refa.getAccessionId() != null && refb.getAccessionId() != null
+              && refb.getAccessionId().equals(refa.getAccessionId()))
+      {
+        return true;
+      }
+      return false;
+    }
+  };
+
+  /**
    * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the
    * database is PDB.
    * <p>