freesci / java-protein-domain-visualization

Java tool written in help of Processing that visualizes domain structure and repeats in proteins

This URL has Read+Write access

java-protein-domain-visualization / arcdiagram.pde
100644 132 lines (120 sloc) 3.074 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
String[] lines;
String[] lines2;
int index=0;
int i2ndex=0;
float len=0;
float dstart=0;
float dend=0;
float difflen=0;
float d2start=0;
float d2end=0;
int swtch=0;
float num=0.0;
String stalk="S";
String head="H";
String conN="CN";
String conH="CH";
String sign="O";
PFont fonta;
 
void setup() {
  size(800, 350);
  background(255);
  smooth();
  lines = loadStrings("data.txt");
  lines2= lines;
  fonta = loadFont("TheSans-Plain-12.vlw");
  textFont(fonta);
  fill (0,0,0);
 
  text("Legend:", 700, 30);
  fill(235,230,10);
  text("stalks", 700, 50);
  fill(185,20,20);
  text("heads", 700, 65);
  fill(20,185,20);
  text("connectors", 700, 80);
  fill(30,30,30);
  text("anchor", 700, 95);
 
}
 
void draw() {
 
  //draw rectangles
  if (index < lines.length) {
    String[] pieces = split(lines[index], ' ');
    if (pieces.length == 2){
      len = float(pieces[1]);
      num=700.0/len;
      noFill();
      stroke(50);
      rect(20,320, num*len, 10);
 
    }
    if (pieces.length == 4) {
      dstart = int(pieces[2]);
      dend = int(pieces[3]);
      len=dend-dstart+1;//len=len+1;
      fill (30,30,30,50);
      if (pieces[0].equals(stalk)==true){
        fill(235,230,10,80);
      }
      if (pieces[0].equals(sign)==true){
        fill(50,70,190,80);
      }
      if (pieces[0].equals(head)==true){
        fill(185,20,20,50);
      }
      if (pieces[0].equals(conN)==true){
        fill(20,185,20,50);
      }
      if (pieces[0].equals(conH)==true){
        fill(20,185,20,50);
      }
 
      rect(20+num*dstart, 320, num*len, 10);
    }
    // Go to the next line for the next run through draw()
    index = index + 1;
  }
 
 
  //draw arcs
  if (i2ndex < lines2.length) {
 
    String[] pieces = split(lines2[i2ndex], ' ');
    if (pieces.length == 4) {
      for (int i = index ; i < lines2.length; i++){
        String[] p2ieces=split (lines2[i], ' ');
        if (p2ieces.length == 4){
          if (int(pieces[1]) == int(p2ieces[1])) {
            swtch=1;
            dstart = float(pieces[2]);
            dend = float(pieces[3]);
            len=dend-dstart+1;//len=len+1;
            d2start = float(p2ieces[2]);
            difflen = float(p2ieces[2]) - dstart;
            if (pieces[0].equals(stalk)==true){
              stroke(235,230,10,80);
            }
            if (pieces[0].equals(head)==true){
              stroke(185,20,20,50);
            }
            if (pieces[0].equals(conN)==true){
              stroke(20,185,20,50);
            }
            if (pieces[0].equals(conH)==true){
              stroke(20,185,20,50);
            }
            noFill();
            strokeWeight(num*(dend - dstart));
            strokeCap(SQUARE);
            arc (21+num*(dend+(d2start-dend)/2), 315, num*difflen, num*difflen, PI, 0);
            strokeWeight(1);
            stroke(50);
            break;
          }
        }
        if (i == lines.length){
          swtch=1;
        }
      }
    }
    // Go to the next line for the next run through draw()
    i2ndex = i2ndex + 1;
  }
  if (i2ndex == lines2.length){
    exit();
  }
}