Skip to content

Commit c2b00fc

Browse files
committed
Merge pull request biojava#481 from sbliven/ecod-rebase
Automatically re-download ECOD if the cache is >2weeks old
2 parents eade31d + 27fd44b commit c2b00fc

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.biojava.nbio.structure.ecod.EcodDomain;
4848
import org.biojava.nbio.structure.ecod.EcodFactory;
4949
import org.biojava.nbio.structure.ecod.EcodInstallation;
50+
import org.junit.Ignore;
5051
import org.junit.Rule;
5152
import org.junit.Test;
5253
import org.junit.rules.TemporaryFolder;
@@ -60,13 +61,13 @@
6061
public class EcodInstallationTest {
6162

6263
private static final Logger logger = LoggerFactory.getLogger(EcodInstallationTest.class);
63-
private static final String VERSION = "develop124"; // Should be updated periodically
64+
private static final String VERSION = "develop133"; // Should be updated periodically
6465

6566
// Info about known versions, for testing
66-
private static final int DEVELOP_FIRST_VERSION = 45;
67-
private static final int DEVELOP_LATEST_VERSTION = 124; // Should be updated periodically
67+
private static final int DEVELOP_FIRST_VERSION = 124;
68+
private static final int DEVELOP_LATEST_VERSTION = 136; // Should be updated periodically
6869
//versions known to be unreleased
69-
private static final List<Integer> DEVELOP_VERSIONS_BLACKLIST = Arrays.asList( 85, 107, 113 );
70+
private static final List<Integer> DEVELOP_VERSIONS_BLACKLIST = Arrays.asList( 85, 107, 113, 125, 128, 131 );
7071

7172
static {
7273
//System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
@@ -106,6 +107,18 @@ public void testAllDomains() throws IOException {
106107
case "develop124":
107108
expected = 468680; //version124
108109
break;
110+
case "develop133":
111+
expected = 479738; //version133
112+
break;
113+
case "develop134":
114+
expected = 483056; //version134 (stats file)
115+
break;
116+
case "develop135":
117+
expected = 483812; //version135 (stats file)
118+
break;
119+
case "develop136":
120+
expected = 484847; //version136 (stats file)
121+
break;
109122
default:
110123
fail("Unrecognized version "+VERSION);
111124
return;
@@ -154,10 +167,9 @@ public void testParsing() throws IOException {
154167
// String chainName, String range, String seqId, String architectureName,
155168
".", "A:3-97,B:106-346", "A:3-97,B:1-241", "beta barrels",
156169
// String xGroupName, String hGroupName, String tGroupName,
157-
"cradle loop barrel", "RIFT-related",
158-
"NO_T_NAME",// should be "acid protease" except for bug in develop124
170+
"cradle loop barrel", "RIFT-related","acid protease",
159171
// String fGroupName, Boolean isAssembly, List<String> ligands
160-
"EF00710",//"UNK_F_TYPE",
172+
"EF00710",
161173
20669l, Collections.singleton("EPE")
162174
);
163175
assertEquals(ecodId,expected,domain);

biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodInstallation.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import java.net.MalformedURLException;
2929
import java.net.URL;
3030
import java.util.ArrayList;
31+
import java.util.Calendar;
3132
import java.util.Collections;
33+
import java.util.Date;
3234
import java.util.HashMap;
3335
import java.util.LinkedHashSet;
3436
import java.util.LinkedList;
@@ -86,6 +88,9 @@ public class EcodInstallation implements EcodDatabase {
8688

8789
private String url;
8890

91+
// Frequency of ECOD updates, in days. If non-null, redownloads "latest" if older than this.
92+
private Integer updateFrequency = 14;
93+
8994
/**
9095
* Use EcodFactory to create instances. The instantiation of multiple
9196
* installations at the same path can lead to race conditions when downloading
@@ -359,7 +364,25 @@ private boolean domainsAvailable() {
359364
try {
360365
File f = getDomainFile();
361366

362-
return f.exists() && f.length()>0;
367+
if (!f.exists() || f.length() <= 0 )
368+
return false;
369+
370+
// Re-download old copies of "latest"
371+
if(updateFrequency != null && requestedVersion == DEFAULT_VERSION ) {
372+
long mod = f.lastModified();
373+
// Time of last update
374+
Date lastUpdate = new Date();
375+
Calendar cal = Calendar.getInstance();
376+
cal.setTime(lastUpdate);
377+
cal.add(Calendar.DAY_OF_WEEK, -updateFrequency);
378+
long updateTime = cal.getTimeInMillis();
379+
// Check if file predates last update
380+
if( mod < updateTime ) {
381+
logger.info("{} is out of date.",f);
382+
return false;
383+
}
384+
}
385+
return true;
363386
} finally {
364387
logger.trace("UNLOCK readlock");
365388
domainsFileLock.readLock().unlock();
@@ -403,6 +426,27 @@ private File getDomainFile() {
403426
return new File(getCacheLocation(),getDomainFilename());
404427
}
405428

429+
/**
430+
* The expected ECOD update frequency determines whether the version
431+
* "latest" should be re-downloaded
432+
* @return the expected ECOD update frequency, in days
433+
*/
434+
public Integer getUpdateFrequency() {
435+
return updateFrequency;
436+
}
437+
438+
/**
439+
* The "latest" version will be re-downloaded if it is older than
440+
* {@link #getUpdateFrequency()} days. Setting this to null disables
441+
* re-downloading (delete $PDB_CACHE_DIR/ecod.latest.domains.txt manually
442+
* to force updating). Setting to 0 will force downloading for every
443+
* program execution.
444+
* @param updateFrequency the updateFrequency to set
445+
*/
446+
public void setUpdateFrequency(Integer updateFrequency) {
447+
this.updateFrequency = updateFrequency;
448+
}
449+
406450
/**
407451
* Parses the domains from the local file
408452
* @throws IOException

0 commit comments

Comments
 (0)