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