JAL-3193 no separatge EnsemblGenomes source in SequenceFetcher
[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.ext.ensembl.EnsemblGene;
24 import jalview.ws.dbsources.EmblCdsSource;
25 import jalview.ws.dbsources.EmblSource;
26 import jalview.ws.dbsources.Pdb;
27 import jalview.ws.dbsources.PfamFull;
28 import jalview.ws.dbsources.PfamSeed;
29 import jalview.ws.dbsources.RfamSeed;
30 import jalview.ws.dbsources.Uniprot;
31 import jalview.ws.seqfetcher.ASequenceFetcher;
32 import jalview.ws.seqfetcher.DbSourceProxy;
33
34 import java.util.ArrayList;
35
36 /**
37  * This implements the run-time discovery of sequence database clients.
38  * 
39  */
40 public class SequenceFetcher extends ASequenceFetcher
41 {
42   /**
43    * Thread safe construction of database proxies TODO: extend to a configurable
44    * database plugin mechanism where classes are instantiated by reflection and
45    * queried for their DbRefSource and version association.
46    * 
47    */
48   public SequenceFetcher()
49   {
50     addDBRefSourceImpl(EnsemblGene.class);
51     // addDBRefSourceImpl(EnsemblGenomes.class);
52     addDBRefSourceImpl(EmblSource.class);
53     addDBRefSourceImpl(EmblCdsSource.class);
54     addDBRefSourceImpl(Uniprot.class);
55     addDBRefSourceImpl(Pdb.class);
56     addDBRefSourceImpl(PfamFull.class);
57     addDBRefSourceImpl(PfamSeed.class);
58     addDBRefSourceImpl(RfamSeed.class);
59   }
60
61   /**
62    * return an ordered list of database sources excluding alignment only databases
63    */
64   public String[] getOrderedSupportedSources()
65   {
66     String[] srcs = this.getSupportedDb();
67     ArrayList<String> src = new ArrayList<>();
68
69     for (int i = 0; i < srcs.length; i++)
70     {
71       boolean skip = false;
72       for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
73       {
74         // Skip the alignment databases for the moment - they're not useful for
75         // verifying a single sequence against its reference source
76         if (dbs.isAlignmentSource())
77         {
78           skip = true;
79         }
80       }
81       if (skip)
82       {
83         continue;
84       }
85       {
86         src.add(srcs[i]);
87       }
88     }
89     String[] tosort = src.toArray(new String[0]),
90             sorted = src.toArray(new String[0]);
91     for (int j = 0, jSize = sorted.length; j < jSize; j++)
92     {
93       tosort[j] = tosort[j].toLowerCase();
94     }
95     jalview.util.QuickSort.sort(tosort, sorted);
96     // construct array with all sources listed
97     int i = 0;
98     for (int j = sorted.length - 1; j >= 0; j--, i++)
99     {
100       srcs[i] = sorted[j];
101     }
102     return srcs;
103   }
104 }