Skip to content

Commit d415e3c

Browse files
committed
New test
1 parent 6ac8877 commit d415e3c

File tree

1 file changed

+93
-1
lines changed

1 file changed

+93
-1
lines changed

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

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@
3030
import org.biojava.nbio.structure.AminoAcidImpl;
3131
import org.biojava.nbio.structure.Atom;
3232
import org.biojava.nbio.structure.AtomImpl;
33+
import org.biojava.nbio.structure.Chain;
34+
import org.biojava.nbio.structure.ChainImpl;
35+
import org.biojava.nbio.structure.EntityInfo;
3336
import org.biojava.nbio.structure.Group;
3437
import org.biojava.nbio.structure.Structure;
3538
import org.biojava.nbio.structure.StructureException;
3639
import org.biojava.nbio.structure.StructureIO;
40+
import org.biojava.nbio.structure.StructureImpl;
3741
import org.biojava.nbio.structure.StructureTools;
3842
import org.junit.Test;
3943

@@ -85,6 +89,47 @@ public void testMergeIdentical() {
8589

8690
}
8791

92+
@Test
93+
public void testMergeIdenticalByEntityId() {
94+
95+
// 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();
101+
102+
// Create two SubunitCluster with same entity id
103+
SubunitCluster sc1 = new SubunitCluster(new Subunit(reprAtoms1,
104+
"A", null, structure1));
105+
SubunitCluster sc2 = new SubunitCluster(new Subunit(reprAtoms2,
106+
"B", null, structure2));
107+
108+
boolean merged = sc1.mergeIdenticalByEntityId(sc2);
109+
110+
// Merged have to be true, and the merged SubunitCluster is sc1
111+
assertTrue(merged);
112+
assertEquals(2, sc1.size());
113+
assertEquals(1, sc2.size());
114+
assertEquals(10, sc1.length());
115+
116+
// 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();
119+
120+
SubunitCluster sc3 = new SubunitCluster(new Subunit(reprAtoms3,
121+
"A", null, structure3));
122+
123+
merged = sc1.mergeIdenticalByEntityId(sc3);
124+
125+
// Merged have to be false, and Clusters result unmodified
126+
assertFalse(merged);
127+
assertEquals(2, sc1.size());
128+
assertEquals(1, sc2.size());
129+
assertEquals(10, sc1.length());
130+
131+
}
132+
88133
/**
89134
* Test {@link SubunitCluster#mergeSequence(SubunitCluster, SubunitClustererParameters)}
90135
*
@@ -232,18 +277,64 @@ public void testDivideInternally() throws StructureException, IOException {
232277
}
233278

234279
/**
235-
* Create a mock atom array, with size1 residues of type1, followed by size2 residues of type2
280+
* Create a mock atom array, with size1 residues of type1, followed by size2 residues of type2.
281+
*
236282
* @param size1 the number of residues of type1 to add
237283
* @param type1 the 3 letter code of residue
238284
* @param size2 the number of residues of type2 to add, if -1 none are added
239285
* @param type2 the 3 letter code of residue, if null none are added
240286
* @return the mock atom array
241287
*/
242288
private Atom[] mockAtomArray(int size1, String type1, int size2, String type2) {
289+
290+
List<Atom> atoms = new ArrayList<>(size1 + size2);
291+
for (int i = 0; i < size1; i++) {
292+
Group g = new AminoAcidImpl();
293+
g.setPDBName(type1);
294+
Atom a = new AtomImpl();
295+
a.setName(StructureTools.CA_ATOM_NAME);
296+
g.addAtom(a);
297+
atoms.add(a);
298+
}
299+
300+
if (size2 >= 0 && type2 !=null) {
301+
for (int i = 0; i < size2; i++) {
302+
Group g = new AminoAcidImpl();
303+
g.setPDBName(type2);
304+
Atom a = new AtomImpl();
305+
a.setName(StructureTools.CA_ATOM_NAME);
306+
g.addAtom(a);
307+
atoms.add(a);
308+
}
309+
}
310+
return atoms.toArray(new Atom[0]);
311+
}
312+
313+
/**
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
323+
*/
324+
private Atom[] mockAtomArray(String chainId, int entityId, int size1, String type1, int size2, String type2) {
325+
Chain chain = new ChainImpl();
326+
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);
332+
243333
List<Atom> atoms = new ArrayList<>(size1 + size2);
244334
for (int i = 0; i < size1; i++) {
245335
Group g = new AminoAcidImpl();
246336
g.setPDBName(type1);
337+
chain.addGroup(g);
247338
Atom a = new AtomImpl();
248339
a.setName(StructureTools.CA_ATOM_NAME);
249340
g.addAtom(a);
@@ -254,6 +345,7 @@ private Atom[] mockAtomArray(int size1, String type1, int size2, String type2) {
254345
for (int i = 0; i < size2; i++) {
255346
Group g = new AminoAcidImpl();
256347
g.setPDBName(type2);
348+
chain.addGroup(g);
257349
Atom a = new AtomImpl();
258350
a.setName(StructureTools.CA_ATOM_NAME);
259351
g.addAtom(a);

0 commit comments

Comments
 (0)