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.bin.ApplicationSingletonProvider;
24 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
25 import jalview.datamodel.DBRefSource;
26 import jalview.ext.ensembl.EnsemblGene;
27 import jalview.ws.dbsources.Uniprot;
28 import jalview.ws.seqfetcher.ASequenceFetcher;
29 import jalview.ws.seqfetcher.DbSourceProxy;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
36 * Thread safe construction of database proxies. This implements the run-time
37 * discovery of sequence database clients.
39 * TODO: extend to a configurable database plugin mechanism where classes are
40 * instantiated by reflection and queried for their DbRefSource and version
43 public class SequenceFetcher extends ASequenceFetcher implements ApplicationSingletonI
46 * set a mock fetcher here for testing only - reset to null afterwards
48 private static SequenceFetcher mockFetcher;
51 * Returns a new SequenceFetcher singleton, or a mock object if one has been
56 public static SequenceFetcher getInstance()
58 return mockFetcher != null ? mockFetcher
59 : (SequenceFetcher) ApplicationSingletonProvider
60 .getInstance(SequenceFetcher.class);
64 * Set the instance object to use (intended for unit testing with mock
67 * Be sure to reset to null in the tearDown method of any tests!
71 public static void setSequenceFetcher(SequenceFetcher sf)
78 * This public constructor is only is for use by testng to anonymously
79 * subclass SequenceFetcher.
83 public SequenceFetcher()
88 public void addAllDatabases()
90 addDBRefSourceImpl(EnsemblGene.class); // includes EnsemblGenomes.class
91 addDBRefSourceImpl(Uniprot.class); // includes UniprotName.class
92 // addDBRefSourceImpl(EmblSource.class);
93 // addDBRefSourceImpl(EmblCdsSource.class);
94 // addDBRefSourceImpl(Pdb.class);
95 // addDBRefSourceImpl(PfamFull.class);
96 // addDBRefSourceImpl(PfamSeed.class);
97 // addDBRefSourceImpl(RfamSeed.class);
98 addDBRefSourceImpl(DBRefSource.EMBL,
99 "jalview.ws.dbsources.EmblSource");
100 addDBRefSourceImpl(DBRefSource.EMBLCDS,
101 "jalview.ws.dbsources.EmblCdsSource");
102 addDBRefSourceImpl(DBRefSource.PDB, "jalview.ws.dbsources.Pdb");
103 addDBRefSourceImpl(DBRefSource.PFAM_FULL,
104 "jalview.ws.dbsources.PfamFull");
105 addDBRefSourceImpl(DBRefSource.PFAM_SEED,
106 "jalview.ws.dbsources.PfamSeed");
107 addDBRefSourceImpl(DBRefSource.RFAM_SEED,
108 "jalview.ws.dbsources.RfamSeed");
112 * return an ordered list of database sources excluding alignment only
115 public String[] getNonAlignmentSources()
117 String[] srcs = this.getSupportedDb();
118 List<String> src = new ArrayList<>();
119 outer: for (int i = 0; i < srcs.length; i++)
121 for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
123 // Skip the alignment databases for the moment - they're not useful for
124 // verifying a single sequence against its reference source
125 if (dbs.isAlignmentSource())
132 Collections.sort(src, String.CASE_INSENSITIVE_ORDER);
133 return src.toArray(new String[src.size()]);