JAL-1717 updated the PDBEntry model and updated the method use for its equality test...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 30 Apr 2015 11:47:08 +0000 (12:47 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 30 Apr 2015 11:47:08 +0000 (12:47 +0100)
12 files changed:
help/html/features/pdbsequencefetcher.html
src/MCview/PDBfile.java
src/jalview/datamodel/PDBEntry.java
src/jalview/datamodel/Sequence.java
src/jalview/ext/jmol/PDBFileWithJmol.java
src/jalview/gui/AppJmol.java
src/jalview/gui/AssociatePdbFileWithSeq.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/Jalview2XML_V1.java
src/jalview/gui/StructureChooser.java
src/jalview/util/DBRefUtils.java
test/jalview/datamodel/PDBEntryTest.java [new file with mode: 0644]

index 0a7802e..15dc2c6 100644 (file)
                or to cross-reference other bioinformatics websites before retrieving
                a sequence data in jalview. The underlying technology is provided by
                EBI and is based on Apache Solr which is a text based search engine.</p>
-
        <p>
                The PDB Sequence Fetcher interface can be opened by selecting <strong>PDB</strong>
                as the choice database from the <strong>'Select Database
                        Retrieval Source'</strong> interface of <a href="seqfetch.html">Sequence
                        Fetcher</a>.
        </p>
-       <br>
-
-       <img src="pdbseqfetcher.png" align="left"
-               alt="PDB sequence fetcher (introduced in Jalview 2.x.x)">
-
-       <br>
        <p>
-               <strong>Searching the PDB Database</strong><br> Once the
-               interface is opened, typing in the search text box will execute a live
-               query to the PDB database and display the results on-the-fly as seen
-               in the screen-shot above. Use the drop-down menu to select a specific
-               field to search by in the PDB database, the default option is <strong>'ALL'</strong>.
-               Furthermore, the PDB search interface also provides the following
-               functionalities:
+               <img src="pdbseqfetcher.png" align="left"
+                       alt="PDB sequence fetcher (introduced in Jalview 2.x.x)">
+       </p>
+
+       <strong>Searching the PDB Database</strong>
+       <br> Once the interface is opened, typing in the search text box
+       will execute a live query to the PDB database and display the results
+       on-the-fly as seen in the screen-shot above. Use the drop-down menu to
+       select a specific field to search by in the PDB database, the default
+       option is
+       <strong>'ALL'</strong>. Furthermore, the PDB search interface also
+       provides the following functionalities:
        <ul>
                <li>Retrieving a unique chain for a PDB entry: <br>To
                        retrieve a specific chain for a PDB entry, append the PDB ID with a
index 3a56ea6..940e27b 100755 (executable)
@@ -195,7 +195,8 @@ public class PDBfile extends jalview.io.AlignFile
         entry.setProperty(new Hashtable());
         if (chains.elementAt(i).id != null)
         {
-          entry.getProperty().put("CHAIN", chains.elementAt(i).id);
+          // entry.getProperty().put("CHAIN", chains.elementAt(i).id);
+          entry.setChainCode(String.valueOf(chains.elementAt(i).id));
         }
         if (inFile != null)
         {
index 3627d6d..0050666 100755 (executable)
@@ -24,12 +24,18 @@ import java.util.Hashtable;
 
 public class PDBEntry
 {
-  String file;
+  private String file;
 
-  String type;
+  private String type;
 
-  String id;
+  private String id;
 
+  private String chainCode;
+
+  public enum Type
+  {
+    PDB, FILE
+  }
   Hashtable properties;
 
   /*
@@ -49,12 +55,17 @@ public class PDBEntry
       return true;
     }
     PDBEntry o = (PDBEntry) obj;
-    return (file == o.file || (file != null && o.file != null && o.file
-            .equals(file)))
-            && (type == o.type || (type != null && o.type != null && o.type
+    return /*
+            * (file == o.file || (file != null && o.file != null && o.file
+            * .equals(file))) &&
+            */
+    (type == o.type || (type != null && o.type != null && o.type
                     .equals(type)))
             && (id == o.id || (id != null && o.id != null && o.id
                     .equalsIgnoreCase(id)))
+            && (chainCode == o.chainCode || (chainCode != null
+                    && o.chainCode != null && o.chainCode
+                      .equalsIgnoreCase(chainCode)))
             && (properties == o.properties || (properties != null
                     && o.properties != null && properties
                       .equals(o.properties)));
@@ -72,12 +83,21 @@ public class PDBEntry
    * 
    * @param filePath
    */
-  public PDBEntry(String filePath, String pdbId)
+  // public PDBEntry(String filePath, String pdbId)
+  // {
+  // this.file = filePath;
+  // this.id = pdbId;
+  // }
+  
+  public PDBEntry(String pdbId, String chain, PDBEntry.Type type,
+          String filePath)
   {
-    this.file = filePath;
     this.id = pdbId;
+    this.chainCode = chain;
+    this.type = type.toString();
+    this.file = filePath;
   }
-  
+
   /**
    * Copy constructor.
    * 
@@ -88,6 +108,7 @@ public class PDBEntry
     file = entry.file;
     type = entry.type;
     id = entry.id;
+    chainCode = entry.chainCode;
     if (entry.properties != null)
     {
       properties = (Hashtable) entry.properties.clone();
@@ -104,9 +125,9 @@ public class PDBEntry
     return file;
   }
 
-  public void setType(String type)
+  public void setType(PDBEntry.Type type)
   {
-    this.type = type;
+    this.type = type.toString();
   }
 
   public String getType()
@@ -134,4 +155,14 @@ public class PDBEntry
     return properties;
   }
 
+  public String getChainCode()
+  {
+    return chainCode;
+  }
+
+  public void setChainCode(String chainCode)
+  {
+    this.chainCode = chainCode;
+  }
+
 }
index 65d8179..9cec370 100755 (executable)
@@ -20,6 +20,9 @@
  */
 package jalview.datamodel;
 
+import jalview.analysis.AlignSeq;
+import jalview.util.StringUtils;
+
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
@@ -27,9 +30,6 @@ import java.util.Vector;
 
 import fr.orsay.lri.varna.models.rna.RNA;
 
-import jalview.analysis.AlignSeq;
-import jalview.util.StringUtils;
-
 /**
  * 
  * Implements the SequenceI interface for a char[] based sequence object.
@@ -355,12 +355,24 @@ public class Sequence implements SequenceI
     {
       pdbIds = new Vector<PDBEntry>();
     }
-    if (!pdbIds.contains(entry))
+    if (pdbIds.contains(entry))
+    {
+      updatePDBEntry(pdbIds.get(pdbIds.indexOf(entry)), entry);
+    }
+    else
     {
       pdbIds.addElement(entry);
     }
   }
 
+  private static void updatePDBEntry(PDBEntry oldEntry, PDBEntry newEntry)
+  {
+    if (newEntry.getFile() != null)
+    {
+      oldEntry.setFile(newEntry.getFile());
+    }
+  }
+
   /**
    * DOCUMENT ME!
    * 
index 7fe8428..bbf90ac 100644 (file)
@@ -179,7 +179,8 @@ public class PDBFileWithJmol extends AlignFile implements
                   pdbe.setId(getDataName());
                   sq.addPDBId(pdbe);
                   pdbe.setProperty(new Hashtable());
-                  pdbe.getProperty().put("CHAIN", "" + _lastChainId);
+                  // pdbe.getProperty().put("CHAIN", "" + _lastChainId);
+                  pdbe.setChainCode(String.valueOf(_lastChainId));
                   // JAL-1533
                   // Need to put the number of models for this polymer somewhere for Chimera/others to grab
                   //                  pdbe.getProperty().put("PDBMODELS", biopoly.)
index 04235be..2180d07 100644 (file)
  */
 package jalview.gui;
 
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.PurinePyrimidineColourScheme;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TaylorColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.schemes.ZappoColourScheme;
+import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -51,28 +73,6 @@ import javax.swing.event.InternalFrameEvent;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
-import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.ZappoColourScheme;
-import jalview.structures.models.AAStructureBindingModel;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-
 public class AppJmol extends StructureViewerBase
 {
   AppJmolBinding jmb;
@@ -147,7 +147,9 @@ public class AppJmol extends StructureViewerBase
     PDBEntry[] pdbentrys = new PDBEntry[files.length];
     for (int i = 0; i < pdbentrys.length; i++)
     {
-      PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
+      // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
+      PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
+              files[i]);
       pdbentrys[i] = pdbentry;
     }
     // / TODO: check if protocol is needed to be set, and if chains are
@@ -666,8 +668,8 @@ public class AppJmol extends StructureViewerBase
           {
             // just transfer the file name from the first sequence's first
             // PDBEntry
-            file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
-                    .elementAt(0)).getFile()).getAbsolutePath();
+            file = new File(pdbseq.getSequenceAt(0).getPDBId()
+                    .elementAt(0).getFile()).getAbsolutePath();
             jmb.getPdbEntry(pi).setFile(file);
 
             files.append(" \"" + Platform.escapeString(file) + "\"");
index d53ddc8..7e646e2 100644 (file)
@@ -80,6 +80,7 @@ public class AssociatePdbFileWithSeq
     {
       entry.setId(pdbfile.id);
     }
+    entry.setType(PDBEntry.Type.FILE);
 
     if (pdbfile != null)
     {
index 8e77111..f56e531 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.Rectangle;
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-
-import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
-import org.exolab.castor.xml.Unmarshaller;
-
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignedCodonFrame;
@@ -121,6 +83,44 @@ import jalview.ws.params.ArgumentI;
 import jalview.ws.params.AutoCalcSetting;
 import jalview.ws.params.WsParamSetI;
 
+import java.awt.Rectangle;
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+import org.exolab.castor.xml.Unmarshaller;
+
 /**
  * Write out the current jalview desktop state as a Jalview XML stream.
  * 
@@ -2544,7 +2544,17 @@ public class Jalview2XML
           {
             jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
             entry.setId(ids[p].getId());
-            entry.setType(ids[p].getType());
+            if (ids[p].getType() != null)
+            {
+              if (ids[p].getType().equalsIgnoreCase("PDB"))
+              {
+                entry.setType(PDBEntry.Type.PDB);
+              }
+              else
+              {
+                entry.setType(PDBEntry.Type.FILE);
+              }
+            }
             if (ids[p].getFile() != null)
             {
               if (!pdbloaded.containsKey(ids[p].getFile()))
@@ -3310,7 +3320,8 @@ public class Jalview2XML
       {
         String filePath = pdb.getValue().getFilePath();
         String pdbId = pdb.getValue().getPdbId();
-        pdbs.add(new PDBEntry(filePath, pdbId));
+        // pdbs.add(new PDBEntry(filePath, pdbId));
+        pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
         final List<SequenceI> seqList = pdb.getValue().getSeqList();
         SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
         allseqs.add(seqs);
index ef01a50..cb572cd 100755 (executable)
@@ -34,6 +34,7 @@ import jalview.binding.Setting;
 import jalview.binding.Tree;
 import jalview.binding.UserColours;
 import jalview.binding.Viewport;
+import jalview.datamodel.PDBEntry;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.ResidueProperties;
@@ -240,7 +241,17 @@ public class Jalview2XML_V1
         {
           jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
           entry.setId(ids[p].getId());
-          entry.setType(ids[p].getType());
+          if (ids[p].getType() != null)
+          {
+            if (ids[p].getType().equalsIgnoreCase("PDB"))
+            {
+              entry.setType(PDBEntry.Type.PDB);
+            }
+            else
+            {
+              entry.setType(PDBEntry.Type.FILE);
+            }
+          }
           al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
           StructureSelectionManager.getStructureSelectionManager(
                   Desktop.instance).registerPDBEntry(entry);
index cd4faf6..358412d 100644 (file)
@@ -179,6 +179,7 @@ public class StructureChooser extends GStructureChooser
     DefaultTableModel tableModel = new DefaultTableModel();
     tableModel.addColumn("Sequence");
     tableModel.addColumn("PDB Id");
+    tableModel.addColumn("Chain");
     tableModel.addColumn("Type");
     tableModel.addColumn("File");
     cachedEntryMap = new Hashtable<String, PDBEntry>();
@@ -189,8 +190,12 @@ public class StructureChooser extends GStructureChooser
       {
         for (PDBEntry pdbEntry : seq.getDatasetSequence().getPDBId())
         {
+          String chain = pdbEntry.getChainCode() == null ? "_" : pdbEntry
+                  .getChainCode();
           String[] pdbEntryRowData = new String[]
-          { seq.getDisplayId(false), pdbEntry.getId(), pdbEntry.getType(),
+          { seq.getDisplayId(false), pdbEntry.getId(),
+ chain,
+              pdbEntry.getType(),
               pdbEntry.getFile() };
           tableModel.addRow(pdbEntryRowData);
           cachedEntryMap.put(seq.getDisplayId(false) + pdbEntry.getId(),
@@ -217,7 +222,7 @@ public class StructureChooser extends GStructureChooser
     {
       PDBEntry newEntry = new PDBEntry();
       newEntry.setId(response.getPdbId());
-      newEntry.setType("PDB");
+      newEntry.setType(PDBEntry.Type.PDB);
       seq.getDatasetSequence().addPDBId(newEntry);
     }
   }
@@ -597,7 +602,7 @@ public class StructureChooser extends GStructureChooser
                 .toString();
         PDBEntry pdbEntry = new PDBEntry();
         pdbEntry.setId(pdbIdStr);
-        pdbEntry.setType("PDB");
+        pdbEntry.setType(PDBEntry.Type.PDB);
         pdbEntriesToView[count++] = pdbEntry;
       }
 
@@ -626,7 +631,7 @@ public class StructureChooser extends GStructureChooser
       }
       PDBEntry pdbEntry = new PDBEntry();
       pdbEntry.setId(txt_search.getText());
-      pdbEntry.setType("PDB");
+      pdbEntry.setType(PDBEntry.Type.PDB);
       selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
       PDBEntry[] pdbEntriesToView = new PDBEntry[]
       { pdbEntry };
index 9765a1a..123a4e1 100755 (executable)
  */
 package jalview.util;
 
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -28,11 +33,6 @@ import java.util.Map;
 
 import com.stevesoft.pat.Regex;
 
-import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.SequenceI;
-
 public class DBRefUtils
 {
   private static Map<String, String> canonicalSourceNameLookup = new HashMap<String, String>();
@@ -450,8 +450,10 @@ public class DBRefUtils
           ref = new DBRefEntry(locsrc, version, pdbid + chaincode);
           PDBEntry pdbr = new PDBEntry();
           pdbr.setId(pdbid);
+          pdbr.setType(PDBEntry.Type.PDB);
           pdbr.setProperty(new Hashtable());
-          pdbr.getProperty().put("CHAIN", chaincode);
+          pdbr.setChainCode(chaincode);
+          // pdbr.getProperty().put("CHAIN", chaincode);
           seq.addPDBId(pdbr);
         } else {
           System.err.println("Malformed PDB DR line:"+acn);
diff --git a/test/jalview/datamodel/PDBEntryTest.java b/test/jalview/datamodel/PDBEntryTest.java
new file mode 100644 (file)
index 0000000..5c597c0
--- /dev/null
@@ -0,0 +1,61 @@
+package jalview.datamodel;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PDBEntryTest
+{
+
+  @Before
+  public void setUp() throws Exception
+  {
+  }
+
+  @After
+  public void tearDown() throws Exception
+  {
+  }
+
+  @Test
+  public void test()
+  {
+    PDBEntry pdbEntry = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB,
+            "x/y/z/File");
+
+    PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB,
+            "x/y/z/File");
+    PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB,
+            "x/y/z/File");
+    PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE,
+            "x/y/z/File");
+    PDBEntry case4 = new PDBEntry(null, null, null, null);
+    PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB,
+            "x/y/z/File");
+    PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
+            "x/y/z/File");
+    PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
+    PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
+
+    System.out.println(">>>> Testing case 1");
+    assertTrue(pdbEntry.equals(case1));
+    System.out.println(">>>> Testing case 2");
+    assertTrue(pdbEntry.equals(case2));
+    System.out.println(">>>> Testing case 3");
+    assertTrue(!pdbEntry.equals(case3));
+    System.out.println(">>>> Testing case 4");
+    assertTrue(!pdbEntry.equals(case4));
+    System.out.println(">>>> Testing case 5");
+    assertTrue(!pdbEntry.equals(case5));
+    System.out.println(">>>> Testing case 6");
+    assertTrue(!pdbEntry.equals(case6));
+    System.out.println(">>>> Testing case 7");
+    assertTrue(!pdbEntry.equals(case7));
+    System.out.println(">>>> Testing case 8");
+    assertTrue(pdbEntry.equals(case8));
+
+  }
+
+}