JAL 1960 added code to restrict structure chooser to discover only PDB and Uniprot...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 10 Nov 2015 12:00:59 +0000 (12:00 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 10 Nov 2015 12:00:59 +0000 (12:00 +0000)
src/jalview/gui/StructureChooser.java

index 2a7da57..3df7e0c 100644 (file)
@@ -22,6 +22,7 @@
 package jalview.gui;
 
 import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.jbgui.GStructureChooser;
@@ -145,7 +146,7 @@ public class StructureChooser extends GStructureChooser
       PDBRestRequest pdbRequest = new PDBRestRequest();
       pdbRequest.setAllowEmptySeq(false);
       pdbRequest.setResponseSize(500);
-      pdbRequest.setFieldToSearchBy("(text:");
+      pdbRequest.setFieldToSearchBy("(");
       pdbRequest.setWantedFields(wantedFields);
       pdbRequest.setSearchTerm(buildQuery(seq) + ")");
       pdbRequest.setAssociatedSequence(seq);
@@ -233,18 +234,10 @@ public class StructureChooser extends GStructureChooser
 
   public static String buildQuery(SequenceI seq)
   {
+    boolean isPDBRefsFound = false;
+    boolean isUniProtRefsFound = false;
+    StringBuilder queryBuilder = new StringBuilder();
     HashSet<String> seqRefs = new LinkedHashSet<String>();
-    String seqName = seq.getName();
-    String[] names = seqName.toLowerCase().split("\\|");
-    for (String name : names)
-    {
-      // System.out.println("Found name : " + name);
-      name.trim();
-      if (isValidSeqName(name))
-      {
-        seqRefs.add(name);
-      }
-    }
 
     if (seq.getAllPDBEntries() != null)
     {
@@ -252,40 +245,77 @@ public class StructureChooser extends GStructureChooser
       {
         if (isValidSeqName(entry.getId()))
         {
-          seqRefs.add(entry.getId());
+          queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
+                  .append(":")
+.append(entry.getId().toLowerCase())
+                  .append(" OR ");
+          isPDBRefsFound = true;
+          // seqRefs.add(entry.getId());
         }
       }
     }
 
     if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
     {
-      int count = 0;
       for (DBRefEntry dbRef : seq.getDBRefs())
       {
         if (isValidSeqName(getDBRefId(dbRef)))
         {
-          seqRefs.add(getDBRefId(dbRef));
-        }
-        ++count;
-        if (count > 10)
-        {
-          break;
+          if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
+          {
+            queryBuilder
+                    .append(PDBRestClient.PDBDocField.UNIPROT_ACCESSION
+                            .getCode()).append(":")
+                    .append(getDBRefId(dbRef))
+                    .append(" OR ");
+            queryBuilder
+                    .append(PDBRestClient.PDBDocField.UNIPROT_ID.getCode())
+                    .append(":")
+                    .append(getDBRefId(dbRef)).append(" OR ");
+            isUniProtRefsFound = true;
+          }
+          else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
+          {
+
+            queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
+                    .append(":").append(getDBRefId(dbRef).toLowerCase())
+                    .append(" OR ");
+            isPDBRefsFound = true;
+          }
+          else
+          {
+            seqRefs.add(getDBRefId(dbRef));
+          }
         }
       }
     }
 
-    StringBuilder queryBuilder = new StringBuilder();
-    for (String seqRef : seqRefs)
+    if (!isPDBRefsFound && !isUniProtRefsFound)
     {
-      queryBuilder.append("text:").append(seqRef).append(" OR ");
+      String seqName = seq.getName();
+      String[] names = seqName.toLowerCase().split("\\|");
+      for (String name : names)
+      {
+        // System.out.println("Found name : " + name);
+        name.trim();
+        if (isValidSeqName(name))
+        {
+          seqRefs.add(name);
+        }
+      }
+
+      for (String seqRef : seqRefs)
+      {
+        queryBuilder.append("text:").append(seqRef).append(" OR ");
+      }
     }
-    int endIndex = queryBuilder.lastIndexOf(" OR ");
 
+    int endIndex = queryBuilder.lastIndexOf(" OR ");
     if (queryBuilder.toString().length() < 6)
     {
       return null;
     }
-    String query = queryBuilder.toString().substring(5, endIndex);
+    String query = queryBuilder.toString().substring(0, endIndex);
     return query;
   }
 
@@ -349,7 +379,7 @@ public class StructureChooser extends GStructureChooser
           PDBRestRequest pdbRequest = new PDBRestRequest();
           pdbRequest.setAllowEmptySeq(false);
           pdbRequest.setResponseSize(1);
-          pdbRequest.setFieldToSearchBy("(text:");
+          pdbRequest.setFieldToSearchBy("(");
           pdbRequest.setFieldToSortBy(fieldToFilterBy,
                   !chk_invertFilter.isSelected());
           pdbRequest.setSearchTerm(buildQuery(seq) + ")");
@@ -420,6 +450,7 @@ public class StructureChooser extends GStructureChooser
   /**
    * Handles action event for btn_pdbFromFile
    */
+  @Override
   public void pdbFromFile_actionPerformed()
   {
     jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
@@ -445,6 +476,7 @@ public class StructureChooser extends GStructureChooser
    * Populates the filter combo-box options dynamically depending on discovered
    * structures
    */
+  @Override
   protected void populateFilterComboBox()
   {
     if (isStructuresDiscovered())
@@ -473,6 +505,7 @@ public class StructureChooser extends GStructureChooser
   /**
    * Updates the displayed view based on the selected filter option
    */
+  @Override
   protected void updateCurrentView()
   {
     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
@@ -503,6 +536,7 @@ public class StructureChooser extends GStructureChooser
    * Validates user selection and activates the view button if all parameters
    * are correct
    */
+  @Override
   public void validateSelections()
   {
     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
@@ -744,6 +778,7 @@ public class StructureChooser extends GStructureChooser
     final StructureViewer sViewer = new StructureViewer(ssm);
     new Thread(new Runnable()
     {
+      @Override
       public void run()
       {
         if (pdbEntriesToView.length > 1)
@@ -768,6 +803,7 @@ public class StructureChooser extends GStructureChooser
    * Populates the combo-box used in associating manually fetched structures to
    * a unique sequence when more than one sequence selection is made.
    */
+  @Override
   public void populateCmbAssociateSeqOptions(
           JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
   {
@@ -812,6 +848,7 @@ public class StructureChooser extends GStructureChooser
   {
     new Thread()
     {
+      @Override
       public void run()
       {
         errorWarning.setLength(0);