19
19
package ubic .gemma .core .analysis .service ;
20
20
21
21
import cern .colt .list .DoubleArrayList ;
22
+ import lombok .extern .apachecommons .CommonsLog ;
22
23
import org .apache .commons .lang3 .ArrayUtils ;
23
24
import org .springframework .beans .factory .annotation .Autowired ;
24
25
import org .springframework .stereotype .Component ;
26
+ import org .springframework .transaction .annotation .Transactional ;
25
27
import ubic .basecode .dataStructure .matrix .DenseDoubleMatrix ;
26
28
import ubic .basecode .dataStructure .matrix .DoubleMatrix ;
27
29
import ubic .basecode .math .DescriptiveWithMissing ;
28
30
import ubic .gemma .core .analysis .preprocess .filter .ExpressionExperimentFilter ;
29
31
import ubic .gemma .core .analysis .preprocess .filter .FilterConfig ;
30
32
import ubic .gemma .core .datastructure .matrix .ExpressionDataDoubleMatrix ;
33
+ import ubic .gemma .model .common .quantitationtype .QuantitationType ;
31
34
import ubic .gemma .model .expression .arrayDesign .ArrayDesign ;
32
35
import ubic .gemma .model .expression .bioAssayData .ProcessedExpressionDataVector ;
36
+ import ubic .gemma .model .expression .bioAssayData .RawExpressionDataVector ;
33
37
import ubic .gemma .model .expression .experiment .ExpressionExperiment ;
34
38
import ubic .gemma .model .genome .Gene ;
35
39
import ubic .gemma .persistence .service .expression .arrayDesign .ArrayDesignService ;
36
40
import ubic .gemma .persistence .service .expression .bioAssayData .ProcessedExpressionDataVectorDao ;
37
41
import ubic .gemma .persistence .service .expression .bioAssayData .ProcessedExpressionDataVectorService ;
42
+ import ubic .gemma .persistence .service .expression .bioAssayData .RawExpressionDataVectorService ;
38
43
import ubic .gemma .persistence .service .expression .experiment .ExpressionExperimentService ;
39
44
40
- import java .util .ArrayList ;
41
- import java .util .Collection ;
42
- import java .util .HashSet ;
43
- import java .util .Map ;
45
+ import java .util .*;
46
+ import java .util .stream .Collectors ;
44
47
45
48
/**
46
49
* Tools for easily getting data matrices for analysis in a consistent way.
47
50
*
48
51
* @author keshav
49
52
*/
50
53
@ Component
54
+ @ CommonsLog
51
55
public class ExpressionDataMatrixServiceImpl implements ExpressionDataMatrixService {
52
56
53
57
@ Autowired
@@ -56,6 +60,9 @@ public class ExpressionDataMatrixServiceImpl implements ExpressionDataMatrixServ
56
60
@ Autowired
57
61
private ProcessedExpressionDataVectorService processedExpressionDataVectorService ;
58
62
63
+ @ Autowired
64
+ private RawExpressionDataVectorService rawExpressionDataVectorService ;
65
+
59
66
@ Autowired
60
67
private ArrayDesignService arrayDesignService ;
61
68
@@ -97,6 +104,32 @@ public ExpressionDataDoubleMatrix getProcessedExpressionDataMatrix( ExpressionEx
97
104
return new ExpressionDataDoubleMatrix ( dataVectors );
98
105
}
99
106
107
+ @ Override
108
+ @ Transactional (readOnly = true )
109
+ public ExpressionDataDoubleMatrix getRawExpressionDataMatrix ( ExpressionExperiment ee ) {
110
+ Map <QuantitationType , List <RawExpressionDataVector >> rawVectorsByQt = ee .getRawExpressionDataVectors ().stream ()
111
+ .collect ( Collectors .groupingBy ( RawExpressionDataVector ::getQuantitationType , Collectors .toList () ) );
112
+
113
+ Set <QuantitationType > preferredQuantitationTypes = rawVectorsByQt .keySet ().stream ()
114
+ .filter ( QuantitationType ::getIsPreferred )
115
+ .collect ( Collectors .toSet () );
116
+
117
+ if ( preferredQuantitationTypes .isEmpty () ) {
118
+ throw new IllegalArgumentException ( "There are no RawExpressionDataVectors for " + ee + ", they must be created first." );
119
+ }
120
+
121
+ if ( preferredQuantitationTypes .size () > 1 ) {
122
+ log .warn ( "There are more than one preferred quantitation type for " + ee + " raw expression vectors." );
123
+ }
124
+
125
+ // pick the QT with the maximum ID, which should be the latest one created
126
+ QuantitationType pickedQuantitationType = preferredQuantitationTypes .stream ()
127
+ .max ( Comparator .comparing ( QuantitationType ::getId ) )
128
+ .orElse ( null );
129
+
130
+ return new ExpressionDataDoubleMatrix ( rawVectorsByQt .get ( pickedQuantitationType ) );
131
+ }
132
+
100
133
@ Override
101
134
public DoubleMatrix <Gene , ExpressionExperiment > getRankMatrix ( Collection <Gene > genes ,
102
135
Collection <ExpressionExperiment > ees , ProcessedExpressionDataVectorDao .RankMethod method ) {
0 commit comments