X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2Fstructurechooser%2FThreeDBStructureChooserQuerySource.java;h=f5a1065f8f35b6728ca6bab2cb56590b8c908b12;hb=e7e3ef45b167b7b823fdc76a7d05e78ae91a7fd3;hp=b1ad65fc432e30d532df17f4b0119cb207bdf3e7;hpb=a1984b1c8c273ed33c7ce9283039f4027dcae2de;p=jalview.git diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java index b1ad65f..f5a1065 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,7 +32,7 @@ import java.util.Set; import javax.swing.JTable; -import jalview.bin.Cache; +import jalview.bin.Console; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; @@ -72,6 +92,7 @@ public class ThreeDBStructureChooserQuerySource * @return the built query string */ + @Override public String buildQuery(SequenceI seq) { List refs = seq.getDBRefs(); @@ -161,6 +182,7 @@ public class ThreeDBStructureChooserQuerySource * @return * @throws Exception */ + @Override public FTSRestResponse fetchStructuresMetaData(SequenceI seq, Collection wantedFields, FilterOption selectedFilterOpt, boolean b) throws Exception @@ -175,7 +197,7 @@ public class ThreeDBStructureChooserQuerySource lastTdbRequest = tdbRequest; if (resultList != null) { // Query the PDB and add additional metadata - FTSRestResponse pdbResponse = fetchStructuresMetaDataFor( + List pdbResponse = fetchStructuresMetaDataFor( getPDBQuerySource(), resultList); resultList = joinResponses(resultList, pdbResponse); @@ -246,7 +268,7 @@ public class ThreeDBStructureChooserQuerySource { // 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); @@ -288,7 +310,7 @@ public class ThreeDBStructureChooserQuerySource && tdBeaconsFilters.contains(fieldToFilterBy); } - private String remove_prefix(String fieldToFilterBy) + protected String remove_prefix(String fieldToFilterBy) { if (tdBeaconsFilters != null && tdBeaconsFilters.contains(fieldToFilterBy) @@ -325,6 +347,7 @@ public class ThreeDBStructureChooserQuerySource * @return * @throws Exception */ + @Override public FTSRestResponse selectFirstRankedQuery(SequenceI seq, Collection collectedResults, Collection wantedFields, String fieldToFilterBy, @@ -364,6 +387,9 @@ public class ThreeDBStructureChooserQuerySource int typeColumnIndex = restable.getColumn("Provider").getModelIndex(); int humanUrl = restable.getColumn("Page URL").getModelIndex(); int modelformat = restable.getColumn("Model Format").getModelIndex(); + int tftype = restable.getColumn("Confidence Score Type").getModelIndex(); + int tftypev = restable.getColumn("Confidence Score Version").getModelIndex(); + final int up_start_idx = restable.getColumn("Uniprot Start") .getModelIndex(); final int up_end_idx = restable.getColumn("Uniprot End") @@ -401,7 +427,8 @@ public class ThreeDBStructureChooserQuerySource String modelPage = humanUrl < 1 ? null : (String) restable.getValueAt(row, humanUrl); String strucFormat = restable.getValueAt(row, modelformat).toString(); - + String strucTfType = tftype<1 ? null : restable.getValueAt(row, tftype)==null ? null : restable.getValueAt(row, tftype).toString(); + String strucTfType_v = tftypev<1 ? null : restable.getValueAt(row, tftypev)==null ? null : restable.getValueAt(row, tftypev).toString(); SequenceI selectedSeq = (SequenceI) restable.getValueAt(row, refSeqColIndex); selectedSeqsToView.add(selectedSeq); @@ -415,12 +442,13 @@ public class ThreeDBStructureChooserQuerySource { pdbEntry = new PDBEntry(); pdbEntry.setId(pdbIdStr); + pdbEntry.setAuthoritative(true); try { pdbEntry.setType(PDBEntry.Type.valueOf(strucFormat)); } catch (Exception q) { - Cache.warn("Unknown filetype for 3D Beacons Model from: " + Console.warn("Unknown filetype for 3D Beacons Model from: " + strucFormat + " - " + pdbIdStr + " - " + modelPage); } @@ -429,7 +457,24 @@ public class ThreeDBStructureChooserQuerySource pdbEntry.setRetrievalUrl(urlStr); } pdbEntry.setProvider(typeColumn); - pdbEntry.setProviderPage(modelPage); + if (modelPage != null) + { + pdbEntry.setProviderPage(modelPage); + } + try + { + if (strucTfType!=null && !"".equals(strucTfType)) { + pdbEntry.setTempFacType(strucTfType); + } + if (strucTfType_v!=null && !"".equals(strucTfType_v)) { + pdbEntry.setTempFacTypeVersion(strucTfType_v); + } + } catch (Exception q) + { + Console.warn("Unknown filetype for 3D Beacons Model from: " + + strucFormat + " - " + pdbIdStr + " - " + modelPage); + } + selectedSeq.getDatasetSequence().addPDBId(pdbEntry); } pdbEntriesToView[count++] = pdbEntry; @@ -451,8 +496,9 @@ public class ThreeDBStructureChooserQuerySource * @return */ - public String buildPDBFTSQueryFor(FTSRestResponse upResponse) + public List buildPDBFTSQueryFor(FTSRestResponse upResponse) { + List ftsQueries = new ArrayList(); Set pdbIds = new HashSet(); int idx_modelId = getLastFTSRequest().getFieldIndex("Model id"); int idx_provider = getLastFTSRequest().getFieldIndex("Provider"); @@ -465,7 +511,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; } /** @@ -475,34 +539,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(); + + 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); + } - resultList = pdbquery.executePDBFTSRestRequest(pdbRequest); + } - lastPdbRequest = pdbRequest; - return resultList; + return results; } public FTSRestResponse joinResponses(FTSRestResponse upResponse, - FTSRestResponse pdbResponse) + List pdbResponses) { boolean hasPdbResp = lastPdbRequest != null; @@ -522,18 +605,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]; + } } } }