4 package eu
.etaxonomy
.cdm
.model
.molecular
;
6 import java
.io
.Serializable
;
8 import javax
.persistence
.Entity
;
9 import javax
.persistence
.FetchType
;
10 import javax
.persistence
.Lob
;
11 import javax
.persistence
.ManyToOne
;
12 import javax
.xml
.bind
.annotation
.XmlAccessType
;
13 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
14 import javax
.xml
.bind
.annotation
.XmlElement
;
15 import javax
.xml
.bind
.annotation
.XmlIDREF
;
16 import javax
.xml
.bind
.annotation
.XmlRootElement
;
17 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
18 import javax
.xml
.bind
.annotation
.XmlType
;
20 import org
.hibernate
.annotations
.Cascade
;
21 import org
.hibernate
.annotations
.CascadeType
;
22 import org
.hibernate
.annotations
.Type
;
23 import org
.hibernate
.envers
.Audited
;
25 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
30 @XmlAccessorType(XmlAccessType
.FIELD
)
31 @XmlType(name
= "SingleReadAlignment", propOrder
= {
41 @XmlRootElement(name
= "SingleReadAlignment")
44 public class SingleReadAlignment
extends VersionableEntity
implements Serializable
{
45 private static final long serialVersionUID
= 6141518347067279304L;
47 /** @see #getDnaMarker() */
48 @XmlElement(name
= "ConsensusAlignment")
50 @XmlSchemaType(name
= "IDREF")
51 @ManyToOne(fetch
= FetchType
.LAZY
)
52 //for now we do not cascade but expect the user to save the sequence manually
53 private Sequence consensusAlignment
;
55 /** @see #getDnaMarker() */
56 @XmlElement(name
= "SingleRead")
58 @XmlSchemaType(name
= "IDREF")
59 @ManyToOne(fetch
= FetchType
.LAZY
)
60 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
})
61 private SingleRead singleRead
;
63 //TODO XML mapping / user type
64 @Type(type
="shiftUserType")
65 private Shift
[] shifts
= new Shift
[0];
67 private Integer firstSeqPosition
;
69 private Integer leftCutPosition
;
71 private Integer rightCutPosition
;
73 @XmlElement(name
= "EditedSequence")
75 private String editedSequence
;
77 @XmlElement(name
= "ReverseComplement")
78 private boolean reverseComplement
;
81 public static class Shift
implements Cloneable
, Serializable
{
86 public Shift(int position
, int steps
) {
87 this.position
= position
;
92 public String
toString(){
93 return String
.valueOf(position
) + "," + String
.valueOf(shift
);
96 protected Object
clone() throws CloneNotSupportedException
{
101 //****************** FACTORY *******************/
103 public static SingleReadAlignment
NewInstance(Sequence consensusSequence
, SingleRead singleRead
){
104 return new SingleReadAlignment(consensusSequence
, singleRead
, null, null);
107 public static SingleReadAlignment
NewInstance(Sequence consensusSequence
, SingleRead singleRead
,
108 Shift
[] shifts
, String editedSequence
){
109 return new SingleReadAlignment(consensusSequence
, singleRead
, shifts
, editedSequence
);
112 // ***************** CONSTRUCTOR *************************/
114 protected SingleReadAlignment(){};
116 private SingleReadAlignment(Sequence consensusAlignment
, SingleRead singleRead
,
117 Shift
[] shifts
, String editedSequence
){
118 setConsensusAlignment(consensusAlignment
);
119 setSingleRead(singleRead
);
120 this.shifts
= shifts
;
121 this.editedSequence
= editedSequence
;
125 // ****************** GETTER / SETTER ***********************/
128 public Sequence
getConsensusSequence() {
129 return consensusAlignment
;
131 public void setConsensusAlignment(Sequence consensusAlignment
) {
132 if (this.consensusAlignment
!= null && this.consensusAlignment
.getSingleReadAlignments().contains(this)){
133 this.consensusAlignment
.removeSingleReadAlignment(this);
135 this.consensusAlignment
= consensusAlignment
;
136 if (consensusAlignment
!= null && ! consensusAlignment
.getSingleReadAlignments().contains(this)){
137 consensusAlignment
.addSingleReadAlignment(this);
141 public SingleRead
getSingleRead() {
144 public void setSingleRead(SingleRead singleRead
) {
145 // if (this.singleRead != null xxx){
146 // this.singleRead.removeSingleReadAlignment(this);
148 this.singleRead
= singleRead
;
149 // if (singleRead != null && singleRead.getSingleReadAlignments().contains(this)){
150 // singleRead.addSingleReadAlignment(this);
155 public Shift
[] getShifts() {
156 return shifts
== null ?
new Shift
[0] : shifts
;
158 public void setShifts(Shift
[] shifts
) {
159 this.shifts
= shifts
;
161 shifts
= new Shift
[0];
166 public String
getEditedSequence() {
167 return editedSequence
;
170 public void setEditedSequence(String editedSequence
) {
171 this.editedSequence
= editedSequence
;
175 public boolean isReverseComplement() {
176 return reverseComplement
;
179 public void setReverseComplement(boolean reverseComplement
) {
180 this.reverseComplement
= reverseComplement
;
183 // ******************* CLONE *********************/
188 public Object
clone() throws CloneNotSupportedException
{
189 SingleReadAlignment result
= (SingleReadAlignment
)super.clone();
192 Shift
[] oldShifts
= this.getShifts();
193 int shiftLength
= oldShifts
.length
;
194 Shift
[] newShift
= new Shift
[shiftLength
];
195 for (int i
= 0; i
< shiftLength
; i
++){
196 Shift oldShift
= oldShifts
[i
];
197 newShift
[0] = (Shift
)oldShift
.clone();
200 //all other objects can be reused
205 * Returns the position in the {@link Sequence sequence}
206 * this {@link SingleReadAlignment single read align} is attached to
207 * where the output of the visible part of the pherogram starts.
208 * @return a valid index in the sequence carrying this data area
209 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/dataarea/implementations/pherogram/PherogramArea.html#getFirstSeqPos
212 public Integer
getFirstSeqPosition() {
213 return firstSeqPosition
;
217 * @see #getFirstSeqPosition()
219 public void setFirstSeqPosition(Integer firstSeqPosition
) {
220 this.firstSeqPosition
= firstSeqPosition
;
224 * Returns the first base call index of the pherogram which has not been cut off.
225 * @return a base call index > 0
226 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/pherogram/PherogramComponent.html#getLeftCutPosition
228 public Integer
getLeftCutPosition() {
229 return leftCutPosition
;
233 * @param see {@link #getLeftCutPosition()}
235 public void setLeftCutPosition(Integer leftCutPosition
) {
236 this.leftCutPosition
= leftCutPosition
;
240 * Returns the first base call index of the pherogram that has been cut off (so that the length of the visible
241 * area of the pherogram can be calculated as getRightCutPosition()
242 * @return a base call inde
243 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/pherogram/PherogramComponent.html#getRightCutPosition
245 public Integer
getRightCutPosition() {
246 return rightCutPosition
;
250 * @param see {@link #getRightCutPosition()}
252 public void setRightCutPosition(Integer rightCutPosition
) {
253 this.rightCutPosition
= rightCutPosition
;