1431 |
20 Mar 07 |
fredrik |
1 |
/* |
1431 |
20 Mar 07 |
fredrik |
$Id$ |
1431 |
20 Mar 07 |
fredrik |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Fredrik Levander, Gregory Vincic |
1431 |
20 Mar 07 |
fredrik |
5 |
|
1431 |
20 Mar 07 |
fredrik |
Files are copyright by their respective authors. The contributions to |
1431 |
20 Mar 07 |
fredrik |
files where copyright is not explicitly stated can be traced with the |
1431 |
20 Mar 07 |
fredrik |
source code revision system. |
1431 |
20 Mar 07 |
fredrik |
9 |
|
1431 |
20 Mar 07 |
fredrik |
This file is part of Proteios. |
1431 |
20 Mar 07 |
fredrik |
Available at http://www.proteios.org/ |
1431 |
20 Mar 07 |
fredrik |
12 |
|
1431 |
20 Mar 07 |
fredrik |
Proteios-2.x is free software; you can redistribute it and/or |
1431 |
20 Mar 07 |
fredrik |
modify it under the terms of the GNU General Public License |
1431 |
20 Mar 07 |
fredrik |
as published by the Free Software Foundation; either version 2 |
1431 |
20 Mar 07 |
fredrik |
of the License, or (at your option) any later version. |
1431 |
20 Mar 07 |
fredrik |
17 |
|
1431 |
20 Mar 07 |
fredrik |
Proteios is distributed in the hope that it will be useful, |
1431 |
20 Mar 07 |
fredrik |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1431 |
20 Mar 07 |
fredrik |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1431 |
20 Mar 07 |
fredrik |
GNU General Public License for more details. |
1431 |
20 Mar 07 |
fredrik |
22 |
|
1431 |
20 Mar 07 |
fredrik |
You should have received a copy of the GNU General Public License |
1431 |
20 Mar 07 |
fredrik |
along with this program; if not, write to the Free Software |
1431 |
20 Mar 07 |
fredrik |
Foundation, Inc., 59 Temple Place - Suite 330, |
1431 |
20 Mar 07 |
fredrik |
Boston, MA 02111-1307, USA. |
1431 |
20 Mar 07 |
fredrik |
27 |
*/ |
1431 |
20 Mar 07 |
fredrik |
28 |
package org.proteios.plugins; |
1431 |
20 Mar 07 |
fredrik |
29 |
|
1431 |
20 Mar 07 |
fredrik |
30 |
import org.proteios.core.BaseException; |
1431 |
20 Mar 07 |
fredrik |
31 |
import org.proteios.core.DbControl; |
1431 |
20 Mar 07 |
fredrik |
32 |
import org.proteios.core.File; |
1431 |
20 Mar 07 |
fredrik |
33 |
import org.proteios.core.FileType; |
1431 |
20 Mar 07 |
fredrik |
34 |
import org.proteios.core.Hit; |
1533 |
29 Apr 07 |
gregory |
35 |
import org.proteios.core.ItemFactory; |
1431 |
20 Mar 07 |
fredrik |
36 |
import org.proteios.core.ItemQuery; |
1431 |
20 Mar 07 |
fredrik |
37 |
import org.proteios.core.ItemResultIterator; |
1431 |
20 Mar 07 |
fredrik |
38 |
import org.proteios.core.ProgressReporter; |
1431 |
20 Mar 07 |
fredrik |
39 |
import org.proteios.core.Project; |
1431 |
20 Mar 07 |
fredrik |
40 |
import org.proteios.core.SessionControl; |
1431 |
20 Mar 07 |
fredrik |
41 |
import org.proteios.core.plugin.About; |
1431 |
20 Mar 07 |
fredrik |
42 |
import org.proteios.core.plugin.AboutImpl; |
1431 |
20 Mar 07 |
fredrik |
43 |
import org.proteios.core.plugin.AbstractPlugin; |
1431 |
20 Mar 07 |
fredrik |
44 |
import org.proteios.core.plugin.ParameterValues; |
1431 |
20 Mar 07 |
fredrik |
45 |
import org.proteios.core.plugin.Request; |
1431 |
20 Mar 07 |
fredrik |
46 |
import org.proteios.core.plugin.Response; |
2534 |
05 Feb 08 |
fredrik |
47 |
import org.proteios.core.query.Expressions; |
2534 |
05 Feb 08 |
fredrik |
48 |
import org.proteios.core.query.Hql; |
2534 |
05 Feb 08 |
fredrik |
49 |
import org.proteios.core.query.Restrictions; |
1431 |
20 Mar 07 |
fredrik |
50 |
import org.proteios.io.FilenameParseUtil; |
1431 |
20 Mar 07 |
fredrik |
51 |
import org.proteios.io.RobotFileImpl; |
2531 |
05 Feb 08 |
fredrik |
52 |
import org.proteios.io.RobotFileSpotXY; |
1431 |
20 Mar 07 |
fredrik |
53 |
import org.xml.sax.SAXException; |
3465 |
27 Oct 09 |
fredrik |
54 |
|
1431 |
20 Mar 07 |
fredrik |
55 |
import java.util.ArrayList; |
1431 |
20 Mar 07 |
fredrik |
56 |
import java.util.Iterator; |
1431 |
20 Mar 07 |
fredrik |
57 |
import java.util.List; |
3465 |
27 Oct 09 |
fredrik |
58 |
|
1431 |
20 Mar 07 |
fredrik |
59 |
import javax.xml.stream.XMLStreamException; |
1431 |
20 Mar 07 |
fredrik |
60 |
|
1431 |
20 Mar 07 |
fredrik |
61 |
/** |
1431 |
20 Mar 07 |
fredrik |
* @author gregory |
1431 |
20 Mar 07 |
fredrik |
* @author fredrik |
1431 |
20 Mar 07 |
fredrik |
64 |
*/ |
1431 |
20 Mar 07 |
fredrik |
65 |
public class GelSpotPlatePosToHitPlugin |
1431 |
20 Mar 07 |
fredrik |
66 |
extends AbstractPlugin |
1431 |
20 Mar 07 |
fredrik |
67 |
{ |
1431 |
20 Mar 07 |
fredrik |
68 |
/** |
1431 |
20 Mar 07 |
fredrik |
* Logger used. Used to log specific events. |
1431 |
20 Mar 07 |
fredrik |
70 |
*/ |
1431 |
20 Mar 07 |
fredrik |
71 |
protected static final org.apache.log4j.Logger log = org.apache.log4j.LogManager |
1431 |
20 Mar 07 |
fredrik |
72 |
.getLogger("org.proteios.io"); |
1431 |
20 Mar 07 |
fredrik |
73 |
|
1533 |
29 Apr 07 |
gregory |
74 |
|
2386 |
14 Nov 07 |
gregory |
75 |
@Override |
1431 |
20 Mar 07 |
fredrik |
76 |
public void init(SessionControl sc, ParameterValues configuration, |
1431 |
20 Mar 07 |
fredrik |
77 |
ParameterValues job) |
1431 |
20 Mar 07 |
fredrik |
78 |
throws BaseException |
1431 |
20 Mar 07 |
fredrik |
79 |
{ |
1431 |
20 Mar 07 |
fredrik |
80 |
super.init(sc, configuration, job); |
1431 |
20 Mar 07 |
fredrik |
81 |
} |
1431 |
20 Mar 07 |
fredrik |
82 |
|
1431 |
20 Mar 07 |
fredrik |
83 |
|
1431 |
20 Mar 07 |
fredrik |
84 |
public void run(Request request, Response response, |
1431 |
20 Mar 07 |
fredrik |
85 |
ProgressReporter progress) |
1431 |
20 Mar 07 |
fredrik |
86 |
{ |
1431 |
20 Mar 07 |
fredrik |
87 |
String command = request.getCommand(); |
1431 |
20 Mar 07 |
fredrik |
88 |
if (command.equals(Request.COMMAND_EXECUTE)) |
1431 |
20 Mar 07 |
fredrik |
89 |
{ |
1431 |
20 Mar 07 |
fredrik |
90 |
execute(request, response, progress); |
1431 |
20 Mar 07 |
fredrik |
91 |
} |
1431 |
20 Mar 07 |
fredrik |
92 |
else if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN)) |
1431 |
20 Mar 07 |
fredrik |
93 |
{ |
1431 |
20 Mar 07 |
fredrik |
94 |
response.setContinue(Request.COMMAND_EXECUTE); |
1431 |
20 Mar 07 |
fredrik |
95 |
} |
1431 |
20 Mar 07 |
fredrik |
96 |
else |
1431 |
20 Mar 07 |
fredrik |
97 |
{ |
1431 |
20 Mar 07 |
fredrik |
98 |
response.setError("Unknown command " + command, null); |
1431 |
20 Mar 07 |
fredrik |
99 |
} |
1431 |
20 Mar 07 |
fredrik |
100 |
} |
1431 |
20 Mar 07 |
fredrik |
101 |
|
1431 |
20 Mar 07 |
fredrik |
102 |
|
1431 |
20 Mar 07 |
fredrik |
103 |
private void execute(Request request, Response response, |
1431 |
20 Mar 07 |
fredrik |
104 |
ProgressReporter progress) |
1431 |
20 Mar 07 |
fredrik |
105 |
{ |
1431 |
20 Mar 07 |
fredrik |
106 |
String gelId = (String) job.getValue("gelId"); |
1533 |
29 Apr 07 |
gregory |
107 |
if (gelId != null && gelId.length() > 0) |
1431 |
20 Mar 07 |
fredrik |
108 |
{ |
1533 |
29 Apr 07 |
gregory |
109 |
log |
1533 |
29 Apr 07 |
gregory |
110 |
.info("GelSpotPlatePosToHitPlugin: only importing results for gel:" + gelId); |
1431 |
20 Mar 07 |
fredrik |
111 |
} |
1431 |
20 Mar 07 |
fredrik |
112 |
FilenameParseUtil fpu = new FilenameParseUtil(); |
1431 |
20 Mar 07 |
fredrik |
113 |
File f = (File) job.getValue("file"); |
1431 |
20 Mar 07 |
fredrik |
114 |
DbControl dc = sc.newDbControl(); |
1533 |
29 Apr 07 |
gregory |
115 |
ItemFactory factory = new ItemFactory(dc); |
1495 |
17 Apr 07 |
fredrik |
116 |
Project project = Project.getById(dc, sc.getActiveProjectId()); |
1431 |
20 Mar 07 |
fredrik |
117 |
ItemQuery<FileType> fileTypeQuery = FileType.getQuery(); |
1533 |
29 Apr 07 |
gregory |
118 |
FileType ft_robot = null; |
3001 |
15 Dec 08 |
fredrik |
119 |
boolean ok = false; |
3001 |
15 Dec 08 |
fredrik |
120 |
int imported = 0; |
1533 |
29 Apr 07 |
gregory |
121 |
ItemResultIterator<FileType> ftit = fileTypeQuery.iterate(dc); |
1431 |
20 Mar 07 |
fredrik |
122 |
while (ftit.hasNext()) |
1533 |
29 Apr 07 |
gregory |
123 |
{ |
1533 |
29 Apr 07 |
gregory |
124 |
FileType fileType = ftit.next(); |
1533 |
29 Apr 07 |
gregory |
125 |
if (fileType.isSystemItem()) |
1431 |
20 Mar 07 |
fredrik |
126 |
{ |
1533 |
29 Apr 07 |
gregory |
127 |
if (fileType.getSystemId().equals(FileType.SHW_RESULT)) |
1533 |
29 Apr 07 |
gregory |
128 |
ft_robot = fileType; |
1431 |
20 Mar 07 |
fredrik |
129 |
} |
1431 |
20 Mar 07 |
fredrik |
130 |
} |
1431 |
20 Mar 07 |
fredrik |
131 |
ftit.close(); |
1431 |
20 Mar 07 |
fredrik |
132 |
dc.reattachItem(f); |
1431 |
20 Mar 07 |
fredrik |
133 |
FileType ft = f.getFileType(); |
3001 |
15 Dec 08 |
fredrik |
134 |
if (ft == null || ft.equals(ft_robot)) |
1431 |
20 Mar 07 |
fredrik |
135 |
{ |
1431 |
20 Mar 07 |
fredrik |
136 |
RobotFileImpl rfi = new RobotFileImpl(f); |
3001 |
15 Dec 08 |
fredrik |
137 |
log.info("GelSpotPlatePosToHitPlugin: Trying if valid"); |
1431 |
20 Mar 07 |
fredrik |
138 |
try |
1431 |
20 Mar 07 |
fredrik |
139 |
{ |
1431 |
20 Mar 07 |
fredrik |
140 |
if (rfi.valid()) |
1431 |
20 Mar 07 |
fredrik |
141 |
{ |
2534 |
05 Feb 08 |
fredrik |
// SHW robot file! |
1431 |
20 Mar 07 |
fredrik |
143 |
log.info("GelSpotPlatePosToHitPlugin: valid robot file"); |
1533 |
29 Apr 07 |
gregory |
144 |
if (f.getFileType() == null) |
1431 |
20 Mar 07 |
fredrik |
145 |
{ |
1431 |
20 Mar 07 |
fredrik |
146 |
f.setFileType(ft_robot); |
1431 |
20 Mar 07 |
fredrik |
147 |
} |
4225 |
08 Jun 11 |
olle |
148 |
if (f.getMimeType() == null) |
4225 |
08 Jun 11 |
olle |
149 |
{ |
4225 |
08 Jun 11 |
olle |
150 |
f.setMimeType("application/xml"); |
4225 |
08 Jun 11 |
olle |
151 |
} |
3465 |
27 Oct 09 |
fredrik |
152 |
List<String> gellist = rfi.getGelIdList(); |
3465 |
27 Oct 09 |
fredrik |
/* If no gel in the file, try to import spotting only */ |
3465 |
27 Oct 09 |
fredrik |
154 |
if (gellist == null) |
1431 |
20 Mar 07 |
fredrik |
155 |
{ |
3465 |
27 Oct 09 |
fredrik |
156 |
List<String> microtitrePlates = rfi |
3465 |
27 Oct 09 |
fredrik |
157 |
.getPlateIdListFromMicroPlate(); |
3465 |
27 Oct 09 |
fredrik |
158 |
rfi = new RobotFileImpl(f); |
3465 |
27 Oct 09 |
fredrik |
159 |
ItemQuery<Hit> hitQuery = Hit.getQuery(project); |
3465 |
27 Oct 09 |
fredrik |
160 |
for (String mp : microtitrePlates) |
1431 |
20 Mar 07 |
fredrik |
161 |
{ |
3465 |
27 Oct 09 |
fredrik |
162 |
hitQuery.reset(); |
3465 |
27 Oct 09 |
fredrik |
163 |
hitQuery.restrict(Restrictions.eq(Hql |
3465 |
27 Oct 09 |
fredrik |
164 |
.property("plateId"), Expressions |
3465 |
27 Oct 09 |
fredrik |
165 |
.parameter("plateId"))); |
3465 |
27 Oct 09 |
fredrik |
166 |
hitQuery.setParameter("plateId", mp, null); |
3465 |
27 Oct 09 |
fredrik |
167 |
List<Hit> hits = hitQuery.list(dc); |
3465 |
27 Oct 09 |
fredrik |
168 |
for (Hit h : hits) |
1431 |
20 Mar 07 |
fredrik |
169 |
{ |
3465 |
27 Oct 09 |
fredrik |
170 |
String plateId = rfi.getPlateIdFromTargetPlate( |
3465 |
27 Oct 09 |
fredrik |
171 |
h.getPlateId(), h.getWellPosition()); |
3465 |
27 Oct 09 |
fredrik |
172 |
if (plateId != null) |
3465 |
27 Oct 09 |
fredrik |
173 |
{ |
3465 |
27 Oct 09 |
fredrik |
174 |
String platePos = rfi |
3465 |
27 Oct 09 |
fredrik |
175 |
.getPlatePosFromTargetPlate(h |
3465 |
27 Oct 09 |
fredrik |
176 |
.getPlateId(), h.getWellPosition()); |
3465 |
27 Oct 09 |
fredrik |
177 |
if (platePos != null) |
3465 |
27 Oct 09 |
fredrik |
178 |
{ |
3465 |
27 Oct 09 |
fredrik |
179 |
imported++; |
3465 |
27 Oct 09 |
fredrik |
180 |
Hit hit = factory.create(Hit.class); |
3465 |
27 Oct 09 |
fredrik |
181 |
hit.setProject(project); |
3465 |
27 Oct 09 |
fredrik |
182 |
hit.setMicroPlate(new Boolean(false)); |
3465 |
27 Oct 09 |
fredrik |
183 |
hit.setPlateId(plateId); |
3465 |
27 Oct 09 |
fredrik |
184 |
hit.setWellPosition(fpu |
3465 |
27 Oct 09 |
fredrik |
185 |
.convertWellNotation(platePos)); |
3465 |
27 Oct 09 |
fredrik |
186 |
hit.setGelExternalId(h |
3465 |
27 Oct 09 |
fredrik |
187 |
.getGelExternalId()); |
3465 |
27 Oct 09 |
fredrik |
188 |
hit.setSpotId(h.getSpotId()); |
3465 |
27 Oct 09 |
fredrik |
189 |
hit.setSpotXPixel(h.getSpotXPixel()); |
3465 |
27 Oct 09 |
fredrik |
190 |
hit.setSpotYPixel(h.getSpotYPixel()); |
3465 |
27 Oct 09 |
fredrik |
191 |
dc.saveItem(hit); |
3465 |
27 Oct 09 |
fredrik |
192 |
if (!ok) |
3465 |
27 Oct 09 |
fredrik |
193 |
{ |
3465 |
27 Oct 09 |
fredrik |
194 |
hitQuery.reset(); |
3465 |
27 Oct 09 |
fredrik |
195 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
196 |
Hql.property("gelExternalId"), |
3465 |
27 Oct 09 |
fredrik |
197 |
Expressions.string(hit |
3465 |
27 Oct 09 |
fredrik |
198 |
.getGelExternalId()))); |
3465 |
27 Oct 09 |
fredrik |
199 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
200 |
Hql.property("spotId"), |
3465 |
27 Oct 09 |
fredrik |
201 |
Expressions.integer(hit |
3465 |
27 Oct 09 |
fredrik |
202 |
.getSpotId()))); |
3465 |
27 Oct 09 |
fredrik |
203 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
204 |
Hql.property("plateId"), |
3465 |
27 Oct 09 |
fredrik |
205 |
Expressions.string(hit |
3465 |
27 Oct 09 |
fredrik |
206 |
.getPlateId()))); |
3465 |
27 Oct 09 |
fredrik |
207 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
208 |
Hql.property("wellPosition"), |
3465 |
27 Oct 09 |
fredrik |
209 |
Expressions.string(hit |
3465 |
27 Oct 09 |
fredrik |
210 |
.getWellPosition()))); |
3465 |
27 Oct 09 |
fredrik |
211 |
if (hitQuery.count(dc) > 0) |
3465 |
27 Oct 09 |
fredrik |
212 |
{ |
3465 |
27 Oct 09 |
fredrik |
213 |
throw new BaseException( |
3465 |
27 Oct 09 |
fredrik |
214 |
"Already imported"); |
3465 |
27 Oct 09 |
fredrik |
215 |
} |
3465 |
27 Oct 09 |
fredrik |
216 |
ok = true; |
3465 |
27 Oct 09 |
fredrik |
217 |
} |
3465 |
27 Oct 09 |
fredrik |
218 |
} |
3465 |
27 Oct 09 |
fredrik |
219 |
} |
1431 |
20 Mar 07 |
fredrik |
220 |
} |
3465 |
27 Oct 09 |
fredrik |
221 |
} |
3465 |
27 Oct 09 |
fredrik |
222 |
if (imported == 0) |
3465 |
27 Oct 09 |
fredrik |
223 |
{ |
3465 |
27 Oct 09 |
fredrik |
224 |
throw new BaseException( |
3465 |
27 Oct 09 |
fredrik |
225 |
"No microtitre plates in the hits report matched those spotted in the file."); |
3465 |
27 Oct 09 |
fredrik |
226 |
} |
3465 |
27 Oct 09 |
fredrik |
227 |
} |
3465 |
27 Oct 09 |
fredrik |
228 |
else |
3465 |
27 Oct 09 |
fredrik |
/* Import gel spots: */ |
3465 |
27 Oct 09 |
fredrik |
230 |
{ |
3465 |
27 Oct 09 |
fredrik |
231 |
Iterator<String> gelit = gellist.iterator(); |
3465 |
27 Oct 09 |
fredrik |
232 |
while (gelit.hasNext()) |
3465 |
27 Oct 09 |
fredrik |
233 |
{ |
3465 |
27 Oct 09 |
fredrik |
234 |
String currentGel = gelit.next(); |
2534 |
05 Feb 08 |
fredrik |
235 |
log |
3465 |
27 Oct 09 |
fredrik |
236 |
.info("GelSpotPlatePosToHitPlugin: gel:" + currentGel); |
3465 |
27 Oct 09 |
fredrik |
237 |
/* |
3465 |
27 Oct 09 |
fredrik |
* If a gel was specified we only enter data for |
3465 |
27 Oct 09 |
fredrik |
* that one |
3465 |
27 Oct 09 |
fredrik |
240 |
*/ |
3465 |
27 Oct 09 |
fredrik |
241 |
if (gelId == null || gelId.length() == 0 || gelId |
3465 |
27 Oct 09 |
fredrik |
242 |
.equals(currentGel)) |
1431 |
20 Mar 07 |
fredrik |
243 |
{ |
3465 |
27 Oct 09 |
fredrik |
244 |
log |
3465 |
27 Oct 09 |
fredrik |
245 |
.info("GelSpotPlatePosToHitPlugin: gel to import:" + currentGel); |
3465 |
27 Oct 09 |
fredrik |
246 |
List<String> spots = rfi |
3465 |
27 Oct 09 |
fredrik |
247 |
.getSpotIdListFromMicroPlate(currentGel); |
3465 |
27 Oct 09 |
fredrik |
248 |
List<String> gels = new ArrayList<String>(); |
3465 |
27 Oct 09 |
fredrik |
249 |
for (int i = 0; i < spots.size(); i++) |
1431 |
20 Mar 07 |
fredrik |
250 |
{ |
3465 |
27 Oct 09 |
fredrik |
251 |
gels.add(currentGel); |
3465 |
27 Oct 09 |
fredrik |
252 |
} |
3465 |
27 Oct 09 |
fredrik |
253 |
List<String> mpIds = rfi |
3465 |
27 Oct 09 |
fredrik |
254 |
.getPlateIdFromMicroPlate(spots, gels); |
3465 |
27 Oct 09 |
fredrik |
255 |
List<String> mpWells = rfi |
3465 |
27 Oct 09 |
fredrik |
256 |
.getWellIdFromMicroPlate(spots, gels); |
3465 |
27 Oct 09 |
fredrik |
257 |
List<String> targetIds = rfi |
3465 |
27 Oct 09 |
fredrik |
258 |
.getTargetIdFromTargetPlate(spots, gels); |
3465 |
27 Oct 09 |
fredrik |
259 |
List<String> targetPos = rfi |
3465 |
27 Oct 09 |
fredrik |
260 |
.getPositionIdFromTargetPlate(spots, gels); |
3465 |
27 Oct 09 |
fredrik |
261 |
RobotFileSpotXY spotxy = new RobotFileSpotXY(f); |
3465 |
27 Oct 09 |
fredrik |
262 |
List<Float> spotXs = spotxy.getSpotXs(spots, |
3465 |
27 Oct 09 |
fredrik |
263 |
gels); |
3465 |
27 Oct 09 |
fredrik |
264 |
List<Float> spotYs = spotxy.getSpotYs(spots, |
3465 |
27 Oct 09 |
fredrik |
265 |
gels); |
3465 |
27 Oct 09 |
fredrik |
266 |
log |
3465 |
27 Oct 09 |
fredrik |
267 |
.info("GelSpotPlatePosToHitPlugin: Spots to add:" + spots |
3465 |
27 Oct 09 |
fredrik |
268 |
.size()); |
3465 |
27 Oct 09 |
fredrik |
269 |
imported = spots.size(); |
3465 |
27 Oct 09 |
fredrik |
270 |
for (int i = 0; i < spots.size(); i++) |
3465 |
27 Oct 09 |
fredrik |
271 |
{ |
3465 |
27 Oct 09 |
fredrik |
272 |
if (mpIds.get(i) != null && mpWells.get(i) != null) |
2534 |
05 Feb 08 |
fredrik |
273 |
{ |
3465 |
27 Oct 09 |
fredrik |
274 |
Hit hit = factory.create(Hit.class); |
3465 |
27 Oct 09 |
fredrik |
275 |
hit.setProject(project); |
3465 |
27 Oct 09 |
fredrik |
276 |
hit.setMicroPlate(new Boolean(true)); |
3465 |
27 Oct 09 |
fredrik |
277 |
hit.setPlateId(mpIds.get(i)); |
3465 |
27 Oct 09 |
fredrik |
278 |
hit |
3465 |
27 Oct 09 |
fredrik |
279 |
.setWellPosition(fpu |
3465 |
27 Oct 09 |
fredrik |
280 |
.convertWellNotation(mpWells |
3465 |
27 Oct 09 |
fredrik |
281 |
.get(i))); |
3465 |
27 Oct 09 |
fredrik |
282 |
hit.setGelExternalId(currentGel); |
3465 |
27 Oct 09 |
fredrik |
283 |
hit.setSpotId(Integer.valueOf(spots |
3465 |
27 Oct 09 |
fredrik |
284 |
.get(i))); |
3465 |
27 Oct 09 |
fredrik |
285 |
hit.setSpotXPixel(spotXs.get(i)); |
3465 |
27 Oct 09 |
fredrik |
286 |
hit.setSpotYPixel(spotYs.get(i)); |
3465 |
27 Oct 09 |
fredrik |
287 |
dc.saveItem(hit); |
3465 |
27 Oct 09 |
fredrik |
288 |
if (!ok) |
2534 |
05 Feb 08 |
fredrik |
289 |
{ |
3465 |
27 Oct 09 |
fredrik |
290 |
ItemQuery<Hit> hitQuery = Hit |
3465 |
27 Oct 09 |
fredrik |
291 |
.getQuery(project); |
3465 |
27 Oct 09 |
fredrik |
292 |
hitQuery |
3465 |
27 Oct 09 |
fredrik |
293 |
.restrict(Restrictions.eq(Hql |
3465 |
27 Oct 09 |
fredrik |
294 |
.property("gelExternalId"), |
3465 |
27 Oct 09 |
fredrik |
295 |
Expressions |
3465 |
27 Oct 09 |
fredrik |
296 |
.string(currentGel))); |
3465 |
27 Oct 09 |
fredrik |
297 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
298 |
Hql.property("spotId"), |
3465 |
27 Oct 09 |
fredrik |
299 |
Expressions.integer(Integer |
3465 |
27 Oct 09 |
fredrik |
300 |
.parseInt(spots.get(i))))); |
3465 |
27 Oct 09 |
fredrik |
301 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
302 |
Hql.property("plateId"), |
3465 |
27 Oct 09 |
fredrik |
303 |
Expressions |
3465 |
27 Oct 09 |
fredrik |
304 |
.string(mpIds.get(i)))); |
3465 |
27 Oct 09 |
fredrik |
305 |
hitQuery.restrict(Restrictions.eq( |
3465 |
27 Oct 09 |
fredrik |
306 |
Hql.property("wellPosition"), |
3465 |
27 Oct 09 |
fredrik |
307 |
Expressions.string(hit |
3465 |
27 Oct 09 |
fredrik |
308 |
.getWellPosition()))); |
3465 |
27 Oct 09 |
fredrik |
309 |
if (hitQuery.count(dc) > 0) |
3465 |
27 Oct 09 |
fredrik |
310 |
{ |
3465 |
27 Oct 09 |
fredrik |
311 |
throw new BaseException( |
3465 |
27 Oct 09 |
fredrik |
312 |
"Already imported"); |
3465 |
27 Oct 09 |
fredrik |
313 |
} |
3465 |
27 Oct 09 |
fredrik |
314 |
ok = true; |
2534 |
05 Feb 08 |
fredrik |
315 |
} |
3465 |
27 Oct 09 |
fredrik |
316 |
imported++; |
2534 |
05 Feb 08 |
fredrik |
317 |
} |
3465 |
27 Oct 09 |
fredrik |
318 |
if (targetIds.get(i) != null && targetPos |
3465 |
27 Oct 09 |
fredrik |
319 |
.get(i) != null) |
3465 |
27 Oct 09 |
fredrik |
320 |
{ |
3465 |
27 Oct 09 |
fredrik |
321 |
Hit hit = factory.create(Hit.class); |
3465 |
27 Oct 09 |
fredrik |
322 |
hit.setProject(project); |
3465 |
27 Oct 09 |
fredrik |
323 |
hit.setMicroPlate(new Boolean(false)); |
3465 |
27 Oct 09 |
fredrik |
324 |
hit.setPlateId(targetIds.get(i)); |
3465 |
27 Oct 09 |
fredrik |
325 |
hit.setWellPosition(fpu |
3465 |
27 Oct 09 |
fredrik |
326 |
.convertWellNotation(targetPos |
3465 |
27 Oct 09 |
fredrik |
327 |
.get(i))); |
3465 |
27 Oct 09 |
fredrik |
328 |
hit.setGelExternalId(currentGel); |
3465 |
27 Oct 09 |
fredrik |
329 |
hit.setSpotId(Integer.valueOf(spots |
3465 |
27 Oct 09 |
fredrik |
330 |
.get(i))); |
3465 |
27 Oct 09 |
fredrik |
331 |
hit.setSpotXPixel(spotXs.get(i)); |
3465 |
27 Oct 09 |
fredrik |
332 |
hit.setSpotYPixel(spotYs.get(i)); |
3465 |
27 Oct 09 |
fredrik |
333 |
dc.saveItem(hit); |
3465 |
27 Oct 09 |
fredrik |
334 |
} |
1431 |
20 Mar 07 |
fredrik |
335 |
} |
1431 |
20 Mar 07 |
fredrik |
336 |
} |
1431 |
20 Mar 07 |
fredrik |
337 |
} |
1431 |
20 Mar 07 |
fredrik |
338 |
} |
3001 |
15 Dec 08 |
fredrik |
339 |
dc.commit(); |
3001 |
15 Dec 08 |
fredrik |
340 |
response |
3001 |
15 Dec 08 |
fredrik |
341 |
.setDone("File imported. " + imported + " mappings added to hits report"); |
1431 |
20 Mar 07 |
fredrik |
342 |
} |
3001 |
15 Dec 08 |
fredrik |
343 |
else |
3001 |
15 Dec 08 |
fredrik |
344 |
{ |
3001 |
15 Dec 08 |
fredrik |
345 |
response.setError("Robot file not valid", |
3001 |
15 Dec 08 |
fredrik |
346 |
new ArrayList<Throwable>()); |
3001 |
15 Dec 08 |
fredrik |
347 |
} |
1431 |
20 Mar 07 |
fredrik |
348 |
} |
1431 |
20 Mar 07 |
fredrik |
349 |
catch (SAXException e) |
1431 |
20 Mar 07 |
fredrik |
350 |
{ |
1431 |
20 Mar 07 |
fredrik |
351 |
ArrayList<Throwable> err = new ArrayList<Throwable>(1); |
1431 |
20 Mar 07 |
fredrik |
352 |
err.add(e); |
1431 |
20 Mar 07 |
fredrik |
353 |
response.setError("SAX Exception when parsing XML stream", err); |
1431 |
20 Mar 07 |
fredrik |
354 |
} |
1431 |
20 Mar 07 |
fredrik |
355 |
catch (XMLStreamException e) |
1431 |
20 Mar 07 |
fredrik |
356 |
{ |
1431 |
20 Mar 07 |
fredrik |
357 |
ArrayList<Throwable> err = new ArrayList<Throwable>(1); |
1431 |
20 Mar 07 |
fredrik |
358 |
err.add(e); |
1431 |
20 Mar 07 |
fredrik |
359 |
response.setError("Error parsing XML stream", err); |
1431 |
20 Mar 07 |
fredrik |
360 |
} |
2534 |
05 Feb 08 |
fredrik |
361 |
catch (BaseException e) |
2534 |
05 Feb 08 |
fredrik |
362 |
{ |
3465 |
27 Oct 09 |
fredrik |
363 |
response.setError("Import failed. " + e.getMessage(), null); |
2534 |
05 Feb 08 |
fredrik |
364 |
} |
1431 |
20 Mar 07 |
fredrik |
365 |
} |
1431 |
20 Mar 07 |
fredrik |
366 |
else |
1431 |
20 Mar 07 |
fredrik |
367 |
{ |
1431 |
20 Mar 07 |
fredrik |
368 |
ArrayList<Throwable> err = new ArrayList<Throwable>(1); |
1533 |
29 Apr 07 |
gregory |
369 |
err.add(new BaseException( |
1533 |
29 Apr 07 |
gregory |
370 |
"File could not be imported using this importer")); |
1431 |
20 Mar 07 |
fredrik |
371 |
response.setError("Nothing imported", err); |
1431 |
20 Mar 07 |
fredrik |
372 |
} |
1431 |
20 Mar 07 |
fredrik |
373 |
done(); |
1431 |
20 Mar 07 |
fredrik |
374 |
} |
1431 |
20 Mar 07 |
fredrik |
375 |
|
1431 |
20 Mar 07 |
fredrik |
376 |
|
1431 |
20 Mar 07 |
fredrik |
377 |
public About getAbout() |
1431 |
20 Mar 07 |
fredrik |
378 |
{ |
1533 |
29 Apr 07 |
gregory |
379 |
About about = new AboutImpl( |
1533 |
29 Apr 07 |
gregory |
380 |
"GelSpotPlatePosToHitPlugin", |
1533 |
29 Apr 07 |
gregory |
381 |
"Imports spots, plates and wells to hits report from RobotResult files", |
3465 |
27 Oct 09 |
fredrik |
382 |
"1.1", "", "Gregory Vincic / Fredrik Levander", |
1533 |
29 Apr 07 |
gregory |
383 |
"gregory@thep.lu.se", "www.proteios.org"); |
1431 |
20 Mar 07 |
fredrik |
384 |
return about; |
1431 |
20 Mar 07 |
fredrik |
385 |
} |
1431 |
20 Mar 07 |
fredrik |
386 |
|
1431 |
20 Mar 07 |
fredrik |
387 |
|
1431 |
20 Mar 07 |
fredrik |
388 |
public MainType getMainType() |
1431 |
20 Mar 07 |
fredrik |
389 |
{ |
1431 |
20 Mar 07 |
fredrik |
390 |
return MainType.IMPORT; |
1431 |
20 Mar 07 |
fredrik |
391 |
} |
1431 |
20 Mar 07 |
fredrik |
392 |
} |