1
1
package org .baderlab .csplugins .enrichmentmap .model ;
2
2
3
3
import java .util .ArrayList ;
4
+ import java .util .LinkedHashSet ;
4
5
import java .util .List ;
5
6
import java .util .Optional ;
6
7
9
10
public class CompressedClass implements ExpressionData {
10
11
11
12
private final ExpressionCache expressionCache ;
12
- private List <Pair <EMDataSet , String >> headers = new ArrayList <>();
13
+ private List <Pair <EMDataSet ,String >> headers = new ArrayList <>();
13
14
14
15
public CompressedClass (List <EMDataSet > datasets , ExpressionCache expressionCache ) {
15
16
this .expressionCache = expressionCache ;
16
17
17
- for (EMDataSet dataset : datasets ) {
18
+ for (EMDataSet dataset : datasets ) {
19
+ LinkedHashSet <String > uniquePhenos = new LinkedHashSet <>();
18
20
SetOfEnrichmentResults enrichments = dataset .getEnrichments ();
21
+
22
+ // Make sure the chosen classes go first
19
23
String pheno1 = enrichments .getPhenotype1 ();
24
+ if (pheno1 != null )
25
+ uniquePhenos .add (pheno1 );
26
+
20
27
String pheno2 = enrichments .getPhenotype2 ();
28
+ if (pheno2 != null )
29
+ uniquePhenos .add (pheno2 );
21
30
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
+ }
26
44
}
27
45
}
28
46
@@ -47,22 +65,18 @@ public double getValue(int geneID, int idx, Compress compress, Transform transfo
47
65
String pheno = getName (idx );
48
66
49
67
String [] phenotypes = dataset .getEnrichments ().getPhenotypes ();
50
-
51
68
if (phenotypes == null || phenotypes .length == 0 )
52
69
return Double .NaN ;
53
70
54
71
Optional <float []> optExpr = expressionCache .getExpressions (geneID , dataset , transform );
55
-
56
72
if (!optExpr .isPresent ())
57
73
return Double .NaN ;
58
74
59
75
float [] expressions = optExpr .get ();
60
-
61
76
if (expressions .length == 0 || expressions .length != phenotypes .length )
62
77
return Double .NaN ;
63
78
64
79
int size = 0 ;
65
-
66
80
for (int i = 0 ; i < expressions .length ; i ++) {
67
81
if (pheno .equals (phenotypes [i ]))
68
82
size ++;
@@ -80,7 +94,7 @@ public double getValue(int geneID, int idx, Compress compress, Transform transfo
80
94
case CLASS_MEDIAN : return GeneExpression .median (vals );
81
95
case CLASS_MAX : return GeneExpression .max (vals );
82
96
case CLASS_MIN : return GeneExpression .min (vals );
83
- default : return Double .NaN ;
97
+ default : return Double .NaN ;
84
98
}
85
99
}
86
100
0 commit comments