add parsed PDB reference to sequences
authorjprocter <Jim Procter>
Wed, 24 Oct 2007 10:59:57 +0000 (10:59 +0000)
committerjprocter <Jim Procter>
Wed, 24 Oct 2007 10:59:57 +0000 (10:59 +0000)
src/jalview/io/StockholmFile.java
src/jalview/util/DBRefUtils.java

index d0d84f5..e7b1c6e 100644 (file)
@@ -31,9 +31,15 @@ import jalview.datamodel.*;
 \r
 /**\r
  * This class is supposed to parse a Stockholm format file into Jalview\r
- * \r
+ * There are TODOs in this class: we do not know what the database source and\r
+ * version is for the file when parsing the #GS= AC tag which associates accessions\r
+ * with sequences. \r
+ * Database references are also not parsed correctly: a separate reference string\r
+ * parser must be added to parse the database reference form into Jalview's local\r
+ * representation.\r
  * @author bsb at sanger.ac.uk\r
- * @version 0.3\r
+ * @version 0.3 + jalview mods\r
+ * \r
  */\r
 public class StockholmFile extends AlignFile\r
 {\r
@@ -158,9 +164,8 @@ public class StockholmFile extends AlignFile
             {\r
               String src = dbr.substring(0, dbr.indexOf(";"));\r
               String acn = dbr.substring(dbr.indexOf(";") + 1);\r
-              DBRefEntry dbref = new DBRefEntry(jalview.util.DBRefUtils\r
-                      .getCanonicalName(src), acn, "");\r
-              seqO.addDBRef(dbref);\r
+              jalview.util.DBRefUtils.parseToDbRef(seqO, src, "0", acn);\r
+              //seqO.addDBRef(dbref);\r
             }\r
           }\r
           Hashtable features = null;\r
index d94e234..49f04cb 100755 (executable)
@@ -339,6 +339,54 @@ public class DBRefUtils
             return false;
           }
     };
+    /**
+     * used by file parsers to generate DBRefs from annotation within file (eg stockholm)
+     * @param dbname
+     * @param version
+     * @param acn
+     * @param seq where to anotate 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 = jalview.util.DBRefUtils
+        .getCanonicalName(dbname);
+        if (locsrc.equals(jalview.datamodel.DBRefSource.PDB))
+        {
+          // check for chaincode and mapping
+          // PFAM style stockhom PDB citation
+          com.stevesoft.pat.Regex r = new com.stevesoft.pat.Regex("([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;([0-9]+)-([0-9]+)");
+          if (r.search(acn.trim()))
+          {
+            String pdbid = r.stringMatched(1);
+            String chaincode = r.stringMatched(2);
+            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);
+            seq.addPDBId(pdbr);
+          }
+        } else {
+          // default:
+          ref = new DBRefEntry(locsrc, version, acn);
+        }
+      }
+      if (ref!=null)
+      {
+        seq.addDBRef(ref);
+      }
+      return ref;
+    }
         
           
 }