Commit 6959d58e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'cellwall-annotations' into 'master'

Cellwall annotations

Closes #142

See merge request piotr.gawron/minerva!201
parents 7192291c 967d9ba0
Pipeline #3660 passed with stage
in 1 minute and 2 seconds
......@@ -30,7 +30,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
......
......@@ -705,6 +705,7 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi
String uniprotId = page.substring(protienLinkPosition, j);
MiriamData uniprotMiriam = new MiriamData(MiriamType.UNIPROT, uniprotId);
MiriamData hgncMiriam = uniprotAnnotator.uniProtToHgnc(uniprotMiriam);
if (hgncMiriam != null) hgncMiriam.setAnnotator(null);
if (hgncMiriam == null || !hgncMiriam.equals(hgncTarget)) {
logger.debug("Invalid target found. Expected " + hgncTarget + ", but found: " + hgncMiriam + " ("
+ uniprotMiriam + ")");
......
......@@ -12,19 +12,26 @@ import java.util.Set;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.BrendaAnnotator;
import lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator;
import lcsb.mapviewer.annotation.services.annotators.CazyAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ChebiAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.annotation.services.annotators.EnsemblAnnotator;
import lcsb.mapviewer.annotation.services.annotators.EntrezAnnotator;
import lcsb.mapviewer.annotation.services.annotators.GoAnnotator;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.annotation.services.annotators.KeggAnnotator;
import lcsb.mapviewer.annotation.services.annotators.PdbAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ReconAnnotator;
import lcsb.mapviewer.annotation.services.annotators.StitchAnnotator;
import lcsb.mapviewer.annotation.services.annotators.StringAnnotator;
import lcsb.mapviewer.annotation.services.annotators.TairAnnotator;
import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
......@@ -35,6 +42,7 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.user.UserAnnotatorsParam;
import lcsb.mapviewer.modelutils.map.ClassTreeNode;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -67,6 +75,12 @@ public class ModelAnnotator {
* Default class logger.
*/
private static Logger logger = Logger.getLogger(ModelAnnotator.class);
/**
* BRENDA annotator.
*/
@Autowired
private BrendaAnnotator brendaAnnotator;
/**
* Service accessing <a href= "http://biocompendium.embl.de/" >internal
......@@ -74,6 +88,12 @@ public class ModelAnnotator {
*/
@Autowired
private BiocompendiumAnnotator biocompendiumAnnotator;
/**
* CAZy annotator.
*/
@Autowired
private CazyAnnotator cazyAnnotator;
/**
* Backend to the chebi database.
......@@ -112,6 +132,12 @@ public class ModelAnnotator {
*/
@Autowired
private HgncAnnotator hgncAnnotator;
/**
* Service accessing <a href= "http://www.kegg.jp/" > KEGG EC Nomenclature</a>.
*/
@Autowired
private KeggAnnotator keggAnnotator;
/**
* Service accessing <a href= "http://www.ncbi.nlm.nih.gov/gene/" >Entrez</a>.
......@@ -124,6 +150,25 @@ public class ModelAnnotator {
*/
@Autowired
private EnsemblAnnotator ensemblAnnotator;
/**
* STITCH annotator.
*/
@Autowired
private StitchAnnotator stitchAnnotator;
/**
* STRING annotator.
*/
@Autowired
private StringAnnotator stringAnnotator;
/**
* TAIR annotator.
*/
@Autowired
private TairAnnotator tairAnnotator;
/**
* List of all avaliable {@link ElementAnnotator} objects.
......@@ -144,15 +189,21 @@ public class ModelAnnotator {
availableAnnotators = new ArrayList<>();
defaultAnnotators = new ArrayList<>();
addAnnotator(brendaAnnotator);
addAnnotator(biocompendiumAnnotator);
addAnnotator(cazyAnnotator);
addAnnotator(chebiBackend);
addAnnotator(uniprotAnnotator);
addAnnotator(goAnnotator);
addAnnotator(hgncAnnotator);
addAnnotator(keggAnnotator);
addAnnotator(pdbAnnotator);
addAnnotator(reconAnnotator);
addAnnotator(entrezAnnotator);
addAnnotator(ensemblAnnotator);
addAnnotator(stitchAnnotator);
addAnnotator(stringAnnotator);
addAnnotator(tairAnnotator);
}
/**
......@@ -178,7 +229,7 @@ public class ModelAnnotator {
* callback function used for updating progress of the function
*/
public void performAnnotations(Model model, final IProgressUpdater progressUpdater) {
performAnnotations(model, progressUpdater, null);
performAnnotations(model, progressUpdater, null, null);
}
/**
......@@ -192,7 +243,8 @@ public class ModelAnnotator {
* @param progressUpdater
* callback function used for updating progress of the function
*/
public void performAnnotations(Model model, final IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) {
public void performAnnotations(Model model, final IProgressUpdater progressUpdater, Map<Class<?>,
List<ElementAnnotator>> annotators, Map<Class<?>, List<UserAnnotatorsParam>> annotatorsParams) {
progressUpdater.setProgress(0);
List<Model> models = new ArrayList<Model>();
models.add(model);
......@@ -215,7 +267,7 @@ public class ModelAnnotator {
progressUpdater
.setProgress(ratio * IProgressUpdater.MAX_PROGRESS + (COPYING_RATIO * IProgressUpdater.MAX_PROGRESS + progress * ANNOTATING_RATIO) / size);
}
}, annotators);
}, annotators, annotatorsParams);
counter++;
}
}
......@@ -254,7 +306,7 @@ public class ModelAnnotator {
progressUpdater.setProgress(counter / amount * IProgressUpdater.MAX_PROGRESS);
}
}
/**
* Annotates all elements in the model using set of {@link ElementAnnotator}
* given in the param. If the set is empty then all annotators will be used.
......@@ -266,15 +318,35 @@ public class ModelAnnotator {
* model where annotation shoud be updated
* @param progressUpdater
* callback function used to refresh progress of function execution
*/
*/
protected void annotateModel(Model model, IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) {
annotateModel(model, progressUpdater, annotators, null);
}
/**
* Annotates all elements in the model using set of {@link ElementAnnotator}
* given in the param. If the set is empty then all annotators will be used.
*
* @param annotators
* this map contains lists of {@link ElementAnnotator} objects that
* should be used for a given classes
* @param annotatorsParams
* this map contains lists of {@link UserAnnotatorsParam} objects that
* should be used for a given {@link ElementAnnotator} class
* @param model
* model where annotation should be updated
* @param progressUpdater
* callback function used to refresh progress of function execution
*/
protected void annotateModel(Model model, IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators,
Map<Class<?>, List<UserAnnotatorsParam>> annotatorsParams) {
ElementUtils elementUtils = new ElementUtils();
progressUpdater.setProgress(0);
double counter = 0;
double amount = model.getElements().size() + model.getReactions().size();
// annotate all elements
for (Element element : model.getElements()) {
List<ElementAnnotator> list = null;
......@@ -287,7 +359,15 @@ public class ModelAnnotator {
for (ElementAnnotator elementAnnotator : list) {
try {
elementAnnotator.annotateElement(element);
if (annotatorsParams != null){
List<UserAnnotatorsParam> params = annotatorsParams.get(elementAnnotator.getClass());
if (params != null) {
elementAnnotator.annotateElement(element, params);
}
} else {
elementAnnotator.annotateElement(element);
}
} catch (AnnotatorException e) {
logger.warn(elementUtils.getElementTag(element) + " " + elementAnnotator.getCommonName() + " annotation problem: " + e.getMessage());
}
......
package lcsb.mapviewer.annotation.services.annotators;
/**
* Definition of a single parameter of an annotator.
*
* @author David Hoksza
*
*/
public class AnnotatorParamDefinition {
private String name;
private String description;
private Class<?> type;
public AnnotatorParamDefinition(String name, Class<?> type, String description) {
super();
this.name = name;
this.description = description;
this.type = type;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public Class<?> getType() {
return type;
}
}
......@@ -83,7 +83,7 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
try {
if (query instanceof String) {
String name = (String) query;
result = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, name));
result = getAnnotation(createMiriamData(MiriamType.HGNC_SYMBOL, name));
} else {
throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass());
}
......@@ -109,7 +109,7 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
throw new InvalidArgumentException("Only " + MiriamType.HGNC_SYMBOL.getCommonName() + " miriam registry is supported.");
}
MiriamData miriamData = new MiriamData(md);
MiriamData miriamData = createMiriamData(md);
miriamData.setResource(miriamData.getResource().replaceAll("[\n\r]+", " "));
String annotation = getCacheValue(miriamData.getResource());
......@@ -282,7 +282,7 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
this.setCache(null);
try {
String annotations = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"));
String annotations = getAnnotation(createMiriamData(MiriamType.HGNC_SYMBOL, "SNCA"));
status.setStatus(ExternalServiceStatusType.OK);
if (annotations == null) {
......@@ -302,7 +302,7 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
public void annotateElement(BioEntity element) throws AnnotatorException {
if (isAnnotatable(element)) {
try {
String annotationString = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, element.getName()));
String annotationString = getAnnotation(createMiriamData(MiriamType.HGNC_SYMBOL, element.getName()));
if (annotationString != null) {
if (element.getMiriamData().size() == 0) {
element.addMiriamData(rap.getMiriamData(annotationString));
......
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.annotation.services.ExternalServiceStatus;
import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.annotation.services.IExternalService;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
/**
* This is a class that implements a backend to Brenda enzyme database.
*
* @author David Hoksza
*
*/
public class BrendaAnnotator extends ElementAnnotator implements IExternalService {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(BrendaAnnotator.class);
/**
* Service used for annotation of entities using {@link MiriamType#TAIR_LOCUS
* TAIR}.
*/
@Autowired
private TairAnnotator tairAnnotator;
/**
* Default constructor.
*/
public BrendaAnnotator() {
super(BrendaAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false);
}
@Override
public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
GeneralCacheInterface cacheCopy = getCache();
this.setCache(null);
try {
Collection<MiriamData> mds = new UniprotAnnotator().uniProtToEC(createMiriamData(MiriamType.UNIPROT, "P12345"));
status.setStatus(ExternalServiceStatusType.OK);
List<String> ecs = new ArrayList<>();
if (mds != null) {
for (MiriamData md: mds) {
ecs.add(md.getResource());
}
}
if (mds == null || mds.size() != 2 || ecs.indexOf("2.6.1.1") < 0 || ecs.indexOf("2.6.1.7") < 0) {
status.setStatus(ExternalServiceStatusType.CHANGED);
}
} catch (Exception e) {
logger.error(status.getName() + " is down", e);
status.setStatus(ExternalServiceStatusType.DOWN);
}
this.setCache(cacheCopy);
return status;
}
@Override
public void annotateElement(BioEntity object) throws AnnotatorException {
if (isAnnotatable(object)) {
MiriamData mdTair = null;
for (MiriamData md : object.getMiriamData()) {
if (md.getDataType().equals(MiriamType.BRENDA)) {
return;
}
else if (md.getDataType().equals(MiriamType.TAIR_LOCUS)) {
mdTair = md;
}
}
if (mdTair != null) {
tairAnnotator.annotateElement(object);
}
List<MiriamData> mdUniprots = new ArrayList<MiriamData>();
for (MiriamData md : object.getMiriamData()) {
if (md.getDataType().equals(MiriamType.UNIPROT)) {
mdUniprots.add(md);
}
}
UniprotAnnotator uniprotAnnotator = new UniprotAnnotator();
List<String> ecIds = new ArrayList<String>();
for (MiriamData mdUniprot: mdUniprots) {
try {
Collection<MiriamData> mdECs = uniprotAnnotator.uniProtToEC(mdUniprot);
if (mdECs != null) {
for (MiriamData mdEC: mdECs) {
mdEC.setAnnotator(BrendaAnnotator.class);
mdEC.setDataType(MiriamType.BRENDA);
if (ecIds.indexOf(mdEC.getResource()) == -1) {
ecIds.add(mdEC.getResource());
object.addMiriamData(mdEC);
}
}
}
} catch (UniprotSearchException e) {
logger.warn("Cannot find EC data for UniProt id: " + mdUniprot.getResource());
}
}
}
}
@Override
public Object refreshCacheQuery(Object query) throws SourceNotAvailable {
String name;
String result = null;
if (query instanceof String) {
name = (String) query;
if (name.startsWith("http")) {
try {
result = getWebPageContent(name);
} catch (IOException e) {
throw new SourceNotAvailable(e);
}
} else {
throw new InvalidArgumentException("Don't know what to do with query: " + query);
}
} else {
throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass());
}
return result;
}
@Override
public String getCommonName() {
return MiriamType.BRENDA.getCommonName();
}
@Override
public String getUrl() {
return MiriamType.BRENDA.getDbHomepage();
}
@Override
protected WebPageDownloader getWebPageDownloader() {
return super.getWebPageDownloader();
}
@Override
protected void setWebPageDownloader(WebPageDownloader webPageDownloader) {
super.setWebPageDownloader(webPageDownloader);
}
}
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.annotation.services.ExternalServiceStatus;
import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.annotation.services.IExternalService;
import lcsb.mapviewer.annotation.services.WrongResponseCodeIOException;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
/**
* This is a class that implements a backend to CAZy.
*
* @author David Hoksza
*
*/
public class CazyAnnotator extends ElementAnnotator implements IExternalService {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(CazyAnnotator.class);
/**
* Service used for annotation of entities using {@link MiriamType#TAIR_LOCUS
* tair}.
*/
@Autowired
private TairAnnotator tairAnnotator;
/**
* Pattern used for finding UniProt symbol from TAIR info page .
*/
private Pattern cazyIdMatcher = Pattern.compile("\\/((GT|GH|PL|CE|CBM)\\d+(\\_\\d+)?)\\.html");
/**
* Default constructor.
*/
public CazyAnnotator() {
super(CazyAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false);
}
@Override
public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
GeneralCacheInterface cacheCopy = getCache();
this.setCache(null);
try {
MiriamData md = uniprotToCazy(createMiriamData(MiriamType.UNIPROT, "Q9SG95"));
status.setStatus(ExternalServiceStatusType.OK);
if (md == null || !md.getResource().equalsIgnoreCase("GH5_7")) {
status.setStatus(ExternalServiceStatusType.CHANGED);
}
} catch (Exception e) {
logger.error(status.getName() + " is down", e);
status.setStatus(ExternalServiceStatusType.DOWN);
}
this.setCache(cacheCopy);
return status;
}
@Override
public void annotateElement(BioEntity object) throws AnnotatorException {
if (isAnnotatable(object)) {
MiriamData mdTair = null;
MiriamData mdCazy = null;
for (MiriamData md : object.getMiriamData()) {
if (md.getDataType().equals(MiriamType.CAZY)) {
mdCazy = md;
}
else if (md.getDataType().equals(MiriamType.TAIR_LOCUS)) {
mdTair = md;
}
}
if (mdCazy != null) {
return;