Merge branch 'develop' into improvement/JAL-3594_BG_and_UoD_logos_added
[jalview.git] / src / jalview / gui / structurechooser / ThreeDBStructureChooserQuerySource.java
index cdf456c..669e58a 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Set;
 
 import javax.swing.JTable;
 
+import jalview.bin.Console;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
@@ -44,8 +45,6 @@ public class ThreeDBStructureChooserQuerySource
 
   private static final String FILTER_SOURCE_PREFIX = "only_";
 
-  private static int MAX_QLENGTH = 7820;
-
   protected FTSRestRequest lastTdbRequest;
 
   protected FTSRestClientI tdbRestClient;
@@ -75,19 +74,9 @@ public class ThreeDBStructureChooserQuerySource
 
   public String buildQuery(SequenceI seq)
   {
-    boolean isPDBRefsFound = false;
-    boolean isUniProtRefsFound = false;
-    StringBuilder queryBuilder = new StringBuilder();
-    Set<String> seqRefs = new LinkedHashSet<>();
-
-    /*
-     * note PDBs as DBRefEntry so they are not duplicated in query
-     */
-    Set<String> pdbids = new HashSet<>();
-
     List<DBRefEntry> refs = seq.getDBRefs();
     int ib = checkUniprotRefs(refs);
-    if (ib>-1)
+    if (ib > -1)
     {
       return getDBRefId(refs.get(ib));
     }
@@ -96,8 +85,10 @@ public class ThreeDBStructureChooserQuerySource
 
   /**
    * Searches DBRefEntry for uniprot refs
+   * 
    * @param seq
-   * @return -2 if no uniprot refs, -1 if no canonical ref., otherwise index of Uniprot canonical DBRefEntry 
+   * @return -2 if no uniprot refs, -1 if no canonical ref., otherwise index of
+   *         Uniprot canonical DBRefEntry
    */
   public static int checkUniprotRefs(List<DBRefEntry> refs)
   {
@@ -129,7 +120,6 @@ public class ThreeDBStructureChooserQuerySource
    */
   static boolean isValidSeqName(String seqName)
   {
-    // System.out.println("seqName : " + seqName);
     String ignoreList = "pdb,uniprot,swiss-prot";
     if (seqName.length() < 3)
     {
@@ -181,13 +171,14 @@ public class ThreeDBStructureChooserQuerySource
     {
       FTSRestRequest tdbRequest = getTDBeaconsRequest(seq, wantedFields);
       resultList = tdbRestClient.executeRequest(tdbRequest);
-      
+
       lastTdbRequest = tdbRequest;
-      if (resultList!=null)
+      if (resultList != null)
       { // Query the PDB and add additional metadata
         FTSRestResponse pdbResponse = fetchStructuresMetaDataFor(
                 getPDBQuerySource(), resultList);
-        FTSRestResponse joinedResp = joinResponses(resultList, pdbResponse);
+
+        resultList = joinResponses(resultList, pdbResponse);
       }
       return resultList;
     }
@@ -250,8 +241,7 @@ public class ThreeDBStructureChooserQuerySource
   {
     if (tdbEntries != null && lastTdbRequest != null)
     {
-      int prov_idx = lastTdbRequest.getFieldIndex("Provider");
-      boolean hasPDBe=false;
+      boolean hasPDBe = false;
       for (FTSData _row : tdbEntries)
       {
         // tdb returns custom object
@@ -266,21 +256,24 @@ public class ThreeDBStructureChooserQuerySource
           tdBeaconsFilters.add(FILTER_SOURCE_PREFIX + provider);
           if ("PDBe".equalsIgnoreCase(provider))
           {
-            hasPDBe=true;
+            hasPDBe = true;
           }
         }
       }
       if (!hasPDBe)
       {
         // remove the PDBe options from the available filters
-        int op=0;
-        while (op<xtantOptions.size())
+        int op = 0;
+        while (op < xtantOptions.size())
         {
           FilterOption filter = xtantOptions.get(op);
-          if (filter.getQuerySource() instanceof PDBStructureChooserQuerySource)
+          if (filter
+                  .getQuerySource() instanceof PDBStructureChooserQuerySource)
           {
             xtantOptions.remove(op);
-          } else {
+          }
+          else
+          {
             op++;
           }
         }
@@ -370,8 +363,7 @@ public class ThreeDBStructureChooserQuerySource
     int urlColumnIndex = restable.getColumn("Url").getModelIndex();
     int typeColumnIndex = restable.getColumn("Provider").getModelIndex();
     int humanUrl = restable.getColumn("Page URL").getModelIndex();
-    int categoryColumnIndex = restable.getColumn("Model Category")
-            .getModelIndex();
+    int modelformat = restable.getColumn("Model Format").getModelIndex();
     final int up_start_idx = restable.getColumn("Uniprot Start")
             .getModelIndex();
     final int up_end_idx = restable.getColumn("Uniprot End")
@@ -408,6 +400,8 @@ public class ThreeDBStructureChooserQuerySource
               .toString();
       String modelPage = humanUrl < 1 ? null
               : (String) restable.getValueAt(row, humanUrl);
+      String strucFormat = restable.getValueAt(row, modelformat).toString();
+
       SequenceI selectedSeq = (SequenceI) restable.getValueAt(row,
               refSeqColIndex);
       selectedSeqsToView.add(selectedSeq);
@@ -421,11 +415,16 @@ public class ThreeDBStructureChooserQuerySource
       {
         pdbEntry = new PDBEntry();
         pdbEntry.setId(pdbIdStr);
-        boolean hasCif = urlStr.toLowerCase(Locale.ENGLISH).endsWith("cif");
-        boolean probablyPdb = urlStr.toLowerCase(Locale.ENGLISH)
-                .contains("pdb");
-        pdbEntry.setType(hasCif ? PDBEntry.Type.MMCIF
-                : probablyPdb ? PDBEntry.Type.PDB : PDBEntry.Type.FILE);
+        pdbEntry.setAuthoritative(true);
+        try
+        {
+          pdbEntry.setType(PDBEntry.Type.valueOf(strucFormat));
+        } catch (Exception q)
+        {
+          Console.warn("Unknown filetype for 3D Beacons Model from: "
+                  + strucFormat + " - " + pdbIdStr + " - " + modelPage);
+        }
+
         if (!"PDBe".equalsIgnoreCase(typeColumn))
         {
           pdbEntry.setRetrievalUrl(urlStr);
@@ -455,7 +454,7 @@ public class ThreeDBStructureChooserQuerySource
 
   public String buildPDBFTSQueryFor(FTSRestResponse upResponse)
   {
-    List<String> pdbIds = new ArrayList<String>();
+    Set<String> pdbIds = new HashSet<String>();
     int idx_modelId = getLastFTSRequest().getFieldIndex("Model id");
     int idx_provider = getLastFTSRequest().getFieldIndex("Provider");
     for (FTSData row : upResponse.getSearchSummary())
@@ -516,7 +515,6 @@ public class ThreeDBStructureChooserQuerySource
             : -1;
     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];
@@ -554,13 +552,15 @@ public class ThreeDBStructureChooserQuerySource
           Collection<FTSData> discoveredStructuresSet)
   {
     int idColumnIndex = restable.getColumn("Model id").getModelIndex();
-    
-    String modelId = (String) restable.getValueAt(selectedRow, idColumnIndex);
-    for (FTSData row:discoveredStructuresSet)
+
+    String modelId = (String) restable.getValueAt(selectedRow,
+            idColumnIndex);
+    for (FTSData row : discoveredStructuresSet)
     {
-      if (row instanceof TDB_FTSData && ((TDB_FTSData)row).getModelId().equals(modelId))
+      if (row instanceof TDB_FTSData
+              && ((TDB_FTSData) row).getModelId().equals(modelId))
       {
-        return ((TDB_FTSData)row);
+        return ((TDB_FTSData) row);
       }
     }
     return null;