Skip to content
Snippets Groups Projects
Commit 42d357fb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

update on recon annotator after changes in API

parent 6268a955
No related branches found
No related tags found
1 merge request!273Resolve "submenu of right click context menu doesn't work on touch table"
...@@ -35,244 +35,305 @@ import lcsb.mapviewer.modelutils.map.ElementUtils; ...@@ -35,244 +35,305 @@ import lcsb.mapviewer.modelutils.map.ElementUtils;
*/ */
public class ReconAnnotator extends ElementAnnotator implements IExternalService { public class ReconAnnotator extends ElementAnnotator implements IExternalService {
/** /**
* Address of annotation rest service for elements. * Address of annotation rest service for elements.
*/ */
private static final String ELEMENT_ANNOTATION_URL_PREFIX = "https://vmh.uni.lu/_api/metabolites/?page_size=10000&format=json&search="; private static final String ELEMENT_ANNOTATION_URL_PREFIX = "https://vmh.uni.lu/_api/metabolites/?page_size=10000&format=json&search=";
/** /**
* Address of annotation rest service for reactions. * Address of annotation rest service for reactions.
*/ */
private static final String REACTION_ANNOTATION_URL_PREFIX = "https://vmh.uni.lu/_api/reactions/?page_size=10000&format=json&search="; private static final String REACTION_ANNOTATION_URL_PREFIX = "https://vmh.uni.lu/_api/reactions/?page_size=10000&format=json&search=";
/** /**
* Class used for some simple operations on {@link BioEntity} elements. * Class used for some simple operations on {@link BioEntity} elements.
*/ */
private ElementUtils elementUtils = new ElementUtils(); private ElementUtils elementUtils = new ElementUtils();
@Override @Override
public String refreshCacheQuery(Object query) throws SourceNotAvailable { public String refreshCacheQuery(Object query) throws SourceNotAvailable {
String name; String name;
String result = null; String result = null;
if (query instanceof String) { if (query instanceof String) {
name = (String) query; name = (String) query;
if (name.startsWith("http")) { if (name.startsWith("http")) {
try { try {
result = getWebPageContent(name); result = getWebPageContent(name);
} catch (IOException e) { } catch (IOException e) {
throw new SourceNotAvailable(e); throw new SourceNotAvailable(e);
} }
} else { } else {
throw new InvalidArgumentException("Don't know what to do with string \"" + query + "\""); throw new InvalidArgumentException("Don't know what to do with string \"" + query + "\"");
} }
} else { } else {
throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass());
} }
return result; return result;
} }
/** /**
* Default class logger. * Default class logger.
*/ */
private static Logger logger = Logger.getLogger(ReconAnnotator.class); private static Logger logger = Logger.getLogger(ReconAnnotator.class);
/** /**
* Default constructor. * Default constructor.
*/ */
public ReconAnnotator() { public ReconAnnotator() {
super(ReconAnnotator.class, new Class[] { Chemical.class, Reaction.class }, false); super(ReconAnnotator.class, new Class[] { Chemical.class, Reaction.class }, false);
} }
@Override @Override
public ExternalServiceStatus getServiceStatus() { public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
GeneralCacheInterface cacheCopy = getCache(); GeneralCacheInterface cacheCopy = getCache();
this.setCache(null); this.setCache(null);
EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); EventStorageLoggerAppender appender = new EventStorageLoggerAppender();
Logger.getRootLogger().addAppender(appender); Logger.getRootLogger().addAppender(appender);
try { try {
SimpleMolecule smallMoleculeAlias = new SimpleMolecule("some_id"); SimpleMolecule smallMoleculeAlias = new SimpleMolecule("some_id");
smallMoleculeAlias.setName("h2o"); smallMoleculeAlias.setName("h2o");
annotateElement(smallMoleculeAlias); annotateElement(smallMoleculeAlias);
status.setStatus(ExternalServiceStatusType.OK); status.setStatus(ExternalServiceStatusType.OK);
if (smallMoleculeAlias.getMiriamData().size() == 0) { if (smallMoleculeAlias.getMiriamData().size() == 0) {
status.setStatus(ExternalServiceStatusType.CHANGED); status.setStatus(ExternalServiceStatusType.CHANGED);
} else if (appender.getWarnings().size() > 0) { } else if (appender.getWarnings().size() > 0) {
status.setStatus(ExternalServiceStatusType.CHANGED); status.setStatus(ExternalServiceStatusType.CHANGED);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(status.getName() + " is down", e); logger.error(status.getName() + " is down", e);
status.setStatus(ExternalServiceStatusType.DOWN); status.setStatus(ExternalServiceStatusType.DOWN);
} }
Logger.getRootLogger().removeAppender(appender); Logger.getRootLogger().removeAppender(appender);
this.setCache(cacheCopy); this.setCache(cacheCopy);
return status; return status;
} }
@Override @Override
public void annotateElement(BioEntity annotatedObject) throws AnnotatorException { public void annotateElement(BioEntity annotatedObject) throws AnnotatorException {
if (isAnnotatable(annotatedObject)) { if (isAnnotatable(annotatedObject)) {
String id = annotatedObject.getAbbreviation(); String id = annotatedObject.getAbbreviation();
if (id == null || id.isEmpty()) { if (id == null || id.isEmpty()) {
id = annotatedObject.getName(); id = annotatedObject.getName();
} }
if (id.indexOf("[") > 0) { if (id.indexOf("[") > 0) {
id = id.substring(0, id.indexOf("[")); id = id.substring(0, id.indexOf("["));
} }
if (id.indexOf(" ") >= 0) { if (id.indexOf(" ") >= 0) {
String[] tmp = id.split(" "); String[] tmp = id.split(" ");
id = tmp[tmp.length - 1]; id = tmp[tmp.length - 1];
} }
String url = null; String url = null;
if (annotatedObject instanceof Element) { if (annotatedObject instanceof Element) {
url = ELEMENT_ANNOTATION_URL_PREFIX + id; url = ELEMENT_ANNOTATION_URL_PREFIX + id;
} else if (annotatedObject instanceof Reaction) { } else if (annotatedObject instanceof Reaction) {
url = REACTION_ANNOTATION_URL_PREFIX + id; url = REACTION_ANNOTATION_URL_PREFIX + id;
} else { } else {
logger.warn("Unknown class type: " + annotatedObject.getClass()); logger.warn("Unknown class type: " + annotatedObject.getClass());
return; return;
} }
try { try {
String content = getWebPageContent(url); String content = getWebPageContent(url);
String prefix = elementUtils.getElementTag(annotatedObject, this); String prefix = elementUtils.getElementTag(annotatedObject, this);
if (!content.isEmpty()) { if (!content.isEmpty()) {
JsonElement jelement = new JsonParser().parse(content); JsonElement jelement = new JsonParser().parse(content);
JsonObject jobject = jelement.getAsJsonObject(); JsonObject jobject = jelement.getAsJsonObject();
if (jobject.get("results").getAsJsonArray().size() > 0) { if (jobject.get("results").getAsJsonArray().size() > 0) {
jobject = jobject.get("results").getAsJsonArray().get(0).getAsJsonObject(); jobject = jobject.get("results").getAsJsonArray().get(0).getAsJsonObject();
for (Entry<String, JsonElement> entry : jobject.entrySet()) { for (Entry<String, JsonElement> entry : jobject.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
String value = null; String value = null;
if (!entry.getValue().isJsonNull()) { if (!entry.getValue().isJsonNull()) {
// if (entry.getValue().isJsonPrimitive()) { // if (entry.getValue().isJsonPrimitive()) {
value = entry.getValue().getAsString().trim(); value = entry.getValue().getAsString().trim();
} }
if (value == null || value.isEmpty()) { if (value == null || value.isEmpty()) {
continue; continue;
} }
boolean unknown = false; boolean unknown = false;
if (key.equals("url")) { if (key.equals("url")) {
continue; continue;
} else if (key.equals("rxn_id")) { } else if (key.equals("rxn_id")) {
continue; continue;
} else if (key.equals("abbreviation")) { } else if (key.equals("abbreviation")) {
setAbbreviation(annotatedObject, value, prefix); setAbbreviation(annotatedObject, value, prefix);
} else if (key.equals("description")) { } else if (key.equals("description")) {
setDescription(annotatedObject, value); setDescription(annotatedObject, value);
} else if (key.equals("formula")) { } else if (key.equals("formula")) {
setFormula(annotatedObject, value, prefix); setFormula(annotatedObject, value, prefix);
} else if (key.equals("reversible")) { } else if (key.equals("reversible")) {
continue; continue;
} else if (key.equals("mcs")) { } else if (key.equals("mcs")) {
if (annotatedObject instanceof Reaction) { if (annotatedObject instanceof Reaction) {
setMcs((Reaction) annotatedObject, value, prefix); setMcs((Reaction) annotatedObject, value, prefix);
} else { } else {
unknown = true; unknown = true;
} }
} else if (key.equals("notes")) { } else if (key.equals("notes")) {
setDescription(annotatedObject, value); setDescription(annotatedObject, value);
} else if (key.equals("ecnumber")) { } else if (key.equals("ecnumber")) {
addEcMiriam(annotatedObject, value); addEcMiriam(annotatedObject, value);
} else if (key.equals("ref")) { } else if (key.equals("ref")) {
continue; continue;
} else if (key.equals("lastModified")) { } else if (key.equals("lastModified")) {
continue; continue;
} else if (key.equals("met_id")) { } else if (key.equals("met_id")) {
continue; continue;
} else if (key.equals("csecoida")) { } else if (key.equals("csecoida")) {
continue; continue;
} else if (key.equals("chargedFormula")) { } else if (key.equals("chargedFormula")) {
setFormula(annotatedObject, value, prefix); setFormula(annotatedObject, value, prefix);
} else if (key.equals("charge")) { } else if (key.equals("charge")) {
if (annotatedObject instanceof Species) { if (annotatedObject instanceof Species) {
setCharge((Species) annotatedObject, value, prefix); setCharge((Species) annotatedObject, value, prefix);
} else { } else {
unknown = true; unknown = true;
} }
} else if (key.equals("inchiString")) { } else if (key.equals("inchiString")) {
if (annotatedObject instanceof Chemical) { if (annotatedObject instanceof Chemical) {
setInchi((Chemical) annotatedObject, value, prefix); setInchi((Chemical) annotatedObject, value, prefix);
} else { } else {
unknown = true; unknown = true;
} }
} else if (key.equals("cheBlId")) { } else if (key.equals("cheBlId")) {
addChebiMiriam(annotatedObject, value); addChebiMiriam(annotatedObject, value);
} else if (key.equals("subsystem")) { } else if (key.equals("subsystem")) {
if (annotatedObject instanceof Reaction) { if (annotatedObject instanceof Reaction) {
setSubsystem((Reaction) annotatedObject, value, prefix); setSubsystem((Reaction) annotatedObject, value, prefix);
} else { } else {
unknown = true; unknown = true;
} }
} else if (key.equals("keggId")) { } else if (key.equals("keggId")) {
addKeggMiriam(annotatedObject, value, prefix); addKeggMiriam(annotatedObject, value, prefix);
} else if (key.equals("fullName")) { } else if (key.equals("fullName")) {
if (annotatedObject instanceof Element) { if (annotatedObject instanceof Element) {
setFullName((Element) annotatedObject, value, prefix); setFullName((Element) annotatedObject, value, prefix);
} else { } else {
unknown = true; unknown = true;
} }
} else if (key.equals("keggorthology")) { } else if (key.equals("keggorthology")) {
addKeggMiriam(annotatedObject, value, prefix); addKeggMiriam(annotatedObject, value, prefix);
} else if (key.equals("pubChemId")) { } else if (key.equals("pubChemId")) {
addPubchemMiriam(annotatedObject, value); addPubchemMiriam(annotatedObject, value);
} else if (key.equals("hmdb")) { } else if (key.equals("hmdb")) {
addHmdbMiriam(annotatedObject, value); addHmdbMiriam(annotatedObject, value);
} else if (key.equals("cog")) { } else if (key.equals("cog")) {
addCogMiriam(annotatedObject, value); addCogMiriam(annotatedObject, value);
} else if (key.equals("synonyms")) { } else if (key.equals("synonyms")) {
List<String> synonyms = new ArrayList<>(); List<String> synonyms = new ArrayList<>();
for (String str : value.split(",")) { for (String str : value.split(",")) {
synonyms.add(str); synonyms.add(str);
} }
setSynonyms(annotatedObject, synonyms, prefix); setSynonyms(annotatedObject, synonyms, prefix);
} else if (key.equals("pdmapName")) { } else if (key.equals("pdmapName")) {
// for now we skip it... // for now we skip it...
continue; continue;
} else if (key.equals("reconMap")) { } else if (key.equals("reconMap")) {
// for now we don't handle it // for now we don't handle it
continue; continue;
} else { } else if (key.equals("reconMap3")) {
unknown = true; // for now we don't handle it
} continue;
if (unknown) { } else if (key.equals("massbalance")) {
logger.warn(prefix + "Unknown field in recon annotation: \"" + key + "\" (value: " + value + ")"); // for now we don't handle it
} continue;
} } else if (key.equals("isHuman")) {
} else { // for now we don't handle it
logger.warn(prefix + "No recon annotations \"" + id + "\""); continue;
} } else if (key.equals("isMicrobe")) {
} else { // for now we don't handle it
logger.warn(prefix + "No recon annotations \"" + id + "\""); continue;
} } else if (key.equals("iupac")) {
} catch (IOException e) { // for now we don't handle it
throw new AnnotatorException(e); continue;
} } else if (key.equals("avgmolweight")) {
} // for now we don't handle it
} continue;
} else if (key.equals("monoisotopicweight")) {
// for now we don't handle it
continue;
} else if (key.equals("miriam")) {
addMiriam(annotatedObject, value, prefix);
} else if (key.equals("biggId")) {
// for now we don't handle it
continue;
} else if (key.equals("lmId")) {
// for now we don't handle it
continue;
} else if (key.equals("hepatonetId")) {
// for now we don't handle it
continue;
} else if (key.equals("inchiKey")) {
if (annotatedObject instanceof Chemical) {
setInchiKey((Chemical) annotatedObject, value, prefix);
}
} else if (key.equals("smile")) {
if (annotatedObject instanceof Chemical) {
setSmile((Chemical) annotatedObject, value, prefix);
}
} else if (key.equals("metanetx")) {
// for now we don't handle it
continue;
} else if (key.equals("seed")) {
// for now we don't handle it
continue;
} else if (key.equals("food_db")) {
// for now we don't handle it
continue;
} else if (key.equals("chemspider")) {
addChemspider(annotatedObject, value);
} else if (key.equals("wikipedia")) {
addWikipedia(annotatedObject, value);
} else if (key.equals("metlin")) {
// for now we don't handle it
continue;
} else if (key.equals("casRegistry")) {
addCas(annotatedObject, value);
} else if (key.equals("epa_id")) {
// for now we don't handle it
continue;
} else {
unknown = true;
}
if (unknown) {
logger.warn(prefix + "Unknown field in recon annotation: \"" + key + "\" (value: " + value + ")");
}
}
} else {
logger.warn(prefix + "No recon annotations \"" + id + "\"");
}
} else {
logger.warn(prefix + "No recon annotations \"" + id + "\"");
}
} catch (IOException e) {
throw new AnnotatorException(e);
}
}
}
@Override @Override
public String getCommonName() { public String getCommonName() {
return "Recon annotator"; return "Recon annotator";
} }
@Override @Override
public String getUrl() { public String getUrl() {
return "http://humanmetabolism.org/"; return "http://humanmetabolism.org/";
} }
@Override @Override
protected WebPageDownloader getWebPageDownloader() { protected WebPageDownloader getWebPageDownloader() {
return super.getWebPageDownloader(); return super.getWebPageDownloader();
} }
@Override @Override
protected void setWebPageDownloader(WebPageDownloader webPageDownloader) { protected void setWebPageDownloader(WebPageDownloader webPageDownloader) {
super.setWebPageDownloader(webPageDownloader); super.setWebPageDownloader(webPageDownloader);
} }
} }
...@@ -674,7 +674,7 @@ public enum MiriamType { ...@@ -674,7 +674,7 @@ public enum MiriamType {
* *
* @param generalIdentifier * @param generalIdentifier
* identifier in the format NAME:IDENTIFIER. Where NAME is the name * identifier in the format NAME:IDENTIFIER. Where NAME is the name
* from {@link MiriamType#commonName} and IDENTIFIER is reasource * from {@link MiriamType#commonName} and IDENTIFIER is resource
* identifier. * identifier.
* @return {@link MiriamData} representing generalIdentifier, when identifier is * @return {@link MiriamData} representing generalIdentifier, when identifier is
* invalid InvalidArgumentException is thrown * invalid InvalidArgumentException is thrown
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment