JAL-3829 insert title for structures from PDBe
authorJim Procter <j.procter@dundee.ac.uk>
Fri, 10 Sep 2021 12:45:07 +0000 (13:45 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Fri, 10 Sep 2021 12:45:07 +0000 (13:45 +0100)
src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java
test/jalview/gui/structurechooser/StructureChooserQuerySourceTest.java

index e5f96be..2c6afe8 100644 (file)
@@ -157,9 +157,24 @@ public class ThreeDBStructureChooserQuerySource
     resultList = tdbRestClient.executeRequest(tdbRequest);
 
     lastTdbRequest = tdbRequest;
+    
+    // Query the PDB and add additional metadata
+    FTSRestResponse pdbResponse = fetchStructuresMetaDataFor(getPDBQuerySource(), resultList);
+    FTSRestResponse joinedResp = joinResponses(resultList,
+            pdbResponse);
     return resultList;
   }
 
+  PDBStructureChooserQuerySource pdbQuerySource=null;
+  private PDBStructureChooserQuerySource getPDBQuerySource()
+  {
+    if (pdbQuerySource==null)
+    {
+      pdbQuerySource = new PDBStructureChooserQuerySource();
+    }
+    return pdbQuerySource;
+  }
+
   private FTSRestRequest getTDBeaconsRequest(SequenceI seq,
           Collection<FTSDataColumnI> wantedFields)
   {
@@ -369,27 +384,31 @@ public class ThreeDBStructureChooserQuerySource
     int idx_provider = getLastFTSRequest().getFieldIndex("Provider");
     // join on
     int idx_modelId = getLastFTSRequest().getFieldIndex("Model id");
-    int pdbIdx = lastPdbRequest.getFieldIndex("pdb_id");
-    for (FTSData row : upResponse.getSearchSummary())
+    int pdbIdx = lastPdbRequest.getFieldIndex("PDB Id");
+    int pdbTitle_idx = lastPdbRequest.getFieldIndex("Title");
+    int tdbTitle_idx = getLastFTSRequest().getFieldIndex("Title");
+    
+    List<FTSData> joinedRows = new ArrayList<FTSData>();
+    for (final FTSData row : upResponse.getSearchSummary())
     {
       String id = (String) row.getSummaryData()[idx_modelId];
       String provider = (String) row.getSummaryData()[idx_provider];
       if ("PDBe".equalsIgnoreCase(provider))
       {
-        for (FTSData pdbrow : pdbResponse.getSearchSummary())
+        for (final FTSData pdbrow : pdbResponse.getSearchSummary())
         {
           String pdbid = (String) pdbrow.getSummaryData()[pdbIdx];
           if (id.equalsIgnoreCase(pdbid))
           {
-            // often multiple entries per PDB ID so we bail after first
-            // get wanted fields
-            // append to FTSRestResponse array
+            row.getSummaryData()[tdbTitle_idx] = pdbrow
+                    .getSummaryData()[pdbTitle_idx];
           }
         }
+      } else {
+        row.getSummaryData()[tdbTitle_idx] = "Model from TDB";
       }
     }
-    // TODO Auto-generated method stub
-    return null;
+    return upResponse;
   }
 
 }
\ No newline at end of file
index acedfed..59c4a50 100644 (file)
@@ -175,7 +175,9 @@ public class StructureChooserQuerySourceTest
   {
     System.out.println("seq >>>> " + upSeq);
     TDBeaconsFTSRestClientTest.setMock();
+    PDBFTSRestClient.setMock();
     StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
+    // gets the lightweight proxy rather than the ThreeDBStructureChooserQuerySource
     AssertJUnit.assertTrue(scquery instanceof ThreeDBStructureChooserQuerySource);
     String query = scquery.buildQuery(upSeq);
     AssertJUnit.assertEquals("P38398", query);
@@ -264,7 +266,7 @@ public class StructureChooserQuerySourceTest
       upResponse = tdbquery.fetchStructuresMetaData(upSeq, tdbquery.getDocFieldPrefs().getStructureSummaryFields(),  null, false);
       // test ranking without additional PDBe data
       FTSRestResponse firstRanked = tdbquery.selectFirstRankedQuery(upSeq, upResponse.getSearchSummary(), tdbquery.getDocFieldPrefs().getStructureSummaryFields(), "", false);
-      assertTrue(firstRanked.getNumberOfItemsFound()==upResponse.getNumberOfItemsFound());
+      assertTrue(firstRanked.getNumberOfItemsFound()<upResponse.getNumberOfItemsFound());
       // NB Could have race condition here 
       String pdb_Query = tdbquery.buildPDBFTSQueryFor(upResponse);
       assertTrue(pdb_Query.trim().length()>0);