JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / ws / seqfetcher / DbSourceProxy.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.seqfetcher;
22
23 import jalview.api.FeatureSettingsModelI;
24 import jalview.datamodel.AlignmentI;
25
26 import com.stevesoft.pat.Regex;
27
28 /**
29  * generic Reference Retrieval interface for a particular database
30  * source/version as cited in DBRefEntry.
31  * 
32  * TODO: add/define mechanism for retrieval of Trees and distance matrices from
33  * a database (unify with io)
34  * 
35  * @author JimP
36  */
37 public interface DbSourceProxy extends DbSourceProxyRoot
38 {
39   /**
40    * Short meaningful name for this data source for display in menus or
41    * selection boxes.
42    * 
43    * @return String
44    */
45   String getDbName();
46
47   /**
48    * 
49    * @return version string for this database.
50    */
51   String getDbVersion();
52
53   /**
54    * Separator between individual accession queries for a database that allows
55    * multiple IDs to be fetched in a single query. Null implies that only a
56    * single ID can be fetched at a time.
57    * 
58    * @return string for separating concatenated queries (as individually
59    *         validated by the accession validator)
60    */
61   String getAccessionSeparator();
62
63   /**
64    * Regular expression for checking form of query string understood by this
65    * source. If the Regex includes parenthesis, then the first parenthesis
66    * should yield the same accession string as the one used to annotate the
67    * sequence. This is used to match query strings to returned sequences.
68    * 
69    * @return null or a validation regex
70    */
71   Regex getAccessionValidator();
72
73   /**
74    * 
75    * @return a test/example query that can be used to validate retrieval and
76    *         parsing mechanisms
77    */
78   String getTestQuery();
79
80   /**
81    * Required for sources supporting multiple query retrieval for use with the
82    * DBRefFetcher, which attempts to limit its queries with putative accession
83    * strings for a source to only those that are likely to be valid.
84    * 
85    * @param accession
86    * @return
87    */
88   boolean isValidReference(String accession);
89
90   /**
91    * make one or more queries to the database and attempt to parse the response
92    * into an alignment
93    * 
94    * @param queries
95    *          - one or more queries for database in expected form
96    * @return null if queries were successful but result was not parsable.
97    *         Otherwise, an AlignmentI object containing properly annotated data
98    *         (e.g. sequences with accessions for this datasource)
99    * @throws Exception
100    *           - propagated from underlying transport to database (note -
101    *           exceptions are not raised if query not found in database)
102    * 
103    */
104   AlignmentI getSequenceRecords(String queries) throws Exception;
105
106   /**
107    * 
108    * @return true if a query is currently being made
109    */
110   boolean queryInProgress();
111
112   /**
113    * get the raw reponse from the last set of queries
114    * 
115    * @return one or more string buffers for each individual query
116    */
117   StringBuffer getRawRecords();
118
119   /**
120    * Tier for this data source
121    * 
122    * @return 0 - primary datasource, 1 - das primary source, 2 - secondary
123    */
124   int getTier();
125
126   /**
127    * Extracts valid accession strings from a query string. If there is an
128    * accession id validator, returns the the matched region or the first
129    * subgroup match from the matched region; else just returns the whole query.
130    * 
131    * @param query
132    * @return
133    */
134   String getAccessionIdFromQuery(String query);
135
136   /**
137    * Returns the maximum number of accession ids that can be queried in one
138    * request.
139    * 
140    * @return
141    */
142   int getMaximumQueryCount();
143
144   /**
145    * Returns true if the source may provide coding DNA i.e. sequences with
146    * implicit peptide products
147    * 
148    * @return
149    */
150   boolean isDnaCoding();
151
152   /**
153    * Answers true if the database is a source of alignments (for example, domain
154    * families)
155    * 
156    * @return
157    */
158   boolean isAlignmentSource();
159
160   /**
161    * Returns an (optional) description of the source, suitable for display as a
162    * tooltip, or null
163    * 
164    * @return
165    */
166   String getDescription();
167
168   /**
169    * Returns the preferred feature colour configuration if there is one, else
170    * null
171    * 
172    * @return
173    */
174   FeatureSettingsModelI getFeatureColourScheme();
175 }