1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io.packed; |
22 |
|
|
23 |
|
import jalview.api.FeatureColourI; |
24 |
|
import jalview.datamodel.AlignmentI; |
25 |
|
import jalview.io.AppletFormatAdapter; |
26 |
|
import jalview.io.FileFormatI; |
27 |
|
import jalview.io.FileParse; |
28 |
|
import jalview.io.FormatAdapter; |
29 |
|
import jalview.io.IdentifyFile; |
30 |
|
import jalview.io.packed.DataProvider.JvDataType; |
31 |
|
|
32 |
|
import java.io.BufferedReader; |
33 |
|
import java.io.IOException; |
34 |
|
import java.util.ArrayList; |
35 |
|
import java.util.HashMap; |
36 |
|
import java.util.List; |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 157 (157) |
Complexity: 36 |
Complexity Density: 0.34 |
|
38 |
|
public class ParsePackedSet |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@param |
46 |
|
|
47 |
|
@param |
48 |
|
|
49 |
|
@return |
50 |
|
@throws |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 109 (109) |
Complexity: 27 |
Complexity Density: 0.38 |
|
52 |
0 |
public Object[] getAlignment(JalviewDataset context,... |
53 |
|
Iterable<DataProvider> files) throws Exception |
54 |
|
{ |
55 |
0 |
List<Object> rslt = new ArrayList<Object>(); |
56 |
0 |
if (context == null) |
57 |
|
{ |
58 |
0 |
context = new JalviewDataset(); |
59 |
|
} |
60 |
0 |
boolean deuniquify = false; |
61 |
0 |
for (DataProvider dta : files) |
62 |
|
{ |
63 |
0 |
Exception exerror = null; |
64 |
0 |
String errmsg = null; |
65 |
0 |
FileParse src = dta.getDataSource(); |
66 |
0 |
if (dta.getType().equals(DataProvider.JvDataType.ALIGNMENT)) |
67 |
|
{ |
68 |
0 |
FileFormatI fmt = null; |
69 |
0 |
try |
70 |
|
{ |
71 |
0 |
fmt = new IdentifyFile().identify(src, false); |
72 |
|
} catch (Exception ex) |
73 |
|
{ |
74 |
0 |
exerror = ex; |
75 |
0 |
errmsg = "Couldn't identify alignment format."; |
76 |
|
} |
77 |
|
|
78 |
0 |
if (fmt != null) |
79 |
|
{ |
80 |
|
|
81 |
0 |
AlignmentI al = null; |
82 |
0 |
try |
83 |
|
{ |
84 |
0 |
al = new FormatAdapter().readFromFile(src, fmt); |
85 |
|
} catch (Exception e) |
86 |
|
{ |
87 |
0 |
errmsg = "Failed to parse alignment from result set"; |
88 |
0 |
exerror = e; |
89 |
|
} |
90 |
0 |
if (al != null) |
91 |
|
{ |
92 |
|
|
93 |
|
|
94 |
0 |
context.addAlignment(al); |
95 |
0 |
context.updateSetModified(true); |
96 |
0 |
rslt.add(al); |
97 |
0 |
deuniquify = true; |
98 |
|
} |
99 |
|
} |
100 |
|
} |
101 |
0 |
if (dta.getType().equals(JvDataType.ANNOTATION)) |
102 |
|
{ |
103 |
0 |
if (!context.hasAlignments()) |
104 |
|
{ |
105 |
0 |
errmsg = "No alignment or sequence dataset to associate annotation with."; |
106 |
|
|
107 |
|
|
108 |
|
} |
109 |
0 |
try |
110 |
|
{ |
111 |
0 |
BufferedReader br; |
112 |
0 |
if (src.getReader() instanceof BufferedReader) |
113 |
|
{ |
114 |
0 |
br = (BufferedReader) src.getReader(); |
115 |
|
} |
116 |
|
else |
117 |
|
{ |
118 |
0 |
br = new BufferedReader(src.getReader()); |
119 |
|
} |
120 |
|
|
121 |
0 |
if (new jalview.io.AnnotationFile().parseAnnotationFrom( |
122 |
|
context.getLastAlignment(), null, br)) |
123 |
|
{ |
124 |
0 |
context.updateSetModified(true); |
125 |
|
} |
126 |
|
else |
127 |
|
{ |
128 |
0 |
errmsg = "Annotation file contained no data."; |
129 |
|
} |
130 |
|
|
131 |
|
} catch (Exception e) |
132 |
|
{ |
133 |
0 |
errmsg = ((errmsg == null) ? "" : errmsg) |
134 |
|
+ "Failed to parse the annotation file associated with the alignment."; |
135 |
0 |
exerror = e; |
136 |
|
} |
137 |
|
} |
138 |
0 |
if (dta.getType().equals(JvDataType.SEQASSOCATED)) |
139 |
|
{ |
140 |
0 |
if (!context.hasSequenceAssoc()) |
141 |
|
{ |
142 |
0 |
errmsg = "No sequence to associate data with."; |
143 |
|
|
144 |
|
} |
145 |
0 |
errmsg = "parsing of sequence associated data is not implemented"; |
146 |
0 |
exerror = new Exception(errmsg); |
147 |
|
} |
148 |
0 |
if (dta.getType().equals(JvDataType.FEATURES)) |
149 |
|
{ |
150 |
|
|
151 |
|
|
152 |
0 |
if (context.featureColours == null) |
153 |
|
{ |
154 |
0 |
context.featureColours = new HashMap<String, FeatureColourI>(); |
155 |
|
} |
156 |
0 |
try |
157 |
|
{ |
158 |
0 |
jalview.io.FeaturesFile ff = new jalview.io.FeaturesFile(src); |
159 |
0 |
context.updateSetModified(ff.parse(context.getLastAlignment(), |
160 |
|
context.featureColours, false, |
161 |
|
context.relaxedIdMatching)); |
162 |
|
} catch (Exception e) |
163 |
|
{ |
164 |
0 |
errmsg = ("Failed to parse the Features file associated with the alignment."); |
165 |
0 |
exerror = e; |
166 |
|
} |
167 |
|
} |
168 |
0 |
if (dta.getType().equals(JvDataType.TREE)) |
169 |
|
{ |
170 |
0 |
try |
171 |
|
{ |
172 |
0 |
jalview.io.NewickFile nf = new jalview.io.NewickFile(src); |
173 |
0 |
if (!nf.isValid()) |
174 |
|
{ |
175 |
0 |
nf.close(); |
176 |
0 |
nf = null; |
177 |
|
} |
178 |
|
else |
179 |
|
{ |
180 |
|
|
181 |
|
|
182 |
0 |
context.addTreeFromFile(nf); |
183 |
0 |
rslt.add(nf); |
184 |
0 |
context.updateSetModified(true); |
185 |
|
} |
186 |
|
} catch (Exception e) |
187 |
|
{ |
188 |
0 |
errmsg = ("Failed to parse the treeFile associated with the result."); |
189 |
0 |
exerror = e; |
190 |
|
} |
191 |
|
|
192 |
|
} |
193 |
0 |
if (exerror != null) |
194 |
|
{ |
195 |
0 |
if (errmsg != null && errmsg.length() > 0) |
196 |
|
{ |
197 |
0 |
throw new IOException(errmsg, exerror); |
198 |
|
} |
199 |
|
else |
200 |
|
{ |
201 |
0 |
throw new IOException(errmsg, exerror); |
202 |
|
} |
203 |
|
} |
204 |
|
else |
205 |
|
{ |
206 |
0 |
if (errmsg != null && errmsg.length() > 0) |
207 |
|
{ |
208 |
0 |
throw new IOException(errmsg); |
209 |
|
} |
210 |
|
} |
211 |
|
} |
212 |
0 |
if (deuniquify) |
213 |
|
{ |
214 |
0 |
context.getLastAlignmentSet().deuniquifyAlignment(); |
215 |
|
} |
216 |
0 |
return rslt.toArray(); |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@param |
226 |
|
|
|
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 9 |
Complexity Density: 0.26 |
|
227 |
0 |
public static void main(String args[])... |
228 |
|
{ |
229 |
|
|
230 |
0 |
int i = 0; |
231 |
0 |
List<DataProvider> dp = new ArrayList<DataProvider>(); |
232 |
0 |
while ((i + 1) < args.length) |
233 |
|
{ |
234 |
0 |
String type = args[i++]; |
235 |
0 |
final String file = args[i++]; |
236 |
0 |
final JvDataType jtype = DataProvider.JvDataType |
237 |
|
.valueOf(type.toUpperCase()); |
238 |
0 |
if (jtype != null) |
239 |
|
{ |
240 |
0 |
final FileParse fp; |
241 |
0 |
try |
242 |
|
{ |
243 |
0 |
fp = new FileParse(file, AppletFormatAdapter.checkProtocol(file)); |
244 |
|
} catch (Exception e) |
245 |
|
{ |
246 |
0 |
System.err.println("Couldn't handle datasource of type " + jtype |
247 |
|
+ " using URI " + file); |
248 |
0 |
e.printStackTrace(); |
249 |
0 |
return; |
250 |
|
} |
251 |
0 |
dp.add(new SimpleDataProvider(jtype, fp, null)); |
252 |
|
} |
253 |
|
else |
254 |
|
{ |
255 |
0 |
System.out.println("Couldn't parse source type token '" |
256 |
|
+ type.toUpperCase() + "'"); |
257 |
|
} |
258 |
|
} |
259 |
0 |
if (i < args.length) |
260 |
|
{ |
261 |
0 |
System.out.print("** WARNING\nIgnoring unused arguments:\n"); |
262 |
0 |
while (i < args.length) |
263 |
|
{ |
264 |
0 |
System.out.print(" " + args[i]); |
265 |
|
} |
266 |
0 |
System.out.print("\n"); |
267 |
|
|
268 |
|
} |
269 |
0 |
System.out.println("Now trying to parse set:"); |
270 |
0 |
JalviewDataset context; |
271 |
0 |
Object[] newdm; |
272 |
0 |
ParsePackedSet pps; |
273 |
0 |
try |
274 |
|
{ |
275 |
0 |
newdm = (pps = new ParsePackedSet()) |
276 |
|
.getAlignment(context = new JalviewDataset(), dp); |
277 |
|
} catch (Exception e) |
278 |
|
{ |
279 |
0 |
System.out.println("Test failed for these arguments.\n"); |
280 |
0 |
e.printStackTrace(System.out); |
281 |
0 |
return; |
282 |
|
} |
283 |
0 |
if (newdm != null) |
284 |
|
{ |
285 |
0 |
for (Object o : newdm) |
286 |
|
{ |
287 |
0 |
System.out.println("Will need to create an " + o.getClass()); |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
} |
296 |
|
else |
297 |
|
{ |
298 |
0 |
if (context.getLastAlignmentSet().isModified()) |
299 |
|
{ |
300 |
0 |
System.err.println( |
301 |
|
"Initial alignment set was modified and any associated views should be updated."); |
302 |
|
} |
303 |
|
} |
304 |
|
} |
305 |
|
} |