4 package eu
.etaxonomy
.cdm
.model
.molecular
;
6 import javax
.persistence
.Entity
;
7 import javax
.persistence
.FetchType
;
8 import javax
.persistence
.Lob
;
9 import javax
.persistence
.ManyToOne
;
10 import javax
.xml
.bind
.annotation
.XmlAccessType
;
11 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
12 import javax
.xml
.bind
.annotation
.XmlElement
;
13 import javax
.xml
.bind
.annotation
.XmlIDREF
;
14 import javax
.xml
.bind
.annotation
.XmlRootElement
;
15 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
16 import javax
.xml
.bind
.annotation
.XmlType
;
18 import org
.hibernate
.annotations
.Cascade
;
19 import org
.hibernate
.annotations
.CascadeType
;
20 import org
.hibernate
.annotations
.Type
;
21 import org
.hibernate
.envers
.Audited
;
23 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
28 @XmlAccessorType(XmlAccessType
.FIELD
)
29 @XmlType(name
= "SingleReadAlignment", propOrder
= {
36 @XmlRootElement(name
= "SingleReadAlignment")
39 public class SingleReadAlignment
extends VersionableEntity
{
40 private static final long serialVersionUID
= 6141518347067279304L;
42 /** @see #getDnaMarker() */
43 @XmlElement(name
= "ConsensusAlignment")
45 @XmlSchemaType(name
= "IDREF")
46 @ManyToOne(fetch
= FetchType
.LAZY
)
47 //for now we do not cascade but expect the user to save the sequence manually
48 private Sequence consensusAlignment
;
50 /** @see #getDnaMarker() */
51 @XmlElement(name
= "SingleRead")
53 @XmlSchemaType(name
= "IDREF")
54 @ManyToOne(fetch
= FetchType
.LAZY
)
55 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
})
56 private SingleRead singleRead
;
58 //TODO XML mapping / user type
59 @Type(type
="shiftUserType")
60 private Shift
[] shifts
= new Shift
[0];
63 private Integer firstSeqPosition
;
65 private Integer leftCutPosition
;
67 private Integer rightCutPosition
;
69 @XmlElement(name
= "EditedSequence")
71 private String editedSequence
;
73 @XmlElement(name
= "ReverseComplement")
74 private boolean reverseComplement
;
77 public static class Shift
implements Cloneable
{
82 public Shift(int position
, int steps
) {
83 this.position
= position
;
88 public String
toString(){
89 return String
.valueOf(position
) + "," + String
.valueOf(shift
);
92 protected Object
clone() throws CloneNotSupportedException
{
97 //****************** FACTORY *******************/
99 public static SingleReadAlignment
NewInstance(Sequence consensusSequence
, SingleRead singleRead
){
100 return new SingleReadAlignment(consensusSequence
, singleRead
, null, null);
103 public static SingleReadAlignment
NewInstance(Sequence consensusSequence
, SingleRead singleRead
,
104 Shift
[] shifts
, String editedSequence
){
105 return new SingleReadAlignment(consensusSequence
, singleRead
, shifts
, editedSequence
);
108 // ***************** CONSTRUCTOR *************************/
110 protected SingleReadAlignment(){};
112 private SingleReadAlignment(Sequence consensusAlignment
, SingleRead singleRead
,
113 Shift
[] shifts
, String editedSequence
){
114 setConsensusAlignment(consensusAlignment
);
115 setSingleRead(singleRead
);
116 this.shifts
= shifts
;
117 this.editedSequence
= editedSequence
;
121 // ****************** GETTER / SETTER ***********************/
124 public Sequence
getConsensusSequence() {
125 return consensusAlignment
;
127 public void setConsensusAlignment(Sequence consensusAlignment
) {
128 if (this.consensusAlignment
!= null && this.consensusAlignment
.getSingleReadAlignments().contains(this)){
129 this.consensusAlignment
.removeSingleReadAlignment(this);
131 this.consensusAlignment
= consensusAlignment
;
132 if (consensusAlignment
!= null && ! consensusAlignment
.getSingleReadAlignments().contains(this)){
133 consensusAlignment
.addSingleReadAlignment(this);
137 public SingleRead
getSingleRead() {
140 public void setSingleRead(SingleRead singleRead
) {
141 // if (this.singleRead != null xxx){
142 // this.singleRead.removeSingleReadAlignment(this);
144 this.singleRead
= singleRead
;
145 // if (singleRead != null && singleRead.getSingleReadAlignments().contains(this)){
146 // singleRead.addSingleReadAlignment(this);
151 public Shift
[] getShifts() {
152 return shifts
== null ?
new Shift
[0] : shifts
;
154 public void setShifts(Shift
[] shifts
) {
155 this.shifts
= shifts
;
157 shifts
= new Shift
[0];
162 public String
getEditedSequence() {
163 return editedSequence
;
166 public void setEditedSequence(String editedSequence
) {
167 this.editedSequence
= editedSequence
;
171 public boolean isReverseComplement() {
172 return reverseComplement
;
175 public void setReverseComplement(boolean reverseComplement
) {
176 this.reverseComplement
= reverseComplement
;
179 // ******************* CLONE *********************/
184 public Object
clone() throws CloneNotSupportedException
{
185 SingleReadAlignment result
= (SingleReadAlignment
)super.clone();
188 Shift
[] oldShifts
= this.getShifts();
189 int shiftLength
= oldShifts
.length
;
190 Shift
[] newShift
= new Shift
[shiftLength
];
191 for (int i
= 0; i
< shiftLength
; i
++){
192 Shift oldShift
= oldShifts
[i
];
193 newShift
[0] = (Shift
)oldShift
.clone();
196 //all other objects can be reused
201 * Returns the position in the {@link Sequence sequence}
202 * this {@link SingleReadAlignment single read align} is attached to
203 * where the output of the visible part of the pherogram starts.
204 * @return a valid index in the sequence carrying this data area
205 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/dataarea/implementations/pherogram/PherogramArea.html#getFirstSeqPos
208 public Integer
getFirstSeqPosition() {
209 return firstSeqPosition
;
213 * @see #getFirstSeqPosition()
215 public void setFirstSeqPosition(Integer firstSeqPosition
) {
216 this.firstSeqPosition
= firstSeqPosition
;
220 * Returns the first base call index of the pherogram which has not been cut off.
221 * @return a base call index > 0
222 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/pherogram/PherogramComponent.html#getLeftCutPosition
224 public Integer
getLeftCutPosition() {
225 return leftCutPosition
;
229 * @param see {@link #getLeftCutPosition()}
231 public void setLeftCutPosition(Integer leftCutPosition
) {
232 this.leftCutPosition
= leftCutPosition
;
236 * Returns the first base call index of the pherogram that has been cut off (so that the length of the visible
237 * area of the pherogram can be calculated as getRightCutPosition()
238 * @return a base call inde
239 * @see http://bioinfweb.info/LibrAlign/Documentation/api/latest/info/bioinfweb/libralign/pherogram/PherogramComponent.html#getRightCutPosition
241 public Integer
getRightCutPosition() {
242 return rightCutPosition
;
246 * @param see {@link #getRightCutPosition()}
248 public void setRightCutPosition(Integer rightCutPosition
) {
249 this.rightCutPosition
= rightCutPosition
;