final implementation of MaterialOrMethodEvent, Cloning, PreservationMethod, ... ...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / Amplification.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.model.molecular;
10
11 import java.util.HashSet;
12 import java.util.Set;
13
14 import javax.persistence.Entity;
15 import javax.persistence.FetchType;
16 import javax.persistence.ManyToOne;
17 import javax.persistence.OneToMany;
18 import javax.validation.constraints.Size;
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlAttribute;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlElementWrapper;
24 import javax.xml.bind.annotation.XmlIDREF;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlSchemaType;
27 import javax.xml.bind.annotation.XmlType;
28
29 import org.apache.log4j.Logger;
30 import org.hibernate.annotations.Cascade;
31 import org.hibernate.annotations.CascadeType;
32 import org.hibernate.envers.Audited;
33 import org.hibernate.search.annotations.Analyze;
34 import org.hibernate.search.annotations.Field;
35 import org.hibernate.search.annotations.IndexedEmbedded;
36 import org.hibernate.search.annotations.NumericField;
37
38 import eu.etaxonomy.cdm.model.common.DefinedTerm;
39 import eu.etaxonomy.cdm.model.common.EventBase;
40 import eu.etaxonomy.cdm.model.common.TermType;
41 import eu.etaxonomy.cdm.model.media.Media;
42 import eu.etaxonomy.cdm.model.occurrence.MaterialOrMethodEvent;
43
44 /**
45 * @author a.mueller
46 * @created 2013-07-05
47 *
48 */
49 @XmlAccessorType(XmlAccessType.FIELD)
50 @XmlType(name = "Amplification", propOrder = {
51 "dnaSample",
52 "dnaMarker",
53 "forwardPrimer",
54 "reversePrimer",
55 "purification",
56 "cloning",
57 "successful",
58 "successText",
59 "ladderUsed",
60 "electrophoresisVoltage",
61 "gelRunningTime",
62 "gelConcentration",
63 "gelPhoto",
64 "singleReads"
65 })
66 @XmlRootElement(name = "Amplification")
67 @Entity
68 @Audited
69 public class Amplification extends EventBase implements Cloneable{
70 private static final long serialVersionUID = -8614860617229484621L;
71 private static final Logger logger = Logger.getLogger(Amplification.class);
72
73
74 /** @see #getDnaSample() */
75 @XmlElement( name = "DnaSample")
76 @XmlIDREF
77 @XmlSchemaType(name = "IDREF")
78 @ManyToOne(fetch = FetchType.LAZY)
79 @IndexedEmbedded
80 private DnaSample dnaSample;
81
82 @XmlElementWrapper(name = "SingleReads")
83 @XmlElement(name = "SingleRead")
84 @XmlIDREF
85 @XmlSchemaType(name = "IDREF")
86 @OneToMany(fetch = FetchType.LAZY)
87 @Cascade({CascadeType.SAVE_UPDATE})
88 private Set<SingleRead> singleReads = new HashSet<SingleRead>();
89
90 /** @see #getMarker()*/
91 @XmlElement(name = "DnaMarker")
92 @XmlIDREF
93 @XmlSchemaType(name = "IDREF")
94 @ManyToOne(fetch=FetchType.EAGER)
95 private DefinedTerm dnaMarker;
96
97 /** @see #getForwardPrimer() */
98 @XmlElement(name = "ForwardPrimer")
99 @XmlIDREF
100 @XmlSchemaType(name = "IDREF")
101 @ManyToOne(fetch=FetchType.LAZY)
102 @Cascade({CascadeType.SAVE_UPDATE})
103 private Primer forwardPrimer;
104
105 /** @see #getReversePrimer()*/
106 @XmlElement(name = "ReversePrimer")
107 @XmlIDREF
108 @XmlSchemaType(name = "IDREF")
109 @ManyToOne(fetch=FetchType.LAZY)
110 @Cascade({CascadeType.SAVE_UPDATE})
111 private Primer reversePrimer;
112
113
114 @XmlElement(name = "Purification")
115 @XmlIDREF
116 @XmlSchemaType(name = "IDREF")
117 @ManyToOne(fetch=FetchType.LAZY)
118 @Cascade({CascadeType.SAVE_UPDATE})
119 private MaterialOrMethodEvent purification;
120
121 @XmlElement(name = "Cloning")
122 @XmlIDREF
123 @XmlSchemaType(name = "IDREF")
124 @ManyToOne(fetch=FetchType.LAZY)
125 @Cascade({CascadeType.SAVE_UPDATE})
126 private Cloning cloning;
127
128
129 /** @see #getSuccessful() */
130 @XmlAttribute(name = "successful")
131 private Boolean successful;
132
133 /** @see #getSuccessText() */
134 @XmlElement(name = "successText")
135 @Field
136 @Size(max=255)
137 private String successText;
138
139 /** @see #getLadderUsed() */
140 @XmlElement(name = "ladderUsed")
141 @Field
142 @Size(max=255)
143 private String ladderUsed;
144
145 /** @see #getElectrophoresisVoltage()*/
146 @XmlElement(name = "electrophoresisVoltage")
147 @Field(analyze = Analyze.NO)
148 @NumericField
149 private Double electrophoresisVoltage;
150
151 /** @see #getGelRunningTime() */
152 @XmlElement(name = "gelRunningTime")
153 @Field(analyze = Analyze.NO)
154 @NumericField
155 private Double gelRunningTime;
156
157 /** @see #getGelConcentration() */
158 @XmlElement(name = "gelConcentration")
159 @Field(analyze = Analyze.NO)
160 @NumericField
161 private Double gelConcentration;
162
163 @XmlElement(name = "GelPhoto")
164 @XmlIDREF
165 @XmlSchemaType(name = "IDREF")
166 @ManyToOne(fetch=FetchType.LAZY)
167 @Cascade({CascadeType.SAVE_UPDATE})
168 private Media gelPhoto;
169
170
171 // ********************* FACTORY METHODS ************************/
172
173 public static Amplification NewInstance(DnaSample dnaSample){
174 Amplification result = new Amplification();
175 dnaSample.addAmplification(result);
176 return result;
177 }
178
179
180 // ******************* CONSTRUCTOR *******************************/
181
182 private Amplification(){}
183
184
185 //********************* GETTER / SETTER ************/
186
187
188 /**
189 * The {@link DnaSample dna sample} which is the input for this {@link Amplification amplification}.
190 */
191 public DnaSample getDnaSample() {
192 return dnaSample;
193 }
194
195 /**
196 * For use by DnaSample.addAmplification(ampl.) only. For now.
197 * @see #getDnaSample()
198 */
199 protected void setDnaSample(DnaSample dnaSample) {
200 this.dnaSample = dnaSample;
201 }
202
203 /**
204 * The {@link SingleRead single sequences} created by using this amplification's result.
205 */
206 public Set<SingleRead> getSingleReads() {
207 return singleReads;
208 }
209
210 public void addSingleRead(SingleRead singleRead){
211 if (singleRead.getAmplification() != null){
212 singleRead.getAmplification().singleReads.remove(singleRead);
213 }
214 this.singleReads.add(singleRead);
215 singleRead.setAmplification(this);
216 }
217
218 /**
219 * @see #getSingleReads()
220 */
221 //TODO private until it is clear how bidirectionality is handled
222 private void setSingleReads(Set<SingleRead> singleReads) {
223 this.singleReads = singleReads;
224 }
225
226
227 /**
228 * The {@link TermType#DnaMarker marker} examined by this amplification.
229 */
230 public DefinedTerm getMarker() {
231 return dnaMarker;
232 }
233
234 /**
235 * @see #getMarker()
236 */
237 public void setMarker(DefinedTerm marker) {
238 this.dnaMarker = marker;
239 }
240
241 /**
242 * The primer used for forward amplification.
243 * @see #getReversePrimer()
244 */
245 public Primer getForwardPrimer() {
246 return forwardPrimer;
247 }
248
249 /**
250 * @see #getForwardPrimer()
251 * @see #getReversePrimer()
252 */
253 public void setForwardPrimer(Primer forwardPrimer) {
254 this.forwardPrimer = forwardPrimer;
255 }
256
257 /**
258 * The primer used for reverse amplification.
259 * @see #getForwardPrimer()
260 */
261 public Primer getReversePrimer() {
262 return reversePrimer;
263 }
264
265 /**
266 * @see #getReversePrimer()
267 * @see #getForwardPrimer()
268 */
269 public void setReversePrimer(Primer reversePrimer) {
270 this.reversePrimer = reversePrimer;
271 }
272
273 /**
274 * Information if this amplification was successful or not. Success may be defined
275 * by the results of the electrophoresis.
276 *
277 * @see #getSuccessText()
278 */
279 public Boolean getSuccessful() {
280 return successful;
281 }
282
283 /**
284 * @see #getSuccessful()
285 * @see #getSuccessText()
286 */
287 public void setSuccessful(Boolean successful) {
288 this.successful = successful;
289 }
290
291 /**
292 * Freetext about the success of this amplification explaining
293 * in detail why it is concidered to be successful/unsucessful
294 *
295 * @see #getSuccessful()
296 */
297 public String getSuccessText() {
298 return successText;
299 }
300
301 /**
302 * @see #getSuccessText()
303 * @see #getSuccessful()
304 */
305 public void setSuccessText(String successText) {
306 this.successText = successText;
307 }
308
309
310 /**
311 * The material and/or method used for purification.
312 */
313 public MaterialOrMethodEvent getPurification() {
314 return purification;
315 }
316
317 /**
318 * @see #getPurification()
319 */
320 public void setPurification(MaterialOrMethodEvent purification) {
321 this.purification = purification;
322 }
323
324
325 /**
326 * The cloning process (including materials and methods) involved in this amplification.
327 */
328 public Cloning getCloning() {
329 return cloning;
330 }
331
332 /**
333 * @see #getCloning()
334 */
335 public void setCloning(Cloning cloning) {
336 this.cloning = cloning;
337 }
338
339 /**
340 * The voltage used for running the electrophoresis quality check.
341 * Base unit is [V].
342 * @see #getGelRunningTime()
343 * @see #getGelPhoto()
344 * @see #getLadderUsed()
345 * @see #getGelConcentration()
346
347 */
348 public Double getElectrophoresisVoltage() {
349 return electrophoresisVoltage;
350 }
351
352 /**
353 * @see #getElectrophoresisVoltage()
354 */
355 public void setElectrophoresisVoltage(Double electrophoresisVoltage) {
356 this.electrophoresisVoltage = electrophoresisVoltage;
357 }
358
359 /**
360 * The time for running the electrophoresis quality check.
361 */
362 public Double getGelRunningTime() {
363 return gelRunningTime;
364 }
365
366 /**
367 * @see #getGelRunningTime()
368 */
369 public void setGelRunningTime(Double gelRunningTime) {
370 this.gelRunningTime = gelRunningTime;
371 }
372
373
374 /**
375 * The gel concentration used for the electrophoresis.
376 * @see #getElectrophoresisVoltage()
377 * @see #getGelRunningTime()
378 * @see #getGelPhoto()
379 * @see #getLadderUsed()
380 */
381 public Double getGelConcentration() {
382 return gelConcentration;
383 }
384
385 /**
386 * @see #getGelConcentration()
387 */
388 public void setGelConcentration(Double gelConcentration) {
389 this.gelConcentration = gelConcentration;
390 }
391
392 /**
393 * Material and method used for testing quality of this amplification.
394 * @see #getElectrophoresisVoltage()
395 * @see #getGelPhoto()
396 * @see #getGelConcentration()
397 * @see #getGelRunningTime()
398 */
399 public String getLadderUsed() {
400 return ladderUsed;
401 }
402
403 /**
404 * @see #getLadderUsed()
405 */
406 public void setLadderUsed(String ladderUsed) {
407 this.ladderUsed = ladderUsed;
408 }
409
410 /**
411 * The photo taken from the electrophoresis result showing the quality of the amplification.
412 * Gelphotos often do show multiple electrophoresis results. One may either cut or mark
413 * the part of the photo that displays <code>this</code> amplification.
414 * @see #getElectrophoresisVoltage()
415 * @see #getLadderUsed()
416 * @see #getGelConcentration()
417 * @see #getGelRunningTime()
418 */
419 public Media getGelPhoto() {
420 return gelPhoto;
421 }
422
423
424 /**
425 * @param gelPhoto the gelPhoto to set
426 */
427 public void setGelPhoto(Media gelPhoto) {
428 this.gelPhoto = gelPhoto;
429 }
430
431
432 // ********************** CLONE ***********************************/
433 /**
434 * Clones <i>this</i> amplification. This is a shortcut that enables to create
435 * a new instance that differs only slightly from <i>this</i> amplification by
436 * modifying only some of the attributes.<BR><BR>
437 *
438 *
439 * @see EventBase#clone()
440 * @see java.lang.Object#clone()
441 */
442 @Override
443 public Object clone() {
444 try{
445 Amplification result = (Amplification)super.clone();
446
447 result.singleReads = new HashSet<SingleRead>();
448 for (SingleRead seq: this.singleReads){
449 result.singleReads.add((SingleRead) seq);
450
451 }
452
453 //don't change dnaSample, marker, successful, successText, forwardPrimer,
454 //reversePrimer, purifiaction, cloning, ladderUsed, electrophoresisVoltage,
455 //gelRunningTime, gelPhoto, gelConcentration
456 return result;
457 }catch (CloneNotSupportedException e) {
458 logger.warn("Object does not implement cloneable");
459 e.printStackTrace();
460 return null;
461 }
462 }
463
464
465 }