Skip to content

Commit 6d8e3e7

Browse files
author
Sebastian Bittrich
committed
moves some tests to integration
1 parent 6ddc053 commit 6d8e3e7

18 files changed

Lines changed: 220 additions & 103601 deletions

File tree

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
package org.biojava.nbio.structure.test.io.cif;
2+
3+
import org.biojava.nbio.structure.*;
4+
import org.biojava.nbio.structure.io.*;
5+
import org.junit.Test;
6+
import org.rcsb.cif.CifReader;
7+
import org.rcsb.cif.model.CifFile;
8+
import org.rcsb.cif.model.Column;
9+
import org.rcsb.cif.model.ValueKind;
10+
11+
import java.io.ByteArrayInputStream;
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.text.ParseException;
15+
import java.text.SimpleDateFormat;
16+
import java.util.Date;
17+
import java.util.List;
18+
import java.util.Locale;
19+
import java.util.Objects;
20+
import java.util.zip.GZIPInputStream;
21+
22+
import static org.junit.Assert.*;
23+
24+
public class CifFileConsumerImplTest {
25+
private static boolean headerOnly;
26+
private static boolean binary;
27+
28+
@Test
29+
public void testLoad() throws IOException {
30+
headerOnly = false;
31+
doTestLoad();
32+
}
33+
34+
@Test
35+
public void testLoadHeaderOnly() throws IOException {
36+
headerOnly = true;
37+
doTestLoad();
38+
}
39+
40+
@Test
41+
public void testLoadBinary() throws IOException {
42+
headerOnly = false;
43+
binary = true;
44+
doTestLoad();
45+
}
46+
47+
@Test
48+
public void testLoadHeaderOnlyBinary() throws IOException {
49+
headerOnly = true;
50+
binary = true;
51+
doTestLoad();
52+
}
53+
54+
private void doTestLoad() throws IOException {
55+
// test a simple protein
56+
comparePDB2cif("5pti","A");
57+
58+
// test a protein with modified residues
59+
comparePDB2cif("1a4w","L");
60+
comparePDB2cif("1a4w","H");
61+
comparePDB2cif("1a4w","I");
62+
63+
//non-standard encoded amino acid
64+
comparePDB2cif("1fdo","A");
65+
66+
// test a DNA binding protein
67+
comparePDB2cif("1j59","A");
68+
comparePDB2cif("1j59","E");
69+
70+
// test a NMR protein
71+
comparePDB2cif("2kc9","A");
72+
}
73+
74+
private void comparePDB2cif(String id, String chainId) throws IOException {
75+
String fileName = binary ? "/" + id + ".bcif" : "/" + id + ".cif";
76+
System.out.println(fileName);
77+
InputStream inStream = getClass().getResourceAsStream(fileName);
78+
assertNotNull("Could not find file " + fileName + ". Config problem?" , inStream);
79+
80+
LocalPDBDirectory reader = binary ? new BcifFileReader() : new CifFileReader();
81+
82+
FileParsingParameters params = new FileParsingParameters();
83+
params.setHeaderOnly(headerOnly);
84+
reader.setFileParsingParameters(params);
85+
86+
Structure cifStructure = reader.getStructure(inStream);
87+
assertNotNull(cifStructure);
88+
89+
// load the PDB file via the PDB parser
90+
Structure pdbStructure;
91+
InputStream pinStream = this.getClass().getResourceAsStream("/" + id + ".pdb");
92+
assertNotNull(inStream);
93+
94+
PDBFileParser pdbParser = new PDBFileParser();
95+
pdbParser.setFileParsingParameters(params);
96+
97+
pdbStructure = pdbParser.parsePDBFile(pinStream);
98+
99+
assertNotNull(pdbStructure);
100+
101+
// check NMR data
102+
assertEquals(id + ": the isNMR flag is not the same!",
103+
pdbStructure.isNmr(),
104+
cifStructure.isNmr());
105+
106+
if ( pdbStructure.isNmr()){
107+
assertEquals(id + ": the nr of NMR models is not the same!",
108+
pdbStructure.nrModels(),
109+
pdbStructure.nrModels());
110+
checkNMR(pdbStructure);
111+
checkNMR(cifStructure);
112+
}
113+
114+
Chain a_pdb = pdbStructure.getPolyChainByPDB(chainId);
115+
Chain a_cif = cifStructure.getPolyChainByPDB(chainId);
116+
117+
String pdb_SEQseq = a_pdb.getSeqResSequence();
118+
String cif_SEQseq = a_cif.getSeqResSequence();
119+
120+
assertEquals(id + ": the SEQRES sequences don't match!",
121+
pdb_SEQseq,
122+
cif_SEQseq);
123+
124+
assertEquals(id + ": The nr of ATOM groups does not match!",
125+
a_pdb.getAtomGroups(GroupType.AMINOACID).size(),
126+
a_cif.getAtomGroups(GroupType.AMINOACID).size());
127+
128+
// actually this check not necessarily works, since there can be waters in PDB that we don;t deal with yet in cif...
129+
for (int i = 0 ; i < a_pdb.getAtomGroups(GroupType.AMINOACID).size(); i++){
130+
Group gp = a_pdb.getAtomGroups(GroupType.AMINOACID).get(i);
131+
List<Group> cifGroups = a_cif.getAtomGroups(GroupType.AMINOACID);
132+
Group gc = cifGroups.get(i);
133+
checkGroups(gp, gc);
134+
}
135+
136+
String pdb_seq = a_pdb.getAtomSequence();
137+
String cif_seq = a_cif.getAtomSequence();
138+
139+
assertEquals("the sequences obtained from PDB and mmCif don't match!", pdb_seq, cif_seq);
140+
141+
List<DBRef> pdb_dbrefs= pdbStructure.getDBRefs();
142+
List<DBRef> cif_dbrefs= cifStructure.getDBRefs();
143+
144+
assertEquals("nr of DBrefs found does not match!", pdb_dbrefs.size(), cif_dbrefs.size());
145+
146+
DBRef p = pdb_dbrefs.get(0);
147+
DBRef c = cif_dbrefs.get(0);
148+
149+
String pdb_dbref = p.toPDB();
150+
String cif_dbref = c.toPDB();
151+
assertEquals("DBRef is not equal", pdb_dbref, cif_dbref);
152+
153+
PDBHeader h1 = pdbStructure.getPDBHeader();
154+
PDBHeader h2 = cifStructure.getPDBHeader();
155+
156+
if (!h1.toPDB().toUpperCase().equals(h2.toPDB().toUpperCase())) {
157+
System.err.println(h1.toPDB());
158+
System.err.println(h2.toPDB());
159+
assertEquals(h1.toPDB(), h2.toPDB());
160+
}
161+
assertEquals("the PDBHeader.toPDB representation is not equivalent",
162+
h1.toPDB().toUpperCase(),
163+
h2.toPDB().toUpperCase());
164+
}
165+
166+
private void checkGroups(Group g1, Group g2){
167+
String pdbId1 = g1.getChain().getStructure().getPDBCode();
168+
String pdbId2 = g1.getChain().getStructure().getPDBCode();
169+
assertEquals(pdbId1, pdbId2);
170+
171+
assertEquals(g1.getType(), g2.getType());
172+
assertEquals(g1.getResidueNumber().getSeqNum(), g2.getResidueNumber().getSeqNum());
173+
assertEquals(g1.getResidueNumber().getInsCode(), g2.getResidueNumber().getInsCode());
174+
assertEquals(g1.getPDBName(), g2.getPDBName());
175+
assertEquals(g1.has3D(), g2.has3D());
176+
177+
assertEquals(g1.hasAltLoc(), g2.hasAltLoc());
178+
assertEquals(pdbId1 + ":" + g1 + " - " + pdbId2 + ":"+ g2, g1.getAltLocs().size(), g2.getAltLocs().size());
179+
assertEquals(pdbId1 + ":" + g1 + " - " + pdbId2 + ":"+ g2, g1.getAtoms().size(), g2.getAtoms().size());
180+
181+
if (g1.has3D()){
182+
Atom a1 = g1.getAtom(0);
183+
Atom a2 = g2.getAtom(0);
184+
if ( a1 == null)
185+
fail("could not get atom for group " + g1);
186+
if (a2 == null)
187+
fail("could not get atom for group " + g2);
188+
assertEquals(a1.getX(),a2.getX(), 0.0001);
189+
assertEquals(a1.getOccupancy(), a2.getOccupancy(), 0.0001);
190+
assertEquals(a1.getTempFactor(), a2.getTempFactor(), 0.0001);
191+
assertEquals(a1.getName(), a2.getName());
192+
}
193+
}
194+
195+
private void checkNMR(Structure s){
196+
assertTrue(s.isNmr());
197+
int models = s.nrModels();
198+
assertTrue(models > 0);
199+
List<Chain> model0 = s.getModel(0);
200+
201+
// compare with all others
202+
for (int i = 1 ; i < models; i++){
203+
List<Chain> modelX = s.getModel(i);
204+
assertEquals(model0.size(),modelX.size());
205+
206+
// compare lengths:
207+
for (int j=0 ; j< model0.size(); j++){
208+
Chain c1 = model0.get(j);
209+
Chain cx = modelX.get(j);
210+
assertEquals(c1.getAtomLength(), cx.getAtomLength());
211+
assertEquals(c1.getAtomSequence(), cx.getAtomSequence());
212+
assertEquals(c1.getAtomGroups(GroupType.AMINOACID).size(), cx.getAtomGroups(GroupType.AMINOACID).size());
213+
assertEquals(c1.getAtomGroups(GroupType.NUCLEOTIDE).size(), cx.getAtomGroups(GroupType.NUCLEOTIDE).size());
214+
assertEquals(c1.getAtomGroups(GroupType.HETATM).size(), cx.getAtomGroups(GroupType.HETATM).size());
215+
}
216+
}
217+
}
218+
}

biojava-structure/src/test/java/org/biojava/nbio/structure/io/cif/CifFileSupplierImplTest.java renamed to biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package org.biojava.nbio.structure.io.cif;
1+
package org.biojava.nbio.structure.test.io.cif;
22

33
import org.biojava.nbio.structure.*;
44
import org.biojava.nbio.structure.align.util.AtomCache;
55
import org.biojava.nbio.structure.io.FileParsingParameters;
6+
import org.biojava.nbio.structure.io.cif.CifFileConverter;
67
import org.junit.Test;
78
import org.rcsb.cif.CifReader;
89
import org.rcsb.cif.CifWriter;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)