Skip to content

Commit

Permalink
KEGGtranslator release 1.2 and associated changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemens82 committed Jul 4, 2011
1 parent 0067edd commit a954aa6
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<!-- Uncomment for SysBio classes instead of compiled jar. -->
<fileset dir="${SysBioPath}/bin">
<exclude name="de/zbit/resources/liftover/*"/>
<exclude name="de/zbit/mapper/*"/>
<exclude name="**/package.html"/>
</fileset>
<!-- Achtung, im ersten SysBio release befinden sich bugs in KeggInfos.java ! -->
Expand All @@ -103,7 +104,6 @@
<!-- <zipfileset excludes="META-INF/*.SF" src="${SysBioPath}/lib/Java5/saaj.jar"/>-->
<!-- <zipfileset excludes="META-INF/*.SF" src="${SysBioPath}/lib/WSDbfetch.jar"/>-->
<zipfileset excludes="META-INF/*" src="${SysBioPath}/lib/commons-cli-1.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${SysBioPath}/lib/argparser.jar"/>

<fileset dir="${JSBMLPath}/bin">
<exclude name="log4j.properties"/> <!-- log4j.properties is in SBML2Latex and jSBML -->
Expand Down
44 changes: 44 additions & 0 deletions src/de/zbit/kegg/TranslatorTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.logging.Logger;

import y.base.DataMap;
import y.base.Graph;
import y.base.Node;
import y.base.NodeMap;
import y.view.Graph2D;
Expand Down Expand Up @@ -104,6 +105,10 @@ public Map<Integer, List<Node>> getGeneID2NodeMap() {
break;
}
}
if (entrez==null) {
log.severe("Could not find Node2EntrezID mapping.");
return null;
}

// build the resulting map
for (Node n : graph.getNodeArray()) {
Expand Down Expand Up @@ -131,4 +136,43 @@ public Map<Integer, List<Node>> getGeneID2NodeMap() {
return id2node;
}

/**
* @param n a node
* @param descriptor e.g., "keggIds" or "entrezIds". See {@link KEGG2yGraph} for a complete list.
* @return the string associated with this node.
*/
@SuppressWarnings("unchecked")
public static String getNodeInfoIDs(Node n, String descriptor) {
Graph graph = n.getGraph();

// Get the NodeMap from kegg 2 node.
GenericDataMap<DataMap, String> mapDescriptionMap = (GenericDataMap<DataMap, String>) graph.getDataProvider(KEGG2yGraph.mapDescription);
NodeMap nodeMap = null;
if (mapDescriptionMap==null) return null;
for (int i=0; i<graph.getRegisteredNodeMaps().length; i++) {
NodeMap nm = graph.getRegisteredNodeMaps()[i];
if (mapDescriptionMap.getV(nm).equals(descriptor)) {
nodeMap = nm;
break;
}
}
if (nodeMap==null) {
log.severe("Could not find Node2" + descriptor==null?"null":descriptor + " mapping.");
return null;
}

// return kegg id(s)
Object id = nodeMap.get(n);
return id!=null?id.toString():null;

}

/**
* @param n
* @return kegg ids, separated by a "," for the given node.
*/
public static String getKeggIDs(Node n) {
return getNodeInfoIDs(n, "keggIds");
}

}
118 changes: 115 additions & 3 deletions src/de/zbit/kegg/ext/RestrictedEditMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
Expand All @@ -42,10 +44,12 @@
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.ToolTipManager;
import javax.swing.table.DefaultTableModel;

import org.sbml.jsbml.util.StringTools;
Expand All @@ -61,11 +65,15 @@
import y.view.Graph2DSelectionEvent;
import y.view.Graph2DSelectionListener;
import y.view.Graph2DView;
import y.view.HitInfo;
import y.view.NavigationComponent;
import y.view.Overview;
import de.zbit.gui.GUITools;
import de.zbit.gui.SystemBrowser;
import de.zbit.kegg.TranslatorTools;
import de.zbit.kegg.io.KEGG2jSBML;
import de.zbit.kegg.io.KEGG2yGraph;
import de.zbit.kegg.io.KEGGtranslator;
import de.zbit.util.EscapeChars;
import de.zbit.util.StringUtil;

Expand All @@ -90,14 +98,44 @@ public class RestrictedEditMode extends EditMode implements Graph2DSelectionList
*/
JTable propTable=null;

/**
* A panel for the {@link #propTable}.
*/
JPanel eastPanel=null;

/**
* This is used to fire openPathway events on double clicks on
* pathway reference nodes.
*/
ActionListener aListener = null;

/**
* This is the ActionCommand for actionlisteners to open a new pathway tab.
* TODO
*/
public final static String OPEN_PATHWAY = "OPEN_PATHWAY";

public RestrictedEditMode() {
super();
//setEditNodeMode(null);
setCreateEdgeMode(null);
/*
* The Tooltips of nodes, provding descriptions must be shown
* longer than the system default. Let's show them 15 seconds!
*/
ToolTipManager.sharedInstance().setDismissDelay(15000);
}

/**
* @param listener this is used to fire TODO
*/
public RestrictedEditMode(ActionListener listener) {
this();
this.aListener = listener;
}



@Override
protected Node createNode(Graph2D graph, double x, double y) {
// do nothing
Expand Down Expand Up @@ -127,10 +165,84 @@ public static void addBackgroundImage(URL imagePath, Graph2DView pane) {
/* (non-Javadoc)
* @see y.view.EditMode#getNodeTip(y.base.Node)
*/
@SuppressWarnings("unchecked")
@Override
protected String getNodeTip(Node n) {
// Show a nice ToolTipText for every node.
GenericDataMap<DataMap, String> mapDescriptionMap = (GenericDataMap<DataMap, String>) n.getGraph().getDataProvider(KEGG2yGraph.mapDescription);
if (mapDescriptionMap==null) return super.getNodeTip(n);

// Get nodeLabel, description and eventually an image for the ToolTipText
String nodeLabel = null;
String description = null;
String image = "";
NodeMap[] nm = n.getGraph().getRegisteredNodeMaps();
if (nm!=null) {
for (int i=0; i<nm.length;i++) {
Object c = nm[i].get(n);
if (c==null || c.toString().length()<1) continue;
String mapDescription = mapDescriptionMap.getV(nm[i]);
if (mapDescription.equals("nodeLabel")) {
nodeLabel = "<b>"+c.toString().replace(",", ",<br/>")+"</b><br/>";
} else if (mapDescription.equals("description")) {
description = "<i>"+c.toString().replace(",", ",<br/>")+"</i><br/>";
} else if (mapDescription.equals("keggIds")) {
for (String s: c.toString().split(",")) {
s=s.toUpperCase().trim();
if (s.startsWith("PATH:")) {
image+=KEGG2jSBML.getPathwayPreviewPicture(s);
} else if (s.startsWith("CPD:")) {
// KEGG provides picture for compounds (e.g., "C00118").
image+=KEGG2jSBML.getCompoundPreviewPicture(s);
}
}
}
}
}

// Merge the three strings to a single tooltip
StringBuffer tooltip = new StringBuffer();
if (nodeLabel!=null) {
tooltip.append(StringUtil.insertLineBreaks(nodeLabel, GUITools.TOOLTIP_LINE_LENGTH, "<br/>"));
}
if (description!=null) {
tooltip.append(StringUtil.insertLineBreaks(description, GUITools.TOOLTIP_LINE_LENGTH, "<br/>"));
}
if (image!=null && image.length()>0) {
tooltip.append("<div align=\"center\">"+image+"</div>");
}

// Append html and return toString.
return "<html><body>"+tooltip.toString()+"</body></html>";
}

/* (non-Javadoc)
* @see y.view.EditMode#mouseClicked(double, double)
*/
@Override
protected String getNodeTip(Node arg0) {
// TODO Auto-generated method stub
return super.getNodeTip(arg0);
public void mouseClicked(double x, double y) {
MouseEvent ev = lastClickEvent;
if (ev.getClickCount() == 2 && aListener!=null) {
// Get double clicked node
HitInfo allHitObjects = getGraph2D().getHitInfo(x, y, false);
Node n = allHitObjects.getHitNode();

// Ask user if he wants to open the pathway and fire an event.
String kgId = TranslatorTools.getKeggIDs(n);
if (kgId.toLowerCase().startsWith("path:")) {
int ret = GUITools.showQuestionMessage(null, "Do you want to download and open the referenced pathway in a new tab?",
KEGGtranslator.APPLICATION_NAME, new String[]{"Yes", "No"});
if (ret==0) {
ActionEvent e = new ActionEvent(kgId.trim().substring(5).toLowerCase(), JOptionPane.OK_OPTION, OPEN_PATHWAY);
aListener.actionPerformed(e);
}
}


} else {
// let EditMode handle the click event
super.mouseClicked(x,y);
}
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/de/zbit/kegg/gui/TranslatorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ public TranslatorPanel(final File inputFile, final Format outputFormat, ActionLi

/**
* Initiates a download and translation of the given pathway.
* @param organism Organism kegg abbreviation (e.g., "mmu")
* @param pathwayID pathway identifier (e.g., "mmu00010")
* @param outputFormat
* @param translationResult
*/
public TranslatorPanel(final String organism, final String pathwayID,
public TranslatorPanel(final String pathwayID,
final Format outputFormat, ActionListener translationResult) {
super();
setLayout(new BorderLayout());
Expand All @@ -155,11 +154,11 @@ public TranslatorPanel(final String organism, final String pathwayID,
this.translationListener = translationResult;

// Execute download and translation in new thread
showTemporaryLoadingPanel(pathwayID, organism);
showTemporaryLoadingPanel(pathwayID, null);
final SwingWorker<String, Void> downloadWorker = new SwingWorker<String, Void>() {
@Override
protected String doInBackground() throws Exception {
return KGMLSelectAndDownload.downloadPathway(organism, pathwayID, false);
return KGMLSelectAndDownload.downloadPathway(pathwayID, false);
}
protected void done() {
String localFile=null;
Expand Down Expand Up @@ -256,7 +255,7 @@ private void showTemporaryLoadingPanel(String pwName, String organism) {
removeAll();
setLayout(new BorderLayout()); // LayoutHelper creates a GridBaglayout, reset it to default.
final AbstractProgressBar pb = generateLoadingPanel(this, "Downloading '" + pwName + "' " +
"for '"+organism+"'...");
(organism!=null&&organism.length()>0? "for '"+organism+"'...":""));
FileDownload.ProgressBar = pb;
repaint();
}
Expand Down Expand Up @@ -345,7 +344,7 @@ protected void done() {
pane.setSize(getSize());
//ViewMode mode = new NavigationMode();
//pane.addViewMode(mode);
EditMode editMode = new RestrictedEditMode();
EditMode editMode = new RestrictedEditMode(translationListener);
editMode.showNodeTips(true);
pane.addViewMode(editMode);

Expand Down
15 changes: 15 additions & 0 deletions src/de/zbit/kegg/gui/TranslatorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import de.zbit.gui.prefs.FileSelector;
import de.zbit.gui.prefs.PreferencesPanel;
import de.zbit.kegg.Translator;
import de.zbit.kegg.ext.RestrictedEditMode;
import de.zbit.kegg.io.KEGGtranslator;
import de.zbit.kegg.io.KEGGtranslatorIOOptions;
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
Expand Down Expand Up @@ -101,6 +102,12 @@ public static enum Action implements ActionCommand {
* {@link Action} for downloading KGMLs.
*/
DOWNLOAD_KGML,
/**
* This is coming from {@link RestrictedEditMode#OPEN_PATHWAY} and must be
* renamed accordingly. The source is a kegg pathway id that should be opened
* as new tab, when this action is fired.
*/
OPEN_PATHWAY,
/**
* Invisible {@link Action} that should be performed, whenever an
* translation is done.
Expand Down Expand Up @@ -386,6 +393,14 @@ public void actionPerformed(ActionEvent e) {
case NEW_PROGRESSBAR:
getStatusBar().showProgress((AbstractProgressBar)e.getSource());
break;
case OPEN_PATHWAY:
try {
tabbedPane.addTab(e.getSource().toString(), new TranslatorPanel(e.getSource().toString(),Format.GraphML,this));
tabbedPane.setSelectedIndex(tabbedPane.getTabCount()-1);
} catch (Exception e1) {
GUITools.showErrorMessage(this, e1);
}
break;
default:
System.out.println(action);
break;
Expand Down
35 changes: 31 additions & 4 deletions src/de/zbit/kegg/io/KEGG2jSBML.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@

import org.sbml.jsbml.Annotation;
import org.sbml.jsbml.CVTerm;
import org.sbml.jsbml.CVTerm.Qualifier;
import org.sbml.jsbml.CVTerm.Type;
import org.sbml.jsbml.Compartment;
import org.sbml.jsbml.Creator;
import org.sbml.jsbml.History;
import org.sbml.jsbml.JSBML;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ModifierSpeciesReference;
import org.sbml.jsbml.SBMLDocument;
Expand All @@ -42,8 +43,6 @@
import org.sbml.jsbml.SBaseChangedListener;
import org.sbml.jsbml.Species;
import org.sbml.jsbml.SpeciesReference;
import org.sbml.jsbml.CVTerm.Qualifier;
import org.sbml.jsbml.CVTerm.Type;
import org.sbml.jsbml.xml.stax.SBMLWriter;

import de.zbit.kegg.KEGGtranslatorOptions;
Expand Down Expand Up @@ -702,8 +701,18 @@ private void addMiriamURNs(Entry entry, Species spec) {
notes.append(String.format("<p><b>All given names:</b><br/>%s</p>\n",EscapeChars.forHTML(infos.getNames().replace(";", ""))));
if (infos.getCas() != null)
notes.append(String.format("<p><b>CAS number:</b> %s</p>\n", infos.getCas()));
if (infos.getFormula() != null)
if (infos.getFormula() != null) {
notes.append(String.format("<p><b>Formula:</b> %s</p>\n", EscapeChars.forHTML(infos.getFormula())));
String ko_id_uc_t = ko_id.toUpperCase().trim();
if (ko_id_uc_t.startsWith("CPD:")) {
// KEGG provides picture for compounds (e.g., "C00118").
notes.append(getCompoundPreviewPicture(ko_id_uc_t));
}
}
if (entry.getType().equals(EntryType.map)) {
// KEGG provides picture for referenced pathways (e.g., "path:hsa00620" => "map00620.gif").
notes.append(getPathwayPreviewPicture(ko_id));
}
if (infos.getMass() != null)
notes.append(String.format("<p><b>Mass:</b> %s</p>\n", infos.getMass()));
notes.append(notesEndString);
Expand Down Expand Up @@ -767,6 +776,24 @@ private void addMiriamURNs(Entry entry, Species spec) {
}


/**
* @param ko_id starting with "cpd:"
* @return an html image tag, containing a preview picture for the given compound.
*/
public static String getCompoundPreviewPicture(String ko_id) {
return String.format("<img src=\"http://www.kegg.jp/Fig/compound/%s.gif\"/><br/>\n", ko_id.trim().substring(4).toUpperCase() );
}

/**
* @param ko_id starting with "path:"
* @return an html image tag, containing a preview picture for the given referenced pathway.
*/
public static String getPathwayPreviewPicture(String ko_id) {
// KEGG provides picture for referenced pathways (e.g., "path:hsa00620" => "map00620.gif").
String mapNumber = Utils.getNumberFromStringRevAsString(ko_id.length(), ko_id);
return String.format("<img src=\"http://www.kegg.jp/kegg/misc/thumbnail/map%s.gif\"/><br/>\n", mapNumber );
}

/**
* Translates the given entry to jSBML.
*
Expand Down
Loading

0 comments on commit a954aa6

Please sign in to comment.