+ * Tries to fetch one or more accession ids from the database proxy
+ *
+ * @param proxy
+ * @param accessions
+ * the queries to fetch
+ * @param aresultq
+ * a successful queries list to add to
+ * @param aresult
+ * a list of retrieved alignments to add to
+ * @param nextFetch
+ * failed queries are added to this list
+ * @throws Exception
+ */
+ void fetchMultipleAccessions(DbSourceProxy proxy,
+ Iterator<String> accessions, List<String> aresultq,
+ List<AlignmentI> aresult, List<String> nextFetch) throws Exception
+ {
+ StringBuilder multiacc = new StringBuilder();
+ List<String> tosend = new ArrayList<String>();
+ while (accessions.hasNext())
+ {
+ String nel = accessions.next();
+ tosend.add(nel);
+ multiacc.append(nel);
+ if (accessions.hasNext())
+ {
+ multiacc.append(proxy.getAccessionSeparator());
+ }
+ }
+
+ try
+ {
+ String query = multiacc.toString();
+ AlignmentI rslt = proxy.getSequenceRecords(query);
+ if (rslt == null || rslt.getHeight() == 0)
+ {
+ // no results - pass on all queries to next source
+ nextFetch.addAll(tosend);
+ }
+ else
+ {
+ aresultq.add(query);
+ aresult.add(rslt);
+ if (tosend.size() > 1)
+ {
+ checkResultForQueries(rslt, tosend, nextFetch, proxy);
+ }
+ }
+ } catch (OutOfMemoryError oome)
+ {
+ new OOMWarning("fetching " + multiacc + " from "
+ + database.getSelectedItem(), oome, this);
+ }
+ }
+
+ /**
+ * Query for a single accession id via the database proxy
+ *
+ * @param proxy
+ * @param accession
+ * @param aresultq
+ * a list of successful queries to add to
+ * @param aresult
+ * a list of retrieved alignments to add to
+ * @return true if the fetch was successful, else false
+ */
+ boolean fetchSingleAccession(DbSourceProxy proxy, String accession,
+ List<String> aresultq, List<AlignmentI> aresult)
+ {
+ boolean success = false;
+ try
+ {
+ if (aresult != null)
+ {
+ try
+ {
+ // give the server a chance to breathe
+ Thread.sleep(5);
+ } catch (Exception e)
+ {
+ //
+ }
+ }
+
+ AlignmentI indres = null;
+ try
+ {
+ indres = proxy.getSequenceRecords(accession);
+ } catch (OutOfMemoryError oome)
+ {
+ new OOMWarning(
+ "fetching " + accession + " from " + proxy.getDbName(),
+ oome, this);
+ }
+ if (indres != null)
+ {
+ aresultq.add(accession);
+ aresult.add(indres);
+ success = true;
+ }
+ } catch (Exception e)
+ {
+ Cache.log.info("Error retrieving " + accession + " from "
+ + proxy.getDbName(), e);
+ }
+ return success;
+ }
+
+ /**
+ * Checks which of the queries were successfully retrieved by searching the
+ * DBRefs of the retrieved sequences for a match. Any not found are added to
+ * the 'nextFetch' list.
+ *
+ * @param rslt
+ * @param queries
+ * @param nextFetch
+ * @param proxy
+ */
+ void checkResultForQueries(AlignmentI rslt, List<String> queries,
+ List<String> nextFetch, DbSourceProxy proxy)
+ {
+ SequenceI[] rs = rslt.getSequencesArray();
+
+ for (String q : queries)
+ {
+ DBRefEntry dbr = new DBRefEntry();
+ dbr.setSource(proxy.getDbSource());
+ dbr.setVersion(null);
+ String accId = proxy.getAccessionIdFromQuery(q);
+ dbr.setAccessionId(accId);
+ boolean rfound = false;
+ for (int r = 0; r < rs.length; r++)
+ {
+ if (rs[r] != null)
+ {
+ List<DBRefEntry> found = DBRefUtils.searchRefs(rs[r].getDBRefs(),
+ accId);
+ if (!found.isEmpty())
+ {
+ rfound = true;
+ break;
+ }
+ }
+ }
+ if (!rfound)
+ {
+ nextFetch.add(q);
+ }
+ }
+ }
+
+ /**