public abstract class DatabaseService extends GeneiousService
retrieve(String)
. For example
DatabaseService service = (DatabaseService)PluginUtilities.getGeneiousService("NCBI_nucleotide_gbc"); List<AnnotatedPluginDocument> documents = service.retrieve("AF093856"); for (AnnotatedPluginDocument document : documents) { if (DocumentType.isSequence(document)) { SequenceDocument sequence = (SequenceDocument) document.getDocument(); System.out.println("name="+sequence.getName()+" sequence="+sequence.getSequenceString()); } }The simplest way to implement a service is to implement
retrieve(Query, RetrieveCallback, com.biomatters.geneious.publicapi.documents.URN[])
and inside the implementation call RetrieveCallback.add(com.biomatters.geneious.publicapi.documents.PluginDocument, java.util.Map)
For example:
public void retrieve(Query query, RetrieveCallback callback, URN[] urnsToNotRetrieve) throws DatabaseServiceException { callback.add(new DefaultNucleotideSequence("name","GATTACA"),null); }For more detailed examples of implementing a DatabaseService, refer to
GeneiousService
or to ExampleGeneiousService in the API examples folder.Modifier and Type | Class and Description |
---|---|
static class |
DatabaseService.SequenceSearchQueryType
The type of query for a sequence search
|
GeneiousService.ServiceStatus
Constructor and Description |
---|
DatabaseService() |
Modifier and Type | Method and Description |
---|---|
void |
addDatabaseServiceListener(DatabaseServiceListener listener)
DatabaseServiceListener has several methods for the database service
to notify the program of changes. |
void |
addWeakDatabaseServiceListener(DatabaseServiceListener listener)
Like
addWeakDatabaseServiceListener(DatabaseServiceListener) but adds a weakly referenced listener instead. |
void |
batchSequenceSearch(List<AnnotatedPluginDocument> querySequences,
String program,
Options options,
RetrieveCallback callback)
If this is a Sequence Database (ie.
|
protected List<DatabaseServiceListener> |
getDatabaseServiceListeners()
The default implementations of
addDatabaseServiceListener(DatabaseServiceListener)
and removeDatabaseServiceListener(DatabaseServiceListener)
store the listeners in a list that is available for subclasses using this method. |
DocumentSelectionSignature[] |
getDocumentTypesForSequenceSearch(DatabaseService.SequenceSearchQueryType queryType,
String program,
Options searchOptions,
boolean summaryDocumentTypes)
Return
DocumentSelectionSignature s describing all possible types of
documents that can be returned from a sequence search on this service. |
ExtendedSearchOption[] |
getExtendedSearchOptions(boolean isAdvancedSearch)
Provide a list of extended options to be displayed the in the search panel.
|
abstract QueryField[] |
getSearchFields()
Gives the set of fields that can be used for searching this repository/database.
|
Options |
getSequenceSearchOptions(String program)
Optionally override to provide options which will be displayed at the bottom of the options in the Sequence Search interface
when this database is selected and the given program is selected.
|
Map<String,String> |
getSequenceSearchPrograms(DatabaseService.SequenceSearchQueryType queryType)
This method can be optionally overridden if this database provides sequence similarity searching and should be
available through the Sequence Search interface in Geneious.
|
boolean |
isBrowsable()
A Database Service is browsable if its documents are viewed when it is selected in the service tree.
|
int |
locateSummaryDocument(AnnotatedPluginDocument actualDocument,
AnnotatedPluginDocument[] summaryDocuments)
Locate summary document of fully downloaded documents.
|
void |
removeDatabaseServiceListener(DatabaseServiceListener listener)
Remove a listener which was added using
addDatabaseServiceListener(DatabaseServiceListener) or addWeakDatabaseServiceListener(DatabaseServiceListener)
. |
void |
resumeSearch(String uniqueIdentifier,
RetrieveCallback callback)
Deprecated.
Geneious no longer supports resuming searches
|
void |
retrieve(AnnotatedPluginDocument[] summaryDocuments,
RetrieveCallback callback,
URN[] urnsToNotRetrieve)
Retrieves full documents corresponding to the given summary documents from the
database.
|
List<AnnotatedPluginDocument> |
retrieve(List<AnnotatedPluginDocument> summaryDocuments,
ProgressListener progressListener)
Convenience method to be used instead of the standard retrieve method
to avoid dealing with a callback method when downloading full documents given summary documents.
|
List<AnnotatedPluginDocument> |
retrieve(Query query,
ProgressListener progressListener)
Convenience method to be used instead of the standard
retrieve(Query, RetrieveCallback, com.biomatters.geneious.publicapi.documents.URN[])
method to avoid dealing with a callback method. |
abstract void |
retrieve(Query query,
RetrieveCallback callback,
URN[] urnsToNotRetrieve)
Get documents by searching a database.
|
List<AnnotatedPluginDocument> |
retrieve(String searchText)
Convenience method to be used instead of the standard retrieve method
when doing a standard textbased search and ignoring failure (by returning
an empty list) and ignoring search properties (such as e-values).
|
void |
retrieve(URN[] urnsToRetrieve,
RetrieveCallback callback)
Retrieve documents with the specified URNs.
|
void |
sequenceSearch(AnnotatedPluginDocument querySequence,
String program,
Options options,
RetrieveCallback callback)
If this is a Sequence Database (ie.
|
_shutdown, addGeneiousServiceListener, addWeakGeneiousServiceListener, canShutdown, getActionsAlwaysEnabled, getActionsEnabledWhenServiceSelected, getChildServices, getDescription, getFullPath, getGeneiousServiceListener, getHelp, getIcons, getName, getParentService, getPreferences, getServiceTreeLabel, getStatus, getUniqueID, hasShutdownOrStartedShuttingDown, initialize, initializeService, isProOnly, removeGeneiousServiceListener, showInServiceTree, shutdown, toString
public abstract QueryField[] getSearchFields()
DatabaseServiceListener.fieldsChanged()
when the fields are available.public abstract void retrieve(Query query, RetrieveCallback callback, URN[] urnsToNotRetrieve) throws DatabaseServiceException
query
- the query specifying what we are searching this DatabaseService for; must not be null.callback
- The RetrieveCallback to which to report search results (documents and progress reports); must not be null.urnsToNotRetrieve
- a set of document URN's to ignore. retrievers can save bandwidth/disk access by not downloading
documents with the same URN. Must not be null. Most implementations can ignore this method.DatabaseServiceException
- if retrieval fails for any reason. May also throw this if the callback requests the retrieve to be cancelled.NullPointerException
- A subclass may, but isn't obliged to, throw a NullPointerException if
any of the arguments (query, callback or urnsToNotRetrieve) is null.
A client shouldn't pass in null for either of this value, but a client should
also not depend for its correctness on a NullPointerException to be thrown.public void retrieve(AnnotatedPluginDocument[] summaryDocuments, RetrieveCallback callback, URN[] urnsToNotRetrieve) throws DatabaseServiceException
SummaryDocument
s
then this method must be implemented to allow the full documents to be downloaded.
summaryDocuments
- A list of summary documents.callback
- Full documents should be passed on to this callback's add method as they
are being retrieved from the database. It is an error to call any methods
on the callback after retrieve() has returned, or after
callback.setFinalStatus() has been called.urnsToNotRetrieve
- a set of document URN's to ignore. Documents matching one of these
URNs must not be passed to the callback, and to save bandwidth,
the DatabaseService should not download them from the database.DatabaseServiceException
- if retrieval fails for any reason. May also throw this if the callback requests the retrieve to be cancelled.public int locateSummaryDocument(AnnotatedPluginDocument actualDocument, AnnotatedPluginDocument[] summaryDocuments)
SummaryDocument
s
then this method must be implemented.
Locate the summary document whose download resulted in this actual document. This is so the
SummaryDocument
can be removed from the
document table once the full document has been downloaded and placed there.actualDocument
- document downloaded for that summarysummaryDocuments
- list of all summary documentspublic void addDatabaseServiceListener(DatabaseServiceListener listener)
DatabaseServiceListener
has several methods for the database service
to notify the program of changes. Store a list of listeners added through this
method and call the required functions as necessary on all of the listeners.
This method can be ignored if none of the listener methods are required.
.
The default implementation stores the listeners in a list that can be accessed
by subclasses using getDatabaseServiceListeners()
.listener
- the DatabaseServiceListenerpublic void addWeakDatabaseServiceListener(DatabaseServiceListener listener)
addWeakDatabaseServiceListener(DatabaseServiceListener)
but adds a weakly referenced listener instead.listener
- the DatabaseServiceListenerpublic void removeDatabaseServiceListener(DatabaseServiceListener listener)
addDatabaseServiceListener(DatabaseServiceListener)
or addWeakDatabaseServiceListener(DatabaseServiceListener)
.
The default implementation removes the listeners from a list that can be accessed
by subclasses using getDatabaseServiceListeners()
.listener
- the DatabaseServiceListenerprotected List<DatabaseServiceListener> getDatabaseServiceListeners()
addDatabaseServiceListener(DatabaseServiceListener)
and removeDatabaseServiceListener(DatabaseServiceListener)
store the listeners in a list that is available for subclasses using this method.public boolean isBrowsable()
public ExtendedSearchOption[] getExtendedSearchOptions(boolean isAdvancedSearch)
isAdvancedSearch
- specifies if the options returned are going be attached to
the advanced or basic search panel. This method will be called twice with true and false.
Disregard this if the extended options are to be on both basic and advanced.public void retrieve(URN[] urnsToRetrieve, RetrieveCallback callback) throws DatabaseServiceException
urnsToRetrieve
- URNs which must be the URNS of documents referenced by a previous document returned from this DatabaseServicecallback
- Used to notify when a document has been retrieved.DatabaseServiceException
- if retrieval fails for any reason. May also throw this if the callback requests the retrieve to be cancelled.public void sequenceSearch(AnnotatedPluginDocument querySequence, String program, Options options, RetrieveCallback callback) throws DatabaseServiceException
getSequenceSearchPrograms(com.biomatters.geneious.publicapi.databaseservice.DatabaseService.SequenceSearchQueryType)
returns a non-empty list) then this method
must be overridden because it will be called when the user initiates a sequence search. If this is not a sequence
database then it is not necessary to override this method.
When returning results from a search, the database service must quickly (i.e. without waiting on network I/O)
either call RetrieveCallback.setPropertyFields(java.util.List, com.biomatters.geneious.publicapi.documents.DocumentField)
or call RetrieveCallback.setFolderViewDocument(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument)
querySequence
- the query sequence, should be used as a referenced document in any results if possible.program
- the program selected by the user to use for the search (see getSequenceSearchPrograms(com.biomatters.geneious.publicapi.databaseservice.DatabaseService.SequenceSearchQueryType)
options
- the options returned from getSequenceSearchOptions(String)
after they have been displayed to the user.callback
- Used to notify when a document has been retrieved.DatabaseServiceException
public void batchSequenceSearch(List<AnnotatedPluginDocument> querySequences, String program, Options options, RetrieveCallback callback) throws DatabaseServiceException
getSequenceSearchPrograms(com.biomatters.geneious.publicapi.databaseservice.DatabaseService.SequenceSearchQueryType)
returns a non-empty list)
then this method may be overridden to allow efficient batch sequence searching.
When returning results from a search, each result set in the batch must be preceeded by a call to either
RetrieveCallback.setFolderViewDocument(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument)
or RetrieveCallback.setPropertyFields(java.util.List, com.biomatters.geneious.publicapi.documents.DocumentField)
.
If RetrieveCallback.setPropertyFields(java.util.List, com.biomatters.geneious.publicapi.documents.DocumentField)
is being used then calls to setPropertyFields must be made in the same order as the query sequences because folder
names are generated from the query sequences. If RetrieveCallback.setFolderViewDocument(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument)
is being used then the calls may be made in any order because the folder names will be the obtained by calling
PluginDocument.getName()
.
There must be exactly querySequences.size() calls to one of these methods before this method returns (unless it is cancelled or an exception is throws).
The default implementation calls sequenceSearch(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument, String, com.biomatters.geneious.publicapi.plugin.Options, RetrieveCallback)
for each query sequence.querySequences
- the query sequences, should be used as a referenced documents in any results if possible.program
- the program selected by the user to use for the search (see getSequenceSearchPrograms(com.biomatters.geneious.publicapi.databaseservice.DatabaseService.SequenceSearchQueryType)
options
- the options returned from getSequenceSearchOptions(String)
after they have been displayed to the user.callback
- Used to notify when a document has been retrieved.DatabaseServiceException
public Map<String,String> getSequenceSearchPrograms(DatabaseService.SequenceSearchQueryType queryType)
queryType
- the DatabaseService.SequenceSearchQueryType
of the query sequene.public Options getSequenceSearchOptions(String program)
program
- the program selected by the user to use for the search (see getSequenceSearchPrograms(com.biomatters.geneious.publicapi.databaseservice.DatabaseService.SequenceSearchQueryType)
public DocumentSelectionSignature[] getDocumentTypesForSequenceSearch(DatabaseService.SequenceSearchQueryType queryType, String program, Options searchOptions, boolean summaryDocumentTypes)
DocumentSelectionSignature
s describing all possible types of
documents that can be returned from a sequence search on this service. If summaryDocumentTypes
is false
then this must be the classes of the full documents after the user downloads any summary documents. If it is true
then only the classes of summary documents (if any) should be returned. If the search only returns full documents
then this method should return an empty selection signature if summaryDocumentTypes
is true.
Sequence searchable services should override this. Default implementation returns a signature matching any type
of document if summaryDocumentTypes
is false or an empty selection signature if it is true.queryType
- the DatabaseService.SequenceSearchQueryType
of the query sequene.program
- the program selected by the user to use for the search (see getSequenceSearchPrograms(com.biomatters.geneious.publicapi.databaseservice.DatabaseService.SequenceSearchQueryType)
searchOptions
- the options returned from getSequenceSearchOptions(String)
after they have been displayed to the user.summaryDocumentTypes
- If false then return the classes of the full documents after the user downloads any summary documents. If true
then return the classes of summary documents (if any).DocumentSelectionSignature
s describing all types of
documents that can be returned from a sequence search on this service.@Deprecated public void resumeSearch(String uniqueIdentifier, RetrieveCallback callback) throws DatabaseServiceException
DatabaseServiceException
public final List<AnnotatedPluginDocument> retrieve(String searchText)
searchText
- the text to search for.public final List<AnnotatedPluginDocument> retrieve(Query query, ProgressListener progressListener) throws DatabaseServiceException
retrieve(Query, RetrieveCallback, com.biomatters.geneious.publicapi.documents.URN[])
method to avoid dealing with a callback method.
This means that search properties (such as e-values) are discarded.query
- the query to search forprogressListener
- to notify about progress and to handle cancelling.DatabaseServiceException
- if anything goes wrong or the retrieval is canceledpublic final List<AnnotatedPluginDocument> retrieve(List<AnnotatedPluginDocument> summaryDocuments, ProgressListener progressListener) throws DatabaseServiceException
DatabaseService blastService = (DatabaseService) PluginUtilities.getGeneiousService("NCBI_blastn");
Map<String, Object> blastOptions = new HashMap<String, Object>();
blastOptions.put("blastDatabase", "nr"); // The database to blast
blastOptions.put("EXPECT", 0.01); // Maximum e-value to match
blastOptions.put("maxHits", 10); // Maximum number of hits returned
String queryString = "ATGGCATATCCCATACAACTAGGATT";
Query query = Query.Factory.createExtendedQuery(queryString, blastOptions);
List<AnnotatedPluginDocument> summaryDocuments = blastService.retrieve(query, ProgressListener.EMPTY);
List<AnnotatedPluginDocument> fullDocuments = blastService.retrieve(summaryDocuments, ProgressListener.EMPTY);
Note: To print a list of blast options available use this:
for (ExtendedSearchOption option : blastService.getExtendedSearchOptions(true)) {
System.out.println(option);
}
summaryDocuments
- a list of summary documents returned from a previous
retrieve(Query, RetrieveCallback, com.biomatters.geneious.publicapi.documents.URN[])
call.progressListener
- to notify about progress and to handle cancelling.DatabaseServiceException
- if any of the full documents can not be retrieved.