From: Jim Procter Date: Fri, 10 Sep 2021 14:06:56 +0000 (+0100) Subject: JAL-3829 provide both PDBe queries and 3D-Beacons queries in the filter combo box X-Git-Tag: Release_2_11_2_0~39^2~7 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a35bdf653fe2f56b6600c57f53991a0191cb0032;p=jalview.git JAL-3829 provide both PDBe queries and 3D-Beacons queries in the filter combo box --- diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 55d0ba1..864f1d0 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -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) diff --git a/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java index 1c43bea..0f38e9f 100644 --- a/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java @@ -240,23 +240,30 @@ public class PDBStructureChooserQuerySource List filters = new ArrayList(); 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 diff --git a/src/jalview/gui/structurechooser/StructureChooserQuerySource.java b/src/jalview/gui/structurechooser/StructureChooserQuerySource.java index 6a1c64f..c18a8a2 100644 --- a/src/jalview/gui/structurechooser/StructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/StructureChooserQuerySource.java @@ -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 diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java index 2c6afe8..d64d643 100644 --- a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java @@ -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 getAvailableFilterOptions(String VIEWS_FILTER) { - List filters = new ArrayList(); - 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 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 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 filteredResponse = analyser.getFilteredResponse(); - - List selectedStructures = analyser.selectStructures(filteredResponse); - resultList.setNumberOfItemsFound(selectedStructures.size()); - resultList.setSearchSummary(selectedStructures); - return resultList; + List filteredResponse = analyser.getFilteredResponse(); + + List 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 selectedSeqsToView) diff --git a/src/jalview/jbgui/FilterOption.java b/src/jalview/jbgui/FilterOption.java index 042df23..d52dbbf 100644 --- a/src/jalview/jbgui/FilterOption.java +++ b/src/jalview/jbgui/FilterOption.java @@ -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