import jalview.fts.service.pdb.PDBFTSRestClient;
import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
import jalview.gui.structurechooser.StructureChooserQuerySource;
+import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
import jalview.io.DataSourceType;
import jalview.jbgui.FilterOption;
import jalview.jbgui.GStructureChooser;
import java.util.Objects;
import java.util.Set;
import java.util.Vector;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
// ensure a filter option is in force for search
populateFilterComboBox(true, cachedPDBExists);
- Thread discoverPDBStructuresThread = new Thread(new Runnable()
+ // todo change to futures I guess
+
+ final Runnable discoverPDBStructures = new Runnable()
{
@Override
public void run()
{
- // looks for any existing structures already loaded
- // for the sequences (the cached ones)
- // then queries the StructureChooserQuerySource to
+ // looks for any existing structures already loaded
+ // for the sequences (the cached ones)
+ // then queries the StructureChooserQuerySource to
// discover more structures.
- //
+ //
// Possible optimisation is to only begin querying
// the structure chooser if there are no cached structures.
-
+
long startTime = System.currentTimeMillis();
updateProgressIndicator(MessageManager
.getString("status.loading_cached_pdb_entries"), startTime);
mainFrame.setVisible(true);
updateCurrentView();
}
- });
- discoverPDBStructuresThread.start();
+ };
+ final List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
+
+ final Runnable discoverCanonicalDBrefs = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ long progressId = System.currentTimeMillis();
+
+ int y = seqsWithoutSourceDBRef.size();
+ setProgressBar(MessageManager.formatMessage(
+ "status.fetching_dbrefs_for_sequences_without_valid_refs",
+ y), progressId);
+ SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
+ .toArray(new SequenceI[y]);
+ DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
+ dbRefFetcher.fetchDBRefs(true);
+
+ setProgressBar("Fetch complete.", progressId); // todo i18n
+
+ SwingUtilities.invokeLater(discoverPDBStructures);
+ }
+ };
+
+ Executors.defaultThreadFactory().newThread(new Runnable()
+ {
+ public void run()
+ {
+
+ for (SequenceI seq : selectedSequences)
+ {
+ if (seq.isProtein())
+ {
+ int dbRef = ThreeDBStructureChooserQuerySource
+ .checkUniprotRefs(seq.getDBRefs());
+ if (dbRef < 0)
+ {
+ seqsWithoutSourceDBRef.add(seq);
+ }
+ }
+ }
+ // retrieve database refs for protein sequences
+ if (!seqsWithoutSourceDBRef.isEmpty())
+ {
+ JvOptionPane.newOptionDialog(Desktop.getDesktop())
+ .setResponseHandler(0, discoverCanonicalDBrefs)
+ .setResponseHandler(1, discoverPDBStructures)
+ .showDialog(MessageManager.formatMessage("label.fetch_references_for",seqsWithoutSourceDBRef.size()), MessageManager.getString(
+ "label.fetch_uniprot_references"),
+ JvOptionPane.YES_NO_OPTION,
+ JvOptionPane.PLAIN_MESSAGE, null, new Object[]
+ { MessageManager.getString("action.ok"),
+ MessageManager.getString("action.cancel") },
+ MessageManager.getString("action.ok"));
+ } else {
+ // get structures directly
+ Executors.defaultThreadFactory().newThread(discoverPDBStructures).start();
+ }
+ };
+ }).start();;
+
}
/**
List<SequenceI> selectedSeqsToView = new ArrayList<>();
for (int row : selectedRows)
{
- PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
- pdbIdColIndex);
+ PDBEntry pdbEntry = ((PDBEntryTableModel) tbl_local_pdb.getModel()).getPDBEntryAt(row).getPdbEntry();
+
pdbEntriesToView[count++] = pdbEntry;
SequenceI selectedSeq = (SequenceI) tbl_local_pdb
.getValueAt(row, refSeqColIndex);
value = entry.getSequence();
break;
case 1:
- value = entry.getPdbEntry();
+ value = entry.getQualifiedId();
break;
case 2:
value = entry.getPdbEntry().getChainCode() == null ? "_"
this.pdbEntry = pdbEntry;
}
+ public String getQualifiedId()
+ {
+ if (pdbEntry.hasProvider())
+ {
+ return pdbEntry.getProvider()+":"+pdbEntry.getId();
+ }
+ return pdbEntry.toString();
+ }
+
public SequenceI getSequence()
{
return sequence;
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 jalview.fts.core.FTSRestResponse;
import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
import jalview.jbgui.FilterOption;
-import jalview.util.MessageManager;
/**
* logic for querying the 3DBeacons API for structures of sequences
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;
}
/**
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;
-
- // Query the PDB and add additional metadata
- FTSRestResponse pdbResponse = fetchStructuresMetaDataFor(
- getPDBQuerySource(), resultList);
- FTSRestResponse joinedResp = joinResponses(resultList, pdbResponse);
+ if (resultList!=null)
+ { // Query the PDB and add additional metadata
+ FTSRestResponse pdbResponse = fetchStructuresMetaDataFor(
+ getPDBQuerySource(), resultList);
+ FTSRestResponse joinedResp = 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");
-
+ 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);
+ 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;
}
/**
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 humanUrl = restable.getColumn("Page URL").getModelIndex();
int categoryColumnIndex = restable.getColumn("Model Category")
.getModelIndex();
final int up_start_idx = restable.getColumn("Uniprot Start")
String urlStr = restable.getValueAt(row, urlColumnIndex).toString();
String typeColumn = restable.getValueAt(row, typeColumnIndex)
.toString();
+ String modelPage = humanUrl < 1 ? null
+ : (String) restable.getValueAt(row, humanUrl);
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);
+ boolean probablyPdb = urlStr.toLowerCase(Locale.ENGLISH)
+ .contains("pdb");
+ pdbEntry.setType(hasCif ? PDBEntry.Type.MMCIF
+ : probablyPdb ? PDBEntry.Type.PDB : PDBEntry.Type.FILE);
if (!"PDBe".equalsIgnoreCase(typeColumn))
{
pdbEntry.setRetrievalUrl(urlStr);
}
+ pdbEntry.setProvider(typeColumn);
+ pdbEntry.setProviderPage(modelPage);
selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
}
pdbEntriesToView[count++] = pdbEntry;
{
String pdb_Query = buildPDBFTSQueryFor(upResponse);
- if (pdb_Query.length()==0)
+ if (pdb_Query.length() == 0)
{
return null;
}
pdbRequest.setWantedFields(
pdbquery.getDocFieldPrefs().getStructureSummaryFields());
pdbRequest.setSearchTerm(pdb_Query + ")");
-
+
resultList = pdbquery.executePDBFTSRestRequest(pdbRequest);
lastPdbRequest = pdbRequest;