Skip to content

Commit

Permalink
fixed pom and output document handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitoii11 committed Aug 30, 2016
1 parent ed625c0 commit e1235ea
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>layoutconverter</groupId>
<artifactId>layoutconverter</artifactId>
<groupId>celldesigner-parser</groupId>
<artifactId>celldesigner-parser</artifactId>
<version>1.0.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>layoutconverter-${version}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -25,9 +26,6 @@
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
Expand Down
9 changes: 8 additions & 1 deletion src/org/sbml/layoutconverter/BaseLayoutConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 0 additions & 15 deletions src/org/sbml/layoutconverter/CD2LayoutConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}
27 changes: 10 additions & 17 deletions src/org/sbml/layoutconverter/Layout2CDConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -641,22 +651,5 @@ public void convertTextToCD(List<TextGlyph> 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();
}
}

}
36 changes: 16 additions & 20 deletions src/org/sbml/wrapper/ModelWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,6 +69,9 @@

public class ModelWrapper extends Model {

/** The sbml. */
private Sbml sbml;

/** The model. */
private Model model;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -272,25 +278,15 @@ void initAnnotations(){
model.setListOfRules(null); // add later

}

//
// /**
// * @param species
// * @return
// * List<Species>
// * TODO
// */
// private List<Species> createIncludedSpeciesList(List<org.sbml._2001.ns.celldesigner.Species> speciesList) {
// List<Species> includedSpeciesList = new ArrayList<Species>(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.
Expand Down
1 change: 0 additions & 1 deletion src/org/sbml/wrapper/ModifierSpeciesReferenceWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public List<Point2D.Double> getEditPoints(){
*/
public void setEditPointList(List<String> editPointList) {
modification.getEditPoints().addAll(editPointList);
System.out.println(modification.getEditPoints());
}

/**
Expand Down
36 changes: 24 additions & 12 deletions src/org/sbml/wrapper/ObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -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();
}
}
1 change: 0 additions & 1 deletion src/org/sbml/wrapper/SpeciesAliasWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ public boolean isComplexSpecies(){
* TODO
*/
public boolean isSetComplexSpeciesAlias(){
System.out.println(complexSpeciesAlias);
if(complexSpeciesAlias == null)
return false;
else
Expand Down

0 comments on commit e1235ea

Please sign in to comment.