Skip to content

Commit 2e35da5

Browse files
committed
Fix biojava#385. Support BIO: identifiers
1 parent e5a54c9 commit 2e35da5

11 files changed

Lines changed: 475 additions & 128 deletions

File tree

biojava-structure-gui/src/main/java/demo/DemoOrientBioAssembly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private static Structure readStructure(String pdbId, int bioAssemblyId) {
228228

229229
Structure structure = null;
230230
try {
231-
structure = StructureIO.getBiologicalAssembly(pdbId, bioAssemblyId);
231+
structure = cache.getBiologicalAssembly(pdbId, bioAssemblyId);
232232
} catch (IOException e) {
233233
// TODO Auto-generated catch block
234234
e.printStackTrace();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.biojava.nbio.structure;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.regex.Matcher;
6+
import java.util.regex.Pattern;
7+
8+
import org.biojava.nbio.structure.align.util.AtomCache;
9+
10+
public class BioAssemblyIdentifier implements StructureIdentifier {
11+
private String pdbCode;
12+
private int biolNr;
13+
14+
public static final Pattern BIO_NAME_PATTERN = Pattern.compile("^(?:BIO:)([0-9][a-z0-9]{3})(?::([0-9]+))?$", Pattern.CASE_INSENSITIVE);
15+
16+
public BioAssemblyIdentifier(String name) {
17+
Matcher match = BIO_NAME_PATTERN.matcher(name);
18+
if(! match.matches() ) {
19+
throw new IllegalArgumentException("Invalid BIO identifier");
20+
}
21+
pdbCode = match.group(1);
22+
if(match.group(2) != null) {
23+
biolNr = Integer.parseInt(match.group(2));
24+
} else {
25+
biolNr = 1;
26+
}
27+
}
28+
29+
public BioAssemblyIdentifier(String pdbCode, int biolNr) {
30+
this.pdbCode = pdbCode;
31+
this.biolNr = biolNr;
32+
}
33+
34+
@Override
35+
public String getIdentifier() {
36+
if( biolNr < 0) {
37+
return "BIO:"+pdbCode;
38+
} else {
39+
return String.format("BIO:%s:%d",pdbCode,biolNr);
40+
}
41+
}
42+
@Override
43+
public String toString() {
44+
return getIdentifier();
45+
}
46+
47+
@Override
48+
public Structure loadStructure(AtomCache cache) throws StructureException,
49+
IOException {
50+
return cache.getBiologicalAssembly(pdbCode, biolNr);
51+
}
52+
53+
@Override
54+
public SubstructureIdentifier toCanonical() throws StructureException {
55+
// null pdbCode indicates that the structure can't be loaded by AtomCache
56+
return new SubstructureIdentifier(null, new ArrayList<ResidueRange>());
57+
}
58+
59+
@Override
60+
public Structure reduce(Structure input) throws StructureException {
61+
// Should be the full structure
62+
return input;
63+
}
64+
65+
}

biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,30 @@ public static Structure getBiologicalAssembly(String pdbId) throws IOException,
145145
* @throws IOException
146146
*/
147147
public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr) throws IOException, StructureException {
148+
checkInitAtomCache();
149+
return getBiologicalAssembly(pdbId,biolAssemblyNr,StructureIO.cache);
150+
}
151+
public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr, AtomCache cache) throws IOException, StructureException {
152+
153+
BioUnitDataProvider provider = null;
154+
try {
155+
provider = BioUnitDataProviderFactory.getBioUnitDataProvider();
156+
provider.setAtomCache(cache);
157+
Structure bio = getBiologicalAssembly(pdbId, biolAssemblyNr,cache,BioUnitDataProviderFactory.getBioUnitDataProvider());
158+
return bio;
159+
} finally {
160+
if(provider != null) {
161+
//cleanup to avoid memory leaks
162+
provider.setAsymUnit(null);
163+
provider.setAtomCache(null);
164+
}
165+
}
166+
}
167+
public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr, AtomCache cache, BioUnitDataProvider provider) throws IOException, StructureException {
148168

149169
pdbId = pdbId.toLowerCase();
150170

151-
BioUnitDataProvider provider = BioUnitDataProviderFactory.getBioUnitDataProvider();
152171

153-
checkInitAtomCache();
154-
provider.setAtomCache(cache);
155172

156173
Structure asymUnit = provider.getAsymUnit(pdbId);
157174

@@ -168,9 +185,6 @@ public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr)
168185
List<BiologicalAssemblyTransformation> transformations =
169186
asymUnit.getPDBHeader().getBioAssemblies().get(biolAssemblyNr).getTransforms();
170187

171-
//cleanup to avoid memory leaks
172-
provider.setAsymUnit(null);
173-
provider.setAtomCache(null);
174188

175189
if ( transformations == null || transformations.size() == 0){
176190

@@ -179,8 +193,6 @@ public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr)
179193
BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder();
180194

181195
return builder.rebuildQuaternaryStructure(asymUnit, transformations);
182-
183-
184196
}
185197

186198
/**

0 commit comments

Comments
 (0)