Skip to content

Commit fe171cc

Browse files
committed
Added some new testing to the mmtf (from the mmtf-java module).
Updated the reader and writer with some refactoring.
1 parent 57b1e82 commit fe171cc

5 files changed

Lines changed: 201 additions & 3 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void setChainInfo(String chainId, String chainName, int groupCount) {
147147
*/
148148
@Override
149149
public void setGroupInfo(String groupName, int groupNumber,
150-
char insertionCode, String chemCompType, int atomCount, char singleLetterCode) {
150+
char insertionCode, String chemCompType, int atomCount, char singleLetterCode, int sequenceIndexId) {
151151
// Get the polymer type
152152
int polymerType = getGroupTypIndicator(chemCompType);
153153
switch (polymerType) {

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void encodeStructure(Structure structure) {
6363
for(int chainInModelIndex=0; chainInModelIndex<modelChains.size(); chainInModelIndex++) {
6464
Chain chain = modelChains.get(chainInModelIndex);
6565
List<Group> groups = chain.getAtomGroups();
66+
List<Group> sequenceGroups = chain.getSeqResGroups();
6667
// TODO we need to include the sequence to group mapping information....
6768
mmtfDecoderInterface.setChainInfo(chain.getChainID(), chain.getInternalChainID(), groups.size());
6869
for(int groupInChainIndex=0; groupInChainIndex<groups.size(); groupInChainIndex++){
@@ -73,7 +74,7 @@ public void encodeStructure(Structure structure) {
7374
ChemComp chemComp = group.getChemComp();
7475
// TODO We need to specify what type of group is being added
7576
mmtfDecoderInterface.setGroupInfo(group.getPDBName(), group.getResidueNumber().getSeqNum(), group.getResidueNumber().getInsCode().charValue(),
76-
chemComp.getPdbx_type(), atomsInGroup.size(), chemComp.getOne_letter_code().charAt(0));
77+
chemComp.getPdbx_type(), atomsInGroup.size(), chemComp.getOne_letter_code().charAt(0), sequenceGroups.indexOf(group));
7778
for (Atom atom : atomsInGroup){
7879
mmtfDecoderInterface.setAtomInfo(atom.getName(), atom.getPDBserial(), atom.getAltLoc().charValue(), (float) atom.getX(),
7980
(float) atom.getY(), (float) atom.getZ(), atom.getOccupancy(),

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class MmtfUtils {
4040
/**
4141
* Set up the configuration parameters for BioJava.
4242
*/
43-
public AtomCache setUpBioJava() {
43+
public static AtomCache setUpBioJava() {
4444
// Set up the atom cache etc
4545
AtomCache cache = new AtomCache();
4646
cache.setUseMmCif(true);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.biojava.nbio.structure.mmtf;
2+
3+
import org.junit.Test;
4+
import static org.junit.Assert.*;
5+
6+
import java.io.IOException;
7+
import java.util.List;
8+
9+
import org.biojava.nbio.structure.Atom;
10+
import org.biojava.nbio.structure.Bond;
11+
import org.biojava.nbio.structure.Chain;
12+
import org.biojava.nbio.structure.Group;
13+
import org.biojava.nbio.structure.Structure;
14+
import org.biojava.nbio.structure.StructureException;
15+
import org.biojava.nbio.structure.StructureIO;
16+
import org.biojava.nbio.structure.align.util.AtomCache;
17+
import org.biojava.nbio.structure.io.FileParsingParameters;
18+
import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior;
19+
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
20+
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
21+
22+
public class TestBondFinding {
23+
24+
/**
25+
* Test that the bonds we are finding is consistenty.
26+
* @throws IOException
27+
* @throws StructureException
28+
*/
29+
@Test
30+
public void testInterGroupBonds() throws IOException, StructureException {
31+
// Normal
32+
assertEquals(getInterBonds("1QMZ"), 2236);
33+
// Disulphide
34+
assertEquals(getInterBonds("2QWO"), 956);
35+
// Covalent ligand
36+
assertEquals(getInterBonds("4QDV"), 2294);
37+
// DNA
38+
assertEquals(getInterBonds("4XSN"), 22);
39+
40+
}
41+
42+
public int getInterBonds(String pdbId) throws IOException, StructureException{
43+
AtomCache cache = new AtomCache();
44+
cache.setUseMmCif(true);
45+
cache.setFetchBehavior(FetchBehavior.FETCH_FILES);
46+
FileParsingParameters params = cache.getFileParsingParams();
47+
params.setCreateAtomBonds(true);
48+
params.setAlignSeqRes(true);
49+
params.setParseBioAssembly(true);
50+
DownloadChemCompProvider dcc = new DownloadChemCompProvider();
51+
ChemCompGroupFactory.setChemCompProvider(dcc);
52+
dcc.checkDoFirstInstall();
53+
cache.setFileParsingParams(params);
54+
StructureIO.setAtomCache(cache);
55+
int counter =0;
56+
// Now get the structure
57+
Structure newStruc = StructureIO.getStructure(pdbId);
58+
// Now loop through the atoms
59+
for(Chain c: newStruc.getChains()){
60+
for(Group g: c.getAtomGroups()){
61+
List<Atom> theseAtoms = g.getAtoms();
62+
for(Atom a: theseAtoms){
63+
List<Bond> theseBonds = a.getBonds();
64+
if(theseBonds != null){
65+
for(Bond b: a.getBonds()){
66+
Atom other = b.getOther(a);
67+
int indexOther = theseAtoms.indexOf(other);
68+
// Check if the index is within the group
69+
if(indexOther<0 || indexOther >= theseAtoms.size()){
70+
counter++;
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
return counter;
78+
}
79+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package org.biojava.nbio.structure.mmtf;
2+
3+
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.*;
7+
8+
import java.io.IOException;
9+
import java.util.ArrayList;
10+
import java.util.HashSet;
11+
import java.util.List;
12+
import java.util.Set;
13+
14+
import org.biojava.nbio.structure.Atom;
15+
import org.biojava.nbio.structure.Chain;
16+
import org.biojava.nbio.structure.Group;
17+
import org.biojava.nbio.structure.Structure;
18+
import org.biojava.nbio.structure.StructureException;
19+
import org.biojava.nbio.structure.StructureIO;
20+
import org.biojava.nbio.structure.io.mmtf.MmtfUtils;
21+
22+
public class TestMmtfUtils {
23+
24+
/**
25+
* Integration test to see that the microheterogenity is being dealt with correctly.
26+
* @throws IOException
27+
* @throws StructureException
28+
*/
29+
@Test
30+
public void microHeterogenity() throws IOException, StructureException {
31+
MmtfUtils.setUpBioJava();
32+
Structure inputStructure = StructureIO.getStructure("4ck4");
33+
// Count the number of groups
34+
Group before = inputStructure.getChains().get(0).getAtomGroup(17);
35+
assertTrue(inputStructure.getChains().get(0).getAtomGroup(17).hasAltLoc());
36+
List<Atom> totalAtoms = new ArrayList<>(MmtfUtils.getAllAtoms(inputStructure));
37+
int totGroups = 0;
38+
int totAtomsCounter = 0;
39+
Set<Atom> totAtoms = new HashSet<>();
40+
for (Chain c : inputStructure.getChains()) {
41+
totGroups += c.getAtomGroups().size();
42+
for (Group g: c.getAtomGroups() ){
43+
totAtomsCounter+=g.getAtoms().size();
44+
totAtoms.addAll(g.getAtoms());
45+
for (Group alt : g.getAltLocs()) {
46+
totAtomsCounter+=alt.getAtoms().size();
47+
totAtoms.addAll(alt.getAtoms());
48+
}
49+
}
50+
}
51+
// Now "fix" the microheterogenity
52+
MmtfUtils.fixMicroheterogenity(inputStructure);
53+
assertEquals(before, inputStructure.getChains().get(0).getAtomGroup(17));
54+
assertFalse(inputStructure.getChains().get(0).getAtomGroup(17).hasAltLoc());
55+
assertFalse(inputStructure.getChains().get(0).getAtomGroup(18).hasAltLoc());
56+
int totGroupsAfter = 0;
57+
int totAtomsCounterAfter = 0;
58+
Set<Atom> totAtomsAfter = new HashSet<>();
59+
for (Chain c : inputStructure.getChains()) {
60+
totGroupsAfter += c.getAtomGroups().size();
61+
for (Group g: c.getAtomGroups() ){
62+
totAtomsCounterAfter+=g.getAtoms().size();
63+
totAtomsAfter.addAll(g.getAtoms());
64+
for (Group alt : g.getAltLocs()) {
65+
totAtomsAfter.addAll(alt.getAtoms());
66+
totAtomsCounterAfter+=alt.getAtoms().size();
67+
}
68+
}
69+
}
70+
// Find the atoms after the fix.
71+
List<Atom> totalAtomsAfter = new ArrayList<>(MmtfUtils.getAllAtoms(inputStructure));
72+
// Get all of the duplicate atoms
73+
Set<Atom> duplicates = findDuplicates(totalAtomsAfter);
74+
for (Atom a : duplicates) {
75+
System.out.println(a);
76+
}
77+
// There should be no duplicates
78+
assertEquals(duplicates.size(), 0);
79+
assertEquals(totalAtoms.size(), totalAtomsAfter.size());
80+
// Check there are two more groups afterwards
81+
assertEquals(totGroupsAfter-2, totGroups);
82+
// Check there are no more atoms afterwards
83+
assertEquals(totAtomsAfter.size(), totAtoms.size());
84+
// Check the counter are the same too
85+
assertEquals(totAtomsCounterAfter, totAtomsCounter);
86+
87+
}
88+
89+
90+
//TODO ADD TESTS FOR THESE FUNCTIONS
91+
// getAllAtoms
92+
//
93+
// getAtomsForGroup
94+
//
95+
// calculateDsspSecondaryStructure
96+
//
97+
// setHeaderInfo
98+
//
99+
// generateSerializableBioAssembly
100+
//
101+
// getChainIdToIndexMap
102+
103+
private Set<Atom> findDuplicates(List<Atom> listContainingDuplicates)
104+
{
105+
final Set<Atom> setToReturn = new HashSet<>();
106+
final Set<Atom> set1 = new HashSet<>();
107+
108+
for (Atom yourInt : listContainingDuplicates)
109+
{
110+
if (!set1.add(yourInt))
111+
{
112+
setToReturn.add(yourInt);
113+
}
114+
}
115+
return setToReturn;
116+
}
117+
}
118+

0 commit comments

Comments
 (0)