Skip to content

Commit 31939ad

Browse files
committed
Bugfix: ScopFactory wasn't working after last commit
1 parent a73eee7 commit 31939ad

3 files changed

Lines changed: 23 additions & 58 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/scop/ScopFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public void testVersions() {
7575
scop = ScopFactory.getSCOP(ScopFactory.VERSION_1_75);
7676
assertEquals(ScopFactory.VERSION_1_75, scop.getScopVersion());
7777

78-
ScopFactory.setScopDatabase(ScopFactory.VERSION_1_75, true);
78+
ScopFactory.setScopDatabase(ScopFactory.VERSION_1_75);
7979
scop = ScopFactory.getSCOP();
8080
assertEquals(ScopFactory.VERSION_1_75, scop.getScopVersion());
8181
assertSame( BerkeleyScopInstallation.class,scop.getClass());
8282

83-
ScopFactory.setScopDatabase(ScopFactory.LATEST_VERSION, true);
83+
ScopFactory.setScopDatabase(ScopFactory.LATEST_VERSION);
8484
scop = ScopFactory.getSCOP();
8585
assertEquals(ScopFactory.LATEST_VERSION, scop.getScopVersion());
8686
assertSame( BerkeleyScopInstallation.class,scop.getClass());

biojava-structure/src/main/java/org/biojava/nbio/structure/scop/ScopFactory.java

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class ScopFactory {
8181
public static final String LATEST_VERSION = VERSION_2_0_7;
8282

8383
// Hold one instance for each version
84-
private static Map<String,ScopDatabase> versionedScopDBs = new HashMap<String, ScopDatabase>();
84+
private static Map<String,ScopDatabase> versionedScopDBs = new HashMap<>();
8585
private static String defaultVersion = LATEST_VERSION;
8686

8787
/**
@@ -92,64 +92,33 @@ public static ScopDatabase getSCOP(){
9292
return getSCOP(defaultVersion);
9393
}
9494

95-
/**
96-
*
97-
* @param forceLocalData Whether to use a local installation or a remote installation
98-
* @return
99-
* @see #getSCOP(String, boolean)
100-
*/
101-
public static ScopDatabase getSCOP(boolean forceLocalData) {
102-
return getSCOP(defaultVersion, forceLocalData);
103-
}
104-
105-
/**
106-
* requests a particular version of SCOP.
107-
*
108-
* Where possible, this will be the current default instance.
109-
* Otherwise a new instance will be created.
110-
* @param version
111-
* @return
112-
*/
113-
public static ScopDatabase getSCOP(String version){
114-
// Default to a remote installation
115-
return getSCOP(version,false);
116-
}
117-
11895
/**
11996
* Gets an instance of the specified scop version.
12097
*
12198
* <p>
122-
* The particular implementation returned is influenced by the <tt>forceLocalData</tt>
123-
* parameter. When false, the instance returned will generally be a
124-
* remote {@link ScopDatabase}, although this may be influenced by
125-
* previous calls to this class. When true, the result is guaranteed to
99+
* The particular implementation returned is guaranteed to
126100
* implement {@link LocalScopDatabase} (generally a {@link BerkeleyScopInstallation}).
127101
*
128-
* <p>
129-
* Note that
130102
* @param version A version number, such as {@link #VERSION_1_75A}
131-
* @param forceLocalData Whether to use a local installation or a remote installation
132103
* @return an
133104
*/
134-
public static ScopDatabase getSCOP(String version, boolean forceLocalData){
105+
public static ScopDatabase getSCOP(String version){
135106
if( version == null ) {
136107
version = defaultVersion;
137108
}
109+
138110
ScopDatabase scop = versionedScopDBs.get(version);
139-
if ( forceLocalData) {
111+
if (scop == null) {
140112
// Use a local installation
141-
if( scop == null || !(scop instanceof LocalScopDatabase) ) {
142-
logger.info("Creating new {}, version {}", BerkeleyScopInstallation.class.getSimpleName(), version);
143-
BerkeleyScopInstallation berkeley = new BerkeleyScopInstallation();
144-
berkeley.setScopVersion(version);
145-
versionedScopDBs.put(version,berkeley);
146-
return berkeley;
147-
}
113+
logger.info("Creating new {}, version {}", BerkeleyScopInstallation.class.getSimpleName(), version);
114+
BerkeleyScopInstallation berkeley = new BerkeleyScopInstallation();
115+
berkeley.setScopVersion(version);
116+
versionedScopDBs.put(version, berkeley);
117+
return berkeley;
148118
}
149119
return scop;
150120
}
151121

152-
153122
/**
154123
* Set the default scop version
155124
* @param version A version number, such as {@link #VERSION_1_75A}
@@ -159,17 +128,6 @@ public static void setScopDatabase(String version) {
159128
defaultVersion = version;
160129
}
161130

162-
/**
163-
* Set the default scop version
164-
* @param version A version number, such as {@link #VERSION_1_75A}
165-
* @param forceLocalData Whether to use a local installation or a remote installation
166-
*/
167-
public static void setScopDatabase(String version, boolean forceLocalData) {
168-
logger.debug("ScopFactory: Setting ScopDatabase to version: {}, forced local: {}", version, forceLocalData);
169-
getSCOP(version,forceLocalData);
170-
defaultVersion = version;
171-
}
172-
173131
/**
174132
* Set the default scop version and instance
175133
* @param scop

biojava-structure/src/test/java/org/biojava/nbio/structure/align/ce/CeCPMainTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,24 +407,31 @@ private Atom[] makeDummyCA(int len) throws PDBParseException {
407407
@Test
408408
public void testCECP1() throws IOException, StructureException{
409409

410-
//String name1 = "PDP:3A2KAc";
411410
String pdb1 = "3A2K";
412-
String name2 = "d1wy5a2";
411+
//String name1 = "PDP:3A2KAc"; // A : 234-333
412+
String pdb2 = "1WY5";
413+
//String name2 = "d1wy5a2"; // A : 217-311
413414

414415
AtomCache cache = new AtomCache();
415416

416417
// since BioJava 6.0.0, there's no PDP provider. The below corresponds to domain "PDP:3A2KAc"
417418
List<ResidueRange> ranges = new ArrayList<>();
418-
// 234-333
419419
ranges.add(new ResidueRange("A", new ResidueNumber("A",234, null), new ResidueNumber("A", 333, null)));
420420
SubstructureIdentifier ssi = new SubstructureIdentifier(pdb1, ranges);
421421
Structure structure1 = cache.getStructure(pdb1);
422422
ssi.reduce(structure1);
423423

424+
// since BioJava 6.0.0, there's no RemoteSCOP provider. The below corresponds to domain "d1wy5a2"
425+
ranges = new ArrayList<>();
426+
ranges.add(new ResidueRange("A", new ResidueNumber("A",217, null), new ResidueNumber("A", 311, null)));
427+
ssi = new SubstructureIdentifier(pdb2, ranges);
428+
Structure structure2 = cache.getStructure(pdb2);
429+
ssi.reduce(structure2);
430+
424431
CeCPMain algorithm = new CeCPMain();
425432

426433
Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
427-
Atom[] ca2 = cache.getAtoms(name2);
434+
Atom[] ca2 = StructureTools.getAtomCAArray(structure2);
428435

429436
AFPChain afpChain = algorithm.align(ca1, ca2);
430437
CECalculator calculator = algorithm.getCECalculator();

0 commit comments

Comments
 (0)