Skip to content

Commit 01c9809

Browse files
committed
Warn user when GMT file comes from EDB directory. Fixes #106.
1 parent 95a3d4a commit 01c9809

File tree

9 files changed

+150
-56
lines changed

9 files changed

+150
-56
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class PropertyManager {
2525
public static final String distanceMetric_propname = "default.distanceMetric";
2626
public static final String Pvalue_propname = "default.pvalue";
2727
public static final String Qvalue_propname = "default.qvalue";
28+
public static final String create_warn_show_propname = "create.warn.show";
2829

2930

3031
private static final double jaccardCutOff_default = 0.25;
@@ -35,14 +36,14 @@ public class PropertyManager {
3536
private static final Distance distanceMetric_default = Distance.PEARSON;
3637
private static final double Pvalue_default = 1.0;
3738
private static final double Qvalue_default = 0.1;
38-
39+
private static final boolean create_warn_show_default = true;
3940

4041
@Inject private CyProperty<Properties> cyProps;
4142

4243
@AfterInjection
4344
private void initializeProperties() {
4445
Properties props = cyProps.getProperties();
45-
if(props.size() < 9) {
46+
if(props.size() < 10) {
4647
props.setProperty(heatmap_autofocus_propname, String.valueOf(false));
4748
props.setProperty(jaccardCutOff_propname, String.valueOf(jaccardCutOff_default));
4849
props.setProperty(overlapCutOff_propname, String.valueOf(overlapCutOff_default));
@@ -52,9 +53,18 @@ private void initializeProperties() {
5253
props.setProperty(distanceMetric_propname, String.valueOf(distanceMetric_default));
5354
props.setProperty(Pvalue_propname, String.valueOf(Pvalue_default));
5455
props.setProperty(Qvalue_propname, String.valueOf(Qvalue_default));
56+
props.setProperty(create_warn_show_propname, String.valueOf(create_warn_show_default));
57+
// remember to increase the number in the if-statement above
5558
}
5659
}
5760

61+
public boolean getShowCreateWarnings() {
62+
return getValue(create_warn_show_propname, create_warn_show_default, Boolean::valueOf);
63+
}
64+
65+
public void setShowCreateWarnings(boolean show) {
66+
cyProps.getProperties().setProperty(create_warn_show_propname, String.valueOf(show));
67+
}
5868

5969
public double getJaccardCutoff() {
6070
return getValue(jaccardCutOff_propname, jaccardCutOff_default, Double::valueOf);
@@ -122,4 +132,7 @@ private <V> V getValue(String name, V defaultVal, Function<String,V> converter)
122132
}
123133
}
124134

135+
136+
137+
125138
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/DetailPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface DetailPanel {
1414

1515
String getIcon();
1616

17-
List<String> validateInput();
17+
List<Message> validateInput();
1818

1919
default DataSetParameters createDataSetParameters() { return null; };
2020

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/EditCommonPanel.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,17 @@ private void createContents() {
8585

8686

8787
@Override
88-
public List<String> validateInput() {
88+
public List<Message> validateInput() {
8989
gmtText.hideError();
9090
expressionsText.hideError();
9191

92-
List<String> err = new ArrayList<>(2);
92+
List<Message> messages = new ArrayList<>(2);
9393
if(!gmtText.emptyOrReadable())
94-
err.add(gmtText.showError("Enrichments file path is not valid."));
94+
messages.add(Message.error(gmtText.showError("Enrichments file path is not valid.")));
9595
if(!expressionsText.emptyOrReadable())
96-
err.add(expressionsText.showError("Enrichments 2 file path is not valid."));
97-
return err;
96+
messages.add(Message.error(expressionsText.showError("Enrichments 2 file path is not valid.")));
97+
98+
return messages;
9899
}
99100

100101

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/EditDataSetPanel.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,27 +292,36 @@ private void initialize(DataSetParameters initDataSet) {
292292

293293

294294
@Override
295-
public List<String> validateInput() {
296-
List<String> err = new ArrayList<>();
295+
public List<Message> validateInput() {
296+
List<Message> messages = new ArrayList<>();
297297
if(nameText.isEmpty())
298-
err.add("Name field is empty.");
298+
messages.add(Message.error("Name field is empty."));
299299
if(enrichments1Text.isEmpty())
300-
err.add("Enrichments file path is empty.");
300+
messages.add(Message.error("Enrichments file path is empty."));
301301
if(!enrichments1Text.emptyOrReadable() && getMethod() == Method.GSEA)
302-
err.add("Enrichments Pos file path is not valid.");
302+
messages.add(Message.error("Enrichments Pos file path is not valid."));
303303
if(!enrichments1Text.emptyOrReadable() && getMethod() != Method.GSEA)
304-
err.add("Enrichments file path is not valid.");
304+
messages.add(Message.error("Enrichments file path is not valid."));
305305
if(!enrichments2Text.emptyOrReadable())
306-
err.add("Enrichments Neg file path is not valid.");
306+
messages.add(Message.error("Enrichments Neg file path is not valid."));
307307
if(!expressionsText.emptyOrReadable())
308-
err.add("Expressions file path is not valid.");
308+
messages.add(Message.error("Expressions file path is not valid."));
309309
if(!gmtText.emptyOrReadable())
310-
err.add("GMT file path is not valid.");
310+
messages.add(Message.error("GMT file path is not valid."));
311311
if(!ranksText.emptyOrReadable())
312-
err.add("Ranks file path is not valid.");
312+
messages.add(Message.error("Ranks file path is not valid."));
313313
if(!classesText.emptyOrReadable())
314-
err.add("Classes file path is not valid.");
315-
return err;
314+
messages.add(Message.error("Classes file path is not valid."));
315+
316+
if(gmtText.isReadable()) {
317+
String parent = gmtText.getPath().getParent().getFileName().toString();
318+
if("edb".equalsIgnoreCase(parent)) {
319+
messages.add(Message.warn("Using GMT file from GSEA EDB directory. This GMT file has been filtered by "
320+
+ "the expressions and may effect the universe size when adding signature gene sets."));
321+
}
322+
}
323+
324+
return messages;
316325
}
317326

318327

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/ErrorMessageDialog.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import javax.swing.BorderFactory;
1212
import javax.swing.JButton;
13+
import javax.swing.JCheckBox;
1314
import javax.swing.JDialog;
1415
import javax.swing.JLabel;
1516
import javax.swing.JPanel;
@@ -29,14 +30,12 @@ public class ErrorMessageDialog extends JDialog {
2930

3031
@Inject private IconManager iconManager;
3132

32-
public static enum MessageType {
33-
WARN, ERROR
34-
}
35-
3633
private JPanel messagePanel;
3734
private int y = 0;
3835
private boolean shouldContinue = false;
3936
private JButton finishButton;
37+
private JCheckBox doNotShowCheckbox;
38+
private boolean hasErrors = false;
4039

4140
public interface Factory {
4241
ErrorMessageDialog create(JDialog parent);
@@ -47,7 +46,7 @@ public ErrorMessageDialog(@Assisted JDialog parent) {
4746
super(parent);
4847
setResizable(true);
4948
setTitle("Create Enrichment Map: Validation");
50-
setMinimumSize(new Dimension(400, 100));
49+
setMinimumSize(new Dimension(430, 100));
5150
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
5251
}
5352

@@ -68,6 +67,9 @@ private void createContents() {
6867
private JPanel createButtonPanel() {
6968
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
7069

70+
doNotShowCheckbox = new JCheckBox("Do not warn me again.");
71+
SwingUtil.makeSmall(doNotShowCheckbox);
72+
7173
JButton cancelButton = new JButton("Cancel");
7274
buttonPanel.add(cancelButton);
7375
cancelButton.addActionListener(e -> dispose());
@@ -79,7 +81,15 @@ private JPanel createButtonPanel() {
7981
dispose();
8082
});
8183

82-
return buttonPanel;
84+
JPanel panel = new JPanel(new BorderLayout());
85+
panel.add(doNotShowCheckbox, BorderLayout.WEST);
86+
panel.add(buttonPanel, BorderLayout.EAST);
87+
88+
return panel;
89+
}
90+
91+
public boolean isDontWarnAgain() {
92+
return doNotShowCheckbox.isSelected();
8393
}
8494

8595
public boolean shouldContinue() {
@@ -90,14 +100,16 @@ public boolean isEmpty() {
90100
return y == 0;
91101
}
92102

93-
public void addSection(MessageType messageType, String title, String icon, String message) {
94-
addSection(messageType, title, icon, Arrays.asList(message));
103+
public void addSection(Message message, String title, String icon) {
104+
addSection(Arrays.asList(message), title, icon);
95105
}
96106

97-
public void addSection(MessageType messageType, String title, String icon, List<String> messages) {
98-
final boolean isError = messageType == MessageType.ERROR;
99-
if(isError) {
107+
public void addSection(List<Message> messages, String title, String icon) {
108+
final boolean hasError = messages.stream().anyMatch(Message::isError);
109+
if(hasError) {
100110
finishButton.setVisible(false);
111+
doNotShowCheckbox.setVisible(false);
112+
hasErrors = true;
101113
}
102114

103115
JLabel iconLabel = new JLabel(" " + icon + " ");
@@ -109,17 +121,21 @@ public void addSection(MessageType messageType, String title, String icon, List<
109121
messagePanel.add(titleLabel, GBCFactory.grid(1,y).insets(2).gridwidth(2).weightx(1.0).get());
110122
y++;
111123

112-
for(String message : messages) {
113-
JLabel errorIcon = new JLabel(isError ? IconManager.ICON_TIMES_CIRCLE : IconManager.ICON_EXCLAMATION_TRIANGLE);
124+
for(Message message : messages) {
125+
JLabel errorIcon = new JLabel(message.isError() ? IconManager.ICON_TIMES_CIRCLE : IconManager.ICON_EXCLAMATION_TRIANGLE);
114126
errorIcon.setFont(iconManager.getIconFont(13.0f));
115-
errorIcon.setForeground(isError ? Color.RED.darker() : Color.YELLOW.darker());
127+
errorIcon.setForeground(message.isError() ? Color.RED.darker() : Color.YELLOW.darker());
116128

117-
JLabel messageLabel = new JLabel(message);
129+
JLabel messageLabel = new JLabel(message.getMessage());
118130
SwingUtil.makeSmall(messageLabel);
119131
messagePanel.add(errorIcon, GBCFactory.grid(1,y).insets(2).get());
120132
messagePanel.add(messageLabel, GBCFactory.grid(2,y).insets(2).get());
121133
y++;
122134
}
123135
}
124136

137+
public boolean hasErrors() {
138+
return hasErrors;
139+
}
140+
125141
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/MasterDetailDialogPage.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.swing.UIManager;
3535
import javax.swing.border.Border;
3636

37+
import org.baderlab.csplugins.enrichmentmap.PropertyManager;
3738
import org.baderlab.csplugins.enrichmentmap.model.DataSetFiles;
3839
import org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters;
3940
import org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters.EdgeStrategy;
@@ -44,7 +45,6 @@
4445
import org.baderlab.csplugins.enrichmentmap.resolver.DataSetParameters;
4546
import org.baderlab.csplugins.enrichmentmap.resolver.ResolverTask;
4647
import org.baderlab.csplugins.enrichmentmap.task.CreateEnrichmentMapTaskFactory;
47-
import org.baderlab.csplugins.enrichmentmap.view.creation.ErrorMessageDialog.MessageType;
4848
import org.baderlab.csplugins.enrichmentmap.view.util.CardDialogCallback;
4949
import org.baderlab.csplugins.enrichmentmap.view.util.CardDialogPage;
5050
import org.baderlab.csplugins.enrichmentmap.view.util.FileBrowser;
@@ -76,6 +76,7 @@ public class MasterDetailDialogPage implements CardDialogPage {
7676
@Inject private EditDataSetPanel.Factory dataSetPanelFactory;
7777
@Inject private CreateEnrichmentMapTaskFactory.Factory taskFactoryFactory;
7878
@Inject private ErrorMessageDialog.Factory errorMessageDialogFactory;
79+
@Inject private PropertyManager propertyManager;
7980

8081
private EditCommonPanel commonPanel;
8182
private DataSetListItem commonParams;
@@ -355,7 +356,7 @@ private boolean validateInput() {
355356
DetailPanel panel = item.getDetailPanel();
356357
if(panel instanceof EditDataSetPanel && !isNullOrEmpty(((EditDataSetPanel)panel).getExpressionFileName())) {
357358
String message = "A common expression file has been provided. Per-dataset expression files will be ignored.";
358-
dialog.addSection(MessageType.WARN, commonPanel.getDisplayName(), commonPanel.getIcon(), message);
359+
dialog.addSection(Message.warn(message), commonPanel.getDisplayName(), commonPanel.getIcon());
359360
break;
360361
}
361362
}
@@ -367,7 +368,7 @@ private boolean validateInput() {
367368
DetailPanel panel = item.getDetailPanel();
368369
if(panel instanceof EditDataSetPanel && !isNullOrEmpty(((EditDataSetPanel)panel).getGMTFileName())) {
369370
String message = "A common GMT file has been provided. Per-dataset GMT files will be ignored.";
370-
dialog.addSection(MessageType.WARN, commonPanel.getDisplayName(), commonPanel.getIcon(), message);
371+
dialog.addSection(Message.warn(message), commonPanel.getDisplayName(), commonPanel.getIcon());
371372
break;
372373
}
373374
}
@@ -381,38 +382,43 @@ private boolean validateInput() {
381382
.map(EditDataSetPanel::getDataSetName)
382383
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
383384

384-
List<String> messages = new ArrayList<>();
385+
List<Message> messages = new ArrayList<>();
385386
dataSetNameCount.forEach((name,count) -> {
386387
if(count > 1) {
387-
messages.add("Duplicate data set name: '" + name + "'");
388+
messages.add(Message.error("Duplicate data set name: '" + name + "'"));
388389
}
389390
});
390391

391392
if(!messages.isEmpty()) {
392-
dialog.addSection(MessageType.ERROR, "Duplicate Data Set Names", commonPanel.getIcon(), messages);
393+
dialog.addSection(messages, "Duplicate Data Set Names", commonPanel.getIcon());
393394
}
394395
}
395396

396397
// Check for input errors.
397398
for(DataSetListItem item : dataSetListModel.toList()) {
398399
DetailPanel panel = item.getDetailPanel();
399-
List<String> messages = panel.validateInput();
400+
List<Message> messages = panel.validateInput();
400401
if(!messages.isEmpty()) {
401-
dialog.addSection(MessageType.ERROR, panel.getDisplayName(), panel.getIcon(), messages);
402+
dialog.addSection(messages, panel.getDisplayName(), panel.getIcon());
402403
}
403404
}
404-
405-
if(!dialog.isEmpty()) {
406-
dialog.pack();
407-
dialog.setLocationRelativeTo(callback.getDialogFrame());
408-
dialog.setModal(true);
409-
dialog.setVisible(true);
410-
// This will always return false if the dialog has error messages.
411-
// If the dialog only has warning messages then the user can choose to continue.
412-
return dialog.shouldContinue();
405+
406+
if(dialog.isEmpty())
407+
return true;
408+
if(!dialog.hasErrors() && !propertyManager.getShowCreateWarnings())
409+
return true;
410+
411+
dialog.pack();
412+
dialog.setLocationRelativeTo(callback.getDialogFrame());
413+
dialog.setModal(true);
414+
dialog.setVisible(true);
415+
// This will always return false if the dialog has error messages.
416+
// If the dialog only has warning messages then the user can choose to continue.
417+
boolean shouldContinue = dialog.shouldContinue();
418+
if(dialog.isDontWarnAgain()) {
419+
propertyManager.setShowCreateWarnings(false);
413420
}
414-
415-
return true;
421+
return shouldContinue;
416422
}
417423

418424

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.baderlab.csplugins.enrichmentmap.view.creation;
2+
3+
import java.util.Objects;
4+
5+
public class Message {
6+
7+
public static enum MessageType {
8+
WARN, ERROR
9+
}
10+
11+
private final MessageType type;
12+
private final String message;
13+
14+
15+
public Message(MessageType type, String message) {
16+
this.type = Objects.requireNonNull(type);
17+
this.message = Objects.requireNonNull(message);
18+
}
19+
20+
public static Message warn(String message) {
21+
return new Message(MessageType.WARN, message);
22+
}
23+
24+
public static Message error(String message) {
25+
return new Message(MessageType.ERROR, message);
26+
}
27+
28+
public MessageType getType() {
29+
return type;
30+
}
31+
32+
public String getMessage() {
33+
return message;
34+
}
35+
36+
public boolean isError() {
37+
return type == MessageType.ERROR;
38+
}
39+
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/PathTextField.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ private static boolean emptyOrReadable(String text) {
104104
return Strings.isNullOrEmpty(text) || Files.isReadable(Paths.get(text));
105105
}
106106

107+
public boolean isReadable() {
108+
return !Strings.isNullOrEmpty(textField.getText()) && Files.isReadable(Paths.get(textField.getText()));
109+
}
110+
111+
public Path getPath() {
112+
return Paths.get(textField.getText());
113+
}
114+
107115
public boolean isEmpty() {
108116
return Strings.isNullOrEmpty(getText());
109117
}

0 commit comments

Comments
 (0)