2121 */
2222package org .gitools .plugins .mutex .analysis ;
2323
24+ import com .google .common .base .Strings ;
2425import 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 ;
2631import org .gitools .api .matrix .IMatrixDimension ;
32+ import org .gitools .api .matrix .MatrixDimensionKey ;
2733import org .gitools .api .modulemap .IModuleMap ;
2834import org .gitools .api .resource .ResourceReference ;
2935import org .gitools .api .resource .adapter .ResourceReferenceXmlAdapter ;
3036import org .gitools .heatmap .Heatmap ;
37+ import org .gitools .heatmap .HeatmapDimension ;
3138import org .gitools .heatmap .HeatmapLayers ;
3239import org .gitools .heatmap .decorator .impl .NonEventToNullFunction ;
3340import org .gitools .heatmap .decorator .impl .PValueDecorator ;
3441import 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
3646import javax .xml .bind .annotation .XmlRootElement ;
3747import javax .xml .bind .annotation .adapters .XmlJavaTypeAdapter ;
48+ import java .util .HashMap ;
49+ import java .util .Map ;
50+ import java .util .Set ;
3851
3952@ XmlRootElement
4053public 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 }
0 commit comments