Skip to content

Commit 8be282f

Browse files
committed
Allow single-residue ranges
e.g. "A:1" rather than "A:1-1"
1 parent a4bdcb7 commit 8be282f

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ public void testGetSubRanges() throws StructureException {
164164
chain = substr.getChain(0);
165165
assertEquals("Did not find the expected number of residues in "+range, 5, chain.getAtomLength() );
166166

167+
// single residue
168+
range = "A:3";
169+
substr = StructureTools.getSubRanges(structure2, range);
170+
assertEquals("Wrong number of chains in "+range, 1, substr.size());
171+
chain = substr.getChain(0);
172+
assertEquals("Did not find the expected number of residues in "+range, 1, chain.getAtomLength() );
173+
167174
// Special '-' case
168175
range = "-";
169176
substr = StructureTools.getSubRanges(structure2, range);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ public class ResidueRange {
4747
"(?::|_|:$|_$|$)" + //colon or underscore, could be at the end of a line, another non-capt. group.
4848
"(?:"+ // another non capturing group for the residue range
4949
"([-+]?[0-9]+[A-Za-z]?)" + // first residue
50-
"\\s*-\\s*" + // -
51-
"([-+]?[0-9]+[A-Za-z]?)" + // second residue
50+
"(?:" +
51+
"\\s*-\\s*" + // -
52+
"([-+]?[0-9]+[A-Za-z]?)" + // second residue
53+
")?+"+
5254
")?+"+
5355
")?" + //end range
5456
"\\s*");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,11 @@ public static final Structure getSubRanges(Structure s, String ranges )
11511151

11521152
String pdbresnumStart = matcher.group(2);
11531153
String pdbresnumEnd = matcher.group(3);
1154+
1155+
if(pdbresnumEnd == null ) {
1156+
// Single residue range
1157+
pdbresnumEnd = pdbresnumStart;
1158+
}
11541159

11551160

11561161
if ( ! firstRange){

biojava-structure/src/test/java/org/biojava/nbio/structure/ResidueRangeTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,8 @@ public void testRangeRegex() {
327327
// Valid ranges
328328
String[] yes = new String[] { "A_", "A:", "ABC:", "abc:", "A_5-100",
329329
"A_5-100S", "A_5S-100", "A_5S-100S", "A_-5-100", "A_-5--100",
330-
"A_-5S--100S", "ABC:-5--200S", "A", "ABCD", "A1", // valid
331-
// multi-char
332-
// chain
333-
// name
330+
"A_-5S--100S", "ABC:-5--200S", "A", "ABCD", "A_1",
331+
"A1", // valid multi-char chain name
334332
"3A:1-100", // Weird chain name
335333
"_", "_:1-10", "__-2--1", "__"// catch-all chain
336334
};
@@ -339,7 +337,7 @@ public void testRangeRegex() {
339337
ResidueRange.RANGE_REGEX.matcher(s).matches());
340338
}
341339
// invalid ranges
342-
String[] no = new String[] { "A_1", "A_1-", "A_1S-", "A_1-100-",
340+
String[] no = new String[] { "A_1-", "A_1S-", "A_1-100-",
343341
"A_-10-1000_", "", "-", "___", "__:" };
344342
for (String s : no) {
345343
assertFalse(s + " was considered a valid range format",

0 commit comments

Comments
 (0)