forked from transmart/Rmodules
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHighDimensionalDataRowMapAdapter.groovy
More file actions
62 lines (54 loc) · 2.42 KB
/
Copy pathHighDimensionalDataRowMapAdapter.groovy
File metadata and controls
62 lines (54 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package jobs.table.columns
import com.google.common.base.Function
import com.google.common.base.Predicate
import com.google.common.collect.ForwardingMap
import com.google.common.collect.ImmutableMap
import com.google.common.collect.Maps
import groovy.transform.CompileStatic
import org.transmartproject.core.dataquery.DataRow
import org.transmartproject.core.dataquery.highdim.AssayColumn
import org.transmartproject.core.dataquery.highdim.BioMarkerDataRow
/**
* Exposes a {@link org.transmartproject.core.dataquery.DataRow} as a
* {@link Map}. The keys are the patient ids, the values are maps with
* a single entry: row label -> value
*/
@CompileStatic
class HighDimensionalDataRowMapAdapter extends ForwardingMap<String, Map<String, Object>> {
Map<String, Map<String, Object>> innerMap
HighDimensionalDataRowMapAdapter(List<AssayColumn> assays,
DataRow<AssayColumn, ?> row,
String contextPrepend = '') {
/* empty cells are dropped!
* In the future we may want to provide a MissingValueAction
* to this class in order to customize this behavior */
Map<String, AssayColumn> patientIdtoAssay =
Maps.uniqueIndex(assays,
{ AssayColumn assay ->
assay.patientInTrialId
} as Function)
Map<String, Map<String, Object> /* one entry */> patientIdToDataValue =
Maps.transformValues patientIdtoAssay,
{ AssayColumn assay ->
def value = row.getAt(assay)
if (value == null) {
return null
}
def bioMarker = (row as BioMarkerDataRow).bioMarker;
if (bioMarker != "" && bioMarker != "null") {
bioMarker = "_" + bioMarker
}
else {
bioMarker = "";
}
ImmutableMap.of(contextPrepend + row.label + bioMarker, value)
} as Function
// drop nulls
innerMap = Maps.filterValues patientIdToDataValue,
{ Object value -> value != null } as Predicate
}
@Override
protected Map<String, Map<String, Object>> delegate() {
innerMap
}
}