forked from biojava/biojava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProteinModificationImpl.java
More file actions
445 lines (369 loc) · 11.4 KB
/
ProteinModificationImpl.java
File metadata and controls
445 lines (369 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
* Created on May 27, 2010
* Author: Jianjiong Gao
*
*/
package org.biojava3.protmod;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* This class contains information about a specific protein
* modification.
*
* @author Jianjiong Gao
* @since 3.0
*/
public class ProteinModificationImpl
implements ProteinModification , Comparable<ProteinModification> {
private final String id;
private final ModificationCondition condition;
private final ModificationCategory category;
private final ModificationOccurrenceType occurrenceType;
private final String pdbccId;
private final String pdbccName;
private final String residId;
private final String residName;
private final String psimodId;
private final String psimodName;
private final String sysName;
private final String formula;
private final Set<String> keywords;
public String getId() {
return id;
}
public String getPdbccId() {
return pdbccId;
}
public String getPdbccName() {
return pdbccName;
}
public String getResidId() {
return residId;
}
public String getResidName() {
return residName;
}
public String getPsimodId() {
return psimodId;
}
public String getPsimodName() {
return psimodName;
}
public String getSystematicName() {
return sysName;
}
public String getDescription() {
return toString();
//return description;
}
public Set<String> getKeywords() {
return keywords;
}
public ModificationCondition getCondition() {
return condition;
}
public String getFormula() {
return formula;
}
public ModificationCategory getCategory() {
return category;
}
public ModificationOccurrenceType getOccurrenceType() {
return occurrenceType;
}
@Override
public String toString() {
return "ProteinModificationImpl [id=" + id + ", condition=" + condition
+ ", category=" + category + ", occurrenceType="
+ occurrenceType + ", pdbccId=" + pdbccId + ", pdbccName="
+ pdbccName + ", residId=" + residId + ", residName="
+ residName + ", psimodId=" + psimodId + ", psimodName="
+ psimodName + ", sysName=" + sysName + ", formula=" + formula
+ ", keywords=" + keywords + "]";
}
/*
private String printModification(ProteinModificationImpl mod) {
StringBuilder sb = new StringBuilder();
String name = getBestPossibleName(mod);
boolean hasName = true;
if ( name.equals(""))
hasName = false;
sb.append(name);
Set<String> keywords = mod.getKeywords();
if (keywords!=null && !keywords.isEmpty()) {
if ( hasName)
sb.append(" (");
for (String keyword : keywords) {
sb.append(keyword);
sb.append(", ");
}
sb.delete(sb.length()-2,sb.length());
}
if ( hasName)
sb.append(")");
return sb.toString();
}
private String getBestPossibleName(ProteinModificationImpl mod) {
//System.out.println(mod.getResidName() + " : " + mod.getPsimodName() + " : " + mod.getPdbccName() + " : " + mod.getSystematicName());
// first: get resid
String resid = mod.getResidId();
if (resid != null) {
String residname = mod.getResidName();
if (residname != null) {
return residname;
}
}
// 2nd: PSI-MOD
String name = mod.getPsimodName();
if ( name != null) {
//System.out.println("PSI_MOD name:" + name);
return name;
}
// 3rd PDB-CC
String pdbcc = mod.getPdbccName();
if ( pdbcc != null ) {
//System.out.println("PDBCC name: " + pdbcc);
return pdbcc;
}
// no public name know, use the systematic name
String systematic = mod.getSystematicName();
if ( systematic != null) {
//System.out.println("SYSTEMATIC NAME: " + mod.getSystematicName());
return systematic;
}
return "";
}
*/
public int hashCode() {
int ret = id.hashCode();
ret = ret * 31 + category.hashCode();
return ret;
}
public boolean equals(Object obj) {
if (!(obj instanceof ProteinModification))
return false;
ProteinModification mod = (ProteinModification)obj;
if (!id.equals(mod.getId()))
return false;
if (category != mod.getCategory())
return false;
return true;
}
/**
* Uses Builder pattern to build a ProteinModification.
*/
public static class Builder {
private final String id;
private ModificationCondition condition;
private ModificationCategory category;
private ModificationOccurrenceType occurrenceType;
private String pdbccId = null;
private String pdbccName = null;
private String residId = null;
private String residName = null;
private String psimodId = null;
private String psimodName = null;
private String sysName = null;
private String formula = null;
private Set<String> keywords = new LinkedHashSet<String>();
/**
*
* @param id
* @param cat
* @param occType
* @param condition
*/
public Builder(final String id, final ModificationCategory cat,
final ModificationOccurrenceType occType,
final ModificationCondition condition) {
if ( id == null) throw new IllegalArgumentException("id == null!");
if ( cat == null) throw new IllegalArgumentException("cat == null!");
if ( occType == null) throw new IllegalArgumentException("occType == null!");
if ( condition == null) throw new IllegalArgumentException("condition == null!");
this.id = id;
this.category = cat;
this.occurrenceType = occType;
this.condition = condition;
}
/**
* Create a Builder from an existing ProteinModification.
* @param copyFrom the ProteinModification to be copied from.
*/
public Builder(final ProteinModification copyFrom) {
this(copyFrom.getId(), copyFrom.getCategory(), copyFrom.getOccurrenceType(), copyFrom.getCondition());
this.pdbccId = copyFrom.getPdbccId();
this.pdbccName = copyFrom.getPdbccName();
this.residId = copyFrom.getResidId();
this.residName = copyFrom.getResidName();
this.psimodId = copyFrom.getPsimodId();
this.psimodName = copyFrom.getPsimodName();
this.sysName = copyFrom.getSystematicName();
this.formula = copyFrom.getFormula();
this.keywords = new LinkedHashSet<String>(copyFrom.getKeywords());
}
public Builder setCategory(final ModificationCategory cat) {
if (cat == null) throw new IllegalArgumentException("cat == null!");
this.category = cat;
return this;
}
public Builder setOccurrenceType(final ModificationOccurrenceType occType) {
if (occType == null) throw new IllegalArgumentException("occType == null!");
this.occurrenceType =occType;
return this;
}
public Builder setCondition(final ModificationCondition condition) {
if (condition == null) throw new IllegalArgumentException("condition == null!");
this.condition = condition;
return this;
}
/**
* Set the Protein Data Bank Chemical Component ID.
* @param pdbccId Protein Data Bank Chemical Component ID.
* @return the same Builder object so you can chain setters.
*/
public Builder setPdbccId(final String pdbccId) {
this.pdbccId = pdbccId;
return this;
}
/**
* Set the Protein Data Bank Chemical Component name.
* @param pdbccName Protein Data Bank Chemical Component name.
* @return the same Builder object so you can chain setters.
*/
public Builder setPdbccName(final String pdbccName) {
this.pdbccName = pdbccName;
return this;
}
/**
* Set the RESID ID.
* @param residId RESID ID.
* @return the same Builder object so you can chain setters.
*/
public Builder setResidId(final String residId) {
this.residId = residId;
return this;
}
/**
* Set the RESID name.
* @param residName RESID name.
* @return the same Builder object so you can chain setters.
*/
public Builder setResidName(final String residName) {
this.residName = residName;
return this;
}
/**
* Set the PSI-MOD ID.
* @param psimodId PSI-MOD ID.
* @return the same Builder object so you can chain setters.
*/
public Builder setPsimodId(final String psimodId) {
this.psimodId = psimodId;
return this;
}
/**
* Set the PSI-MOD name.
* @param psimodName PSI-MOD name.
* @return the same Builder object so you can chain setters.
*/
public Builder setPsimodName(final String psimodName) {
this.psimodName = psimodName;
return this;
}
/**
* Set the systematic name.
* @param sysName systematic name.
* @return the same Builder object so you can chain setters.
*/
public Builder setSystematicName(final String sysName) {
this.sysName = sysName;
return this;
}
/**
*
* @param description description of the modification.
* @return the same Builder object so you can chain setters.
*/
public Builder setDescription(final String description) {
// description is created on the fly in getDescription
return this;
}
/**
* Add a keyword associate with the PTM.
* @param keyword a keyword.
* @return the same Builder object so you can chain setters.
* @throws IllegalArgumentException if the keyword is null.
*/
public Builder addKeyword(String keyword) {
if (keyword == null) throw new IllegalArgumentException("Keyword cannot be null.");
keywords.add(keyword);
return this;
}
public Builder addKeywords(Collection<String> keywords) {
if (keywords==null) throw new IllegalArgumentException("Keywords cannot be null.");
for (String keyword : keywords) {
addKeyword(keyword);
}
return this;
}
/**
* Set the residue formula.
* @param formula residue formula.
* @return the same Builder object so you can chain setters.
*/
public Builder setFormula(final String formula) {
this.formula = formula;
return this;
}
/**
*
* @return build ProteinModification.
*/
public ProteinModificationImpl build() {
return new ProteinModificationImpl(this);
}
}
/**
*
*/
private ProteinModificationImpl(Builder builder) {
this.id = builder.id;
this.category = builder.category;
this.occurrenceType = builder.occurrenceType;
this.condition = builder.condition;
this.pdbccId = builder.pdbccId;
this.pdbccName = builder.pdbccName;
this.residId = builder.residId;
this.residName = builder.residName;
this.psimodId = builder.psimodId;
this.psimodName = builder.psimodName;
this.sysName = builder.sysName;
this.formula = builder.formula;
this.keywords = new LinkedHashSet<String>(builder.keywords);
}
@Override
public int compareTo(ProteinModification arg0) {
if ( this.equals(arg0))
return 0;
return this.toString().compareTo(arg0.toString());
}
}