+ /**
+ * Initializes parameters used by the Structure Chooser Panel
+ */
+ public void init()
+ {
+ Thread discoverPDBStructuresThread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ long startTime = System.currentTimeMillis();
+ updateProgressIndicator(MessageManager
+ .getString("status.loading_cached_pdb_entries"), startTime);
+ loadLocalCachedPDBEntries();
+ updateProgressIndicator(null, startTime);
+ updateProgressIndicator(MessageManager
+ .getString("status.searching_for_pdb_structures"),
+ startTime);
+ fetchStructuresMetaData();
+ populateFilterComboBox();
+ updateProgressIndicator(null, startTime);
+ mainFrame.setVisible(true);
+ updateCurrentView();
+ }
+ });
+ discoverPDBStructuresThread.start();
+ }
+
+ /**
+ * Updates the progress indicator with the specified message
+ *
+ * @param message
+ * displayed message for the operation
+ * @param id
+ * unique handle for this indicator
+ */
+ public void updateProgressIndicator(String message, long id)
+ {
+ if (progressIndicator != null)
+ {
+ progressIndicator.setProgressBar(message, id);
+ }
+ }
+
+ /**
+ * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
+ * selection group
+ */
+ public void fetchStructuresMetaData()
+ {
+ long startTime = System.currentTimeMillis();
+ Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
+ .getStructureSummaryFields();
+
+ discoveredStructuresSet = new LinkedHashSet<PDBResponseSummary>();
+ HashSet<String> errors = new HashSet<String>();
+ for (SequenceI seq : selectedSequences)
+ {
+ PDBRestRequest pdbRequest = new PDBRestRequest();
+ pdbRequest.setAllowEmptySeq(false);
+ pdbRequest.setResponseSize(500);
+ pdbRequest.setFieldToSearchBy("(text:");
+ pdbRequest.setWantedFields(wantedFields);
+ pdbRequest.setSearchTerm(buildQuery(seq) + ")");
+ pdbRequest.setAssociatedSequence(seq);
+ pdbRestCleint = new PDBRestClient();
+ PDBRestResponse resultList;
+ try
+ {
+ resultList = pdbRestCleint.executeRequest(pdbRequest);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ errors.add(e.getMessage());
+ continue;
+ }
+ lastPdbRequest = pdbRequest;
+ if (resultList.getSearchSummary() != null
+ && !resultList.getSearchSummary().isEmpty())
+ {
+ discoveredStructuresSet.addAll(resultList.getSearchSummary());
+ }
+ }
+
+ int noOfStructuresFound = 0;
+ String totalTime = (System.currentTimeMillis() - startTime)
+ + " milli secs";
+ if (discoveredStructuresSet != null
+ && !discoveredStructuresSet.isEmpty())
+ {
+ tbl_summary.setModel(PDBRestResponse.getTableModel(lastPdbRequest,
+ discoveredStructuresSet));
+ structuresDiscovered = true;
+ noOfStructuresFound = discoveredStructuresSet.size();
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_no_of_structures",
+ noOfStructuresFound, totalTime));
+ }
+ else
+ {
+ mainFrame.setTitle(MessageManager
+ .getString("label.structure_chooser_manual_association"));
+ if (errors.size() > 0)
+ {
+ StringBuilder errorMsg = new StringBuilder();
+ for (String error : errors)
+ {
+ errorMsg.append(error).append("\n");
+ }
+ JOptionPane.showMessageDialog(this, errorMsg.toString(),
+ MessageManager.getString("label.pdb_web-service_error"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+
+ public void loadLocalCachedPDBEntries()
+ {
+ ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
+ for (SequenceI seq : selectedSequences)
+ {
+ if (seq.getDatasetSequence() != null
+ && seq.getDatasetSequence().getAllPDBEntries() != null)
+ {
+ for (PDBEntry pdbEntry : seq.getDatasetSequence()
+ .getAllPDBEntries())
+ {
+ if (pdbEntry.getFile() != null)
+ {
+ entries.add(new CachedPDB(seq, pdbEntry));
+ }
+ }
+ }
+ }
+
+ PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
+ tbl_local_pdb.setModel(tableModelx);
+ }
+
+ /**
+ * Builds a query string for a given sequences using its DBRef entries
+ *
+ * @param seq
+ * the sequences to build a query for
+ * @return the built query string
+ */
+
+ public static String buildQuery(SequenceI seq)
+ {
+ HashSet<String> seqRefs = new LinkedHashSet<String>();
+ String seqName = seq.getName();
+ String[] names = seqName.toLowerCase().split("\\|");
+ for (String name : names)
+ {
+ // System.out.println("Found name : " + name);
+ name.trim();
+ if (isValidSeqName(name))
+ {
+ seqRefs.add(name);
+ }
+ }
+
+ if (seq.getAllPDBEntries() != null)
+ {
+ for (PDBEntry entry : seq.getAllPDBEntries())
+ {
+ if (isValidSeqName(entry.getId()))
+ {
+ seqRefs.add(entry.getId());
+ }
+ }
+ }
+
+ if (seq.getDBRef() != null && seq.getDBRef().length != 0)
+ {
+ int count = 0;
+ for (DBRefEntry dbRef : seq.getDBRef())
+ {
+ if (isValidSeqName(getDBRefId(dbRef)))
+ {
+ seqRefs.add(getDBRefId(dbRef));
+ }
+ ++count;
+ if (count > 10)
+ {
+ break;
+ }
+ }
+ }
+
+ StringBuilder queryBuilder = new StringBuilder();
+ for (String seqRef : seqRefs)
+ {
+ queryBuilder.append("text:").append(seqRef).append(" OR ");
+ }
+ int endIndex = queryBuilder.lastIndexOf(" OR ");
+
+ if (queryBuilder.toString().length() < 6)
+ {
+ return null;
+ }
+ String query = queryBuilder.toString().substring(5, endIndex);
+ return query;
+ }
+
+ /**
+ * Ensures sequence ref names are not less than 3 characters and does not
+ * contain a database name
+ *
+ * @param seqName
+ * @return
+ */
+ public static boolean isValidSeqName(String seqName)