From 3eb959d7f16b64260b8bec08d49b28ffc9670517 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 20 Oct 2017 14:05:40 +0100 Subject: [PATCH] JAL-2253 pull up constant, additional unit test --- src/jalview/ext/ensembl/EnsemblGenomes.java | 1 + src/jalview/ext/ensembl/EnsemblLookup.java | 2 +- src/jalview/ext/ensembl/EnsemblRestClient.java | 11 +++++------ src/jalview/ext/ensembl/EnsemblSymbol.java | 15 ++++++++++----- src/jalview/ext/ensembl/EnsemblXref.java | 2 +- test/jalview/ext/ensembl/EnsemblGeneTest.java | 24 ++++++++++++++++++++++++ 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/jalview/ext/ensembl/EnsemblGenomes.java b/src/jalview/ext/ensembl/EnsemblGenomes.java index 5a390f2..b40df50 100644 --- a/src/jalview/ext/ensembl/EnsemblGenomes.java +++ b/src/jalview/ext/ensembl/EnsemblGenomes.java @@ -44,6 +44,7 @@ public class EnsemblGenomes extends EnsemblGene return "EnsemblGenomes"; } + private String Wrong[]; @Override public String getTestQuery() { diff --git a/src/jalview/ext/ensembl/EnsemblLookup.java b/src/jalview/ext/ensembl/EnsemblLookup.java index 6e824cc..31da9c0 100644 --- a/src/jalview/ext/ensembl/EnsemblLookup.java +++ b/src/jalview/ext/ensembl/EnsemblLookup.java @@ -94,7 +94,7 @@ public class EnsemblLookup extends EnsemblRestClient protected URL getUrl(String identifier) { String url = getDomain() + "/lookup/id/" + identifier - + "?content-type=application/json"; + + CONTENT_TYPE_JSON; try { return new URL(url); diff --git a/src/jalview/ext/ensembl/EnsemblRestClient.java b/src/jalview/ext/ensembl/EnsemblRestClient.java index 17f9986..6384120 100644 --- a/src/jalview/ext/ensembl/EnsemblRestClient.java +++ b/src/jalview/ext/ensembl/EnsemblRestClient.java @@ -74,6 +74,8 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher private final static long VERSION_RETEST_INTERVAL = 1000L * 3600; // 1 hr + protected static final String CONTENT_TYPE_JSON = "?content-type=application/json"; + static { domainData = new HashMap(); @@ -164,8 +166,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher { // note this format works for both ensembl and ensemblgenomes // info/ping.json works for ensembl only (March 2016) - URL ping = new URL( - getDomain() + "/info/ping?content-type=application/json"); + URL ping = new URL(getDomain() + "/info/ping" + CONTENT_TYPE_JSON); /* * expect {"ping":1} if ok @@ -455,8 +456,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher URL url = null; try { - url = new URL( - getDomain() + "/info/rest?content-type=application/json"); + url = new URL(getDomain() + "/info/rest" + CONTENT_TYPE_JSON); BufferedReader br = getHttpResponse(url, null); if (br == null) { @@ -522,8 +522,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher URL url = null; try { - url = new URL( - getDomain() + "/info/data?content-type=application/json"); + url = new URL(getDomain() + "/info/data" + CONTENT_TYPE_JSON); BufferedReader br = getHttpResponse(url, null); if (br != null) { diff --git a/src/jalview/ext/ensembl/EnsemblSymbol.java b/src/jalview/ext/ensembl/EnsemblSymbol.java index 671bfec..7862fce 100644 --- a/src/jalview/ext/ensembl/EnsemblSymbol.java +++ b/src/jalview/ext/ensembl/EnsemblSymbol.java @@ -42,6 +42,10 @@ import org.json.simple.parser.ParseException; */ public class EnsemblSymbol extends EnsemblXref { + private static final String GENE = "gene"; + private static final String TYPE = "type"; + private static final String ID = "id"; + /** * Constructor given the target domain to fetch data from * @@ -73,9 +77,9 @@ public class EnsemblSymbol extends EnsemblXref while (rvals.hasNext()) { JSONObject val = (JSONObject) rvals.next(); - String id = val.get("id").toString(); - String type = val.get("type").toString(); - if (id != null && "gene".equals(type)) + String id = val.get(ID).toString(); + String type = val.get(TYPE).toString(); + if (id != null && GENE.equals(type)) { result = id; break; @@ -105,7 +109,7 @@ public class EnsemblSymbol extends EnsemblXref StringBuilder sb = new StringBuilder(); sb.append(getDomain()).append("/xrefs/symbol/") .append(species.toString()).append("/").append(id) - .append("?content-type=application/json"); + .append(CONTENT_TYPE_JSON); for (String t : type) { sb.append("&object_type=").append(t); @@ -143,13 +147,14 @@ public class EnsemblSymbol extends EnsemblXref { if (taxon.isModelOrganism()) { - URL url = getUrl(query, taxon, "gene"); + URL url = getUrl(query, taxon, GENE); if (url != null) { br = getHttpResponse(url, ids); if (br != null) { String geneId = parseSymbolResponse(br); + System.out.println(url + " returned " + geneId); if (geneId != null && !result.contains(geneId)) { result.add(geneId); diff --git a/src/jalview/ext/ensembl/EnsemblXref.java b/src/jalview/ext/ensembl/EnsemblXref.java index 9634ad3..bf77cd0 100644 --- a/src/jalview/ext/ensembl/EnsemblXref.java +++ b/src/jalview/ext/ensembl/EnsemblXref.java @@ -211,7 +211,7 @@ class EnsemblXref extends EnsemblRestClient protected URL getUrl(String identifier) { String url = getDomain() + "/xrefs/id/" + identifier - + "?content-type=application/json&all_levels=1"; + + CONTENT_TYPE_JSON + "&all_levels=1"; try { return new URL(url); diff --git a/test/jalview/ext/ensembl/EnsemblGeneTest.java b/test/jalview/ext/ensembl/EnsemblGeneTest.java index a8c491c..5920b89 100644 --- a/test/jalview/ext/ensembl/EnsemblGeneTest.java +++ b/test/jalview/ext/ensembl/EnsemblGeneTest.java @@ -296,4 +296,28 @@ public class EnsemblGeneTest assertEquals(-1, fc.compare("coding_exon", "feature_variant")); assertEquals(1f, fc.getTransparency()); } + + @Test(groups = "Network") + public void testGetGeneIds() + { + /* + * ENSG00000158828 gene id PINK1 human + * ENST00000321556 transcript for the same gene - should not be duplicated + * P30419 Uniprot identifier for ENSG00000136448 + * ENST00000592782 transcript for Uniprot gene - should not be duplicated + * BRAF - gene name resolvabe (at time of writing) for 6 model species + */ + String ids = "ENSG00000158828 ENST00000321556 P30419 ENST00000592782 BRAF"; + EnsemblGene testee = new EnsemblGene(); + List geneIds = testee.getGeneIds(ids); + assertEquals(8, geneIds.size()); + assertTrue(geneIds.contains("ENSG00000158828")); + assertTrue(geneIds.contains("ENSG00000136448")); + assertTrue(geneIds.contains("ENSG00000157764")); // BRAF human + assertTrue(geneIds.contains("ENSMUSG00000002413")); // mouse + assertTrue(geneIds.contains("ENSRNOG00000010957")); // rat + assertTrue(geneIds.contains("ENSXETG00000004845")); // xenopus + assertTrue(geneIds.contains("ENSDARG00000017661")); // zebrafish + assertTrue(geneIds.contains("ENSGALG00000012865")); // chicken + } } -- 1.7.10.2