1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import jalview.datamodel.Sequence; |
26 |
|
import jalview.datamodel.SequenceI; |
27 |
|
import jalview.util.Comparison; |
28 |
|
import jalview.util.Format; |
29 |
|
|
30 |
|
import java.io.IOException; |
31 |
|
import java.util.ArrayList; |
32 |
|
import java.util.Hashtable; |
33 |
|
import java.util.List; |
34 |
|
import java.util.StringTokenizer; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
@version |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 213 (213) |
Complexity: 49 |
Complexity Density: 0.36 |
|
42 |
|
public class MSFfile extends AlignFile |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
48 |
0 |
public MSFfile()... |
49 |
|
{ |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
|
57 |
|
@param |
58 |
|
|
59 |
|
|
60 |
|
@throws |
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0 |
public MSFfile(String inFile, DataSourceType type) throws IOException... |
64 |
|
{ |
65 |
0 |
super(inFile, type); |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
0 |
public MSFfile(FileParse source) throws IOException... |
69 |
|
{ |
70 |
0 |
super(source); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
|
|
| 0% |
Uncovered Elements: 59 (59) |
Complexity: 13 |
Complexity Density: 0.33 |
|
76 |
0 |
@Override... |
77 |
|
public void parse() throws IOException |
78 |
|
{ |
79 |
0 |
boolean seqFlag = false; |
80 |
0 |
List<String> headers = new ArrayList<String>(); |
81 |
0 |
Hashtable<String, StringBuilder> seqhash = new Hashtable<String, StringBuilder>(); |
82 |
|
|
83 |
0 |
try |
84 |
|
{ |
85 |
0 |
String line; |
86 |
0 |
while ((line = nextLine()) != null) |
87 |
|
{ |
88 |
0 |
StringTokenizer str = new StringTokenizer(line); |
89 |
|
|
90 |
0 |
String key = null; |
91 |
0 |
while (str.hasMoreTokens()) |
92 |
|
{ |
93 |
0 |
String inStr = str.nextToken(); |
94 |
|
|
95 |
|
|
96 |
0 |
if (inStr.indexOf("Name:") != -1) |
97 |
|
{ |
98 |
0 |
key = str.nextToken(); |
99 |
0 |
headers.add(key); |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
0 |
if (inStr.indexOf("//") != -1) |
104 |
|
{ |
105 |
0 |
seqFlag = true; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
0 |
if ((inStr.indexOf("//") == -1) && seqFlag) |
110 |
|
{ |
111 |
|
|
112 |
0 |
key = inStr; |
113 |
|
|
114 |
0 |
StringBuilder tempseq; |
115 |
|
|
116 |
|
|
117 |
0 |
if (seqhash.containsKey(key)) |
118 |
|
{ |
119 |
0 |
tempseq = seqhash.get(key); |
120 |
|
} |
121 |
|
else |
122 |
|
{ |
123 |
0 |
tempseq = new StringBuilder(64); |
124 |
0 |
seqhash.put(key, tempseq); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
0 |
while (str.hasMoreTokens()) |
129 |
|
{ |
130 |
|
|
131 |
0 |
String sequenceBlock = str.nextToken(); |
132 |
0 |
tempseq.append(sequenceBlock); |
133 |
|
} |
134 |
|
} |
135 |
|
} |
136 |
|
} |
137 |
|
} catch (IOException e) |
138 |
|
{ |
139 |
0 |
jalview.bin.Console.errPrintln("Exception parsing MSFFile " + e); |
140 |
0 |
e.printStackTrace(); |
141 |
|
} |
142 |
|
|
143 |
0 |
this.noSeqs = headers.size(); |
144 |
|
|
145 |
|
|
146 |
0 |
for (int i = 0; i < headers.size(); i++) |
147 |
|
{ |
148 |
0 |
if (seqhash.get(headers.get(i)) != null) |
149 |
|
{ |
150 |
0 |
String head = headers.get(i); |
151 |
0 |
String seq = seqhash.get(head).toString(); |
152 |
|
|
153 |
0 |
if (maxLength < head.length()) |
154 |
|
{ |
155 |
0 |
maxLength = head.length(); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
0 |
seq = seq.replace('~', '.'); |
163 |
|
|
164 |
0 |
Sequence newSeq = parseId(head); |
165 |
|
|
166 |
0 |
newSeq.setSequence(seq); |
167 |
|
|
168 |
0 |
seqs.addElement(newSeq); |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
0 |
jalview.bin.Console |
173 |
|
.errPrintln("MSFFile Parser: Can't find sequence for " |
174 |
|
+ headers.get(i)); |
175 |
|
} |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
@param |
183 |
|
|
184 |
|
|
185 |
|
@return |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
187 |
0 |
public int checkSum(String seq)... |
188 |
|
{ |
189 |
0 |
int check = 0; |
190 |
0 |
String sequence = seq.toUpperCase(Locale.ROOT); |
191 |
|
|
192 |
0 |
for (int i = 0; i < sequence.length(); i++) |
193 |
|
{ |
194 |
0 |
try |
195 |
|
{ |
196 |
|
|
197 |
0 |
int value = sequence.charAt(i); |
198 |
0 |
if (value != -1) |
199 |
|
{ |
200 |
0 |
check += (i % 57 + 1) * value; |
201 |
|
} |
202 |
|
} catch (Exception e) |
203 |
|
{ |
204 |
0 |
jalview.bin.Console |
205 |
|
.errPrintln("Exception during MSF Checksum calculation"); |
206 |
0 |
e.printStackTrace(); |
207 |
|
} |
208 |
|
} |
209 |
|
|
210 |
0 |
return check % 10000; |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
@param |
217 |
|
|
218 |
|
@param |
219 |
|
|
220 |
|
|
221 |
|
@return |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 132 (132) |
Complexity: 29 |
Complexity Density: 0.34 |
|
223 |
0 |
@Override... |
224 |
|
public String print(SequenceI[] sqs, boolean jvSuffix) |
225 |
|
{ |
226 |
|
|
227 |
0 |
boolean is_NA = Comparison.isNucleotide(sqs); |
228 |
|
|
229 |
0 |
SequenceI[] s = new SequenceI[sqs.length]; |
230 |
|
|
231 |
0 |
StringBuilder out = new StringBuilder(256); |
232 |
0 |
out.append("!!").append(is_NA ? "NA" : "AA") |
233 |
|
.append("_MULTIPLE_ALIGNMENT 1.0"); |
234 |
|
|
235 |
0 |
out.append(newline); |
236 |
0 |
out.append(newline); |
237 |
0 |
int max = 0; |
238 |
0 |
int maxid = 0; |
239 |
0 |
int i = 0; |
240 |
|
|
241 |
0 |
while ((i < sqs.length) && (sqs[i] != null)) |
242 |
|
{ |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
0 |
String seqString = sqs[i].getSequenceAsString().replace('-', '.'); |
248 |
|
|
249 |
0 |
StringBuilder sb = new StringBuilder(seqString); |
250 |
|
|
251 |
0 |
for (int ii = 0; ii < sb.length(); ii++) |
252 |
|
{ |
253 |
0 |
if (sb.charAt(ii) == '.') |
254 |
|
{ |
255 |
0 |
sb.setCharAt(ii, '~'); |
256 |
|
} |
257 |
|
else |
258 |
|
{ |
259 |
0 |
break; |
260 |
|
} |
261 |
|
} |
262 |
|
|
263 |
0 |
for (int ii = sb.length() - 1; ii > 0; ii--) |
264 |
|
{ |
265 |
0 |
if (sb.charAt(ii) == '.') |
266 |
|
{ |
267 |
0 |
sb.setCharAt(ii, '~'); |
268 |
|
} |
269 |
|
else |
270 |
|
{ |
271 |
0 |
break; |
272 |
|
} |
273 |
|
} |
274 |
0 |
s[i] = new Sequence(sqs[i].getName(), sb.toString(), |
275 |
|
sqs[i].getStart(), sqs[i].getEnd()); |
276 |
|
|
277 |
0 |
if (sb.length() > max) |
278 |
|
{ |
279 |
0 |
max = sb.length(); |
280 |
|
} |
281 |
|
|
282 |
0 |
i++; |
283 |
|
} |
284 |
|
|
285 |
0 |
Format maxLenpad = new Format( |
286 |
|
"%" + (new String("" + max)).length() + "d"); |
287 |
0 |
Format maxChkpad = new Format( |
288 |
|
"%" + (new String("1" + max)).length() + "d"); |
289 |
0 |
i = 0; |
290 |
|
|
291 |
0 |
int bigChecksum = 0; |
292 |
0 |
int[] checksums = new int[s.length]; |
293 |
0 |
while (i < s.length) |
294 |
|
{ |
295 |
0 |
checksums[i] = checkSum(s[i].getSequenceAsString()); |
296 |
0 |
bigChecksum += checksums[i]; |
297 |
0 |
i++; |
298 |
|
} |
299 |
|
|
300 |
0 |
long maxNB = 0; |
301 |
0 |
out.append(" MSF: " + s[0].getLength() + " Type: " |
302 |
0 |
+ (is_NA ? "N" : "P") + " Check: " + (bigChecksum % 10000) |
303 |
|
+ " .."); |
304 |
0 |
out.append(newline); |
305 |
0 |
out.append(newline); |
306 |
0 |
out.append(newline); |
307 |
|
|
308 |
0 |
String[] nameBlock = new String[s.length]; |
309 |
0 |
String[] idBlock = new String[s.length]; |
310 |
|
|
311 |
0 |
i = 0; |
312 |
0 |
while ((i < s.length) && (s[i] != null)) |
313 |
|
{ |
314 |
|
|
315 |
0 |
nameBlock[i] = new String(" Name: " + printId(s[i], jvSuffix) + " "); |
316 |
|
|
317 |
0 |
idBlock[i] = new String("Len: " + maxLenpad.form(s[i].getLength()) |
318 |
|
+ " Check: " + maxChkpad.form(checksums[i]) |
319 |
|
+ " Weight: 1.00" + newline); |
320 |
|
|
321 |
0 |
if (s[i].getName().length() > maxid) |
322 |
|
{ |
323 |
0 |
maxid = s[i].getName().length(); |
324 |
|
} |
325 |
|
|
326 |
0 |
if (nameBlock[i].length() > maxNB) |
327 |
|
{ |
328 |
0 |
maxNB = nameBlock[i].length(); |
329 |
|
} |
330 |
|
|
331 |
0 |
i++; |
332 |
|
} |
333 |
|
|
334 |
0 |
if (maxid < 10) |
335 |
|
{ |
336 |
0 |
maxid = 10; |
337 |
|
} |
338 |
|
|
339 |
0 |
if (maxNB < 15) |
340 |
|
{ |
341 |
0 |
maxNB = 15; |
342 |
|
} |
343 |
|
|
344 |
0 |
Format nbFormat = new Format("%-" + maxNB + "s"); |
345 |
|
|
346 |
0 |
for (i = 0; (i < s.length) && (s[i] != null); i++) |
347 |
|
{ |
348 |
0 |
out.append(nbFormat.form(nameBlock[i]) + idBlock[i]); |
349 |
|
} |
350 |
|
|
351 |
0 |
maxid++; |
352 |
0 |
out.append(newline); |
353 |
0 |
out.append(newline); |
354 |
0 |
out.append("//"); |
355 |
0 |
out.append(newline); |
356 |
0 |
out.append(newline); |
357 |
0 |
int len = 50; |
358 |
|
|
359 |
0 |
int nochunks = (max / len) + (max % len > 0 ? 1 : 0); |
360 |
|
|
361 |
0 |
for (i = 0; i < nochunks; i++) |
362 |
|
{ |
363 |
0 |
int j = 0; |
364 |
|
|
365 |
0 |
while ((j < s.length) && (s[j] != null)) |
366 |
|
{ |
367 |
0 |
String name = printId(s[j], jvSuffix); |
368 |
|
|
369 |
0 |
out.append(new Format("%-" + maxid + "s").form(name + " ")); |
370 |
|
|
371 |
0 |
for (int k = 0; k < 5; k++) |
372 |
|
{ |
373 |
0 |
int start = (i * 50) + (k * 10); |
374 |
0 |
int end = start + 10; |
375 |
|
|
376 |
0 |
int length = s[j].getLength(); |
377 |
0 |
if ((end < length) && (start < length)) |
378 |
|
{ |
379 |
0 |
out.append(s[j].getSequence(start, end)); |
380 |
|
|
381 |
0 |
if (k < 4) |
382 |
|
{ |
383 |
0 |
out.append(" "); |
384 |
|
} |
385 |
|
else |
386 |
|
{ |
387 |
0 |
out.append(newline); |
388 |
|
} |
389 |
|
} |
390 |
|
else |
391 |
|
{ |
392 |
0 |
if (start < length) |
393 |
|
{ |
394 |
0 |
out.append(s[j].getSequenceAsString().substring(start)); |
395 |
0 |
out.append(newline); |
396 |
|
} |
397 |
|
else |
398 |
|
{ |
399 |
0 |
if (k == 0) |
400 |
|
{ |
401 |
0 |
out.append(newline); |
402 |
|
} |
403 |
|
} |
404 |
|
} |
405 |
|
} |
406 |
|
|
407 |
0 |
j++; |
408 |
|
} |
409 |
|
|
410 |
0 |
out.append(newline); |
411 |
|
} |
412 |
|
|
413 |
0 |
return out.toString(); |
414 |
|
} |
415 |
|
} |