JAL-1720 JAL-2002 improvement for 'uniprot coverage' filter using facet pivot query
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 22 Feb 2016 17:12:36 +0000 (17:12 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 22 Feb 2016 17:12:36 +0000 (17:12 +0000)
src/jalview/gui/StructureChooser.java
src/jalview/ws/dbsources/PDBRestClient.java
src/jalview/ws/uimodel/PDBRestRequest.java

index cf58322..7d0d76a 100644 (file)
@@ -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
index c6251a6..2c05acd 100644 (file)
@@ -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;
index 24f38d1..7bfc226 100644 (file)
@@ -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;
+  }
 }