Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.ext.ensembl

File EnsemblInfo.java

 

Coverage histogram

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

Code metrics

8
20
8
1
155
77
13
0.65
2.5
8
1.62

Classes

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