Author: clopes
Date: 2011-08-30 13:50:25 -0700 (Tue, 30 Aug 2011)
New Revision: 26657
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
Log:
Ported over the export feature.
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
2011-08-30 20:41:01 UTC (rev 26656)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
2011-08-30 20:50:25 UTC (rev 26657)
@@ -43,10 +43,13 @@
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTableEntry;
import org.cytoscape.model.subnetwork.CyRootNetwork;
import org.cytoscape.model.subnetwork.CyRootNetworkFactory;
import org.cytoscape.model.subnetwork.CySubNetwork;
+import org.cytoscape.util.swing.FileChooserFilter;
+import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.CyNetworkViewManager;
@@ -120,6 +123,7 @@
private final CyEventHelper eventHelper;
private final VisualMappingFunctionFactory discreteMappingFactory;
private final VisualMappingFunctionFactory continuousMappingFactory;
+ private final FileUtil fileUtil;
private boolean interrupted;
private Image placeHolderImage;
@@ -144,7 +148,8 @@
final CySwingApplication
swingApplication,
final CyEventHelper eventHelper,
final VisualMappingFunctionFactory
discreteMappingFactory,
- final VisualMappingFunctionFactory
continuousMappingFactory) {
+ final VisualMappingFunctionFactory
continuousMappingFactory,
+ final FileUtil fileUtil) {
this.renderingEngineFactory = renderingEngineFactory;
this.networkViewFactory = networkViewFactory;
this.rootNetworkFactory = rootNetworkFactory;
@@ -157,6 +162,7 @@
this.eventHelper = eventHelper;
this.discreteMappingFactory = discreteMappingFactory;
this.continuousMappingFactory = continuousMappingFactory;
+ this.fileUtil = fileUtil;
this.reset();
}
@@ -469,10 +475,9 @@
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_HEIGHT, 40.0);
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_PAINT, Color.RED);
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_FILL_COLOR, Color.RED);
-
clusterStyle.setDefaultValue(RichVisualLexicon.NODE_BORDER_PAINT, Color.BLACK);
-
clusterStyle.setDefaultValue(RichVisualLexicon.NODE_BORDER_WIDTH, 5.0);
+
clusterStyle.setDefaultValue(RichVisualLexicon.NODE_BORDER_WIDTH, 0.0);
-
clusterStyle.setDefaultValue(MinimalVisualLexicon.EDGE_WIDTH, 2.0);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.EDGE_WIDTH, 5.0);
clusterStyle.setDefaultValue(MinimalVisualLexicon.EDGE_PAINT, Color.BLUE);
clusterStyle.setDefaultValue(RichVisualLexicon.EDGE_UNSELECTED_PAINT,
Color.BLUE);
clusterStyle.setDefaultValue(RichVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT,
Color.BLUE);
@@ -648,7 +653,14 @@
StringBuffer sb = new StringBuffer();
for (CyNode node : network.getNodeList()) {
- sb.append(node.getSUID());
+ CyRow row = node.getCyRow();
+ String id = "" + node.getSUID();
+
+ if (row.isSet(CyNetwork.NAME)) {
+ id = row.get(CyNetwork.NAME, String.class);
+ }
+
+ sb.append(id);
sb.append(", ");
}
@@ -666,46 +678,65 @@
* @param fileName The file name to write to
* @return True if the file was written, false otherwise
*/
- public boolean exportMCODEResults(MCODEAlgorithm alg, MCODECluster[]
clusters, CyNetwork network, String fileName) {
- if (alg == null || clusters == null || network == null ||
fileName == null) {
+ public boolean exportMCODEResults(MCODEAlgorithm alg, MCODECluster[]
clusters, CyNetwork network) {
+ if (alg == null || clusters == null || network == null) {
return false;
}
- String lineSep = System.getProperty("line.separator");
+ final String lineSep = System.getProperty("line.separator");
+ String fileName = null;
+ FileWriter fout = null;
try {
- File file = new File(fileName);
- FileWriter fout = new FileWriter(file);
- //write header
- fout.write("MCODE Plugin Results" + lineSep);
- fout.write("Date: " +
DateFormat.getDateTimeInstance().format(new Date()) + lineSep + lineSep);
- fout.write("Parameters:" + lineSep +
alg.getParams().toString() + lineSep);
- fout.write("Cluster Score
(Density*#Nodes)\tNodes\tEdges\tNode IDs" + lineSep);
+ // Call save method in MCODE get the file name
+ Collection<FileChooserFilter> filters = new
ArrayList<FileChooserFilter>();
+ filters.add(new FileChooserFilter("BioPAX format",
"rdf"));
+ File file =
fileUtil.getFile(swingApplication.getJFrame(),
+
"Export Graph as Interactions",
+
FileUtil.SAVE,
+
filters);
- // get sub-networks for all clusters, score and rank
them
- // convert the ArrayList to an array of
GraphPerspectives and sort it by cluster score
- for (int i = 0; i < clusters.length; i++) {
- CyNetwork clusterNetwork =
clusters[i].getNetwork();
- fout.write((i + 1) + "\t"); //rank
- NumberFormat nf = NumberFormat.getInstance();
- nf.setMaximumFractionDigits(3);
-
fout.write(nf.format(clusters[i].getClusterScore()) + "\t");
- // cluster size - format: (# prot, # intx)
- fout.write(clusterNetwork.getNodeCount() +
"\t");
- fout.write(clusterNetwork.getEdgeCount() +
"\t");
- // create a string of node names - this can be
long
- fout.write(getNodeNameList(clusterNetwork) +
lineSep);
- }
+ if (file != null) {
+ fileName = file.getAbsolutePath();
+ fout = new FileWriter(file);
- fout.close();
+ // Write header
+ fout.write("MCODE Plugin Results" + lineSep);
+ fout.write("Date: " +
DateFormat.getDateTimeInstance().format(new Date()) + lineSep + lineSep);
+ fout.write("Parameters:" + lineSep +
alg.getParams().toString() + lineSep);
+ fout.write("Cluster Score
(Density*#Nodes)\tNodes\tEdges\tNode IDs" + lineSep);
- return true;
+ // Get sub-networks for all clusters, score and
rank them
+ // convert the ArrayList to an array of
GraphPerspectives and sort it by cluster score
+ for (int i = 0; i < clusters.length; i++) {
+ CyNetwork clusterNetwork =
clusters[i].getNetwork();
+ fout.write((i + 1) + "\t"); //rank
+ NumberFormat nf =
NumberFormat.getInstance();
+ nf.setMaximumFractionDigits(3);
+
fout.write(nf.format(clusters[i].getClusterScore()) + "\t");
+ // cluster size - format: (# prot, #
intx)
+
fout.write(clusterNetwork.getNodeCount() + "\t");
+
fout.write(clusterNetwork.getEdgeCount() + "\t");
+ // create a string of node names - this
can be long
+
fout.write(getNodeNameList(clusterNetwork) + lineSep);
+ }
+ return true;
+ }
} catch (IOException e) {
JOptionPane.showMessageDialog(null,
e.toString(),
"Error Writing to \"" + fileName + "\"",
JOptionPane.ERROR_MESSAGE);
- return false;
+ } finally {
+ if (fout != null) {
+ try {
+ fout.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
+
+ return false;
}
}
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
2011-08-30 20:41:01 UTC (rev 26656)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
2011-08-30 20:50:25 UTC (rev 26657)
@@ -60,7 +60,6 @@
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyRow;
-import org.cytoscape.util.swing.FileChooserFilter;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
@@ -129,7 +128,7 @@
// Graphical classes
private MCODELoader loader;
- private final MCODEUtil mcodeutil;
+ private final MCODEUtil mcodeUtil;
private final CySwingApplication swingApplication;
private final MCODEDiscardResultAction discardResultAction;
@@ -145,7 +144,7 @@
*/
public MCODEResultsPanel(MCODECluster[] clusters,
MCODEAlgorithm alg,
- MCODEUtil mcodeutil,
+ MCODEUtil mcodeUtil,
CyNetwork network,
CyNetworkView
networkView,
Image[] imageList,
@@ -155,7 +154,7 @@
setLayout(new BorderLayout());
this.alg = alg;
- this.mcodeutil = mcodeutil;
+ this.mcodeUtil = mcodeUtil;
this.resultId = resultId;
this.clusters = clusters;
this.network = network;
@@ -164,7 +163,7 @@
this.swingApplication = swingApplication;
this.discardResultAction = discardResultAction;
- currentParamsCopy =
mcodeutil.getCurrentParameters().getResultParams(resultId);
+ currentParamsCopy =
mcodeUtil.getCurrentParameters().getResultParams(resultId);
JPanel clusterBrowserPanel =
createClusterBrowserPanel(imageList);
JPanel bottomPanel = createBottomPanel();
@@ -300,6 +299,7 @@
* @return panel A JPanel with the contents of the explore panel, get's
* added to the explore collapsable panel's content pane
*/
+ @SuppressWarnings("unchecked")
private JPanel createExploreContent(int selectedRow) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
@@ -373,10 +373,8 @@
enumerationsTable.setDefaultRenderer(StringBuffer.class, new
MCODEResultsPanel.JTextAreaRenderer(0));
enumerationsTable.setFocusable(false);
- // Create a combo box that lists all the available node
attributes for
- // enumeration
- nodeAttributesComboBox.addActionListener(new
MCODEResultsPanel.enumerateAction(enumerationsTable,
-
modelEnumerator, selectedRow));
+ // Create a combo box that lists all the available node
attributes for enumeration
+ nodeAttributesComboBox.addActionListener(new
MCODEResultsPanel.enumerateAction(modelEnumerator, selectedRow));
nodeAttributesPanel.add(nodeAttributesComboBox,
BorderLayout.NORTH);
nodeAttributesPanel.add(tableScrollPane, BorderLayout.SOUTH);
@@ -481,16 +479,16 @@
@Override
protected CyNetworkView doInBackground() throws
Exception {
- CyNetwork newNetwork =
mcodeutil.createSubNetwork(clusterNetwork, clusterNetwork.getNodeList());
+ CyNetwork newNetwork =
mcodeUtil.createSubNetwork(clusterNetwork, clusterNetwork.getNodeList());
newNetwork.getCyRow().set(CyNetwork.NAME, title);
- VisualStyle vs =
mcodeutil.getNetworkViewStyle(networkView);
- CyNetworkView newNetworkView =
mcodeutil.createNetworkView(newNetwork, vs);
+ VisualStyle vs =
mcodeUtil.getNetworkViewStyle(networkView);
+ CyNetworkView newNetworkView =
mcodeUtil.createNetworkView(newNetwork, vs);
newNetworkView.setVisualProperty(MinimalVisualLexicon.NETWORK_CENTER_X_LOCATION,
0.0);
newNetworkView.setVisualProperty(MinimalVisualLexicon.NETWORK_CENTER_Y_LOCATION,
0.0);
-
mcodeutil.displayNetworkView(newNetworkView);
+
mcodeUtil.displayNetworkView(newNetworkView);
// Layout new cluster and fit it to
window.
// Randomize node positions before
layout so that they don't all layout in a line
@@ -633,6 +631,7 @@
listIt(enumerations);
}
+ @SuppressWarnings("unchecked")
public void listIt(HashMap<?, ?> enumerations) {
// First we sort the hash map of attributes values and
their occurrences
ArrayList<?> enumerationsSorted = sortMap(enumerations);
@@ -700,6 +699,7 @@
* Has values mapped to keys
* @return outputList of Map.Entries
*/
+ @SuppressWarnings("unchecked")
private ArrayList sortMap(Map map) {
ArrayList outputList = null;
int count = 0;
@@ -717,10 +717,7 @@
// Sort the entries with own comparator for the values:
Arrays.sort(entries, new Comparator<Map.Entry>() {
- public int compareTo(Map.Entry o1, Map.Entry o2) {
- return ((Comparable)
o1.getValue()).compareTo((Comparable) o2.getValue());
- }
-
+ @Override
public int compare(Map.Entry o1, Map.Entry o2) {
return ((Comparable)
o1.getValue()).compareTo((Comparable) o2.getValue());
}
@@ -741,15 +738,11 @@
*/
private class enumerateAction extends AbstractAction {
- JTable enumerationsTable;
int selectedRow;
MCODEResultsPanel.MCODEResultsEnumeratorTableModel
modelEnumerator;
- enumerateAction(JTable enumerationsTable,
-
MCODEResultsPanel.MCODEResultsEnumeratorTableModel modelEnumerator,
- int selectedRow) {
+
enumerateAction(MCODEResultsPanel.MCODEResultsEnumeratorTableModel
modelEnumerator, int selectedRow) {
this.selectedRow = selectedRow;
- this.enumerationsTable = enumerationsTable;
this.modelEnumerator = modelEnumerator;
}
@@ -817,19 +810,7 @@
private class ExportAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
- // Call save method in MCODE get the file name
- Collection<FileChooserFilter> filters = new
ArrayList<FileChooserFilter>();
- filters.add(new FileChooserFilter("BioPAX format",
"rdf"));
- // TODO
- // File file =
FileUtil.getFile((Component) e.getSource(),
- //
"Export Graph as Interactions",
- //
FileUtil.SAVE,
- //
filters);
- //
- // if (file != null) {
- // String fileName =
file.getAbsolutePath();
- //
mcodeutil.exportMCODEResults(alg, clusters, network, fileName);
- // }
+ mcodeUtil.exportMCODEResults(alg, clusters, network);
}
}
@@ -914,8 +895,8 @@
// Only do this if a view has been created on this
network
if (networkView != null) {
// start with no selected nodes
- //
mcodeutil.setSelected(network.getNodeList(), false, networkView);
-
mcodeutil.setSelected(custerNetwork.getNodeList(), network, networkView);
+ //
mcodeUtil.setSelected(network.getNodeList(), false, networkView);
+
mcodeUtil.setSelected(custerNetwork.getNodeList(), network, networkView);
// TODO: is it still necessary?
// We want the focus to switch to the
appropriate network view but only if the cytopanel is docked
@@ -933,7 +914,7 @@
JOptionPane.INFORMATION_MESSAGE);
}
} else {
- mcodeutil.setSelected(new ArrayList<CyNode>(), network,
networkView); // deselect all
+ mcodeUtil.setSelected(new ArrayList<CyNode>(), network,
networkView); // deselect all
}
}
@@ -1156,7 +1137,7 @@
// process was interrupted by the
slider movement
// In that case the drawing must occur
for a new cluster using the drawGraph method
if (drawGraph && !drawPlaceHolder) {
- Image image =
mcodeutil.createClusterImage(cluster,
+ Image image =
mcodeUtil.createClusterImage(cluster,
graphPicSize,
graphPicSize,
layouter,
@@ -1185,7 +1166,7 @@
placeHolderDrawn = false;
} else if (drawPlaceHolder &&
!placeHolderDrawn) {
// draw place holder, only once
though (as per the if statement)
- Image image =
mcodeutil.getPlaceHolderImage(graphPicSize, graphPicSize);
+ Image image =
mcodeUtil.getPlaceHolderImage(graphPicSize, graphPicSize);
// Update the table
table.setValueAt(new
ImageIcon(image), cluster.getRank(), 0);
// select the cluster
@@ -1212,7 +1193,7 @@
public void interruptDrawing() {
drawGraph = false;
layouter.interruptDoLayout();
- mcodeutil.interruptLoading();
+ mcodeUtil.interruptLoading();
}
}
}
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-08-30 20:41:01 UTC (rev 26656)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-08-30 20:50:25 UTC (rev 26657)
@@ -41,6 +41,9 @@
interface="org.cytoscape.view.presentation.RenderingEngineFactory"
filter="(id=ding)" />
+ <osgi:reference id="fileUtilServiceRef"
+ interface="org.cytoscape.util.swing.FileUtil" />
+
<osgi:reference id="openBrowserServiceRef"
interface="org.cytoscape.util.swing.OpenBrowser" />
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
2011-08-30 20:41:01 UTC (rev 26656)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
2011-08-30 20:50:25 UTC (rev 26657)
@@ -70,6 +70,7 @@
<constructor-arg ref="cyEventHelperServiceRef" />
<constructor-arg ref="discreteMappingFactoryServiceRef" />
<constructor-arg ref="continuousMappingFactoryServiceRef" />
+ <constructor-arg ref="fileUtilServiceRef" />
</bean>
<!-- Other beans -->
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.