Commit 8a908bbf authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'refactor' into 'master'

Refactoring

issues #9, #10, #12

See merge request !3
parents d47a3508 5304f825
...@@ -28,10 +28,12 @@ import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator; ...@@ -28,10 +28,12 @@ import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator;
import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.common.EventStorageLoggerAppender;
import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
...@@ -165,13 +167,13 @@ public class ModelAnnotator { ...@@ -165,13 +167,13 @@ public class ModelAnnotator {
/** /**
* Performs all possible and automatic annotations on the model. * Performs all possible and automatic annotations on the model.
* *
* @param model * @param project
* model to update * project to update
* @param progressUpdater * @param progressUpdater
* callback function used for updating progress of the function * callback function used for updating progress of the function
*/ */
public void performAnnotations(Model model, final IProgressUpdater progressUpdater) { public void performAnnotations(Project project, final IProgressUpdater progressUpdater) {
performAnnotations(model, progressUpdater, null); performAnnotations(project, progressUpdater, null);
} }
/** /**
...@@ -180,19 +182,21 @@ public class ModelAnnotator { ...@@ -180,19 +182,21 @@ public class ModelAnnotator {
* @param annotators * @param annotators
* this map contains lists of {@link ElementAnnotator} objects that * this map contains lists of {@link ElementAnnotator} objects that
* should be used for a given classes * should be used for a given classes
* @param model * @param project
* model to update * project with models to update
* @param progressUpdater * @param progressUpdater
* callback function used for updating progress of the function * callback function used for updating progress of the function
*/ */
public void performAnnotations(Model model, final IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) { public void performAnnotations(Project project, final IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) {
EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); EventStorageLoggerAppender appender = new EventStorageLoggerAppender();
try { try {
Logger.getRootLogger().addAppender(appender); Logger.getRootLogger().addAppender(appender);
progressUpdater.setProgress(0); progressUpdater.setProgress(0);
List<Model> models = new ArrayList<Model>(); List<Model> models = new ArrayList<>();
models.add(model); for (ModelData model: project.getModels()) {
models.addAll(model.getSubmodels()); models.add(model.getModel());
models.addAll(model.getModel().getSubmodels());
}
final double size = models.size(); final double size = models.size();
double counter = 0; double counter = 0;
for (Model m : models) { for (Model m : models) {
...@@ -215,7 +219,7 @@ public class ModelAnnotator { ...@@ -215,7 +219,7 @@ public class ModelAnnotator {
counter++; counter++;
} }
Logger.getRootLogger().removeAppender(appender); Logger.getRootLogger().removeAppender(appender);
model.addLoggingInfo(appender); project.addLoggingInfo(appender);
} finally { } finally {
Logger.getRootLogger().removeAppender(appender); Logger.getRootLogger().removeAppender(appender);
} }
......
...@@ -29,6 +29,7 @@ import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; ...@@ -29,6 +29,7 @@ import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator; import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ReconAnnotator; import lcsb.mapviewer.annotation.services.annotators.ReconAnnotator;
import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamRelationType; import lcsb.mapviewer.model.map.MiriamRelationType;
...@@ -311,7 +312,9 @@ public class ModelAnnotatorTest extends AnnotationTestFunctions { ...@@ -311,7 +312,9 @@ public class ModelAnnotatorTest extends AnnotationTestFunctions {
final MutableDouble maxProgress = new MutableDouble(0.0); final MutableDouble maxProgress = new MutableDouble(0.0);
modelAnnotator.performAnnotations(model, new IProgressUpdater() { Project project = new Project();
project.addModel(model);
modelAnnotator.performAnnotations(project, new IProgressUpdater() {
@Override @Override
public void setProgress(double progress) { public void setProgress(double progress) {
maxProgress.setValue(Math.max(progress, maxProgress.getValue())); maxProgress.setValue(Math.max(progress, maxProgress.getValue()));
......
...@@ -5,7 +5,8 @@ import org.junit.runners.Suite; ...@@ -5,7 +5,8 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ CompositeStrokeTest.class, // @SuiteClasses({ ColorParserTest.class, //
CompositeStrokeTest.class, //
EllipseTransformationTest.class, // EllipseTransformationTest.class, //
LineTransformationTest.class, // LineTransformationTest.class, //
PointTransformationTest.class, // PointTransformationTest.class, //
......
...@@ -7,6 +7,7 @@ import lcsb.mapviewer.annotation.services.ModelAnnotator; ...@@ -7,6 +7,7 @@ import lcsb.mapviewer.annotation.services.ModelAnnotator;
import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.persist.ApplicationContextLoader; import lcsb.mapviewer.persist.ApplicationContextLoader;
...@@ -26,25 +27,25 @@ public class BellExport { ...@@ -26,25 +27,25 @@ public class BellExport {
/** /**
* Default class logger. * Default class logger.
*/ */
private static Logger logger = Logger.getLogger(BellExport.class.getName()); private static Logger logger = Logger.getLogger(BellExport.class.getName());
/** /**
* Object that performs different types of export transformation. * Object that performs different types of export transformation.
*/ */
@Autowired @Autowired
private IExporterService exporter; private IExporterService exporter;
/** /**
* Object used to annotate the model. * Object used to annotate the model.
*/ */
@Autowired @Autowired
private ModelAnnotator modelAnnotator; private ModelAnnotator modelAnnotator;
/** /**
* Object used to annotate the model. * Object used to annotate the model.
*/ */
@Autowired @Autowired
private DbUtils dbUtils; private DbUtils dbUtils;
/** /**
* Static main method used to run this stand alone code. * Static main method used to run this stand alone code.
...@@ -76,23 +77,22 @@ public class BellExport { ...@@ -76,23 +77,22 @@ public class BellExport {
try { try {
String filename = PdMapAnnotations.getLastPdFilename(); String filename = PdMapAnnotations.getLastPdFilename();
String version = PdMapAnnotations.getLastPdVersion(); String version = PdMapAnnotations.getLastPdVersion();
//filename = "testFiles/other_full/ASTHMAP18000X8000V1_38.xml"; // filename = "testFiles/other_full/ASTHMAP18000X8000V1_38.xml";
//version = "1.1.38"; // version = "1.1.38";
dbUtils.createSessionForCurrentThread(); dbUtils.createSessionForCurrentThread();
Model model = p.createModel(new ConverterParams().filename(filename)); Model model = p.createModel(new ConverterParams().filename(filename));
Project project = new Project();
project.addModel(model);
modelAnnotator.performAnnotations(model, new IProgressUpdater() { modelAnnotator.performAnnotations(project, new IProgressUpdater() {
@Override @Override
public void setProgress(double progress) { public void setProgress(double progress) {
// TODO Auto-generated method stub
} }
}); });
ExporterParameters params = new IExporterService.ExporterParameters().model(model).// ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileName("out/bell/" + version + "-reactions.txt").// fileName("out/bell/" + version + "-reactions.txt").//
fileType(ExportFileType.TAB_SEPARATED).// fileType(ExportFileType.TAB_SEPARATED).//
type(Species.class).// type(Species.class).//
moleculeEdges(false); moleculeEdges(false);
...@@ -100,15 +100,15 @@ public class BellExport { ...@@ -100,15 +100,15 @@ public class BellExport {
exporter.exportReactions(params); exporter.exportReactions(params);
params = new IExporterService.ExporterParameters().model(model).// params = new IExporterService.ExporterParameters().model(model).//
fileName("out/bell/" + version + "-species.txt").// fileName("out/bell/" + version + "-species.txt").//
fileType(ExportFileType.TAB_SEPARATED).// fileType(ExportFileType.TAB_SEPARATED).//
type(Species.class).// type(Species.class).//
// column(ExportColumn.FULL).// // column(ExportColumn.FULL).//
moleculeEdges(false); moleculeEdges(false);
exporter.exportSpecies(params); exporter.exportSpecies(params);
params = new IExporterService.ExporterParameters().model(model).// params = new IExporterService.ExporterParameters().model(model).//
fileName("out/bell/" + version + "-compartments.txt").// fileName("out/bell/" + version + "-compartments.txt").//
fileType(ExportFileType.TAB_SEPARATED).// fileType(ExportFileType.TAB_SEPARATED).//
type(Object.class); // type(Object.class); //
// column(ExportColumn.FULL); // column(ExportColumn.FULL);
......
...@@ -20,13 +20,14 @@ import lcsb.mapviewer.common.Configuration; ...@@ -20,13 +20,14 @@ import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.persist.ApplicationContextLoader; import lcsb.mapviewer.persist.ApplicationContextLoader;
import lcsb.mapviewer.persist.DbUtils; import lcsb.mapviewer.persist.DbUtils;
...@@ -112,8 +113,11 @@ public class Statistics { ...@@ -112,8 +113,11 @@ public class Statistics {
try { try {
// String modelName = PdMapAnnotations.getLastPdFilename(); // String modelName = PdMapAnnotations.getLastPdFilename();
CellDesignerXmlParser parser = new CellDesignerXmlParser(); CellDesignerXmlParser parser = new CellDesignerXmlParser();
Project project = new Project();
for (String name : fileNames) { for (String name : fileNames) {
models.add(parser.createModel(new ConverterParams().filename(name))); Model model = parser.createModel(new ConverterParams().filename(name));
models.add(model);
project.addModel(model);
} }
IProgressUpdater updater = new IProgressUpdater() { IProgressUpdater updater = new IProgressUpdater() {
...@@ -122,9 +126,7 @@ public class Statistics { ...@@ -122,9 +126,7 @@ public class Statistics {
logger.debug("Progress: " + progress); logger.debug("Progress: " + progress);
} }
}; };
for (Model model : models) { modelAnnotator.performAnnotations(project, updater);
modelAnnotator.performAnnotations(model, updater);
}
// modelAnnotator.removeIncorrectAnnotations(model, updater); // modelAnnotator.removeIncorrectAnnotations(model, updater);
printStatistics(models); printStatistics(models);
......
...@@ -18,7 +18,6 @@ import org.w3c.dom.Document; ...@@ -18,7 +18,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import lcsb.mapviewer.common.EventStorageLoggerAppender;
import lcsb.mapviewer.common.MimeType; import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.XmlParser; import lcsb.mapviewer.common.XmlParser;
...@@ -77,7 +76,6 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { ...@@ -77,7 +76,6 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
/** /**
* Default class logger. * Default class logger.
*/ */
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerXmlParser.class.getName()); private static Logger logger = Logger.getLogger(CellDesignerXmlParser.class.getName());
/** /**
...@@ -107,153 +105,143 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { ...@@ -107,153 +105,143 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
@Override @Override
public Model createModel(ConverterParams params) throws InvalidInputDataExecption { public Model createModel(ConverterParams params) throws InvalidInputDataExecption {
EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); CellDesignerElementCollection elements = new CellDesignerElementCollection();
try {
Logger.getRootLogger().addAppender(appender);
CellDesignerElementCollection elements = new CellDesignerElementCollection(); Model model = new ModelFullIndexed(null);
Model model = new ModelFullIndexed(null); if (params.getFilename() != null) {
model.setSbgnFormat(params.isSbgnFormat()); model.setName(FilenameUtils.getBaseName(params.getFilename()));
}
speciesSbmlParser = new SpeciesCollectionXmlParser(elements);
aliasCollectionParser = new AliasCollectionXmlParser(elements, model);
compartmentCollectionXmlParser = new CompartmentCollectionXmlParser(elements);
if (params.getFilename() != null) { DOMParser parser = new DOMParser();
model.setName(FilenameUtils.getBaseName(params.getFilename())); try {
} parser.parse(params.getSource());
speciesSbmlParser = new SpeciesCollectionXmlParser(elements); } catch (IOException e) {
aliasCollectionParser = new AliasCollectionXmlParser(elements, model); throw new InvalidInputDataExecption("IO Problem with a file: " + params.getSource().getSystemId(), e);
compartmentCollectionXmlParser = new CompartmentCollectionXmlParser(elements); }
Document doc = parser.getDocument();
DOMParser parser = new DOMParser(); try {
try {
parser.parse(params.getSource());
} catch (IOException e) {
throw new InvalidInputDataExecption("IO Problem with a file: " + params.getSource().getSystemId(), e);
}
Document doc = parser.getDocument();
try {
// Get the document's root XML node // Get the document's root XML node
NodeList root = doc.getChildNodes(); NodeList root = doc.getChildNodes();
// Navigate down the hierarchy to get to the CEO node // Navigate down the hierarchy to get to the CEO node
Node sbmlNode = getNode("SBML", root); Node sbmlNode = getNode("SBML", root);
if (sbmlNode == null) { if (sbmlNode == null) {
throw new InvalidInputDataExecption("No SBML node"); throw new InvalidInputDataExecption("No SBML node");
} }
Node modelNode = getNode("model", sbmlNode.getChildNodes()); Node modelNode = getNode("model", sbmlNode.getChildNodes());
if (modelNode == null) { if (modelNode == null) {
throw new InvalidInputDataExecption("No model node in SBML"); throw new InvalidInputDataExecption("No model node in SBML");
} }
// we ignore metaid - it's useless and obstruct data model // we ignore metaid - it's useless and obstruct data model
// model.setMetaId(getNodeAttr("metaId", modelNode)); // model.setMetaId(getNodeAttr("metaId", modelNode));
model.setIdModel(getNodeAttr("id", modelNode)); model.setIdModel(getNodeAttr("id", modelNode));
Node compartmentNode = getNode("listOfCompartments", modelNode.getChildNodes()); Node compartmentNode = getNode("listOfCompartments", modelNode.getChildNodes());
if (compartmentNode != null) { if (compartmentNode != null) {
List<CellDesignerCompartment> compartments = compartmentCollectionXmlParser.parseXmlCompartmentCollection(compartmentNode); List<CellDesignerCompartment> compartments = compartmentCollectionXmlParser.parseXmlCompartmentCollection(compartmentNode);
elements.addElements(compartments); elements.addElements(compartments);
} }
InternalModelSpeciesData modelData = new InternalModelSpeciesData(); InternalModelSpeciesData modelData = new InternalModelSpeciesData();
Node speciesNode = getNode("listOfSpecies", modelNode.getChildNodes()); Node speciesNode = getNode("listOfSpecies", modelNode.getChildNodes());
if (speciesNode != null) { if (speciesNode != null) {
List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode); List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode);
modelData.updateSpecies(species); modelData.updateSpecies(species);
} }
Node reactionsNode = null; Node reactionsNode = null;
NodeList nodes = modelNode.getChildNodes(); NodeList nodes = modelNode.getChildNodes();
for (int x = 0; x < nodes.getLength(); x++) { for (int x = 0; x < nodes.getLength(); x++) {
Node node = nodes.item(x); Node node = nodes.item(x);
if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("annotation")) { if (node.getNodeName().equalsIgnoreCase("annotation")) {
continue; continue;
} else if (node.getNodeName().equalsIgnoreCase("listOfSpecies")) { } else if (node.getNodeName().equalsIgnoreCase("listOfSpecies")) {
continue; continue;
} else if (node.getNodeName().equalsIgnoreCase("listOfReactions")) { } else if (node.getNodeName().equalsIgnoreCase("listOfReactions")) {
reactionsNode = node; reactionsNode = node;
} else if (node.getNodeName().equalsIgnoreCase("listOfCompartments")) { } else if (node.getNodeName().equalsIgnoreCase("listOfCompartments")) {
// we already parsed compartemnts // we already parsed compartemnts
continue; continue;
} else if (node.getNodeName().equalsIgnoreCase("notes")) { } else if (node.getNodeName().equalsIgnoreCase("notes")) {
String notes = rap.getNotes(node); String notes = rap.getNotes(node);
if (notes != null) { if (notes != null) {
notes = StringEscapeUtils.unescapeHtml4(notes); notes = StringEscapeUtils.unescapeHtml4(notes);
}
model.setNotes(notes);
} else if (node.getNodeName().equalsIgnoreCase("listOfUnitDefinitions")) {
continue; // we can ignore unit definitions
} else {
throw new InvalidInputDataExecption("Unknown element of model: " + node.getNodeName());
} }
model.setNotes(notes);
} else if (node.getNodeName().equalsIgnoreCase("listOfUnitDefinitions")) {
continue; // we can ignore unit definitions
} else {
throw new InvalidInputDataExecption("Unknown element of model: " + node.getNodeName());
} }
} }
}
Node annotationNode = getNode("annotation", modelNode.getChildNodes()); Node annotationNode = getNode("annotation", modelNode.getChildNodes());
if (annotationNode == null) { if (annotationNode == null) {
throw new InvalidInputDataExecption("No annotation node in SBML/model"); throw new InvalidInputDataExecption("No annotation node in SBML/model");
} }
parseAnnotation(model, annotationNode, modelData, elements); parseAnnotation(model, annotationNode, modelData, elements);
if (speciesNode != null) { if (speciesNode != null) {
List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode); List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode);
modelData.updateSpecies(species); modelData.updateSpecies(species);
} }
if (reactionsNode != null) { if (reactionsNode != null) {
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements); ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, params.isSbgnFormat());
List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode); List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode);
model.addReactions(reactions); model.addReactions(reactions);
} }
if (params.isSizeAutoAdjust()) { if (params.isSizeAutoAdjust()) {
Rectangle2D bound = getModelBound(model); Rectangle2D bound = getModelBound(model);
double width = bound.getWidth() + 2 * (Math.max(0, bound.getX())); double width = bound.getWidth() + 2 * (Math.max(0, bound.getX()));
double height = bound.getHeight() + 2 * (Math.max(0, bound.getY())); double height = bound.getHeight() + 2 * (Math.max(0, bound.getY()));
model.setWidth(width); model.setWidth(width);
model.setHeight(height); model.setHeight(height);
}