5277 |
22 Mar 10 |
nicklas |
1 |
/** |
5277 |
22 Mar 10 |
nicklas |
$Id $ |
5277 |
22 Mar 10 |
nicklas |
3 |
|
5277 |
22 Mar 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5277 |
22 Mar 10 |
nicklas |
5 |
|
5277 |
22 Mar 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5277 |
22 Mar 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5277 |
22 Mar 10 |
nicklas |
8 |
|
5277 |
22 Mar 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5277 |
22 Mar 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5277 |
22 Mar 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5277 |
22 Mar 10 |
nicklas |
of the License, or (at your option) any later version. |
5277 |
22 Mar 10 |
nicklas |
13 |
|
5277 |
22 Mar 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5277 |
22 Mar 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5277 |
22 Mar 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5277 |
22 Mar 10 |
nicklas |
GNU General Public License for more details. |
5277 |
22 Mar 10 |
nicklas |
18 |
|
5277 |
22 Mar 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5277 |
22 Mar 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5277 |
22 Mar 10 |
nicklas |
21 |
*/ |
5277 |
22 Mar 10 |
nicklas |
22 |
package net.sf.basedb.util.export.spotdata; |
5277 |
22 Mar 10 |
nicklas |
23 |
|
5277 |
22 Mar 10 |
nicklas |
24 |
import net.sf.basedb.core.BioAssaySet; |
5277 |
22 Mar 10 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
5277 |
22 Mar 10 |
nicklas |
26 |
import net.sf.basedb.core.ItemNotFoundException; |
5277 |
22 Mar 10 |
nicklas |
27 |
import net.sf.basedb.core.ExtraValue.CoordinateType; |
5277 |
22 Mar 10 |
nicklas |
28 |
|
5277 |
22 Mar 10 |
nicklas |
29 |
|
5277 |
22 Mar 10 |
nicklas |
30 |
/** |
5277 |
22 Mar 10 |
nicklas |
Default field converter implementation that works mainly by |
5277 |
22 Mar 10 |
nicklas |
checking names and/or external id values of formulas, extra |
5277 |
22 Mar 10 |
nicklas |
values, experimental factors etc. |
5277 |
22 Mar 10 |
nicklas |
34 |
|
5277 |
22 Mar 10 |
nicklas |
@author nicklas |
5277 |
22 Mar 10 |
nicklas |
@since 2.15 |
5277 |
22 Mar 10 |
nicklas |
37 |
*/ |
5277 |
22 Mar 10 |
nicklas |
38 |
public class StandardFieldConverter |
5277 |
22 Mar 10 |
nicklas |
39 |
extends AbstractFieldConverter |
5277 |
22 Mar 10 |
nicklas |
40 |
{ |
5277 |
22 Mar 10 |
nicklas |
41 |
|
5277 |
22 Mar 10 |
nicklas |
42 |
/** |
5277 |
22 Mar 10 |
nicklas |
Create a new standard field converter. |
5277 |
22 Mar 10 |
nicklas |
@param dc A DbControl to use for database access |
5277 |
22 Mar 10 |
nicklas |
@param source The source bioassay set |
5277 |
22 Mar 10 |
nicklas |
46 |
*/ |
5277 |
22 Mar 10 |
nicklas |
47 |
public StandardFieldConverter(DbControl dc, BioAssaySet source) |
5277 |
22 Mar 10 |
nicklas |
48 |
{ |
5277 |
22 Mar 10 |
nicklas |
49 |
super(dc, source); |
5277 |
22 Mar 10 |
nicklas |
50 |
} |
5277 |
22 Mar 10 |
nicklas |
51 |
|
5277 |
22 Mar 10 |
nicklas |
52 |
/** |
5277 |
22 Mar 10 |
nicklas |
Find an assay field. This method will try to locate a field |
5277 |
22 Mar 10 |
nicklas |
in the following order: |
5277 |
22 Mar 10 |
nicklas |
55 |
|
5277 |
22 Mar 10 |
nicklas |
<ol> |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is an experimental factor with the given name |
5277 |
22 Mar 10 |
nicklas |
(case-sensitivity depends on the database that is used). |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is an assay-level annotation type with the |
5277 |
22 Mar 10 |
nicklas |
given name. |
5277 |
22 Mar 10 |
nicklas |
<li>If name is 'name', 'description' or another static property |
5277 |
22 Mar 10 |
nicklas |
(case-insensitive) the corresponding assay value is used. |
5277 |
22 Mar 10 |
nicklas |
</ol> |
5277 |
22 Mar 10 |
nicklas |
64 |
|
5277 |
22 Mar 10 |
nicklas |
@param name The name to find |
5277 |
22 Mar 10 |
nicklas |
@param required If TRUE and no field is found this method will |
5277 |
22 Mar 10 |
nicklas |
throw an ItemNotFoundException |
5277 |
22 Mar 10 |
nicklas |
@return The field or null |
5277 |
22 Mar 10 |
nicklas |
69 |
*/ |
5277 |
22 Mar 10 |
nicklas |
70 |
@Override |
5277 |
22 Mar 10 |
nicklas |
71 |
public AssayField getAssayField(String name, boolean required) |
5277 |
22 Mar 10 |
nicklas |
72 |
{ |
5277 |
22 Mar 10 |
nicklas |
73 |
AssayField fld = null; |
5277 |
22 Mar 10 |
nicklas |
74 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
75 |
{ |
5277 |
22 Mar 10 |
nicklas |
76 |
fld = getExperimentalFactorField(name, name); |
5277 |
22 Mar 10 |
nicklas |
77 |
} |
5277 |
22 Mar 10 |
nicklas |
78 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
79 |
{ |
5277 |
22 Mar 10 |
nicklas |
80 |
fld = getAssayAnnotationField(name, name); |
5277 |
22 Mar 10 |
nicklas |
81 |
} |
5277 |
22 Mar 10 |
nicklas |
82 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
83 |
{ |
5277 |
22 Mar 10 |
nicklas |
84 |
fld = getAssayPropertyField(name, name); |
5277 |
22 Mar 10 |
nicklas |
85 |
} |
5277 |
22 Mar 10 |
nicklas |
86 |
if (fld == null && required) |
5277 |
22 Mar 10 |
nicklas |
87 |
{ |
5277 |
22 Mar 10 |
nicklas |
88 |
throw new ItemNotFoundException("Unknown assay field: " + name + |
5277 |
22 Mar 10 |
nicklas |
89 |
" (you can add this field as an experimental factor or assay annotation)"); |
5277 |
22 Mar 10 |
nicklas |
90 |
} |
5277 |
22 Mar 10 |
nicklas |
91 |
return fld; |
5277 |
22 Mar 10 |
nicklas |
92 |
} |
5277 |
22 Mar 10 |
nicklas |
93 |
|
5277 |
22 Mar 10 |
nicklas |
94 |
/** |
5277 |
22 Mar 10 |
nicklas |
Find a reporter dynamic field. This method will try to locate a field |
5277 |
22 Mar 10 |
nicklas |
in the following order: |
5277 |
22 Mar 10 |
nicklas |
97 |
|
5277 |
22 Mar 10 |
nicklas |
<ol> |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is an position extra value with the given name |
5277 |
22 Mar 10 |
nicklas |
(case-sensitivity depends on the database that is used). |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is a formula with the given name |
5277 |
22 Mar 10 |
nicklas |
(case-sensitivity depends on the database that is used). |
5277 |
22 Mar 10 |
nicklas |
<li>If name is 'name', 'externalId', 'description' or another static |
5277 |
22 Mar 10 |
nicklas |
property (case-insensitive) the corresponding reporter value |
5277 |
22 Mar 10 |
nicklas |
is used. |
5300 |
31 Mar 10 |
nicklas |
<li>Special case for "External ID" and "Internal ID" to simplify pass-throguh |
5300 |
31 Mar 10 |
nicklas |
to the BFS importer which expects at least one of those columns. |
5277 |
22 Mar 10 |
nicklas |
</ol> |
5277 |
22 Mar 10 |
nicklas |
@param name The name to find |
5277 |
22 Mar 10 |
nicklas |
@param required If TRUE and no field is found this method will |
5277 |
22 Mar 10 |
nicklas |
throw an ItemNotFoundException |
5277 |
22 Mar 10 |
nicklas |
@return The field or null |
5277 |
22 Mar 10 |
nicklas |
113 |
*/ |
5277 |
22 Mar 10 |
nicklas |
114 |
@Override |
5277 |
22 Mar 10 |
nicklas |
115 |
public DynamicField getReporterField(String name, boolean required) |
5277 |
22 Mar 10 |
nicklas |
116 |
{ |
5277 |
22 Mar 10 |
nicklas |
117 |
DynamicField fld = getExtraValueField(name, CoordinateType.POSITION, name); |
5277 |
22 Mar 10 |
nicklas |
118 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
119 |
{ |
5277 |
22 Mar 10 |
nicklas |
120 |
fld = getFormulaField(name, name); |
5277 |
22 Mar 10 |
nicklas |
121 |
} |
5277 |
22 Mar 10 |
nicklas |
122 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
123 |
{ |
5277 |
22 Mar 10 |
nicklas |
124 |
fld = getReporterProperty(name, name); |
5277 |
22 Mar 10 |
nicklas |
125 |
} |
5277 |
22 Mar 10 |
nicklas |
126 |
if (fld == null && required) |
5277 |
22 Mar 10 |
nicklas |
127 |
{ |
5277 |
22 Mar 10 |
nicklas |
128 |
throw new ItemNotFoundException("Unknown reporter field: " + name + |
5277 |
22 Mar 10 |
nicklas |
129 |
" (you can add this field as a formula or extra value)"); |
5277 |
22 Mar 10 |
nicklas |
130 |
} |
5277 |
22 Mar 10 |
nicklas |
131 |
return fld; |
5277 |
22 Mar 10 |
nicklas |
132 |
} |
5277 |
22 Mar 10 |
nicklas |
133 |
|
5277 |
22 Mar 10 |
nicklas |
134 |
/** |
5277 |
22 Mar 10 |
nicklas |
Find a spot dynamic field. This method will try to locate a field |
5277 |
22 Mar 10 |
nicklas |
in the following order: |
5277 |
22 Mar 10 |
nicklas |
137 |
|
5277 |
22 Mar 10 |
nicklas |
<ol> |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is a spot extra value with the given name |
5277 |
22 Mar 10 |
nicklas |
(case-sensitivity depends on the database that is used). |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is a formula with the given name |
5277 |
22 Mar 10 |
nicklas |
(case-sensitivity depends on the database that is used). |
5277 |
22 Mar 10 |
nicklas |
<li>Check if there is a raw data property that matches the |
5300 |
31 Mar 10 |
nicklas |
name (case-insensitive) |
5300 |
31 Mar 10 |
nicklas |
<li>Special values: Ch 1, Ch2, etc. to get channel intensities |
5300 |
31 Mar 10 |
nicklas |
(case-insensitive) |
5277 |
22 Mar 10 |
nicklas |
</ol> |
5277 |
22 Mar 10 |
nicklas |
@param name The name to find |
5277 |
22 Mar 10 |
nicklas |
@param required If TRUE and no field is found this method will |
5277 |
22 Mar 10 |
nicklas |
throw an ItemNotFoundException |
5277 |
22 Mar 10 |
nicklas |
@return The field or null |
5277 |
22 Mar 10 |
nicklas |
152 |
*/ |
5277 |
22 Mar 10 |
nicklas |
153 |
@Override |
5277 |
22 Mar 10 |
nicklas |
154 |
public DynamicField getSpotField(String name, boolean required) |
5277 |
22 Mar 10 |
nicklas |
155 |
{ |
5277 |
22 Mar 10 |
nicklas |
156 |
DynamicField fld = getExtraValueField(name, CoordinateType.SPOT, name); |
5277 |
22 Mar 10 |
nicklas |
157 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
158 |
{ |
5277 |
22 Mar 10 |
nicklas |
159 |
fld = getFormulaField(name, name); |
5277 |
22 Mar 10 |
nicklas |
160 |
} |
5277 |
22 Mar 10 |
nicklas |
161 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
162 |
{ |
5277 |
22 Mar 10 |
nicklas |
163 |
fld = getRawDataProperty(name, name); |
5277 |
22 Mar 10 |
nicklas |
164 |
} |
5277 |
22 Mar 10 |
nicklas |
165 |
if (fld == null) |
5277 |
22 Mar 10 |
nicklas |
166 |
{ |
5277 |
22 Mar 10 |
nicklas |
167 |
fld = getIntensityField(name, name); |
5277 |
22 Mar 10 |
nicklas |
168 |
} |
5277 |
22 Mar 10 |
nicklas |
169 |
if (fld == null && required) |
5277 |
22 Mar 10 |
nicklas |
170 |
{ |
5277 |
22 Mar 10 |
nicklas |
171 |
throw new ItemNotFoundException("Unknown spot field: " + name + |
5277 |
22 Mar 10 |
nicklas |
172 |
" (you can add this field as a formula or extra value)"); |
5277 |
22 Mar 10 |
nicklas |
173 |
} |
5277 |
22 Mar 10 |
nicklas |
174 |
return fld; |
5277 |
22 Mar 10 |
nicklas |
175 |
} |
5277 |
22 Mar 10 |
nicklas |
176 |
|
5277 |
22 Mar 10 |
nicklas |
177 |
} |