Skip to content
Snippets Groups Projects

Resolve "problem with caching drugs list for big projects"

Merged Piotr Gawron requested to merge 2168-problem-with-caching-drugs-list-for-big-projects into master
Files
6
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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;
@@ -31,15 +20,23 @@ 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.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* This class is responsible for connecting to
* <a href="https://rest.genenames.org/">HGNC restfull API</a> and annotate
* elements with information taken from this service.
*
*
*
* @author Piotr Gawron
*
*/
@Service
public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator {
@@ -51,13 +48,13 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
private final Logger logger = LogManager.getLogger();
private MiriamConnector miriamConnector;
private final MiriamConnector miriamConnector;
/**
* Constructor.
*/
public HgncAnnotatorImpl(final MiriamConnector miriamConnector) {
super(HgncAnnotator.class, new Class[] { Protein.class, Rna.class, Gene.class }, true);
super(HgncAnnotator.class, new Class[]{Protein.class, Rna.class, Gene.class}, true);
this.miriamConnector = miriamConnector;
}
@@ -234,8 +231,7 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
/**
* Creates query url for given {@link MiriamType#HGNC} identifier.
*
* @param id
* {@link MiriamType#HGNC} identifier
* @param id {@link MiriamType#HGNC} identifier
* @return url to restful api webpage for given identifier
*/
private String getHgncIdUrl(final String id) {
@@ -245,12 +241,11 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
/**
* Creates query url for given {@link MiriamType#HGNC_SYMBOL}.
*
* @param name
* {@link MiriamType#HGNC_SYMBOL}
* @param name {@link MiriamType#HGNC_SYMBOL}
* @return url to restful API web page for given HGNC symbol
*/
private String getHgncNameUrl(final String name) {
String hgncSymbol = "" + name;
String hgncSymbol = name;
hgncSymbol = hgncSymbol.split("\\s+")[0];
return REST_API_URL + "symbol/" + hgncSymbol;
}
@@ -259,12 +254,10 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
* Converts {@link MiriamType#HGNC}/{@link MiriamType#HGNC_SYMBOL} identifier
* into list of {@link MiriamType#UNIPROT} identifiers.
*
* @param miriamData
* {@link MiriamData} with {@link MiriamType#HGNC} identifier
* @param miriamData {@link MiriamData} with {@link MiriamType#HGNC} identifier
* @return list of {@link MiriamData} with {@link MiriamType#UNIPROT}
* @throws AnnotatorException
* thrown when there was problem with accessing external database or
* any other unknown problem
* @throws AnnotatorException thrown when there was problem with accessing external database or
* any other unknown problem
*/
@Override
public List<MiriamData> hgncToUniprot(final MiriamData miriamData) throws AnnotatorException {
@@ -323,12 +316,10 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
* Converts {@link MiriamType#HGNC} identifier into
* {@link MiriamType#HGNC_SYMBOL}.
*
* @param miriamData
* {@link MiriamData} with {@link MiriamType#HGNC} identifier
* @param miriamData {@link MiriamData} with {@link MiriamType#HGNC} identifier
* @return {@link MiriamData} with {@link MiriamType#HGNC_SYMBOL}
* @throws AnnotatorException
* thrown when there was problem with accessing external database or
* any other unknown problem
* @throws AnnotatorException thrown when there was problem with accessing external database or
* any other unknown problem
*/
@Override
public MiriamData hgncIdToHgncName(final MiriamData miriamData) throws AnnotatorException {
@@ -373,13 +364,9 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
* Returns <code>true</code> if the {@link MiriamData} given in the parameter
* is a valid {@link MiriamType#HGNC} or {@link MiriamType#HGNC_SYMBOL}.
*
* @param md
* {@link MiriamData} to validate
* @return <code>true</code> if the {@link MiriamData} given in the parameter
* is a valid {@link MiriamType#HGNC} or
* {@link MiriamType#HGNC_SYMBOL}
* @throws AnnotatorException
* thrown when there is a problem accessing HGNC restful AI
* @param md {@link MiriamData} to validate
* @return <code>true</code> if the {@link MiriamData} given in the parameter is a valid {@link MiriamType#HGNC} or {@link MiriamType#HGNC_SYMBOL}
* @throws AnnotatorException thrown when there is a problem accessing HGNC restful AI
*/
@Override
public boolean isValidHgncMiriam(final MiriamData md) throws AnnotatorException {
@@ -388,7 +375,7 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
if (url == null) {
return false;
}
return hgncToUniprot(md).size() > 0;
return !hgncToUniprot(md).isEmpty();
} else {
return false;
}
@@ -397,11 +384,9 @@ public class HgncAnnotatorImpl extends ElementAnnotator implements HgncAnnotator
/**
* Transforms HGNC symbol into {@link MiriamType#ENTREZ} identifier.
*
* @param md
* hgnc symbol
* @param md hgnc symbol
* @return {@link MiriamType#ENTREZ} identifier for a given hgnc symbol
* @throws AnnotatorException
* thrown when there is a problem with accessing hgnc server
* @throws AnnotatorException thrown when there is a problem with accessing hgnc server
*/
@Override
public MiriamData hgncToEntrez(final MiriamData md) throws AnnotatorException {
Loading