Skip to content

Commit 3e808d4

Browse files
committed
Merge branch 'master' into removeLoadChemCompInfo
2 parents a73d6f5 + 4d0de44 commit 3e808d4

File tree

18 files changed

+779
-136
lines changed

18 files changed

+779
-136
lines changed

biojava-aa-prop/src/test/java/org/biojava/nbio/aaproperties/profeat/CookBookTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.biojava.nbio.aaproperties.profeat.IProfeatProperties.GROUPING;
2626
import org.biojava.nbio.aaproperties.profeat.IProfeatProperties.TRANSITION;
2727
import org.biojava.nbio.aaproperties.profeat.ProfeatProperties;
28-
import org.junit.Test;
28+
//import org.junit.Test;
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
3131

@@ -35,7 +35,8 @@ public class CookBookTest {
3535

3636
private final static Logger logger = LoggerFactory.getLogger(CookBookTest.class);
3737

38-
@Test
38+
// TODO there's no assertions here, i.e. this is not a test! must fix! For the moment removed test tags - JD 2016-03-08
39+
3940
public void shortExample1() throws Exception{
4041
/*
4142
* Composition
@@ -50,7 +51,7 @@ public void shortExample1() throws Exception{
5051
}
5152
}
5253

53-
@Test
54+
5455
public void shortExample2() throws Exception{
5556
/*
5657
* Transition
@@ -68,7 +69,7 @@ public void shortExample2() throws Exception{
6869
}
6970
}
7071

71-
@Test
72+
7273
public void shortExample3() throws Exception{
7374
/*
7475
* Distribution
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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.alignment;
22+
23+
import static org.junit.Assert.*;
24+
25+
import org.biojava.nbio.core.alignment.template.Profile;
26+
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
27+
import org.biojava.nbio.core.sequence.DNASequence;
28+
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
29+
import org.biojava.nbio.core.util.ConcurrencyTools;
30+
import org.junit.Before;
31+
import org.junit.Ignore;
32+
import org.junit.Test;
33+
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
37+
public class TestSubOptimalMSA {
38+
39+
private List<DNASequence> sequences = new ArrayList<DNASequence>();
40+
41+
@Before
42+
public void setUp() {
43+
try {
44+
sequences.add(new DNASequence("TTGGGGCCTCTAAACGGGGTCTT"));
45+
sequences.add(new DNASequence("TTGGGGCCTCTAAACGGGTCTT"));
46+
sequences.add(new DNASequence("TTGGGGCTCTAACGGGTCTT"));
47+
} catch (CompoundNotFoundException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
52+
@Test
53+
public void gapPenalty52() {
54+
SimpleGapPenalty gapP = new SimpleGapPenalty((short) 5, (short) 2);
55+
Profile<DNASequence, NucleotideCompound> msa = Alignments
56+
.getMultipleSequenceAlignment(sequences, gapP);
57+
58+
assertEquals("TTGGGGCCTCTAAACGGGGTCTT\n"
59+
+ "TTGGGGCCTCTAAACGGG-TCTT\n"
60+
+ "TTGGGGC-TCTAA-CGGG-TCTT\n",
61+
msa.toString());
62+
63+
ConcurrencyTools.shutdown();
64+
}
65+
66+
@Test @Ignore
67+
public void gapPenaltyDefault() {
68+
// Default is currently 10-1
69+
SimpleGapPenalty gapP = new SimpleGapPenalty((short) 10, (short) 1);
70+
Profile<DNASequence, NucleotideCompound> msa = Alignments
71+
.getMultipleSequenceAlignment(sequences, gapP);
72+
73+
// TODO test not passing (see issue 288 in github) - Aleix 03.2016
74+
assertEquals("TTGGGGCCTCTAAACGGGGTCTT\n"
75+
+ "TTGGGGCCTCTAAACGGG-TCTT\n"
76+
+ "TTGGGGC-TCTAA-CGGG-TCTT\n",
77+
msa.toString());
78+
79+
ConcurrencyTools.shutdown();
80+
}
81+
}

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

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

228228
Structure structure = null;
229229
try {
230-
structure = StructureIO.getBiologicalAssembly(pdbId, bioAssemblyId);
230+
structure = cache.getBiologicalAssembly(pdbId, bioAssemblyId);
231231
} catch (IOException e) {
232232
// TODO Auto-generated catch block
233233
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
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ public SubstructureIdentifier(String id) {
8686
if(1 > idRange.length || idRange.length > 2 ) {
8787
throw new IllegalArgumentException(String.format("Malformed %s: %s",getClass().getSimpleName(),id));
8888
}
89-
this.pdbId = idRange[0];
90-
if(this.pdbId.length() != 4) {
89+
if(idRange[0].length() != 4) {
90+
this.pdbId = idRange[0];
9191
// Changed from Exception to a warning to support files and stuff -sbliven 2015/01/22
9292
logger.warn(String.format("Unrecognized PDB code %s",this.pdbId));
93+
} else {
94+
this.pdbId = idRange[0].toUpperCase();
9395
}
9496

9597
if( idRange.length == 2) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public Structure loadStructure(AtomCache cache) throws StructureException,
177177
public static String guessPDBID(String name) {
178178
Matcher match = PDBID_REGEX.matcher(name);
179179
if(match.matches()) {
180-
return match.group(1);
180+
return match.group(1).toUpperCase();
181181
} else {
182182
// Give up if doesn't match
183183
return null;

0 commit comments

Comments
 (0)