1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import jalview.analysis.scoremodels.ScoreMatrix; |
24 |
|
import jalview.schemes.ResidueProperties; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
@version |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 68 (68) |
Complexity: 22 |
Complexity Density: 0.61 |
|
33 |
|
public class BinarySequence extends Sequence |
34 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
35 |
|
public class InvalidSequenceTypeException extends Exception |
36 |
|
{ |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0 |
public InvalidSequenceTypeException(String string)... |
39 |
|
{ |
40 |
0 |
super(string); |
41 |
|
} |
42 |
|
|
43 |
|
} |
44 |
|
|
45 |
|
int[] binary; |
46 |
|
|
47 |
|
double[] dbinary; |
48 |
|
|
49 |
|
boolean isNa = false; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
|
56 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
57 |
0 |
public BinarySequence(String s, boolean isNa)... |
58 |
|
{ |
59 |
0 |
super("", s, 0, s.length()); |
60 |
0 |
this.isNa = isNa; |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@return |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
68 |
0 |
private int initMatrixGetNoRes()... |
69 |
|
{ |
70 |
0 |
int nores = (isNa) ? ResidueProperties.maxNucleotideIndex |
71 |
|
: ResidueProperties.maxProteinIndex; |
72 |
|
|
73 |
0 |
dbinary = new double[getLength() * nores]; |
74 |
|
|
75 |
0 |
return nores; |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
78 |
0 |
private int[] getSymbolmatrix()... |
79 |
|
{ |
80 |
0 |
return (isNa) ? ResidueProperties.nucleotideIndex |
81 |
|
: ResidueProperties.aaIndex; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
87 |
0 |
public void encode()... |
88 |
|
{ |
89 |
0 |
int nores = initMatrixGetNoRes(); |
90 |
0 |
final int[] sindex = getSymbolmatrix(); |
91 |
0 |
for (int i = 0; i < getLength(); i++) |
92 |
|
{ |
93 |
0 |
int aanum = nores - 1; |
94 |
|
|
95 |
0 |
try |
96 |
|
{ |
97 |
0 |
aanum = sindex[getCharAt(i)]; |
98 |
|
} catch (NullPointerException e) |
99 |
|
{ |
100 |
0 |
aanum = nores - 1; |
101 |
|
} |
102 |
|
|
103 |
0 |
if (aanum >= nores) |
104 |
|
{ |
105 |
0 |
aanum = nores - 1; |
106 |
|
} |
107 |
|
|
108 |
0 |
dbinary[(i * nores) + aanum] = 1.0; |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 1.33 |
|
117 |
0 |
public void matrixEncode(final ScoreMatrix smtrx)... |
118 |
|
throws InvalidSequenceTypeException |
119 |
|
{ |
120 |
0 |
if (isNa != smtrx.isDNA()) |
121 |
|
{ |
122 |
0 |
throw new InvalidSequenceTypeException( |
123 |
|
"matrix " + smtrx.getClass().getCanonicalName() |
124 |
|
+ " is not a valid matrix for " |
125 |
0 |
+ (isNa ? "nucleotide" : "protein") + "sequences"); |
126 |
|
} |
127 |
0 |
matrixEncode(smtrx.isDNA() ? ResidueProperties.nucleotideIndex |
128 |
|
: ResidueProperties.aaIndex, smtrx.getMatrix()); |
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
131 |
0 |
private void matrixEncode(final int[] aaIndex, final float[][] matrix)... |
132 |
|
{ |
133 |
0 |
int nores = initMatrixGetNoRes(); |
134 |
|
|
135 |
0 |
for (int i = 0, iSize = getLength(); i < iSize; i++) |
136 |
|
{ |
137 |
0 |
int aanum = nores - 1; |
138 |
|
|
139 |
0 |
try |
140 |
|
{ |
141 |
0 |
aanum = aaIndex[getCharAt(i)]; |
142 |
|
} catch (NullPointerException e) |
143 |
|
{ |
144 |
0 |
aanum = nores - 1; |
145 |
|
} |
146 |
|
|
147 |
0 |
if (aanum >= nores) |
148 |
|
{ |
149 |
0 |
aanum = nores - 1; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
0 |
for (int j = 0; j < nores; j++) |
155 |
|
{ |
156 |
0 |
dbinary[(i * nores) + j] = matrix[aanum][j]; |
157 |
|
} |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@return |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
166 |
0 |
public String toBinaryString()... |
167 |
|
{ |
168 |
0 |
String out = ""; |
169 |
|
|
170 |
0 |
for (int i = 0; i < binary.length; i++) |
171 |
|
{ |
172 |
0 |
out += (Integer.valueOf(binary[i])).toString(); |
173 |
|
|
174 |
0 |
if (i < (binary.length - 1)) |
175 |
|
{ |
176 |
0 |
out += " "; |
177 |
|
} |
178 |
|
} |
179 |
|
|
180 |
0 |
return out; |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
@return |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
0 |
public double[] getDBinary()... |
189 |
|
{ |
190 |
0 |
return dbinary; |
191 |
|
} |
192 |
|
|
193 |
|
} |