Skip to content

Commit d045133

Browse files
committed
Refs #124. One-sided Mann-Whitney test.
1 parent 24919d9 commit d045133

File tree

14 files changed

+437
-77
lines changed

14 files changed

+437
-77
lines changed

EnrichmentMapPlugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
<Bundle-Activator>${bundle.namespace}.enrichmentmap.CyActivator</Bundle-Activator>
185185
<Embed-Dependency>colt;inline=true,commons-math3;inline=true,itext;inline=true</Embed-Dependency>
186186
<Private-Package>${bundle.namespace}.*</Private-Package>
187-
<Export-Package>org.mskcc.*;prefuse.*;version="${project.version}"</Export-Package>
187+
<Export-Package>org.mskcc.*;prefuse.*;org.apache.*;version="${project.version}"</Export-Package>
188188
<Import-Package>*;resolution:=optional</Import-Package>
189189
<_failok>true</_failok>
190190
</instructions>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ public class EnrichmentMapVisualStyle {
113113
public static final String OVERLAP_GENES = "Overlap_genes";
114114
public static final String HYPERGEOM_PVALUE = "Overlap_Hypergeom_pVal";
115115
public static final String HYPERGEOM_CUTOFF = "Overlap_Hypergeom_cutoff";
116-
public static final String MANN_WHIT_PVALUE = "Overlap_Mann_Whit_pVal";
116+
public static final String MANN_WHIT_TWOSIDED_PVALUE = "Overlap_Mann_Whit_pVal";
117+
public static final String MANN_WHIT_GREATER_PVALUE = "Overlap_Mann_Whit_greater_pVal";
118+
public static final String MANN_WHIT_LESS_PVALUE = "Overlap_Mann_Whit_less_pVal";
117119
public static final String MANN_WHIT_CUTOFF = "Overlap_Mann_Whit_cutoff";
118120
public static final String CUTOFF_TYPE = "Overlap_cutoff";
119121
public static final String ENRICHMENT_SET = "ENRICHMENT_SET";

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.EnumMap;
44

5+
import org.baderlab.csplugins.mannwhit.MannWhitneyUTestSided;
6+
57

68

79
/**
@@ -14,11 +16,16 @@ public class FilterParameters {
1416
*/
1517
public enum FilterType {
1618
NO_FILTER("-- no filter --", 0.0),
17-
HYPERGEOM("Hypergeometric Test", 0.05), // MKTODO confirm this default, Ruth opened a bug about this at some point
18-
MANN_WHIT("Mann-Whitney", 0.05),
19+
HYPERGEOM("Hypergeometric Test", 0.05),
20+
MANN_WHIT_TWO_SIDED("Mann-Whitney (Two-Sided)", 0.05),
21+
MANN_WHIT_GREATER("Mann-Whitney (One-Sided Less)", 0.05),
22+
MANN_WHIT_LESS("Mann-Whitney (One-Sided Greater)", 0.05),
1923
NUMBER("Overlap has at least X genes", 5),
2024
PERCENT("Overlap is X percent of EM gs", 25),
2125
SPECIFIC("Overlap is X percent of Sig gs", 25);
26+
27+
// For backwards compatibility
28+
public static final String OLD_MANN_WHIT_LABEL = "Mann-Whitney";
2229

2330
public final String display;
2431
public final double defaultValue;
@@ -32,7 +39,34 @@ public String toString() {
3239
return display;
3340
}
3441

42+
public boolean isMannWhitney() {
43+
switch(this) {
44+
case MANN_WHIT_TWO_SIDED:
45+
case MANN_WHIT_GREATER:
46+
case MANN_WHIT_LESS:
47+
return true;
48+
default:
49+
return false;
50+
}
51+
}
52+
53+
public MannWhitneyUTestSided.Type mannWhitneyTestType() {
54+
switch(this) {
55+
case MANN_WHIT_TWO_SIDED:
56+
return MannWhitneyUTestSided.Type.TWO_SIDED;
57+
case MANN_WHIT_GREATER:
58+
return MannWhitneyUTestSided.Type.GREATER;
59+
case MANN_WHIT_LESS:
60+
return MannWhitneyUTestSided.Type.LESS;
61+
default:
62+
return null;
63+
}
64+
}
65+
3566
public static FilterType fromDisplayString(String val) {
67+
if(OLD_MANN_WHIT_LABEL.equals(val))
68+
return MANN_WHIT_TWO_SIDED;
69+
3670
for(FilterType metric : values()) {
3771
if(metric.display.equals(val)) {
3872
return metric;

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,23 @@ private void calculateAndSetEdgeWidths(CyNetwork network, String prefix, TaskMon
9090
}
9191

9292
Double pvalue, cutoff;
93-
if(filterType == FilterType.MANN_WHIT) {
94-
pvalue = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_PVALUE, Double.class);
93+
switch(filterType) {
94+
case MANN_WHIT_TWO_SIDED:
95+
pvalue = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_TWOSIDED_PVALUE, Double.class);
9596
cutoff = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF, Double.class);
96-
}
97-
else {
97+
break;
98+
case MANN_WHIT_GREATER:
99+
pvalue = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_GREATER_PVALUE, Double.class);
100+
cutoff = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF, Double.class);
101+
break;
102+
case MANN_WHIT_LESS:
103+
pvalue = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_LESS_PVALUE, Double.class);
104+
cutoff = row.get(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF, Double.class);
105+
break;
106+
default:
98107
pvalue = row.get(prefix + EnrichmentMapVisualStyle.HYPERGEOM_PVALUE, Double.class);
99108
cutoff = row.get(prefix + EnrichmentMapVisualStyle.HYPERGEOM_CUTOFF, Double.class);
109+
break;
100110
}
101111

102112
if(pvalue == null || cutoff == null) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/actions/BuildPostAnalysisActionListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import javax.swing.JOptionPane;
5252

5353
import org.baderlab.csplugins.enrichmentmap.EnrichmentMapManager;
54-
import org.baderlab.csplugins.enrichmentmap.FilterParameters.FilterType;
5554
import org.baderlab.csplugins.enrichmentmap.PostAnalysisParameters;
5655
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
5756
import org.baderlab.csplugins.enrichmentmap.task.BuildDiseaseSignatureTask;
@@ -129,8 +128,8 @@ public void runPostAnalysis() {
129128

130129
StringBuilder errorBuilder = new StringBuilder();
131130
paParams.checkMinimalRequirements(errorBuilder);
132-
if(paParams.getRankTestParameters().getType() == FilterType.MANN_WHIT && map.getAllRanks().isEmpty()) {
133-
errorBuilder.append(FilterType.MANN_WHIT.display + " requires ranks. \n");
131+
if(paParams.getRankTestParameters().getType().isMannWhitney() && map.getAllRanks().isEmpty()) {
132+
errorBuilder.append("Mann-Whitney requires ranks. \n");
134133
}
135134
String errors = errorBuilder.toString();
136135

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/autoannotate/task/cluster/ComputeClusterLabelsTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.baderlab.csplugins.enrichmentmap.autoannotate.model.Cluster;
77
import org.cytoscape.model.CyTable;
88
import org.cytoscape.work.AbstractTask;
9-
import org.cytoscape.work.TaskFactory;
109
import org.cytoscape.work.TaskIterator;
1110
import org.cytoscape.work.TaskMonitor;
1211

@@ -34,7 +33,7 @@ public void run(TaskMonitor arg0) throws Exception {
3433

3534
// Generate the labels for the clusters
3635
for (Cluster cluster : annotationSet.getClusterMap().values()) {
37-
currentTasks.append(new UpdateClusterLabelTask(cluster, clusterSetTable));
36+
currentTasks.append(new UpdateClusterLabelTask(cluster, clusterSetTable));
3837
}
3938
AutoAnnotationManager.getInstance().getDialogTaskManager().execute(currentTasks);
4039
}

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public class GenesetSimilarity {
7575
private int hypergeom_m;
7676

7777
// Mann-Whitney U
78-
private double mann_whit_pvalue;
78+
private double mann_whit_pvalue_twoSided;
79+
private double mann_whit_pvalue_greater;
80+
private double mann_whit_pvalue_less;
81+
7982
// flag that indicates if either of the gene sets has no ranks (and therefore we cannot calculated mann-whit
8083
private boolean mann_whit_missing_ranks = false;
8184

@@ -323,31 +326,35 @@ public void setHypergeom_m(int hypergeom_m) {
323326
}
324327

325328

326-
/**
327-
* Get mann whitney p value
328-
* @param null
329-
* @return double mann_whit_pvalue
330-
*/
331-
public double getMann_Whit_pValue() {
332-
return mann_whit_pvalue;
329+
public double getMann_Whit_pValue_twoSided() {
330+
return mann_whit_pvalue_twoSided;
333331
}
334332

333+
public void setMann_Whit_pValue_twoSided(double mann_whit_pvalue) {
334+
this.mann_whit_pvalue_twoSided = mann_whit_pvalue;
335+
}
335336

336-
/**
337-
* Set mann whitney p value
338-
* @param double mann_whit_pvalue
339-
* @return null
340-
*/
341-
public void setMann_Whit_pValue(double mann_whit_pvalue) {
342-
this.mann_whit_pvalue = mann_whit_pvalue;
337+
public double getMann_Whit_pValue_greater() {
338+
return mann_whit_pvalue_greater;
339+
}
340+
341+
public void setMann_Whit_pValue_greater(double mann_whit_pvalue) {
342+
this.mann_whit_pvalue_greater = mann_whit_pvalue;
343+
}
344+
345+
public double getMann_Whit_pValue_less() {
346+
return mann_whit_pvalue_less;
347+
}
348+
349+
public void setMann_Whit_pValue_less(double mann_whit_pvalue) {
350+
this.mann_whit_pvalue_less = mann_whit_pvalue;
343351
}
344352

345353

346354
public boolean isMannWhitMissingRanks() {
347355
return mann_whit_missing_ranks;
348356
}
349357

350-
351358
public void setMannWhitMissingRanks(boolean mann_whit_missing_ranks) {
352359
this.mann_whit_missing_ranks = mann_whit_missing_ranks;
353360
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/BuildDiseaseSignatureTask.java

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import java.util.Map;
5454
import java.util.Set;
5555

56-
import org.apache.commons.math3.stat.inference.MannWhitneyUTest;
5756
import org.baderlab.csplugins.enrichmentmap.EnrichmentMapManager;
5857
import org.baderlab.csplugins.enrichmentmap.EnrichmentMapVisualStyle;
5958
import org.baderlab.csplugins.enrichmentmap.FilterParameters;
@@ -65,6 +64,7 @@
6564
import org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity;
6665
import org.baderlab.csplugins.enrichmentmap.model.Ranking;
6766
import org.baderlab.csplugins.enrichmentmap.util.NetworkUtil;
67+
import org.baderlab.csplugins.mannwhit.MannWhitneyUTestSided;
6868
import org.cytoscape.application.CyApplicationManager;
6969
import org.cytoscape.application.swing.CySwingApplication;
7070
import org.cytoscape.event.CyEventHelper;
@@ -291,12 +291,15 @@ else if (cyNodeAttrs.getRow(nodesMap.get(geneset_name).getSUID()).get(prefix + E
291291
double coeffecient = ComputeSimilarityTask.computeSimilarityCoeffecient(map.getParams(), intersection, union, sigGenes, enrGenes);
292292
GenesetSimilarity comparison = new GenesetSimilarity(hub_name, geneset_name, coeffecient, interaction, intersection);
293293

294-
switch(paParams.getRankTestParameters().getType()) {
294+
FilterType filterType = paParams.getRankTestParameters().getType();
295+
switch(filterType) {
295296
case HYPERGEOM:
296297
int universeSize1 = paParams.getUniverseSize();
297298
hypergeometric(universeSize1, sigGenesInUniverse, enrGenes, intersection, comparison);
298299
break;
299-
case MANN_WHIT:
300+
case MANN_WHIT_TWO_SIDED:
301+
case MANN_WHIT_GREATER:
302+
case MANN_WHIT_LESS:
300303
mannWhitney(intersection, comparison);
301304
default: // want mann-whit to fall through
302305
int universeSize2 = map.getNumberOfGenes(); // #70 calculate hypergeometric also
@@ -364,8 +367,12 @@ private boolean passesCutoff(String edge_name) {
364367
switch(filterParams.getType()) {
365368
case HYPERGEOM:
366369
return similarity.getHypergeom_pvalue() <= filterParams.getValue(FilterType.HYPERGEOM);
367-
case MANN_WHIT:
368-
return !similarity.isMannWhitMissingRanks() && similarity.getMann_Whit_pValue() <= filterParams.getValue(FilterType.MANN_WHIT);
370+
case MANN_WHIT_TWO_SIDED:
371+
return !similarity.isMannWhitMissingRanks() && similarity.getMann_Whit_pValue_twoSided() <= filterParams.getValue(FilterType.MANN_WHIT_TWO_SIDED);
372+
case MANN_WHIT_GREATER:
373+
return !similarity.isMannWhitMissingRanks() && similarity.getMann_Whit_pValue_greater() <= filterParams.getValue(FilterType.MANN_WHIT_GREATER);
374+
case MANN_WHIT_LESS:
375+
return !similarity.isMannWhitMissingRanks() && similarity.getMann_Whit_pValue_less() <= filterParams.getValue(FilterType.MANN_WHIT_LESS);
369376
case NUMBER:
370377
return similarity.getSizeOfOverlap() >= filterParams.getValue(FilterType.NUMBER);
371378
case PERCENT:
@@ -518,21 +525,22 @@ private void createEdge(String edge_name, CyNetwork current_network, CyNetworkVi
518525
if(passed_cutoff)
519526
current_edgerow.set(prefix + EnrichmentMapVisualStyle.CUTOFF_TYPE, paParams.getRankTestParameters().getType().display);
520527

521-
// Attributes related to the Hypergeometric Test
522-
switch(paParams.getRankTestParameters().getType()) {
523-
case MANN_WHIT:
524-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.MANN_WHIT_PVALUE, genesetSimilarity.getMann_Whit_pValue());
525-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF, paParams.getRankTestParameters().getValue(FilterType.MANN_WHIT));
526-
// want to fall through to the HYERGEOM case
527-
default:
528-
case HYPERGEOM:
529-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_PVALUE, genesetSimilarity.getHypergeom_pvalue());
530-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_N, genesetSimilarity.getHypergeom_N());
531-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_n, genesetSimilarity.getHypergeom_n());
532-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_m, genesetSimilarity.getHypergeom_m());
533-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_k, genesetSimilarity.getHypergeom_k());
534-
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_CUTOFF, paParams.getRankTestParameters().getValue(FilterType.HYPERGEOM));
528+
FilterType filterType = paParams.getRankTestParameters().getType();
529+
530+
if(filterType.isMannWhitney()) {
531+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.MANN_WHIT_TWOSIDED_PVALUE, genesetSimilarity.getMann_Whit_pValue_twoSided());
532+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.MANN_WHIT_GREATER_PVALUE, genesetSimilarity.getMann_Whit_pValue_greater());
533+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.MANN_WHIT_LESS_PVALUE, genesetSimilarity.getMann_Whit_pValue_less());
534+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF, paParams.getRankTestParameters().getValue(filterType));
535535
}
536+
537+
// always calculate hypergeometric
538+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_PVALUE, genesetSimilarity.getHypergeom_pvalue());
539+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_N, genesetSimilarity.getHypergeom_N());
540+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_n, genesetSimilarity.getHypergeom_n());
541+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_m, genesetSimilarity.getHypergeom_m());
542+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_k, genesetSimilarity.getHypergeom_k());
543+
current_edgerow.set(prefix + EnrichmentMapVisualStyle.HYPERGEOM_CUTOFF, paParams.getRankTestParameters().getValue(FilterType.HYPERGEOM));
536544
}
537545

538546

@@ -563,7 +571,9 @@ private void hypergeometric(int universeSize,
563571
private void mannWhitney(Set<Integer> intersection, GenesetSimilarity comparison) {
564572
Map<Integer, Double> gene2score = ranks.getGene2Score();
565573
if (gene2score == null || gene2score.isEmpty()) {
566-
comparison.setMann_Whit_pValue(1.5);
574+
comparison.setMann_Whit_pValue_twoSided(1.5);
575+
comparison.setMann_Whit_pValue_greater(1.5);
576+
comparison.setMann_Whit_pValue_less(1.5);
567577
comparison.setMannWhitMissingRanks(true);
568578
} else {
569579
// Calculate Mann-Whitney U pValue for Overlap
@@ -582,13 +592,20 @@ private void mannWhitney(Set<Integer> intersection, GenesetSimilarity comparison
582592
double[] scores = ranks.getScores();
583593

584594
if(scores.length == 0 || overlap_gene_scores.length == 0) {
585-
comparison.setMann_Whit_pValue(1.5); // avoid NoDataException
595+
comparison.setMann_Whit_pValue_twoSided(1.5); // avoid NoDataException
596+
comparison.setMann_Whit_pValue_greater(1.5);
597+
comparison.setMann_Whit_pValue_less(1.5);
586598
comparison.setMannWhitMissingRanks(true);
587599
}
588600
else {
589-
MannWhitneyUTest mann_whit = new MannWhitneyUTest();
590-
double mannPval = mann_whit.mannWhitneyUTest(overlap_gene_scores, scores);
591-
comparison.setMann_Whit_pValue(mannPval);
601+
// MKTODO could modify MannWHitneyUTestSided to return all three values from one call
602+
MannWhitneyUTestSided mann_whit = new MannWhitneyUTestSided();
603+
double mannPvalTwoSided = mann_whit.mannWhitneyUTest(overlap_gene_scores, scores, MannWhitneyUTestSided.Type.TWO_SIDED);
604+
comparison.setMann_Whit_pValue_twoSided(mannPvalTwoSided);
605+
double mannPvalGreater = mann_whit.mannWhitneyUTest(overlap_gene_scores, scores, MannWhitneyUTestSided.Type.GREATER);
606+
comparison.setMann_Whit_pValue_greater(mannPvalGreater);
607+
double mannPvalLess = mann_whit.mannWhitneyUTest(overlap_gene_scores, scores, MannWhitneyUTestSided.Type.LESS);
608+
comparison.setMann_Whit_pValue_less(mannPvalLess);
592609
}
593610
}
594611
}
@@ -643,8 +660,13 @@ private CyTable createEdgeAttributes(CyNetwork network, String name, String pref
643660
if(edgeTable.getColumn(prefix + EnrichmentMapVisualStyle.HYPERGEOM_CUTOFF) == null)
644661
edgeTable.createColumn(prefix + EnrichmentMapVisualStyle.HYPERGEOM_CUTOFF , Double.class, false);
645662

646-
if(edgeTable.getColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_PVALUE) == null)
647-
edgeTable.createColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_PVALUE , Double.class, false);
663+
if(edgeTable.getColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_TWOSIDED_PVALUE) == null)
664+
edgeTable.createColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_TWOSIDED_PVALUE , Double.class, false);
665+
if(edgeTable.getColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_GREATER_PVALUE) == null)
666+
edgeTable.createColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_GREATER_PVALUE , Double.class, false);
667+
if(edgeTable.getColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_LESS_PVALUE) == null)
668+
edgeTable.createColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_LESS_PVALUE , Double.class, false);
669+
648670
if(edgeTable.getColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF) == null)
649671
edgeTable.createColumn(prefix + EnrichmentMapVisualStyle.MANN_WHIT_CUTOFF , Double.class, false);
650672

0 commit comments

Comments
 (0)