Skip to content

Commit b5f1d36

Browse files
committed
Show all classes when compressing data in heat map.
Refs #436
1 parent c424c79 commit b5f1d36

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.baderlab.csplugins.enrichmentmap.model;
22

33
import java.util.ArrayList;
4+
import java.util.LinkedHashSet;
45
import java.util.List;
56
import java.util.Optional;
67

@@ -9,20 +10,37 @@
910
public class CompressedClass implements ExpressionData {
1011

1112
private final ExpressionCache expressionCache;
12-
private List<Pair<EMDataSet, String>> headers = new ArrayList<>();
13+
private List<Pair<EMDataSet,String>> headers = new ArrayList<>();
1314

1415
public CompressedClass(List<EMDataSet> datasets, ExpressionCache expressionCache) {
1516
this.expressionCache = expressionCache;
1617

17-
for (EMDataSet dataset : datasets) {
18+
for(EMDataSet dataset : datasets) {
19+
LinkedHashSet<String> uniquePhenos = new LinkedHashSet<>();
1820
SetOfEnrichmentResults enrichments = dataset.getEnrichments();
21+
22+
// Make sure the chosen classes go first
1923
String pheno1 = enrichments.getPhenotype1();
24+
if(pheno1 != null)
25+
uniquePhenos.add(pheno1);
26+
2027
String pheno2 = enrichments.getPhenotype2();
28+
if(pheno2 != null)
29+
uniquePhenos.add(pheno2);
2130

22-
if (pheno1 != null)
23-
headers.add(Pair.of(dataset, pheno1));
24-
if (pheno2 != null)
25-
headers.add(Pair.of(dataset, pheno2));
31+
// Add the rest of the classes
32+
String[] phenotypes = enrichments.getPhenotypes();
33+
if(phenotypes != null) {
34+
for(String pheno : phenotypes) {
35+
if(pheno != null) {
36+
uniquePhenos.add(pheno);
37+
}
38+
}
39+
}
40+
41+
for(String pheno : uniquePhenos) {
42+
headers.add(Pair.of(dataset, pheno));
43+
}
2644
}
2745
}
2846

@@ -47,22 +65,18 @@ public double getValue(int geneID, int idx, Compress compress, Transform transfo
4765
String pheno = getName(idx);
4866

4967
String[] phenotypes = dataset.getEnrichments().getPhenotypes();
50-
5168
if (phenotypes == null || phenotypes.length == 0)
5269
return Double.NaN;
5370

5471
Optional<float[]> optExpr = expressionCache.getExpressions(geneID, dataset, transform);
55-
5672
if (!optExpr.isPresent())
5773
return Double.NaN;
5874

5975
float[] expressions = optExpr.get();
60-
6176
if (expressions.length == 0 || expressions.length != phenotypes.length)
6277
return Double.NaN;
6378

6479
int size = 0;
65-
6680
for (int i = 0; i < expressions.length; i++) {
6781
if (pheno.equals(phenotypes[i]))
6882
size++;
@@ -80,7 +94,7 @@ public double getValue(int geneID, int idx, Compress compress, Transform transfo
8094
case CLASS_MEDIAN: return GeneExpression.median(vals);
8195
case CLASS_MAX: return GeneExpression.max(vals);
8296
case CLASS_MIN: return GeneExpression.min(vals);
83-
default: return Double.NaN;
97+
default: return Double.NaN;
8498
}
8599
}
86100

0 commit comments

Comments
 (0)