|
34 | 34 | import org.biojava.nbio.structure.ChainImpl; |
35 | 35 | import org.biojava.nbio.structure.EntityInfo; |
36 | 36 | import org.biojava.nbio.structure.Group; |
| 37 | +import org.biojava.nbio.structure.ResidueNumber; |
37 | 38 | import org.biojava.nbio.structure.Structure; |
38 | 39 | import org.biojava.nbio.structure.StructureException; |
39 | 40 | import org.biojava.nbio.structure.StructureIO; |
@@ -93,40 +94,37 @@ public void testMergeIdentical() { |
93 | 94 | public void testMergeIdenticalByEntityId() { |
94 | 95 |
|
95 | 96 | // Create 2 Atom Arrays, with same entity id |
96 | | - Atom[] reprAtoms1 = mockAtomArray("A", 1, 10, "ALA", -1, null); |
97 | | - Structure structure1 = reprAtoms1[0].getGroup().getChain().getStructure(); |
98 | | - |
99 | | - Atom[] reprAtoms2 = mockAtomArray("B", 1, 10, "PRO", -1, null); |
100 | | - Structure structure2 = reprAtoms2[0].getGroup().getChain().getStructure(); |
| 97 | + Structure structure = mockStructure(); |
| 98 | + Atom[] reprAtoms1 = getAtomArray(structure.getChain("A")); |
| 99 | + Atom[] reprAtoms2 = getAtomArray(structure.getChain("B")); |
101 | 100 |
|
102 | 101 | // Create two SubunitCluster with same entity id |
103 | 102 | SubunitCluster sc1 = new SubunitCluster(new Subunit(reprAtoms1, |
104 | | - "A", null, structure1)); |
| 103 | + "A", null, structure)); |
105 | 104 | SubunitCluster sc2 = new SubunitCluster(new Subunit(reprAtoms2, |
106 | | - "B", null, structure2)); |
| 105 | + "B", null, structure)); |
107 | 106 |
|
108 | 107 | boolean merged = sc1.mergeIdenticalByEntityId(sc2); |
109 | 108 |
|
110 | 109 | // Merged have to be true, and the merged SubunitCluster is sc1 |
111 | 110 | assertTrue(merged); |
112 | 111 | assertEquals(2, sc1.size()); |
113 | 112 | assertEquals(1, sc2.size()); |
114 | | - assertEquals(10, sc1.length()); |
| 113 | + assertEquals(9, sc1.length()); |
115 | 114 |
|
116 | 115 | // Create an Atom Array of poly-glycine with a different entity id |
117 | | - Atom[] reprAtoms3 = mockAtomArray("A", 2, 10, "GLY", -1, null); |
118 | | - Structure structure3 = reprAtoms2[0].getGroup().getChain().getStructure(); |
| 116 | + Atom[] reprAtoms3 = getAtomArray(structure.getChain("C")); |
119 | 117 |
|
120 | 118 | SubunitCluster sc3 = new SubunitCluster(new Subunit(reprAtoms3, |
121 | | - "A", null, structure3)); |
| 119 | + "C", null, structure)); |
122 | 120 |
|
123 | 121 | merged = sc1.mergeIdenticalByEntityId(sc3); |
124 | 122 |
|
125 | 123 | // Merged have to be false, and Clusters result unmodified |
126 | 124 | assertFalse(merged); |
127 | 125 | assertEquals(2, sc1.size()); |
128 | 126 | assertEquals(1, sc2.size()); |
129 | | - assertEquals(10, sc1.length()); |
| 127 | + assertEquals(9, sc1.length()); |
130 | 128 |
|
131 | 129 | } |
132 | 130 |
|
@@ -311,47 +309,71 @@ private Atom[] mockAtomArray(int size1, String type1, int size2, String type2) { |
311 | 309 | } |
312 | 310 |
|
313 | 311 | /** |
314 | | - * Create a mock atom array, with size1 residues of type1, followed by size2 residues of type2. |
315 | | - * |
316 | | - * @param chainId a chain with this chain id will be set as parent of groups |
317 | | - * @param entityId an entity with this id will be set as parent of chain |
318 | | - * @param size1 the number of residues of type1 to add |
319 | | - * @param type1 the 3 letter code of residue |
320 | | - * @param size2 the number of residues of type2 to add, if -1 none are added |
321 | | - * @param type2 the 3 letter code of residue, if null none are added |
322 | | - * @return the mock atom array |
| 312 | + * Create a mock structure with 2 entities 1 (chains A, B) and 2 (chain C). |
| 313 | + * @return a structure |
323 | 314 | */ |
324 | | - private Atom[] mockAtomArray(String chainId, int entityId, int size1, String type1, int size2, String type2) { |
325 | | - Chain chain = new ChainImpl(); |
| 315 | + private Structure mockStructure() { |
326 | 316 | Structure structure = new StructureImpl(); |
327 | | - chain.setId(chainId); |
328 | | - structure.addChain(chain); |
329 | | - EntityInfo entityInfo = new EntityInfo(); |
330 | | - entityInfo.setMolId(entityId); |
331 | | - chain.setEntityInfo(entityInfo); |
| 317 | + EntityInfo entity1 = new EntityInfo(); |
| 318 | + entity1.setMolId(1); |
| 319 | + EntityInfo entity2 = new EntityInfo(); |
| 320 | + entity2.setMolId(2); |
| 321 | + structure.addEntityInfo(entity1); |
| 322 | + structure.addEntityInfo(entity2); |
| 323 | + |
| 324 | + Chain chainA = new ChainImpl(); |
| 325 | + chainA.setId("A"); |
| 326 | + Chain chainB = new ChainImpl(); |
| 327 | + chainB.setId("B"); |
| 328 | + entity1.addChain(chainA); |
| 329 | + entity1.addChain(chainB); |
| 330 | + Chain chainC = new ChainImpl(); |
| 331 | + chainC.setId("C"); |
| 332 | + entity2.addChain(chainC); |
| 333 | + |
| 334 | + structure.addChain(chainA); |
| 335 | + structure.addChain(chainB); |
| 336 | + structure.addChain(chainC); |
| 337 | + |
| 338 | + // entity 1: chain A 10 observed residues, chain B 9 observed residues (first unobserved) |
| 339 | + List<Group> aGroups = getGroupList(10, "ALA", chainA); |
| 340 | + chainA.setAtomGroups(new ArrayList<>(aGroups)); |
| 341 | + chainA.setSeqResGroups(aGroups); |
| 342 | + chainA.setEntityInfo(entity1); |
| 343 | + |
| 344 | + List<Group> bGroups = getGroupList(10, "ALA", chainB); |
| 345 | + chainB.setAtomGroups(new ArrayList<>(bGroups.subList(1,10))); |
| 346 | + chainB.setSeqResGroups(bGroups); |
| 347 | + chainB.setEntityInfo(entity1); |
| 348 | + |
| 349 | + List<Group> cGroups = getGroupList(20, "GLY", chainC); |
| 350 | + chainC.setAtomGroups(new ArrayList<>(cGroups)); |
| 351 | + chainC.setSeqResGroups(cGroups); |
| 352 | + chainC.setEntityInfo(entity2); |
| 353 | + |
| 354 | + return structure; |
| 355 | + } |
332 | 356 |
|
333 | | - List<Atom> atoms = new ArrayList<>(size1 + size2); |
334 | | - for (int i = 0; i < size1; i++) { |
| 357 | + private List<Group> getGroupList(int size, String type, Chain chain) { |
| 358 | + List<Group> list = new ArrayList<>(); |
| 359 | + for (int i=0;i<size;i++) { |
335 | 360 | Group g = new AminoAcidImpl(); |
336 | | - g.setPDBName(type1); |
| 361 | + g.setPDBName(type); |
| 362 | + g.setResidueNumber(new ResidueNumber(chain.getId(), i+1, null)); |
337 | 363 | chain.addGroup(g); |
338 | 364 | Atom a = new AtomImpl(); |
339 | 365 | a.setName(StructureTools.CA_ATOM_NAME); |
340 | 366 | g.addAtom(a); |
341 | | - atoms.add(a); |
| 367 | + list.add(g); |
342 | 368 | } |
| 369 | + return list; |
| 370 | + } |
343 | 371 |
|
344 | | - if (size2 >= 0 && type2 !=null) { |
345 | | - for (int i = 0; i < size2; i++) { |
346 | | - Group g = new AminoAcidImpl(); |
347 | | - g.setPDBName(type2); |
348 | | - chain.addGroup(g); |
349 | | - Atom a = new AtomImpl(); |
350 | | - a.setName(StructureTools.CA_ATOM_NAME); |
351 | | - g.addAtom(a); |
352 | | - atoms.add(a); |
353 | | - } |
| 372 | + private Atom[] getAtomArray(Chain chain) { |
| 373 | + Atom[] atoms = new Atom[chain.getAtomGroups().size()]; |
| 374 | + for (int i = 0; i<chain.getAtomGroups().size(); i++) { |
| 375 | + atoms[i] = chain.getAtomGroups().get(i).getAtom(StructureTools.CA_ATOM_NAME); |
354 | 376 | } |
355 | | - return atoms.toArray(new Atom[0]); |
| 377 | + return atoms; |
356 | 378 | } |
357 | 379 | } |
0 commit comments