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
.OneToOne
;
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 @OneToOne(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 @OneToOne(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 *********************/
186 public SingleReadAlignment
clone() throws CloneNotSupportedException
{
188 SingleReadAlignment result
= (SingleReadAlignment
)super.clone();
191 Shift
[] oldShifts
= this.getShifts();
192 int shiftLength
= oldShifts
.length
;
193 Shift
[] newShift
= new Shift
[shiftLength
];
194 for (int i
= 0; i
< shiftLength
; i
++){
195 Shift oldShift
= oldShifts
[i
];
196 newShift
[0] = (Shift
)oldShift
.clone();
199 //all other objects can be reused
204 * Returns the position in the {@link Sequence sequence}
205 * this {@link SingleReadAlignment single read align} is attached to
206 * where the output of the visible part of the pherogram starts.
207 * @return a valid index in the sequence carrying this data area
208 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/dataarea/implementations/pherogram/PherogramArea.html#getFirstSeqPos
211 public Integer
getFirstSeqPosition() {
212 return firstSeqPosition
;
216 * @see #getFirstSeqPosition()
218 public void setFirstSeqPosition(Integer firstSeqPosition
) {
219 this.firstSeqPosition
= firstSeqPosition
;
223 * Returns the first base call index of the pherogram which has not been cut off.
224 * @return a base call index > 0
225 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/pherogram/PherogramComponent.html#getLeftCutPosition
227 public Integer
getLeftCutPosition() {
228 return leftCutPosition
;
232 * @param see {@link #getLeftCutPosition()}
234 public void setLeftCutPosition(Integer leftCutPosition
) {
235 this.leftCutPosition
= leftCutPosition
;
239 * Returns the first base call index of the pherogram that has been cut off (so that the length of the visible
240 * area of the pherogram can be calculated as getRightCutPosition()
241 * @return a base call inde
242 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/pherogram/PherogramComponent.html#getRightCutPosition
244 public Integer
getRightCutPosition() {
245 return rightCutPosition
;
249 * @param see {@link #getRightCutPosition()}
251 public void setRightCutPosition(Integer rightCutPosition
) {
252 this.rightCutPosition
= rightCutPosition
;