4740 |
05 Feb 09 |
nicklas |
1 |
/** |
4740 |
05 Feb 09 |
nicklas |
$Id$ |
4740 |
05 Feb 09 |
nicklas |
3 |
|
4740 |
05 Feb 09 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4740 |
05 Feb 09 |
nicklas |
5 |
|
4740 |
05 Feb 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4740 |
05 Feb 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4740 |
05 Feb 09 |
nicklas |
8 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4740 |
05 Feb 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4740 |
05 Feb 09 |
nicklas |
of the License, or (at your option) any later version. |
4740 |
05 Feb 09 |
nicklas |
13 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4740 |
05 Feb 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4740 |
05 Feb 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4740 |
05 Feb 09 |
nicklas |
GNU General Public License for more details. |
4740 |
05 Feb 09 |
nicklas |
18 |
|
4740 |
05 Feb 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4740 |
05 Feb 09 |
nicklas |
21 |
*/ |
4740 |
05 Feb 09 |
nicklas |
22 |
package net.sf.basedb.util.overview.validator; |
4740 |
05 Feb 09 |
nicklas |
23 |
|
6098 |
03 Sep 12 |
nicklas |
24 |
import java.util.List; |
6098 |
03 Sep 12 |
nicklas |
25 |
|
5076 |
25 Aug 09 |
nicklas |
26 |
import net.sf.basedb.core.ArrayDesign; |
6959 |
01 Oct 15 |
nicklas |
27 |
import net.sf.basedb.core.BasicItem; |
4740 |
05 Feb 09 |
nicklas |
28 |
import net.sf.basedb.core.DbControl; |
5652 |
10 Jun 11 |
nicklas |
29 |
import net.sf.basedb.core.DerivedBioAssay; |
5807 |
14 Oct 11 |
nicklas |
30 |
import net.sf.basedb.core.Extract; |
6959 |
01 Oct 15 |
nicklas |
31 |
import net.sf.basedb.core.Nameable; |
5807 |
14 Oct 11 |
nicklas |
32 |
import net.sf.basedb.core.PermissionDeniedException; |
5807 |
14 Oct 11 |
nicklas |
33 |
import net.sf.basedb.core.PhysicalBioAssay; |
4740 |
05 Feb 09 |
nicklas |
34 |
import net.sf.basedb.core.Project; |
4740 |
05 Feb 09 |
nicklas |
35 |
import net.sf.basedb.core.RawBioAssay; |
4740 |
05 Feb 09 |
nicklas |
36 |
import net.sf.basedb.core.RawDataType; |
6959 |
01 Oct 15 |
nicklas |
37 |
import net.sf.basedb.core.RootRawBioAssay; |
5076 |
25 Aug 09 |
nicklas |
38 |
import net.sf.basedb.util.Values; |
4740 |
05 Feb 09 |
nicklas |
39 |
import net.sf.basedb.util.overview.Fix; |
4740 |
05 Feb 09 |
nicklas |
40 |
import net.sf.basedb.util.overview.OverviewContext; |
4740 |
05 Feb 09 |
nicklas |
41 |
import net.sf.basedb.util.overview.Validator; |
4740 |
05 Feb 09 |
nicklas |
42 |
import net.sf.basedb.util.overview.Node; |
6047 |
18 Apr 12 |
nicklas |
43 |
import net.sf.basedb.util.overview.extensions.ValidationRuleAction; |
4740 |
05 Feb 09 |
nicklas |
44 |
|
4740 |
05 Feb 09 |
nicklas |
45 |
/** |
6959 |
01 Oct 15 |
nicklas |
Validator implementation for raw bioassays and root raw bioassays. |
6959 |
01 Oct 15 |
nicklas |
Validation rules: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
4740 |
05 Feb 09 |
nicklas |
<li>Non-default raw data type: {@link Validator#NONDEFAULT_RAWDATATYPE} |
5807 |
14 Oct 11 |
nicklas |
<li>Parent extract mismatch: {@link Validator#PARENT_EXTRACT_MISMATCH} |
5076 |
25 Aug 09 |
nicklas |
<li>The number of raw data spots is different from the number of |
5076 |
25 Aug 09 |
nicklas |
features on the array design: {@link Validator#NONMATCHING_SPOTCOUNT}. |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
54 |
|
4740 |
05 Feb 09 |
nicklas |
@author Nicklas |
4740 |
05 Feb 09 |
nicklas |
@version 2.10 |
4740 |
05 Feb 09 |
nicklas |
@base.modified $Date$ |
4740 |
05 Feb 09 |
nicklas |
58 |
*/ |
4740 |
05 Feb 09 |
nicklas |
59 |
public class RawBioAssayValidator |
6959 |
01 Oct 15 |
nicklas |
60 |
extends NameableNodeValidator<Nameable> |
4740 |
05 Feb 09 |
nicklas |
61 |
{ |
4740 |
05 Feb 09 |
nicklas |
62 |
|
4740 |
05 Feb 09 |
nicklas |
63 |
public RawBioAssayValidator() |
4740 |
05 Feb 09 |
nicklas |
64 |
{ |
4740 |
05 Feb 09 |
nicklas |
65 |
super(null, null); |
4740 |
05 Feb 09 |
nicklas |
66 |
} |
4740 |
05 Feb 09 |
nicklas |
67 |
|
4740 |
05 Feb 09 |
nicklas |
68 |
/* |
4740 |
05 Feb 09 |
nicklas |
From BasicValidator class |
4740 |
05 Feb 09 |
nicklas |
70 |
------------------------- |
4740 |
05 Feb 09 |
nicklas |
71 |
*/ |
4740 |
05 Feb 09 |
nicklas |
72 |
@Override |
4740 |
05 Feb 09 |
nicklas |
73 |
public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
74 |
{ |
4740 |
05 Feb 09 |
nicklas |
75 |
super.postValidate(dc, context, node, parentNode); |
4740 |
05 Feb 09 |
nicklas |
76 |
|
5807 |
14 Oct 11 |
nicklas |
// Check raw data type against default raw data type |
4740 |
05 Feb 09 |
nicklas |
78 |
Project project = context.getProject(); |
6959 |
01 Oct 15 |
nicklas |
79 |
BasicItem item = node.getItem(dc); |
6959 |
01 Oct 15 |
nicklas |
80 |
if (item instanceof RootRawBioAssay) |
6959 |
01 Oct 15 |
nicklas |
81 |
{ |
6959 |
01 Oct 15 |
nicklas |
// The parent may be a root raw bioasay if the overview starts at the |
6959 |
01 Oct 15 |
nicklas |
// experiment level |
6959 |
01 Oct 15 |
nicklas |
84 |
item = ((RootRawBioAssay)item).getRawBioAssay(); |
6959 |
01 Oct 15 |
nicklas |
85 |
} |
6959 |
01 Oct 15 |
nicklas |
86 |
RawBioAssay rba = (RawBioAssay)item; |
4740 |
05 Feb 09 |
nicklas |
87 |
if (project != null) |
4740 |
05 Feb 09 |
nicklas |
88 |
{ |
4816 |
16 Mar 09 |
martin |
89 |
project = Project.getById(dc, project.getId()); |
4740 |
05 Feb 09 |
nicklas |
90 |
RawDataType projectDefault = project.getDefaultRawDataType(); |
4740 |
05 Feb 09 |
nicklas |
91 |
if (projectDefault != null && rba.getRawDataType() != projectDefault) |
4740 |
05 Feb 09 |
nicklas |
92 |
{ |
4740 |
05 Feb 09 |
nicklas |
93 |
context.createFailure(Validator.NONDEFAULT_RAWDATATYPE, node, null, |
4740 |
05 Feb 09 |
nicklas |
94 |
new Fix("Change default raw data type of project", project) |
4740 |
05 Feb 09 |
nicklas |
95 |
); |
4740 |
05 Feb 09 |
nicklas |
96 |
} |
4740 |
05 Feb 09 |
nicklas |
97 |
} |
4740 |
05 Feb 09 |
nicklas |
98 |
|
5807 |
14 Oct 11 |
nicklas |
// Check that parent items make sense |
6098 |
03 Sep 12 |
nicklas |
100 |
Extract parentExtract = null; |
5807 |
14 Oct 11 |
nicklas |
101 |
DerivedBioAssay parentBioAssay = null; |
5807 |
14 Oct 11 |
nicklas |
102 |
Extract parentBioAssayExtract = null; |
6098 |
03 Sep 12 |
nicklas |
103 |
List<PhysicalBioAssay> physicalBioAssays = null; |
5807 |
14 Oct 11 |
nicklas |
104 |
try |
5807 |
14 Oct 11 |
nicklas |
105 |
{ |
5807 |
14 Oct 11 |
nicklas |
106 |
parentBioAssay = rba.getParentBioAssay(); |
5807 |
14 Oct 11 |
nicklas |
107 |
parentExtract = rba.getParentExtract(); |
6098 |
03 Sep 12 |
nicklas |
108 |
if (parentBioAssay != null && parentExtract != null) |
5807 |
14 Oct 11 |
nicklas |
109 |
{ |
6098 |
03 Sep 12 |
nicklas |
110 |
physicalBioAssays = PhysicalBioAssayValidator.getPhysicalBioAssays(dc, context, parentBioAssay); |
5807 |
14 Oct 11 |
nicklas |
111 |
parentBioAssayExtract = parentBioAssay.getExtract(); |
5807 |
14 Oct 11 |
nicklas |
112 |
} |
5807 |
14 Oct 11 |
nicklas |
113 |
} |
5807 |
14 Oct 11 |
nicklas |
114 |
catch (PermissionDeniedException ex) |
5807 |
14 Oct 11 |
nicklas |
115 |
{} |
4759 |
13 Feb 09 |
nicklas |
116 |
|
6098 |
03 Sep 12 |
nicklas |
// Check that the extract is found on among the parents for at least on of the physical bioassays |
6098 |
03 Sep 12 |
nicklas |
118 |
if (parentExtract != null && physicalBioAssays != null && physicalBioAssays.size() > 0) |
5807 |
14 Oct 11 |
nicklas |
119 |
{ |
6098 |
03 Sep 12 |
nicklas |
120 |
boolean found = false; |
6098 |
03 Sep 12 |
nicklas |
121 |
for (PhysicalBioAssay pba : physicalBioAssays) |
5807 |
14 Oct 11 |
nicklas |
122 |
{ |
6098 |
03 Sep 12 |
nicklas |
123 |
if (PhysicalBioAssayValidator.getAllParentExtracts(dc, context, pba).contains(parentExtract)) |
6098 |
03 Sep 12 |
nicklas |
124 |
{ |
6098 |
03 Sep 12 |
nicklas |
125 |
found = true; |
6098 |
03 Sep 12 |
nicklas |
126 |
break; |
6098 |
03 Sep 12 |
nicklas |
127 |
} |
5807 |
14 Oct 11 |
nicklas |
128 |
} |
6098 |
03 Sep 12 |
nicklas |
129 |
|
6098 |
03 Sep 12 |
nicklas |
130 |
if (!found) |
6098 |
03 Sep 12 |
nicklas |
131 |
{ |
6098 |
03 Sep 12 |
nicklas |
132 |
if (physicalBioAssays.size() == 1) |
6098 |
03 Sep 12 |
nicklas |
133 |
{ |
6098 |
03 Sep 12 |
nicklas |
134 |
PhysicalBioAssay pba = physicalBioAssays.get(0); |
6098 |
03 Sep 12 |
nicklas |
135 |
context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, |
6098 |
03 Sep 12 |
nicklas |
136 |
"The extract '" + parentExtract.getName() + "' is not a parent to the physical bioassay: " + |
6098 |
03 Sep 12 |
nicklas |
137 |
pba.getName(), |
6098 |
03 Sep 12 |
nicklas |
138 |
new Fix("Change extract or parent bioassay on raw bioassay", rba), |
6098 |
03 Sep 12 |
nicklas |
139 |
new Fix("Change extracts on physical bioassay", pba) |
6098 |
03 Sep 12 |
nicklas |
140 |
); |
6098 |
03 Sep 12 |
nicklas |
141 |
} |
6098 |
03 Sep 12 |
nicklas |
142 |
else |
6098 |
03 Sep 12 |
nicklas |
143 |
{ |
6098 |
03 Sep 12 |
nicklas |
144 |
context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, |
6098 |
03 Sep 12 |
nicklas |
145 |
"The extract '" + parentExtract.getName() + "' is not a parent to any of the physical bioassays", |
6098 |
03 Sep 12 |
nicklas |
146 |
new Fix("Change extract or parent bioassay on raw bioassay", rba) |
6098 |
03 Sep 12 |
nicklas |
147 |
); |
6098 |
03 Sep 12 |
nicklas |
148 |
} |
6098 |
03 Sep 12 |
nicklas |
149 |
} |
5807 |
14 Oct 11 |
nicklas |
150 |
} |
5807 |
14 Oct 11 |
nicklas |
151 |
|
6098 |
03 Sep 12 |
nicklas |
// Check that extract is related to the extract on the parent derived bioassay |
6098 |
03 Sep 12 |
nicklas |
153 |
if (parentExtract != null && parentBioAssayExtract != null) |
5807 |
14 Oct 11 |
nicklas |
154 |
{ |
6098 |
03 Sep 12 |
nicklas |
155 |
if (!ExtractValidator.isRelated(dc, context, parentExtract, parentBioAssayExtract) && !ExtractValidator.isRelated(dc, context, parentBioAssayExtract, parentExtract)) |
5807 |
14 Oct 11 |
nicklas |
156 |
{ |
5807 |
14 Oct 11 |
nicklas |
157 |
context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, |
6098 |
03 Sep 12 |
nicklas |
158 |
"The parent bioassay '" + parentBioAssay.getName() + "' has unrelated extract: " + |
6098 |
03 Sep 12 |
nicklas |
159 |
parentBioAssayExtract.getName(), |
6098 |
03 Sep 12 |
nicklas |
160 |
new Fix("Change extract on raw bioassay", rba), |
6098 |
03 Sep 12 |
nicklas |
161 |
new Fix("Change extract on parent bioassay", parentBioAssay) |
5807 |
14 Oct 11 |
nicklas |
162 |
); |
5807 |
14 Oct 11 |
nicklas |
163 |
} |
5807 |
14 Oct 11 |
nicklas |
164 |
} |
6098 |
03 Sep 12 |
nicklas |
165 |
|
5813 |
18 Oct 11 |
nicklas |
166 |
|
5076 |
25 Aug 09 |
nicklas |
167 |
if (rba.hasArrayDesign() && rba.hasData()) |
5076 |
25 Aug 09 |
nicklas |
168 |
{ |
5076 |
25 Aug 09 |
nicklas |
169 |
try |
5076 |
25 Aug 09 |
nicklas |
170 |
{ |
5076 |
25 Aug 09 |
nicklas |
171 |
ArrayDesign design = rba.getArrayDesign(); |
5076 |
25 Aug 09 |
nicklas |
172 |
String threshold = context.getValidationOptions().getOption( |
6047 |
18 Apr 12 |
nicklas |
173 |
(ValidationRuleAction)Validator.NONMATCHING_SPOTCOUNT, "threshold", "5%"); |
5076 |
25 Aug 09 |
nicklas |
174 |
|
5076 |
25 Aug 09 |
nicklas |
175 |
int numDbSpots = rba.getNumDbSpots(); |
5076 |
25 Aug 09 |
nicklas |
176 |
int numDbFeatures = design.getNumDbFeatures(); |
5076 |
25 Aug 09 |
nicklas |
177 |
int numFileSpots = rba.getNumFileSpots(); |
5076 |
25 Aug 09 |
nicklas |
178 |
int numFileFeatures = design.getNumFileFeatures(); |
5076 |
25 Aug 09 |
nicklas |
179 |
int maxDbDelta = 0; |
5076 |
25 Aug 09 |
nicklas |
180 |
int maxFileDelta = 0; |
5076 |
25 Aug 09 |
nicklas |
181 |
if (threshold.endsWith("%")) |
5076 |
25 Aug 09 |
nicklas |
182 |
{ |
5076 |
25 Aug 09 |
nicklas |
183 |
int percentage = Values.getInt(threshold.substring(0, threshold.length()-1)); |
5076 |
25 Aug 09 |
nicklas |
184 |
if (numDbFeatures > 0) maxDbDelta = (numDbFeatures * percentage) / 100; |
5076 |
25 Aug 09 |
nicklas |
185 |
if (numFileFeatures > 0) maxFileDelta = (numFileFeatures * percentage) / 100; |
5076 |
25 Aug 09 |
nicklas |
186 |
} |
5076 |
25 Aug 09 |
nicklas |
187 |
else |
5076 |
25 Aug 09 |
nicklas |
188 |
{ |
5076 |
25 Aug 09 |
nicklas |
189 |
maxDbDelta = Values.getInt(threshold); |
5076 |
25 Aug 09 |
nicklas |
190 |
maxFileDelta = maxDbDelta; |
5076 |
25 Aug 09 |
nicklas |
191 |
} |
5076 |
25 Aug 09 |
nicklas |
192 |
|
5076 |
25 Aug 09 |
nicklas |
193 |
|
5076 |
25 Aug 09 |
nicklas |
194 |
if (numDbSpots > 0 && Math.abs(numDbFeatures - numDbSpots) > maxDbDelta) |
5076 |
25 Aug 09 |
nicklas |
195 |
{ |
5076 |
25 Aug 09 |
nicklas |
196 |
context.createFailure(Validator.NONMATCHING_SPOTCOUNT, node, |
5076 |
25 Aug 09 |
nicklas |
197 |
"Raw spots (db) <> features by more than " + threshold + ": " + |
5076 |
25 Aug 09 |
nicklas |
198 |
numDbSpots + "<>" + numDbFeatures); |
5076 |
25 Aug 09 |
nicklas |
199 |
} |
5076 |
25 Aug 09 |
nicklas |
200 |
if (numFileSpots > 0 && Math.abs(numFileFeatures - numFileSpots) > maxFileDelta) |
5076 |
25 Aug 09 |
nicklas |
201 |
{ |
5076 |
25 Aug 09 |
nicklas |
202 |
context.createFailure(Validator.NONMATCHING_SPOTCOUNT, node, |
5076 |
25 Aug 09 |
nicklas |
203 |
"Raw spots (file) <> features by more than " + threshold + ": " + |
5076 |
25 Aug 09 |
nicklas |
204 |
numFileSpots + "<>" + numFileFeatures); |
5076 |
25 Aug 09 |
nicklas |
205 |
} |
5076 |
25 Aug 09 |
nicklas |
206 |
|
5076 |
25 Aug 09 |
nicklas |
207 |
} |
5384 |
13 Aug 10 |
nicklas |
208 |
catch (RuntimeException ex) |
5076 |
25 Aug 09 |
nicklas |
209 |
{} |
5076 |
25 Aug 09 |
nicklas |
210 |
} |
4740 |
05 Feb 09 |
nicklas |
211 |
} |
4740 |
05 Feb 09 |
nicklas |
212 |
|
4740 |
05 Feb 09 |
nicklas |
213 |
/** |
4740 |
05 Feb 09 |
nicklas |
@return Always null |
4740 |
05 Feb 09 |
nicklas |
215 |
*/ |
4740 |
05 Feb 09 |
nicklas |
216 |
@Override |
5651 |
08 Jun 11 |
nicklas |
217 |
protected Fix getMissingItemFix(DbControl dc, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
218 |
{ |
4740 |
05 Feb 09 |
nicklas |
219 |
return null; |
4740 |
05 Feb 09 |
nicklas |
220 |
} |
4740 |
05 Feb 09 |
nicklas |
221 |
// ---------------------------- |
4740 |
05 Feb 09 |
nicklas |
222 |
} |