Debian Codegraph @

metastudentPkg/lib/groupB/pp2/components/Protein.java

raw
1 package pp2.components;
2 import java.util.ArrayList;
3 import java.util.List;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7
8 public class Protein {
9
10 private String id;
11 private String description;
12 private String sequence;
13 private GO[] annotations;
14
15 public Protein(String id) {
16 this.id = id;
17 }
18
19 public Protein(StringBuffer swissProtEntry) {
20 Pattern sq = Pattern.compile("SQ\\s+SEQUENCE.+;([\\w\\s]+)//");
21 Pattern id = Pattern.compile("ID\\s+([\\w\\d_]+)");
22 Pattern de = Pattern.compile("DE\\s+(.+);\\n");
23 Pattern go = Pattern.compile("DR\\s+GO; GO:(\\d+);");
24
25
26 Matcher ma = id.matcher(swissProtEntry.toString());
27 if(ma.find()) {
28 this.id = ma.group(1);
29 }
30 ma = de.matcher(swissProtEntry.toString());
31 if(ma.find()) {
32 this.description = ma.group(1);
33 }
34 ma = sq.matcher(swissProtEntry.toString());
35 if(ma.find()) {
36 this.sequence = parseSequence(ma.group(1));
37 }
38 ma = go.matcher(swissProtEntry.toString());
39 List<GO> list = new ArrayList<GO>();
40 while(!ma.hitEnd()) {
41 if(ma.find()) {
42 String goID = ma.group(1);
43 list.add(new GO(goID));
44 }
45 }
46 annotations = list.toArray(new GO[list.size()]);
47 }
48
49 public String parseSequence(String sq) {
50 return sq.replaceAll("\\s", "").toUpperCase();
51 }
52
53 @Override
54 public String toString() {
55 StringBuffer buffer = new StringBuffer(">");
56 for(GO an : annotations) {
57 buffer.append(an.toString()+",");
58 }
59 return buffer.substring(0, buffer.length()-1)+"\n"+sequence;
60 }
61
62 public void addAnnotation(GO an) {
63 //TODO
64 }
65
66 public String getId() {
67 return id;
68 }
69
70 public String getDescription() {
71 return description;
72 }
73
74 public String getSequence() {
75 return sequence;
76 }
77
78 public GO[] getAnnotations() {
79 return annotations;
80 }
81
82 public void setDescription(String description) {
83 this.description = description;
84 }
85
86 }