Commit b8137f18 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'master' into frontend-refactor

Conflicts:
	annotation/src/main/java/lcsb/mapviewer/annotation/cache/XmlSerializer.java
	annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java
	pathvisio/testFiles/wikipathways/gstp.gpml
	web/src/main/webapp/resources/js/Functions.js
parents 2d873f8a 63c2e991
minerva (10.0.5) stable; urgency=medium
* Bug fix: interacting drugs can be found for RNAs
* Bug fix: error handling improved on map upload
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 31 Jan 2017 12:00:00 +0200
minerva (10.0.4) stable; urgency=medium
* Bug fix: overlays colors are centered in white (not black)
* Bug fix: export to CellDesigner fixed
* Bug fix: DrugBank connector updated due to change in DrugBank website
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 29 Dec 2016 17:01:16 +0200
minerva (10.0.3) stable; urgency=medium
* Bug fix: login cannot contain whitespace
......@@ -8,7 +23,7 @@ minerva (10.0.3) stable; urgency=medium
* Bug fix: link to submap from comment panel
* Overlay coloring can be defined in Configuration
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 10 Oct 2016 10:01:16 +0200
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 15 Dec 2016 15:01:16 +0200
minerva (10.0.2) stable; urgency=medium
......
......@@ -837,6 +837,13 @@ public class BigFileCache {
*/
public boolean isCached(String sourceUrl) {
BigFileEntry entry = bigFileEntryDao.getByUrl(sourceUrl);
if (entry != null) {
File f = new File(Configuration.getWebAppDir() + entry.getLocalPath());
if (!f.exists()) {
logger.warn("File is supposed to be cached but it's not there... " + sourceUrl);
return false;
}
}
return entry != null;
}
......
......@@ -53,7 +53,7 @@ public class XmlSerializer<T> {
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
} catch (JAXBException e) {
throw new SerializationException();
throw new SerializationException(e);
}
}
......@@ -73,6 +73,8 @@ public class XmlSerializer<T> {
jaxbMarshaller.marshal(object, sw);
} catch (JAXBException e) {
throw new SerializationException(e);
} catch (Exception e) {
throw new SerializationException(e);
}
return sw.toString();
}
......
......@@ -496,10 +496,18 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
Document document = getXmlDocumentFromString(content);
Node response = getNode("response", document);
if (response == null) {
throw new DrugSearchException("Invalid source XML for drug: " + drugId);
}
Node moleculesNode = getNode("molecules", response);
if (moleculesNode == null) {
throw new DrugSearchException("Invalid source XML for drug: " + drugId);
}
Node moleculeNode = getNode("molecule", moleculesNode);
if (moleculeNode == null) {
throw new DrugSearchException("Invalid source XML for drug: " + drugId);
}
return parseDrug(moleculeNode);
} catch (IOException e) {
throw new DrugSearchException("Problem with accessing external database for id: " + drugId, e);
} catch (InvalidXmlSchemaException e) {
......
......@@ -572,7 +572,7 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi
int id = page.indexOf("<th>DrugBank ID</th>");
if (id < 0) {
throw new InvalidArgumentException("Problematic web page");
throw new DrugSearchException("Problematic web page for target: " + drugbankTarget + "(" + hgncTarget + ")");
}
int i = page.indexOf("/polypeptides/");
......
......@@ -2,8 +2,6 @@ package lcsb.mapviewer.annotation.services;
import java.io.IOException;
import javax.sql.rowset.serial.SerialException;
import org.apache.commons.lang3.SerializationException;
import org.apache.log4j.Logger;
import org.w3c.dom.Node;
......
......@@ -54,7 +54,7 @@ public class PubmedParser extends CachableInterface implements IExternalService
/**
* Version of the remote API thnat is supported by this connecting class.
*/
static final String SUPPORTED_VERSION = "4.5.3";
static final String SUPPORTED_VERSION = "4.5.3.2";
/**
* Connector used for accessing data from miriam registry.
......@@ -258,6 +258,7 @@ public class PubmedParser extends CachableInterface implements IExternalService
try {
Article art = getPubmedArticleById(SERVICE_STATUS_PUBMED_ID);
if (!getApiVersion().equals(SUPPORTED_VERSION)) {
logger.debug("New europepmc API version: " + getApiVersion());
status.setStatus(ExternalServiceStatusType.CHANGED);
} else if (art == null) {
status.setStatus(ExternalServiceStatusType.DOWN);
......
package lcsb.mapviewer.annotation.services.annotators;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.log4j.Logger;
......@@ -176,6 +178,28 @@ public abstract class ElementAnnotator extends CachableInterface {
}
}
/**
* Sets synonyms to the element.
*
* @param element
* element where we change data
* @param synonyms
* new synonyms list
* @param prefix
* prefix used in warnings
*/
protected void setSynonyms(AnnotatedObject element, Collection<String> synonyms, String prefix) {
if (element.getSynonyms() == null || element.getSynonyms().size() == 0) {
List<String> sortedSynonyms = new ArrayList<>();
sortedSynonyms.addAll(synonyms);
Collections.sort(sortedSynonyms);
element.setSynonyms(sortedSynonyms);
} else {
logger.warn(prefix + "Synonyms don't match: \"" + synonyms + "\", \"" + element.getSynonyms() + "\"");
}
}
/**
* Sets name to the element.
*
......
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
......@@ -44,7 +41,7 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi
/**
* Version of the rest API that is supported by this annotator.
*/
static final String SUPPORTED_VERSION = "4.7";
static final String SUPPORTED_VERSION = "4.8";
/**
* Url address of ensembl restfull service.
......@@ -252,10 +249,7 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi
}
}
if (synonyms.size() > 0) {
List<String> sortedSynonyms = new ArrayList<String>();
sortedSynonyms.addAll(synonyms);
Collections.sort(sortedSynonyms);
annotatedObject.setSynonyms(sortedSynonyms);
setSynonyms(annotatedObject, synonyms, prefix);
}
} catch (WrongResponseCodeIOException e) {
logger.warn(prefix + "Cannot find information for ensembl: " + entrezMiriamData.getResource());
......
......@@ -189,7 +189,7 @@ public class EntrezAnnotator extends ElementAnnotator implements IExternalServic
setFullName((Element) element, data.getFullName(), prefix);
element.addMiriamData(data.getMiriamData());
element.setSynonyms(data.getSynonyms());
setSynonyms(element, data.getSynonyms(), prefix);
setDescription(element, data.getDescription());
}
......
......@@ -208,7 +208,7 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
}
((Element) element).setFormerSymbols(strings);
} else if (type.equals("alias_symbol")) {
List<String> strings = new ArrayList<String>();
List<String> strings = new ArrayList<>();
NodeList sublist = node.getChildNodes();
for (int j = 0; j < sublist.getLength(); j++) {
Node subnode = sublist.item(j);
......@@ -216,7 +216,7 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
strings.add(getNodeValue(subnode));
}
}
element.setSynonyms(strings);
setSynonyms(element, strings, prefix);
} else if (type.equals("uniprot_ids")) {
NodeList sublist = node.getChildNodes();
for (int j = 0; j < sublist.getLength(); j++) {
......
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import org.apache.log4j.Logger;
......@@ -208,6 +210,12 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
}
} else if (key.equals("keggId")) {
addKeggMiriam(annotatedObject, value, prefix);
} else if (key.equals("fullName")) {
if (annotatedObject instanceof Element) {
setFullName((Element) annotatedObject, value, prefix);
} else {
unknown = true;
}
} else if (key.equals("keggorthology")) {
addKeggMiriam(annotatedObject, value, prefix);
} else if (key.equals("pubChemId")) {
......@@ -216,6 +224,12 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
addHmdbMiriam(annotatedObject, value);
} else if (key.equals("cog")) {
addCogMiriam(annotatedObject, value);
} else if (key.equals("synonyms")) {
List<String> synonyms = new ArrayList<>();
for (String str : value.split(",")) {
synonyms.add(str);
}
setSynonyms(annotatedObject, synonyms, prefix);
} else if (key.equals("pdmapName")) {
// for now we skip it...
continue;
......
......@@ -72,8 +72,11 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
assertEquals("CABOZANTINIB", drug.getName());
assertNull(drug.getDescription());
assertEquals(2, drug.getTargets().size());
logger.debug(drug.getSynonyms());
assertTrue(drug.getSynonyms().contains("Cabozantinib"));
List<String> lowerCaseSynonyms = new ArrayList<>();
for (String s: drug.getSynonyms()) {
lowerCaseSynonyms.add(s.toLowerCase());
}
assertTrue(lowerCaseSynonyms.contains("cabozantinib"));
} catch (Exception e) {
e.printStackTrace();
......
......@@ -51,11 +51,11 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
drugBankHTMLParser.setCache(cache);
}
@Test
public void test1FindDrug() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("Urokinase");
assertNotNull(test);
assertEquals(MiriamType.DRUGBANK, test.getSources().get(0).getDataType());
assertEquals("DB00013", test.getSources().get(0).getResource());
assertEquals("Urokinase", test.getName());
......@@ -73,8 +73,8 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void test2FindDrug() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("diazoxide");
assertNotNull(test);
assertEquals("Diazoxide", test.getName());
assertEquals("DB01119", test.getSources().get(0).getResource());
assertTrue(test.getBloodBrainBarrier().equalsIgnoreCase("YES"));
......@@ -91,17 +91,17 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void test3FindDrug() throws Exception {
try {
// finding synonym
Drug test = drugBankHTMLParser.findDrug("Rapamycin");
assertEquals("Sirolimus", test.getName());
assertEquals("DB00877", test.getSources().get(0).getResource());
assertTrue(test.getBloodBrainBarrier().equalsIgnoreCase("NO"));
boolean res = test.getDescription().contains(
Drug rapamycinDrug = drugBankHTMLParser.findDrug("Rapamycin");
assertNotNull(rapamycinDrug);
assertEquals("Sirolimus", rapamycinDrug.getName());
assertEquals("DB00877", rapamycinDrug.getSources().get(0).getResource());
assertTrue(rapamycinDrug.getBloodBrainBarrier().equalsIgnoreCase("NO"));
boolean res = rapamycinDrug.getDescription().contains(
"A macrolide compound obtained from Streptomyces hygroscopicus that acts by selectively blocking the transcriptional activation of cytokines thereby inhibiting cytokine production. It is bioactive only when bound to immunophilins. Sirolimus is a potent immunosuppressant and possesses both antifungal and antineoplastic properties. [PubChem]");
assertTrue(res);
assertEquals(3, test.getTargets().size());
assertEquals(3, rapamycinDrug.getTargets().size());
} catch (Exception e) {
e.printStackTrace();
......@@ -114,6 +114,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
try {
Drug test = drugBankHTMLParser.findDrug("Methylamine");
assertNotNull(test);
assertEquals("Methylamine", test.getName());
assertEquals("DB01828", test.getSources().get(0).getResource());
assertEquals(null, test.getDescription());
......@@ -135,15 +136,15 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void test5FindDrug() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("Amantadine");
assertEquals("Amantadine", test.getName());
assertEquals("DB00915", test.getSources().get(0).getResource());
boolean res = test.getDescription().contains(
Drug amantadineDrug = drugBankHTMLParser.findDrug("Amantadine");
assertNotNull(amantadineDrug);
assertEquals("Amantadine", amantadineDrug.getName());
assertEquals("DB00915", amantadineDrug.getSources().get(0).getResource());
boolean res = amantadineDrug.getDescription().contains(
"An antiviral that is used in the prophylactic or symptomatic treatment of influenza A. It is also used as an antiparkinsonian agent, to treat extrapyramidal reactions, and for postherpetic neuralgia. The mechanisms of its effects in movement disorders are not well understood but probably reflect an increase in synthesis and release of dopamine, with perhaps some inhibition of dopamine uptake. [PubChem]");
assertTrue(res);
assertEquals(3, test.getTargets().size());
assertEquals(3, amantadineDrug.getTargets().size());
} catch (Exception e) {
e.printStackTrace();
......@@ -153,7 +154,6 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void test6FindDrug() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("qwertyuiop");
assertEquals(null, test);
......@@ -166,8 +166,8 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void test7FindDrug() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("Aluminum hydroxide");
assertNotNull(test);
assertEquals("Aluminum hydroxide", test.getName());
assertEquals("DB06723", test.getSources().get(0).getResource());
assertTrue(
......@@ -421,9 +421,9 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void testFindIbuprofen() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("Ibuprofen");
assertNotNull(test);
assertEquals("Ibuprofen", test.getName());
assertEquals("DB01050", test.getSources().get(0).getResource());
assertNotNull(test.getDescription());
......@@ -440,6 +440,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
try {
Drug test = drugBankHTMLParser.findDrug("Dopamine");
assertNotNull(test);
for (Target target : test.getTargets()) {
assertFalse(target.getName().contains("Details"));
}
......@@ -451,10 +452,10 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void testFindGadobutrol() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("Gadobutrol");
assertTrue(test.getBloodBrainBarrier().equalsIgnoreCase("NO"));
Drug gadobutrolDrug = drugBankHTMLParser.findDrug("Gadobutrol");
assertNotNull(gadobutrolDrug);
assertTrue(gadobutrolDrug.getBloodBrainBarrier().equalsIgnoreCase("NO"));
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -466,6 +467,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
try {
Drug test = drugBankHTMLParser.findDrug("Guanosine-5’-Diphosphate");
assertNotNull(test);
assertFalse(test.getName().contains("&"));
} catch (Exception e) {
e.printStackTrace();
......
......@@ -272,7 +272,7 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
try {
MiriamData md1 = new MiriamData(MiriamType.HGNC, "11138");
MiriamData md2 = new MiriamData(MiriamType.HGNC, "111382");
Species proteinAlias = new GenericProtein("id");
Species proteinAlias = new GenericProtein("");
proteinAlias.addMiriamData(md1);
proteinAlias.addMiriamData(md2);
hgncAnnotator.annotateElement(proteinAlias);
......
package lcsb.mapviewer.converter.model.celldesigner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* This ctructure containes informationa about {@link CellDesignerElement
......@@ -36,6 +48,11 @@ public class CellDesignerElementCollection {
return (T) elementById.get(speciesId);
}
/**
*
*/
private Map<String, String> sbmlIdByElement = new HashMap<>();
/**
* Returns element identifier that should be used for model element when
* creating cell designer xml file.
......@@ -45,9 +62,127 @@ public class CellDesignerElementCollection {
* @return identifier of cell designer element that will be exported
*/
public String getElementId(Element modelElement) {
// TODO
// silly implementation for now (if CD won't crash than we can keep it)
return "s_id_" + modelElement.getElementId();
if ("default".equals(modelElement.getElementId())) {
return modelElement.getElementId();
} else {
String sbmlId = getSbmlId(modelElement, true);
if (sbmlIdByElement.get(sbmlId) == null) {
String id = "s_id_" + modelElement.getElementId();
if (sbmlIdByElement.values().contains(id)) {
throw new InvalidArgumentException("id duplicates");
}
sbmlIdByElement.put(sbmlId, id);
}
return sbmlIdByElement.get(sbmlId);
}
}
/**
* Creates a String that identifies element as distinct SBML entity.
*
* @param modelElement
* element that we want to identify
* @param useComplex
* should we use identifier of a complex. This should be used by
* default (because if the complex is different then element should
* have different identifier). However, when element asks complex for
* id, complex will try to resolve ids of children (becuase this is
* what defines complex identity), and in such situation it shoudl
* disable resolving complex, because there will by infity cyclic
* calls and stack overflow error will be thrown.
* @return unique String for sbml entity
*/
private String getSbmlId(Element modelElement, boolean useComplex) {
String compartmenName = "default";
if (modelElement.getCompartment() != null) {
compartmenName = modelElement.getCompartment().getName();
}
String modifications = "";
if (modelElement instanceof AntisenseRna) {
AntisenseRna asAntisenseRna = ((AntisenseRna) modelElement);
for (AntisenseRnaRegion region : asAntisenseRna.getRegions()) {
modifications += region.getState();
}
} else if (modelElement instanceof Gene) {
Gene asGene = ((Gene) modelElement);
for (ModificationResidue region : asGene.getModificationResidues()) {
modifications += region.getState();
}
} else if (modelElement instanceof Protein) {
Protein asProtein = ((Protein) modelElement);
modifications = asProtein.getStructuralState();
for (ModificationResidue region : asProtein.getModificationResidues()) {
modifications += region.getState();
}
} else if (modelElement instanceof Rna) {
Rna asRna = ((Rna) modelElement);
for (RnaRegion region : asRna.getRegions()) {
modifications += region.getState();
}
} else if (modelElement instanceof Complex) {
Complex asComplex = ((Complex) modelElement);
modifications = asComplex.getStructuralState();
}
String complexId = "";
String homodimer = "";
if (modelElement instanceof Species) {
homodimer = ((Species) modelElement).getHomodimer() + "";
if (((Species) modelElement).getComplex() != null) {
if (useComplex) {
if (!isCyclicNesting(((Species) modelElement).getComplex())) {
complexId = getElementId(((Species) modelElement).getComplex());
} else {
throw new InvalidArgumentException("Cycling nested structure found in element: " + modelElement.getElementId());
}
} else {
complexId = ((Species) modelElement).getComplex().getName();
}
}
}
String childrenId = "";
if (modelElement instanceof Complex) {
Complex asComplex = (Complex) modelElement;
List<String> childIds = new ArrayList<>();
for (Species child : asComplex.getAllChildren()) {
childIds.add(getSbmlId(child, false));
}
Collections.sort(childIds);
for (String string : childIds) {
childrenId += string + "\n";
}
}
// identifier that distinguish elements in sbml depends only on type,
// name, compartment, modifications, homodimer, state, complex where it's
// located,
// children of the complex
String sbmlId = compartmenName + "\n" + modelElement.getName() + "\n" + modelElement.getStringType() + "\n" + modifications + "\n" + complexId + "\n"
+ homodimer + "\n" + childrenId;
return sbmlId;
}
/**
* Checks if complex parenting is cyclic.
*
* @param complex
* complex for which data is checked
* @return true if parent of the complex is also a (grand)child of this
* complex, false otherwise