Skip to content

Commit

Permalink
Changes due to changes in SysBio: A new initialization method to conn…
Browse files Browse the repository at this point in the history
…ect to Garuda, the UUID is now automatically generated based on the package and main class name and SBMLsqueezer does no longer care about how the connection to Garuda is actually being done. The new UUID has been added to the build script.
  • Loading branch information
draeger committed Sep 28, 2014
1 parent 98bfe04 commit 838de21
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 124 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<property name="celldesigner.test" value="${celldesigner}/test"/>
<property name="celldesigner.resources" value="${celldesigner}/resources"/>
<property name="celldesigner.version" value="celldesigner-4.4-GSoC"/>
<property name="UUID" value="dd624b40-7bc0-11e2-b92a-0800200c9a66"/>
<property name="UUID" value="b3048f09-e26d-3d28-b0da-4e708c2dd6ec"/>

<property name="jar.name" value="${Name}_v${version}"/>
<property name="appJar" value="${dist.dir}/${jar.name}_incl-libs.jar"/>
Expand Down
Binary file modified lib/SysBio.jar
Binary file not shown.
229 changes: 106 additions & 123 deletions src/org/sbml/squeezer/SBMLsqueezer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

import javax.xml.stream.XMLStreamException;

import jp.sbi.garuda.platform.commons.exception.NetworkException;

import org.sbml.jsbml.Model;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.SBMLDocument;
Expand All @@ -68,9 +66,7 @@
import de.zbit.AppConf;
import de.zbit.Launcher;
import de.zbit.garuda.GarudaOptions;
import de.zbit.garuda.GarudaSoftwareBackend;
import de.zbit.gui.GUIOptions;
import de.zbit.gui.GUITools;
import de.zbit.io.FileWalker;
import de.zbit.io.filefilter.SBFileFilter;
import de.zbit.util.ResourceManager;
Expand All @@ -94,25 +90,29 @@
@SuppressWarnings("unchecked")
public class SBMLsqueezer<T> extends Launcher {

private static Boolean libSBMLAvailable = null;
/**
* Localization support.
* The {@link Logger} for this class.
*/
public static final transient ResourceBundle MESSAGES = ResourceManager.getBundle(Bundles.MESSAGES);
private static final transient Logger logger = Logger.getLogger(SBMLsqueezer.class.getName());

/**
* Localization support.
*/
public static final transient ResourceBundle WARNINGS = ResourceManager.getBundle(Bundles.WARNINGS);
public static final transient ResourceBundle MESSAGES = ResourceManager.getBundle(Bundles.MESSAGES);

/**
* The {@link Logger} for this class.
*/
private static final transient Logger logger = Logger.getLogger(SBMLsqueezer.class.getName());
private static boolean sabiorkEnabled = true;

/**
* Generated serial version identifier.
*/
private static final long serialVersionUID = 8751196023375780898L;

/**
* Localization support.
*/
public static final transient ResourceBundle WARNINGS = ResourceManager.getBundle(Bundles.WARNINGS);

/**
*
* @return
Expand All @@ -121,22 +121,6 @@ public static List<Class<? extends KeyProvider>> getInteractiveConfigOptions() {
return Arrays.asList(getInteractiveConfigOptionsArray());
}

private static boolean sabiorkEnabled = true;

/**
* @return the sabiorkEnabled
*/
public static boolean isSABIORKEnabled() {
return sabiorkEnabled;
}

/**
* @param sabiorkEnabled the sabiorkEnabled to set
*/
public static void setSABIORKEnabled(boolean sabiorkEnabled) {
SBMLsqueezer.sabiorkEnabled = sabiorkEnabled;
}

/**
*
* @return
Expand Down Expand Up @@ -178,42 +162,11 @@ public static String[] getPossibleEnzymeTypes() {
return enzymeTypes.toArray(new String[] {});
}

private static Boolean libSBMLAvailable = null;

/**
* Does initialization for creating a SBMLsqueezer Object.
* Checks if libSBML is available and initializes the Reader/Writer.
* @param tryLoadingLibSBML
* @param reader
* @param writer
* @return the sabiorkEnabled
*/
private void initializeReaderAndWriter(boolean tryLoadingLibSBML) {
if (tryLoadingLibSBML) {
if (libSBMLAvailable == null) {
try {
// In order to initialize libSBML, check the java.library.path.
System.loadLibrary("sbmlj");
// Extra check to be sure we have access to libSBML:
Class.forName("org.sbml.libsbml.libsbml");
logger.info(MESSAGES.getString("LOADING_LIBSBML"));
libSBMLAvailable = Boolean.TRUE;
} catch (Error e) {
libSBMLAvailable = Boolean.FALSE;
} catch (Throwable e) {
libSBMLAvailable = Boolean.FALSE;
}
}
if (libSBMLAvailable.booleanValue()) {
logger.info(MESSAGES.getString("LAUNCHING_LIBSBML"));
sbmlIo = (SBMLio<T>) new SBMLio<org.sbml.libsbml.Model>(
new LibSBMLReader(), new LibSBMLWriter());
}
}
if (sbmlIo == null) {
logger.info(MESSAGES.getString("LOADING_JSBML"));
sbmlIo = (SBMLio<T>) new SBMLio<Model>(new SqSBMLReader(),
new SqSBMLWriter());
}
public static boolean isSABIORKEnabled() {
return sabiorkEnabled;
}

/**
Expand All @@ -225,15 +178,22 @@ public static void main(String[] args) {
}

/**
*
* @param sabiorkEnabled the sabiorkEnabled to set
*/
private SBMLio<T> sbmlIo;
public static void setSABIORKEnabled(boolean sabiorkEnabled) {
SBMLsqueezer.sabiorkEnabled = sabiorkEnabled;
}

/**
*
*/
private AppConf appConf;

/**
*
*/
private SBMLio<T> sbmlIo;

/**
*
*/
Expand Down Expand Up @@ -262,6 +222,7 @@ public SBMLsqueezer(SBMLInputConverter<T> sbmlReader,
*/
public SBMLsqueezer(String[] args) {
super(args);
System.out.println(getId());
}

/* (non-Javadoc)
Expand Down Expand Up @@ -323,7 +284,6 @@ public List<Class<? extends KeyProvider>> getCmdLineOptions() {
return list;
}


/* (non-Javadoc)
* @see de.zbit.Launcher#getInteractiveOptions()
*/
Expand All @@ -332,6 +292,7 @@ public List<Class<? extends KeyProvider>> getInteractiveOptions() {
return getInteractiveConfigOptions();
}


/* (non-Javadoc)
* @see de.zbit.Launcher#getLogPackages()
*/
Expand Down Expand Up @@ -381,7 +342,7 @@ public URL getURLOnlineUpdate() {
*/
@Override
public String getVersionNumber() {
return "2.0";
return "2.0.1";
}

/* (non-Javadoc)
Expand Down Expand Up @@ -409,29 +370,51 @@ public java.awt.Window initGUI(AppConf appConf) {
if (properties.containsKey(IOOptions.SBML_IN_FILE)) {
readSBMLSource(properties.get(IOOptions.SBML_IN_FILE));
}
final SBMLsqueezerUI gui = new SBMLsqueezerUI(getSBMLIO(), appConf);
if (getCmdLineOptions().contains(GarudaOptions.class)
&& (!appConf.getCmdArgs().containsKey(GarudaOptions.CONNECT_TO_GARUDA) ||
appConf.getCmdArgs().getBoolean(GarudaOptions.CONNECT_TO_GARUDA))) {
new Thread(new Runnable() {
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
GarudaSoftwareBackend garudaBackend = new GarudaSoftwareBackend(
"dd624b40-7bc0-11e2-b92a-0800200c9a66", gui);
garudaBackend.init();
} catch (NetworkException exc) {
GUITools.showErrorMessage(gui, exc);
} catch (Throwable exc) {
logger.fine(getMessage(exc));
}
return new SBMLsqueezerUI(getSBMLIO(), appConf);
}

/**
* Does initialization for creating a SBMLsqueezer Object.
* Checks if libSBML is available and initializes the Reader/Writer.
* @param tryLoadingLibSBML
* @param reader
* @param writer
*/
private void initializeReaderAndWriter(boolean tryLoadingLibSBML) {
if (tryLoadingLibSBML) {
if (libSBMLAvailable == null) {
try {
// In order to initialize libSBML, check the java.library.path.
System.loadLibrary("sbmlj");
// Extra check to be sure we have access to libSBML:
Class.forName("org.sbml.libsbml.libsbml");
logger.info(MESSAGES.getString("LOADING_LIBSBML"));
libSBMLAvailable = Boolean.TRUE;
} catch (Error e) {
libSBMLAvailable = Boolean.FALSE;
} catch (Throwable e) {
libSBMLAvailable = Boolean.FALSE;
}
}).start();
}
if (libSBMLAvailable.booleanValue()) {
logger.info(MESSAGES.getString("LAUNCHING_LIBSBML"));
sbmlIo = (SBMLio<T>) new SBMLio<org.sbml.libsbml.Model>(
new LibSBMLReader(), new LibSBMLWriter());
}
}
if (sbmlIo == null) {
logger.info(MESSAGES.getString("LOADING_JSBML"));
sbmlIo = (SBMLio<T>) new SBMLio<Model>(new SqSBMLReader(),
new SqSBMLWriter());
}
return gui;
}

/* (non-Javadoc)
* @see de.zbit.Launcher#isGarudaEnabled()
*/
@Override
public boolean isGarudaEnabled() {
return true;
}

/**
Expand Down Expand Up @@ -594,39 +577,12 @@ public void squeeze(Object sbmlSource, String outfile, boolean searchSABIO) thro
}

/**
* Convenient method that writes a LaTeX file from the given SBML source.
*
* @param sbmlInfile
* @param latexFile
* @throws IOException
* @throws SBMLException
* @throws XMLStreamException
* @param absolutePath
* @param outputPath
* @throws Throwable
*/
public void toLaTeX(Object sbmlSource, String latexFile) throws IOException, SBMLException, XMLStreamException {
readSBMLSource(sbmlSource);
SBPreferences prefsIO = SBPreferences.getPreferencesFor(GUIOptions.class);
String dir = prefsIO.get(GUIOptions.OPEN_DIR).toString();
if (latexFile != null) {
File out = new File(latexFile);
if (SBFileFilter.createTeXFileFilter().accept(out)) {
String path = out.getParent();
if (!path.equals(dir)) {
prefsIO.put(GUIOptions.OPEN_DIR, path);
}
if (!out.exists()) {
long time = System.currentTimeMillis();
logger.info(MESSAGES.getString("WRITING_LATEX_OUTPUT"));
SBML2LaTeX.convert(sbmlIo.getSelectedModel(), out);
logger.info(MessageFormat.format(
MESSAGES.getString("DONE_IN_MS"), (System.currentTimeMillis() - time)) + "\n");
}
} else {
logger.log(Level.WARNING, MessageFormat.format(
WARNINGS.getString("INVALID_TEX_FILE"), latexFile) +"\n");
}
} else {
logger.log(Level.WARNING, WARNINGS.getString("NO_TEX_FILE_PROVIDED"));
}
public void squeeze(String absolutePath, String outputPath) throws Throwable {
squeeze(absolutePath, outputPath, false);
}

/**
Expand Down Expand Up @@ -777,12 +733,39 @@ public Set<Reaction> squeezeWithKineticsFromSABIORK(SBMLDocument sbmlDocument, b
}

/**
* @param absolutePath
* @param outputPath
* @throws Throwable
* Convenient method that writes a LaTeX file from the given SBML source.
*
* @param sbmlInfile
* @param latexFile
* @throws IOException
* @throws SBMLException
* @throws XMLStreamException
*/
public void squeeze(String absolutePath, String outputPath) throws Throwable {
squeeze(absolutePath, outputPath, false);
public void toLaTeX(Object sbmlSource, String latexFile) throws IOException, SBMLException, XMLStreamException {
readSBMLSource(sbmlSource);
SBPreferences prefsIO = SBPreferences.getPreferencesFor(GUIOptions.class);
String dir = prefsIO.get(GUIOptions.OPEN_DIR).toString();
if (latexFile != null) {
File out = new File(latexFile);
if (SBFileFilter.createTeXFileFilter().accept(out)) {
String path = out.getParent();
if (!path.equals(dir)) {
prefsIO.put(GUIOptions.OPEN_DIR, path);
}
if (!out.exists()) {
long time = System.currentTimeMillis();
logger.info(MESSAGES.getString("WRITING_LATEX_OUTPUT"));
SBML2LaTeX.convert(sbmlIo.getSelectedModel(), out);
logger.info(MessageFormat.format(
MESSAGES.getString("DONE_IN_MS"), (System.currentTimeMillis() - time)) + "\n");
}
} else {
logger.log(Level.WARNING, MessageFormat.format(
WARNINGS.getString("INVALID_TEX_FILE"), latexFile) +"\n");
}
} else {
logger.log(Level.WARNING, WARNINGS.getString("NO_TEX_FILE_PROVIDED"));
}
}

}

0 comments on commit 838de21

Please sign in to comment.