1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.model.molecular;
|
5
|
|
6
|
import java.io.Serializable;
|
7
|
|
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;
|
19
|
|
20
|
import org.hibernate.annotations.Cascade;
|
21
|
import org.hibernate.annotations.CascadeType;
|
22
|
import org.hibernate.annotations.Type;
|
23
|
import org.hibernate.envers.Audited;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
*/
|
30
|
@XmlAccessorType(XmlAccessType.FIELD)
|
31
|
@XmlType(name = "SingleReadAlignment", propOrder = {
|
32
|
"consensusAlignment",
|
33
|
"singleRead",
|
34
|
"shifts",
|
35
|
"editedSequence",
|
36
|
"reverseComplement",
|
37
|
"firstSeqPosition",
|
38
|
"leftCutPosition",
|
39
|
"rightCutPosition"
|
40
|
})
|
41
|
@XmlRootElement(name = "SingleReadAlignment")
|
42
|
@Entity
|
43
|
@Audited
|
44
|
public class SingleReadAlignment extends VersionableEntity implements Serializable {
|
45
|
private static final long serialVersionUID = 6141518347067279304L;
|
46
|
|
47
|
/** @see #getDnaMarker() */
|
48
|
@XmlElement(name = "ConsensusAlignment")
|
49
|
@XmlIDREF
|
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;
|
54
|
|
55
|
/** @see #getDnaMarker() */
|
56
|
@XmlElement(name = "SingleRead")
|
57
|
@XmlIDREF
|
58
|
@XmlSchemaType(name = "IDREF")
|
59
|
@OneToOne(fetch = FetchType.LAZY)
|
60
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
61
|
private SingleRead singleRead;
|
62
|
|
63
|
//TODO XML mapping / user type
|
64
|
@Type(type="shiftUserType")
|
65
|
private Shift[] shifts = new Shift[0];
|
66
|
|
67
|
private Integer firstSeqPosition;
|
68
|
|
69
|
private Integer leftCutPosition;
|
70
|
|
71
|
private Integer rightCutPosition;
|
72
|
|
73
|
@XmlElement(name = "EditedSequence")
|
74
|
@Lob
|
75
|
private String editedSequence;
|
76
|
|
77
|
@XmlElement(name = "ReverseComplement")
|
78
|
private boolean reverseComplement;
|
79
|
|
80
|
|
81
|
public static class Shift implements Cloneable, Serializable {
|
82
|
public int position;
|
83
|
public int shift;
|
84
|
|
85
|
public Shift(){};
|
86
|
public Shift(int position, int steps) {
|
87
|
this.position = position;
|
88
|
this.shift = steps;
|
89
|
}
|
90
|
|
91
|
@Override
|
92
|
public String toString(){
|
93
|
return String.valueOf(position) + "," + String.valueOf(shift);
|
94
|
}
|
95
|
@Override
|
96
|
protected Object clone() throws CloneNotSupportedException {
|
97
|
return super.clone();
|
98
|
}
|
99
|
}
|
100
|
|
101
|
//****************** FACTORY *******************/
|
102
|
|
103
|
public static SingleReadAlignment NewInstance(Sequence consensusSequence, SingleRead singleRead){
|
104
|
return new SingleReadAlignment(consensusSequence, singleRead, null, null);
|
105
|
}
|
106
|
|
107
|
public static SingleReadAlignment NewInstance(Sequence consensusSequence, SingleRead singleRead,
|
108
|
Shift[] shifts, String editedSequence){
|
109
|
return new SingleReadAlignment(consensusSequence, singleRead, shifts, editedSequence);
|
110
|
}
|
111
|
|
112
|
// ***************** CONSTRUCTOR *************************/
|
113
|
|
114
|
protected SingleReadAlignment(){};
|
115
|
|
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;
|
122
|
}
|
123
|
|
124
|
|
125
|
// ****************** GETTER / SETTER ***********************/
|
126
|
|
127
|
//consensus sequence
|
128
|
public Sequence getConsensusSequence() {
|
129
|
return consensusAlignment;
|
130
|
}
|
131
|
public void setConsensusAlignment(Sequence consensusAlignment) {
|
132
|
if (this.consensusAlignment != null && this.consensusAlignment.getSingleReadAlignments().contains(this)){
|
133
|
this.consensusAlignment.removeSingleReadAlignment(this);
|
134
|
}
|
135
|
this.consensusAlignment = consensusAlignment;
|
136
|
if (consensusAlignment != null && ! consensusAlignment.getSingleReadAlignments().contains(this)){
|
137
|
consensusAlignment.addSingleReadAlignment(this);
|
138
|
}
|
139
|
}
|
140
|
|
141
|
public SingleRead getSingleRead() {
|
142
|
return singleRead;
|
143
|
}
|
144
|
public void setSingleRead(SingleRead singleRead) {
|
145
|
// if (this.singleRead != null xxx){
|
146
|
// this.singleRead.removeSingleReadAlignment(this);
|
147
|
// }
|
148
|
this.singleRead = singleRead;
|
149
|
// if (singleRead != null && singleRead.getSingleReadAlignments().contains(this)){
|
150
|
// singleRead.addSingleReadAlignment(this);
|
151
|
// }
|
152
|
}
|
153
|
|
154
|
//shifts
|
155
|
public Shift[] getShifts() {
|
156
|
return shifts == null ? new Shift[0] : shifts;
|
157
|
}
|
158
|
public void setShifts(Shift[] shifts) {
|
159
|
this.shifts = shifts;
|
160
|
if (shifts == null){
|
161
|
shifts = new Shift[0];
|
162
|
}
|
163
|
}
|
164
|
|
165
|
//edited sequence
|
166
|
public String getEditedSequence() {
|
167
|
return editedSequence;
|
168
|
}
|
169
|
|
170
|
public void setEditedSequence(String editedSequence) {
|
171
|
this.editedSequence = editedSequence;
|
172
|
}
|
173
|
|
174
|
|
175
|
public boolean isReverseComplement() {
|
176
|
return reverseComplement;
|
177
|
}
|
178
|
|
179
|
public void setReverseComplement(boolean reverseComplement) {
|
180
|
this.reverseComplement = reverseComplement;
|
181
|
}
|
182
|
|
183
|
// ******************* CLONE *********************/
|
184
|
|
185
|
|
186
|
|
187
|
@Override
|
188
|
public Object clone() throws CloneNotSupportedException {
|
189
|
SingleReadAlignment result = (SingleReadAlignment)super.clone();
|
190
|
|
191
|
//deep copy shifts
|
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();
|
198
|
}
|
199
|
|
200
|
//all other objects can be reused
|
201
|
return result;
|
202
|
}
|
203
|
|
204
|
/**
|
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
|
210
|
*
|
211
|
*/
|
212
|
public Integer getFirstSeqPosition() {
|
213
|
return firstSeqPosition;
|
214
|
}
|
215
|
|
216
|
/**
|
217
|
* @see #getFirstSeqPosition()
|
218
|
*/
|
219
|
public void setFirstSeqPosition(Integer firstSeqPosition) {
|
220
|
this.firstSeqPosition = firstSeqPosition;
|
221
|
}
|
222
|
|
223
|
/**
|
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
|
227
|
*/
|
228
|
public Integer getLeftCutPosition() {
|
229
|
return leftCutPosition;
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* @param see {@link #getLeftCutPosition()}
|
234
|
*/
|
235
|
public void setLeftCutPosition(Integer leftCutPosition) {
|
236
|
this.leftCutPosition = leftCutPosition;
|
237
|
}
|
238
|
|
239
|
/**
|
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
|
244
|
*/
|
245
|
public Integer getRightCutPosition() {
|
246
|
return rightCutPosition;
|
247
|
}
|
248
|
|
249
|
/**
|
250
|
* @param see {@link #getRightCutPosition()}
|
251
|
*/
|
252
|
public void setRightCutPosition(Integer rightCutPosition) {
|
253
|
this.rightCutPosition = rightCutPosition;
|
254
|
}
|
255
|
|
256
|
}
|