+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui.structurechooser;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import javax.swing.JTable;
+import jalview.bin.Console;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
import jalview.datamodel.PDBEntry;
import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
import jalview.fts.core.FTSRestRequest;
import jalview.fts.core.FTSRestResponse;
+import jalview.fts.service.threedbeacons.TDB_FTSData;
import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
import jalview.jbgui.FilterOption;
-import jalview.util.MessageManager;
/**
* logic for querying the 3DBeacons API for structures of sequences
private static final String FILTER_SOURCE_PREFIX = "only_";
- private static int MAX_QLENGTH = 7820;
-
protected FTSRestRequest lastTdbRequest;
protected FTSRestClientI tdbRestClient;
* @return the built query string
*/
+ @Override
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)
+ {
+ return getDBRefId(refs.get(ib));
+ }
+ return null;
+ }
+
+ /**
+ * Searches DBRefEntry for uniprot refs
+ *
+ * @param seq
+ * @return -2 if no uniprot refs, -1 if no canonical ref., otherwise index of
+ * Uniprot canonical DBRefEntry
+ */
+ public static int checkUniprotRefs(List<DBRefEntry> refs)
+ {
+ boolean hasUniprot = false;
if (refs != null && refs.size() != 0)
{
for (int ib = 0, nb = refs.size(); ib < nb; ib++)
{
DBRefEntry dbRef = refs.get(ib);
- if (isValidSeqName(getDBRefId(dbRef))
- && queryBuilder.length() < MAX_QLENGTH)
+ if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
{
- if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT)
- && dbRef.isCanonical())
+ hasUniprot = true;
+ if (dbRef.isCanonical())
{
- // TODO: pick best Uniprot accession
- isUniProtRefsFound = true;
- return getDBRefId(dbRef);
-
+ return ib;
}
}
}
}
- return null;
+ return hasUniprot ? -1 : -2;
}
/**
*/
static boolean isValidSeqName(String seqName)
{
- // System.out.println("seqName : " + seqName);
String ignoreList = "pdb,uniprot,swiss-prot";
if (seqName.length() < 3)
{
{
return false;
}
- seqName = seqName.toLowerCase();
+ seqName = seqName.toLowerCase(Locale.ROOT);
for (String ignoredEntry : ignoreList.split(","))
{
if (seqName.contains(ignoredEntry))
* @return
* @throws Exception
*/
+ @Override
public FTSRestResponse fetchStructuresMetaData(SequenceI seq,
Collection<FTSDataColumnI> wantedFields,
FilterOption selectedFilterOpt, boolean b) throws Exception
{
FTSRestResponse resultList;
- if (selectedFilterOpt!=null && tdBeaconsFilter(selectedFilterOpt.getValue()))
+ if (selectedFilterOpt != null
+ && tdBeaconsFilter(selectedFilterOpt.getValue()))
{
FTSRestRequest tdbRequest = getTDBeaconsRequest(seq, wantedFields);
resultList = tdbRestClient.executeRequest(tdbRequest);
lastTdbRequest = tdbRequest;
+ if (resultList != null)
+ { // Query the PDB and add additional metadata
+ List<FTSRestResponse> pdbResponse = fetchStructuresMetaDataFor(
+ getPDBQuerySource(), resultList);
- // Query the PDB and add additional metadata
- FTSRestResponse pdbResponse = fetchStructuresMetaDataFor(
- getPDBQuerySource(), resultList);
- FTSRestResponse joinedResp = joinResponses(resultList, pdbResponse);
+ resultList = joinResponses(resultList, pdbResponse);
+ }
return resultList;
}
// use the PDBFTS directly
wantedFields, selectedFilterOpt, b);
lastTdbRequest = getPDBQuerySource().lastPdbRequest;
lastPdbRequest = lastTdbRequest; // both queries the same - indicates we
- // rank using PDBe
+ // rank using PDBe
return resultList;
}
public void updateAvailableFilterOptions(String VIEWS_FILTER,
List<FilterOption> xtantOptions, Collection<FTSData> tdbEntries)
{
- if (tdbEntries !=null && lastTdbRequest != null)
+ if (tdbEntries != null && lastTdbRequest != null)
{
- int prov_idx = lastTdbRequest.getFieldIndex("Provider");
-
- for (FTSData row : tdbEntries)
+ boolean hasPDBe = false;
+ for (FTSData _row : tdbEntries)
{
- String provider = (String) row.getSummaryData()[prov_idx];
- FilterOption providerOpt = new FilterOption("3DB Provider - " + provider,
- FILTER_SOURCE_PREFIX + provider, VIEWS_FILTER,
- false, this);
+ // tdb returns custom object
+ TDB_FTSData row = (TDB_FTSData) _row;
+ String provider = row.getProvider();
+ FilterOption providerOpt = new FilterOption(
+ "3DB Provider - " + provider,
+ FILTER_SOURCE_PREFIX + provider, VIEWS_FILTER, false, this);
if (!xtantOptions.contains(providerOpt))
{
- xtantOptions.add(1,
- providerOpt);
- tdBeaconsFilters.add(FILTER_SOURCE_PREFIX+provider);
-
+ xtantOptions.add(1, providerOpt);
+ tdBeaconsFilters.add(FILTER_SOURCE_PREFIX + provider);
+ if ("PDBe".equalsIgnoreCase(provider))
+ {
+ hasPDBe = true;
+ }
+ }
+ }
+ if (!hasPDBe)
+ {
+ // remove the PDBe options from the available filters
+ int op = 0;
+ while (op < xtantOptions.size())
+ {
+ FilterOption filter = xtantOptions.get(op);
+ if (filter
+ .getQuerySource() instanceof PDBStructureChooserQuerySource)
+ {
+ xtantOptions.remove(op);
+ }
+ else
+ {
+ op++;
+ }
}
}
}
@Override
public boolean needsRefetch(FilterOption selectedFilterOpt)
{
- return selectedFilterOpt==null || !tdBeaconsFilter(selectedFilterOpt.getValue())
- && lastPdbRequest != lastTdbRequest;
+ return selectedFilterOpt == null
+ || !tdBeaconsFilter(selectedFilterOpt.getValue())
+ && lastPdbRequest != lastTdbRequest;
}
/**
* @return
* @throws Exception
*/
+ @Override
public FTSRestResponse selectFirstRankedQuery(SequenceI seq,
Collection<FTSData> collectedResults,
Collection<FTSDataColumnI> wantedFields, String fieldToFilterBy,
boolean b) throws Exception
{
- if (fieldToFilterBy!=null && tdBeaconsFilter(fieldToFilterBy))
+ if (fieldToFilterBy != null && tdBeaconsFilter(fieldToFilterBy))
{
TDBResultAnalyser analyser = new TDBResultAnalyser(seq,
collectedResults, lastTdbRequest, fieldToFilterBy,
int idColumnIndex = restable.getColumn("Model id").getModelIndex();
int urlColumnIndex = restable.getColumn("Url").getModelIndex();
int typeColumnIndex = restable.getColumn("Provider").getModelIndex();
- int categoryColumnIndex = restable.getColumn("Model Category")
- .getModelIndex();
+ int humanUrl = restable.getColumn("Page URL").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")
String urlStr = restable.getValueAt(row, urlColumnIndex).toString();
String typeColumn = restable.getValueAt(row, typeColumnIndex)
.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);
{
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);
}
+ pdbEntry.setProvider(typeColumn);
+ if (modelPage != null)
+ {
+ pdbEntry.setProviderPage(modelPage);
+ }
selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
}
pdbEntriesToView[count++] = pdbEntry;
* @return
*/
- public String buildPDBFTSQueryFor(FTSRestResponse upResponse)
+ public List<String> buildPDBFTSQueryFor(FTSRestResponse upResponse)
{
- List<String> pdbIds = new ArrayList<String>();
+ List<String> ftsQueries = 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())
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;
}
/**
* @param upResponse
* @return FTSRestResponse via PDBStructureChooserQuerySource
*/
- public FTSRestResponse fetchStructuresMetaDataFor(
+ public List<FTSRestResponse> fetchStructuresMetaDataFor(
PDBStructureChooserQuerySource pdbquery,
FTSRestResponse upResponse) throws Exception
{
-
- String pdb_Query = buildPDBFTSQueryFor(upResponse);
- if (pdb_Query.length()==0)
+ List<String> 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 + ")");
-
- resultList = pdbquery.executePDBFTSRestRequest(pdbRequest);
-
- lastPdbRequest = pdbRequest;
- return resultList;
+ List<FTSRestResponse> results = new ArrayList<FTSRestResponse>();
+
+ 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);
+ }
+
+ }
+
+ return results;
}
public FTSRestResponse joinResponses(FTSRestResponse upResponse,
- FTSRestResponse pdbResponse)
+ List<FTSRestResponse> pdbResponses)
{
boolean hasPdbResp = lastPdbRequest != null;
: -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];
{
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];
+ }
}
}
}
return upResponse;
}
+ public TDB_FTSData getFTSDataFor(JTable restable, int selectedRow,
+ Collection<FTSData> discoveredStructuresSet)
+ {
+ int idColumnIndex = restable.getColumn("Model id").getModelIndex();
+
+ String modelId = (String) restable.getValueAt(selectedRow,
+ idColumnIndex);
+ for (FTSData row : discoveredStructuresSet)
+ {
+ if (row instanceof TDB_FTSData
+ && ((TDB_FTSData) row).getModelId().equals(modelId))
+ {
+ return ((TDB_FTSData) row);
+ }
+ }
+ return null;
+ }
+
}
\ No newline at end of file