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