Project

General

Profile

Download (3.91 KB) Statistics
| Branch: | Tag: | Revision:
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.io.Serializable;
12

    
13
import javax.persistence.Embeddable;
14
import javax.persistence.Lob;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlRootElement;
19
import javax.xml.bind.annotation.XmlType;
20

    
21
import org.apache.log4j.Logger;
22
import org.codehaus.plexus.util.StringUtils;
23

    
24
/**
25
 * A sequence contains the genetic code of a DNA or RNA part. It is basically a string
26
 * based on 4 letters: ATGC (Adenin, Thymin, Guanin, Cytosin) for DNA and AUGC (Thymin replaced by Uracil)
27
 * for RNA.
28
 * <BR>
29
 * The direction of the string shall always be 5'-3' which is a convention.
30
 * <BR>
31
 * The sequence has a length which is stored as such if no further information is given. If the sequence
32
 * string is given the length is computed automatically.
33
 *
34
 * @author a.mueller
35
 * @created 2013-07-05
36
 */
37
@XmlAccessorType(XmlAccessType.FIELD)
38
@XmlType(name = "SequenceString", propOrder = {
39
	"string",
40
	"length"
41
})
42
@XmlRootElement(name = "SequenceString")
43
@Embeddable
44
public class SequenceString implements Cloneable, Serializable{
45
	private static final long serialVersionUID = 45735207807329055L;
46
	private static final Logger logger = Logger.getLogger(SequenceString.class);
47

    
48
	/**{@link #getString()}*/
49
	@XmlElement(name = "String")
50
    @Lob
51
	private String string;
52

    
53
	@XmlElement(name = "Length")
54
	private Integer length;
55

    
56

    
57
// ******************** FACTORY METHOD ******************/
58

    
59
	public static SequenceString NewInstance(){
60
		SequenceString result = new SequenceString();
61
		return result;
62
	}
63

    
64
	public static SequenceString NewInstance(String sequence){
65
		SequenceString result = new SequenceString();
66
		result.setString(sequence);
67
		return result;
68
	}
69

    
70
// ********************* CONSTRUCTOR ********************/
71

    
72
	private SequenceString(){};
73

    
74
// ********************* GETTER / SETTER ********************/
75

    
76
	/**
77
	 * The sequence as a string of base pairs in direction 5'->3'.
78
	 */
79
	public String getString(){
80
		return this.string;
81
	}
82

    
83
	/**
84
	 * Sets the sequence. Also {@link #getLength() length information} will be set automatically.
85
	 * @see #getString()
86
	 * @param sequence    sequence
87
	 */
88
	public void setString(String sequence){
89
		this.string = sequence;
90
		this.length = (sequence == null ? 0 : sequence.length());
91
	}
92

    
93

    
94
	/**
95
	 * The length of the sequence. Will be calculated if the {@link #getString() sequence}  is set.
96
	 * @return the length of the sequence.
97
	 */
98
	public Integer getLength(){
99
		return this.length;
100
	}
101

    
102
	/**
103
	 * Sets the {@link #getLength() length}, if the {@link #getString() sequence} is not set.
104
	 * If {@link #getString() sequence}  is available, length has no effect.
105
	 * @see #getLength()
106
	 * @param length    length
107
	 */
108
	public void setLength(Integer length){
109
		if (StringUtils.isBlank(string)){
110
			this.length = length;
111
		}
112
	}
113

    
114

    
115
	// ********************* CLONE ********************/
116

    
117
	/**
118
	 * Clones <i>this</i> sequence. This is a shortcut that enables to create
119
	 * a new instance that differs only slightly from <i>this</i> sequencing by
120
	 * modifying only some of the attributes.<BR><BR>
121
	 *
122
	 *
123
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
124
	 * @see java.lang.Object#clone()
125
	 */
126
	@Override
127
	public Object clone()  {
128
		try{
129
		SequenceString result = (SequenceString)super.clone();
130

    
131
		//don't change sequence, length
132

    
133
		return result;
134
		}catch (CloneNotSupportedException e) {
135
			logger.warn("Object does not implement cloneable");
136
			e.printStackTrace();
137
			return null;
138
		}
139
	}
140
}
(10-10/14)