1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
* Created on 2012-12-01
*
*/
package org.biojava.nbio.structure;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.biojava.nbio.structure.io.LocalPDBDirectory;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
import java.util.NavigableMap;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
/**
* A unit test for {@link org.biojava.nbio.structure.AtomPositionMap}.
* @author dmyerstu
*/
public class AtomPositionMapTest {
@Before
public void setUp() throws Exception {
cache = new AtomCache(); // TODO Should mock instead of depending on real data from AtomCache
cache.setObsoleteBehavior(LocalPDBDirectory.ObsoleteBehavior.FETCH_OBSOLETE);
}
private AtomCache cache;
/**
* Tests with no insertion codes.
* @throws StructureException
* @throws IOException
*/
@Ignore("The test requires the network")
@Test
public void testEasy() throws IOException, StructureException { // no insertion codes
// Straightforward case. Density for residues 25-777 (743 residues)
String pdbId = "1w0p";
int length = 93;
ResidueNumber start = new ResidueNumber("A", 25, null);
ResidueNumber end = new ResidueNumber("A", 117, null);
AtomPositionMap map = new AtomPositionMap(cache.getAtoms(pdbId));
NavigableMap<ResidueNumber,Integer> navMap = map.getNavMap();
for (ResidueNumber n : navMap.keySet()) {
assertEquals("An element is missing", map.getPosition(n).intValue(), navMap.get(n).intValue());
}
int realLength = map.getLength(start, end);
assertEquals("Real atom length is wrong", length, realLength);
}
@Ignore("The test requires the network")
@Test
public void testLengths() throws IOException, StructureException {
// Two identical chains, residues 1-68, no insertion codes or missing residues
String pdbId = "3w0e";
Atom[] atoms = cache.getAtoms(pdbId);
AtomPositionMap map = new AtomPositionMap(atoms);
// Double check that the chain length is correct
int chainAlen = cache.getStructure(pdbId).getPolyChainByPDB("A").getAtomGroups(GroupType.AMINOACID).size();
assumeTrue(68==chainAlen);
int len;
int start,end;// 0-based
// Single residue
start = 0;
end = 0;
len = map.getLength(new ResidueNumber("A",start+1,null), new ResidueNumber("A",end+1,null));
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLength(start, end,"A");
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLengthDirectional(start, end, "A");
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLengthDirectional(end, start, "A");
assertEquals("Bad length for ("+start+","+end+")",1, len);
// Short range
start = 2;
end = 4;
len = map.getLength(new ResidueNumber("A",start+1,null), new ResidueNumber("A",end+1,null));
assertEquals("Bad length for ("+start+","+end+")",3, len);
len = map.getLength(start, end,"A");
assertEquals("Bad length for ("+start+","+end+")",3, len);
len = map.getLengthDirectional(start, end, "A");
assertEquals("Bad length for ("+start+","+end+")",3, len);
len = map.getLengthDirectional(end, start, "A");
assertEquals("Bad length for ("+start+","+end+")",-3, len);
//Full chain
start = 0;
end = chainAlen-1;
len = map.getLength(new ResidueNumber("A",start+1,null), new ResidueNumber("A",end+1,null));
assertEquals("Bad length for ("+start+","+end+")",chainAlen, len);
len = map.getLength(start, end,"A");
assertEquals("Bad length for ("+start+","+end+")",chainAlen, len);
len = map.getLengthDirectional(start, end, "A");
assertEquals("Bad length for ("+start+","+end+")",chainAlen, len);
len = map.getLengthDirectional(end, start, "A");
assertEquals("Bad length for ("+start+","+end+")",-chainAlen, len);
// Chain spanning
start = chainAlen-1;
end = chainAlen;
try {
len = map.getLength(new ResidueNumber("A",chainAlen,null), new ResidueNumber("B",1,null));
fail("Not the same chain");
} catch( IllegalArgumentException e) {}
len = map.getLength(start, end,"A");
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLengthDirectional(start, end, "A");
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLengthDirectional(end, start, "A");
assertEquals("Bad length for ("+start+","+end+")",-1, len);
len = map.getLengthDirectional(start,end, "B");
assertEquals("Bad length for ("+start+","+end+")",1, len);
start = chainAlen-2; //2 residues of A
end = chainAlen+2; // 3 residues of B
len = map.getLengthDirectional(start, end, "A");
assertEquals("Bad length for ("+start+","+end+")",2, len);
len = map.getLengthDirectional(end, start, "A");
assertEquals("Bad length for ("+start+","+end+")",-2, len);
len = map.getLengthDirectional(start, end, "B");
assertEquals("Bad length for ("+start+","+end+")",3, len);
len = map.getLengthDirectional(end, start, "B");
assertEquals("Bad length for ("+start+","+end+")",-3, len);
start = 0;
end = chainAlen;
try {
len = map.getLength(new ResidueNumber("A",start+1,null), new ResidueNumber("A",end+1,null));
fail("Residue found from the wrong chain");
} catch( IllegalArgumentException e) {
// end residue should be B1, not A142
}
// Chain Spanning
len = map.getLength(start, end,"B");
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLengthDirectional(start, end, "B");
assertEquals("Bad length for ("+start+","+end+")",1, len);
len = map.getLengthDirectional(end, start, "B");
assertEquals("Bad length for ("+start+","+end+")",-1, len);
len = map.getLength(start, end,"A");
assertEquals("Bad length for ("+start+","+end+")",chainAlen, len);
len = map.getLengthDirectional(start, end, "A");
assertEquals("Bad length for ("+start+","+end+")",chainAlen, len);
len = map.getLengthDirectional(end, start, "A");
assertEquals("Bad length for ("+start+","+end+")",-chainAlen, len);
}
/**
* Tests with insertion codes.
* @throws StructureException
* @throws IOException
*/
@Ignore("The test requires the network")
@Test
public void testInsertionCodes() throws IOException, StructureException {
String pdbId = "1qdm";
// has 2 insertion code regions, lettered P and S, as well as disordered regions:
// 6P-26P,2-163,169-247,1S-37S,65S-104S,248-338
// Len:21, 162, 79, 37, 40, 91 = 430
AtomPositionMap map = new AtomPositionMap(cache.getAtoms(pdbId));
NavigableMap<ResidueNumber,Integer> navMap = map.getNavMap();
for (ResidueNumber n : navMap.keySet()) {
assertEquals("An element is missing", map.getPosition(n).intValue(), navMap.get(n).intValue());
}
int length1 = 60; // 2+37+21
int length2 = 132;// 2+37+40+53
ResidueNumber start = new ResidueNumber("A", 246, null);
ResidueNumber mid = new ResidueNumber("A", 85, 'S');
ResidueNumber end = new ResidueNumber("A", 300, null);
int realLength1 = map.getLength(start, mid);
assertEquals("Real atom length is wrong", length1, realLength1);
int realLength2 = map.getLength(start, end);
assertEquals("Real atom length is wrong", length2, realLength2);
int realLength = map.getLength(new ResidueNumber("A",6,'P'),new ResidueNumber("A",338,null));
assertEquals("Full length wrong",430,realLength);
}
@Ignore("The test requires the network")
@Test
public void testTrim() throws IOException, StructureException {
// Two identical chains, residues 1-68, no insertion codes or missing residues
String pdbId = "3w0e";
AtomPositionMap map = new AtomPositionMap(cache.getAtoms(pdbId));
ResidueRangeAndLength trimmed;
ResidueRange untrimmed;
untrimmed = new ResidueRange("A", "1", "68");
trimmed = map.trimToValidResidues(untrimmed);
assertEquals("Wrong start after trimming "+untrimmed,new ResidueNumber("A", 1, null), trimmed.getStart());
assertEquals("Wrong end after trimming "+untrimmed,new ResidueNumber("A", 68, null), trimmed.getEnd());
assertEquals("Wrong length after trimming "+untrimmed,68, trimmed.getLength());
untrimmed = new ResidueRange("A", "1", "1");
trimmed = map.trimToValidResidues(untrimmed);
assertEquals("Wrong start after trimming "+untrimmed,new ResidueNumber("A", 1, null), trimmed.getStart());
assertEquals("Wrong end after trimming "+untrimmed,new ResidueNumber("A", 1, null), trimmed.getEnd());
assertEquals("Wrong length after trimming "+untrimmed,1, trimmed.getLength());
untrimmed = new ResidueRange("A", "-1", "70");
trimmed = map.trimToValidResidues(untrimmed);
assertEquals("Wrong start after trimming "+untrimmed,new ResidueNumber("A", 1, null), trimmed.getStart());
assertEquals("Wrong end after trimming "+untrimmed,new ResidueNumber("A", 68, null), trimmed.getEnd());
assertEquals("Wrong length after trimming "+untrimmed,68, trimmed.getLength());
// Fully out of range
untrimmed = new ResidueRange("A", "-4", "-1");
trimmed = map.trimToValidResidues(untrimmed);
assertNull("Should be empty range "+untrimmed,trimmed);
// Start before end. Arguably should be invalid, but currently works
untrimmed = new ResidueRange("A", "4", "1");
trimmed = map.trimToValidResidues(untrimmed);
assertEquals("Wrong start after trimming "+untrimmed,new ResidueNumber("A", 4, null), trimmed.getStart());
assertEquals("Wrong end after trimming "+untrimmed,new ResidueNumber("A", 1, null), trimmed.getEnd());
assertEquals("Wrong length after trimming "+untrimmed,4, trimmed.getLength());
// However, doesn't work if the endpoints are invalid, since searches wrong direction
untrimmed = new ResidueRange("A", "4", "-1");
trimmed = map.trimToValidResidues(untrimmed);
assertNull("Should be empty range "+untrimmed,trimmed);
untrimmed = new ResidueRange("A", "70", "50");
trimmed = map.trimToValidResidues(untrimmed);
assertNull("Should be empty range "+untrimmed,trimmed);
}
@Ignore("The test requires the network")
@Test
public void testChains() throws IOException, StructureException {
String pdbId = "1qdm";
AtomPositionMap map = new AtomPositionMap(cache.getAtoms(pdbId));
ResidueNumber start,end;
try {
start = new ResidueNumber("A",6,'P');
end = new ResidueNumber("B",338,null);
map.getLength(start, end);
fail("Chain missmatch");
} catch(IllegalArgumentException e) {
// Expected
}
try {
start = new ResidueNumber("A",6,'P');
end = new ResidueNumber("B",338,null);
map.getLengthDirectional(start, end);
fail("Chain missmatch");
} catch(IllegalArgumentException e) {
// Expected
}
// With integers, only count matching chain atoms
start = new ResidueNumber("A",338,null);
end = new ResidueNumber("B",6,'P');
int len = map.getLength(map.getPosition(start),map.getPosition(end),"A");
assertEquals(1, len);
}
}
|