*/
package jalview.ext.ensembl;
+import jalview.bin.Cache;
+
/**
* A class to behave much like EnsemblGene but referencing the ensemblgenomes
* domain and data
*/
public EnsemblGenomes()
{
- super(ENSEMBL_GENOMES_REST);
+ super();
+ setDomain(Cache.getDefault(ENSEMBL_GENOMES_DOMAIN,
+ DEFAULT_ENSEMBL_GENOMES_DOMAIN));
}
@Override
private static final String OBJECT_TYPE_GENE = "Gene";
private static final String OBJECT_TYPE = "object_type";
+ private String lastId;
+
/**
* Default constructor (to use rest.ensembl.org)
*/
try
{
URL url = getUrl(identifier);
+ if (identifier.equals(lastId))
+ {
+ System.err.println("** Ensembl lookup " + url.toString()
+ + " looping on Parent!");
+ return null;
+ }
+ lastId = identifier;
if (url != null)
{
br = getHttpResponse(url, ids);
private static final String REST_CHANGE_LOG = "https://github.com/Ensembl/ensembl-rest/wiki/Change-log";
- private static Map<String, EnsemblInfo> domainData;
-
- // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
- private static final String PING_URL = "http://rest.ensembl.org/info/ping.json";
+ private static Map<String, EnsemblInfo> domainData = new HashMap<>();
private final static long AVAILABILITY_RETEST_INTERVAL = 10000L; // 10 seconds
static
{
- domainData = new HashMap<>();
- domainData.put(ENSEMBL_REST,
- new EnsemblInfo(ENSEMBL_REST, LATEST_ENSEMBL_REST_VERSION));
- domainData.put(ENSEMBL_GENOMES_REST, new EnsemblInfo(
- ENSEMBL_GENOMES_REST, LATEST_ENSEMBLGENOMES_REST_VERSION));
+ domainData.put(DEFAULT_ENSEMBL_DOMAIN,
+ new EnsemblInfo(DEFAULT_ENSEMBL_DOMAIN, LATEST_ENSEMBL_REST_VERSION));
+ domainData.put(DEFAULT_ENSEMBL_GENOMES_DOMAIN, new EnsemblInfo(
+ DEFAULT_ENSEMBL_GENOMES_DOMAIN, LATEST_ENSEMBLGENOMES_REST_VERSION));
}
protected volatile boolean inProgress = false;
*/
public EnsemblRestClient()
{
- this(ENSEMBL_REST);
+ super();
+
+ /*
+ * initialise domain info lazily
+ */
+ if (!domainData.containsKey(ensemblDomain))
+ {
+ domainData.put(ensemblDomain,
+ new EnsemblInfo(ensemblDomain, LATEST_ENSEMBL_REST_VERSION));
+ }
+ if (!domainData.containsKey(ensemblGenomesDomain))
+ {
+ domainData.put(ensemblGenomesDomain, new EnsemblInfo(
+ ensemblGenomesDomain, LATEST_ENSEMBLGENOMES_REST_VERSION));
+ }
}
/**
boolean checkEnsembl()
{
BufferedReader br = null;
+ String pingUrl = getDomain() + "/info/ping" + CONTENT_TYPE_JSON;
try
{
// 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_JSON);
+ URL ping = new URL(pingUrl);
/*
* expect {"ping":1} if ok
} catch (Throwable t)
{
System.err.println(
- "Error connecting to " + PING_URL + ": " + t.getMessage());
+ "Error connecting to " + pingUrl + ": " + t.getMessage());
} finally
{
if (br != null)
*/
package jalview.ext.ensembl;
+import jalview.bin.Cache;
import jalview.datamodel.DBRefSource;
import jalview.ws.seqfetcher.DbSourceProxyImpl;
*/
abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
{
+ // domain properties lookup keys:
+ protected static final String ENSEMBL_DOMAIN = "ENSEMBL_DOMAIN";
+ protected static final String ENSEMBL_GENOMES_DOMAIN = "ENSEMBL_GENOMES_DOMAIN";
+
+ // domain properties default values:
+ protected static final String DEFAULT_ENSEMBL_DOMAIN = "http://rest.ensembl.org";
+ protected static final String DEFAULT_ENSEMBL_GENOMES_DOMAIN = "http://rest.ensemblgenomes.org";
+
/*
* accepts ENSG/T/E/P with 11 digits
* or ENSMUSP or similar for other species
"(ENS([A-Z]{3}|)[GTEP]{1}[0-9]{11}$)" + "|"
+ "(CCDS[0-9.]{3,}$)");
- protected static final String ENSEMBL_GENOMES_REST = "http://rest.ensemblgenomes.org";
+ protected final String ensemblGenomesDomain;
- protected static final String ENSEMBL_REST = "http://rest.ensembl.org";
+ protected final String ensemblDomain;
/*
* possible values for the 'feature' parameter of the /overlap REST service
constrained, regulatory
}
- private String domain = ENSEMBL_REST;
+ private String domain;
+
+ /**
+ * Constructor
+ */
+ public EnsemblSequenceFetcher()
+ {
+ /*
+ * the default domain names may be overridden in .jalview_properties;
+ * this allows an easy change from http to https in future if needed
+ */
+ ensemblDomain = Cache.getDefault(ENSEMBL_DOMAIN, DEFAULT_ENSEMBL_DOMAIN);
+ ensemblGenomesDomain = Cache.getDefault(ENSEMBL_GENOMES_DOMAIN,
+ DEFAULT_ENSEMBL_GENOMES_DOMAIN);
+ domain = ensemblDomain;
+ }
@Override
public String getDbSource()
{
// NB ensure Uniprot xrefs are canonicalised from "Ensembl" to "ENSEMBL"
- if (ENSEMBL_GENOMES_REST.equals(getDomain()))
+ if (ensemblGenomesDomain.equals(getDomain()))
{
return DBRefSource.ENSEMBLGENOMES;
}
package jalview.fts.service.uniprot;
+import jalview.bin.Cache;
import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
public class UniProtFTSRestClient extends FTSRestClient
{
+ private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
+
private static FTSRestClientI instance = null;
- public static final String UNIPROT_SEARCH_ENDPOINT = "http://www.uniprot.org/uniprot/?";
+ public final String uniprotSearchEndpoint;
+
+ public UniProtFTSRestClient()
+ {
+ super();
+ uniprotSearchEndpoint = Cache.getDefault("UNIPROT_DOMAIN",
+ DEFAULT_UNIPROT_DOMAIN) + "/uniprot/?";
+ }
@Override
public FTSRestResponse executeRequest(FTSRestRequest uniportRestRequest)
}
WebResource webResource = null;
- webResource = client.resource(UNIPROT_SEARCH_ENDPOINT)
+ webResource = client.resource(uniprotSearchEndpoint)
.queryParam("format", "tab")
.queryParam("columns", wantedFields)
.queryParam("limit", String.valueOf(responseSize))
String[] foundDataRow = uniProtTabDelimittedResponseString.split("\n");
if (foundDataRow != null && foundDataRow.length > 0)
{
- result = new ArrayList<FTSData>();
+ result = new ArrayList<>();
boolean firstRow = true;
for (String dataRow : foundDataRow)
{
*/
package jalview.ws.dbsources;
+import jalview.bin.Cache;
import jalview.datamodel.DBRefSource;
import com.stevesoft.pat.Regex;
*/
abstract public class Pfam extends Xfam
{
+ private static final String PFAM_DOMAIN_KEY = "PFAM_DOMAIN";
+ private static final String DEFAULT_PFAM_DOMAIN = "http://pfam.xfam.org";
public Pfam()
{
@Override
public String getAccessionSeparator()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public Regex getAccessionValidator()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public String getDbVersion()
{
- // TODO Auto-generated method stub
return null;
}
- /**
- * Returns base URL for selected Pfam alignment type
- *
- * @return PFAM URL stub for this DbSource
- */
@Override
- protected abstract String getXFAMURL();
+ protected String getDomain()
+ {
+ return Cache.getDefault(PFAM_DOMAIN_KEY, DEFAULT_PFAM_DOMAIN);
+ }
/*
* (non-Javadoc)
super();
}
- /*
- * (non-Javadoc)
- *
- * @see jalview.ws.dbsources.Pfam#getPFAMURL()
- */
- @Override
- protected String getXFAMURL()
- {
- return "http://pfam.xfam.org/family/";
-
- }
-
@Override
- public String getXFAMURLSUFFIX()
+ public String getURLSuffix()
{
return "/alignment/full";
}
super();
}
- /*
- * (non-Javadoc)
- *
- * @see jalview.ws.dbsources.Pfam#getPFAMURL()
- */
- @Override
- protected String getXFAMURL()
- {
- return "http://pfam.xfam.org/family/";
- }
-
@Override
- public String getXFAMURLSUFFIX()
+ public String getURLSuffix()
{
return "/alignment/seed";
}
*/
package jalview.ws.dbsources;
+import jalview.bin.Cache;
import jalview.datamodel.DBRefSource;
import com.stevesoft.pat.Regex;
*/
abstract public class Rfam extends Xfam
{
+ private static final String RFAM_DOMAIN_KEY = "RFAM_DOMAIN";
+
+ private static final String DEFAULT_RFAM_DOMAIN = "http://rfam.xfam.org";
+
+ @Override
+ protected String getDomain()
+ {
+ return Cache.getDefault(RFAM_DOMAIN_KEY, DEFAULT_RFAM_DOMAIN);
+ }
public Rfam()
{
@Override
public String getAccessionSeparator()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public Regex getAccessionValidator()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public String getDbVersion()
{
- // TODO Auto-generated method stub
return null;
}
- /**
- * Returns base URL for selected Rfam alignment type
- *
- * @return RFAM URL stub for this DbSource
- */
- @Override
- protected abstract String getXFAMURL();
-
/*
* (non-Javadoc)
*
super();
}
- /*
- * (non-Javadoc)
- *
- * @see jalview.ws.dbsources.Rfam#getXFAMURL()
- */
- @Override
- protected String getXFAMURL()
- {
- return "http://rfam.xfam.org/family/";
-
- }
-
@Override
- public String getXFAMURLSUFFIX()
+ public String getURLSuffix()
{
return "/alignment/full";
}
super();
}
- /*
- * (non-Javadoc)
- *
- * @see jalview.ws.dbsources.Rfam#getRFAMURL()
- */
- @Override
- protected String getXFAMURL()
- {
- return "http://rfam.xfam.org/family/";
- }
-
@Override
- public String getXFAMURLSUFFIX()
+ public String getURLSuffix()
{
// to download gzipped file add '?gzip=1'
return "/alignment/stockholm";
*/
package jalview.ws.dbsources;
+import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
*/
public class Uniprot extends DbSourceProxyImpl
{
+ private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
+
private static final String BAR_DELIMITER = "|";
/*
super();
}
+ private String getDomain()
+ {
+ return Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN);
+ }
+
/*
* (non-Javadoc)
*
"(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
AlignmentI al = null;
- String downloadstring = "http://www.uniprot.org/uniprot/" + queries
+ String downloadstring = getDomain() + "/uniprot/" + queries
+ ".xml";
URL url = null;
URLConnection urlconn = null;
super();
}
- protected abstract String getXFAMURL();
+ protected abstract String getDomain();
@Override
public abstract String getDbVersion();
// retrieved.
startQuery();
// TODO: trap HTTP 404 exceptions and return null
- String xfamUrl = getXFAMURL() + queries.trim().toUpperCase()
- + getXFAMURLSUFFIX();
+ String xfamUrl = getURL(queries);
if (Cache.log != null)
{
return rcds;
}
+ String getURL(String queries)
+ {
+ return getDomain() + "/family/" + queries.trim().toUpperCase()
+ + getURLSuffix();
+ }
+
/**
* Pfam and Rfam provide alignments
*/
*
* @return "" for most Xfam sources
*/
- public String getXFAMURLSUFFIX()
+ public String getURLSuffix()
{
return "";
}
import static org.testng.AssertJUnit.assertTrue;
import jalview.api.FeatureSettingsModelI;
+import jalview.bin.Cache;
import jalview.datamodel.SequenceDummy;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
@BeforeClass(alwaysRun = true)
public void setUp()
{
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
}
--- /dev/null
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class PfamFullTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ }
+
+ @Test(groups = "Functional")
+ public void testGetURL()
+ {
+ // with default value for domain
+ String url = new PfamFull().getURL(" abc ");
+ assertEquals(url, "http://pfam.xfam.org/family/ABC/alignment/full");
+
+ // with override in properties
+ Cache.setProperty("PFAM_DOMAIN", "https://pfam.xfam.org");
+ url = new PfamFull().getURL(" abc ");
+ assertEquals(url, "https://pfam.xfam.org/family/ABC/alignment/full");
+ }
+}
--- /dev/null
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class PfamSeedTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ }
+
+ @Test(groups = "Functional")
+ public void testGetURL()
+ {
+ // with default value for domain
+ String url = new PfamSeed().getURL(" abc ");
+ assertEquals(url, "http://pfam.xfam.org/family/ABC/alignment/seed");
+
+ // with override in properties
+ Cache.setProperty("PFAM_DOMAIN", "https://pfam.xfam.org");
+ url = new PfamSeed().getURL(" abc ");
+ assertEquals(url, "https://pfam.xfam.org/family/ABC/alignment/seed");
+ }
+}
--- /dev/null
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class RfamFullTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ }
+
+ @Test(groups = "Functional")
+ public void testGetURL()
+ {
+ // with default value for domain
+ String url = new RfamFull().getURL(" abc ");
+ assertEquals(url, "http://rfam.xfam.org/family/ABC/alignment/full");
+
+ // with override in properties
+ Cache.setProperty("RFAM_DOMAIN", "https://rfam.xfam.org");
+ url = new RfamFull().getURL(" abc ");
+ assertEquals(url, "https://rfam.xfam.org/family/ABC/alignment/full");
+ }
+}
--- /dev/null
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class RfamSeedTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ }
+
+ @Test(groups = "Functional")
+ public void testGetURL()
+ {
+ // with default value for domain
+ String url = new RfamSeed().getURL(" abc ");
+ assertEquals(url,
+ "http://rfam.xfam.org/family/ABC/alignment/stockholm");
+
+ // with override in properties
+ Cache.setProperty("RFAM_DOMAIN", "https://rfam.xfam.org");
+ url = new RfamSeed().getURL(" abc ");
+ assertEquals(url,
+ "https://rfam.xfam.org/family/ABC/alignment/stockholm");
+ }
+}
@Test(groups = { "External" })
public void testPfamFullAndSeed() throws Exception
{
- PfamFull pff = new PfamFull();
+ Pfam pff = new PfamFull();
PfamSeed pfseed = new PfamSeed();
AlignmentI fullpf = pff.getSequenceRecords(pff.getTestQuery());