2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import jalview.ext.ensembl.EnsemblGene;
24 import jalview.ext.ensembl.EnsemblGenomes;
25 import jalview.ws.dbsources.EmblCdsSource;
26 import jalview.ws.dbsources.EmblSource;
27 import jalview.ws.dbsources.Pdb;
28 import jalview.ws.dbsources.PfamFull;
29 import jalview.ws.dbsources.PfamSeed;
30 import jalview.ws.dbsources.RfamFull;
31 import jalview.ws.dbsources.RfamSeed;
32 import jalview.ws.dbsources.Uniprot;
33 import jalview.ws.dbsources.UniprotName;
34 import jalview.ws.dbsources.das.api.jalviewSourceI;
35 import jalview.ws.seqfetcher.ASequenceFetcher;
36 import jalview.ws.seqfetcher.DbSourceProxy;
38 import java.util.ArrayList;
39 import java.util.List;
42 * This is the the concrete implementation of the sequence retrieval interface
43 * and abstract class in jalview.ws.seqfetcher. This implements the run-time
44 * discovery of sequence database clientss.
47 public class SequenceFetcher extends ASequenceFetcher
50 * Thread safe construction of database proxies TODO: extend to a configurable
51 * database plugin mechanism where classes are instantiated by reflection and
52 * queried for their DbRefSource and version association.
55 public SequenceFetcher()
60 public SequenceFetcher(boolean addDas)
62 addDBRefSourceImpl(EnsemblGene.class);
63 addDBRefSourceImpl(EnsemblGenomes.class);
64 addDBRefSourceImpl(EmblSource.class);
65 addDBRefSourceImpl(EmblCdsSource.class);
66 addDBRefSourceImpl(Uniprot.class);
67 addDBRefSourceImpl(UniprotName.class);
68 addDBRefSourceImpl(Pdb.class);
69 addDBRefSourceImpl(PfamFull.class);
70 addDBRefSourceImpl(PfamSeed.class);
71 // ensures Seed alignment is 'default' for PFAM
72 addDBRefSourceImpl(RfamFull.class);
73 addDBRefSourceImpl(RfamSeed.class);
76 registerDasSequenceSources();
81 * return an ordered list of database sources where non-das database classes
82 * appear before das database classes
84 public String[] getOrderedSupportedSources()
86 String[] srcs = this.getSupportedDb();
87 ArrayList<String> dassrc = new ArrayList<String>(), nondas = new ArrayList<String>();
88 for (int i = 0; i < srcs.length; i++)
90 boolean das = false, skip = false;
92 for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
94 // Skip the alignment databases for the moment - they're not useful for
95 // verifying a single sequence against its reference source
96 if (dbs.isAlignmentSource())
102 nm = dbs.getDbName();
103 if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
105 if (nm.startsWith("das:"))
107 nm = nm.substring(4);
127 String[] tosort = nondas.toArray(new String[0]), sorted = nondas
128 .toArray(new String[0]);
129 for (int j = 0, jSize = sorted.length; j < jSize; j++)
131 tosort[j] = tosort[j].toLowerCase();
133 jalview.util.QuickSort.sort(tosort, sorted);
134 // construct array with all sources listed
136 srcs = new String[sorted.length + dassrc.size()];
138 for (int j = sorted.length - 1; j >= 0; j--, i++)
144 sorted = dassrc.toArray(new String[0]);
145 tosort = dassrc.toArray(new String[0]);
146 for (int j = 0, jSize = sorted.length; j < jSize; j++)
148 tosort[j] = tosort[j].toLowerCase();
150 jalview.util.QuickSort.sort(tosort, sorted);
151 for (int j = sorted.length - 1; j >= 0; j--, i++)
159 * query the currently defined DAS source registry for sequence sources and
160 * add a DasSequenceSource instance for each source to the SequenceFetcher
163 public void registerDasSequenceSources()
165 // TODO: define a context as a registry provider (either desktop,
166 // jalview.bin.cache, or something else).
167 for (jalviewSourceI source : jalview.bin.Cache.getDasSourceRegistry()
170 if (source.isSequenceSource())
172 List<DbSourceProxy> dassources = source.getSequenceSourceProxies();
173 for (DbSourceProxy seqsrc : dassources)
175 addDbRefSourceImpl(seqsrc);