Skip to content

Commit

Permalink
Allow single-residue ranges
Browse files Browse the repository at this point in the history
e.g. "A:1" rather than "A:1-1"
  • Loading branch information
sbliven committed Apr 15, 2015
1 parent a4bdcb7 commit 8be282f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ public void testGetSubRanges() throws StructureException {
chain = substr.getChain(0);
assertEquals("Did not find the expected number of residues in "+range, 5, chain.getAtomLength() );

// single residue
range = "A:3";
substr = StructureTools.getSubRanges(structure2, range);
assertEquals("Wrong number of chains in "+range, 1, substr.size());
chain = substr.getChain(0);
assertEquals("Did not find the expected number of residues in "+range, 1, chain.getAtomLength() );

// Special '-' case
range = "-";
substr = StructureTools.getSubRanges(structure2, range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class ResidueRange {
"(?::|_|:$|_$|$)" + //colon or underscore, could be at the end of a line, another non-capt. group.
"(?:"+ // another non capturing group for the residue range
"([-+]?[0-9]+[A-Za-z]?)" + // first residue
"\\s*-\\s*" + // -
"([-+]?[0-9]+[A-Za-z]?)" + // second residue
"(?:" +
"\\s*-\\s*" + // -
"([-+]?[0-9]+[A-Za-z]?)" + // second residue
")?+"+
")?+"+
")?" + //end range
"\\s*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,11 @@ public static final Structure getSubRanges(Structure s, String ranges )

String pdbresnumStart = matcher.group(2);
String pdbresnumEnd = matcher.group(3);

if(pdbresnumEnd == null ) {
// Single residue range
pdbresnumEnd = pdbresnumStart;
}


if ( ! firstRange){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,8 @@ public void testRangeRegex() {
// Valid ranges
String[] yes = new String[] { "A_", "A:", "ABC:", "abc:", "A_5-100",
"A_5-100S", "A_5S-100", "A_5S-100S", "A_-5-100", "A_-5--100",
"A_-5S--100S", "ABC:-5--200S", "A", "ABCD", "A1", // valid
// multi-char
// chain
// name
"A_-5S--100S", "ABC:-5--200S", "A", "ABCD", "A_1",
"A1", // valid multi-char chain name
"3A:1-100", // Weird chain name
"_", "_:1-10", "__-2--1", "__"// catch-all chain
};
Expand All @@ -339,7 +337,7 @@ public void testRangeRegex() {
ResidueRange.RANGE_REGEX.matcher(s).matches());
}
// invalid ranges
String[] no = new String[] { "A_1", "A_1-", "A_1S-", "A_1-100-",
String[] no = new String[] { "A_1-", "A_1S-", "A_1-100-",
"A_-10-1000_", "", "-", "___", "__:" };
for (String s : no) {
assertFalse(s + " was considered a valid range format",
Expand Down

0 comments on commit 8be282f

Please sign in to comment.