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

Merge branch '1319-handle-model-notes-in-sbgn-ml' into 'master'

Resolve "Handle model notes in SBGN-ML"

Closes #1319

See merge request !1223
parents 0c8dafc8 4ba553e3
Pipeline #29745 passed with stage
in 14 minutes and 22 seconds
......@@ -27,6 +27,8 @@ minerva (15.1.0) unstable; urgency=medium
clickable (#1314)
* Small improvement: Modifier Reaction from CellDesigner are exported properly
to SBGN-ML PD (#1320)
* Small improvement: SBGN notes are imported properly (#1319)
* Small improvement: SBGN notes are exported properly (#1319)
* Bug fix: export to image from selected polygon contained all elements
inside rectangle bounded by the polygon coordinates (#1096)
* Bug fix: continuous refreshing list of project when uploading/removing
......
......@@ -29,6 +29,7 @@ import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SpeciesConverter;
import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.ArrowType;
......@@ -161,6 +162,26 @@ public class SbgnmlXmlExporter {
throw new ConverterException("Problem with providing render information");
}
try {
StringBuilder notes = new StringBuilder();
notes.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>");
if (model.getNotes() != null) {
notes.append(new CommonXmlParser().getNotesXmlContent(model.getNotes()));
}
notes.append("</body></html>");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db;
db = dbf.newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(notes.toString().getBytes()));
map.setNotes(new SBGNBase.Notes());
map.getNotes().getAny().add((org.w3c.dom.Element) (doc.getFirstChild()));
} catch (Exception e) {
logger.warn("Problem with processing notes");
}
sbgnData.getMap().add(map);
return sbgnData;
}
......
......@@ -3,15 +3,20 @@ package lcsb.mapviewer.converter.model.sbgnml;
import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbgn.*;
import org.sbgn.bindings.*;
import org.sbgn.bindings.Arc.*;
import org.sbgn.bindings.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.Configuration;
......@@ -25,6 +30,7 @@ import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.ZIndexPopulator;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SpeciesConverter;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesignerConverter;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.PolylineDataFactory;
......@@ -115,7 +121,7 @@ public class SbgnmlXmlParser {
model.setIdModel(filename);
Sbgn sbgnData;
Map map;
Map map = null;
// Check if input file has valid SBGN-ML data
try {
if (!SbgnUtil.isValid(inputSbgnmlFile)) {
......@@ -134,6 +140,23 @@ public class SbgnmlXmlParser {
} catch (Exception ex) {
throw new InvalidInputDataExecption("Unable to read given file.", ex);
}
RestAnnotationParser rap = new RestAnnotationParser();
if (map.getNotes() != null && map.getNotes().getAny().size() > 0) {
try {
String notes = "<notes>" + XmlParser.nodeToString(map.getNotes().getAny().get(0).getParentNode(), true)
+ "</notes>";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db;
db = dbf.newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(notes.getBytes()));
model.setNotes(rap.getNotes(doc.getFirstChild()));
} catch (Exception e) {
logger.warn("Problem with extracting map notes", e);
}
}
adjustSizeOfElements(map);
......@@ -372,6 +395,15 @@ public class SbgnmlXmlParser {
}
}
if (minX > maxX) {
minX = maxX;
maxX = 1;
}
if (minY > maxY) {
minY = maxY;
maxY = 1;
}
model.setWidth(maxX + minX);
model.setHeight(maxY + minY);
}
......
......@@ -4,6 +4,7 @@ import static org.junit.Assert.*;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.logging.log4j.LogManager;
......@@ -16,6 +17,7 @@ import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.field.Residue;
......@@ -318,4 +320,17 @@ public class SbgnmlXmlParserTest2 extends SbgnmlTestFunctions {
assertEquals(0, model.getReactions().size());
}
@Test
public void parseModelNotes() throws Exception {
Converter converter = new SbgnmlXmlConverter();
Model model = converter.createModel(new ConverterParams().filename("testFiles/sbgnmlParserTestFiles/sbgnmlFiles/model_notes.sbgn"));
assertFalse(model.getNotes().isEmpty());
model.setIdModel(null);
Model model2 = converter.createModel(new ConverterParams().inputStream(new ByteArrayInputStream(converter.model2String(model).getBytes())));
assertEquals(0, new ModelComparator().compare(model, model2));
}
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.2">
<map language="process description">
<notes>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner">
<head>
<title/>
</head>
<body>Vidisha Singh, Genhotel laboratory, University of Evry-paris saclay, Evry, France
Apoptosis pathway for Covid-19 maps project is constructed by using the review paper of Fung&amp;Liu,2019,Annu rev micro (PMID=31226023).
KEGG pathway database is used to add reactions between the elements.
Map is constructed in the form of a cell including plasma membrane, cytoplasm in addition to extracellular space.
Ligands are present in the extracellular space which interacts with receptors in the plasma membrane to initiate signaling cascade in the cytoplasm.
All the map elements are named according to HGNC naming scheme.
All map reactions are annotated with PubMed Ids, KEGG pathway Ids using MIRIAM add relation'bqbiol:isDescribedby'.
MESH Id is provided for the phenotype 'Apoptosis'.
</body>
</html>
</notes>
</map>
</sbgn>
......@@ -81,8 +81,6 @@ public class ModelComparator extends Comparator<Model> {
}
if (stringComparator.compare(arg0.getNotes(), arg1.getNotes(), true) != 0) {
logger.debug(arg0.getNotes());
logger.debug(arg1.getNotes());
logger.debug("Notes different:\n" + arg0.getNotes() + "\n---\n" + arg1.getNotes() + "\n---");
return stringComparator.compare(arg0.getNotes(), arg1.getNotes(), true);
}
......
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