|
22 | 22 |
|
23 | 23 | import static org.junit.Assert.*; |
24 | 24 |
|
| 25 | +import java.io.BufferedReader; |
25 | 26 | import java.io.File; |
| 27 | +import java.io.FileReader; |
26 | 28 | import java.io.IOException; |
| 29 | +import java.io.Reader; |
| 30 | +import java.io.StringReader; |
27 | 31 | import java.util.ArrayList; |
28 | 32 | import java.util.Arrays; |
29 | 33 | import java.util.Collections; |
|
47 | 51 | import org.biojava.nbio.structure.ecod.EcodDomain; |
48 | 52 | import org.biojava.nbio.structure.ecod.EcodFactory; |
49 | 53 | import org.biojava.nbio.structure.ecod.EcodInstallation; |
| 54 | +import org.biojava.nbio.structure.ecod.EcodInstallation.EcodParser; |
50 | 55 | import org.junit.Ignore; |
51 | 56 | import org.junit.Rule; |
52 | 57 | import org.junit.Test; |
@@ -277,12 +282,47 @@ public void testFilterByHierarchy() throws IOException { |
277 | 282 | assertEquals(expected,actual); |
278 | 283 | } |
279 | 284 |
|
| 285 | + /** |
| 286 | + * Checks that the current release can still be read. |
| 287 | + * <p> |
| 288 | + * The version is read from the file's header without parsing the domains, so this |
| 289 | + * additionally parses the first few thousand lines of the same file. That is enough to |
| 290 | + * notice a column change — which is what ECOD did at v294.1, unnoticed for months — |
| 291 | + * without building the three million domains the whole file now holds. |
| 292 | + */ |
280 | 293 | @Test |
281 | 294 | public void testVersion() throws IOException { |
282 | 295 | EcodDatabase ecod3 = EcodFactory.getEcodDatabase("latest"); |
283 | 296 | String version = ecod3.getVersion(); |
284 | 297 | assertNotNull(version); |
285 | 298 | assertNotEquals("latest", version); |
| 299 | + System.out.println("latest version of ECOD is "+version); |
| 300 | + |
| 301 | + File domainsFile = new File(((EcodInstallation) ecod3).getCacheLocation(), |
| 302 | + "ecod.latest.domains.txt"); |
| 303 | + assertTrue("No local copy of the domains file at "+domainsFile, domainsFile.exists()); |
| 304 | + |
| 305 | + EcodParser parser = new EcodParser(firstLines(domainsFile, 5000)); |
| 306 | + assertEquals(version, parser.getVersion()); |
| 307 | + assertFalse("No domains parsed from ECOD "+version |
| 308 | + + "; the distribution format has probably changed", |
| 309 | + parser.getDomains().isEmpty()); |
| 310 | + } |
| 311 | + |
| 312 | + /** |
| 313 | + * @return a reader over the first {@code maxLines} lines of the file |
| 314 | + */ |
| 315 | + private static Reader firstLines(File f, int maxLines) throws IOException { |
| 316 | + StringBuilder head = new StringBuilder(); |
| 317 | + try (BufferedReader in = new BufferedReader(new FileReader(f))) { |
| 318 | + String line; |
| 319 | + int n = 0; |
| 320 | + while (n < maxLines && (line = in.readLine()) != null) { |
| 321 | + head.append(line).append('\n'); |
| 322 | + n++; |
| 323 | + } |
| 324 | + } |
| 325 | + return new StringReader(head.toString()); |
286 | 326 | } |
287 | 327 |
|
288 | 328 | /** |
|
0 commit comments