From e6438a4c2df8713e8acc65b1625f7446b6e76416 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Mon, 22 Feb 2016 17:12:36 +0000 Subject: [PATCH] JAL-1720 JAL-2002 improvement for 'uniprot coverage' filter using facet pivot query --- src/jalview/gui/StructureChooser.java | 32 +++++++++++++++++------ src/jalview/ws/dbsources/PDBRestClient.java | 33 +++++++++++++++++++----- src/jalview/ws/uimodel/PDBRestRequest.java | 37 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 14 deletions(-) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index cf58322..7d0d76a 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -385,14 +385,30 @@ public class StructureChooser extends GStructureChooser implements for (SequenceI seq : selectedSequences) { PDBRestRequest pdbRequest = new PDBRestRequest(); - pdbRequest.setAllowEmptySeq(false); - pdbRequest.setResponseSize(1); - pdbRequest.setFieldToSearchBy("("); - pdbRequest.setFieldToSortBy(fieldToFilterBy, - !chk_invertFilter.isSelected()); - pdbRequest.setSearchTerm(buildQuery(seq) + ")"); - pdbRequest.setWantedFields(wantedFields); - pdbRequest.setAssociatedSequence(seq); + if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage")) + { + System.out.println(">>>>>> Filtering with uniprot coverate"); + pdbRequest.setAllowEmptySeq(false); + pdbRequest.setResponseSize(1); + pdbRequest.setFieldToSearchBy("("); + pdbRequest.setSearchTerm(buildQuery(seq) + ")"); + pdbRequest.setWantedFields(wantedFields); + pdbRequest.setAssociatedSequence(seq); + pdbRequest.setFacet(true); + pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity"); + pdbRequest.setFacetPivotMinCount(1); + } + else + { + pdbRequest.setAllowEmptySeq(false); + pdbRequest.setResponseSize(1); + pdbRequest.setFieldToSearchBy("("); + pdbRequest.setFieldToSortBy(fieldToFilterBy, + !chk_invertFilter.isSelected()); + pdbRequest.setSearchTerm(buildQuery(seq) + ")"); + pdbRequest.setWantedFields(wantedFields); + pdbRequest.setAssociatedSequence(seq); + } pdbRestCleint = new PDBRestClient(); PDBRestResponse resultList; try diff --git a/src/jalview/ws/dbsources/PDBRestClient.java b/src/jalview/ws/dbsources/PDBRestClient.java index c6251a6..2c05acd 100644 --- a/src/jalview/ws/dbsources/PDBRestClient.java +++ b/src/jalview/ws/dbsources/PDBRestClient.java @@ -79,19 +79,39 @@ public class PDBRestClient .getFieldToSortBy().trim().isEmpty()) ? "" : (pdbRestRequest .getFieldToSortBy() + (pdbRestRequest.isAscending() ? " asc" : " desc")); + String facetPivot = (pdbRestRequest.getFacetPivot() == null || pdbRestRequest + .getFacetPivot().isEmpty()) ? "" : pdbRestRequest + .getFacetPivot(); + String facetPivotMinCount = String.valueOf(pdbRestRequest + .getFacetPivotMinCount()); + // Build request parameters for the REST Request - WebResource webResource = client.resource(PDB_SEARCH_ENDPOINT) - .queryParam("wt", "json").queryParam("fl", wantedFields) - .queryParam("rows", String.valueOf(responseSize)) - .queryParam("q", pdbRestRequest.getQuery()) - .queryParam("sort", sortParam); - + WebResource webResource = null; + if (pdbRestRequest.isFacet()) + { + webResource = client.resource(PDB_SEARCH_ENDPOINT) + .queryParam("wt", "json").queryParam("fl", wantedFields) + .queryParam("rows", String.valueOf(responseSize)) + .queryParam("q", pdbRestRequest.getQuery()) + .queryParam("sort", sortParam).queryParam("facet", "true") + .queryParam("facet.pivot", facetPivot) + .queryParam("facet.pivot.mincount", facetPivotMinCount); + } + else + { + webResource = client.resource(PDB_SEARCH_ENDPOINT) + .queryParam("wt", "json").queryParam("fl", wantedFields) + .queryParam("rows", String.valueOf(responseSize)) + .queryParam("q", pdbRestRequest.getQuery()) + .queryParam("sort", sortParam); + } // Execute the REST request ClientResponse clientResponse = webResource.accept( MediaType.APPLICATION_JSON).get(ClientResponse.class); // Get the JSON string from the response object String responseString = clientResponse.getEntity(String.class); + System.out.println("query >>>>>>> " + pdbRestRequest.toString()); // Check the response status and report exception if one occurs if (clientResponse.getStatus() != 200) @@ -414,6 +434,7 @@ public class PDBRestClient return code; } + @Override public String toString() { return name; diff --git a/src/jalview/ws/uimodel/PDBRestRequest.java b/src/jalview/ws/uimodel/PDBRestRequest.java index 24f38d1..7bfc226 100644 --- a/src/jalview/ws/uimodel/PDBRestRequest.java +++ b/src/jalview/ws/uimodel/PDBRestRequest.java @@ -48,6 +48,12 @@ public class PDBRestRequest private boolean allowUnpublishedEntries = Cache.getDefault( "ALLOW_UNPUBLISHED_PDB_QUERYING", false); + private boolean facet; + + private String facetPivot; + + private int facetPivotMinCount; + private int responseSize; private boolean isSortAscending; @@ -137,6 +143,7 @@ public class PDBRestRequest + (isAllowUnpublishedEntries() ? "" : " AND status:REL"); } + @Override public String toString() { return "Query : " + getQuery() + " sort field: " + fieldToSortBy @@ -153,4 +160,34 @@ public class PDBRestRequest { this.allowUnpublishedEntries = allowUnpublishedEntries; } + + public boolean isFacet() + { + return facet; + } + + public void setFacet(boolean facet) + { + this.facet = facet; + } + + public String getFacetPivot() + { + return facetPivot; + } + + public void setFacetPivot(String facetPivot) + { + this.facetPivot = facetPivot; + } + + public int getFacetPivotMinCount() + { + return facetPivotMinCount; + } + + public void setFacetPivotMinCount(int facetPivotMinCount) + { + this.facetPivotMinCount = facetPivotMinCount; + } } -- 1.7.10.2