Skip to content

Commit c42e822

Browse files
committed
Refs #373. Add swagger documentation to commands. Refactor
CommandModule. Add 'mastermap list' command.
1 parent 3f14202 commit c42e822

File tree

11 files changed

+254
-124
lines changed

11 files changed

+254
-124
lines changed
Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,105 @@
11
package org.baderlab.csplugins.enrichmentmap;
22

3-
import static java.lang.annotation.RetentionPolicy.RUNTIME;
4-
5-
import java.lang.annotation.Retention;
6-
73
import org.baderlab.csplugins.enrichmentmap.actions.OpenEnrichmentMapAction;
84
import org.baderlab.csplugins.enrichmentmap.commands.ChartCommandTask;
95
import org.baderlab.csplugins.enrichmentmap.commands.DatasetShowCommandTask;
106
import org.baderlab.csplugins.enrichmentmap.commands.EMBuildCommandTask;
117
import org.baderlab.csplugins.enrichmentmap.commands.EMGseaCommandTask;
128
import org.baderlab.csplugins.enrichmentmap.commands.ExportModelJsonCommandTask;
139
import org.baderlab.csplugins.enrichmentmap.commands.ExportPDFCommandTask;
10+
import org.baderlab.csplugins.enrichmentmap.commands.MastermapCommandTask;
11+
import org.baderlab.csplugins.enrichmentmap.commands.MastermapListCommandTask;
1412
import org.baderlab.csplugins.enrichmentmap.commands.PAKnownSignatureCommandTask;
15-
import org.baderlab.csplugins.enrichmentmap.commands.ResolverCommandTask;
1613
import org.baderlab.csplugins.enrichmentmap.commands.TableCommandTask;
17-
import org.cytoscape.work.AbstractTaskFactory;
18-
import org.cytoscape.work.Task;
19-
import org.cytoscape.work.TaskFactory;
20-
import org.cytoscape.work.TaskIterator;
2114

2215
import com.google.inject.AbstractModule;
23-
import com.google.inject.BindingAnnotation;
2416
import com.google.inject.Provider;
25-
import com.google.inject.Provides;
17+
import com.google.inject.multibindings.MultibindingsScanner;
18+
import com.google.inject.multibindings.ProvidesIntoSet;
2619

2720
public class CommandModule extends AbstractModule {
2821

29-
@BindingAnnotation @Retention(RUNTIME) public @interface BuildCommand { }
30-
@BindingAnnotation @Retention(RUNTIME) public @interface GSEACommand { }
31-
@BindingAnnotation @Retention(RUNTIME) public @interface ResolveCommand { }
32-
@BindingAnnotation @Retention(RUNTIME) public @interface PACommand { }
33-
@BindingAnnotation @Retention(RUNTIME) public @interface JsonCommand { }
34-
@BindingAnnotation @Retention(RUNTIME) public @interface BuildTableCommand { }
35-
@BindingAnnotation @Retention(RUNTIME) public @interface DatasetShowCommand { }
36-
@BindingAnnotation @Retention(RUNTIME) public @interface DatasetHideCommand { }
37-
@BindingAnnotation @Retention(RUNTIME) public @interface ChartCommand { }
38-
@BindingAnnotation @Retention(RUNTIME) public @interface ExportPDFCommand { }
39-
4022
@Override
41-
protected void configure() {
23+
protected void configure() {
24+
install(MultibindingsScanner.asModule());
4225
}
4326

44-
@Provides @BuildCommand
45-
public TaskFactory provideBuild(Provider<EMBuildCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
46-
return createTaskFactory(taskProvider, showTask);
47-
}
4827

49-
@Provides @GSEACommand
50-
public TaskFactory provideGSEA(Provider<EMGseaCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
51-
return createTaskFactory(taskProvider, showTask);
28+
@ProvidesIntoSet
29+
public CommandTaskFactory provideBuild(Provider<EMBuildCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
30+
String desc = "Creates an EnrichmentMap network containing one or two data sets.";
31+
return CommandTaskFactory.create("build", desc, null, taskProvider, showTask);
5232
}
5333

54-
@Provides @ResolveCommand
55-
public TaskFactory provideResolve(Provider<ResolverCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
56-
return createTaskFactory(taskProvider, showTask);
34+
@ProvidesIntoSet
35+
public CommandTaskFactory provideGSEA(Provider<EMGseaCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
36+
String desc = "Creates an EnrichmetMap network from one or two GSEA results. (Deprecated, use 'build' or 'mastermap' command instead.)";
37+
return CommandTaskFactory.create("gseabuild", desc, null, taskProvider, showTask);
5738
}
5839

59-
@Provides @PACommand
60-
public TaskFactory providePA(Provider<PAKnownSignatureCommandTask> taskProvider) {
61-
return createTaskFactory(taskProvider);
40+
@ProvidesIntoSet
41+
public CommandTaskFactory provideMastermap(Provider<MastermapCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
42+
String desc = "Creates an EnrichmentMap network containing any number of data sets by scanning files in a folder.";
43+
String longDesc = "Uses the same algorithm as the Create EnrichmentMap Dialog to scan the files in a folder and "
44+
+ "automatically group them into data sets. Sub-folders will be scanned up to one level deep, allowing you to "
45+
+ "organize your data sets into sub-folders under the root folder. Please see the EnrichmentMap documentation "
46+
+ "for more details on how files are chosen for each data set.";
47+
return CommandTaskFactory.create("mastermap", desc, longDesc, taskProvider, showTask);
6248
}
6349

64-
@Provides @JsonCommand
65-
public TaskFactory provideJson(Provider<ExportModelJsonCommandTask> taskProvider) {
66-
return createTaskFactory(taskProvider);
50+
@ProvidesIntoSet
51+
public CommandTaskFactory provideMastermapList(Provider<MastermapListCommandTask> taskProvider) {
52+
String desc = "Scans files in a folder and prints out how they would be grouped into data sets, but does not create a network. "
53+
+ "This command is intended to help debug the 'mastermap' command by showing how the files will be grouped into data sets "
54+
+ "without actually creating the network.";
55+
return CommandTaskFactory.create("mastermap list", desc, null, taskProvider);
6756
}
6857

69-
@Provides @BuildTableCommand
70-
public TaskFactory provideBuildTable(Provider<TableCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
71-
return createTaskFactory(taskProvider, showTask);
58+
@ProvidesIntoSet
59+
public CommandTaskFactory providePA(Provider<PAKnownSignatureCommandTask> taskProvider) {
60+
String desc = "Adds more gene sets to an existing network. This is done by calculating the overlap between gene sets of the "
61+
+ "current EnrichmentMap network and all the gene sets contained in the provided signature gene set file.";
62+
return CommandTaskFactory.create("pa", desc, null, taskProvider);
7263
}
7364

74-
@Provides @DatasetShowCommand
75-
public TaskFactory provideDatasetShow(DatasetShowCommandTask.Factory taskFactory) {
76-
return createTaskFactory(() -> taskFactory.create(true));
65+
@ProvidesIntoSet
66+
public CommandTaskFactory provideJson(Provider<ExportModelJsonCommandTask> taskProvider) {
67+
String desc = "Exports the EnrichmentMap data model to a file. Intended mainly for debugging.";
68+
return CommandTaskFactory.create("export model", desc, null, taskProvider);
7769
}
7870

79-
@Provides @DatasetHideCommand
80-
public TaskFactory provideDatasetHide(DatasetShowCommandTask.Factory taskFactory) {
81-
return createTaskFactory(() -> taskFactory.create(false));
71+
@ProvidesIntoSet
72+
public CommandTaskFactory provideBuildTable(Provider<TableCommandTask> taskProvider, OpenEnrichmentMapAction showTask) {
73+
String desc = "Creates an EnrichmentMap network from values in a table.";
74+
String longDesc = "Intended mainly for other Apps to programatically create an EnrichmentMap network.";
75+
return CommandTaskFactory.create("build-table", desc, longDesc, taskProvider, showTask);
8276
}
8377

84-
@Provides @ChartCommand
85-
public TaskFactory provideChart(Provider<ChartCommandTask> taskFactory) {
86-
return createTaskFactory(taskFactory);
78+
@ProvidesIntoSet
79+
public CommandTaskFactory provideDatasetShow(DatasetShowCommandTask.Factory taskFactory) {
80+
String desc = "Allows to select the data sets to show in an EnrichmentMap network.";
81+
String longDesc = "This command is basically the same as clicking the checkboxes next to the data sets in the main EnrichmentMap panel.";
82+
return CommandTaskFactory.create("dataset show", desc, longDesc, () -> taskFactory.create(true));
8783
}
8884

89-
@Provides @ExportPDFCommand
90-
public TaskFactory provideExportPDF(Provider<ExportPDFCommandTask> taskProvider) {
91-
return createTaskFactory(taskProvider);
85+
@ProvidesIntoSet
86+
public CommandTaskFactory provideDatasetHide(DatasetShowCommandTask.Factory taskFactory) {
87+
String desc = "Allows to de-select the data sets to show in an EnrichmentMap network.";
88+
String longDesc = "This command is basically the same as clicking the checkboxes next to the data sets in the main EnrichmentMap panel.";
89+
return CommandTaskFactory.create("dataset hide", desc, longDesc, () -> taskFactory.create(false));
9290
}
9391

94-
95-
private static TaskFactory createTaskFactory(Provider<? extends Task> taskProvider, Task ... tasks) {
96-
return new AbstractTaskFactory() {
97-
@Override
98-
public TaskIterator createTaskIterator() {
99-
TaskIterator taskIterator = new TaskIterator(taskProvider.get());
100-
for(Task task : tasks) {
101-
taskIterator.append(task);
102-
}
103-
return taskIterator;
104-
}
105-
};
92+
@ProvidesIntoSet
93+
public CommandTaskFactory provideChart(Provider<ChartCommandTask> taskFactory) {
94+
String desc = "Sets the chart options for an EnrichmentMap network.";
95+
String longDesc = "This command is basically the same as setting the chart options in the main EnrichmentMap panel.";
96+
return CommandTaskFactory.create("chart", desc, longDesc, taskFactory);
10697
}
10798

99+
@ProvidesIntoSet
100+
public CommandTaskFactory provideExportPDF(Provider<ExportPDFCommandTask> taskProvider) {
101+
String desc = "Exports the contents of the Heat Map panel to a PDF file.";
102+
return CommandTaskFactory.create("export pdf", desc, null, taskProvider);
103+
}
104+
108105
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.baderlab.csplugins.enrichmentmap;
2+
3+
import org.cytoscape.work.ObservableTask;
4+
import org.cytoscape.work.Task;
5+
import org.cytoscape.work.TaskFactory;
6+
import org.cytoscape.work.TaskIterator;
7+
import org.cytoscape.work.json.JSONResult;
8+
9+
import com.google.inject.Provider;
10+
11+
public interface CommandTaskFactory extends TaskFactory {
12+
13+
14+
public String getName();
15+
16+
public String getDescription();
17+
18+
public String getLongDescription();
19+
20+
public boolean supportsJson();
21+
22+
23+
public static CommandTaskFactory create(String name, String desc, String longDesc, Provider<? extends Task> taskProvider, Task... moreTasks) {
24+
Task task = taskProvider.get();
25+
boolean supportsJson;
26+
if(task instanceof ObservableTask) {
27+
supportsJson = ((ObservableTask)task).getResultClasses().contains(JSONResult.class);
28+
} else {
29+
supportsJson = false;
30+
}
31+
32+
return new CommandTaskFactory() {
33+
@Override
34+
public TaskIterator createTaskIterator() {
35+
TaskIterator taskIterator = new TaskIterator(taskProvider.get());
36+
for(Task task : moreTasks) {
37+
taskIterator.append(task);
38+
}
39+
return taskIterator;
40+
}
41+
42+
@Override public boolean isReady() { return true; }
43+
@Override public String getName() { return name; }
44+
@Override public String getDescription() { return desc; }
45+
@Override public String getLongDescription() { return longDesc == null ? null : desc + " " + longDesc; }
46+
@Override public boolean supportsJson() { return supportsJson; }
47+
};
48+
}
49+
}

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

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66
import static org.cytoscape.work.ServiceProperties.TITLE;
77

88
import java.util.Properties;
9+
import java.util.Set;
910

1011
import org.baderlab.csplugins.enrichmentmap.ApplicationModule.Headless;
11-
import org.baderlab.csplugins.enrichmentmap.CommandModule.BuildCommand;
12-
import org.baderlab.csplugins.enrichmentmap.CommandModule.BuildTableCommand;
13-
import org.baderlab.csplugins.enrichmentmap.CommandModule.ChartCommand;
14-
import org.baderlab.csplugins.enrichmentmap.CommandModule.DatasetHideCommand;
15-
import org.baderlab.csplugins.enrichmentmap.CommandModule.DatasetShowCommand;
16-
import org.baderlab.csplugins.enrichmentmap.CommandModule.ExportPDFCommand;
17-
import org.baderlab.csplugins.enrichmentmap.CommandModule.GSEACommand;
18-
import org.baderlab.csplugins.enrichmentmap.CommandModule.JsonCommand;
19-
import org.baderlab.csplugins.enrichmentmap.CommandModule.PACommand;
20-
import org.baderlab.csplugins.enrichmentmap.CommandModule.ResolveCommand;
2112
import org.baderlab.csplugins.enrichmentmap.actions.OpenEnrichmentMapAction;
2213
import org.baderlab.csplugins.enrichmentmap.actions.OpenPathwayCommonsTaskFactory;
2314
import org.baderlab.csplugins.enrichmentmap.commands.tunables.MannWhitRanksTunableHandlerFactory;
@@ -143,28 +134,23 @@ private void registerNodeViewMenu(BundleContext bc, String text, Class<?> klass)
143134
}
144135

145136
private void initializeCommands(BundleContext bc) {
146-
registerCommand(bc, "build", injector.getInstance(Key.get(TaskFactory.class, BuildCommand.class)));
147-
registerCommand(bc, "gseabuild", injector.getInstance(Key.get(TaskFactory.class, GSEACommand.class)));
148-
registerCommand(bc, "mastermap", injector.getInstance(Key.get(TaskFactory.class, ResolveCommand.class)));
149-
registerCommand(bc, "pa", injector.getInstance(Key.get(TaskFactory.class, PACommand.class)));
150-
registerCommand(bc, "export model", injector.getInstance(Key.get(TaskFactory.class, JsonCommand.class)));
151-
registerCommand(bc, "build-table", injector.getInstance(Key.get(TaskFactory.class, BuildTableCommand.class)));
152-
registerCommand(bc, "dataset show", injector.getInstance(Key.get(TaskFactory.class, DatasetShowCommand.class)));
153-
registerCommand(bc, "dataset hide", injector.getInstance(Key.get(TaskFactory.class, DatasetHideCommand.class)));
154-
registerCommand(bc, "chart", injector.getInstance(Key.get(TaskFactory.class, ChartCommand.class)));
155-
registerCommand(bc, "export pdf", injector.getInstance(Key.get(TaskFactory.class, ExportPDFCommand.class)));
137+
Set<CommandTaskFactory> commands = injector.getInstance(Key.get(new TypeLiteral<Set<CommandTaskFactory>>(){}));
138+
for(CommandTaskFactory command : commands) {
139+
Properties props = new Properties();
140+
props.put(ServiceProperties.COMMAND, command.getName());
141+
props.put(ServiceProperties.COMMAND_NAMESPACE, "enrichmentmap");
142+
props.put(ServiceProperties.COMMAND_DESCRIPTION, command.getDescription());
143+
if(command.getLongDescription() != null)
144+
props.put(ServiceProperties.COMMAND_LONG_DESCRIPTION, command.getLongDescription());
145+
if(command.supportsJson())
146+
props.put(ServiceProperties.COMMAND_SUPPORTS_JSON, true);
147+
148+
registerService(bc, command, TaskFactory.class, props);
149+
}
156150
registerService(bc, new MannWhitRanksTunableHandlerFactory(), StringTunableHandlerFactory.class);
157151
}
158152

159153

160-
private void registerCommand(BundleContext bc, String command, TaskFactory taskFactory) {
161-
Properties props = new Properties();
162-
props.put(ServiceProperties.COMMAND, command);
163-
props.put(ServiceProperties.COMMAND_NAMESPACE, "enrichmentmap");
164-
registerService(bc, taskFactory, TaskFactory.class, props);
165-
}
166-
167-
168154
@Override
169155
public void shutDown() {
170156
try {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public class ChartCommandTask extends AbstractTask {
4040
@ContainsTunables @Inject
4141
public NetworkTunable networkTunable;
4242

43-
@Tunable
43+
@Tunable(description = "Sets the chart data to show.")
4444
public ListSingleSelection<String> data;
4545

46-
@Tunable
46+
@Tunable(description = "Sets the chart type.")
4747
public ListSingleSelection<String> type;
4848

49-
@Tunable
49+
@Tunable(description = "Sets the chart colors.")
5050
public ListSingleSelection<String> colors;
5151

5252
@Tunable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ExportPDFCommandTask extends AbstractTask {
3737
@ContainsTunables @Inject
3838
public NetworkTunable networkTunable;
3939

40-
@Tunable(required=true)
40+
@Tunable(required=true, description = "Absolute path to the PDF file to be exported. Will be overwritten if it already exists.")
4141
public File file;
4242

4343
@Tunable(description="true (default) for only selected nodes and edges, false for all nodes and edges")
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323

2424
import com.google.inject.Inject;
2525

26-
public class ResolverCommandTask extends AbstractTask implements ObservableTask {
2726

28-
@Tunable(required=true)
27+
public class MastermapCommandTask extends AbstractTask implements ObservableTask {
28+
29+
@Tunable(required=true, description="Absolute path to a folder containing the data files. "
30+
+ "The files will be scanned and automatically grouped into data sets. Sub-folders will be scanned up to one level deep.")
2931
public File rootFolder;
3032

31-
@Tunable
33+
@Tunable(description="Absolute path to a GMT file that will be used for every data set. Overrides other GMT files.")
3234
public File commonGMTFile;
3335

34-
@Tunable
36+
@Tunable(description="Absolute path to an expression file that will be used for every data set. Overrides other expression files.")
3537
public File commonExpressionFile;
3638

3739
@ContainsTunables
@@ -50,7 +52,7 @@ public class ResolverCommandTask extends AbstractTask implements ObservableTask
5052
public void run(TaskMonitor tm) throws Exception {
5153
if(tm == null)
5254
tm = new NullTaskMonitor();
53-
tm.setStatusMessage("Running EnrichmentMap Data Set Resolver Task");
55+
tm.setStatusMessage("Running EnrichmentMap Mastermap Task");
5456

5557
if(rootFolder == null || !rootFolder.exists()) {
5658
throw new IllegalArgumentException("rootFolder is invalid: " + rootFolder);

0 commit comments

Comments
 (0)