JAL-3829 provide both PDBe queries and 3D-Beacons queries in the filter combo box
authorJim Procter <j.procter@dundee.ac.uk>
Fri, 10 Sep 2021 14:06:56 +0000 (15:06 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Fri, 10 Sep 2021 14:06:56 +0000 (15:06 +0100)
src/jalview/gui/StructureChooser.java
src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java
src/jalview/gui/structurechooser/StructureChooserQuerySource.java
src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java
src/jalview/jbgui/FilterOption.java

index 55d0ba1..864f1d0 100644 (file)
@@ -466,16 +466,16 @@ public class StructureChooser extends GStructureChooser
     }
     cmb_filterOption.addItem(
             new FilterOption(MessageManager.getString("label.enter_pdb_id"),
-                    "-", VIEWS_ENTER_ID, false));
+                    "-", VIEWS_ENTER_ID, false,null));
     cmb_filterOption.addItem(
             new FilterOption(MessageManager.getString("label.from_file"),
-                    "-", VIEWS_FROM_FILE, false));
+                    "-", VIEWS_FROM_FILE, false,null));
 
     if (cachedPDBExist)
     {
       FilterOption cachedOption = new FilterOption(
               MessageManager.getString("label.cached_structures"), "-",
-              VIEWS_LOCAL_PDB, false);
+              VIEWS_LOCAL_PDB, false,null);
       cmb_filterOption.addItem(cachedOption);
       cmb_filterOption.setSelectedItem(cachedOption);
     }
@@ -499,7 +499,16 @@ public class StructureChooser extends GStructureChooser
     {
       mainFrame.setTitle(filterTitle);
       chk_invertFilter.setVisible(true);
-      filterResultSet(selectedFilterOpt.getValue());
+      
+      if (data!=selectedFilterOpt.getQuerySource() || data.needsRefetch(selectedFilterOpt)) 
+      {
+        data = selectedFilterOpt.getQuerySource();
+        // rebuild the views completely, since prefs will also change
+        tabRefresh();
+        return;
+      } else {
+        filterResultSet(selectedFilterOpt.getValue());
+      }
     }
     else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
             || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
index 1c43bea..0f38e9f 100644 (file)
@@ -240,23 +240,30 @@ public class PDBStructureChooserQuerySource
     List<FilterOption> filters = new ArrayList<FilterOption>();
     filters.add(new FilterOption(
             MessageManager.getString("label.best_quality"),
-            "overall_quality", VIEWS_FILTER, false));
+            "overall_quality", VIEWS_FILTER, false,this));
     filters.add(new FilterOption(
             MessageManager.getString("label.best_resolution"),
-            "resolution", VIEWS_FILTER, false));
+            "resolution", VIEWS_FILTER, false,this));
     filters.add(new FilterOption(
             MessageManager.getString("label.most_protein_chain"),
-            "number_of_protein_chains", VIEWS_FILTER, false));
+            "number_of_protein_chains", VIEWS_FILTER, false,this));
     filters.add(new FilterOption(
             MessageManager.getString("label.most_bound_molecules"),
-            "number_of_bound_molecules", VIEWS_FILTER, false));
+            "number_of_bound_molecules", VIEWS_FILTER, false,this));
     filters.add(new FilterOption(
             MessageManager.getString("label.most_polymer_residues"),
-            "number_of_polymer_residues", VIEWS_FILTER, true));
+            "number_of_polymer_residues", VIEWS_FILTER, true,this));
   
     return filters;
   }
 
+  @Override
+  public boolean needsRefetch(FilterOption selectedFilterOpt)
+  {
+    // PDBe queries never need a refetch first
+    return false;
+  }
+
   /**
    * FTSRestClient specific query builder to pick top ranked entry from a
    * fetchStructuresMetaData query
index 6a1c64f..c18a8a2 100644 (file)
@@ -238,4 +238,11 @@ public abstract class StructureChooserQuerySource
     return new PDBStructureChooserQuerySource();
   }
 
+  /**
+   * some filter options may mean the original query needs to be executed again. 
+   * @param selectedFilterOpt
+   * @return true if the fetchStructuresMetadata method needs to be called again
+   */
+  public abstract boolean needsRefetch(FilterOption selectedFilterOpt);
+
 }
\ No newline at end of file
index 2c6afe8..d64d643 100644 (file)
@@ -36,6 +36,8 @@ public class ThreeDBStructureChooserQuerySource
         extends StructureChooserQuerySource
 {
 
+  private static final String FILTER_TDBEACONS_COVERAGE = "3d_beacons_coverage";
+
   private static int MAX_QLENGTH = 7820;
 
   protected FTSRestRequest lastTdbRequest;
@@ -51,7 +53,7 @@ public class ThreeDBStructureChooserQuerySource
             PreferenceSource.STRUCTURE_CHOOSER,
             TDBeaconsFTSRestClient.getInstance());
 
-  }
+  }  
 
   /**
    * Builds a query string for a given sequences using its DBRef entries 3d
@@ -153,6 +155,7 @@ public class ThreeDBStructureChooserQuerySource
           FilterOption selectedFilterOpt, boolean b) throws Exception
   {
     FTSRestResponse resultList;
+    if (tdBeaconsFilter(selectedFilterOpt.getValue())) {
     FTSRestRequest tdbRequest = getTDBeaconsRequest(seq, wantedFields);
     resultList = tdbRestClient.executeRequest(tdbRequest);
 
@@ -163,6 +166,13 @@ public class ThreeDBStructureChooserQuerySource
     FTSRestResponse joinedResp = joinResponses(resultList,
             pdbResponse);
     return resultList;
+    } 
+    // use the PDBFTS directly
+    resultList = getPDBQuerySource().fetchStructuresMetaData(seq, wantedFields, selectedFilterOpt, b);
+    lastTdbRequest = getPDBQuerySource().lastPdbRequest;
+    lastPdbRequest = lastTdbRequest; // both queries the same - indicates we rank using PDBe
+    return resultList;
+    
   }
 
   PDBStructureChooserQuerySource pdbQuerySource=null;
@@ -195,26 +205,23 @@ public class ThreeDBStructureChooserQuerySource
   @Override
   public List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER)
   {
-    List<FilterOption> filters = new ArrayList<FilterOption>();
-    filters.add(
-            new FilterOption(MessageManager.getString("label.best_quality"),
-                    "overall_quality", VIEWS_FILTER, false));
-    filters.add(new FilterOption(
-            MessageManager.getString("label.best_resolution"), "resolution",
-            VIEWS_FILTER, false));
-    filters.add(new FilterOption(
-            MessageManager.getString("label.most_protein_chain"),
-            "number_of_protein_chains", VIEWS_FILTER, false));
-    filters.add(new FilterOption(
-            MessageManager.getString("label.most_bound_molecules"),
-            "number_of_bound_molecules", VIEWS_FILTER, false));
-    filters.add(new FilterOption(
-            MessageManager.getString("label.most_polymer_residues"),
-            "number_of_polymer_residues", VIEWS_FILTER, true));
-
+    List<FilterOption> filters = getPDBQuerySource().getAvailableFilterOptions(VIEWS_FILTER);
+    
+    filters.add(0,
+            new FilterOption("3D-Beacons Coverage",
+                    FILTER_TDBEACONS_COVERAGE, VIEWS_FILTER, true, this));
     return filters;
   }
+  private boolean tdBeaconsFilter(String fieldToFilterBy)
+  {
+    return FILTER_TDBEACONS_COVERAGE.equals(fieldToFilterBy);
+  }
 
+  @Override
+  public boolean needsRefetch(FilterOption selectedFilterOpt)
+  {
+    return tdBeaconsFilter(selectedFilterOpt.getValue()) && lastPdbRequest!=lastTdbRequest;
+  }
   /**
    * FTSRestClient specific query builder to pick top ranked entry from a
    * fetchStructuresMetaData query
@@ -235,20 +242,26 @@ public class ThreeDBStructureChooserQuerySource
           Collection<FTSDataColumnI> wantedFields, String fieldToFilterBy,
           boolean b) throws Exception
   {
+    if (tdBeaconsFilter(fieldToFilterBy))
+    {
+      TDBResultAnalyser analyser = new TDBResultAnalyser(seq,
+              collectedResults, lastTdbRequest);
 
-    TDBResultAnalyser analyser= new TDBResultAnalyser(seq,collectedResults, lastTdbRequest);
-    
-    
-    FTSRestResponse resultList = new FTSRestResponse();
+      FTSRestResponse resultList = new FTSRestResponse();
 
-    List<FTSData> filteredResponse = analyser.getFilteredResponse();
-    
-    List<FTSData> selectedStructures = analyser.selectStructures(filteredResponse);
-    resultList.setNumberOfItemsFound(selectedStructures.size());
-    resultList.setSearchSummary(selectedStructures);
-    return resultList;
+      List<FTSData> filteredResponse = analyser.getFilteredResponse();
+
+      List<FTSData> selectedStructures = analyser
+              .selectStructures(filteredResponse);
+      resultList.setNumberOfItemsFound(selectedStructures.size());
+      resultList.setSearchSummary(selectedStructures);
+      return resultList;
+    }
+    // Fall back to PDBe rankings
+    return getPDBQuerySource().selectFirstRankedQuery(seq, collectedResults, wantedFields, fieldToFilterBy, b);
   }
 
+
   @Override
   public PDBEntry[] collectSelectedRows(JTable restable, int[] selectedRows,
           List<SequenceI> selectedSeqsToView)
index 042df23..d52dbbf 100644 (file)
@@ -1,5 +1,8 @@
 package jalview.jbgui;
 
+import jalview.gui.structurechooser.StructureChooserQuerySource;
+import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
+
 /**
  * This inner class provides the data model for the structure filter combo-box
  * 
@@ -15,6 +18,8 @@ public class FilterOption
   private String view;
 
   private boolean addSeparatorAfter;
+  
+  private StructureChooserQuerySource querySource;
 
   /**
    * Model for structure filter option
@@ -28,13 +33,15 @@ public class FilterOption
    * @param addSeparatorAfter
    *          - if true, a horizontal separator is rendered immediately after
    *          this filter option, otherwise
+   * @param structureChooserQuerySource - the query source that actions this filter
    */
   public FilterOption(String name, String value, String view,
-          boolean addSeparatorAfter)
+          boolean addSeparatorAfter, StructureChooserQuerySource structureChooserQuerySource)
   {
     this.name = name;
     this.value = value;
     this.view = view;
+    this.querySource=structureChooserQuerySource;
     this.addSeparatorAfter = addSeparatorAfter;
   }
 
@@ -83,4 +90,9 @@ public class FilterOption
   {
     this.addSeparatorAfter = addSeparatorAfter;
   }
+
+  public StructureChooserQuerySource getQuerySource()
+  {
+    return querySource;
+  }
 }
\ No newline at end of file