Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.ext.ensembl

File EnsemblInfo.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

8
20
8
1
164
83
13
0.65
2.5
8
1.62

Classes

Class Line # Actions
EnsemblInfo 41 20 13
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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.ext.ensembl;
22   
23    import java.util.Locale;
24   
25    import jalview.datamodel.AlignmentI;
26    import jalview.datamodel.DBRefSource;
27    import jalview.util.JSONUtils;
28   
29    import java.io.BufferedReader;
30    import java.io.IOException;
31    import java.net.MalformedURLException;
32    import java.net.URL;
33    import java.util.HashMap;
34    import java.util.Iterator;
35    import java.util.List;
36    import java.util.Map;
37    import java.util.Set;
38   
39    import org.json.simple.parser.ParseException;
40   
 
41    public class EnsemblInfo extends EnsemblRestClient
42    {
43   
44    /*
45    * cached results of REST /info/divisions service, currently
46    * <pre>
47    * {
48    * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
49    * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
50    * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
51    * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
52    * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
53    * "ENSEMBL", "http://rest.ensembl.org" }
54    * }
55    * </pre>
56    * The values for EnsemblGenomes are retrieved by a REST call, that for
57    * Ensembl is added programmatically for convenience of lookup
58    */
59    private static Map<String, String> divisions;
60   
 
61  0 toggle @Override
62    public String getDbName()
63    {
64  0 return "ENSEMBL";
65    }
66   
 
67  0 toggle @Override
68    public AlignmentI getSequenceRecords(String queries) throws Exception
69    {
70  0 return null;
71    }
72   
 
73  0 toggle @Override
74    protected URL getUrl(List<String> ids) throws MalformedURLException
75    {
76  0 return null;
77    }
78   
 
79  0 toggle @Override
80    protected boolean useGetRequest()
81    {
82  0 return true;
83    }
84   
85    /**
86    * Answers the domain (http://rest.ensembl.org or
87    * http://rest.ensemblgenomes.org) for the given division, or null if not
88    * recognised by Ensembl.
89    *
90    * @param division
91    * @return
92    */
 
93  0 toggle public String getDomain(String division)
94    {
95  0 if (divisions == null)
96    {
97  0 fetchDivisions();
98    }
99  0 return divisions.get(division.toUpperCase(Locale.ROOT));
100    }
101   
102    /**
103    * On first request only, populate the lookup map by fetching the list of
104    * divisions known to EnsemblGenomes.
105    */
 
106  0 toggle void fetchDivisions()
107    {
108  0 divisions = new HashMap<>();
109   
110    /*
111    * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
112    */
113  0 divisions.put(DBRefSource.ENSEMBL.toUpperCase(Locale.ROOT),
114    ensemblDomain);
115  0 try
116    {
117  0 @SuppressWarnings("unchecked")
118    Iterator<Object> rvals = (Iterator<Object>) getJSON(
119    getDivisionsUrl(ensemblGenomesDomain), null, -1,
120    MODE_ITERATOR, null);
121  0 if (rvals == null)
122  0 return;
123  0 while (rvals.hasNext())
124    {
125  0 String division = rvals.next().toString();
126  0 divisions.put(division.toUpperCase(Locale.ROOT),
127    ensemblGenomesDomain);
128    }
129    } catch (IOException | ParseException | NumberFormatException e)
130    {
131    // ignore
132    }
133    }
134   
135    /**
136    * Constructs the URL for the EnsemblGenomes /info/divisions REST service
137    *
138    * @param domain
139    * TODO
140    *
141    * @return
142    * @throws MalformedURLException
143    */
 
144  0 toggle URL getDivisionsUrl(String domain) throws MalformedURLException
145    {
146  0 return new URL(
147    domain + "/info/divisions?content-type=application/json");
148    }
149   
150    /**
151    * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
152    *
153    * @return
154    */
 
155  0 toggle public Set<String> getDivisions()
156    {
157  0 if (divisions == null)
158    {
159  0 fetchDivisions();
160    }
161   
162  0 return divisions.keySet();
163    }
164    }