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