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