JAL-3829 comments on the 3D structure chooser’s initialisation process
[jalview.git] / src / jalview / gui / StructureChooser.java
index ebba2e5..a83adcb 100644 (file)
@@ -35,9 +35,11 @@ import jalview.fts.core.FTSDataColumnPreferences;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.service.pdb.PDBFTSRestClient;
+import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
+import jalview.gui.structurechooser.StructureChooserQuerySource;
 import jalview.io.DataSourceType;
+import jalview.jbgui.FilterOption;
 import jalview.jbgui.GStructureChooser;
-import jalview.jbgui.GStructureChooser.FilterOption;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
@@ -102,7 +104,7 @@ public class StructureChooser extends GStructureChooser
   {
     // which FTS engine to use
     data = StructureChooserQuerySource
-            .getPDBfts();
+            .getQuerySourceFor(selectedSeqs);
     initDialog();
     
     this.ap = ap;
@@ -132,6 +134,14 @@ public class StructureChooser extends GStructureChooser
       @Override
       public void run()
       {
+        // looks for any existing structures already loaded 
+        // for the sequences (the cached ones) 
+        // then queries the StructureChooserQuerySource to 
+        // discover more structures.
+        // 
+        // Possible optimisation is to only begin querying
+        // the structure chooser if there are no cached structures.
+        
         long startTime = System.currentTimeMillis();
         updateProgressIndicator(MessageManager
                 .getString("status.loading_cached_pdb_entries"), startTime);
@@ -243,6 +253,12 @@ public class StructureChooser extends GStructureChooser
       {
         resultList = data.fetchStructuresMetaData(seq, wantedFields,
                 selectedFilterOpt, !chk_invertFilter.isSelected());
+        // null response means the FTSengine didn't yield a query for this
+        // consider designing a special exception if we really wanted to be OOCrazy
+        if (resultList==null)
+        {
+          continue;
+        }
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -442,21 +458,11 @@ public class StructureChooser extends GStructureChooser
     cmb_filterOption.removeAllItems();
     if (haveData)
     {
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.best_quality"),
-              "overall_quality", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.best_resolution"),
-              "resolution", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.most_protein_chain"),
-              "number_of_protein_chains", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.most_bound_molecules"),
-              "number_of_bound_molecules", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.most_polymer_residues"),
-              "number_of_polymer_residues", VIEWS_FILTER, true));
+      List<FilterOption> filters = data.getAvailableFilterOptions(VIEWS_FILTER);
+      for (FilterOption filter:filters)
+      {
+        cmb_filterOption.addItem(filter);
+      }
     }
     cmb_filterOption.addItem(
             new FilterOption(MessageManager.getString("label.enter_pdb_id"),
@@ -735,36 +741,11 @@ public class StructureChooser extends GStructureChooser
 
         if (currentView == VIEWS_FILTER)
         {
-          int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
-          int refSeqColIndex = restable.getColumn("Ref Sequence")
-                  .getModelIndex();
           int[] selectedRows = restable.getSelectedRows();
           PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
-          int count = 0;
           List<SequenceI> selectedSeqsToView = new ArrayList<>();
-          for (int row : selectedRows)
-          {
-            String pdbIdStr = restable.getValueAt(row, pdbIdColIndex)
-                    .toString();
-            SequenceI selectedSeq = (SequenceI) restable.getValueAt(row,
-                    refSeqColIndex);
-            selectedSeqsToView.add(selectedSeq);
-            PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
-            if (pdbEntry == null)
-            {
-              pdbEntry = getFindEntry(pdbIdStr,
-                      selectedSeq.getAllPDBEntries());
-            }
+          pdbEntriesToView = data.collectSelectedRows(restable,selectedRows,selectedSeqsToView);
 
-            if (pdbEntry == null)
-            {
-              pdbEntry = new PDBEntry();
-              pdbEntry.setId(pdbIdStr);
-              pdbEntry.setType(PDBEntry.Type.PDB);
-              selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
-            }
-            pdbEntriesToView[count++] = pdbEntry;
-          }
           SequenceI[] selectedSeqs = selectedSeqsToView
                   .toArray(new SequenceI[selectedSeqsToView.size()]);
           sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
@@ -872,21 +853,6 @@ public class StructureChooser extends GStructureChooser
     }
   }
 
-  private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
-  {
-    Objects.requireNonNull(id);
-    Objects.requireNonNull(pdbEntries);
-    PDBEntry foundEntry = null;
-    for (PDBEntry entry : pdbEntries)
-    {
-      if (entry.getId().equalsIgnoreCase(id))
-      {
-        return entry;
-      }
-    }
-    return foundEntry;
-  }
-
   /**
    * Answers a structure viewer (new or existing) configured to superimpose
    * added structures or not according to the user's choice