final implementation of MaterialOrMethodEvent, Cloning, PreservationMethod, ... ...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / SingleRead.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 javax.persistence.Entity;
12 import javax.persistence.Enumerated;
13 import javax.persistence.FetchType;
14 import javax.persistence.ManyToOne;
15 import javax.persistence.Transient;
16 import javax.xml.bind.annotation.XmlAccessType;
17 import javax.xml.bind.annotation.XmlAccessorType;
18 import javax.xml.bind.annotation.XmlAttribute;
19 import javax.xml.bind.annotation.XmlElement;
20 import javax.xml.bind.annotation.XmlIDREF;
21 import javax.xml.bind.annotation.XmlRootElement;
22 import javax.xml.bind.annotation.XmlSchemaType;
23 import javax.xml.bind.annotation.XmlType;
24
25 import org.apache.log4j.Logger;
26 import org.hibernate.annotations.Type;
27 import org.hibernate.envers.Audited;
28
29 import eu.etaxonomy.cdm.model.agent.AgentBase;
30 import eu.etaxonomy.cdm.model.common.EventBase;
31 import eu.etaxonomy.cdm.model.common.TimePeriod;
32 import eu.etaxonomy.cdm.model.media.Media;
33 import eu.etaxonomy.cdm.model.occurrence.MaterialOrMethodEvent;
34
35 /**
36 * Instances of this the {@link SingleRead} class describe the process and the result of a single
37 * sequence generation (read). It has as an input the PCR result ({@link Amplification}). A primer
38 * is used for expressing the DNA in either {@link SequenceDirection#Forward forward} or
39 * {@link SequenceDirection#Reverse reverse} direction.
40 * The result of the process is a {@link #getPherogram() pherogram} which by interpretation results
41 * in the most probable {@link #getSequence() sequence}.
42 * The event dates like the sequencing date and the sequencing agent(person) are inherited by {@link EventBase}.
43 *
44 * @see Amplification
45 * @see SequenceString
46 * @see Sequence
47 *
48 * @author a.mueller
49 * @created 2013-07-05
50 */
51 @XmlAccessorType(XmlAccessType.FIELD)
52 @XmlType(name = "SingleRead", propOrder = {
53 "amplification",
54 "sequence",
55 "primer",
56 "direction",
57 "pherogram",
58 "materialOrMethod"
59 })
60 @XmlRootElement(name = "Primer")
61 @Entity
62 @Audited
63 public class SingleRead extends EventBase implements Cloneable{
64 private static final long serialVersionUID = 1735535003073536132L;
65 private static final Logger logger = Logger.getLogger(SingleRead.class);
66
67 /** @see #getAmplification() */
68 @XmlElement(name = "Amplification")
69 @XmlIDREF
70 @XmlSchemaType(name = "IDREF")
71 @ManyToOne(fetch = FetchType.LAZY)
72 private Amplification amplification;
73
74 /** @see #getPrimer()*/
75 @XmlElement(name = "Primer")
76 @XmlIDREF
77 @XmlSchemaType(name = "IDREF")
78 @ManyToOne(fetch = FetchType.LAZY)
79 private Primer primer;
80
81 /** @see #getSequence()*/
82 /**{@link #getSequence()}*/
83 @XmlElement(name = "Sequence")
84 private SequenceString sequence = SequenceString.NewInstance();
85
86 @XmlElement(name = "Pherogram")
87 @XmlIDREF
88 @XmlSchemaType(name = "IDREF")
89 @ManyToOne(fetch = FetchType.LAZY)
90 private Media pherogram;
91
92 /** @see #getDirection()*/
93 @XmlAttribute(name ="direction")
94 //TODO length = 3
95 @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
96 parameters = {@org.hibernate.annotations.Parameter(name = "enumClass", value = "eu.etaxonomy.cdm.model.molecular.SequenceDirection")}
97 )
98 private SequenceDirection direction;
99
100 @XmlElement(name = "MaterialOrMethod")
101 @XmlIDREF
102 @XmlSchemaType(name = "IDREF")
103 @ManyToOne(fetch = FetchType.LAZY)
104 private MaterialOrMethodEvent materialOrMethod;
105
106
107 // ******************** FACTORY METHOD ******************/
108
109 public static SingleRead NewInstance(){
110 return new SingleRead();
111 }
112
113 // ********************* CONSTRUCTOR ********************/
114
115 private SingleRead(){};
116
117 // ********************* GETTER / SETTER ********************/
118
119
120 /**
121 * Returns the {@link Amplification amplification} that was the input for this
122 * {@link SingleRead single sequence}.
123 */
124 public Amplification getAmplification() {
125 return amplification;
126 }
127
128 /**
129 * TODO this method is protected as long as bidirectionality is not clear.
130 * @see #getAmplification()
131 */
132 protected void setAmplification(Amplification amplification) {
133 this.amplification = amplification;
134 }
135
136 /**
137 * The {@link Primer primer} used for processing this single sequence.
138 */
139 public Primer getPrimer() {
140 return primer;
141 }
142
143 /**
144 * @see #getPrimer()
145 */
146 public void setPrimer(Primer primer) {
147 this.primer = primer;
148 }
149
150 /**
151 * The {@link SequenceString sequence string} of this single sequence process (e.g. AGTGGTAGGATG)
152 */
153 public SequenceString getSequence() {
154 return sequence;
155 }
156
157 /**
158 * @see #getSequence()
159 */
160 public void setSequence(SequenceString sequence) {
161 if (sequence == null){
162 SequenceString.NewInstance();
163 }
164 this.sequence = sequence;
165 }
166
167 /**
168 * The direction in which this single sequence has been created.
169 * Usually an amplification and a sequencing has a forward single sequence and/or
170 * a reverse single sequence.
171 */
172 public SequenceDirection getDirection() {
173 return direction;
174 }
175
176 /**
177 * @see #getDirection()
178 */
179 public void setDirection(SequenceDirection direction) {
180 this.direction = direction;
181 }
182
183 /**
184 * The pherogram (chromatogram) which visualizes the result of this single sequence.
185 */
186 public Media getPherogram() {
187 return pherogram;
188 }
189
190 /**
191 * @see #getPherogram()
192 */
193 public void setPherogram(Media pherogram) {
194 this.pherogram = pherogram;
195 }
196
197
198 /**
199 * The material and/or method used for this sequencing.
200 */
201 public MaterialOrMethodEvent getMaterialOrMethod() {
202 return materialOrMethod;
203 }
204
205 /**
206 * @see #getMaterialOrMethod()
207 */
208 public void setMaterialOrMethod(MaterialOrMethodEvent materialOrMethod) {
209 this.materialOrMethod = materialOrMethod;
210 }
211
212
213
214 //*************************** Transient GETTER /SETTER *****************************/
215 /**
216 * Delegate method to get the text representation of the {@link #getSequence() sequence}.
217 * @see #setSequenceString(String)
218 */
219 @Transient
220 public String getSequenceString() {
221 return sequence.getString();
222 }
223
224 /**
225 * Delegate method to set the text representation of the {@link #getSequence() sequence}.
226 */
227 @Transient
228 public void setSequenceString(String sequence) {
229 this.sequence.setString(sequence);
230 }
231
232 /**
233 * Transient convenience method which wrapps {@link EventBase#getActor()}.
234 * @return the {@link TimePeriod date/period} when this sequence was created.
235 */
236 @Transient
237 public TimePeriod getDateSequenced(){
238 return ((EventBase)this).getTimeperiod();
239 }
240
241 /**
242 * @see #getDateSequenced()
243 */
244 public void setDateSequenced(TimePeriod dateSequenced){
245 this.setTimeperiod(dateSequenced);
246 }
247
248 /**
249 * Transient convenience method which wrapps {@link EventBase#getActor()}.
250 * @return the {@link AgentBase agent} who sequenced this single sequence.
251 */
252 @Transient
253 public AgentBase getSequencedBy(){
254 return ((EventBase)this).getActor();
255 }
256
257 /**
258 * @see #getSequencedBy()
259 */
260 public void setSequencedBy(AgentBase sequencedBy){
261 this.setActor(sequencedBy);
262 }
263
264
265 // ********************* CLONE ********************/
266 /**
267 * Clones <i>this</i> sequence. This is a shortcut that enables to create
268 * a new instance that differs only slightly from <i>this</i> sequencing by
269 * modifying only some of the attributes.<BR><BR>
270 *
271 *
272 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
273 * @see java.lang.Object#clone()
274 */
275 @Override
276 public Object clone() {
277 try{
278 SingleRead result = (SingleRead)super.clone();
279
280 //sequences
281 result.sequence = (SequenceString)this.sequence.clone();
282
283
284 //Don't change amplification, pherogram, primer, sequence, direction
285 return result;
286
287 }catch (CloneNotSupportedException e) {
288 logger.warn("Object does not implement cloneable");
289 e.printStackTrace();
290 return null;
291 }
292 }
293
294 }