Skip to content
Snippets Groups Projects

fix tair annotator (endpoint with old data)

Merged Piotr Gawron requested to merge bugfix/tair-annotator into master
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import lcsb.mapviewer.annotation.cache.QueryCacheInterface;
import lcsb.mapviewer.annotation.services.ExternalServiceStatus;
import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
@@ -30,15 +18,25 @@ import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.model.user.annotator.AnnotatorInputParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorOutputParameter;
import lcsb.mapviewer.model.user.annotator.BioEntityField;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* This class is responsible for connecting to
* <a href="https://rest.ensembl.org">Ensembl API</a> and annotate elements with
* information taken from this service.
*
*
*
* @author Piotr Gawron
*
*/
@Service
public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnnotator {
@@ -46,7 +44,7 @@ public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnn
/**
* Version of the rest API that is supported by this annotator.
*/
static final String SUPPORTED_VERSION = "15.7";
static final String SUPPORTED_VERSION = "15.8";
/**
* Url address of ensembl restful service.
@@ -72,19 +70,19 @@ public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnn
* Default constructor.
*/
public EnsemblAnnotatorImpl() {
super(EnsemblAnnotator.class, new Class[] { Protein.class, Rna.class, Gene.class }, false);
super(EnsemblAnnotator.class, new Class[]{Protein.class, Rna.class, Gene.class}, false);
}
@Override
public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
final ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
QueryCacheInterface cacheCopy = getCache();
final QueryCacheInterface cacheCopy = getCache();
this.setCache(null);
try {
GenericProtein proteinAlias = new GenericProtein("mock_id");
final GenericProtein proteinAlias = new GenericProtein("mock_id");
proteinAlias.addMiriamData(getExampleValidAnnotation());
annotateElement(proteinAlias);
@@ -94,7 +92,7 @@ public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnn
status.setStatus(ExternalServiceStatusType.OK);
}
String version = getRestfulApiVersion();
final String version = getRestfulApiVersion();
if (!SUPPORTED_VERSION.equals(version)) {
logger.debug("Version of Ensembl API changed... (new version: " + version + ")");
status.setStatus(ExternalServiceStatusType.CHANGED);
@@ -112,61 +110,59 @@ public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnn
* Returns current version of restful API.
*
* @return version of Ensembl restful API
* @throws IOException
* thrown when there is a problem with accessing API
* @throws InvalidXmlSchemaException
* thrown when the result returned by API is invalid
* @throws IOException thrown when there is a problem with accessing API
* @throws InvalidXmlSchemaException thrown when the result returned by API is invalid
*/
private String getRestfulApiVersion() throws IOException, InvalidXmlSchemaException {
String content = getWebPageContent(REST_SERVICE_VERSION_URL);
Node xml = XmlParser.getXmlDocumentFromString(content);
Node response = XmlParser.getNode("opt", xml.getChildNodes());
Node data = XmlParser.getNode("data", response.getChildNodes());
final String content = getWebPageContent(REST_SERVICE_VERSION_URL);
final Node xml = XmlParser.getXmlDocumentFromString(content);
final Node response = XmlParser.getNode("opt", xml.getChildNodes());
final Node data = XmlParser.getNode("data", response.getChildNodes());
String version = XmlParser.getNodeAttr("release", data);
final String version = XmlParser.getNodeAttr("release", data);
return version;
}
@Override
public boolean annotateElement(final BioEntityProxy element, final MiriamData identifier,
final AnnotatorData parameters)
final AnnotatorData parameters)
throws AnnotatorException {
if (identifier.getDataType().equals(MiriamType.ENSEMBL)) {
String query = REST_SERVICE_URL + identifier.getResource() + URL_SUFFIX;
final String query = REST_SERVICE_URL + identifier.getResource() + URL_SUFFIX;
try {
String content = getWebPageContent(query);
Node xml = XmlParser.getXmlDocumentFromString(content);
Node response = XmlParser.getNode("opt", xml.getChildNodes());
final String content = getWebPageContent(query);
final Node xml = XmlParser.getXmlDocumentFromString(content);
final Node response = XmlParser.getNode("opt", xml.getChildNodes());
NodeList list = response.getChildNodes();
Set<String> synonyms = new HashSet<String>();
final NodeList list = response.getChildNodes();
final Set<String> synonyms = new HashSet<String>();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
final Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("data")) {
String error = XmlParser.getNodeAttr("error", node);
final String error = XmlParser.getNodeAttr("error", node);
if (error != null && !error.isEmpty()) {
logger.warn(element.getLogMarker(ProjectLogEntryType.OTHER), error);
}
String dbname = XmlParser.getNodeAttr("dbname", node);
final String dbname = XmlParser.getNodeAttr("dbname", node);
if ("EntrezGene".equals(dbname)) {
String entrezId = XmlParser.getNodeAttr("primary_id", node);
final String entrezId = XmlParser.getNodeAttr("primary_id", node);
if (entrezId != null && !entrezId.isEmpty()) {
element.addMiriamData(MiriamType.ENTREZ, entrezId);
}
String symbol = XmlParser.getNodeAttr("display_id", node);
final String symbol = XmlParser.getNodeAttr("display_id", node);
if (symbol != null) {
element.setSymbol(symbol);
}
String fullName = XmlParser.getNodeAttr("description", node);
final String fullName = XmlParser.getNodeAttr("description", node);
if (fullName != null) {
element.setFullName(fullName);
}
NodeList synonymNodeList = node.getChildNodes();
final NodeList synonymNodeList = node.getChildNodes();
for (int j = 0; j < synonymNodeList.getLength(); j++) {
Node synonymNode = synonymNodeList.item(j);
final Node synonymNode = synonymNodeList.item(j);
if (synonymNode.getNodeType() == Node.ELEMENT_NODE
&& "synonyms".equalsIgnoreCase(synonymNode.getNodeName())) {
synonyms.add(synonymNode.getTextContent());
@@ -178,14 +174,14 @@ public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnn
hgncId = hgncId.replaceAll("HGNC:", "");
element.addMiriamData(MiriamType.HGNC, hgncId);
}
String hgncSymbol = XmlParser.getNodeAttr("display_id", node);
final String hgncSymbol = XmlParser.getNodeAttr("display_id", node);
if (hgncSymbol != null && !hgncSymbol.isEmpty()) {
element.addMiriamData(MiriamType.HGNC_SYMBOL, hgncId);
}
NodeList synonymNodeList = node.getChildNodes();
final NodeList synonymNodeList = node.getChildNodes();
for (int j = 0; j < synonymNodeList.getLength(); j++) {
Node synonymNode = synonymNodeList.item(j);
final Node synonymNode = synonymNodeList.item(j);
if (synonymNode.getNodeType() == Node.ELEMENT_NODE
&& "synonyms".equalsIgnoreCase(synonymNode.getNodeName())) {
synonyms.add(synonymNode.getTextContent());
@@ -223,7 +219,7 @@ public class EnsemblAnnotatorImpl extends ElementAnnotator implements EnsemblAnn
@Override
public List<AnnotatorInputParameter> getAvailableInputParameters() {
return Arrays.asList(new AnnotatorInputParameter(MiriamType.ENSEMBL));
return Collections.singletonList(new AnnotatorInputParameter(MiriamType.ENSEMBL));
}
@Override
Loading