Commit 246de1df authored by Piotr Gawron's avatar Piotr Gawron
Browse files

REST api provides info about annotations in new format

parent 77a70183
......@@ -65,21 +65,23 @@ GuiUtils.prototype.createLink = function(url, name) {
return link;
};
GuiUtils.prototype.createAnnotationLink = function(element, showType) {
GuiUtils.prototype.createAnnotationLink = function(annotation, showType) {
var name, type, hint;
if (element.title !== undefined) {
hint = element.title + " " + element.authors.join(", ") + ", " + element.year + ", " + element.journal;
var article = annotation.getArticle();
if (article !== undefined) {
hint = article.getTitle()+ " " + article.getAuthors().join(", ") + ", " + article.getYear()+ ", " + article.getJournal();
type = "PUBMED";
name = element.id;
name = article.getId();
} else {
name = element.name;
type = element.type;
name = annotation.getResource();
type = annotation.getType();
}
var link;
if (showType) {
link = this.createLink(element.link, type + " (" + name + ")");
link = this.createLink(annotation.getLink(), type + " (" + name + ")");
} else {
link = this.createLink(element.link, name);
link = this.createLink(annotation.getLink(), name);
}
if (hint !== undefined) {
var div = document.createElement("div");
......
......@@ -46,7 +46,7 @@ Alias.prototype.constructor = Alias;
*/
Alias.prototype.update = function(javaObject) {
if (javaObject instanceof Alias) {
if (javaObject.getName()=== undefined) {
if (javaObject.getName() === undefined) {
return;
}
this.setDescription(javaObject.getDescription());
......
"use strict";
var Article = require("./Article");
var logger = require('../../logger');
function Annotation(javaObject) {
if (javaObject instanceof Annotation) {
this.setLink(javaObject.getLink());
this.setId(javaObject.getId());
if (javaObject.getArticle() !== undefined) {
this.setArticle(new Article(javaObject.getArticle()));
}
this.setType(javaObject.getType());
this.setResource(javaObject.getResource());
} else {
this.setLink(javaObject.link);
this.setId(javaObject.id);
if (javaObject.article !== undefined) {
this.setArticle(new Article(javaObject.article));
}
this.setType(javaObject.type);
this.setResource(javaObject.resource);
}
}
Annotation.prototype.setLink = function(link) {
this._link = link;
};
Annotation.prototype.getLink = function() {
return this._link;
};
Annotation.prototype.setId = function(id) {
this._id = id;
};
Annotation.prototype.getId = function() {
return this._id;
};
Annotation.prototype.setResource = function(resource) {
if (resource === undefined) {
throw new Error("resource cannot be undefined");
}
this._resource = resource;
};
Annotation.prototype.getResource = function() {
return this._resource;
};
Annotation.prototype.setType = function(type) {
if (type === undefined) {
throw new Error("type cannot be undefined");
}
this._type = type;
};
Annotation.prototype.getType = function() {
return this._type;
};
Annotation.prototype.setArticle = function(article) {
this._article = article;
};
Annotation.prototype.getArticle = function() {
return this._article;
};
module.exports = Annotation;
"use strict";
function Article(javaObject) {
if (javaObject instanceof Article) {
this.setTitle(javaObject.getTitle());
this.setAuthors(javaObject.getAuthors());
this.setJournal(javaObject.getJournal());
this.setYear(javaObject.getYear());
this.setLink(javaObject.getLink());
this.setCitationCount(javaObject.getCitationCount());
this.setId(javaObject.getId());
} else {
this.setTitle(javaObject.title);
this.setAuthors(javaObject.authors);
this.setJournal(javaObject.journal);
this.setYear(javaObject.year);
this.setLink(javaObject.link);
this.setCitationCount(javaObject.citationCount);
this.setId(javaObject.id);
}
}
Article.prototype.setTitle = function(title) {
this._title = title;
};
Article.prototype.getTitle = function() {
return this._title;
};
Article.prototype.setId = function(id) {
this._id = id;
};
Article.prototype.getAuthors = function() {
return this._authors;
};
Article.prototype.setAuthors = function(authors) {
this._authors = authors;
};
Article.prototype.setId = function(id) {
this._id = id;
};
Article.prototype.getId = function() {
return this._id;
};
Article.prototype.setJournal = function(journal) {
this._journal = journal;
};
Article.prototype.getJournal = function() {
return this._journal;
};
Article.prototype.setYear = function(year) {
this._year = year;
};
Article.prototype.getYear = function() {
return this._year;
};
Article.prototype.setLink = function(link) {
this._link = link;
};
Article.prototype.getLink = function() {
return this._link;
};
Article.prototype.setCitationCount = function(citationCount) {
this._citationCount = citationCount;
};
Article.prototype.getCitationCount = function() {
return this._citationCount;
};
module.exports = Article;
"use strict";
var Annotation = require("./Annotation");
/**
* Class representing BioEntity.
*
......@@ -125,7 +127,13 @@ BioEntity.prototype.getReferences = function() {
};
BioEntity.prototype.setReferences = function(references) {
this.references = references;
if (references=== undefined) {
throw new Error("references must be defined");
}
this.references = [];
for (var i = 0; i < references.length; i++) {
this.references.push(new Annotation(references[i]));
}
};
module.exports = BioEntity;
"use strict";
var Annotation = require("./Annotation");
var Target = require("./Target");
function Chemical(javaObject) {
......@@ -25,7 +26,10 @@ Chemical.prototype.getDirectEvidence = function() {
};
Chemical.prototype.setDirectEvidenceReferences = function(directeEvidenceReferences) {
this._directeEvidenceReferences = directeEvidenceReferences;
this._directeEvidenceReferences = [];
for (var i = 0; i < directeEvidenceReferences.length; i++) {
this._directeEvidenceReferences.push(new Annotation(directeEvidenceReferences[i]));
}
};
Chemical.prototype.getDirectEvidenceReferences = function() {
......@@ -41,7 +45,10 @@ Chemical.prototype.getBrandNames = function() {
};
Chemical.prototype.setReferences = function(references) {
this._references = references;
this._references = [];
for (var i = 0; i < references.length; i++) {
this._references.push(new Annotation(references[i]));
}
};
Chemical.prototype.getReferences = function() {
......
"use strict";
var Annotation = require("./Annotation");
var Target = require("./Target");
function Drug(javaObject) {
......@@ -24,7 +25,10 @@ Drug.prototype.getBrandNames = function() {
};
Drug.prototype.setReferences = function(references) {
this._references = references;
this._references = [];
for (var i = 0; i < references.length; i++) {
this._references.push(new Annotation(references[i]));
}
};
Drug.prototype.getReferences = function() {
......
......@@ -3,6 +3,8 @@
var Alias = require('./Alias');
var BioEntity = require("./BioEntity");
var logger = require('../../logger');
/**
* Class representing reaction data.
*
......
......@@ -2,6 +2,7 @@
/* exported logger */
var Annotation = require("./Annotation");
var IdentifiedElement = require('./IdentifiedElement');
var logger = require('../../logger');
......@@ -26,7 +27,10 @@ Target.prototype.getTargetElements = function() {
};
Target.prototype.setTargetParticipants = function(targetParticipants) {
this._targetParticipants = targetParticipants;
this._targetParticipants = [];
for (var i = 0; i < targetParticipants.length; i++) {
this._targetParticipants.push(new Annotation(targetParticipants[i]));
}
};
Target.prototype.getTargetParticipants = function() {
......@@ -50,7 +54,10 @@ Target.prototype.isVisible = function() {
};
Target.prototype.setReferences = function(references) {
this._references = references;
this._references = [];
for (var i = 0; i < references.length; i++) {
this._references.push(new Annotation(references[i]));
}
};
Target.prototype.getReferences = function() {
......
......@@ -52,7 +52,9 @@ describe('AbstractDbPanel', function() {
id : 329168,
modelId : 15781,
type : "ALIAS"
} ]
} ],
references : [],
targetParticipants : [],
});
var htmlTag = panel.createTargetRow(target, "empty.png");
assert.ok(htmlTag);
......
......@@ -59,7 +59,8 @@ describe('GuiUtils', function() {
height : 25.0
},
formula : "FORMULA",
id : 380217
id : 380217,
references: [],
};
var alias = new Alias(aliasObj);
......
......@@ -119,7 +119,8 @@ describe('GenericSearchPanel', function() {
height : 25.0
},
formula : "FORMULA",
id : 380217
id : 380217,
references: [],
};
var alias = new Alias(aliasObj);
......
......@@ -166,6 +166,7 @@ Helper.prototype.createAlias = function(map) {
width : 30.0,
height : 40.0,
},
references : [],
});
if (map !== undefined) {
map.getModel().addAlias(result);
......@@ -253,6 +254,7 @@ Helper.prototype.createReaction = function(map) {
} ],
centerPoint : new google.maps.Point(0, 0),
modelId : mapId,
references : [],
});
return result;
};
......@@ -340,6 +342,9 @@ Helper.prototype.createAbstractCustomMap = function() {
};
Helper.prototype.createCustomMap = function(project) {
if (project === null) {
throw new Error("Project cannot be null");
}
var options = this.createCustomMapOptions(project);
var result = new CustomMap(options);
return result;
......
......@@ -54,6 +54,7 @@ describe('MapModel', function() {
var aliasObj = {
idObject : 32,
modelId : model.id,
references : [],
};
model.addAlias(aliasObj);
......@@ -67,6 +68,7 @@ describe('MapModel', function() {
modelId : model.id,
name : "testName",
type : "Protein",
references : [],
};
model.addAlias(aliasObj2);
......
......@@ -16,15 +16,6 @@ describe('Reaction', function() {
helper = new Helper();
});
it("contructor", function() {
return ServerConnector.readFile("testFiles/reaction.json").then(function(content) {
var javaObject = JSON.parse(content);
var reaction = new Reaction(javaObject);
assert.ok(reaction);
assert.ok(reaction.getId());
assert.ok(reaction.getType());
});
});
it("constructor from invalid", function() {
var javaObject = {
lines : [ {
......
"use strict";
var Target = require('../../../../main/js/map/data/Target');
var logger = require('../../logger');
var chai = require('chai');
var assert = chai.assert;
describe('Target', function() {
it("contructor", function() {
return ServerConnector.readFile("testFiles/target.json").then(function(res) {
var object = JSON.parse(res);
var target = new Target(object);
assert.ok(target);
assert.equal(target.getTargetElements().length, 1);
assert.ok(target.getTargetParticipants().length>0);
assert.equal(target.getName(),"D-beta-hydroxybutyrate dehydrogenase, mitochondrial");
assert.equal(logger.getWarnings().length, 0);
});
});
});
......@@ -4,6 +4,7 @@ var Helper = require('../../Helper');
var logger = require('../../logger');
var CustomMap = require('../../../../main/js/map/CustomMap');
var IdentifiedElement = require('../../../../main/js/map/data/IdentifiedElement');
var DrugDbOverlay = require('../../../../main/js/map/overlay/DrugDbOverlay');
......@@ -28,15 +29,20 @@ describe('DrugDbOverlay', function() {
});
it("searchByQuery", function() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
var searchDb = helper.createDrugDbOverlay(map);
return searchDb.searchByQuery("NADH").then(function(drugs) {
helper.setUrl("http://test/?id=drug_target_sample");
GuiConnector.init();
var map, searchDb;
return ServerConnector.getProject("drug_target_sample").then(function(project) {
map = helper.createCustomMap(project);
searchDb = helper.createDrugDbOverlay(map);
return searchDb.searchByQuery("NADH");
}).then(function(drugs) {
assert.equal(drugs.length, 1);
assert.equal(searchDb.getQueries().length, 1);
return searchDb.getElementsByQuery(searchDb.getQueries()[0]);
}).then(function(elements) {
assert.ok(elements.length>1);
assert.ok(elements.length > 1);
return searchDb.getIdentifiedElements();
}).then(function(elements) {
assert.equal(elements.length, 1);
......
......@@ -28,10 +28,12 @@ describe('MiRnaDbOverlay', function() {
});
it("searchByQuery", function() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
var searchDb = helper.createMiRnaDbOverlay(map);
return searchDb.searchByQuery("hsa-miR-125a-3p").then(function(miRnas) {
var map, searchDb;
return ServerConnector.getProject().then(function(project) {
map = helper.createCustomMap(project);
searchDb = helper.createMiRnaDbOverlay(map);
return searchDb.searchByQuery("hsa-miR-125a-3p");
}).then(function(miRnas) {
assert.equal(miRnas.length, 1);
assert.equal(searchDb.getQueries().length, 1);
return searchDb.getElementsByQuery(searchDb.getQueries()[0]);
......
......@@ -105,7 +105,7 @@ describe('SearchDbOverlay', function() {
return searchDb.searchByCoordinates(searchParams);
}).then(function(result) {
// id of the parent
assert.equal(result[0].getId(), 329158);
assert.equal(result[0].getId(), 329159);
});
});
......
......@@ -93,9 +93,9 @@ beforeEach(function() {
ServerConnector.getSessionData(null).setToken("MOCK_TOKEN_ID");
ServerConnector.getSessionData(null).setLogin("anonymous");
GuiConnector.init();
new Helper().setUrl("http://test/");
GuiConnector.init();
global.testDiv = document.createElement("div");
global.testDiv.id = "test";
......
Supports Markdown
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