| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.ext.ensembl; |
| 22 |
|
|
| 23 |
|
import jalview.bin.Console; |
| 24 |
|
import jalview.datamodel.AlignmentI; |
| 25 |
|
import jalview.datamodel.GeneLociI; |
| 26 |
|
import jalview.datamodel.GeneLocus; |
| 27 |
|
import jalview.datamodel.Mapping; |
| 28 |
|
import jalview.util.MapList; |
| 29 |
|
|
| 30 |
|
import java.io.IOException; |
| 31 |
|
import java.net.MalformedURLException; |
| 32 |
|
import java.net.URL; |
| 33 |
|
import java.util.Arrays; |
| 34 |
|
import java.util.Collections; |
| 35 |
|
import java.util.List; |
| 36 |
|
import java.util.Map; |
| 37 |
|
|
| 38 |
|
import org.json.simple.parser.ParseException; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@author |
| 46 |
|
|
| |
|
| 0% |
Uncovered Elements: 96 (96) |
Complexity: 28 |
Complexity Density: 0.47 |
|
| 47 |
|
public class EnsemblLookup extends EnsemblRestClient |
| 48 |
|
{ |
| 49 |
|
private static final String SPECIES = "species"; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 54 |
0 |
public EnsemblLookup()... |
| 55 |
|
{ |
| 56 |
0 |
super(); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@param |
| 63 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
0 |
public EnsemblLookup(String d)... |
| 65 |
|
{ |
| 66 |
0 |
super(d); |
| 67 |
|
} |
| 68 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0 |
@Override... |
| 70 |
|
public String getDbName() |
| 71 |
|
{ |
| 72 |
0 |
return "ENSEMBL"; |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
0 |
@Override... |
| 76 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
| 77 |
|
{ |
| 78 |
0 |
return null; |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 81 |
0 |
@Override... |
| 82 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
| 83 |
|
{ |
| 84 |
0 |
String identifier = ids.get(0); |
| 85 |
0 |
return getUrl(identifier, null); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
@param |
| 93 |
|
@param |
| 94 |
|
@return |
| 95 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 96 |
0 |
protected URL getUrl(String identifier, String objectType)... |
| 97 |
|
{ |
| 98 |
0 |
String url = getDomain() + "/lookup/id/" + identifier |
| 99 |
|
+ CONTENT_TYPE_JSON; |
| 100 |
0 |
if (objectType != null) |
| 101 |
|
{ |
| 102 |
0 |
url += "&" + OBJECT_TYPE + "=" + objectType; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
0 |
try |
| 106 |
|
{ |
| 107 |
0 |
return new URL(url); |
| 108 |
|
} catch (MalformedURLException e) |
| 109 |
|
{ |
| 110 |
0 |
return null; |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 114 |
0 |
@Override... |
| 115 |
|
protected boolean useGetRequest() |
| 116 |
|
{ |
| 117 |
0 |
return true; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
@param |
| 125 |
|
@return |
| 126 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
0 |
public String getGeneId(String identifier)... |
| 128 |
|
{ |
| 129 |
0 |
return getGeneId(identifier, null); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
@param |
| 137 |
|
@param |
| 138 |
|
@return |
| 139 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 140 |
0 |
public String getGeneId(String identifier, String objectType)... |
| 141 |
|
{ |
| 142 |
0 |
return parseGeneId(getResult(identifier, objectType)); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
@param |
| 152 |
|
@return |
| 153 |
|
|
| |
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 154 |
0 |
protected String parseGeneId(Map<String, Object> val)... |
| 155 |
|
{ |
| 156 |
0 |
if (val == null) |
| 157 |
|
{ |
| 158 |
0 |
return null; |
| 159 |
|
} |
| 160 |
0 |
String geneId = null; |
| 161 |
0 |
String type = val.get(OBJECT_TYPE).toString(); |
| 162 |
0 |
if (OBJECT_TYPE_GENE.equalsIgnoreCase(type)) |
| 163 |
|
{ |
| 164 |
|
|
| 165 |
0 |
geneId = val.get(JSON_ID).toString(); |
| 166 |
|
} |
| 167 |
0 |
else if (OBJECT_TYPE_TRANSCRIPT.equalsIgnoreCase(type)) |
| 168 |
|
{ |
| 169 |
|
|
| 170 |
0 |
geneId = val.get(PARENT).toString(); |
| 171 |
|
} |
| 172 |
0 |
else if (OBJECT_TYPE_TRANSLATION.equalsIgnoreCase(type)) |
| 173 |
|
{ |
| 174 |
|
|
| 175 |
0 |
String transcriptId = val.get(PARENT).toString(); |
| 176 |
0 |
geneId = getGeneId(transcriptId, OBJECT_TYPE_TRANSCRIPT); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
0 |
return geneId; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
@param |
| 187 |
|
@return |
| 188 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 189 |
0 |
public String getSpecies(String identifier)... |
| 190 |
|
{ |
| 191 |
0 |
String species = null; |
| 192 |
0 |
Map<String, Object> json = getResult(identifier, null); |
| 193 |
0 |
if (json != null) |
| 194 |
|
{ |
| 195 |
0 |
Object o = json.get(SPECIES); |
| 196 |
0 |
if (o != null) |
| 197 |
|
{ |
| 198 |
0 |
species = o.toString(); |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
0 |
return species; |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
@param |
| 209 |
|
@param |
| 210 |
|
|
| 211 |
|
@return |
| 212 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 213 |
0 |
@SuppressWarnings("unchecked")... |
| 214 |
|
protected Map<String, Object> getResult(String identifier, |
| 215 |
|
String objectType) |
| 216 |
|
{ |
| 217 |
0 |
List<String> ids = Arrays.asList(new String[] { identifier }); |
| 218 |
|
|
| 219 |
0 |
try |
| 220 |
|
{ |
| 221 |
0 |
return (Map<String, Object>) getJSON(getUrl(identifier, objectType), |
| 222 |
|
ids, -1, MODE_MAP, null); |
| 223 |
|
} catch (IOException | ParseException e) |
| 224 |
|
{ |
| 225 |
0 |
jalview.bin.Console.errPrintln("Error parsing " + identifier |
| 226 |
|
+ " lookup response " + e.getMessage()); |
| 227 |
0 |
return null; |
| 228 |
|
} |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
@param |
| 236 |
|
@return |
| 237 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 238 |
0 |
public GeneLociI getGeneLoci(String geneId)... |
| 239 |
|
{ |
| 240 |
0 |
return parseGeneLoci(getResult(geneId, OBJECT_TYPE_GENE)); |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
|
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 248 |
|
@param |
| 249 |
|
@return |
| 250 |
|
|
| |
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 6 |
Complexity Density: 0.3 |
|
| 251 |
0 |
GeneLociI parseGeneLoci(Map<String, Object> json)... |
| 252 |
|
{ |
| 253 |
0 |
if (json == null) |
| 254 |
|
{ |
| 255 |
0 |
return null; |
| 256 |
|
} |
| 257 |
|
|
| 258 |
0 |
try |
| 259 |
|
{ |
| 260 |
0 |
final String species = json.get("species").toString(); |
| 261 |
0 |
final String assembly = json.get("assembly_name").toString(); |
| 262 |
0 |
final String chromosome = json.get("seq_region_name").toString(); |
| 263 |
0 |
String strand = json.get("strand").toString(); |
| 264 |
0 |
int start = Integer.parseInt(json.get("start").toString()); |
| 265 |
0 |
int end = Integer.parseInt(json.get("end").toString()); |
| 266 |
0 |
int fromEnd = end - start + 1; |
| 267 |
0 |
boolean reverseStrand = "-1".equals(strand); |
| 268 |
0 |
int toStart = reverseStrand ? end : start; |
| 269 |
0 |
int toEnd = reverseStrand ? start : end; |
| 270 |
0 |
List<int[]> fromRange = Collections |
| 271 |
|
.singletonList(new int[] |
| 272 |
|
{ 1, fromEnd }); |
| 273 |
0 |
List<int[]> toRange = Collections |
| 274 |
|
.singletonList(new int[] |
| 275 |
|
{ toStart, toEnd }); |
| 276 |
0 |
final Mapping map = new Mapping( |
| 277 |
|
new MapList(fromRange, toRange, 1, 1)); |
| 278 |
0 |
return new GeneLocus(species == null ? "" : species, assembly, |
| 279 |
|
chromosome, map); |
| 280 |
|
} catch (NullPointerException | NumberFormatException e) |
| 281 |
|
{ |
| 282 |
0 |
Console.error("Error looking up gene loci: " + e.getMessage()); |
| 283 |
0 |
e.printStackTrace(); |
| 284 |
|
} |
| 285 |
0 |
return null; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
} |