Skip to content
Snippets Groups Projects
Commit fc66fc2c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

visualization of sbml function removes lambda expression and provides only the function

parent 9596d419
No related branches found
No related tags found
1 merge request!229Resolve "sbml function visualization"
Pipeline #
Showing
with 94 additions and 15 deletions
{"arguments":["x","y"],"definition":"<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n<lambda>\n<bvar>\n<ci> x </ci>\n</bvar>\n<bvar>\n<ci> y </ci>\n</bvar>\n<apply>\n<plus/>\n<ci> x </ci>\n<ci> y </ci>\n<cn type=\"integer\"> 2 </cn>\n</apply>\n</lambda>\n\n</math>","functionId":"fun","id":7,"mathMlPresentation":"\n<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n<mrow>\n<mo>λ</mo>\n<mrow>\n<mo>(</mo>\n<mi> x </mi>\n<mo>,</mo>\n<mi> y </mi>\n<mo>,</mo>\n<mrow>\n<mi> x </mi>\n<mo>+</mo>\n<mi> y </mi>\n<mo>+</mo>\n<mn> 2 </mn>\n</mrow>\n<mo>)</mo>\n</mrow>\n</mrow>\n\n</math>\n","name":"fun"} {"arguments":["x","y"],"definition":"<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n<lambda>\n<bvar>\n<ci> x </ci>\n</bvar>\n<bvar>\n<ci> y </ci>\n</bvar>\n<apply>\n<plus/>\n<ci> x </ci>\n<ci> y </ci>\n<cn type=\"integer\"> 2 </cn>\n</apply>\n</lambda>\n\n</math>","functionId":"fun","id":7,"mathMlPresentation":"\n<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n\n\n\n<mrow>\n<mi> x </mi>\n<mo>+</mo>\n<mi> y </mi>\n<mo>+</mo>\n<mn> 2 </mn>\n</mrow>\n\n\n</math>\n","name":"fun"}
\ No newline at end of file \ No newline at end of file
source diff could not be displayed: it is too large. Options to address this: view the blob.
[{"id":"hsa-miR-125a-3p","name":"hsa-miR-125a-3p","targets":[{"name":"FYN","references":[{"annotatorClassName":"","article":{"title":"microRNA-125a-3p reduces cell proliferation and migration by targeting Fyn.","authors":["Ninio-Many L"," Grossman H"," Shomron N"," Chuderland D"," Shalgi R."],"journal":"Journal of cell science","year":2013,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23606749","id":"23606749","citationCount":18,"stringAuthors":"Ninio-Many L, Grossman H, Shomron N, Chuderland D, Shalgi R."},"descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23606749","resource":"23606749","type":"PUBMED"}],"targetElements":[],"targetParticipants":[{"annotatorClassName":"","descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.genenames.org/cgi-bin/gene_symbol_report?match=FYN","resource":"FYN","type":"HGNC_SYMBOL"}]},{"name":"GPC4","references":[{"annotatorClassName":"","article":{"title":"MicroRNA-125a inhibits cell growth by targeting glypican-4.","authors":["Feng C"," Li J"," Ruan J"," Ding K."],"journal":"Glycoconjugate journal","year":2012,"link":"http://www.ncbi.nlm.nih.gov/pubmed/22644326","id":"22644326","citationCount":8,"stringAuthors":"Feng C, Li J, Ruan J, Ding K."},"descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.ncbi.nlm.nih.gov/pubmed/22644326","resource":"22644326","type":"PUBMED"}],"targetElements":[],"targetParticipants":[{"annotatorClassName":"","descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.genenames.org/cgi-bin/gene_symbol_report?match=GPC4","resource":"GPC4","type":"HGNC_SYMBOL"}]},{"name":"RHOA","references":[{"annotatorClassName":"","article":{"title":"MiRNA-125a-3p is a negative regulator of the RhoA-actomyosin pathway in A549 cells.","authors":["Huang B"," Luo W"," Sun L"," Zhang Q"," Jiang L"," Chang J"," Qiu X"," Wang E."],"journal":"International journal of oncology","year":2013,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23525486","id":"23525486","citationCount":8,"stringAuthors":"Huang B, Luo W, Sun L, Zhang Q, Jiang L, Chang J, Qiu X, Wang E."},"descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23525486","resource":"23525486","type":"PUBMED"}],"targetElements":[],"targetParticipants":[{"annotatorClassName":"","descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.genenames.org/cgi-bin/gene_symbol_report?match=RHOA","resource":"RHOA","type":"HGNC_SYMBOL"}]}]}] [{"id":"hsa-miR-125a-3p","name":"hsa-miR-125a-3p","targets":[{"name":"FYN","references":[{"annotatorClassName":"","article":{"title":"microRNA-125a-3p reduces cell proliferation and migration by targeting Fyn.","authors":["Ninio-Many L"," Grossman H"," Shomron N"," Chuderland D"," Shalgi R."],"journal":"Journal of cell science","year":2013,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23606749","id":"23606749","citationCount":25,"stringAuthors":"Ninio-Many L, Grossman H, Shomron N, Chuderland D, Shalgi R."},"descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23606749","resource":"23606749","type":"PUBMED"}],"targetElements":[],"targetParticipants":[{"annotatorClassName":"","descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.genenames.org/cgi-bin/gene_symbol_report?match=FYN","resource":"FYN","type":"HGNC_SYMBOL"}]},{"name":"GPC4","references":[{"annotatorClassName":"","article":{"title":"MicroRNA-125a inhibits cell growth by targeting glypican-4.","authors":["Feng C"," Li J"," Ruan J"," Ding K."],"journal":"Glycoconjugate journal","year":2012,"link":"http://www.ncbi.nlm.nih.gov/pubmed/22644326","id":"22644326","citationCount":8,"stringAuthors":"Feng C, Li J, Ruan J, Ding K."},"descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.ncbi.nlm.nih.gov/pubmed/22644326","resource":"22644326","type":"PUBMED"}],"targetElements":[],"targetParticipants":[{"annotatorClassName":"","descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.genenames.org/cgi-bin/gene_symbol_report?match=GPC4","resource":"GPC4","type":"HGNC_SYMBOL"}]},{"name":"RHOA","references":[{"annotatorClassName":"","article":{"title":"MiRNA-125a-3p is a negative regulator of the RhoA-actomyosin pathway in A549 cells.","authors":["Huang B"," Luo W"," Sun L"," Zhang Q"," Jiang L"," Chang J"," Qiu X"," Wang E."],"journal":"International journal of oncology","year":2013,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23525486","id":"23525486","citationCount":8,"stringAuthors":"Huang B, Luo W, Sun L, Zhang Q, Jiang L, Chang J, Qiu X, Wang E."},"descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.ncbi.nlm.nih.gov/pubmed/23525486","resource":"23525486","type":"PUBMED"}],"targetElements":[],"targetParticipants":[{"annotatorClassName":"","descriptionByType":"","descriptionByTypeRelation":"","id":0,"link":"http://www.genenames.org/cgi-bin/gene_symbol_report?match=RHOA","resource":"RHOA","type":"HGNC_SYMBOL"}]}]}]
\ No newline at end of file \ No newline at end of file
package lcsb.mapviewer.api.projects.models.functions; package lcsb.mapviewer.api.projects.models.functions;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.TreeMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathExpressionException;
import org.apache.axis.utils.ByteArrayOutputStream;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import lcsb.mapviewer.api.BaseRestImpl; import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.ObjectNotFoundException; import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.QueryException; import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.model.map.kinetics.SbmlFunction; import lcsb.mapviewer.model.map.kinetics.SbmlFunction;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.SecurityException; import lcsb.mapviewer.services.SecurityException;
...@@ -49,15 +62,38 @@ public class FunctionsRestImpl extends BaseRestImpl { ...@@ -49,15 +62,38 @@ public class FunctionsRestImpl extends BaseRestImpl {
result.put("name", function.getName()); result.put("name", function.getName());
result.put("definition", function.getDefinition()); result.put("definition", function.getDefinition());
try { try {
result.put("mathMlPresentation", super.mathMLToPresentationML(function.getDefinition())); String definition = extractLambda(function.getDefinition());
} catch (IOException | InvalidXmlSchemaException | TransformerException e) { result.put("mathMlPresentation", super.mathMLToPresentationML(definition));
} catch (Exception e) {
logger.error("Problems with transforming kinetics", e); logger.error("Problems with transforming kinetics", e);
} }
result.put("arguments", function.getArguments()); result.put("arguments", function.getArguments());
return result; return result;
} }
public List<Map<String, Object>> getFunctions(String projectId, String modelId, String token) throws SecurityException, QueryException { protected String extractLambda(String definition)
throws SAXException, IOException, ParserConfigurationException, XPathExpressionException, TransformerException {
String result = definition.replaceAll("<lambda>", "").replaceAll("</lambda>", "");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document document = dbf.newDocumentBuilder().parse(new InputSource(new ByteArrayInputStream(result.getBytes())));
NodeList nodes = document.getElementsByTagName("bvar");
for (int i = nodes.getLength() - 1; i >= 0; i--) {
Node e = nodes.item(i);
e.getParentNode().removeChild(e);
}
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
t.transform(new DOMSource(document), new StreamResult(baos));
return baos.toString();
}
public List<Map<String, Object>> getFunctions(String projectId, String modelId, String token)
throws SecurityException, QueryException {
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
List<Model> models = getModels(projectId, modelId, token); List<Model> models = getModels(projectId, modelId, token);
for (Model model : models) { for (Model model : models) {
......
...@@ -5,13 +5,15 @@ import org.junit.runners.Suite; ...@@ -5,13 +5,15 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.api.projects.models.bioEntities.AllBioeEntitiesTests; import lcsb.mapviewer.api.projects.models.bioEntities.AllBioeEntitiesTests;
import lcsb.mapviewer.api.projects.models.functions.AllFunctionsTests;
import lcsb.mapviewer.api.projects.models.publications.AllPublicationsTests; import lcsb.mapviewer.api.projects.models.publications.AllPublicationsTests;
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ // @SuiteClasses({ //
AllBioeEntitiesTests.class, // AllBioeEntitiesTests.class, //
AllPublicationsTests.class, // AllFunctionsTests.class, //
ModelRestImplTest.class,// AllPublicationsTests.class, //
ModelRestImplTest.class,//
}) })
public class AllModelsTests { public class AllModelsTests {
......
package lcsb.mapviewer.api.projects.models.functions;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ FunctionsRestImplTest.class })
public class AllFunctionsTests {
}
package lcsb.mapviewer.api.projects.models.functions;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.api.RestTestFunctions;
public class FunctionsRestImplTest extends RestTestFunctions {
Logger logger = Logger.getLogger(FunctionsRestImplTest.class);
@Autowired
FunctionsRestImpl functionRestImpl;
@Test
public void testExtractLambda() throws Exception{
String lambda = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n<lambda>\n<bvar>\n<ci> x </ci>\n</bvar>\n<bvar>\n<ci> y </ci>\n</bvar>\n<apply>\n<plus/>\n<ci> x </ci>\n<ci> y </ci>\n<cn type=\"integer\"> 2 </cn>\n</apply>\n</lambda>\n\n</math>";
String definition = functionRestImpl.extractLambda(lambda);
assertNotNull(definition);
assertFalse(definition.contains("lambda"));
assertFalse(definition.contains("bvar"));
assertTrue(definition.contains("math"));
assertTrue(definition.contains("apply"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment