Skip to content

Commit

Permalink
Bug fixes, added support for L2V5, correct indentation of generated S…
Browse files Browse the repository at this point in the history
…BML files, and new third-party libraries:

* New libs JSBML and SysBio
* JSBML lib is smaller in parts because unused packages are no longer in this JAR, but I added the tidy project for correct indentation.
* Fixed bugs: groups extension wasn't correctly used and duplicate ids were often generated (also in other cases).
* Bug with incorrect links; I added a replacement of ampersent characters for encoding these links.
* Added more try-catch blocks to avoid crashing of the program upon one error.
  • Loading branch information
draeger committed Sep 13, 2015
1 parent 20a82c9 commit c2e77c3
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 106 deletions.
Binary file modified lib/SysBio.jar
Binary file not shown.
Binary file not shown.
30 changes: 15 additions & 15 deletions src/de/zbit/graph/SearchSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public void onGraphEvent( final GraphEvent e ) {
}

/**
* Returns the <code>Graph2DView</code> that is associated to the search
* Returns the {@code Graph2DView} that is associated to the search
* suuport.
* @return the <code>Graph2DView</code> that is associated to the search
* @return the {@code Graph2DView} that is associated to the search
* suuport.
*/
public Graph2DView getView() {
Expand Down Expand Up @@ -464,9 +464,9 @@ public void actionPerformed( final ActionEvent e ) {

/**
* Creates a preconfigured action map for the support's
* <em>find next match</em> and <em>clear result</code> actions.
* <em>find next match</em> and <em>clear result} actions.
* @return a preconfigured action map for the support's
* <em>find next match</em> and <em>clear result</code> actions.
* <em>find next match</em> and <em>clear result} actions.
* @see #getClearAction()
* @see #getNextAction()
*/
Expand All @@ -479,12 +479,12 @@ public ActionMap createActionMap() {

/**
* Creates a preconfigured input map for the support's
* <em>find next match</em> and <em>clear result</code> actions.
* <em>find next match</em> and <em>clear result} actions.
* The default implementation maps the <em>find next match</em> action
* to the <code>F3</code> function key and the <em>clear search result</em>
* action to the <code>ESCAPE</code> key.
* to the {@code F3} function key and the <em>clear search result</em>
* action to the {@code ESCAPE} key.
* @return a preconfigured input map for the support's
* <em>find next match</em> and <em>clear result</code> actions.
* <em>find next match</em> and <em>clear result} actions.
* @see #getClearAction()
* @see #getNextAction()
*/
Expand All @@ -500,7 +500,7 @@ public InputMap createDefaultInputMap() {
private static final Color HIGHLIGHT_COLOR = new Color(202,227,255);

/**
* <code>Drawable</code> 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 {
Expand Down Expand Up @@ -576,7 +576,7 @@ public static final class SearchResult {

/**
* Add the specified node to the search result set.
* @param node the <code>Node</code> to add.
* @param node the {@code Node} to add.
*/
void add( final Node node ) {
nodes.add(node);
Expand Down Expand Up @@ -648,16 +648,16 @@ public void emphasizePrevious() {
/**
* Sorts the nodes in the search result set according to the order
* induced by the specified comparator.
* @param c the <code>Comparator</code> 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 ) {
nodes.sort(c);
}

/**
* Returns a <code>Collection</code> handle for the search result.
* @return a <code>Collection</code> 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;
Expand All @@ -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 <code>Graph2D</code> to which the specified node
* @param graph the {@code Graph2D} to which the specified node
* belongs.
* @param node the <code>Node</code> 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.
Expand Down
8 changes: 4 additions & 4 deletions src/de/zbit/graph/StackingNodeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>groupNode</code> 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) {
Expand All @@ -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 <code>groupNode</code> 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) {
Expand Down Expand Up @@ -202,7 +202,7 @@ private void layoutGroupNode(Node group) {

/**
* @param group
* @return all children of the given <code>group</code> node.
* @return all children of the given {@code group} node.
*/
@SuppressWarnings("unchecked")
public List<Node> getChildren(Node group) {
Expand All @@ -220,7 +220,7 @@ public List<Node> 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 <code>group</code>
* @return all children of the given {@code group}
* node and all group nodes in this group node.
*/
public List<Node> getChildrenDeep(Node group) {
Expand Down
2 changes: 1 addition & 1 deletion src/de/zbit/kegg/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public URL getURLOnlineUpdate() {
*/
@Override
public String getVersionNumber() {
return "2.4.0";
return "2.5";
}

/* (non-Javadoc)
Expand Down
2 changes: 1 addition & 1 deletion src/de/zbit/kegg/ext/KEGGTranslatorPanelOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>(Integer.class, "{[0,100]}"), 65, SHOW_KEGG_PICTURE_IN_GRAPH_BACKGROUND, TRUE_RANGE);

/**
* <code>TRUE</code> 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<Boolean> GREYSCALE_KEGG_BACKGROUND_IMAGE = new Option<Boolean>("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);
Expand Down
7 changes: 6 additions & 1 deletion src/de/zbit/kegg/gui/TranslatorPanelTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/de/zbit/kegg/gui/TranslatorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void actionPerformed(ActionEvent e) {
* with the currently selected format and eventually
* issues a warning.
* @param format
* @return <code>FALSE</code> if the translation should be
* @return {@code false} if the translation should be
* stopped.
*/
protected boolean checkSettingsAndIssueWarning(String format) {
Expand Down Expand Up @@ -412,7 +412,7 @@ private File getInputFile(JComponent r) {

/**
* A method to set the value of a currently displayed {@link FileSelector}
* corresponding to the <code>KEGGtranslatorIOOptions.INPUT</code> 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
Expand Down
4 changes: 2 additions & 2 deletions src/de/zbit/kegg/io/AbstractKEGGtranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ public void translate(String infile, String outfile) throws Exception {

/**
* This method converts a given KGML file into the
* specified <code>OutputFormat</code>.
* specified {@code OutputFormat}.
*
* @param f the input file.
* @return the generated document in <code>OutputFormat</code>.
* @return the generated document in {@code OutputFormat}.
* @throws IOException if the input file is not readable.
*/
@Override
Expand Down
3 changes: 3 additions & 0 deletions src/de/zbit/kegg/io/BatchKEGGtranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/de/zbit/kegg/io/KEGG2BioPAX.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>p</code>.
* the input pathway {@code p}.
* <p> Please call this method only once per model and save the
* result somewhere, in case you need it multiple times.
*
Expand Down Expand Up @@ -881,7 +881,7 @@ public void createReactions(Pathway p) {
* set.
* <br/>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 <code>reaction</code> .
* to the BioPAX reaction given as {@code reaction} .
* @param p
* @param r KEGG reaction
* @param reaction BioPAX reaction
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -1155,7 +1155,7 @@ public boolean isGraphicalOutput() {

/**
* Please implement this method to add the given {@link Entry}
* <code>e</code> 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}
Expand All @@ -1164,7 +1164,7 @@ public boolean isGraphicalOutput() {

/**
* Please implement this method to add the given {@link Reaction}
* <code>r</code> 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}
Expand All @@ -1173,7 +1173,7 @@ public boolean isGraphicalOutput() {

/**
* Please implement this method to add the given {@link Relation}
* <code>r</code> 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}
Expand Down
2 changes: 1 addition & 1 deletion src/de/zbit/kegg/io/KEGG2BioPAX_level2.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public BioPAXElement addEntry(Entry entry, Pathway p) {

/**
* Searches for the {@link physicalEntityParticipant} represented by the given
* {@link BioPAXElement} <code>ceb</code>.
* {@link BioPAXElement} {@code ceb}.
* @param ceb
* @return instance of {@link physicalEntityParticipant}
*/
Expand Down
24 changes: 13 additions & 11 deletions src/de/zbit/kegg/io/KEGG2SBMLGroupExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,42 +67,44 @@ 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<String> componentSpeciesIDs = new ArrayList<String>();
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);
}
}
}

// 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 <code>g</code>
* 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
Expand Down Expand Up @@ -138,7 +139,7 @@ public static Group cloneGroup(String id, Group g, String prefixForMembers) {
}

/**
* Duplicates all members of the given group <code>g</code> and
* Duplicates all members of the given group {@code g} and
* adds a prefix to all duplicated members.
* @param g
* @param prefixForMembers
Expand All @@ -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);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/de/zbit/kegg/io/KEGG2SBMLLayoutExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ public static void addLayoutExtension(Pathway p, SBMLDocument doc, Model model,
// => track min and max values.
MinAndMaxTracker tracker = new MinAndMaxTracker();

Map<String, Integer> idCounts = new HashMap<String, Integer>();
String keyWord = "KEGGtranslator_idCounts";
Map<String, Integer> idCounts = (Map<String, Integer>) doc.getUserObject(keyWord);
if (idCounts == null) {
idCounts = new HashMap<String, Integer>();
doc.putUserObject(keyWord, idCounts);
}
Map<String, ReactionGlyph> keggReactionName2glyph = new HashMap<String, ReactionGlyph>();

// First, create a glyph for each reaction
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit c2e77c3

Please sign in to comment.