Skip to content

Commit f784248

Browse files
committed
Moved gmt file check. Fixes #110.
1 parent 61c9c58 commit f784248

File tree

7 files changed

+113
-125
lines changed

7 files changed

+113
-125
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/CyActivator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void start(BundleContext bc) {
124124
//create the Panels
125125
BulkEMCreationPanel bulkEmPanel = new BulkEMCreationPanel(cySwingApplicationRef,fileUtil,registrar, sessionManager, streamUtil, cyApplicationManagerRef);
126126
EnrichmentMapInputPanel emPanel = new EnrichmentMapInputPanel(cyNetworkFactoryRef, cyApplicationManagerRef, cyNetworkManagerRef, cyNetworkViewManagerRef, tableFactory, tableManager, cyNetworkViewFactoryRef, visualMappingManagerRef, visualStyleFactoryRef, continuousMappingFunctionFactoryRef,discreteMappingFunctionFactoryRef, passthroughMappingFunctionFactoryRef, dialogTaskManager, sessionManager, cySwingApplicationRef, openBrowserRef,fileUtil,streamUtil,registrar,layoutManager,mapTableToNetworkTable,bulkEmPanel);
127-
PostAnalysisPanel postEMPanel = new PostAnalysisPanel(cyApplicationManagerRef,cySwingApplicationRef, openBrowserRef,fileUtil,sessionManager, streamUtil,registrar, dialogTaskManager,eventHelper, compilerServiceRef, visualMappingManagerRef, visualStyleFactoryRef, continuousMappingFunctionFactoryRef, discreteMappingFunctionFactoryRef, passthroughMappingFunctionFactoryRef);
127+
PostAnalysisPanel postEMPanel = new PostAnalysisPanel(cyApplicationManagerRef,cySwingApplicationRef, openBrowserRef,fileUtil,sessionManager, streamUtil,registrar, dialogTaskManager, syncTaskManager, eventHelper, compilerServiceRef, visualMappingManagerRef, visualStyleFactoryRef, continuousMappingFunctionFactoryRef, discreteMappingFunctionFactoryRef, passthroughMappingFunctionFactoryRef);
128128
//create two instances of the heatmap panel
129129
HeatMapPanel heatMapPanel_node = new HeatMapPanel(true, cySwingApplicationRef, fileUtil, cyApplicationManagerRef, openBrowserRef,dialogTaskManager,streamUtil);
130130
HeatMapPanel heatMapPanel_edge = new HeatMapPanel(false, cySwingApplicationRef, fileUtil, cyApplicationManagerRef, openBrowserRef,dialogTaskManager,streamUtil);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/PostAnalysisParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public FilterParameters getRankTestParameters() {
169169
*/
170170
public String checkGMTfiles() {
171171
String signatureGMTFileName = getSignatureGMTFileName();
172-
if(signatureGMTFileName.isEmpty() || !EnrichmentMapParameters.checkFile(signatureGMTFileName))
172+
if(signatureGMTFileName == null || signatureGMTFileName.isEmpty() || !EnrichmentMapParameters.checkFile(signatureGMTFileName))
173173
return "Signature GMT file can not be found \n";
174174
return "";
175175
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/actions/BuildPostAnalysisActionListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public BuildPostAnalysisActionListener (PostAnalysisInputPanel panel,
117117
}
118118

119119
public void actionPerformed(ActionEvent event) {
120-
120+
runPostAnalysis();
121+
}
122+
123+
public void runPostAnalysis() {
121124
//make sure that the minimum information is set in the current set of parameters
122125
PostAnalysisParameters paParams = inputPanel.getPaParams();
123126

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/PostAnalysisInputPanel.java

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
8888
import org.cytoscape.view.vizmap.VisualMappingManager;
8989
import org.cytoscape.view.vizmap.VisualStyleFactory;
90+
import org.cytoscape.work.SynchronousTaskManager;
9091
import org.cytoscape.work.swing.DialogTaskManager;
9192

9293

@@ -105,7 +106,8 @@ public class PostAnalysisInputPanel extends JPanel {
105106
private final CyServiceRegistrar registrar;
106107
private final CySessionManager sessionManager;
107108
private final StreamUtil streamUtil;
108-
private final DialogTaskManager dialog;
109+
private final DialogTaskManager dialogTaskManager;
110+
private final SynchronousTaskManager syncTaskManager;
109111
private final CyEventHelper eventHelper;
110112
private final EquationCompiler equationCompiler;
111113

@@ -133,7 +135,7 @@ public class PostAnalysisInputPanel extends JPanel {
133135
public PostAnalysisInputPanel(CyApplicationManager cyApplicationManager, CySwingApplication application,
134136
OpenBrowser browser,FileUtil fileUtil, CySessionManager sessionManager,
135137
StreamUtil streamUtil,CyServiceRegistrar registrar,
136-
DialogTaskManager dialog,CyEventHelper eventHelper, EquationCompiler equationCompiler,
138+
DialogTaskManager dialog, SynchronousTaskManager syncTaskManager, CyEventHelper eventHelper, EquationCompiler equationCompiler,
137139
VisualMappingManager visualMappingManager, VisualStyleFactory visualStyleFactory,
138140
VisualMappingFunctionFactory vmfFactoryContinuous, VisualMappingFunctionFactory vmfFactoryDiscrete, VisualMappingFunctionFactory vmfFactoryPassthrough) {
139141

@@ -144,7 +146,8 @@ public PostAnalysisInputPanel(CyApplicationManager cyApplicationManager, CySwing
144146
this.registrar = registrar;
145147
this.sessionManager = sessionManager;
146148
this.streamUtil = streamUtil;
147-
this.dialog = dialog;
149+
this.dialogTaskManager = dialog;
150+
this.syncTaskManager = syncTaskManager;
148151
this.eventHelper = eventHelper;
149152
this.equationCompiler = equationCompiler;
150153
this.visualMappingManager = visualMappingManager;
@@ -155,7 +158,7 @@ public PostAnalysisInputPanel(CyApplicationManager cyApplicationManager, CySwing
155158

156159

157160
// Create the two main panels, set the default one
158-
knownSignaturePanel = new PostAnalysisKnownSignaturePanel(this, cyApplicationManager, application, streamUtil, dialog, fileUtil);
161+
knownSignaturePanel = new PostAnalysisKnownSignaturePanel(this, cyApplicationManager, application, streamUtil, syncTaskManager);
159162
signatureDiscoveryPanel = new PostAnalysisSignatureDiscoveryPanel(this, cyApplicationManager, application, streamUtil, dialog, fileUtil);
160163

161164
userInputPanel = new JPanel(new BorderLayout());
@@ -176,7 +179,7 @@ public PostAnalysisInputPanel(CyApplicationManager cyApplicationManager, CySwing
176179
}
177180

178181

179-
private void flipPanels(JPanel toRemove, JPanel toAdd){
182+
private void flipPanels(JPanel toRemove, JPanel toAdd) {
180183
userInputPanel.remove(toRemove);
181184
userInputPanel.add(toAdd, BorderLayout.CENTER);
182185
userInputPanel.revalidate();
@@ -304,9 +307,19 @@ public void actionPerformed(ActionEvent evt) {
304307

305308
JButton importButton = new JButton();
306309
importButton.setText("Run");
307-
importButton.addActionListener(new BuildPostAnalysisActionListener(this, sessionManager, streamUtil, application, cyApplicationManager,
308-
dialog, eventHelper, equationCompiler, visualMappingManager, visualStyleFactory,
309-
vmfFactoryContinuous, vmfFactoryDiscrete, vmfFactoryPassthrough));
310+
importButton.addActionListener(new ActionListener() {
311+
public void actionPerformed(ActionEvent e) {
312+
boolean okToRun = beforeRun();
313+
if(okToRun) {
314+
BuildPostAnalysisActionListener action = new BuildPostAnalysisActionListener(PostAnalysisInputPanel.this, sessionManager, streamUtil, application, cyApplicationManager,
315+
dialogTaskManager, eventHelper, equationCompiler, visualMappingManager, visualStyleFactory, vmfFactoryContinuous, vmfFactoryDiscrete, vmfFactoryPassthrough);
316+
action.runPostAnalysis();
317+
}
318+
}
319+
});
320+
321+
322+
310323
importButton.setEnabled(true);
311324

312325
panel.add(resetButton);
@@ -323,14 +336,13 @@ protected File chooseGMTFile(JFormattedTextField textField) {
323336

324337
// Get the file name
325338
File file = fileUtil.getFile(SwingUtil.getWindowInstance(this), "Import Signature GMT File", FileUtil.LOAD, all_filters);
326-
getPaParams().setSignatureGMTFileName("");
327339

328340
if(file != null) {
329-
textField.setForeground(PostAnalysisInputPanel.checkFile(file.getAbsolutePath()));
330-
textField.setText(file.getAbsolutePath());
331-
textField.setValue(file.getAbsolutePath());
332-
getPaParams().setSignatureGMTFileName(file.getAbsolutePath());
333-
textField.setToolTipText(file.getAbsolutePath());
341+
String absolutePath = file.getAbsolutePath();
342+
textField.setForeground(PostAnalysisInputPanel.checkFile(absolutePath));
343+
textField.setText(absolutePath);
344+
textField.setValue(absolutePath);
345+
textField.setToolTipText(absolutePath);
334346
textField.setCaretPosition(textField.getText().length());
335347
}
336348

@@ -450,4 +462,11 @@ public void setAvSigCount(int avSigCount) {
450462
}
451463
}
452464

465+
public boolean beforeRun() {
466+
if(knownSignature.isSelected())
467+
return knownSignaturePanel.beforeRun();
468+
else
469+
return true;
470+
}
471+
453472
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/PostAnalysisKnownSignaturePanel.java

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import java.awt.BorderLayout;
44
import java.awt.Color;
5+
import java.awt.Font;
56
import java.awt.Insets;
67
import java.awt.event.ActionEvent;
78
import java.awt.event.ActionListener;
89
import java.beans.PropertyChangeEvent;
910
import java.beans.PropertyChangeListener;
10-
import java.io.File;
1111

1212
import javax.swing.BoxLayout;
1313
import javax.swing.JButton;
@@ -25,8 +25,7 @@
2525
import org.cytoscape.application.CyApplicationManager;
2626
import org.cytoscape.application.swing.CySwingApplication;
2727
import org.cytoscape.io.util.StreamUtil;
28-
import org.cytoscape.util.swing.FileUtil;
29-
import org.cytoscape.work.swing.DialogTaskManager;
28+
import org.cytoscape.work.SynchronousTaskManager;
3029

3130
@SuppressWarnings("serial")
3231
public class PostAnalysisKnownSignaturePanel extends JPanel {
@@ -36,8 +35,7 @@ public class PostAnalysisKnownSignaturePanel extends JPanel {
3635
private final CyApplicationManager cyApplicationManager;
3736
private final CySwingApplication application;
3837
private final StreamUtil streamUtil;
39-
private final DialogTaskManager dialog;
40-
private final FileUtil fileUtil;
38+
private final SynchronousTaskManager syncTaskManager;
4139

4240
// 'Known Signature Panel' parameters
4341
private EnrichmentMap map;
@@ -46,21 +44,20 @@ public class PostAnalysisKnownSignaturePanel extends JPanel {
4644
private PostAnalysisWeightPanel weightPanel;
4745

4846
private JFormattedTextField knownSignatureGMTFileNameTextField;
47+
4948

5049
public PostAnalysisKnownSignaturePanel(
5150
PostAnalysisInputPanel parentPanel,
5251
CyApplicationManager cyApplicationManager,
5352
CySwingApplication application,
5453
StreamUtil streamUtil,
55-
DialogTaskManager dialog,
56-
FileUtil fileUtil) {
54+
SynchronousTaskManager syncTaskManager) {
5755

5856
this.parentPanel = parentPanel;
5957
this.cyApplicationManager = cyApplicationManager;
6058
this.application = application;
6159
this.streamUtil = streamUtil;
62-
this.dialog = dialog;
63-
this.fileUtil = fileUtil;
60+
this.syncTaskManager = syncTaskManager;
6461

6562
createKnownSignatureOptionsPanel();
6663
}
@@ -103,20 +100,23 @@ public JToolTip createToolTip() {
103100
JButton selectSigGMTFileButton = new JButton();
104101
knownSignatureGMTFileNameTextField = new JFormattedTextField() ;
105102
knownSignatureGMTFileNameTextField.setColumns(15);
103+
final Color textFieldForeground = knownSignatureGMTFileNameTextField.getForeground();
106104

107-
108-
//components needed for the directory load
109-
knownSignatureGMTFileNameTextField.setFont(new java.awt.Font("Dialog",1,10));
110-
//GMTFileNameTextField.setText(gmt_instruction);
111-
knownSignatureGMTFileNameTextField.addPropertyChangeListener("value",new FormattedTextFieldAction());
105+
knownSignatureGMTFileNameTextField.setFont(new Font("Dialog",1,10));
106+
knownSignatureGMTFileNameTextField.addPropertyChangeListener("value", new PropertyChangeListener() {
107+
public void propertyChange(PropertyChangeEvent e) {
108+
// if the text is red set it back to black as soon as the user starts typing
109+
knownSignatureGMTFileNameTextField.setForeground(textFieldForeground);
110+
}
111+
});
112112

113113

114114
selectSigGMTFileButton.setText("...");
115115
selectSigGMTFileButton.setMargin(new Insets(0,0,0,0));
116116
selectSigGMTFileButton.setActionCommand("Known Signature");
117117
selectSigGMTFileButton.addActionListener(new ActionListener() {
118118
public void actionPerformed(ActionEvent evt) {
119-
selectSignatureGMTFileButtonActionPerformed(evt);
119+
parentPanel.chooseGMTFile(knownSignatureGMTFileNameTextField);
120120
}
121121
});
122122

@@ -136,56 +136,29 @@ public void actionPerformed(ActionEvent evt) {
136136
}
137137

138138

139-
/**
140-
* Event Handler for selectSignatureGMTFileButton.<p>
141-
* Opens a file browser dialog to select the SignatureGMTFile.
142-
*/
143-
private void selectSignatureGMTFileButtonActionPerformed(ActionEvent evt) {
144-
File file = parentPanel.chooseGMTFile(knownSignatureGMTFileNameTextField);
145-
if(file != null) {
146-
//Load in the GMT file
147-
//Manually fire the same action listener that is used by the signature discovery panel
148-
LoadSignatureSetsActionListener loadAction = new LoadSignatureSetsActionListener(parentPanel, application, cyApplicationManager, dialog, streamUtil);
149-
loadAction.setSelectAll(true);
150-
loadAction.actionPerformed(evt);
139+
public boolean beforeRun() {
140+
String filePath = (String)knownSignatureGMTFileNameTextField.getValue();
141+
142+
if(filePath == null || PostAnalysisInputPanel.checkFile(filePath).equals(Color.RED)){
143+
String message = "SigGMT file name not valid.\n";
144+
knownSignatureGMTFileNameTextField.setForeground(Color.RED);
145+
JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
146+
return false;
151147
}
148+
149+
paParams.setSignatureGMTFileName(filePath);
150+
151+
// Load in the GMT file
152+
// Manually fire the same action listener that is used by the signature discovery panel.
153+
// Use the synchronousTaskManager so that this blocks
154+
LoadSignatureSetsActionListener loadAction = new LoadSignatureSetsActionListener(parentPanel, application, cyApplicationManager, syncTaskManager, streamUtil);
155+
loadAction.setSelectAll(true);
156+
loadAction.actionPerformed(null);
157+
158+
return true;
152159
}
153160

154161

155-
/**
156-
* Handles setting for the text field parameters that are numbers.
157-
* Makes sure that the numbers make sense.
158-
*/
159-
private class FormattedTextFieldAction implements PropertyChangeListener {
160-
public void propertyChange(PropertyChangeEvent e) {
161-
JFormattedTextField source = (JFormattedTextField) e.getSource();
162-
163-
String message = "The value you have entered is invalid.\n";
164-
boolean invalid = false;
165-
166-
if (source == knownSignatureGMTFileNameTextField) {
167-
String value = knownSignatureGMTFileNameTextField.getText();
168-
if(value.equalsIgnoreCase("") )
169-
paParams.setSignatureGMTFileName(value);
170-
else if(knownSignatureGMTFileNameTextField.getText().equalsIgnoreCase((String)e.getOldValue())){
171-
//do nothing
172-
}
173-
else if(PostAnalysisInputPanel.checkFile(value).equals(Color.RED)){
174-
JOptionPane.showMessageDialog(application.getJFrame(),message,"File name change entered is not a valid file name",JOptionPane.WARNING_MESSAGE);
175-
knownSignatureGMTFileNameTextField.setForeground(PostAnalysisInputPanel.checkFile(value));
176-
}
177-
else {
178-
paParams.setSignatureGMTFileName(value);
179-
paParams.getSignatureSetNames().clear();
180-
paParams.getSelectedSignatureSetNames().clear();
181-
}
182-
}
183-
if (invalid) {
184-
JOptionPane.showMessageDialog(application.getJFrame(), message, "Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
185-
}
186-
}
187-
}
188-
189162
void resetPanel() {
190163
paParams.setSignatureGenesets(new SetOfGeneSets());
191164
//Gene-Sets Panel

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/PostAnalysisPanel.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
2626
import org.cytoscape.view.vizmap.VisualMappingManager;
2727
import org.cytoscape.view.vizmap.VisualStyleFactory;
28+
import org.cytoscape.work.SynchronousTaskManager;
2829
import org.cytoscape.work.swing.DialogTaskManager;
2930

3031
/**
@@ -43,6 +44,7 @@ public class PostAnalysisPanel extends JPanel implements CytoPanelComponent {
4344
private final CySessionManager sessionManager;
4445
private final StreamUtil streamUtil;
4546
private final DialogTaskManager dialog;
47+
private final SynchronousTaskManager syncTaskManager;
4648
private final CyEventHelper eventHelper;
4749
private final EquationCompiler equationCompiler;
4850

@@ -61,7 +63,7 @@ public class PostAnalysisPanel extends JPanel implements CytoPanelComponent {
6163
public PostAnalysisPanel(CyApplicationManager cyApplicationManager, CySwingApplication application,
6264
OpenBrowser browser,FileUtil fileUtil, CySessionManager sessionManager,
6365
StreamUtil streamUtil,CyServiceRegistrar registrar,
64-
DialogTaskManager dialog,CyEventHelper eventHelper, EquationCompiler equationCompiler,
66+
DialogTaskManager dialog, SynchronousTaskManager syncTaskManager, CyEventHelper eventHelper, EquationCompiler equationCompiler,
6567
VisualMappingManager visualMappingManager, VisualStyleFactory visualStyleFactory,
6668
VisualMappingFunctionFactory vmfFactoryContinuous, VisualMappingFunctionFactory vmfFactoryDiscrete, VisualMappingFunctionFactory vmfFactoryPassthrough) {
6769

@@ -73,6 +75,7 @@ public PostAnalysisPanel(CyApplicationManager cyApplicationManager, CySwingAppli
7375
this.sessionManager = sessionManager;
7476
this.streamUtil = streamUtil;
7577
this.dialog = dialog;
78+
this.syncTaskManager = syncTaskManager;
7679
this.eventHelper = eventHelper;
7780
this.equationCompiler = equationCompiler;
7881
this.visualMappingManager = visualMappingManager;
@@ -113,7 +116,7 @@ public void removeEnrichmentMap(EnrichmentMap map) {
113116
}
114117

115118
private PostAnalysisInputPanel newPostAnalysisInputPanel() {
116-
return new PostAnalysisInputPanel(cyApplicationManager, application, browser, fileUtil, sessionManager, streamUtil, registrar, dialog,
119+
return new PostAnalysisInputPanel(cyApplicationManager, application, browser, fileUtil, sessionManager, streamUtil, registrar, dialog, syncTaskManager,
117120
eventHelper, equationCompiler, visualMappingManager, visualStyleFactory, vmfFactoryContinuous, vmfFactoryDiscrete, vmfFactoryPassthrough);
118121
}
119122

0 commit comments

Comments
 (0)