Commit a51471d9 authored by David Hoksza's avatar David Hoksza
Browse files

Annotators propagation up to server (server part to be implemented)

parent 2fe8a13f
......@@ -13,7 +13,7 @@ public class AnnotatorParamDefinition {
private Class<?> type;
public AnnotatorParamDefinition(String name, String decription, Class<?> type) {
public AnnotatorParamDefinition(String name, Class<?> type, String decription) {
super();
this.name = name;
this.decription = decription;
......
......@@ -3,9 +3,7 @@ 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;
......@@ -17,7 +15,6 @@ 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;
......@@ -46,11 +43,6 @@ public class BrendaAnnotator extends ElementAnnotator implements IExternalServic
@Autowired
private TairAnnotator tairAnnotator;
/**
* Pattern used for finding EC symbol from UniProt page .
*/
private Pattern uniprotECMatcher = Pattern.compile("EC=((\\d+\\.-\\.-\\.-)|(\\d+\\.\\d+\\.-\\.-)|(\\d+\\.\\d+\\.\\d+\\.-)|(\\d+\\.\\d+\\.\\d+\\.\\d+))");
/**
* Default constructor.
*/
......
......@@ -182,8 +182,7 @@ public abstract class ElementAnnotator extends CachableInterface {
/**
* Returns list with definitions of the parameters available for this annotator.
* @return the parameters {@link AnnotatorParamDefinition} list
*/
*/
public Collection<AnnotatorParamDefinition> getParametersDefinitions(){
return paramsDefs;
}
......@@ -532,6 +531,24 @@ public abstract class ElementAnnotator extends CachableInterface {
}
}
/**
* Sets definitions of parameters for given annotator.
* @param paramDefs
* definitions to be set
*/
public void setParametersDefinitions(List<AnnotatorParamDefinition> paramDefs){
this.paramsDefs = paramDefs;
}
/**
* Adds parameter definition to the definitions of parameters for given annotator
* @param paramDef
* parameter definition to be added
*/
public void addParameterDefinition(AnnotatorParamDefinition paramDef){
this.paramsDefs.add(paramDef);
}
/**
* Sets MiriamData.annotator to this annotator
*
......
......@@ -66,6 +66,13 @@ public class KeggAnnotator extends ElementAnnotator implements IExternalService
*/
public KeggAnnotator() {
super(KeggAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false);
AnnotatorParamDefinition paramDef = new AnnotatorParamDefinition(
"KEGG organism identifier",
String.class,
"Space-delimited list of organisms codes for which homologous genes"
+ " (GENE section in the KEGG enzyme record) should be imported."
+ " Currently ATH (Arabidopsis Thaliana) is supported.");
this.addParameterDefinition(paramDef);
}
@Override
......
......@@ -51,13 +51,6 @@ public class PdbAnnotator extends ElementAnnotator implements IExternalService {
*/
private ElementUtils elementUtils = new ElementUtils();
/**
* Service used for annotation of proteins using {@link MiriamType#UNIPROT
* uniprot}.
*/
@Autowired
private UniprotAnnotator uniprotAnnotator;
/**
* Service used for annotation of proteins using {@link MiriamType#HGNC
* hgnc} (this can include lookup and loading annotation from {@link
......
......@@ -186,7 +186,7 @@ public class TairAnnotator extends ElementAnnotator implements IExternalService
@Override
public String getCommonName() {
return MiriamType.TAIR_LOCUS.getCommonName();
return "TAIR";
}
@Override
......
......@@ -17,6 +17,7 @@ import org.junit.runners.Suite.SuiteClasses;
GoAnnotatorTest.class, //
HgncAnnotatorTest.class, //
KeggAnnotatorTest.class, //
MultipleAnnotatorsTest.class, //
PdbAnnotatorTest.class, //
ReconAnnotatorTest.class, //
StitchAnnotatorTest.class, //
......
......@@ -535,3 +535,55 @@ h1 {
}
.minerva-annotators-params {
margin-top: 10px;
border: 1px #ddd solid;
}
.minerva-annotator-params {
padding: 5px;
}
.minerva-annotator-params-header {
font-weight: bold;
text-align: center;
padding-bottom: 5px;
}
.minerva-annotator-param {
display: table;
width: 100%;
}
.minerva-annotator-param-name {
display: table-cell;
vertical-align: middle;
width: 30%;
padding-right: 5px;
}
.minerva-annotator-param-value {
display: table-cell;
width: 70%;
}
.minerva-annotator-param-value textarea {
width: 100%;
height: 100px;
}
.minerva-annotators-params-header {
position: relative
}
.minerva-annotators-params-header>div {
position: absolute;
left: 20px;
top: -11px;
background-color: white;
padding-left: 10px;
padding-right: 10px;
font-weight: bold;
}
......@@ -271,6 +271,9 @@ Functions.createElement = function (params) {
if (params.onclick !== null && params.onclick !== undefined) {
result.onclick = params.onclick;
}
if (params.onchange !== null && params.onchange !== undefined) {
result.onchange = params.onchange;
}
if (params.href !== null && params.href !== undefined) {
result.href = params.href;
}
......
......@@ -7,6 +7,8 @@ var DualListbox = require('dual-listbox').DualListbox;
var GuiConnector = require("../../GuiConnector");
var UserPreferences = require("../../map/data/UserPreferences");
var InvalidArgumentError = require ('../../InvalidArgumentError');
var Functions = require('../../Functions');
var logger = require('../../logger');
......@@ -34,16 +36,41 @@ ChooseAnnotatorsDialog.prototype.createGui = function () {
xss: false
}));
content.appendChild(Functions.createElement({
var annotatorsDiv = Functions.createElement({
type: "div",
style: "display:table-cell",
content: "<div name='annotatorListBox'/>",
xss: false
});
annotatorsDiv.appendChild(Functions.createElement({
type: "div",
name: "annotatorListBox"
}));
annotatorsDiv.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotators-params"
}));
content.appendChild(annotatorsDiv);
self.getElement().appendChild(content);
};
function onChangeParameterValue(element, user){
var value = element;
var name = $(element).siblings(".minerva-annotator-param-name").text();
var annotatorClassName = $(element).parent().parent().attr('name');
var data = new UserPreferences();
var annotatorsParams = {};
annotatorsParams[annotatorClassName] = {name: value};
data.setAnnotatorsParameters(annotatorsParams);
return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
}
ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
var self = this;
......@@ -54,7 +81,9 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
return ServerConnector.getLoggedUser();
}).then(function (user) {
var element = $("[name='annotatorListBox']", self.getElement())[0];
var annotatorsParams = $(".minerva-annotators-params", self.getElement())[0];
Functions.removeChildren(element);
Functions.removeChildren(annotatorsParams);
var selectElement = Functions.createElement({
type: "select",
......@@ -71,14 +100,76 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
for (var j = 0; j < selectedAnnotators.length; j++) {
if (annotator.getName() === selectedAnnotators[j]) {
selected = true;
}
var paramsDefs = annotator.getParametersDefinitions();
if (paramsDefs.length > 0) {
annotatorsParams.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotators-params-header",
content: '<div>Available parameters</div>'
}))
var annotatorParams = Functions.createElement({
type: "div",
className: "minerva-annotator-params",
name: annotator.getClassName()
});
annotatorParams.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotator-params-header",
content: annotator.getName()
}));
for (var k = 0; k < paramsDefs.length; k++) {
var param = paramsDefs[k];
var paramElement = Functions.createElement({
type: "div",
className: "minerva-annotator-param"
});
paramElement.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotator-param-name",
content: param.name
}));
var paramValue;
if (param.type.indexOf("String") >= 0) {
paramValue = Functions.createElement({
type: "textarea",
onchange: function(){return onChangeParameterValue(this, user);}
});
} else if (param.type.indexOf("Integer") >= 0) {
paramValue = Functions.createElement({
type: "input",
inputType: "number",
onchange: function(){return onChangeParameterValue(this, user);}
});
} else if (param.type.indexOf("Boolean") >= 0) {
paramValue = Functions.createElement({
type: "input",
inputType: "checkbox",
onchange: function(){return onChangeParameterValue(this, user);}
});
} else {
throw new InvalidAlgorithmError("Unknown annotator parameter type");
}
paramElement.appendChild(paramValue);
annotatorParams.appendChild(paramElement);
}
annotatorsParams.appendChild(annotatorParams);
}
}
}
var option = new Option();
option.value = annotator.getClassName();
option.attributes.selected = selected;
option.innerHTML = "<div>" + annotator.getName() + "</div>";
selectElement.appendChild(option);
}
};
element.appendChild(selectElement);
new DualListbox(selectElement, {
......
......@@ -12,11 +12,13 @@ function Annotator(javaObject, configuration) {
self.setClassName(javaObject.getClassName());
this._elementTypes = javaObject.getElementTypes();
self.setName(javaObject.getName());
self.setParametersDefinitions(javaObject.getParametersDefinitions());
self.setUrl(javaObject.getUrl());
} else {
self.setClassName(javaObject.className);
self.setElementTypes(javaObject.elementClassNames, configuration);
self.setName(javaObject.name);
self.setParametersDefinitions(javaObject.parametersDefinitions);
self.setUrl(javaObject.url);
}
}
......@@ -45,6 +47,14 @@ Annotator.prototype.getUrl = function () {
return this._url;
};
Annotator.prototype.getParametersDefinitions = function () {
return this._parametersDefinitions;
}
Annotator.prototype.setParametersDefinitions = function (parametersDefinitions) {
this._parametersDefinitions = parametersDefinitions;
}
Annotator.prototype.setElementTypes = function (elementTypesClassNames, configuration) {
this._elementTypes = [];
var typeByClassName = {};
......
......@@ -10,11 +10,13 @@ function UserPreferences(javaObject) {
this.setElementAnnotators(javaObject["element-annotators"]);
this.setElementRequiredAnnotations(javaObject["element-required-annotations"]);
this.setElementValidAnnotations(javaObject["element-valid-annotations"]);
this.setAnnotatorsParameters(javaObject["annotators-parameters"]);
} else {
this._projectUpload = {};
this._elementAnnotators = {};
this._elementRequiredAnnotations = {};
this._elementValidAnnotations = {};
this._annotatorsParameters = {};
}
}
......@@ -28,10 +30,16 @@ UserPreferences.prototype.setProjectUpload = function (projectUpload) {
sbgn: projectUpload["sbgn"]
};
};
UserPreferences.prototype.getAnnotatorsParameters = function () {
return this._annotatorsParameters;
};
UserPreferences.prototype.setAnnotatorsParameters = function (annotatorsParameters) {
this._annotatorsParameters = annotatorsParameters;
};
UserPreferences.prototype.getProjectUpload = function () {
return this._projectUpload;
};
UserPreferences.prototype.setElementAnnotators = function (elementAnnotators) {
UserPreferences.prototype .setElementAnnotators = function (elementAnnotators) {
this._elementAnnotators = elementAnnotators;
};
UserPreferences.prototype.getElementAnnotators = function (className) {
......@@ -94,7 +102,8 @@ UserPreferences.prototype.toExport = function () {
},
"element-annotators": this._elementAnnotators,
"element-valid-annotations": this._elementValidAnnotations,
"element-required-annotations": requiredAnnotations
"element-required-annotations": requiredAnnotations,
"annotators-parameters": this.getAnnotatorsParameters()
};
};
......
......@@ -163,6 +163,10 @@ public class UserRestImpl extends BaseRestImpl {
}
}
}
private void updateAnnotatorsParams(UserAnnotationSchema schema, Map<String, Object> data) {
}
private Map<String, Object> prepareRequiredAnnotations(List<UserClassRequiredAnnotations> classRequiredAnnotators) {
Map<String, Object> result = new HashMap<>();
......@@ -401,6 +405,9 @@ public class UserRestImpl extends BaseRestImpl {
for (String key : preferencesData.keySet()) {
Map<String, Object> value = (Map<String, Object>) preferencesData.get(key);
logger.debug(key);
logger.debug(value);
if (key.equals("project-upload")) {
updateUploadPreferences(schema, value);
......@@ -410,6 +417,8 @@ public class UserRestImpl extends BaseRestImpl {
updateRequiredAnnotations(schema, value);
} else if (key.equals("element-valid-annotations")) {
updateValidAnnotations(schema, value);
} else if (key.equals("annotators-parameters")) {
updateAnnotatorsParams(schema, value);
} else {
throw new QueryException("Unknown preferences field: " + key);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment