Skip to content

Commit 23c19f3

Browse files
author
Michael P Schroeder
committed
Mutex wizard
1 parent af67768 commit 23c19f3

File tree

26 files changed

+364
-272
lines changed

26 files changed

+364
-272
lines changed

org.gitools.analysis/src/main/java/org/gitools/analysis/Analysis.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
*/
2222
package org.gitools.analysis;
2323

24+
import org.gitools.api.analysis.IAnalysis;
2425
import org.gitools.resource.Resource;
2526

2627
import javax.xml.bind.annotation.XmlAccessType;
2728
import javax.xml.bind.annotation.XmlAccessorType;
2829
import java.util.Date;
2930

3031
@XmlAccessorType(XmlAccessType.FIELD)
31-
public class Analysis extends Resource {
32+
public class Analysis extends Resource implements IAnalysis {
3233

3334
private static final long serialVersionUID = 44219853082656184L;
3435

@@ -45,18 +46,22 @@ public class Analysis extends Resource {
4546
protected Analysis() {
4647
}
4748

49+
@Override
4850
public Date getStartTime() {
4951
return startTime;
5052
}
5153

54+
@Override
5255
public long getElapsedTime() {
5356
return elapsedTime;
5457
}
5558

59+
@Override
5660
public void setStartTime(Date startTime) {
5761
this.startTime = startTime;
5862
}
5963

64+
@Override
6065
public void setElapsedTime(long elapsedTime) {
6166
this.elapsedTime = elapsedTime;
6267
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* #%L
3+
* org.gitools.api
4+
* %%
5+
* Copyright (C) 2013 - 2014 Universitat Pompeu Fabra - Biomedical Genomics group
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/gpl-3.0.html>.
20+
* #L%
21+
*/
22+
package org.gitools.api.analysis;
23+
24+
import java.util.Date;
25+
26+
public interface IAnalysis {
27+
Date getStartTime();
28+
29+
long getElapsedTime();
30+
31+
void setStartTime(Date startTime);
32+
33+
void setElapsedTime(long elapsedTime);
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* #%L
3+
* gitools-ui-app
4+
* %%
5+
* Copyright (C) 2013 Universitat Pompeu Fabra - Biomedical Genomics group
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/gpl-3.0.html>.
20+
* #L%
21+
*/
22+
package org.gitools.plugins.mutex;
23+
24+
import org.gitools.api.analysis.IProgressMonitor;
25+
import org.gitools.plugins.mutex.control.MutalExclusiveAnalysisCommand;
26+
import org.gitools.plugins.mutex.ui.MutualExclusiveAnalysisWizard;
27+
import org.gitools.ui.core.Application;
28+
import org.gitools.ui.core.actions.HeatmapAction;
29+
import org.gitools.ui.platform.progress.JobRunnable;
30+
import org.gitools.ui.platform.progress.JobThread;
31+
import org.gitools.ui.platform.wizard.WizardDialog;
32+
33+
import java.awt.event.ActionEvent;
34+
35+
public class MutualExclusiveAnalysisAction extends HeatmapAction {
36+
37+
public MutualExclusiveAnalysisAction() {
38+
super("<html>Mutual exclusion & Co-occurrence</html>");
39+
}
40+
41+
@Override
42+
public void actionPerformed(ActionEvent e) {
43+
44+
final MutualExclusiveAnalysisWizard wizard = new MutualExclusiveAnalysisWizard(getHeatmap());
45+
46+
WizardDialog wizDlg = new WizardDialog(Application.get(), wizard);
47+
wizDlg.open();
48+
if (wizDlg.isCancelled()) {
49+
return;
50+
}
51+
52+
JobThread.execute(Application.get(), new JobRunnable() {
53+
@Override
54+
public void run(IProgressMonitor monitor) {
55+
56+
MutalExclusiveAnalysisCommand command = new MutalExclusiveAnalysisCommand(wizard.createAnalysis());
57+
JobThread.execute(Application.get(), command);
58+
59+
}
60+
});
61+
62+
63+
}
64+
65+
}

org.gitools.plugins.mutex/src/main/java/org/gitools/plugins/mutex/actions/MutualExclusiveSortAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void run(IProgressMonitor monitor) {
9494
//TEST
9595
monitor.begin("Analyse ...", 1);
9696

97-
MutualExclusiveAnalysis analysis = new MutualExclusiveAnalysis();
97+
MutualExclusiveAnalysis analysis = new MutualExclusiveAnalysis(getHeatmap());
9898

9999
IMatrixDimension testDimension = hm.getContents().getDimension(dimensionKey);
100100
ArrayList<String> selected = newArrayList(

org.gitools.plugins.mutex/src/main/java/org/gitools/plugins/mutex/analysis/MutualExclusiveAnalysis.java

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,33 @@
2121
*/
2222
package org.gitools.plugins.mutex.analysis;
2323

24+
import com.google.common.base.Strings;
2425
import org.gitools.analysis.Analysis;
25-
import org.gitools.api.matrix.IMatrix;
26+
import org.gitools.analysis.clustering.ClusteringData;
27+
import org.gitools.analysis.clustering.ClusteringException;
28+
import org.gitools.analysis.clustering.annotations.AnnPatClusteringData;
29+
import org.gitools.analysis.clustering.annotations.AnnPatClusteringMethod;
30+
import org.gitools.api.analysis.Clusters;
2631
import org.gitools.api.matrix.IMatrixDimension;
32+
import org.gitools.api.matrix.MatrixDimensionKey;
2733
import org.gitools.api.modulemap.IModuleMap;
2834
import org.gitools.api.resource.ResourceReference;
2935
import org.gitools.api.resource.adapter.ResourceReferenceXmlAdapter;
3036
import org.gitools.heatmap.Heatmap;
37+
import org.gitools.heatmap.HeatmapDimension;
3138
import org.gitools.heatmap.HeatmapLayers;
3239
import org.gitools.heatmap.decorator.impl.NonEventToNullFunction;
3340
import org.gitools.heatmap.decorator.impl.PValueDecorator;
3441
import org.gitools.heatmap.decorator.impl.ZScoreDecorator;
42+
import org.gitools.matrix.modulemap.HashModuleMap;
43+
import org.gitools.ui.platform.settings.Settings;
44+
import org.gitools.utils.progressmonitor.DefaultProgressMonitor;
3545

3646
import javax.xml.bind.annotation.XmlRootElement;
3747
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
48+
import java.util.HashMap;
49+
import java.util.Map;
50+
import java.util.Set;
3851

3952
@XmlRootElement
4053
public class MutualExclusiveAnalysis extends Analysis {
@@ -45,13 +58,13 @@ public class MutualExclusiveAnalysis extends Analysis {
4558
private ResourceReference<Heatmap> results;
4659

4760
@XmlJavaTypeAdapter(ResourceReferenceXmlAdapter.class)
48-
private ResourceReference<IMatrix> data;
61+
private ResourceReference<Heatmap> data;
4962

5063
@XmlJavaTypeAdapter(ResourceReferenceXmlAdapter.class)
51-
private ResourceReference<IModuleMap> testGroupsModuleMap;
64+
private ResourceReference<IModuleMap> rowsModuleMap;
5265

5366
@XmlJavaTypeAdapter(ResourceReferenceXmlAdapter.class)
54-
private ResourceReference<IModuleMap> weightGroupsModuleMap;
67+
private ResourceReference<IModuleMap> columnsModuleMap;
5568

5669
private IMatrixDimension testDimension;
5770

@@ -63,7 +76,35 @@ public class MutualExclusiveAnalysis extends Analysis {
6376

6477
private boolean discardEmpty = false;
6578

66-
public MutualExclusiveAnalysis() {
79+
public MutualExclusiveAnalysis(Heatmap heatmap) {
80+
setData(heatmap);
81+
}
82+
83+
public static HashModuleMap createModules(String columnPattern, boolean allItemGroup, HeatmapDimension columns) {
84+
85+
HashModuleMap moduleMap = new HashModuleMap();
86+
87+
Map<String, Set<String>> colGroups = new HashMap<>();
88+
if (!Strings.isNullOrEmpty(columnPattern)) {
89+
ClusteringData data = new AnnPatClusteringData(columns, columnPattern);
90+
Clusters results = null;
91+
try {
92+
results = new AnnPatClusteringMethod().cluster(data, new DefaultProgressMonitor());
93+
} catch (ClusteringException e) {
94+
e.printStackTrace();
95+
}
96+
colGroups = results.getClustersMap();
97+
}
98+
99+
for (String key : colGroups.keySet()) {
100+
moduleMap.addMapping(key, colGroups.get(key));
101+
}
102+
103+
if (allItemGroup) {
104+
moduleMap.addMapping("All " + columns.getId().getLabel() + "s", columns.toList());
105+
}
106+
107+
return moduleMap;
67108
}
68109

69110

@@ -73,41 +114,43 @@ public IMatrixDimension getTestDimension() {
73114

74115
public void setTestDimension(IMatrixDimension testDimension) {
75116
this.testDimension = testDimension;
117+
this.weightDimension = data.get().getDimension(testDimension.getId().equals(MatrixDimensionKey.ROWS) ?
118+
MatrixDimensionKey.COLUMNS : MatrixDimensionKey.ROWS);
76119
}
77120

78-
public ResourceReference<IModuleMap> getTestGroupsModuleMap() {
79-
return testGroupsModuleMap;
121+
public ResourceReference<IModuleMap> getRowsModuleMap() {
122+
return rowsModuleMap;
80123
}
81124

82-
public void setTestGroupsModuleMap(ResourceReference<IModuleMap> testGroupsModuleMap) {
83-
this.testGroupsModuleMap = testGroupsModuleMap;
125+
public void setRowsModuleMap(ResourceReference<IModuleMap> rowsModuleMap) {
126+
this.rowsModuleMap = rowsModuleMap;
84127
}
85128

86-
public void setTestGroupsModuleMap(IModuleMap testGroupsModuleMap) {
87-
setTestGroupsModuleMap(new ResourceReference<>("testGroupsModuleMap", testGroupsModuleMap));
129+
public void setRowModuleMap(IModuleMap rowsModuleMap) {
130+
setRowsModuleMap(new ResourceReference<>("rowsModuleMap", rowsModuleMap));
88131
}
89132

90-
public ResourceReference<IModuleMap> getWeightGroupsModuleMap() {
91-
return weightGroupsModuleMap;
133+
public ResourceReference<IModuleMap> getColumnsModuleMap() {
134+
return columnsModuleMap;
92135
}
93136

94-
public void setWeightGroupsModuleMap(ResourceReference<IModuleMap> weightGroupsModuleMap) {
95-
this.weightGroupsModuleMap = weightGroupsModuleMap;
137+
public void setColumnsModuleMap(ResourceReference<IModuleMap> columnsModuleMap) {
138+
this.columnsModuleMap = columnsModuleMap;
96139
}
97140

98-
public void setWeightGroupsModuleMap(IModuleMap weightGroupsModuleMap) {
99-
setWeightGroupsModuleMap(new ResourceReference<>("weightGroupsModuleMap", weightGroupsModuleMap));
141+
public void setColumnsModuleMap(IModuleMap columnsModuleMap) {
142+
setColumnsModuleMap(new ResourceReference<>("setColumnsModuleMap", columnsModuleMap));
100143
}
101144

102-
public ResourceReference<IMatrix> getData() {
145+
public ResourceReference<Heatmap> getData() {
103146
return data;
104147
}
105148

106-
public void setData(ResourceReference<IMatrix> data) {
149+
private void setData(ResourceReference<Heatmap> data) {
107150
this.data = data;
108151
}
109152

110-
public void setData(IMatrix data) {
153+
private void setData(Heatmap data) {
111154
setData(new ResourceReference<>("data", data));
112155
}
113156

@@ -130,7 +173,14 @@ public ResourceReference<Heatmap> getResults() {
130173

131174
public void setResults(ResourceReference<Heatmap> results) {
132175
this.results = results;
133-
HeatmapLayers layers = results.get().getLayers();
176+
177+
Heatmap heatmap = results.get();
178+
heatmap.setTitle(getTitle() + "(Results)");
179+
180+
heatmap.setAuthorName(Settings.get().getAuthorName());
181+
heatmap.setAuthorEmail(Settings.get().getAuthorEmail());
182+
183+
HeatmapLayers layers = heatmap.getLayers();
134184
layers.get(MutualExclusiveResult.COOC_PVALUE).setDecorator(new PValueDecorator());
135185
layers.get(MutualExclusiveResult.MUTEX_PVALUE).setDecorator(new PValueDecorator());
136186
layers.get(MutualExclusiveResult.Z_SCORE).setDecorator(new ZScoreDecorator());
@@ -141,10 +191,6 @@ public IMatrixDimension getWeightDimension() {
141191
return weightDimension;
142192
}
143193

144-
public void setWeightDimension(IMatrixDimension weightDimension) {
145-
this.weightDimension = weightDimension;
146-
}
147-
148194
public int getIterations() {
149195
return iterations;
150196
}

org.gitools.plugins.mutex/src/main/java/org/gitools/plugins/mutex/analysis/MutualExclusiveProcessor.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,25 @@ public void run(IProgressMonitor monitor) {
6363
Date startTime = new Date();
6464

6565
// Prepare results matrix
66+
IMatrixDimension testDimension = analysis.getTestDimension();
67+
IModuleMap testGroups;
68+
IModuleMap weightGroups;
69+
70+
if (testDimension.getId().equals(ROWS)) {
71+
testGroups = analysis.getRowsModuleMap().get();
72+
weightGroups = analysis.getColumnsModuleMap().get();
73+
} else {
74+
weightGroups = analysis.getRowsModuleMap().get();
75+
testGroups = analysis.getColumnsModuleMap().get(); }
76+
6677

6778
IMatrix results = calculate(
6879
monitor,
6980
analysis.getData().get(),
7081
analysis.getData().get().getLayers().get(analysis.getLayer()),
71-
analysis.getTestGroupsModuleMap().get(),
72-
analysis.getWeightGroupsModuleMap().get(),
73-
analysis.getTestDimension(),
82+
testGroups,
83+
weightGroups,
84+
testDimension,
7485
analysis.getWeightDimension(),
7586
analysis.getIterations(),
7687
analysis.getEventFunction(),
@@ -84,7 +95,7 @@ public void run(IProgressMonitor monitor) {
8495
}
8596

8697
private IMatrix calculate(final IProgressMonitor monitor,
87-
final IMatrix data,
98+
final Heatmap data,
8899
final IMatrixLayer<Double> dataLayer,
89100
final IModuleMap testGroups,
90101
final IModuleMap weightGroups,
@@ -124,10 +135,10 @@ private IMatrix calculate(final IProgressMonitor monitor,
124135
if (discardEmpty) {
125136
samples = getNonEmptySamples(data, dataLayer, testDimensionSubset, weightDimension.subset(samples), eventFunction);
126137
weightDimensionSubset = weightDimension.subset(samples);
127-
weights = getWeights(monitor, data, dataLayer, testDimension, weightDimensionSubset, weightGroupInfo + ": " + testGroup, eventFunction);
138+
weights = getWeights(monitor, data, dataLayer, testDimension.getId(), weightDimensionSubset, weightGroupInfo + ": " + testGroup, eventFunction);
128139
} else if (weights.length == 0) {
129140
weightDimensionSubset = weightDimension.subset(samples);
130-
weights = getWeights(monitor, data, dataLayer, testDimension, weightDimensionSubset, weightGroupInfo, eventFunction);
141+
weights = getWeights(monitor, data, dataLayer, testDimension.getId(), weightDimensionSubset, weightGroupInfo, eventFunction);
131142
}
132143

133144
if (!weightGroupInfoSet) {
@@ -214,12 +225,13 @@ private void setCachedWeights(IMatrixLayer<Double> dataLayer,
214225
dataLayer.setCache(CACHEKEY, cache);
215226
}
216227

217-
private double[] getWeights(IProgressMonitor monitor, IMatrix data, final IMatrixLayer<Double> dataLayer, IMatrixDimension testDimension, IMatrixDimension weightDimension, String weightGroupInfo, final NonEventToNullFunction<?> eventFunction) {
228+
private double[] getWeights(IProgressMonitor monitor, Heatmap data, final IMatrixLayer<Double> dataLayer, MatrixDimensionKey testDimensionKey, IMatrixDimension weightDimension, String weightGroupInfo, final NonEventToNullFunction<?> eventFunction) {
218229

219230
IMatrixIterable<Double> weightIterator;
220231
final Map<String, Double> cachedWeights = getCachedWeights(dataLayer, weightDimension, eventFunction);
221232
int cacheSize = cachedWeights.size();
222-
final AggregationFunction aggregation = new AggregationFunction(dataLayer, NonNullCountAggregator.INSTANCE, testDimension, eventFunction);
233+
IMatrixDimension completeDataDimension = data.getContents().getDimension(testDimensionKey);
234+
final AggregationFunction aggregation = new AggregationFunction(dataLayer, NonNullCountAggregator.INSTANCE, completeDataDimension, eventFunction);
223235

224236
final AbstractMatrixFunction<Double, String> readWeightFunction =
225237
new AbstractMatrixFunction<Double, String>() {

0 commit comments

Comments
 (0)