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.Instance;
24 import jalview.datamodel.DBRefSource;
25 import jalview.ext.ensembl.EnsemblGene;
26 import jalview.ws.dbsources.Uniprot;
27 import jalview.ws.seqfetcher.ASequenceFetcher;
28 import jalview.ws.seqfetcher.DbSourceProxy;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
35 * Thread safe construction of database proxies. This implements the run-time
36 * discovery of sequence database clients.
38 * TODO: extend to a configurable database plugin mechanism where classes are
39 * instantiated by reflection and queried for their DbRefSource and version
42 public class SequenceFetcher extends ASequenceFetcher
46 * Returns a new SequenceFetcher singleton, or a mock object if one has been
51 public static SequenceFetcher getInstance()
53 Instance j = Instance.getInstance();
54 return (j.sequenceFetcher == null
55 ? j.sequenceFetcher = new SequenceFetcher()
60 * Set the instance object to use (intended for unit testing with mock
63 * Be sure to reset to null in the tearDown method of any tests!
67 public static void setSequenceFetcher(SequenceFetcher sf)
69 Instance.getInstance().sequenceFetcher = sf;
74 * This public constructor is only is for use by testng to anonymously
75 * subclass SequenceFetcher.
79 public SequenceFetcher()
84 public void addAllDatabases()
86 addDBRefSourceImpl(EnsemblGene.class); // includes EnsemblGenomes.class
87 addDBRefSourceImpl(Uniprot.class); // includes UniprotName.class
88 // addDBRefSourceImpl(EmblSource.class);
89 // addDBRefSourceImpl(EmblCdsSource.class);
90 // addDBRefSourceImpl(Pdb.class);
91 // addDBRefSourceImpl(PfamFull.class);
92 // addDBRefSourceImpl(PfamSeed.class);
93 // addDBRefSourceImpl(RfamSeed.class);
94 addDBRefSourceImpl(DBRefSource.EMBL,
95 "jalview.ws.dbsources.EmblSource");
96 addDBRefSourceImpl(DBRefSource.EMBLCDS,
97 "jalview.ws.dbsources.EmblCdsSource");
98 addDBRefSourceImpl(DBRefSource.PDB, "jalview.ws.dbsources.Pdb");
99 addDBRefSourceImpl(DBRefSource.PFAM_FULL,
100 "jalview.ws.dbsources.PfamFull");
101 addDBRefSourceImpl(DBRefSource.PFAM_SEED,
102 "jalview.ws.dbsources.PfamSeed");
103 addDBRefSourceImpl(DBRefSource.RFAM_SEED,
104 "jalview.ws.dbsources.RfamSeed");
108 * return an ordered list of database sources excluding alignment only
111 public String[] getNonAlignmentSources()
113 String[] srcs = this.getSupportedDb();
114 List<String> src = new ArrayList<>();
115 outer: for (int i = 0; i < srcs.length; i++)
117 for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
119 // Skip the alignment databases for the moment - they're not useful for
120 // verifying a single sequence against its reference source
121 if (dbs.isAlignmentSource())
128 Collections.sort(src, String.CASE_INSENSITIVE_ORDER);
129 return src.toArray(new String[src.size()]);