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 jalview.datamodel.AlignmentAnnotation; |
24 |
|
import jalview.datamodel.Sequence; |
25 |
|
import jalview.datamodel.SequenceI; |
26 |
|
import jalview.util.Format; |
27 |
|
|
28 |
|
import java.io.IOException; |
29 |
|
import java.util.HashMap; |
30 |
|
import java.util.Map; |
31 |
|
import java.util.StringTokenizer; |
32 |
|
import java.util.Vector; |
33 |
|
|
|
|
| 76.2% |
Uncovered Elements: 36 (151) |
Complexity: 37 |
Complexity Density: 0.4 |
|
34 |
|
public class ClustalFile extends AlignFile |
35 |
|
{ |
36 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
37 |
34 |
public ClustalFile()... |
38 |
|
{ |
39 |
|
} |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
41 |
0 |
public ClustalFile(String inFile, DataSourceType sourceType)... |
42 |
|
throws IOException |
43 |
|
{ |
44 |
0 |
super(inFile, sourceType); |
45 |
|
} |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
1 |
public ClustalFile(FileParse source) throws IOException... |
48 |
|
{ |
49 |
1 |
super(source); |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
35 |
@Override... |
53 |
|
public void initData() |
54 |
|
{ |
55 |
35 |
super.initData(); |
56 |
|
} |
57 |
|
|
|
|
| 67.7% |
Uncovered Elements: 31 (96) |
Complexity: 21 |
Complexity Density: 0.35 |
|
58 |
1 |
@Override... |
59 |
|
public void parse() throws IOException |
60 |
|
{ |
61 |
1 |
int i = 0; |
62 |
1 |
boolean flag = false; |
63 |
1 |
boolean top = false; |
64 |
1 |
StringBuffer pssecstr = new StringBuffer(); |
65 |
1 |
StringBuffer consstr = new StringBuffer(); |
66 |
1 |
Vector<String> headers = new Vector<>(); |
67 |
1 |
Map<String, StringBuffer> seqhash = new HashMap<>(); |
68 |
1 |
StringBuffer tempseq; |
69 |
1 |
String line, id; |
70 |
1 |
StringTokenizer str; |
71 |
|
|
72 |
1 |
try |
73 |
|
{ |
74 |
? |
while ((line = nextLine()) != null) |
75 |
|
{ |
76 |
50 |
if (line.length() == 0) |
77 |
|
{ |
78 |
4 |
top = true; |
79 |
|
} |
80 |
50 |
boolean isConservation = line.startsWith(SPACE) |
81 |
|
|| line.startsWith(TAB); |
82 |
50 |
if (!isConservation) |
83 |
|
{ |
84 |
50 |
str = new StringTokenizer(line); |
85 |
|
|
86 |
50 |
if (str.hasMoreTokens()) |
87 |
|
{ |
88 |
46 |
id = str.nextToken(); |
89 |
|
|
90 |
46 |
if (id.equalsIgnoreCase("CLUSTAL")) |
91 |
|
{ |
92 |
1 |
flag = true; |
93 |
|
} |
94 |
|
else |
95 |
|
{ |
96 |
45 |
if (flag) |
97 |
|
{ |
98 |
45 |
if (seqhash.containsKey(id)) |
99 |
|
{ |
100 |
30 |
tempseq = seqhash.get(id); |
101 |
|
} |
102 |
|
else |
103 |
|
{ |
104 |
15 |
tempseq = new StringBuffer(); |
105 |
15 |
seqhash.put(id, tempseq); |
106 |
|
} |
107 |
|
|
108 |
45 |
if (!(headers.contains(id))) |
109 |
|
{ |
110 |
15 |
headers.addElement(id); |
111 |
|
} |
112 |
|
|
113 |
45 |
if (str.hasMoreTokens()) |
114 |
|
{ |
115 |
45 |
tempseq.append(str.nextToken()); |
116 |
|
} |
117 |
45 |
top = false; |
118 |
|
} |
119 |
|
} |
120 |
|
} |
121 |
|
else |
122 |
|
{ |
123 |
4 |
flag = true; |
124 |
|
} |
125 |
|
} |
126 |
|
else |
127 |
|
{ |
128 |
0 |
if (line.matches("\\s+(-|\\.|\\(|\\[|\\]|\\))+")) |
129 |
|
{ |
130 |
0 |
if (top) |
131 |
|
{ |
132 |
0 |
pssecstr.append(line.trim()); |
133 |
|
} |
134 |
|
else |
135 |
|
{ |
136 |
0 |
consstr.append(line.trim()); |
137 |
|
} |
138 |
|
} |
139 |
|
} |
140 |
|
} |
141 |
|
} catch (IOException e) |
142 |
|
{ |
143 |
0 |
jalview.bin.Console.errPrintln("Exception parsing clustal file " + e); |
144 |
0 |
e.printStackTrace(); |
145 |
|
} |
146 |
|
|
147 |
1 |
if (flag) |
148 |
|
{ |
149 |
1 |
this.noSeqs = headers.size(); |
150 |
|
|
151 |
|
|
152 |
16 |
for (i = 0; i < headers.size(); i++) |
153 |
|
{ |
154 |
15 |
if (seqhash.get(headers.elementAt(i)) != null) |
155 |
|
{ |
156 |
15 |
if (maxLength < seqhash.get(headers.elementAt(i)).toString() |
157 |
|
.length()) |
158 |
|
{ |
159 |
1 |
maxLength = seqhash.get(headers.elementAt(i)).toString() |
160 |
|
.length(); |
161 |
|
} |
162 |
|
|
163 |
15 |
Sequence newSeq = parseId(headers.elementAt(i).toString()); |
164 |
15 |
newSeq.setSequence( |
165 |
|
seqhash.get(headers.elementAt(i).toString()).toString()); |
166 |
|
|
167 |
15 |
seqs.addElement(newSeq); |
168 |
|
} |
169 |
|
else |
170 |
|
{ |
171 |
0 |
jalview.bin.Console.errPrintln( |
172 |
|
"Clustal File Reader: Can't find sequence for " |
173 |
|
+ headers.elementAt(i)); |
174 |
|
} |
175 |
|
} |
176 |
1 |
AlignmentAnnotation lastssa = null; |
177 |
1 |
if (pssecstr.length() == maxLength) |
178 |
|
{ |
179 |
0 |
Vector<AlignmentAnnotation> ss = new Vector<>(); |
180 |
0 |
AlignmentAnnotation ssa = lastssa = StockholmFile |
181 |
|
.parseAnnotationRow(ss, "secondary structure", |
182 |
|
pssecstr.toString()); |
183 |
0 |
ssa.label = "Secondary Structure"; |
184 |
0 |
annotations.addElement(ssa); |
185 |
|
} |
186 |
1 |
if (consstr.length() == maxLength) |
187 |
|
{ |
188 |
0 |
Vector<AlignmentAnnotation> ss = new Vector<>(); |
189 |
0 |
AlignmentAnnotation ssa = StockholmFile.parseAnnotationRow(ss, |
190 |
|
"secondary structure", consstr.toString()); |
191 |
0 |
ssa.label = "Consensus Secondary Structure"; |
192 |
0 |
if (lastssa == null || !lastssa.getRNAStruc() |
193 |
|
.equals(ssa.getRNAStruc().replace('-', '.'))) |
194 |
|
{ |
195 |
0 |
annotations.addElement(ssa); |
196 |
|
} |
197 |
|
} |
198 |
|
} |
199 |
|
} |
200 |
|
|
|
|
| 93.5% |
Uncovered Elements: 3 (46) |
Complexity: 12 |
Complexity Density: 0.4 |
|
201 |
34 |
@Override... |
202 |
|
public String print(SequenceI[] s, boolean jvsuffix) |
203 |
|
{ |
204 |
34 |
StringBuffer out = new StringBuffer("CLUSTAL" + newline + newline); |
205 |
|
|
206 |
34 |
int max = 0; |
207 |
34 |
int maxid = 0; |
208 |
|
|
209 |
34 |
int i = 0; |
210 |
|
|
211 |
190 |
while ((i < s.length) && (s[i] != null)) |
212 |
|
{ |
213 |
156 |
String tmp = printId(s[i], jvsuffix); |
214 |
|
|
215 |
156 |
max = Math.max(max, s[i].getLength()); |
216 |
|
|
217 |
156 |
if (tmp.length() > maxid) |
218 |
|
{ |
219 |
41 |
maxid = tmp.length(); |
220 |
|
} |
221 |
|
|
222 |
156 |
i++; |
223 |
|
} |
224 |
|
|
225 |
34 |
if (maxid < 15) |
226 |
|
{ |
227 |
34 |
maxid = 15; |
228 |
|
} |
229 |
|
|
230 |
34 |
maxid++; |
231 |
|
|
232 |
34 |
int len = 60; |
233 |
34 |
int nochunks = (max / len) + (max % len > 0 ? 1 : 0); |
234 |
|
|
235 |
70 |
for (i = 0; i < nochunks; i++) |
236 |
|
{ |
237 |
36 |
int j = 0; |
238 |
|
|
239 |
222 |
while ((j < s.length) && (s[j] != null)) |
240 |
|
{ |
241 |
186 |
out.append(new Format("%-" + maxid + "s") |
242 |
|
.form(printId(s[j], jvsuffix) + " ")); |
243 |
|
|
244 |
186 |
int chunkStart = i * len; |
245 |
186 |
int chunkEnd = chunkStart + len; |
246 |
|
|
247 |
186 |
int length = s[j].getLength(); |
248 |
186 |
if ((chunkEnd < length) && (chunkStart < length)) |
249 |
|
{ |
250 |
30 |
out.append(s[j].getSequenceAsString(chunkStart, chunkEnd)); |
251 |
|
} |
252 |
|
else |
253 |
|
{ |
254 |
156 |
if (chunkStart < length) |
255 |
|
{ |
256 |
156 |
out.append(s[j].getSequenceAsString().substring(chunkStart)); |
257 |
|
} |
258 |
|
} |
259 |
|
|
260 |
186 |
out.append(newline); |
261 |
186 |
j++; |
262 |
|
} |
263 |
|
|
264 |
36 |
out.append(newline); |
265 |
|
} |
266 |
|
|
267 |
34 |
return out.toString(); |
268 |
|
} |
269 |
|
} |