JAL-3829 provide both PDBe queries and 3D-Beacons queries in the filter combo box
[jalview.git] / src / jalview / gui / structurechooser / StructureChooserQuerySource.java
index 9861b1a..c18a8a2 100644 (file)
@@ -1,29 +1,23 @@
 package jalview.gui.structurechooser;
 
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
-import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JTable;
 import javax.swing.table.TableModel;
 
 import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
 import jalview.fts.core.FTSDataColumnPreferences;
-import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
-import jalview.fts.service.pdb.PDBFTSRestClient;
-import jalview.jbgui.GStructureChooser.FilterOption;
+import jalview.jbgui.FilterOption;
 
 /**
  * logic for querying sources of structural data for structures of sequences
@@ -34,9 +28,6 @@ import jalview.jbgui.GStructureChooser.FilterOption;
  */
 public abstract class StructureChooserQuerySource
 {
-  protected FTSRestRequest lastPdbRequest;
-
-  protected FTSRestClientI pdbRestClient;
 
   protected FTSDataColumnPreferences docFieldPrefs;
 
@@ -176,6 +167,7 @@ public abstract class StructureChooserQuerySource
    * 
    * @param seq
    *          - seq to generate a query for
+   * @param discoveredStructuresSet - existing set of entries - allows client side selection
    * @param wantedFields
    *          - fields to retrieve
    * @param selectedFilterOpt
@@ -186,7 +178,7 @@ public abstract class StructureChooserQuerySource
    * @throws Exception
    */
   public abstract FTSRestResponse selectFirstRankedQuery(SequenceI seq,
-          Collection<FTSDataColumnI> wantedFields, String fieldToFilterBy,
+          Collection<FTSData> discoveredStructuresSet, Collection<FTSDataColumnI> wantedFields, String fieldToFilterBy,
           boolean b) throws Exception;
 
   /**
@@ -197,11 +189,60 @@ public abstract class StructureChooserQuerySource
   public TableModel getTableModel(
           Collection<FTSData> discoveredStructuresSet)
   {
-    return FTSRestResponse.getTableModel(lastPdbRequest,
+    return FTSRestResponse.getTableModel(getLastFTSRequest(),
             discoveredStructuresSet);
   }
 
+  protected abstract FTSRestRequest getLastFTSRequest();
+
   public abstract PDBEntry[] collectSelectedRows(JTable restable,
           int[] selectedRows, List<SequenceI> selectedSeqsToView);
 
+  /**
+   * @param VIEWS_FILTER
+   *          - a String key that can be used by the caller to tag the returned filter
+   *          options to distinguish them in a collection
+   * @return list of FilterOption - convention is that the last one in the list
+   *         will be constructed with 'addSeparator==true'
+   */
+  public abstract List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER);
+
+  /**
+   * construct a structure chooser query source for the given set of sequences
+   * @param selectedSeqs
+   * @return PDBe or 3DB query source
+   */
+  public static StructureChooserQuerySource getQuerySourceFor(
+          SequenceI[] selectedSeqs)
+  {
+    ThreeDBStructureChooserQuerySource tdbSource = new ThreeDBStructureChooserQuerySource();
+    boolean hasUniprot=false;
+    boolean hasNA=false,hasProtein=false;
+    for (SequenceI seq:selectedSeqs)
+    {
+      hasNA|=!seq.isProtein();
+      hasProtein |= seq.isProtein();
+      if (seq.isProtein())
+      {
+        String query = tdbSource.buildQuery(seq);
+        if (query!=null && query.length()>0)
+        {
+          hasUniprot=true;
+        }
+      }
+    }
+    if (hasProtein && hasUniprot && !hasNA)
+    {
+      return tdbSource;
+    }
+    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