JAL-3253 preliminary static fixes for JavaScript part 3 of 3
[jalview.git] / src / jalview / ws / SequenceFetcher.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;
22
23 import jalview.datamodel.DBRefSource;
24 import jalview.ext.ensembl.EnsemblGene;
25 import jalview.ws.dbsources.Uniprot;
26 import jalview.ws.seqfetcher.ASequenceFetcher;
27 import jalview.ws.seqfetcher.DbSourceProxy;
28
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32
33 /**
34  * This implements the run-time discovery of sequence database clients.
35  * 
36  */
37 public class SequenceFetcher extends ASequenceFetcher
38 {
39   /**
40    * Thread safe construction of database proxies TODO: extend to a configurable
41    * database plugin mechanism where classes are instantiated by reflection and
42    * queried for their DbRefSource and version association.
43    * 
44    */
45   public SequenceFetcher()
46   {
47     addAllDatabases();
48   }
49
50   public void addAllDatabases()
51   {
52     addDBRefSourceImpl(EnsemblGene.class); // includes EnsemblGenomes.class
53     addDBRefSourceImpl(Uniprot.class); // includes UniprotName.class
54     // addDBRefSourceImpl(EmblSource.class);
55     // addDBRefSourceImpl(EmblCdsSource.class);
56     // addDBRefSourceImpl(Pdb.class);
57     // addDBRefSourceImpl(PfamFull.class);
58     // addDBRefSourceImpl(PfamSeed.class);
59     // addDBRefSourceImpl(RfamSeed.class);
60     addDBRefSourceImpl(DBRefSource.EMBL,
61             "jalview.ws.dbsources.EmblSource");
62     addDBRefSourceImpl(DBRefSource.EMBLCDS,
63             "jalview.ws.dbsources.EmblCdsSource");
64     addDBRefSourceImpl(DBRefSource.PDB, "jalview.ws.dbsources.Pdb");
65     addDBRefSourceImpl(DBRefSource.PFAM_FULL,
66             "jalview.ws.dbsources.PfamFull");
67     addDBRefSourceImpl(DBRefSource.PFAM_SEED,
68             "jalview.ws.dbsources.PfamSeed");
69     addDBRefSourceImpl(DBRefSource.RFAM_SEED,
70             "jalview.ws.dbsources.RfamSeed");
71   }
72
73   /**
74    * return an ordered list of database sources excluding alignment only
75    * databases
76    */
77   public String[] getNonAlignmentSources()
78   {
79     String[] srcs = this.getSupportedDb();
80     List<String> src = new ArrayList<>();
81     outer: for (int i = 0; i < srcs.length; i++)
82     {
83       for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
84       {
85         // Skip the alignment databases for the moment - they're not useful for
86         // verifying a single sequence against its reference source
87         if (dbs.isAlignmentSource())
88         {
89           continue outer;
90         }
91       }
92       src.add(srcs[i]);
93     }
94     Collections.sort(src, String.CASE_INSENSITIVE_ORDER);
95     return src.toArray(new String[src.size()]);
96   }
97 }