From e1235eae29c09ca9ab195d4461606eda7bb70767 Mon Sep 17 00:00:00 2001 From: kaitoii11 Date: Tue, 30 Aug 2016 12:58:18 +0900 Subject: [PATCH] fixed pom and output document handling --- README.md | 2 +- pom.xml | 8 ++--- .../layoutconverter/BaseLayoutConverter.java | 9 ++++- .../layoutconverter/CD2LayoutConverter.java | 15 -------- .../layoutconverter/Layout2CDConverter.java | 27 ++++++-------- src/org/sbml/wrapper/ModelWrapper.java | 36 +++++++++---------- .../ModifierSpeciesReferenceWrapper.java | 1 - src/org/sbml/wrapper/ObjectFactory.java | 36 ++++++++++++------- src/org/sbml/wrapper/SpeciesAliasWrapper.java | 1 - 9 files changed, 62 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 410cb69..9e6b4a5 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Interconvertable Layout Software for CellDesigner provides the way to convert fr ## How to convert file - java -jar layoutconverter-1.0.0-with-dependencies.jar /path/to/input.xml /path/to/output.xml + java -jar layoutconverter-1.0.0-jar-with-dependencies.jar /path/to/input.xml /path/to/output.xml ### Command Line Options **-h, --help** diff --git a/pom.xml b/pom.xml index 1dc7554..28ed586 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,11 @@ 4.0.0 - layoutconverter - layoutconverter + celldesigner-parser + celldesigner-parser 1.0.0 src + layoutconverter-${version} maven-compiler-plugin @@ -25,9 +26,6 @@ jar-with-dependencies - - descriptor.xml - diff --git a/src/org/sbml/layoutconverter/BaseLayoutConverter.java b/src/org/sbml/layoutconverter/BaseLayoutConverter.java index c52409d..15204df 100644 --- a/src/org/sbml/layoutconverter/BaseLayoutConverter.java +++ b/src/org/sbml/layoutconverter/BaseLayoutConverter.java @@ -27,6 +27,7 @@ import org.sbml.jsbml.SBMLErrorLog; import org.sbml.jsbml.SBMLException; import org.sbml.jsbml.SBMLReader; +import org.sbml.jsbml.SBMLWriter; import org.sbml.jsbml.TidySBMLWriter; import org.sbml.jsbml.ext.layout.Layout; import org.sbml.wrapper.ModelWrapper; @@ -185,7 +186,13 @@ public void setModel(Model model) { /** * Save. */ - public abstract void save(); + public void save(){ + try { + SBMLWriter.write(document, new File(outputFileName), ' ', (short) 2); + } catch (SBMLException | XMLStreamException | IOException e) { + e.printStackTrace(); + } + } /** * Validate. diff --git a/src/org/sbml/layoutconverter/CD2LayoutConverter.java b/src/org/sbml/layoutconverter/CD2LayoutConverter.java index 2cb2876..41277a4 100644 --- a/src/org/sbml/layoutconverter/CD2LayoutConverter.java +++ b/src/org/sbml/layoutconverter/CD2LayoutConverter.java @@ -711,19 +711,4 @@ public void convertComplexAliasToLayout( } } - /** - * Save. - */ - /* (non-Javadoc) - * @see org.sbml.layoutconverter.abstractLayoutConverter#save() - */ - @Override - public void save() { - try { - SBMLWriter.write(document, new File(outputFileName), ' ', (short) 2); - } catch (SBMLException | XMLStreamException | IOException e) { - e.printStackTrace(); - } - } - } diff --git a/src/org/sbml/layoutconverter/Layout2CDConverter.java b/src/org/sbml/layoutconverter/Layout2CDConverter.java index 7205bcc..9d7e064 100644 --- a/src/org/sbml/layoutconverter/Layout2CDConverter.java +++ b/src/org/sbml/layoutconverter/Layout2CDConverter.java @@ -174,6 +174,16 @@ public void convert() { convertSpeciesToCD(layout.getListOfSpeciesGlyphs()); convertReactionsToCD(layout.getListOfReactionGlyphs()); convertTextToCD(layout.getListOfTextGlyphs()); + + try { + String s = ObjectFactory.generateXMLString(mWrapper); + document = SBMLReader.read(s); + document = SBMLUtil.setMaths(document, downgrade_document); + } catch (JAXBException e) { + e.printStackTrace(); + } catch (XMLStreamException e) { + e.printStackTrace(); + } } /** @@ -641,22 +651,5 @@ public void convertTextToCD(List tgList){ } } } - - /* (non-Javadoc) - * @see org.sbml.layoutconverter.abstractLayoutConverter#save() - */ - @Override - public void save() { - try { - File file = ObjectFactory.saveModel(mWrapper, outputFileName); - document = SBMLUtil.setMaths(SBMLReader.read(file), downgrade_document); - } catch (JAXBException e) { - e.printStackTrace(); - } catch (XMLStreamException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } } diff --git a/src/org/sbml/wrapper/ModelWrapper.java b/src/org/sbml/wrapper/ModelWrapper.java index 8762fae..85526f5 100644 --- a/src/org/sbml/wrapper/ModelWrapper.java +++ b/src/org/sbml/wrapper/ModelWrapper.java @@ -55,6 +55,7 @@ import org.sbml.sbml.level2.version4.Compartment; import org.sbml.sbml.level2.version4.Model; import org.sbml.sbml.level2.version4.Reaction; +import org.sbml.sbml.level2.version4.Sbml; import org.sbml.sbml.level2.version4.Species; // TODO: Auto-generated Javadoc @@ -68,6 +69,9 @@ public class ModelWrapper extends Model { + /** The sbml. */ + private Sbml sbml; + /** The model. */ private Model model; @@ -138,8 +142,10 @@ public class ModelWrapper extends Model { * Instantiates a new model wrapper. * * @param model the model + * @param sbml the sbml */ - public ModelWrapper(Model model){ + public ModelWrapper(Model model, Sbml sbml){ + this.sbml = sbml; this.model = model; this.id = model.getId(); this.name = model.getName(); @@ -272,25 +278,15 @@ void initAnnotations(){ model.setListOfRules(null); // add later } - -// -// /** -// * @param species -// * @return -// * List -// * TODO -// */ -// private List createIncludedSpeciesList(List speciesList) { -// List includedSpeciesList = new ArrayList(speciesList.size()); -// -// for(org.sbml._2001.ns.celldesigner.Species s : speciesList){ -// Species species = new Species(); -// -// //includedSpeciesList -// } -// -// return includedSpeciesList; -// } + + /** + * Gets the sbml. + * + * @return the sbml + */ + public Sbml getSbml() { + return sbml; + } /** * Gets the w. diff --git a/src/org/sbml/wrapper/ModifierSpeciesReferenceWrapper.java b/src/org/sbml/wrapper/ModifierSpeciesReferenceWrapper.java index b41f02f..940bd80 100644 --- a/src/org/sbml/wrapper/ModifierSpeciesReferenceWrapper.java +++ b/src/org/sbml/wrapper/ModifierSpeciesReferenceWrapper.java @@ -248,7 +248,6 @@ public List getEditPoints(){ */ public void setEditPointList(List editPointList) { modification.getEditPoints().addAll(editPointList); - System.out.println(modification.getEditPoints()); } /** diff --git a/src/org/sbml/wrapper/ObjectFactory.java b/src/org/sbml/wrapper/ObjectFactory.java index ac004fd..42f4498 100644 --- a/src/org/sbml/wrapper/ObjectFactory.java +++ b/src/org/sbml/wrapper/ObjectFactory.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.StringReader; +import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -75,7 +76,7 @@ public static ModelWrapper unmarshalSBML(File file) throws JAXBException{ sbml = getSbml(file); model = sbml.getModel(); - modelWrapper = createModelWrapper(model); + modelWrapper = createModelWrapper(model, sbml); return modelWrapper; } @@ -91,7 +92,7 @@ public static ModelWrapper unmarshalSBMLFromString(String xml) throws JAXBExcept sbml = getSbml(xml); model = sbml.getModel(); - modelWrapper = createModelWrapper(model); + modelWrapper = createModelWrapper(model, sbml); return modelWrapper; } @@ -133,10 +134,11 @@ public static Sbml getSbml(String xml) throws JAXBException{ * Creates a new Object object. * * @param model the model + * @param sbml the sbml * @return the model wrapper */ - public static ModelWrapper createModelWrapper(Model model){ - return new ModelWrapper(model); + public static ModelWrapper createModelWrapper(Model model, Sbml sbml){ + return new ModelWrapper(model, sbml); } /** @@ -147,13 +149,7 @@ public static ModelWrapper createModelWrapper(Model model){ * @throws JAXBException the JAXB exception */ public static File saveModel(ModelWrapper modelWrapper) throws JAXBException{ - File file = new File(modelWrapper.getId() + ".xml"); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - marshaller.marshal(sbml, file); - - return file; + return saveModel(modelWrapper, modelWrapper.getId() + ".xml"); } /** @@ -169,8 +165,24 @@ public static File saveModel(ModelWrapper modelWrapper, String fileName) throws Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - marshaller.marshal(sbml, file); + marshaller.marshal(modelWrapper.getSbml(), file); return file; } + + /** + * Generate XML string. + * + * @param modelWrapper the model wrapper + * @return the string + * @throws JAXBException the JAXB exception + */ + public static String generateXMLString(ModelWrapper modelWrapper) throws JAXBException{ + StringWriter sw = new StringWriter(); + context = JAXBContext.newInstance(Sbml.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.marshal(modelWrapper.getSbml(), sw); + + return sw.toString(); + } } diff --git a/src/org/sbml/wrapper/SpeciesAliasWrapper.java b/src/org/sbml/wrapper/SpeciesAliasWrapper.java index 10f9a5a..e0d0aed 100644 --- a/src/org/sbml/wrapper/SpeciesAliasWrapper.java +++ b/src/org/sbml/wrapper/SpeciesAliasWrapper.java @@ -401,7 +401,6 @@ public boolean isComplexSpecies(){ * TODO */ public boolean isSetComplexSpeciesAlias(){ - System.out.println(complexSpeciesAlias); if(complexSpeciesAlias == null) return false; else