Skip to content

Commit 9cd191c

Browse files
authored
Merge pull request #1141 from aalhossary/aa/ecod-new-format
Support the new ECOD distribution format
2 parents 4ab9f4a + cbab39b commit 9cd191c

3 files changed

Lines changed: 767 additions & 51 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/ecod/EcodInstallationTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222

2323
import static org.junit.Assert.*;
2424

25+
import java.io.BufferedReader;
2526
import java.io.File;
27+
import java.io.FileReader;
2628
import java.io.IOException;
29+
import java.io.Reader;
30+
import java.io.StringReader;
2731
import java.util.ArrayList;
2832
import java.util.Arrays;
2933
import java.util.Collections;
@@ -47,6 +51,7 @@
4751
import org.biojava.nbio.structure.ecod.EcodDomain;
4852
import org.biojava.nbio.structure.ecod.EcodFactory;
4953
import org.biojava.nbio.structure.ecod.EcodInstallation;
54+
import org.biojava.nbio.structure.ecod.EcodInstallation.EcodParser;
5055
import org.junit.Ignore;
5156
import org.junit.Rule;
5257
import org.junit.Test;
@@ -277,12 +282,47 @@ public void testFilterByHierarchy() throws IOException {
277282
assertEquals(expected,actual);
278283
}
279284

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+
*/
280293
@Test
281294
public void testVersion() throws IOException {
282295
EcodDatabase ecod3 = EcodFactory.getEcodDatabase("latest");
283296
String version = ecod3.getVersion();
284297
assertNotNull(version);
285298
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());
286326
}
287327

288328
/**

0 commit comments

Comments
 (0)