diff --git a/lib/SysBio.jar b/lib/SysBio.jar index 9c6838c..2e95728 100644 Binary files a/lib/SysBio.jar and b/lib/SysBio.jar differ diff --git a/lib/jsbml-1.0-incl-libs.jar b/lib/jsbml-1.1-incl-libs.jar similarity index 72% rename from lib/jsbml-1.0-incl-libs.jar rename to lib/jsbml-1.1-incl-libs.jar index 13695a1..956260c 100644 Binary files a/lib/jsbml-1.0-incl-libs.jar and b/lib/jsbml-1.1-incl-libs.jar differ diff --git a/src/de/zbit/graph/SearchSupport.java b/src/de/zbit/graph/SearchSupport.java index 7c5e113..901eb2d 100644 --- a/src/de/zbit/graph/SearchSupport.java +++ b/src/de/zbit/graph/SearchSupport.java @@ -126,9 +126,9 @@ public void onGraphEvent( final GraphEvent e ) { } /** - * Returns the Graph2DView that is associated to the search + * Returns the {@code Graph2DView} that is associated to the search * suuport. - * @return the Graph2DView that is associated to the search + * @return the {@code Graph2DView} that is associated to the search * suuport. */ public Graph2DView getView() { @@ -464,9 +464,9 @@ public void actionPerformed( final ActionEvent e ) { /** * Creates a preconfigured action map for the support's - * find next match and clear result actions. + * find next match and clear result} actions. * @return a preconfigured action map for the support's - * find next match and clear result actions. + * find next match and clear result} actions. * @see #getClearAction() * @see #getNextAction() */ @@ -479,12 +479,12 @@ public ActionMap createActionMap() { /** * Creates a preconfigured input map for the support's - * find next match and clear result actions. + * find next match and clear result} actions. * The default implementation maps the find next match action - * to the F3 function key and the clear search result - * action to the ESCAPE key. + * to the {@code F3} function key and the clear search result + * action to the {@code ESCAPE} key. * @return a preconfigured input map for the support's - * find next match and clear result actions. + * find next match and clear result} actions. * @see #getClearAction() * @see #getNextAction() */ @@ -500,7 +500,7 @@ public InputMap createDefaultInputMap() { private static final Color HIGHLIGHT_COLOR = new Color(202,227,255); /** - * Drawable that highlights search results by drawing a thick, + * {@code Drawable} that highlights search results by drawing a thick, * colored border around search result nodes. */ private final class Marker implements Drawable { @@ -576,7 +576,7 @@ public static final class SearchResult { /** * Add the specified node to the search result set. - * @param node the Node to add. + * @param node the {@code Node} to add. */ void add( final Node node ) { nodes.add(node); @@ -648,7 +648,7 @@ public void emphasizePrevious() { /** * Sorts the nodes in the search result set according to the order * induced by the specified comparator. - * @param c the Comparator to sort the nodes in the search + * @param c the {@code Comparator} to sort the nodes in the search * result set. */ void sort( final Comparator c ) { @@ -656,8 +656,8 @@ void sort( final Comparator c ) { } /** - * Returns a Collection handle for the search result. - * @return a Collection handle for the search result. + * Returns a {@code Collection} handle for the search result. + * @return a {@code Collection} handle for the search result. */ Collection asCollection() { return nodes; @@ -671,9 +671,9 @@ public static interface SearchCriterion { /** * Returns {@code true} if the specified node should be included * in the search result and {@code false} otherwise. - * @param graph the Graph2D to which the specified node + * @param graph the {@code Graph2D} to which the specified node * belongs. - * @param node the Node to test for inclusion in the + * @param node the {@code Node} to test for inclusion in the * search result. * @return {@code true} if the specified node should be included * in the search result and {@code false} otherwise. diff --git a/src/de/zbit/graph/StackingNodeLayout.java b/src/de/zbit/graph/StackingNodeLayout.java index 4928587..3e8d2e6 100644 --- a/src/de/zbit/graph/StackingNodeLayout.java +++ b/src/de/zbit/graph/StackingNodeLayout.java @@ -117,7 +117,7 @@ private StackingNodeLayout(Graph2D graph, Node group, boolean recursive) { /** * Perform a simply stacking layout with {@link #cols} columns. - * @param graph graph in which groupNode is contained + * @param graph graph in which {@code groupNode} is contained * @param groupNode the group node whose childs should be stacked */ public static void doLayout(Graph2D graph, Node groupNode) { @@ -128,7 +128,7 @@ public static void doLayout(Graph2D graph, Node groupNode) { * Perform a simply stacking layout with {@link #cols} columns. * Perform also a stacking layout for all group nodes in this * group node. - * @param graph graph in which groupNode is contained + * @param graph graph in which {@code groupNode} is contained * @param groupNode the group node whose childs should be stacked */ public static void doRecursiveLayout(Graph2D graph, Node groupNode) { @@ -202,7 +202,7 @@ private void layoutGroupNode(Node group) { /** * @param group - * @return all children of the given group node. + * @return all children of the given {@code group} node. */ @SuppressWarnings("unchecked") public List getChildren(Node group) { @@ -220,7 +220,7 @@ public List getChildren(Node group) { * The order of the returned list is fixed: First grouped nodes * than ungrouped nodes! * @param group - * @return all children of the given group + * @return all children of the given {@code group} * node and all group nodes in this group node. */ public List getChildrenDeep(Node group) { diff --git a/src/de/zbit/kegg/Translator.java b/src/de/zbit/kegg/Translator.java index e3c3d9c..c177997 100644 --- a/src/de/zbit/kegg/Translator.java +++ b/src/de/zbit/kegg/Translator.java @@ -526,7 +526,7 @@ public URL getURLOnlineUpdate() { */ @Override public String getVersionNumber() { - return "2.4.0"; + return "2.5"; } /* (non-Javadoc) diff --git a/src/de/zbit/kegg/ext/KEGGTranslatorPanelOptions.java b/src/de/zbit/kegg/ext/KEGGTranslatorPanelOptions.java index b245f4d..f4b2ca1 100644 --- a/src/de/zbit/kegg/ext/KEGGTranslatorPanelOptions.java +++ b/src/de/zbit/kegg/ext/KEGGTranslatorPanelOptions.java @@ -55,7 +55,7 @@ public abstract interface KEGGTranslatorPanelOptions extends de.zbit.graph.gui.o "Select percentage for brightening the KEGG background image.", new Range(Integer.class, "{[0,100]}"), 65, SHOW_KEGG_PICTURE_IN_GRAPH_BACKGROUND, TRUE_RANGE); /** - * TRUE if the image should be converted to a greyscale image. + * {@code true} if the image should be converted to a greyscale image. */ public static final Option GREYSCALE_KEGG_BACKGROUND_IMAGE = new Option("GREYSCALE_KEGG_BACKGROUND_IMAGE", Boolean.class, "If true, converts the KEGG background image to a greyscale picture.", true, SHOW_KEGG_PICTURE_IN_GRAPH_BACKGROUND, TRUE_RANGE); diff --git a/src/de/zbit/kegg/gui/TranslatorPanelTools.java b/src/de/zbit/kegg/gui/TranslatorPanelTools.java index 20c374d..a4732c1 100644 --- a/src/de/zbit/kegg/gui/TranslatorPanelTools.java +++ b/src/de/zbit/kegg/gui/TranslatorPanelTools.java @@ -48,7 +48,12 @@ public static TranslatorPanel createPanel(final File inputFile, final Format TranslatorPanel panel = null; switch (outputFormat) { - case SBML: case SBML_QUAL: case SBML_CORE_AND_QUAL: case SBML_L2V4: case SBML_L3V1: /*case LaTeX: */ + case SBML: + case SBML_QUAL: + case SBML_CORE_AND_QUAL: + case SBML_L2V4: + case SBML_L2V5: + case SBML_L3V1: /*case LaTeX: */ panel = new TranslatorSBMLPanel(inputFile, outputFormat, translationResult); break; diff --git a/src/de/zbit/kegg/gui/TranslatorUI.java b/src/de/zbit/kegg/gui/TranslatorUI.java index 97090bb..0285b2d 100644 --- a/src/de/zbit/kegg/gui/TranslatorUI.java +++ b/src/de/zbit/kegg/gui/TranslatorUI.java @@ -335,7 +335,7 @@ public void actionPerformed(ActionEvent e) { * with the currently selected format and eventually * issues a warning. * @param format - * @return FALSE if the translation should be + * @return {@code false} if the translation should be * stopped. */ protected boolean checkSettingsAndIssueWarning(String format) { @@ -412,7 +412,7 @@ private File getInputFile(JComponent r) { /** * A method to set the value of a currently displayed {@link FileSelector} - * corresponding to the KEGGtranslatorIOOptions.INPUT option. + * corresponding to the {@code KEGGtranslatorIOOptions.INPUT} option. * @param r the JComponent on which the component for the mentioned * optioned is placed. * @param file the file to set diff --git a/src/de/zbit/kegg/io/AbstractKEGGtranslator.java b/src/de/zbit/kegg/io/AbstractKEGGtranslator.java index c1beb33..a7be19c 100644 --- a/src/de/zbit/kegg/io/AbstractKEGGtranslator.java +++ b/src/de/zbit/kegg/io/AbstractKEGGtranslator.java @@ -466,10 +466,10 @@ public void translate(String infile, String outfile) throws Exception { /** * This method converts a given KGML file into the - * specified OutputFormat. + * specified {@code OutputFormat}. * * @param f the input file. - * @return the generated document in OutputFormat. + * @return the generated document in {@code OutputFormat}. * @throws IOException if the input file is not readable. */ @Override diff --git a/src/de/zbit/kegg/io/BatchKEGGtranslator.java b/src/de/zbit/kegg/io/BatchKEGGtranslator.java index b3e46e1..2f596be 100644 --- a/src/de/zbit/kegg/io/BatchKEGGtranslator.java +++ b/src/de/zbit/kegg/io/BatchKEGGtranslator.java @@ -350,6 +350,9 @@ public static KEGGtranslator getTranslator(Format outFormat, KeggInfoManageme case SBML_L2V4: translator = new KEGG2jSBML(manager, 2, 4); break; + case SBML_L2V5: + translator = new KEGG2jSBML(manager, 2, 5); + break; case SBML_L3V1: translator = new KEGG2jSBML(manager, 3, 1); break; diff --git a/src/de/zbit/kegg/io/KEGG2BioPAX.java b/src/de/zbit/kegg/io/KEGG2BioPAX.java index d2e80df..05844d6 100644 --- a/src/de/zbit/kegg/io/KEGG2BioPAX.java +++ b/src/de/zbit/kegg/io/KEGG2BioPAX.java @@ -342,7 +342,7 @@ public BioPAXElement createXRef(IdentifierDatabases db, String id, int type) { /** * Creates a biosource, corresponding to the organism/species of - * the input pathway p. + * the input pathway {@code p}. *

Please call this method only once per model and save the * result somewhere, in case you need it multiple times. * @@ -881,7 +881,7 @@ public void createReactions(Pathway p) { * set. *
But these entries might be reused in relations (i.e., relations involving * reactions) and thus, this method will set the custom attribute of an {@link Entry} - * to the BioPAX reaction given as reaction . + * to the BioPAX reaction given as {@code reaction} . * @param p * @param r KEGG reaction * @param reaction BioPAX reaction @@ -1078,7 +1078,7 @@ protected BioPAXElement getInteractionVocuabulary(SubType st) { * This method tries to denote the vocabulary with an identifiers.org URI. * This has been suggested by Igor R. * @param st the corresponding subtype - * @param proteinModification {@code TRUE} ONLY for modification + * @param proteinModification {@code true} ONLY for modification * vocabularies, such as {@link SequenceModificationVocabulary}. * @return an RDF-ID of the vocabulary element. */ @@ -1155,7 +1155,7 @@ public boolean isGraphicalOutput() { /** * Please implement this method to add the given {@link Entry} - * e as appropriate BioPAX entity to the {@link #model}. + * {@code e} as appropriate BioPAX entity to the {@link #model}. * @param e * @param p * @return created {@link BioPAXElement} @@ -1164,7 +1164,7 @@ public boolean isGraphicalOutput() { /** * Please implement this method to add the given {@link Reaction} - * r as appropriate BioPAX entity to the {@link #model}. + * {@code r} as appropriate BioPAX entity to the {@link #model}. * @param r * @param p * @return created {@link BioPAXElement} @@ -1173,7 +1173,7 @@ public boolean isGraphicalOutput() { /** * Please implement this method to add the given {@link Relation} - * r as appropriate BioPAX entity to the {@link #model}. + * {@code r} as appropriate BioPAX entity to the {@link #model}. * @param r * @param p * @return created {@link BioPAXElement} diff --git a/src/de/zbit/kegg/io/KEGG2BioPAX_level2.java b/src/de/zbit/kegg/io/KEGG2BioPAX_level2.java index 214b5fa..3a7af00 100644 --- a/src/de/zbit/kegg/io/KEGG2BioPAX_level2.java +++ b/src/de/zbit/kegg/io/KEGG2BioPAX_level2.java @@ -354,7 +354,7 @@ public BioPAXElement addEntry(Entry entry, Pathway p) { /** * Searches for the {@link physicalEntityParticipant} represented by the given - * {@link BioPAXElement} ceb. + * {@link BioPAXElement} {@code ceb}. * @param ceb * @return instance of {@link physicalEntityParticipant} */ diff --git a/src/de/zbit/kegg/io/KEGG2SBMLGroupExtension.java b/src/de/zbit/kegg/io/KEGG2SBMLGroupExtension.java index 9cd46ed..7b3a275 100644 --- a/src/de/zbit/kegg/io/KEGG2SBMLGroupExtension.java +++ b/src/de/zbit/kegg/io/KEGG2SBMLGroupExtension.java @@ -31,7 +31,6 @@ import org.sbml.jsbml.NamedSBase; import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.ext.groups.Group; -import org.sbml.jsbml.ext.groups.GroupKind; import org.sbml.jsbml.ext.groups.GroupsConstants; import org.sbml.jsbml.ext.groups.GroupsModelPlugin; import org.sbml.jsbml.ext.groups.Member; @@ -68,17 +67,18 @@ public class KEGG2SBMLGroupExtension { * @param p * @param model * @param entry + * @param groupId * @return */ - public static Group createGroup(Pathway p, Model model, Entry entry) { + public static Group createGroup(Pathway p, Model model, Entry entry, String groupId) { GroupsModelPlugin groupModel = getGroupsModelPlugin(model); // Get all group-members List componentSpeciesIDs = new ArrayList(); if (entry.hasComponents()) { - for (int c:entry.getComponents()) { + for (int c : entry.getComponents()) { Entry ce = p.getEntryForId(c); - if (ce!=null && ce.getCustom()!=null && ce.getCustom() instanceof NamedSBase) { + if ((ce != null) && (ce.getCustom() != null) && (ce.getCustom() instanceof NamedSBase)) { String speciesID = ((NamedSBase)ce.getCustom()).getId(); componentSpeciesIDs.add(speciesID); } @@ -86,24 +86,25 @@ public static Group createGroup(Pathway p, Model model, Entry entry) { } // Create group and add all members - Group g = groupModel.createGroup(); + Group g = groupModel.createGroup(groupId); for (String id: componentSpeciesIDs) { - try{ - g.createMember(id); + try { + Member member = g.createMember(g.getId() + "_member_" + id); + member.setIdRef(id); } catch (Throwable e) { log.log(Level.WARNING, "Duplicated component species ID: " + id); } } // The KIND attribute is required. Possible values are listed in GroupKind - g.setKind(GroupKind.collection); + g.setKind(Group.Kind.collection); return g; } /** - * Clones the given group g + * Clones the given group {@code g} * @param id the id of the new group * @param g * @param prefixForMembers this will be prepended to all member symbols @@ -138,7 +139,7 @@ public static Group cloneGroup(String id, Group g, String prefixForMembers) { } /** - * Duplicates all members of the given group g and + * Duplicates all members of the given group {@code g} and * adds a prefix to all duplicated members. * @param g * @param prefixForMembers @@ -159,7 +160,8 @@ public static void cloneGroupComponents(Group g, String prefixForMembers) { if (prefixForMembers!=null) { if (!symbol.startsWith(prefixForMembers)) { symbol = prefixForMembers + symbol; - g.createMember(symbol); + Member member = g.createMember(g.getId() + "_member_" + symbol); + member.setIdRef(symbol); } } } diff --git a/src/de/zbit/kegg/io/KEGG2SBMLLayoutExtension.java b/src/de/zbit/kegg/io/KEGG2SBMLLayoutExtension.java index e5c8e73..f7374db 100644 --- a/src/de/zbit/kegg/io/KEGG2SBMLLayoutExtension.java +++ b/src/de/zbit/kegg/io/KEGG2SBMLLayoutExtension.java @@ -135,7 +135,12 @@ public static void addLayoutExtension(Pathway p, SBMLDocument doc, Model model, // => track min and max values. MinAndMaxTracker tracker = new MinAndMaxTracker(); - Map idCounts = new HashMap(); + String keyWord = "KEGGtranslator_idCounts"; + Map idCounts = (Map) doc.getUserObject(keyWord); + if (idCounts == null) { + idCounts = new HashMap(); + doc.putUserObject(keyWord, idCounts); + } Map keggReactionName2glyph = new HashMap(); // First, create a glyph for each reaction @@ -171,7 +176,7 @@ public static void addLayoutExtension(Pathway p, SBMLDocument doc, Model model, // Create a glyph for each entry (In KGML, only entries have graph objects) for (Entry e : p.getEntries()) { Object s = e.getCustom(); - if (s!=null && e.hasGraphics()) { + if ((s != null) && e.hasGraphics()) { Graphics g = e.getGraphics(); boolean isLineGraphic = g.getType().equals(GraphicsType.line); if (isLineGraphic) { diff --git a/src/de/zbit/kegg/io/KEGG2SBMLqual.java b/src/de/zbit/kegg/io/KEGG2SBMLqual.java index 74d3ea8..ed4517b 100644 --- a/src/de/zbit/kegg/io/KEGG2SBMLqual.java +++ b/src/de/zbit/kegg/io/KEGG2SBMLqual.java @@ -21,6 +21,7 @@ package de.zbit.kegg.io; import java.io.File; +import java.text.MessageFormat; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -35,6 +36,7 @@ import org.sbml.jsbml.NamedSBase; import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.Species; +import org.sbml.jsbml.TidySBMLWriter; import org.sbml.jsbml.ext.SBasePlugin; import org.sbml.jsbml.ext.groups.Group; import org.sbml.jsbml.ext.qual.Input; @@ -47,7 +49,6 @@ import org.sbml.jsbml.ext.qual.Sign; import org.sbml.jsbml.ext.qual.Transition; import org.sbml.jsbml.util.ValuePair; -import org.sbml.jsbml.xml.stax.SBMLWriter; import de.zbit.cache.InfoManagement; import de.zbit.kegg.KEGGtranslatorOptions; @@ -186,14 +187,14 @@ protected SBMLDocument translateWithoutPreprocessing(Pathway p) throws XMLStream // Add extension and namespace to model doc.addNamespace(KEGG2SBMLqual.QUAL_NS_NAME, "xmlns", KEGG2SBMLqual.QUAL_NS); - doc.getSBMLDocumentAttributes().put(QUAL_NS_NAME + ":required", (isCombindedModel?"false":"true")); + doc.getSBMLDocumentAttributes().put(QUAL_NS_NAME + ":required", (isCombindedModel? "false" : "true")); model.addExtension(KEGG2SBMLqual.QUAL_NS, qualModel); - /* Until (INCLUDING) Verison 2.2, if there were no relations, no qual species + /* Until (INCLUDING) Version 2.2, if there were no relations, no qual species * have been created. The comment was as follows: * * // Qualitative species are just created if transitions are available - * // Reason: all species are in the file as normal sbml species. Following the + * // Reason: all species are in the file as normal SBML species. Following the * // qualitative species are not necessary */ @@ -234,12 +235,12 @@ protected SBMLDocument translateWithoutPreprocessing(Pathway p) throws XMLStream * @param qualModel */ private void createQualSpecies(Pathway p, QualModelPlugin qualModel) { - for (Entry e: p.getEntries()) { + for (Entry e : p.getEntries()) { Object s = e.getCustom(); - if (s!=null && s instanceof Species) { + if ((s != null) && (s instanceof Species)) { QualitativeSpecies qs = createQualitativeSpeciesFromSpecies((Species) s, qualModel); e.setCustom(qs); - } else if (s!=null && s instanceof Group) { + } else if ((s != null) && (s instanceof Group)) { Group updatedReferences = createQualitativeGroupFromGroup((Group) s); e.setCustom(updatedReferences); // Sinmply KEEP non-species objects (e.g., groups when using the group extension) @@ -390,7 +391,13 @@ public Transition addKGMLRelation(Relation r, Pathway p, QualModelPlugin qualMod StringBuffer notes = new StringBuffer(KEGG2jSBML.notesStartString); notes.append(String.format("This transition is defined by '%s'.\n", r.getSource())); notes.append(KEGG2jSBML.notesEndString); - t.setNotes(notes.toString()); + try { + t.setNotes(notes.toString()); + } catch (Throwable exc) { + logger.warning(MessageFormat.format( + "Cannot write notes for species ''{0}'' because of {1}: {2}.", + t.getId(), exc.getClass().getName(), Utils.getMessage(exc))); + } } // Don't add same relations twice @@ -527,7 +534,7 @@ && new File(Translator.cacheFileName).length() > 1) { // k2s.translate("files/KGMLsamplefiles/hsa00010.xml", "files/KGMLsamplefiles/hsa00010.sbml.xml"); SBMLDocument doc = k2s.translate(new File("files/KGMLsamplefiles/hsa04210.xml")); - new SBMLWriter().write(doc, "files/KGMLsamplefiles/hsa04210.sbml.xml"); + TidySBMLWriter.write(doc, "files/KGMLsamplefiles/hsa04210.sbml.xml", ' ', (short) 2); // Remember already queried objects if (AbstractKEGGtranslator.getKeggInfoManager().hasChanged()) { diff --git a/src/de/zbit/kegg/io/KEGG2jSBML.java b/src/de/zbit/kegg/io/KEGG2jSBML.java index d48751a..afa40f9 100644 --- a/src/de/zbit/kegg/io/KEGG2jSBML.java +++ b/src/de/zbit/kegg/io/KEGG2jSBML.java @@ -21,6 +21,7 @@ package de.zbit.kegg.io; import java.io.File; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -49,9 +50,11 @@ import org.sbml.jsbml.SBase; import org.sbml.jsbml.Species; import org.sbml.jsbml.SpeciesReference; +import org.sbml.jsbml.TidySBMLWriter; import org.sbml.jsbml.UnitDefinition; +import org.sbml.jsbml.ext.fbc.FBCConstants; +import org.sbml.jsbml.ext.fbc.FBCSpeciesPlugin; import org.sbml.jsbml.util.ValuePair; -import org.sbml.jsbml.xml.stax.SBMLWriter; import de.zbit.cache.InfoManagement; import de.zbit.kegg.AtomBalanceCheck; @@ -119,14 +122,14 @@ public class KEGG2jSBML extends AbstractKEGGtranslator { private double speciesDefaultInitialAmount = 1d; /** - * The SBML level to be initialized. NULL results in + * The SBML level to be initialized. {@code NULL} results in * initializing it automatically (adjusts the level as needed (e.g. * extensions require L3)). */ protected Integer level = null; /** - * The SBML version to be initialized. NULL results in + * The SBML version to be initialized. {@code NULL} results in * initializing it automatically (adjusts it as needed). */ protected Integer version = null; @@ -270,7 +273,7 @@ private void loadPreferences() { private void configureReactionComponent(Pathway p, ReactionComponent rc, SpeciesReference sr, int SBO) { if (!rc.isSetID() && !rc.isSetName()) { rc = rc.getAlt(); - if (rc==null || ((!rc.isSetID() && !rc.isSetName()))) { + if ((rc == null) || ((!rc.isSetID() && !rc.isSetName()))) { return; } } @@ -292,7 +295,7 @@ private void configureReactionComponent(Pathway p, ReactionComponent rc, Species // Set the stoichiometry Integer stoich = rc.getStoichiometry(); - sr.setStoichiometry(stoich==null?1d:stoich); + sr.setStoichiometry(stoich == null ? 1d : stoich); // Get Species for ReactionComponent and assign to SpeciesReference. Entry rcEntry = p.getEntryForReactionComponent(rc); @@ -320,8 +323,7 @@ public boolean writeToFile(SBMLDocument doc, String outFile) { lastFileWasOverwritten=true; } try { - SBMLWriter writer = new SBMLWriter(); - writer.write(doc, outFile, System.getProperty("app.name"), System + TidySBMLWriter.write(doc, outFile, System.getProperty("app.name"), System .getProperty("app.version")); } catch (Exception e) { log.log(Level.SEVERE, "Could not write SBML document.", e); @@ -616,7 +618,13 @@ else if (p.isSetLink()) { // Finalize notes and annotations. notes.append(notesEndString); - model.setNotes(notes.toString()); + try { + model.setNotes(notes.toString()); + } catch (Throwable t) { + logger.warning(MessageFormat.format( + "Cannot write notes for model ''{0}'' because of {1}: {2}.", + model.getId(), t.getClass().getName(), Utils.getMessage(t))); + } if (addCellDesignerAnnots) { cdu.addCellDesignerAnnotationToModel(p, model, compartment); } @@ -651,7 +659,7 @@ private Compartment createCompartment(Model model) { } /** - * Create a compartment with the given name. + * Create a compartment with the given {@code name}. * @param model * @param name * @return @@ -783,12 +791,12 @@ private org.sbml.jsbml.Reaction addKGMLReaction(Reaction r, Pathway p, Model mod // Add substrates/ products sbReaction.setReversible(r.getType().equals(ReactionType.reversible)); for (ReactionComponent rc : r.getSubstrates()) { - int sbo = (r.getType().equals(ReactionType.irreversible))?15:10; + int sbo = (r.getType().equals(ReactionType.irreversible))? 15 : 10; SpeciesReference sr = sbReaction.createReactant(); configureReactionComponent(p, rc, sr, sbo); // 15=Substrate, 10=Reactant } for (ReactionComponent rc : r.getProducts()) { - int sbo = (r.getType().equals(ReactionType.irreversible))?11:10; + int sbo = (r.getType().equals(ReactionType.irreversible))? 11 : 10; SpeciesReference sr = sbReaction.createProduct(); configureReactionComponent(p, rc, sr, sbo); // 11=Product } @@ -866,7 +874,6 @@ private org.sbml.jsbml.Reaction addKGMLReaction(Reaction r, Pathway p, Model mod sbReaction.addCVTerm(rePWs); } - // Check the atom balance (only makes sense if reactions are corrected, // else, they are clearly wrong). if (autocompleteReactions && checkAtomBalance) { @@ -895,7 +902,13 @@ private org.sbml.jsbml.Reaction addKGMLReaction(Reaction r, Pathway p, Model mod sbReaction.setName(r.getName()); sbReaction.setId(NameToSId(r.getName())); notes.append(notesEndString); - sbReaction.setNotes(notes.toString()); + try { + sbReaction.setNotes(notes.toString()); + } catch (Throwable t) { + logger.warning(MessageFormat.format( + "Cannot write notes for reaction ''{0}'' because of {1}: {2}.", + sbReaction.getId(), t.getClass().getName(), Utils.getMessage(t))); + } sbReaction.setMetaId("meta_" + sbReaction.getId()); sbReaction.setSBOTerm(176); // biochemical reaction. Most generic SBO Term possible, for a reaction. //rAnnot.setAbout("#" + sbReaction.getMetaId()); @@ -1112,10 +1125,10 @@ public static String concatReactionIDs(Collection reactions, String... } /** - * Assigns a {@link Qualifier} to CVterm, dependent + * Assigns a {@link Qualifier} to {@code CVterm}, dependent * on the number of contained resources. If this CVTerm contains - * one resource, BQB_IS is assigned, else - * BQB_HAS_VERSION + * one resource, {@code BQB_IS} is assigned, else + * {@code BQB_HAS_VERSION} * is assignes. * @param CVterm any CVTerm */ @@ -1204,11 +1217,11 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp // --- // Initialize species object - SBase spec; + NamedSBase spec; + String id = NameToSId(name.replace(' ', '_')); // defined in org.sbml.jsbml.NamedSBase if (useGroupsExtension && (entry.hasComponents() || entry.getType().equals(EntryType.group))) { - spec = KEGG2SBMLGroupExtension.createGroup(p, model, entry); + spec = KEGG2SBMLGroupExtension.createGroup(p, model, entry, "group_" + id); } else { - spec = model.createSpecies(); // Eventually assign a different compartment Compartment c = compartment; @@ -1226,8 +1239,7 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp } } } - ((Species) spec).setCompartment(c); - + spec = model.createSpecies(id, c); } if (spec instanceof Species) { @@ -1239,6 +1251,25 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp ((Species) spec).setHasOnlySubstanceUnits(false); ((Species) spec).setBoundaryCondition(false); ((Species) spec).setConstant(false); // defined in org.sbml.jsbml.Variable + + + KeggInfos infos = KeggInfos.get(entry.getName(), manager); + + if ((infos != null) && infos.queryWasSuccessfull()) { + + // Component.getName() might be a glycan and the chemical formula is only given for compounds + // => Look if we have synonym identifers for KEGG compound and refetch + String formula = infos.getFormulaDirectOrFromSynonym(manager); + if (formula != null) { + FBCSpeciesPlugin specPlug = (FBCSpeciesPlugin) spec.getPlugin(FBCConstants.getNamespaceURI(spec.getLevel(), spec.getVersion(), 2)); + try { + specPlug.setChemicalFormula(formula); + } catch (IllegalArgumentException exc) { + logger.warning(exc.getClass().getSimpleName() + ": " + Utils.getMessage(exc)); + } + } + } + } ((Species) spec).setInitialAmount(speciesDefaultInitialAmount); //((Species) spec).setUnits(model.getUnitDefinition("substance")); @@ -1247,8 +1278,7 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp // ID has to be at this place, because other refer to it by id and if id is not set. refenreces go to null. // spec.setId(NameToSId(entry.getName().replace(' ', '_'))); if (spec instanceof NamedSBase) { - ((NamedSBase)spec).setId(NameToSId(name.replace(' ', '_'))); // defined in org.sbml.jsbml.NamedSBase - spec.setMetaId("meta_" + ((NamedSBase) spec).getId()); // defined in org.sbml.jsbml.SBase + spec.setMetaId("meta_" + spec.getId()); // defined in org.sbml.jsbml.SBase } //Annotation specAnnot = new Annotation(""); @@ -1256,7 +1286,7 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp //spec.setAnnotation(specAnnot); // manchmal ist jSBML schon bescheurt... StringBuffer notes = new StringBuffer(notesStartString); if (entry.isSetLink()) { - notes.append(String.format("Original Kegg Entry
\n", entry.getLink())); + notes.append(String.format("Original Kegg Entry
\n", entry.getLink().replace("&", "&"))); } @@ -1271,11 +1301,11 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp CVTerm cvt = new CVTerm(Type.BIOLOGICAL_QUALIFIER,Qualifier.BQB_IS_ENCODED_BY); for (int c:entry.getComponents()) { Entry ce = p.getEntryForId(c); - if (ce==null) { + if (ce == null) { notesAppend.append("

  • Unknown
  • "); } else { String ce_name = getNameForEntry(ce); - notesAppend.append(String.format("
  • %s
  • ",ce_name)); + notesAppend.append(String.format("
  • %s
  • ", ce_name)); // Append all kegg ids as "has_part" NLN: Should be "IS_ENCONDED_BY" for (String kg_id: ce.getName().split(" ")) { @@ -1297,7 +1327,13 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp // Set notes here, so other methods (miriam) can append the notes. notes.append(notesEndString); - spec.setNotes(notes.toString()); + try { + spec.setNotes(notes.toString()); + } catch (Throwable t) { + logger.warning(MessageFormat.format( + "Cannot write notes for species ''{0}'' because of {1}: {2}.", + spec.getId(), t.getClass().getName(), Utils.getMessage(t))); + } // Set SBO Term spec.setSBOTerm(SBOMapping.getSBOTerm(entry)); @@ -1306,7 +1342,7 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp addMiriamURNs(entry, spec); // Finally, add the fully configured species. - ((NamedSBase) spec).setName(name); + spec.setName(name); //specAnnot.setAbout("#" + spec.getMetaId()); entry.setCustom(spec); // Remember node in KEGG Structure for further references. // NOT here, because it may depend on other entries, that are not yet processed. @@ -1318,7 +1354,7 @@ private SBase addKGMLEntry(Entry entry, Pathway p, Model model, Compartment comp /** * Creates a {@link ModifierSpeciesReference} for entry and spec and adds this reference - * to the reactionModifiers list. + * to the {@code reactionModifiers} list. * * @param entry * @param spec diff --git a/src/de/zbit/kegg/io/KEGG2yGraph.java b/src/de/zbit/kegg/io/KEGG2yGraph.java index 05ee64c..0be6569 100644 --- a/src/de/zbit/kegg/io/KEGG2yGraph.java +++ b/src/de/zbit/kegg/io/KEGG2yGraph.java @@ -1297,7 +1297,7 @@ protected Graph2D translateWithoutPreprocessing(Pathway p) { } /** - * Returns {@code TRUE} if a direct relation between the given + * Returns {@code true} if a direct relation between the given * entry {@code one} and {@code two} exists. * @param one * @param two @@ -1334,8 +1334,8 @@ public static boolean directRelation(Entry one, Entry two) { } /** - * Links all information in all nodeMaps that are - * assigned to oldNode also to the newNode. + * Links all information in all {@code nodeMaps} that are + * assigned to {@code oldNode} also to the {@code newNode}. * @param nodeMaps * @param oldNode * @param newNode @@ -1403,12 +1403,12 @@ private void stackGroupNodeContents(Graph2D graph, Set toLayout) { } /** - * Layoutes the node parent if all children are contained - * in toLayout. (Uses {@link StackingNodeLayout}). + * Layoutes the node {@code parent} if all children are contained + * in {@code toLayout}. (Uses {@link StackingNodeLayout}). * @param graph * @param parent * @param toLayout nodes without layout information - * @return TRUE if a layout has been applied, + * @return {@code true} if a layout has been applied, */ @SuppressWarnings("unchecked") private boolean layoutIfallChildsAreInSet(Graph2D graph, Node parent, Set toLayout) { @@ -1553,7 +1553,7 @@ private NodeRealizer setupGraphics(NodeRealizer nr, NodeLabel nl, Graphics g) { * @param graph * @param reactionModifiers * @return the intermediate reaction node (should be layouted!) or - * NULL if the reaction wasn't drawn. + * {@code NULL} if the reaction wasn't drawn. */ private Node addKGMLReaction(Reaction r, Pathway p, Graph2D graph, Map> reactionModifiers) { if (!reactionHasAtLeastOneSubstrateAndProduct(r, p)) { @@ -1665,17 +1665,17 @@ private Node addKGMLReaction(Reaction r, Pathway p, Graph2D graph, Mapchilds that belong to + * Bundles all {@code childs} that belong to * the same group node (i.e., parent), by removing the * childs from the list and adding the parent group node. * Only if all childs of (any) group nodes in the graph - * are inside the childs list, this bundling + * are inside the {@code childs} list, this bundling * is performed. * If only a subset of a group node is given as childs or * no given node belongs to a group node, the list is * returned unmodifified. * @param childs - * @return common group node parent or NULL. + * @return common group node parent or {@code NULL}. */ private List bundle(Graph2D graph, List childs) { if (childs==null || !childs.iterator().hasNext()) { diff --git a/src/de/zbit/kegg/io/KEGGtranslatorIOOptions.java b/src/de/zbit/kegg/io/KEGGtranslatorIOOptions.java index 4751448..d62f3b5 100644 --- a/src/de/zbit/kegg/io/KEGGtranslatorIOOptions.java +++ b/src/de/zbit/kegg/io/KEGGtranslatorIOOptions.java @@ -58,6 +58,10 @@ public enum Format { * */ SBML_L2V4, + /** + * SBML Level 2 Version 5 + */ + SBML_L2V5, /** * */ diff --git a/src/de/zbit/kegg/io/SBOMapping.java b/src/de/zbit/kegg/io/SBOMapping.java index 7263171..d60b5b6 100644 --- a/src/de/zbit/kegg/io/SBOMapping.java +++ b/src/de/zbit/kegg/io/SBOMapping.java @@ -180,7 +180,7 @@ public class SBOMapping { /** * Get the most appropriate SBO term for this - * entry. + * {@code entry}. * @param entry * @return */ @@ -280,10 +280,10 @@ public static int getGOTerm(String subtype) { } /** - * Convert subtype to a MI-term that is a child of 'MI:0190' (Molecular Interaction (PSI-MI)). + * Convert {@code subtype} to a MI-term that is a child of 'MI:0190' (Molecular Interaction (PSI-MI)). * The terms are for relations/interactions. * @param subtype - * @return {@link ValuePair} with the term name and integer id. Or NULL if + * @return {@link ValuePair} with the term name and integer id. Or {@code NULL} if * no MI term is available that matches the given input {@link SubType}. */ public static ValuePair getMITerm(String subtype) { @@ -338,11 +338,11 @@ public static ValuePair getMITerm(String subtype) { } /** - * Convert subtype to a MOD-term (Protein Modification Ontology (PSI-MOD)) + * Convert {@code subtype} to a MOD-term (Protein Modification Ontology (PSI-MOD)) * that is either a child of 'MOD:01157' or 'MOD:01156'. *

    The terms are for entries that are modified as result of an relation/interaction. * @param subtype - * @return {@link ValuePair} with the term name and integer id. Or NULL if + * @return {@link ValuePair} with the term name and integer id. Or {@code NULL} if * no MI term is available that matches the given input {@link SubType}. */ public static ValuePair getMODTerm(String subtype) { diff --git a/src/de/zbit/util/TranslatorTools.java b/src/de/zbit/util/TranslatorTools.java index 7384677..91b2483 100644 --- a/src/de/zbit/util/TranslatorTools.java +++ b/src/de/zbit/util/TranslatorTools.java @@ -73,7 +73,7 @@ public class TranslatorTools extends GraphTools { public static final transient Logger log = Logger.getLogger(TranslatorTools.class.getName()); /** - * Static String for the type {@link NodeMap} of the {@link #graph} + * Static String for the {@code type} {@link NodeMap} of the {@link #graph} * to be used for, e.g. microRNAs. */ public final static String RNA_TYPE = "RNA"; @@ -182,7 +182,7 @@ public Set getMapDescriptors() { } /** - * Get a reverse map for the descriptor. This means, + * Get a reverse map for the {@code descriptor}. This means, * descriptor object to List of nodes with this descriptor. *

    Key is an Object, Value is a

    List
    * @param descriptor diff --git a/test/de/zbit/kegg/gui/ReactionPanelTest.java b/test/de/zbit/kegg/gui/ReactionPanelTest.java index 44e46ed..097b07c 100644 --- a/test/de/zbit/kegg/gui/ReactionPanelTest.java +++ b/test/de/zbit/kegg/gui/ReactionPanelTest.java @@ -35,7 +35,7 @@ import org.sbml.jsbml.SBMLException; import org.sbml.jsbml.Species; import org.sbml.jsbml.SpeciesReference; -import org.sbml.jsbml.xml.stax.SBMLWriter; +import org.sbml.jsbml.TidySBMLWriter; import de.zbit.sbml.gui.ReactionPanel; @@ -54,10 +54,7 @@ public class ReactionPanelTest { public static void main(String[] args) throws XMLStreamException, SBMLException { SBMLDocument doc = createSimpleSBMLDocument(1, 2, 2, false); - SBMLWriter writer = new SBMLWriter(); - writer.setIndentationCount(2); - writer.setIndentationChar(' '); - System.out.println(writer.writeSBMLToString(doc)); + TidySBMLWriter.write(doc, System.out, null, null); JFrame f = new JFrame("Reaction test"); JPanel panel = new ReactionPanel(doc.getModel().getReaction(0), false); panel.setBackground(Color.WHITE);