1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Hashtable; |
25 |
|
|
|
|
| 0% |
Uncovered Elements: 112 (112) |
Complexity: 25 |
Complexity Density: 0.37 |
|
26 |
|
public class SecStrConsensus |
27 |
|
{ |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
@author |
33 |
|
|
34 |
|
|
|
|
| 50% |
Uncovered Elements: 7 (14) |
Complexity: 7 |
Complexity Density: 1 |
|
35 |
|
public static class SimpleBP |
36 |
|
{ |
37 |
|
int bp5; |
38 |
|
|
39 |
|
int bp3; |
40 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
41 |
0 |
public SimpleBP()... |
42 |
|
{ |
43 |
|
|
44 |
|
} |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
46 |
9493 |
public SimpleBP(int i5, int i3)... |
47 |
|
{ |
48 |
9493 |
bp5 = i5; |
49 |
9493 |
bp3 = i3; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
public void setBP5(int i5)... |
53 |
|
{ |
54 |
0 |
bp5 = i5; |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
public void setBP3(int i3)... |
58 |
|
{ |
59 |
0 |
bp3 = i3; |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
254105 |
public int getBP5()... |
63 |
|
{ |
64 |
254105 |
return bp5; |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
9493 |
public int getBP3()... |
68 |
|
{ |
69 |
9493 |
return bp3; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
public String toString()... |
73 |
|
{ |
74 |
0 |
return "(" + bp5 + "," + bp3 + ")"; |
75 |
|
} |
76 |
|
|
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 4 |
Complexity Density: 0.17 |
|
79 |
0 |
public static int[] extractConsensus(ArrayList<ArrayList<SimpleBP>> bps)... |
80 |
|
{ |
81 |
|
|
82 |
|
|
83 |
0 |
int maxlength = 0; |
84 |
0 |
for (ArrayList<SimpleBP> strs : bps) |
85 |
|
{ |
86 |
0 |
for (SimpleBP bp : strs) |
87 |
|
{ |
88 |
|
|
89 |
0 |
maxlength = Math.max(1 + Math.max(bp.bp5, bp.bp3), maxlength); |
90 |
|
|
91 |
|
} |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
0 |
ArrayList<Hashtable<Integer, Double>> seq = new ArrayList<Hashtable<Integer, Double>>(); |
96 |
0 |
for (int i = 0; i < maxlength; i++) |
97 |
|
{ |
98 |
0 |
seq.add(new Hashtable<Integer, Double>()); |
99 |
|
} |
100 |
0 |
for (ArrayList<SimpleBP> strs : bps) |
101 |
|
{ |
102 |
0 |
for (SimpleBP bp : strs) |
103 |
|
{ |
104 |
0 |
int i = bp.bp5; |
105 |
0 |
int j = bp.bp3; |
106 |
0 |
Hashtable<Integer, Double> h = seq.get(i); |
107 |
0 |
if (!h.containsKey(j)) |
108 |
|
{ |
109 |
0 |
h.put(j, 0.0); |
110 |
|
} |
111 |
0 |
h.put(j, h.get(j) + 1.); |
112 |
|
} |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
0 |
double[][] mat = fillMatrix(seq); |
121 |
0 |
ArrayList<SimpleBP> res = backtrack(mat, seq); |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
0 |
int[] finalres = new int[seq.size()]; |
127 |
0 |
for (int i = 0; i < seq.size(); i++) |
128 |
|
{ |
129 |
0 |
finalres[i] = -1; |
130 |
|
} |
131 |
0 |
for (SimpleBP bp : res) |
132 |
|
{ |
133 |
0 |
finalres[bp.bp5] = bp.bp3; |
134 |
0 |
finalres[bp.bp3] = bp.bp5; |
135 |
|
} |
136 |
|
|
137 |
0 |
return finalres; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
private static boolean canBasePair(... |
141 |
|
ArrayList<Hashtable<Integer, Double>> seq, int i, int k) |
142 |
|
{ |
143 |
0 |
return seq.get(i).containsKey(k); |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
0 |
private static double basePairScore(... |
149 |
|
ArrayList<Hashtable<Integer, Double>> seq, int i, int k) |
150 |
|
{ |
151 |
0 |
return seq.get(i).get(k); |
152 |
|
} |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 8 |
Complexity Density: 0.44 |
|
154 |
0 |
private static double[][] fillMatrix(... |
155 |
|
ArrayList<Hashtable<Integer, Double>> seq) |
156 |
|
{ |
157 |
0 |
int n = seq.size(); |
158 |
0 |
double[][] tab = new double[n][n]; |
159 |
0 |
for (int m = 1; m <= n; m++) |
160 |
|
{ |
161 |
0 |
for (int i = 0; i < n - m + 1; i++) |
162 |
|
{ |
163 |
0 |
int j = i + m - 1; |
164 |
0 |
tab[i][j] = 0; |
165 |
0 |
if (i < j) |
166 |
|
{ |
167 |
0 |
tab[i][j] = Math.max(tab[i][j], tab[i + 1][j]); |
168 |
0 |
for (int k = i + 1; k <= j; k++) |
169 |
|
{ |
170 |
0 |
if (canBasePair(seq, i, k)) |
171 |
|
{ |
172 |
0 |
double fact1 = 0; |
173 |
0 |
if (k > i + 1) |
174 |
|
{ |
175 |
0 |
fact1 = tab[i + 1][k - 1]; |
176 |
|
} |
177 |
0 |
double fact2 = 0; |
178 |
0 |
if (k < j) |
179 |
|
{ |
180 |
0 |
fact2 = tab[k + 1][j]; |
181 |
|
} |
182 |
0 |
tab[i][j] = Math.max(tab[i][j], |
183 |
|
basePairScore(seq, i, k) + fact1 + fact2); |
184 |
|
} |
185 |
|
} |
186 |
|
} |
187 |
|
} |
188 |
|
} |
189 |
0 |
return tab; |
190 |
|
} |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
0 |
private static ArrayList<SimpleBP> backtrack(double[][] tab,... |
193 |
|
ArrayList<Hashtable<Integer, Double>> seq) |
194 |
|
{ |
195 |
0 |
return backtrack(tab, seq, 0, seq.size() - 1); |
196 |
|
} |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 10 |
Complexity Density: 0.43 |
|
198 |
0 |
private static ArrayList<SimpleBP> backtrack(double[][] tab,... |
199 |
|
ArrayList<Hashtable<Integer, Double>> seq, int i, int j) |
200 |
|
{ |
201 |
0 |
ArrayList<SimpleBP> result = new ArrayList<SimpleBP>(); |
202 |
0 |
if (i < j) |
203 |
|
{ |
204 |
0 |
ArrayList<Integer> indices = new ArrayList<Integer>(); |
205 |
0 |
indices.add(-1); |
206 |
0 |
for (int k = i + 1; k <= j; k++) |
207 |
|
{ |
208 |
0 |
indices.add(k); |
209 |
|
} |
210 |
0 |
for (int k : indices) |
211 |
|
{ |
212 |
0 |
if (k == -1) |
213 |
|
{ |
214 |
0 |
if (tab[i][j] == tab[i + 1][j]) |
215 |
|
{ |
216 |
0 |
result = backtrack(tab, seq, i + 1, j); |
217 |
|
} |
218 |
|
} |
219 |
|
else |
220 |
|
{ |
221 |
0 |
if (canBasePair(seq, i, k)) |
222 |
|
{ |
223 |
0 |
double fact1 = 0; |
224 |
0 |
if (k > i + 1) |
225 |
|
{ |
226 |
0 |
fact1 = tab[i + 1][k - 1]; |
227 |
|
} |
228 |
0 |
double fact2 = 0; |
229 |
0 |
if (k < j) |
230 |
|
{ |
231 |
0 |
fact2 = tab[k + 1][j]; |
232 |
|
} |
233 |
0 |
if (tab[i][j] == basePairScore(seq, i, k) + fact1 + fact2) |
234 |
|
{ |
235 |
0 |
result = backtrack(tab, seq, i + 1, k - 1); |
236 |
0 |
result.addAll(backtrack(tab, seq, k + 1, j)); |
237 |
0 |
result.add(new SimpleBP(i, k)); |
238 |
|
} |
239 |
|
} |
240 |
|
} |
241 |
|
} |
242 |
|
} |
243 |
0 |
else if (i == j) |
244 |
|
{ |
245 |
|
|
246 |
|
} |
247 |
|
else |
248 |
|
{ |
249 |
|
|
250 |
|
} |
251 |
0 |
return result; |
252 |
|
} |
253 |
|
|
254 |
|
} |