Merge branch 'Jalview-JS/develop' into develop
[jalview.git] / src / jalview / util / DBRefUtils.java
index fb54bba..ae0243e 100755 (executable)
  */
 package jalview.util;
 
-import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
-import jalview.datamodel.Mapping;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.SequenceI;
-
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import com.stevesoft.pat.Regex;
 
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.Mapping;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+
 /**
  * Utilities for handling DBRef objects and their collections.
  */
@@ -308,6 +307,75 @@ public class DBRefUtils
 
        };
 
+  /**
+   * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the
+   * database is PDB.
+   * <p>
+   * Used by file parsers to generate DBRefs from annotation within file (eg
+   * Stockholm)
+   * 
+   * @param dbname
+   * @param version
+   * @param acn
+   * @param seq
+   *          where to annotate with reference
+   * @return parsed version of entry that was added to seq (if any)
+   */
+  public static DBRefEntry parseToDbRef(SequenceI seq, String dbname,
+          String version, String acn)
+  {
+    DBRefEntry ref = null;
+    if (dbname != null)
+    {
+      String locsrc = DBRefUtils.getCanonicalName(dbname);
+      if (locsrc.equals(DBRefSource.PDB))
+      {
+        /*
+         * Check for PFAM style stockhom PDB accession id citation e.g.
+         * "1WRI A; 7-80;"
+         */
+        Regex r = new com.stevesoft.pat.Regex(
+                "([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)");
+        if (r.search(acn.trim()))
+        {
+          String pdbid = r.stringMatched(1);
+          String chaincode = r.stringMatched(2);
+          if (chaincode == null)
+          {
+            chaincode = " ";
+          }
+          // String mapstart = r.stringMatched(3);
+          // String mapend = r.stringMatched(4);
+          if (chaincode.equals(" "))
+          {
+            chaincode = "_";
+          }
+          // construct pdb ref.
+          ref = new DBRefEntry(locsrc, version, pdbid + chaincode);
+          PDBEntry pdbr = new PDBEntry();
+          pdbr.setId(pdbid);
+          pdbr.setType(PDBEntry.Type.PDB);
+          pdbr.setChainCode(chaincode);
+          seq.addPDBId(pdbr);
+        }
+        else
+        {
+          System.err.println("Malformed PDB DR line:" + acn);
+        }
+      }
+      else
+      {
+        // default:
+        ref = new DBRefEntry(locsrc, version, acn.trim());
+      }
+    }
+    if (ref != null)
+    {
+      seq.addDBRef(ref);
+    }
+    return ref;
+  }
+
        /**
         * accession ID and DB must be identical. Version is ignored. Map is either not
         * defined or is a match (or is compatible?)
@@ -451,60 +519,6 @@ public class DBRefUtils
   }
 
        /**
-        * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the
-        * database is PDB.
-        * <p>
-        * Used by file parsers to generate DBRefs from annotation within file (eg
-        * Stockholm)
-        * 
-        * @param dbname
-        * @param version
-        * @param acn
-        * @param seq     where to annotate with reference
-        * @return parsed version of entry that was added to seq (if any)
-        */
-       public static DBRefEntry parseToDbRef(SequenceI seq, String dbname, String version, String acn) {
-               DBRefEntry ref = null;
-               if (dbname != null) {
-                       String locsrc = DBRefUtils.getCanonicalName(dbname);
-                       if (locsrc.equals(DBRefSource.PDB)) {
-                               /*
-                                * Check for PFAM style stockhom PDB accession id citation e.g. "1WRI A; 7-80;"
-                                */
-                               Regex r = new com.stevesoft.pat.Regex("([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)");
-                               if (r.search(acn.trim())) {
-                                       String pdbid = r.stringMatched(1);
-                                       String chaincode = r.stringMatched(2);
-                                       if (chaincode == null) {
-                                               chaincode = " ";
-                                       }
-                                       // String mapstart = r.stringMatched(3);
-                                       // String mapend = r.stringMatched(4);
-                                       if (chaincode.equals(" ")) {
-                                               chaincode = "_";
-                                       }
-                                       // construct pdb ref.
-                                       ref = new DBRefEntry(locsrc, version, pdbid + chaincode);
-                                       PDBEntry pdbr = new PDBEntry();
-                                       pdbr.setId(pdbid);
-                                       pdbr.setType(PDBEntry.Type.PDB);
-                                       pdbr.setChainCode(chaincode);
-                                       seq.addPDBId(pdbr);
-                               } else {
-                                       System.err.println("Malformed PDB DR line:" + acn);
-                               }
-                       } else {
-                               // default:
-                               ref = new DBRefEntry(locsrc, version, acn);
-                       }
-               }
-               if (ref != null) {
-                       seq.addDBRef(ref);
-               }
-               return ref;
-       }
-
-       /**
         * Returns true if either object is null, or they are equal
         * 
         * @param o1