Skip to content

Commit 415cfe5

Browse files
committed
Generate mastermap command in creation dialog. Refs #351
1 parent 1224b05 commit 415cfe5

File tree

16 files changed

+441
-38
lines changed

16 files changed

+441
-38
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class EMBuildProps {
2424
public static final String HELP_URL_HEATMAP = DOC_BASE_URL + "HeatMapPanel.html";
2525
public static final String HELP_URL_LEGEND = DOC_BASE_URL + "LegendDialog.html";
2626
public static final String HELP_URL_PA = DOC_BASE_URL + "PostAnalysis.html";
27+
public static final String HELP_URL_AUTO = DOC_BASE_URL + "Automating.html";
2728

2829

2930
private EMBuildProps() {}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/commands/MastermapCommandTask.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class MastermapCommandTask extends AbstractTask implements ObservableTask
3737
@Tunable(description="Absolute path to an expression file that will be used for every data set. Overrides other expression files.")
3838
public File commonExpressionFile;
3939

40+
@Tunable(description="Absolute path to a class file that will be used for every data set. Overrides other class files.")
41+
public File commonClassFile;
42+
4043
@ContainsTunables
4144
@Inject
4245
public FilterTunables filterArgs;
@@ -98,6 +101,16 @@ public void run(TaskMonitor tm) throws Exception {
98101
}
99102
}
100103

104+
// Overwrite all the gmt files if a common file has been provided
105+
if(commonClassFile != null) {
106+
if(!commonClassFile.canRead()) {
107+
throw new IllegalArgumentException("Cannot read commonClassFile: " + commonClassFile);
108+
}
109+
for(DataSetParameters dsp : dataSets) {
110+
dsp.getFiles().setClassFile(commonClassFile.getAbsolutePath());
111+
}
112+
}
113+
101114
tm.setStatusMessage(filterArgs.toString());
102115

103116
EMCreationParameters params = filterArgs.getCreationParameters();

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/model/DataSetParameters.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.baderlab.csplugins.enrichmentmap.model;
22

3+
import java.nio.file.Path;
4+
import java.nio.file.Paths;
5+
import java.util.ArrayList;
6+
import java.util.List;
37
import java.util.Objects;
48
import java.util.Optional;
59

@@ -49,6 +53,23 @@ public Method getMethod() {
4953
return method;
5054
}
5155

56+
public List<Path> getFilePaths() {
57+
List<Path> paths = new ArrayList<>();
58+
if(files.getGMTFileName() != null)
59+
paths.add(Paths.get(files.getGMTFileName()));
60+
if(files.getEnrichmentFileName1() != null)
61+
paths.add(Paths.get(files.getEnrichmentFileName1()));
62+
if(files.getEnrichmentFileName2() != null)
63+
paths.add(Paths.get(files.getEnrichmentFileName2()));
64+
if(files.getExpressionFileName() != null)
65+
paths.add(Paths.get(files.getExpressionFileName()));
66+
if(files.getRankedFile() != null)
67+
paths.add(Paths.get(files.getRankedFile()));
68+
if(files.getClassFile() != null)
69+
paths.add(Paths.get(files.getClassFile()));
70+
return paths;
71+
}
72+
5273
@Override
5374
public String toString() {
5475
return MoreObjects.toStringHelper(this)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.baderlab.csplugins.enrichmentmap.util;
2+
3+
import java.nio.file.Path;
4+
import java.nio.file.Paths;
5+
import java.util.Collection;
6+
import java.util.List;
7+
import java.util.stream.Collectors;
8+
9+
import org.baderlab.csplugins.enrichmentmap.model.DataSetParameters;
10+
11+
public class PathUtil {
12+
13+
private PathUtil() {}
14+
15+
public static List<Path> dataSetsRoots(Collection<DataSetParameters> dataSets) {
16+
return dataSets.stream()
17+
.map(DataSetParameters::getFilePaths)
18+
.map(PathUtil::commonRoot)
19+
.collect(Collectors.toList());
20+
}
21+
22+
public static Path commonRoot(List<Path> paths) {
23+
if(paths == null || paths.isEmpty())
24+
return null;
25+
if(paths.size() == 1)
26+
return paths.get(0);
27+
28+
Path common = paths.get(0);
29+
for(Path path : paths.subList(1, paths.size())) {
30+
common = commonRoot(common, path);
31+
if(common == null) {
32+
return null;
33+
}
34+
}
35+
return common;
36+
}
37+
38+
39+
public static Path commonRoot(Path p1, Path p2) {
40+
if(p1 == null || p2 == null)
41+
return null;
42+
Path common;
43+
if(p1.isAbsolute() && p2.isAbsolute() && p1.getRoot().equals(p2.getRoot()))
44+
common = p1.getRoot();
45+
else if(!p1.isAbsolute() && !p2.isAbsolute())
46+
common = Paths.get("");
47+
else
48+
return null;
49+
50+
int n = Math.min(p1.getNameCount(), p2.getNameCount());
51+
for(int i = 0; i < n; i++) {
52+
Path name1 = p1.getName(i);
53+
Path name2 = p2.getName(i);
54+
if(!name1.equals(name2))
55+
break;
56+
common = common.resolve(name1);
57+
}
58+
return common;
59+
}
60+
}
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
package org.baderlab.csplugins.enrichmentmap.view.creation;
2+
3+
import static org.baderlab.csplugins.enrichmentmap.EMBuildProps.HELP_URL_AUTO;
4+
5+
import java.awt.BorderLayout;
6+
import java.awt.Dimension;
7+
import java.awt.GridBagConstraints;
8+
import java.awt.GridBagLayout;
9+
import java.nio.file.Path;
10+
import java.util.List;
11+
12+
import javax.swing.BorderFactory;
13+
import javax.swing.JButton;
14+
import javax.swing.JDialog;
15+
import javax.swing.JLabel;
16+
import javax.swing.JOptionPane;
17+
import javax.swing.JPanel;
18+
import javax.swing.JScrollPane;
19+
import javax.swing.JTextArea;
20+
import javax.swing.UIManager;
21+
import javax.swing.WindowConstants;
22+
23+
import org.baderlab.csplugins.enrichmentmap.commands.tunables.FilterTunables;
24+
import org.baderlab.csplugins.enrichmentmap.model.DataSetParameters;
25+
import org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters;
26+
import org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters.SimilarityMetric;
27+
import org.baderlab.csplugins.enrichmentmap.util.PathUtil;
28+
import org.baderlab.csplugins.enrichmentmap.view.util.GBCFactory;
29+
import org.baderlab.csplugins.enrichmentmap.view.util.OpenBrowser;
30+
import org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil;
31+
import org.cytoscape.util.swing.LookAndFeelUtil;
32+
33+
import com.google.inject.Inject;
34+
35+
@SuppressWarnings("serial")
36+
public class CommandDisplayMediator {
37+
38+
@Inject private OpenBrowser openBrowser;
39+
40+
41+
public void showCommand(
42+
JDialog parent,
43+
EMCreationParameters params,
44+
List<DataSetParameters> dataSets,
45+
String commonExprFile,
46+
String commonGMTFile,
47+
String commonClassFile
48+
) {
49+
Path root = getCommonRoot(dataSets);
50+
if(root == null) {
51+
showFailDialog(parent);
52+
} else {
53+
String command = generateCommand(root, params, dataSets, commonExprFile, commonGMTFile, commonClassFile);
54+
CommandDisplayDialog dialog = new CommandDisplayDialog(parent, command);
55+
dialog.showDialog();
56+
}
57+
}
58+
59+
private static void showFailDialog(JDialog parent) {
60+
String message = "Data Set files do not have a common root folder.";
61+
String title = "Create EnrichmentMap Command";
62+
JOptionPane.showMessageDialog(parent, message, title, JOptionPane.WARNING_MESSAGE);
63+
}
64+
65+
66+
private static Path getCommonRoot(List<DataSetParameters> dataSets) {
67+
List<Path> dataSetRoots = PathUtil.dataSetsRoots(dataSets);
68+
Path r = PathUtil.commonRoot(dataSetRoots);
69+
70+
if(r == null || r.getNameCount() == 1) {
71+
return null;
72+
}
73+
for(Path p : dataSetRoots) {
74+
if(!(p.startsWith(r) && p.getNameCount() - r.getNameCount() < 2)) {
75+
return null;
76+
}
77+
}
78+
return r;
79+
}
80+
81+
82+
private static String generateCommand(
83+
Path root,
84+
EMCreationParameters params,
85+
List<DataSetParameters> dataSets,
86+
String commonExprFile,
87+
String commonGMTFile,
88+
String commonClassFile
89+
) {
90+
StringBuilder command = new StringBuilder("enrichmentmap mastermap ");
91+
command.append("rootFolder=\"").append(root).append("\" ");
92+
93+
FilterTunables defaults = new FilterTunables();
94+
95+
if(params.getSimilarityMetric() != defaults.getSimilarityMetric()) {
96+
command.append("coefficients=").append(params.getSimilarityMetric().name()).append(" ");
97+
}
98+
if(params.getPvalue() != defaults.pvalue) {
99+
command.append("pvalue=").append(params.getPvalue()).append(" ");
100+
}
101+
if(params.getQvalue() != defaults.qvalue) {
102+
command.append("qvalue=").append(params.getQvalue()).append(" ");
103+
}
104+
if(params.getSimilarityCutoff() != defaults.similaritycutoff) {
105+
command.append("similaritycutoff=").append(params.getSimilarityCutoff()).append(" ");
106+
}
107+
if(params.getSimilarityMetric() == SimilarityMetric.COMBINED) {
108+
command.append("combinedConstant=").append(params.getCombinedConstant()).append(" ");
109+
}
110+
if(params.getEdgeStrategy() != defaults.getEdgeStrategy()) {
111+
command.append("edgeStrategy=").append(params.getEdgeStrategy().name()).append(" ");
112+
}
113+
if(params.getMinExperiments().isPresent()) {
114+
command.append("minExperiments=").append(params.getMinExperiments().get()).append(" ");
115+
}
116+
if(params.getNESFilter() != defaults.getNesFilter()) {
117+
command.append("nesFilter=").append(params.getNESFilter().name()).append(" ");
118+
}
119+
if(params.isFilterByExpressions() != defaults.filterByExpressions) {
120+
command.append("filterByExpressions=").append(params.isFilterByExpressions()).append(" ");
121+
}
122+
if(params.isParseBaderlabGeneSets() != defaults.parseBaderlabNames) {
123+
command.append("parseBaderlabNames=").append(params.isParseBaderlabGeneSets()).append(" ");
124+
}
125+
if(params.getNetworkName() != null) {
126+
command.append("networkName=\"").append(params.getNetworkName()).append("\" ");
127+
}
128+
if(commonGMTFile != null) {
129+
command.append("commonGMTFile=\"").append(commonGMTFile).append("\" ");
130+
}
131+
if(commonExprFile != null) {
132+
command.append("commonExpressionFile=\"").append(commonExprFile).append("\" ");
133+
}
134+
if(commonClassFile != null) {
135+
command.append("commonClassFile=\"").append(commonClassFile).append("\" ");
136+
}
137+
138+
return command.toString();
139+
}
140+
141+
142+
private class CommandDisplayDialog extends JDialog {
143+
144+
public CommandDisplayDialog(JDialog parent, String command) {
145+
super(parent);
146+
setResizable(true);
147+
setTitle("EnrichmentMap: Command");
148+
setMinimumSize(new Dimension(500, 300));
149+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
150+
151+
JPanel messagePanel = createMessagePanel();
152+
JPanel commandPanel = createCommandPanel(command);
153+
JPanel buttonPanel = createButtonPanel();
154+
155+
messagePanel.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
156+
commandPanel.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
157+
buttonPanel .setBorder(BorderFactory.createMatteBorder(1,0,0,0, UIManager.getColor("Separator.foreground")));
158+
159+
JPanel panel = new JPanel(new BorderLayout());
160+
panel.add(messagePanel, BorderLayout.NORTH);
161+
panel.add(commandPanel, BorderLayout.CENTER);
162+
panel.add(buttonPanel, BorderLayout.SOUTH);
163+
setContentPane(panel);
164+
}
165+
166+
public void showDialog() {
167+
setLocationRelativeTo(getParent());
168+
pack();
169+
setVisible(true);
170+
}
171+
172+
private JPanel createMessagePanel() {
173+
String message =
174+
"<html>The command below can be used in a script to automate the<br>"
175+
+ "creation of an EnrichmentMap network. Data files are expected to<br>"
176+
+ "be under a common root folder. The command arguments are based<br>"
177+
+ "on the values currently entered in the Create EnrichmentMap Dialog.</html>";
178+
JLabel label = new JLabel(message);
179+
JButton link = SwingUtil.createLinkButton(openBrowser, "View online help", HELP_URL_AUTO);
180+
181+
JPanel panel = new JPanel(new GridBagLayout());
182+
panel.add(label, GBCFactory.grid(0,0).weightx(1.0).anchor(GridBagConstraints.WEST).get());
183+
panel.add(link, GBCFactory.grid(0,1).fill(GridBagConstraints.NONE).anchor(GridBagConstraints.WEST).get());
184+
return panel;
185+
}
186+
187+
188+
private JPanel createCommandPanel(String command) {
189+
JTextArea textArea = new JTextArea(command);
190+
textArea.setEditable(false);
191+
textArea.setLineWrap(true);
192+
textArea.setWrapStyleWord(true);
193+
JScrollPane scrollPane = new JScrollPane(textArea);
194+
195+
JPanel panel = new JPanel(new BorderLayout());
196+
panel.add(scrollPane, BorderLayout.CENTER);
197+
return panel;
198+
}
199+
200+
private JPanel createButtonPanel() {
201+
JButton okButton = new JButton("Close");
202+
okButton.addActionListener(e -> dispose());
203+
return LookAndFeelUtil.createOkCancelPanel(okButton, null);
204+
}
205+
}
206+
207+
208+
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
public class CreationDialogParameters implements CardDialogParameters {
2121

22-
static final String RESET_BUTTON_ACTION_COMMAND = "reset";
22+
static final String RESET_BUTTON_ACTION = "reset";
23+
static final String COMMAND_BUTTON_ACTION = "command";
2324

2425
@Inject private Provider<MasterDetailDialogPage> masterDetailDialogPage;
2526
@Inject private CyServiceRegistrar registrar;
@@ -56,10 +57,15 @@ public Dimension getMinimumSize() {
5657
}
5758

5859
@Override
59-
public AbstractButton[] getAdditionalButtons() {
60+
public AbstractButton[] getExtraButtons() {
6061
JButton resetButton = new JButton("Reset");
61-
resetButton.setActionCommand(RESET_BUTTON_ACTION_COMMAND);
62+
resetButton.setActionCommand(RESET_BUTTON_ACTION);
63+
64+
JButton commandButton = new JButton("Show Command");
65+
commandButton.setActionCommand(COMMAND_BUTTON_ACTION);
66+
6267
JButton helpButton = SwingUtil.createOnlineHelpButton(HELP_URL_CREATE, "View online help", registrar);
63-
return new JButton[] { resetButton, helpButton };
68+
69+
return new JButton[] { resetButton, commandButton, helpButton };
6470
}
6571
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ public String getGmtFile() {
129129
return gmtText.getText();
130130
}
131131

132-
public String getExpressionFile() {
132+
public String getExprFile() {
133133
return expressionsText.getText();
134134
}
135135

136136
public String getClassFile() {
137137
return classText.getText();
138138
}
139139

140-
public boolean hasExpressionFile() {
141-
return !isNullOrEmpty(getExpressionFile());
140+
public boolean hasExprFile() {
141+
return !isNullOrEmpty(getExprFile());
142142
}
143143

144144
public boolean hasGmtFile() {

0 commit comments

Comments
 (0)