1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.viewmodel; |
22 |
|
|
23 |
|
import jalview.analysis.PCA; |
24 |
|
import jalview.api.RotatableCanvasI; |
25 |
|
import jalview.api.analysis.ScoreModelI; |
26 |
|
import jalview.api.analysis.SimilarityParamsI; |
27 |
|
import jalview.datamodel.AlignmentView; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.datamodel.SequencePoint; |
30 |
|
|
31 |
|
import java.util.Vector; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 93 (93) |
Complexity: 24 |
Complexity Density: 0.4 |
|
33 |
|
public class PCAModel |
34 |
|
{ |
35 |
|
private volatile PCA pca; |
36 |
|
|
37 |
|
int top; |
38 |
|
|
39 |
|
AlignmentView seqstrings; |
40 |
|
|
41 |
|
SequenceI[] seqs; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
ScoreModelI scoreModel; |
47 |
|
|
48 |
|
private boolean nucleotide = false; |
49 |
|
|
50 |
|
private Vector<SequencePoint> points; |
51 |
|
|
52 |
|
private SimilarityParamsI similarityParams; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
@param |
60 |
|
@param |
61 |
|
@param |
62 |
|
@param |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
64 |
0 |
public PCAModel(AlignmentView seqData, SequenceI[] sqs, boolean nuc,... |
65 |
|
ScoreModelI modelName, SimilarityParamsI params) |
66 |
|
{ |
67 |
0 |
seqstrings = seqData; |
68 |
0 |
seqs = sqs; |
69 |
0 |
nucleotide = nuc; |
70 |
0 |
scoreModel = modelName; |
71 |
0 |
similarityParams = params; |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
74 |
0 |
public void run()... |
75 |
|
{ |
76 |
0 |
pca = new PCA(seqstrings, scoreModel, similarityParams); |
77 |
0 |
pca.run(); |
78 |
|
|
79 |
|
|
80 |
0 |
int ii = 0; |
81 |
|
|
82 |
0 |
while ((ii < seqs.length) && (seqs[ii] != null)) |
83 |
|
{ |
84 |
0 |
ii++; |
85 |
|
} |
86 |
|
|
87 |
0 |
int height = pca.getHeight(); |
88 |
|
|
89 |
0 |
top = height - 1; |
90 |
|
|
91 |
0 |
points = new Vector<SequencePoint>(); |
92 |
0 |
float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100); |
93 |
|
|
94 |
0 |
for (int i = 0; i < height; i++) |
95 |
|
{ |
96 |
0 |
SequencePoint sp = new SequencePoint(seqs[i], scores[i]); |
97 |
0 |
points.addElement(sp); |
98 |
|
} |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
public void updateRc(RotatableCanvasI rc)... |
102 |
|
{ |
103 |
0 |
rc.setPoints(points, pca.getHeight()); |
104 |
|
} |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
0 |
public boolean isNucleotide()... |
107 |
|
{ |
108 |
0 |
return nucleotide; |
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public void setNucleotide(boolean nucleotide)... |
112 |
|
{ |
113 |
0 |
this.nucleotide = nucleotide; |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
@return |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
0 |
public int getTop()... |
122 |
|
{ |
123 |
0 |
return top; |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
@param |
133 |
|
@param |
134 |
|
@param |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
136 |
0 |
public void updateRcView(int dim1, int dim2, int dim3)... |
137 |
|
{ |
138 |
|
|
139 |
0 |
float[][] scores = pca.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 100); |
140 |
|
|
141 |
0 |
for (int i = 0; i < pca.getHeight(); i++) |
142 |
|
{ |
143 |
0 |
points.elementAt(i).coord = scores[i]; |
144 |
|
} |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
0 |
public String getDetails()... |
148 |
|
{ |
149 |
0 |
return pca.getDetails(); |
150 |
|
} |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0 |
public AlignmentView getSeqtrings()... |
153 |
|
{ |
154 |
0 |
return seqstrings; |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 7 |
Complexity Density: 0.27 |
|
157 |
0 |
public String getPointsasCsv(boolean transformed, int xdim, int ydim,... |
158 |
|
int zdim) |
159 |
|
{ |
160 |
0 |
StringBuffer csv = new StringBuffer(); |
161 |
0 |
csv.append("\"Sequence\""); |
162 |
0 |
if (transformed) |
163 |
|
{ |
164 |
0 |
csv.append(","); |
165 |
0 |
csv.append(xdim); |
166 |
0 |
csv.append(","); |
167 |
0 |
csv.append(ydim); |
168 |
0 |
csv.append(","); |
169 |
0 |
csv.append(zdim); |
170 |
|
} |
171 |
|
else |
172 |
|
{ |
173 |
0 |
for (int d = 1, dmax = pca.component(1).length; d <= dmax; d++) |
174 |
|
{ |
175 |
0 |
csv.append("," + d); |
176 |
|
} |
177 |
|
} |
178 |
0 |
csv.append("\n"); |
179 |
0 |
for (int s = 0; s < seqs.length; s++) |
180 |
|
{ |
181 |
0 |
csv.append("\"" + seqs[s].getName() + "\""); |
182 |
0 |
double fl[]; |
183 |
0 |
if (!transformed) |
184 |
|
{ |
185 |
|
|
186 |
0 |
fl = pca.component(s); |
187 |
0 |
for (int d = fl.length - 1; d >= 0; d--) |
188 |
|
{ |
189 |
0 |
csv.append(","); |
190 |
0 |
csv.append(fl[d]); |
191 |
|
} |
192 |
|
} |
193 |
|
else |
194 |
|
{ |
195 |
|
|
196 |
0 |
fl = getPointPosition(s); |
197 |
0 |
for (int d = 0; d < fl.length; d++) |
198 |
|
{ |
199 |
0 |
csv.append(","); |
200 |
0 |
csv.append(fl[d]); |
201 |
|
} |
202 |
|
} |
203 |
0 |
csv.append("\n"); |
204 |
|
} |
205 |
0 |
return csv.toString(); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
@return |
211 |
|
|
212 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
213 |
0 |
public double[] getPointPosition(int s)... |
214 |
|
{ |
215 |
0 |
double pts[] = new double[3]; |
216 |
0 |
float[] p = points.elementAt(s).coord; |
217 |
0 |
pts[0] = p[0]; |
218 |
0 |
pts[1] = p[1]; |
219 |
0 |
pts[2] = p[2]; |
220 |
0 |
return pts; |
221 |
|
} |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
223 |
0 |
public String getScoreModelName()... |
224 |
|
{ |
225 |
0 |
return scoreModel == null ? "" : scoreModel.getName(); |
226 |
|
} |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
228 |
0 |
public void setScoreModel(ScoreModelI sm)... |
229 |
|
{ |
230 |
0 |
this.scoreModel = sm; |
231 |
|
} |
232 |
|
|
233 |
|
} |