X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2Fstructurechooser%2FThreeDBStructureChooserQuerySource.java;h=76ef85f85f16d2f3e11b21e76fbeeea499daab8f;hb=5640ec0623c6d1205e62f9fe15292f32bfdab7d9;hp=ffc6c6686a0c3af5fc78f96422486b91985a6833;hpb=b334bfb75ddd402fa7368873f4c25cffae0b1740;p=jalview.git
diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java
index ffc6c66..76ef85f 100644
--- a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java
+++ b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui.structurechooser;
import java.util.ArrayList;
@@ -12,6 +32,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 +65,6 @@ public class ThreeDBStructureChooserQuerySource
private static final String FILTER_SOURCE_PREFIX = "only_";
- private static int MAX_QLENGTH = 7820;
-
protected FTSRestRequest lastTdbRequest;
protected FTSRestClientI tdbRestClient;
@@ -73,21 +92,12 @@ public class ThreeDBStructureChooserQuerySource
* @return the built query string
*/
+ @Override
public String buildQuery(SequenceI seq)
{
- boolean isPDBRefsFound = false;
- boolean isUniProtRefsFound = false;
- StringBuilder queryBuilder = new StringBuilder();
- Set seqRefs = new LinkedHashSet<>();
-
- /*
- * note PDBs as DBRefEntry so they are not duplicated in query
- */
- Set pdbids = new HashSet<>();
-
List refs = seq.getDBRefs();
int ib = checkUniprotRefs(refs);
- if (ib>-1)
+ if (ib > -1)
{
return getDBRefId(refs.get(ib));
}
@@ -96,8 +106,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 refs)
{
@@ -129,7 +141,6 @@ public class ThreeDBStructureChooserQuerySource
*/
static boolean isValidSeqName(String seqName)
{
- // System.out.println("seqName : " + seqName);
String ignoreList = "pdb,uniprot,swiss-prot";
if (seqName.length() < 3)
{
@@ -171,6 +182,7 @@ public class ThreeDBStructureChooserQuerySource
* @return
* @throws Exception
*/
+ @Override
public FTSRestResponse fetchStructuresMetaData(SequenceI seq,
Collection wantedFields,
FilterOption selectedFilterOpt, boolean b) throws Exception
@@ -181,13 +193,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(
+ List pdbResponse = fetchStructuresMetaDataFor(
getPDBQuerySource(), resultList);
- FTSRestResponse joinedResp = joinResponses(resultList, pdbResponse);
+
+ resultList = joinResponses(resultList, pdbResponse);
}
return resultList;
}
@@ -250,13 +263,12 @@ 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
TDB_FTSData row = (TDB_FTSData) _row;
- String provider = (String) row.getProvider();
+ String provider = row.getProvider();
FilterOption providerOpt = new FilterOption(
"3DB Provider - " + provider,
FILTER_SOURCE_PREFIX + provider, VIEWS_FILTER, false, this);
@@ -266,21 +278,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 collectedResults,
Collection wantedFields, String fieldToFilterBy,
@@ -371,8 +387,6 @@ public class ThreeDBStructureChooserQuerySource
int typeColumnIndex = restable.getColumn("Provider").getModelIndex();
int humanUrl = restable.getColumn("Page URL").getModelIndex();
int modelformat = restable.getColumn("Model Format").getModelIndex();
- int categoryColumnIndex = restable.getColumn("Model Category")
- .getModelIndex();
final int up_start_idx = restable.getColumn("Uniprot Start")
.getModelIndex();
final int up_end_idx = restable.getColumn("Uniprot End")
@@ -424,12 +438,13 @@ public class ThreeDBStructureChooserQuerySource
{
pdbEntry = new PDBEntry();
pdbEntry.setId(pdbIdStr);
+ pdbEntry.setAuthoritative(true);
try
{
pdbEntry.setType(PDBEntry.Type.valueOf(strucFormat));
} catch (Exception q)
{
- Cache.log.warn("Unknown filetype for 3D Beacons Model from: "
+ Console.warn("Unknown filetype for 3D Beacons Model from: "
+ strucFormat + " - " + pdbIdStr + " - " + modelPage);
}
@@ -438,7 +453,10 @@ public class ThreeDBStructureChooserQuerySource
pdbEntry.setRetrievalUrl(urlStr);
}
pdbEntry.setProvider(typeColumn);
- pdbEntry.setProviderPage(modelPage);
+ if (modelPage != null)
+ {
+ pdbEntry.setProviderPage(modelPage);
+ }
selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
}
pdbEntriesToView[count++] = pdbEntry;
@@ -460,9 +478,10 @@ public class ThreeDBStructureChooserQuerySource
* @return
*/
- public String buildPDBFTSQueryFor(FTSRestResponse upResponse)
+ public List buildPDBFTSQueryFor(FTSRestResponse upResponse)
{
- List pdbIds = new ArrayList();
+ List ftsQueries = new ArrayList();
+ Set pdbIds = new HashSet();
int idx_modelId = getLastFTSRequest().getFieldIndex("Model id");
int idx_provider = getLastFTSRequest().getFieldIndex("Provider");
for (FTSData row : upResponse.getSearchSummary())
@@ -474,7 +493,25 @@ public class ThreeDBStructureChooserQuerySource
pdbIds.add(id);
}
}
- return String.join(" OR ", pdbIds).toString();
+ StringBuilder sb = new StringBuilder();
+ for (String pdbId : pdbIds)
+ {
+ if (sb.length() > 2500)
+ {
+ ftsQueries.add(sb.toString());
+ sb.setLength(0);
+ }
+ if (sb.length() > 0)
+ {
+ sb.append(" OR ");
+ }
+ sb.append(pdbId);
+ }
+ if (sb.length() > 0)
+ {
+ ftsQueries.add(sb.toString());
+ }
+ return ftsQueries;
}
/**
@@ -484,34 +521,53 @@ public class ThreeDBStructureChooserQuerySource
* @param upResponse
* @return FTSRestResponse via PDBStructureChooserQuerySource
*/
- public FTSRestResponse fetchStructuresMetaDataFor(
+ public List fetchStructuresMetaDataFor(
PDBStructureChooserQuerySource pdbquery,
FTSRestResponse upResponse) throws Exception
{
-
- String pdb_Query = buildPDBFTSQueryFor(upResponse);
- if (pdb_Query.length() == 0)
+ List pdb_Queries = buildPDBFTSQueryFor(upResponse);
+ if (pdb_Queries.size() == 0)
{
return null;
}
- FTSRestResponse resultList;
- FTSRestRequest pdbRequest = new FTSRestRequest();
- pdbRequest.setAllowEmptySeq(false);
- pdbRequest.setResponseSize(500);
- pdbRequest.setFieldToSearchBy("(");
- // pdbRequest.setFieldToSortBy("pdb_id");
- pdbRequest.setWantedFields(
- pdbquery.getDocFieldPrefs().getStructureSummaryFields());
- pdbRequest.setSearchTerm(pdb_Query + ")");
+ List results = new ArrayList();
- resultList = pdbquery.executePDBFTSRestRequest(pdbRequest);
+ for (String pdb_Query : pdb_Queries)
+ {
+ FTSRestResponse resultList;
+ FTSRestRequest pdbRequest = new FTSRestRequest();
+ pdbRequest.setAllowEmptySeq(false);
+ pdbRequest.setResponseSize(500);
+ pdbRequest.setFieldToSearchBy("(");
+ // pdbRequest.setFieldToSortBy("pdb_id");
+ pdbRequest.setWantedFields(
+ pdbquery.getDocFieldPrefs().getStructureSummaryFields());
+ pdbRequest.setSearchTerm(pdb_Query + ")");
+
+ // handle exceptions like server errors here - means the threedbeacons
+ // discovery isn't broken by issues to do with the PDBe SOLR api
+ try
+ {
+ resultList = pdbquery.executePDBFTSRestRequest(pdbRequest);
+ if (resultList.getNumberOfItemsFound() == 0)
+ {
+ Console.info("Unexpectedly returned no results for pdbe query: "
+ + pdb_Query);
+ }
+ results.add(resultList);
+ lastPdbRequest = pdbRequest;
+ } catch (Exception ex)
+ {
+ Console.error("PDBFTSQuery failed", ex);
+ }
- lastPdbRequest = pdbRequest;
- return resultList;
+ }
+
+ return results;
}
public FTSRestResponse joinResponses(FTSRestResponse upResponse,
- FTSRestResponse pdbResponse)
+ List pdbResponses)
{
boolean hasPdbResp = lastPdbRequest != null;
@@ -523,7 +579,6 @@ public class ThreeDBStructureChooserQuerySource
: -1;
int tdbTitle_idx = getLastFTSRequest().getFieldIndex("Title");
- List joinedRows = new ArrayList();
for (final FTSData row : upResponse.getSearchSummary())
{
String id = (String) row.getSummaryData()[idx_modelId];
@@ -532,18 +587,21 @@ public class ThreeDBStructureChooserQuerySource
{
if (!hasPdbResp)
{
- System.out.println(
+ jalview.bin.Console.outPrintln(
"Warning: seems like we couldn't get to the PDBe search interface.");
}
else
{
- for (final FTSData pdbrow : pdbResponse.getSearchSummary())
+ for (final FTSRestResponse pdbResponse : pdbResponses)
{
- String pdbid = (String) pdbrow.getSummaryData()[pdbIdx];
- if (id.equalsIgnoreCase(pdbid))
+ for (final FTSData pdbrow : pdbResponse.getSearchSummary())
{
- row.getSummaryData()[tdbTitle_idx] = pdbrow
- .getSummaryData()[pdbTitle_idx];
+ String pdbid = (String) pdbrow.getSummaryData()[pdbIdx];
+ if (id.equalsIgnoreCase(pdbid))
+ {
+ row.getSummaryData()[tdbTitle_idx] = pdbrow
+ .getSummaryData()[pdbTitle_idx];
+ }
}
}
}
@@ -561,13 +619,15 @@ public class ThreeDBStructureChooserQuerySource
Collection 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;