Skip to content

Commit 750b1a3

Browse files
committed
ECOD improvements
- Moved all ECOD code to its own package - Added EcodFactory to manage singletons - Improved documentation - Added EcodDatabase interface (for future remote implementations) - getVersion() returns parsed version rather than "latest"
1 parent 3946214 commit 750b1a3

File tree

5 files changed

+377
-111
lines changed

5 files changed

+377
-111
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import java.util.concurrent.TimeoutException;
2121

2222
import org.biojava.nbio.core.util.ConcurrencyTools;
23-
import org.biojava.nbio.structure.domain.EcodDomain;
24-
import org.biojava.nbio.structure.domain.EcodInstallation;
25-
import org.biojava.nbio.structure.io.util.FileDownloadUtils;
23+
import org.biojava.nbio.structure.ecod.EcodDatabase;
24+
import org.biojava.nbio.structure.ecod.EcodDomain;
25+
import org.biojava.nbio.structure.ecod.EcodFactory;
26+
import org.biojava.nbio.structure.ecod.EcodInstallation;
2627
import org.junit.Rule;
2728
import org.junit.Test;
2829
import org.junit.rules.TemporaryFolder;
@@ -41,8 +42,7 @@ public class EcodInstallationTest {
4142

4243
// Set up static ecod singleton
4344
static {
44-
ecod = new EcodInstallation();
45-
ecod.setVersion(VERSION);
45+
ecod = (EcodInstallation) EcodFactory.getEcodDatabase(VERSION);
4646
}
4747

4848
static {
@@ -53,8 +53,7 @@ public class EcodInstallationTest {
5353
@Test
5454
public void testDownloads() throws IOException {
5555
// Use second installation with tmp location to avoid overwriting main cache
56-
EcodInstallation ecod2 = new EcodInstallation(tmpFolder.getRoot().getAbsolutePath());
57-
ecod2.setVersion(VERSION);
56+
EcodInstallation ecod2 = new EcodInstallation(tmpFolder.getRoot().getAbsolutePath(),VERSION);
5857
// Delete old VERSION
5958
File domainsFile = new File(ecod2.getCacheLocation(),"ecod."+VERSION+".domains.txt");
6059
if( domainsFile.exists() ) {
@@ -80,7 +79,7 @@ public void testByPDB() throws IOException {
8079

8180
pdbId = "1lyw";
8281
expectedDomains = new String[] {"e1lyw.1","e1lyw.2","e1lyw.3","e1lyw.4"};
83-
domains = ecod.getDomainsForPDB(pdbId);
82+
domains = ecod.getDomainsForPdb(pdbId);
8483

8584
matchNames(pdbId,expectedDomains,domains);
8685

@@ -114,7 +113,11 @@ public void testParsing() throws IOException {
114113
"UNK_F_TYPE", false, Collections.singleton("EPE")
115114
);
116115
assertEquals(ecodId,expected,domain);
117-
116+
117+
ecodId = "e4v4fAA1";
118+
domain = ecod.getDomainsById(ecodId);
119+
assertNotNull(ecodId,domain);
120+
assertEquals(ecodId,ecodId,domain.getDomainId());
118121
}
119122

120123
@Test
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*/
20+
21+
package org.biojava.nbio.structure.ecod;
22+
23+
import java.io.IOException;
24+
import java.util.List;
25+
26+
import org.biojava.nbio.structure.cath.CathCategory;
27+
import org.biojava.nbio.structure.cath.CathDomain;
28+
import org.biojava.nbio.structure.cath.CathFragment;
29+
import org.biojava.nbio.structure.cath.CathNode;
30+
31+
/** General API for interacting with CATH.
32+
*
33+
* @author Spencer Bliven
34+
*/
35+
public interface EcodDatabase {
36+
37+
/** Return the release version.
38+
*
39+
* @return version
40+
*/
41+
public String getVersion();
42+
43+
/**
44+
* Get a particular ECOD domain by the domain ID (e.g. "e4hhbA1")
45+
* @param ecodId
46+
* @return
47+
* @throws IOException
48+
*/
49+
public EcodDomain getDomainsById(String ecodId) throws IOException;
50+
51+
/**
52+
* Get a list of all ECOD domains for a particular PDB ID
53+
* @param pdbId
54+
* @return the list of domains, or null if no matching domains were found
55+
* @throws IOException
56+
*/
57+
public List<EcodDomain> getDomainsForPdb(String pdbId) throws IOException;
58+
59+
/**
60+
* Get all ECOD domains
61+
* @return
62+
* @throws IOException
63+
*/
64+
public List<EcodDomain> getAllDomains() throws IOException;
65+
}

biojava-structure/src/main/java/org/biojava/nbio/structure/domain/EcodDomain.java renamed to biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDomain.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1-
package org.biojava.nbio.structure.domain;
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*/
20+
package org.biojava.nbio.structure.ecod;
221

322
import java.io.Serializable;
423
import java.util.HashSet;
524
import java.util.List;
625
import java.util.Set;
726

27+
/**
28+
* @author Spencer Bliven
29+
*
30+
*/
831
public class EcodDomain implements Serializable, Cloneable {
932

1033
/*
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*
20+
*/
21+
package org.biojava.nbio.structure.ecod;
22+
23+
import java.util.Collections;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
27+
import org.biojava.nbio.structure.align.util.UserConfiguration;
28+
import org.biojava.nbio.structure.cath.CathDatabase;
29+
import org.biojava.nbio.structure.cath.CathInstallation;
30+
import org.biojava.nbio.structure.scop.ScopFactory;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
33+
34+
/**
35+
* Controls global {@link CathDatabase CathDatabases} being used.
36+
* Implements a multiton pattern through {@link #getCathDatabase(String)},
37+
* and a singleton pattern through {@link #getCathDatabase()}.
38+
* @author Spencer Bliven
39+
* @see ScopFactory
40+
* @see CathInstallation
41+
*/
42+
public class EcodFactory {
43+
44+
private static Logger logger = LoggerFactory.getLogger(EcodFactory.class);
45+
46+
public static String DEFAULT_VERSION = EcodInstallation.DEFAULT_VERSION;
47+
48+
private static Map<String, EcodDatabase> versionedEcodDBs =
49+
Collections.synchronizedMap(new HashMap<String, EcodDatabase>());
50+
private static String defaultVersion = DEFAULT_VERSION;
51+
52+
/**
53+
* Returns the (singleton) database for the current default version
54+
*/
55+
public static EcodDatabase getEcodDatabase() {
56+
return getEcodDatabase(defaultVersion);
57+
}
58+
59+
public static EcodDatabase getEcodDatabase(String version) {
60+
if( version == null )
61+
version = defaultVersion;
62+
63+
synchronized(versionedEcodDBs) {
64+
EcodDatabase ecod = versionedEcodDBs.get(version.toLowerCase());
65+
if( ecod == null ) {
66+
logger.info("Creating new {}, version {}",EcodInstallation.class.getSimpleName(),version);
67+
String cacheDir = new UserConfiguration().getCacheFilePath();
68+
ecod = new EcodInstallation(cacheDir, version);
69+
versionedEcodDBs.put(version.toLowerCase(), ecod);
70+
71+
// If the parsed version differed from that requested, add that too
72+
if( ! versionedEcodDBs.containsKey(ecod.getVersion().toLowerCase()) ) {
73+
versionedEcodDBs.put(ecod.getVersion().toLowerCase(),ecod);
74+
}
75+
}
76+
77+
return ecod;
78+
}
79+
}
80+
81+
/**
82+
* Updates the default version
83+
* @param version
84+
*/
85+
public static void setEcodDatabase(String version) {
86+
getEcodDatabase(version);
87+
defaultVersion = version;
88+
}
89+
90+
/** Can't instantiate */
91+
private EcodFactory() {}
92+
93+
}

0 commit comments

Comments
 (0)