Skip to content

Commit f09a417

Browse files
author
Sebastian Bittrich
committed
updates CifFileSupplier to infer types
1 parent e4f654a commit f09a417

File tree

3 files changed

+87
-35
lines changed

3 files changed

+87
-35
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplierImpl.java

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
* @since 5.2.1
2323
*/
2424
class CifFileSupplierImpl implements CifFileSupplier<Structure> {
25-
26-
2725
@Override
2826
public CifFile get(Structure structure) {
2927
// for now BioJava only considered 3 categories for create a Cif representation of a structure
@@ -47,27 +45,27 @@ public CifFile get(Structure structure) {
4745
if (crystalCell != null) {
4846
// set cell category
4947
blockBuilder.enterCategory("cell")
50-
.enterColumn("length_a")
48+
.enterFloatColumn("length_a")
5149
.floatValues(crystalCell.getA())
5250
.leaveColumn()
5351

54-
.enterColumn("length_b")
52+
.enterFloatColumn("length_b")
5553
.floatValues(crystalCell.getB())
5654
.leaveColumn()
5755

58-
.enterColumn("length_c")
56+
.enterFloatColumn("length_c")
5957
.floatValues(crystalCell.getC())
6058
.leaveColumn()
6159

62-
.enterColumn("angle_alpha")
60+
.enterFloatColumn("angle_alpha")
6361
.floatValues(crystalCell.getAlpha())
6462
.leaveColumn()
6563

66-
.enterColumn("angle_beta")
64+
.enterFloatColumn("angle_beta")
6765
.floatValues(crystalCell.getBeta())
6866
.leaveColumn()
6967

70-
.enterColumn("angle_gamma")
68+
.enterFloatColumn("angle_gamma")
7169
.floatValues(crystalCell.getGamma())
7270
.leaveColumn()
7371
.leaveCategory();
@@ -76,7 +74,7 @@ public CifFile get(Structure structure) {
7674
if (spaceGroup != null) {
7775
// set symmetry category
7876
blockBuilder.enterCategory("symmetry")
79-
.enterColumn("space_group_name_H-M")
77+
.enterStrColumn("space_group_name_H-M")
8078
.stringValues(spaceGroup.getShortSymbol())
8179
.leaveColumn()
8280
.leaveCategory();
@@ -200,29 +198,28 @@ static class AtomSiteCollector implements Consumer<WrappedAtom> {
200198
private final Column.StrColumnBuilder authAsymId;
201199
private final Column.StrColumnBuilder authAtomId;
202200
private final Column.IntColumnBuilder pdbxPDBModelNum;
203-
private int atomId = 1;
204201

205202
AtomSiteCollector() {
206-
this.groupPDB = Column.enterStrColumn("group_PDB");
207-
this.id = Column.enterIntColumn("id");
208-
this.typeSymbol = Column.enterStrColumn("type_symbol");
209-
this.labelAtomId = Column.enterStrColumn("label_atom_id");
210-
this.labelAltId = Column.enterStrColumn("label_alt_id");
211-
this.labelCompId = Column.enterStrColumn("label_comp_id");
212-
this.labelAsymId = Column.enterStrColumn("label_asym_id");
213-
this.labelEntityId = Column.enterStrColumn("label_entity_id");
214-
this.labelSeqId = Column.enterIntColumn("label_seq_id");
215-
this.pdbxPDBInsCode = Column.enterStrColumn("pdbx_PDB_ins_code");
216-
this.cartnX = Column.enterFloatColumn("Cartn_x");
217-
this.cartnY = Column.enterFloatColumn("Cartn_y");
218-
this.cartnZ = Column.enterFloatColumn("Cartn_z");
219-
this.occupancy = Column.enterFloatColumn("occupancy");
220-
this.bIsoOrEquiv = Column.enterFloatColumn("B_iso_or_equiv");
221-
this.authSeqId = Column.enterIntColumn("auth_seq_id");
222-
this.authCompId = Column.enterStrColumn("auth_comp_id");
223-
this.authAsymId = Column.enterStrColumn("auth_asym_id");
224-
this.authAtomId = Column.enterStrColumn("auth_atom_id");
225-
this.pdbxPDBModelNum = Column.enterIntColumn("pdbx_PDB_model_num");
203+
this.groupPDB = Column.enterStrColumn("atom_site", "group_PDB");
204+
this.id = Column.enterIntColumn("atom_site", "id");
205+
this.typeSymbol = Column.enterStrColumn("atom_site", "type_symbol");
206+
this.labelAtomId = Column.enterStrColumn("atom_site", "label_atom_id");
207+
this.labelAltId = Column.enterStrColumn("atom_site", "label_alt_id");
208+
this.labelCompId = Column.enterStrColumn("atom_site", "label_comp_id");
209+
this.labelAsymId = Column.enterStrColumn("atom_site", "label_asym_id");
210+
this.labelEntityId = Column.enterStrColumn("atom_site", "label_entity_id");
211+
this.labelSeqId = Column.enterIntColumn("atom_site", "label_seq_id");
212+
this.pdbxPDBInsCode = Column.enterStrColumn("atom_site", "pdbx_PDB_ins_code");
213+
this.cartnX = Column.enterFloatColumn("atom_site", "Cartn_x");
214+
this.cartnY = Column.enterFloatColumn("atom_site", "Cartn_y");
215+
this.cartnZ = Column.enterFloatColumn("atom_site", "Cartn_z");
216+
this.occupancy = Column.enterFloatColumn("atom_site", "occupancy");
217+
this.bIsoOrEquiv = Column.enterFloatColumn("atom_site", "B_iso_or_equiv");
218+
this.authSeqId = Column.enterIntColumn("atom_site", "auth_seq_id");
219+
this.authCompId = Column.enterStrColumn("atom_site", "auth_comp_id");
220+
this.authAsymId = Column.enterStrColumn("atom_site", "auth_asym_id");
221+
this.authAtomId = Column.enterStrColumn("atom_site", "auth_atom_id");
222+
this.pdbxPDBModelNum = Column.enterIntColumn("atom_site", "pdbx_PDB_model_num");
226223
}
227224

228225
@Override
@@ -275,8 +272,6 @@ public void accept(WrappedAtom wrappedAtom) {
275272
authAsymId.stringValues(wrappedAtom.getChainName());
276273
authAtomId.stringValues(atom.getName());
277274
pdbxPDBModelNum.intValues(wrappedAtom.getModel());
278-
279-
atomId++;
280275
}
281276

282277
AtomSiteCollector combine(AtomSiteCollector other) {

biojava-structure/src/test/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImplTest.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.biojava.nbio.structure.io.cif;
22

33
import org.biojava.nbio.structure.*;
4+
import org.biojava.nbio.structure.align.util.AtomCache;
45
import org.biojava.nbio.structure.io.*;
6+
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
7+
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
58
import org.junit.Test;
69
import org.rcsb.cif.CifReader;
710
import org.rcsb.cif.model.CifFile;
@@ -24,6 +27,63 @@
2427
public class CifFileConsumerImplTest {
2528
// TODO use test resources provided by integration-test module
2629

30+
@Test
31+
public void testEntityId() throws IOException, StructureException {
32+
// Set up the atom cache to parse on Internal chain id
33+
AtomCache cache = new AtomCache();
34+
cache.setUseCif(true);
35+
FileParsingParameters params = cache.getFileParsingParams();
36+
37+
DownloadChemCompProvider cc = new DownloadChemCompProvider();
38+
ChemCompGroupFactory.setChemCompProvider(cc);
39+
cc.checkDoFirstInstall();
40+
cache.setFileParsingParams(params);
41+
StructureIO.setAtomCache(cache);
42+
// This is hte information we want to test against
43+
String[] typeInformation = new String[] {"POLYMER", "NONPOLYMER", "NONPOLYMER", "NONPOLYMER", "NONPOLYMER", "WATER"};
44+
String[] descriptionInformation = new String[] {"BROMODOMAIN ADJACENT TO ZINC FINGER DOMAIN PROTEIN 2B","4-Fluorobenzamidoxime", "METHANOL", "METHANOL", "METHANOL", "water"};
45+
46+
// Now some other information fields to test this data is collated correctly
47+
String[] geneSourceSciName = new String[] {"HOMO SAPIENS", null, null, null, null, null};
48+
String[] geneSourceTaxId = new String[] {"9606", null, null, null, null, null};
49+
String[] hostOrganismSciName = new String[] {"ESCHERICHIA COLI", null, null, null, null, null};
50+
String[] hostOrganismTaxId = new String[] {"469008", null, null, null, null, null};
51+
52+
/// TODO GET ALL THE ENTITY INFORMATION REQUIRED FOR 4CUP
53+
// Get this structure
54+
Structure bioJavaStruct = StructureIO.getStructure("4cup");
55+
String[] testTypeInfo = new String[6];
56+
String[] testDescInfo = new String[6];
57+
58+
String[] testGeneSourceSciName = new String[6];
59+
String[] testGeneSourceTaxId = new String[6];
60+
String[] testHostOrganismSciName = new String[6];
61+
String[] testHostOrganismTaxId = new String[6];
62+
63+
// Now loop through the structure
64+
int chainCounter = 0;
65+
for (Chain c: bioJavaStruct.getChains()) {
66+
// Now get the entity information we want to test
67+
EntityInfo thisCmpd = c.getEntityInfo();
68+
testTypeInfo[chainCounter] = thisCmpd.getType().toString();
69+
testDescInfo[chainCounter] = thisCmpd.getDescription();
70+
testGeneSourceSciName[chainCounter] = thisCmpd.getOrganismScientific();
71+
testGeneSourceTaxId[chainCounter] = thisCmpd.getOrganismTaxId();
72+
testHostOrganismSciName[chainCounter] = thisCmpd.getExpressionSystem();
73+
testHostOrganismTaxId[chainCounter] = thisCmpd.getExpressionSystemTaxId();
74+
75+
chainCounter++;
76+
}
77+
// Now check they're both the same
78+
assertArrayEquals(descriptionInformation, testDescInfo);
79+
assertArrayEquals(typeInformation, testTypeInfo);
80+
// Now check these work too
81+
assertArrayEquals(geneSourceSciName, testGeneSourceSciName);
82+
assertArrayEquals(geneSourceTaxId, testGeneSourceTaxId);
83+
assertArrayEquals(hostOrganismSciName, testHostOrganismSciName);
84+
assertArrayEquals(hostOrganismTaxId, testHostOrganismTaxId);
85+
}
86+
2787
/**
2888
* Test parsing dates from MMCIF file version 4.
2989
*/
@@ -64,8 +124,6 @@ public void testDatesV5() throws IOException, ParseException {
64124

65125
Date depositionDate = dateFormat.parse("1992-03-12");
66126
assertEquals(depositionDate, s.getPDBHeader().getDepDate());
67-
68-
69127
}
70128

71129
/**

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
*
3939
*/
4040
public class TestEntityNameAndType {
41-
4241
@Test
4342
public void testEntityId() throws IOException, StructureException {
4443

0 commit comments

Comments
 (0)