Skip to content

Commit 4d6a504

Browse files
committed
Now testing for subunit clustering with entity ids
1 parent 679f840 commit 4d6a504

2 files changed

Lines changed: 89 additions & 43 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,28 @@ public void testPseudoIdentity95() throws IOException, StructureException {
366366
assertEquals(SubunitClustererMethod.SEQUENCE, symmetry.getSubunitClusters().get(0).getClustererMethod());
367367

368368
}
369+
370+
@Test
371+
public void testSymDetectionWithSubunitClusterByEntityId() throws IOException, StructureException {
372+
Structure pdb = StructureIO.getStructure("BIO:1SMT:1");
373+
374+
SubunitClustererParameters cp = new SubunitClustererParameters();
375+
// cp.setOptimizeAlignment(false);
376+
// cp.setSequenceIdentityThreshold(0.75);
377+
// cp.setMinimumSequenceLength(3);
378+
// cp.setAbsoluteMinimumSequenceLength(3);
379+
// cp.setUseSequenceCoverage(false);
380+
// cp.setUseStructureCoverage(false);
381+
// cp.setUseRMSD(false);
382+
cp.setUseEntityIdForSeqIdentityDetermination(true);
383+
cp.setClustererMethod(SubunitClustererMethod.SEQUENCE);
384+
QuatSymmetryParameters symmParams = new QuatSymmetryParameters();
385+
// symmParams.setOnTheFly(true);
386+
QuatSymmetryResults symmetry = QuatSymmetryDetector.calcGlobalSymmetry(
387+
pdb, symmParams, cp);
388+
389+
// C2 symmetry, A2 stoichiometry
390+
assertEquals("C2", symmetry.getSymmetry());
391+
assertEquals("A2", symmetry.getStoichiometry().toString());
392+
}
369393
}

biojava-structure/src/test/java/org/biojava/nbio/structure/cluster/TestSubunitCluster.java

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.biojava.nbio.structure.ChainImpl;
3535
import org.biojava.nbio.structure.EntityInfo;
3636
import org.biojava.nbio.structure.Group;
37+
import org.biojava.nbio.structure.ResidueNumber;
3738
import org.biojava.nbio.structure.Structure;
3839
import org.biojava.nbio.structure.StructureException;
3940
import org.biojava.nbio.structure.StructureIO;
@@ -93,40 +94,37 @@ public void testMergeIdentical() {
9394
public void testMergeIdenticalByEntityId() {
9495

9596
// 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"));
101100

102101
// Create two SubunitCluster with same entity id
103102
SubunitCluster sc1 = new SubunitCluster(new Subunit(reprAtoms1,
104-
"A", null, structure1));
103+
"A", null, structure));
105104
SubunitCluster sc2 = new SubunitCluster(new Subunit(reprAtoms2,
106-
"B", null, structure2));
105+
"B", null, structure));
107106

108107
boolean merged = sc1.mergeIdenticalByEntityId(sc2);
109108

110109
// Merged have to be true, and the merged SubunitCluster is sc1
111110
assertTrue(merged);
112111
assertEquals(2, sc1.size());
113112
assertEquals(1, sc2.size());
114-
assertEquals(10, sc1.length());
113+
assertEquals(9, sc1.length());
115114

116115
// 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"));
119117

120118
SubunitCluster sc3 = new SubunitCluster(new Subunit(reprAtoms3,
121-
"A", null, structure3));
119+
"C", null, structure));
122120

123121
merged = sc1.mergeIdenticalByEntityId(sc3);
124122

125123
// Merged have to be false, and Clusters result unmodified
126124
assertFalse(merged);
127125
assertEquals(2, sc1.size());
128126
assertEquals(1, sc2.size());
129-
assertEquals(10, sc1.length());
127+
assertEquals(9, sc1.length());
130128

131129
}
132130

@@ -311,47 +309,71 @@ private Atom[] mockAtomArray(int size1, String type1, int size2, String type2) {
311309
}
312310

313311
/**
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
323314
*/
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() {
326316
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+
}
332356

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++) {
335360
Group g = new AminoAcidImpl();
336-
g.setPDBName(type1);
361+
g.setPDBName(type);
362+
g.setResidueNumber(new ResidueNumber(chain.getId(), i+1, null));
337363
chain.addGroup(g);
338364
Atom a = new AtomImpl();
339365
a.setName(StructureTools.CA_ATOM_NAME);
340366
g.addAtom(a);
341-
atoms.add(a);
367+
list.add(g);
342368
}
369+
return list;
370+
}
343371

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);
354376
}
355-
return atoms.toArray(new Atom[0]);
377+
return atoms;
356378
}
357379
}

0 commit comments

Comments
 (0)