From 7023ffb73e14664f57a8c0193ccf7926850535fa Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Fri, 1 Apr 2016 17:39:30 -0700 Subject: [PATCH 001/108] Updated poms to dev mode. Interface is now just primitives. Decode structure updated to follow suit --- .../mmtf/api/StructureDecoderInterface.java | 6 ++---- .../org/rcsb/mmtf/decoder/DecodeStructure.java | 18 ++++++++++++++---- mmtf-encoder/pom.xml | 2 +- mmtf-update/pom.xml | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java index 58f7ead..83d7a78 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java @@ -2,8 +2,6 @@ import java.util.List; -import org.rcsb.mmtf.dataholders.BioAssemblyData; - /** * Interface to inflate a given MMTF data source. * @@ -73,11 +71,11 @@ void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, /** - * Sets the Bioassembly information for the structure. + * Sets a single Bioassembly transformation to a structure. bioAssemblyId indicates the index of the bioassembly. * * @param inputBioassemblies */ - void setBioAssemblyList(List inputBioAssemblies); + void setBioAssemblyTrans(int bioAssemblyId, String[] inputChainIds, double[] inputTransform); /** * Sets the space group and unit cell information. diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index e853855..3cd3e64 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -6,6 +6,8 @@ import org.rcsb.mmtf.api.DataApiInterface; import org.rcsb.mmtf.api.StructureDecoderInterface; +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.BioAssemblyTrans; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.PDBGroup; @@ -17,14 +19,14 @@ */ public class DecodeStructure { - + /** The struct inflator. */ private StructureDecoderInterface structInflator; /** The api to the data */ private DataApiInterface dataApi; - + /* * Initialise the counters */ @@ -77,7 +79,7 @@ public final void getStructFromByteArray(final StructureDecoderInterface inputSt // Now do any required cleanup structInflator.cleanUpStructure(); } - + /** * Add the main atomic information to the data model */ @@ -252,7 +254,15 @@ private void addXtalographicInfo() { * Parses the bioassembly data and inputs it to the structure inflator */ private void generateBioAssembly() { - structInflator.setBioAssemblyList(dataApi.getBioAssemblyList()); + int bioAssemblyId = 0; + for (BioAssemblyData bioassembly : dataApi.getBioAssemblyList()) { + bioAssemblyId++; + List trans = bioassembly.getTransforms(); + for (BioAssemblyTrans bioAssemblyTrans : trans ) { + String[] chainIdList = bioAssemblyTrans.getChainIdList().toArray(new String[0]); + structInflator.setBioAssemblyTrans(bioAssemblyId, chainIdList, bioAssemblyTrans.getTransformation()); + } + } } diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index f1c6c7b..ce267ca 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -29,7 +29,7 @@ org.biojava biojava-structure - 5.0.0-alpha3 + 5.0.0-SNAPSHOT org.msgpack diff --git a/mmtf-update/pom.xml b/mmtf-update/pom.xml index dad80eb..46d4ce0 100644 --- a/mmtf-update/pom.xml +++ b/mmtf-update/pom.xml @@ -39,7 +39,7 @@ org.biojava biojava-structure - 5.0.0-alpha3 + 5.0.0-SNAPSHOT org.apache.spark From a01d4dd4edc2c6af106b71ee3d4024259f02f162 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Fri, 1 Apr 2016 18:37:17 -0700 Subject: [PATCH 002/108] Updates to remove Entity and PDBGroup from the DataApi interface --- .../org/rcsb/mmtf/api/DataApiInterface.java | 123 +++++++++--- .../rcsb/mmtf/decoder/DecodeStructure.java | 42 ++-- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 111 ++++++++++- .../org/rcsb/mmtf/examples/HelloWorld.java | 4 +- .../rcsb/mmtf/testutils/CheckOnRawApi.java | 185 +++++++++--------- 5 files changed, 311 insertions(+), 154 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java index 6e3356a..bb3f79d 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java @@ -1,12 +1,8 @@ package org.rcsb.mmtf.api; import java.util.List; -import java.util.Map; import org.rcsb.mmtf.dataholders.BioAssemblyData; -import org.rcsb.mmtf.dataholders.Entity; -import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.dataholders.PDBGroup; /** * An interface describing the data API. @@ -90,13 +86,68 @@ public interface DataApiInterface { */ int[] getResidueNums(); + /** - * Returns the group map, mapping the numbers from indices specified in {@link #getGroupIndices()} - * to {@link PDBGroup} objects, which specify the atom names, - * elements, bonds and charges for each group. - * @return a map of group indices to {@link PDBGroup} objects + * Returns the group name for the group specified in {@link #getGroupIndices()}. + * to link groups to the 3 letter group name, e.g. HIS. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return a 3 letter string specifiying the group name. + */ + String getGroupName(int groupInd); + + /** + * Returns the number of atoms in the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return The number of atoms in the group + */ + int getNumAtomsInGroup(int groupInd); + + + /** Returns the atom names (e.g. CB) for the group specified in {@link #getGroupIndices()}. + * Atom names are unique for each unique atom in a group. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A list of strings for the atom names. + * */ + String[] getGroupAtomNames(int groupInd); + + /** Returns the element names (e.g. C is carbon) for the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A list of strings for the element information. + * */ + String[] getGroupElementNames(int groupInd); + + /** Returns the bond orders for the group specified in {@link #getGroupIndices()}. + * A list of integers indicating the bond orders + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A list of integers (1,2 or 3) indicating the bond orders. + * */ + int[] getGroupBondOrders(int groupInd); + + /** Returns the zero-indexed bond indices (in pairs) for the group specified in {@link #getGroupIndices()}. + * (e.g. 0,1 means there is bond between atom 0 and 1). + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A list of integers specifying the bond indices (within the group). Indices are zero indexed. + * */ + int[] getGroupBondIndices(int groupInd); + + /** Returns the atom charges for the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A list of integers indicating the atomic charge for each atom in the group. + */ + int[] getGroupAtomCharges(int groupInd); + + /** Returns the single letter amino acid code for the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A string indicating the single letter amino acid + */ + String getGroupSingleLetterCode(int groupInd); + + /** Returns the chemical componenet type for the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @return A string (taken from the chemical component dictionary) indicating + * the type of the group. Corresponds to -> http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html */ - Map getGroupMap(); + String getGroupChemCompType(int groupInd); /** * Returns an array containing indices of all groups in the structure as used in {@link #getGroupMap()}. @@ -186,11 +237,37 @@ public interface DataApiInterface { String getMmtfProducer(); /** - * Returns an array with all {@link Entity} objects for the structure. - * The sequences can be obtained from the Entities. - * @return + * @return The number of entities in the Structure + */ + int getNumEntities(); + + /** + * Returns the entity description for the entity specified by the index. + * @param The index of this entity. + * @return The description based on the PDBx model. + */ + String getEntityDescription(int entityInd); + + /** + * Returns the the type (polymer, non-polymer, water) for the entity specified by the index. + * @param The index of this entity. + * @return The type (polymer, non-polymer, water) + */ + String getEntityType(int entityInd); + + /** + * Returns the chain indices for the entity specified by the index. + * @param The index of this entity. + * @return The chain index list - referencing the entity to the chains. + */ + int[] getEntityChainIndexList(int entityInd); + + /** + * Returns the sequence for the entity specified by the index. + * @param The index of this entity. + * @return The one letter sequence for this entity. Empty string if no sequence is applicable. */ - Entity[] getEntityList(); + String getEntitySequence(int entityInd); /** * Returns the four character PDB id of the structure. @@ -203,54 +280,54 @@ public interface DataApiInterface { * @return the number of models */ int getNumModels(); - + /** * Returns the number of chains (for all models) in the structure. * @return the number of chains for all models * @see #getChainsPerModel() */ int getNumChains(); - + /** * Returns the number of groups (residues) in the structure that have * experimentally determined 3D coordinates. * @return the number of residues in the structure, counting all models and chains */ int getNumResidues(); - + /** * Returns the number of atoms in the structure. * @return the number of atoms in the structure, counting all models and chains */ int getNumAtoms(); - - + + /** * Returns the Rfree (if available) of the dataset. * @return the Rfree value or {@value MmtfBean#UNAVAILABLE_R_VALUE} if unavailable */ float getRfree(); - + /** * Returns the Resolution (if available) of the dataset. * @return the resolution value in Angstroms or {@value MmtfBean#UNAVAILABLE_R_VALUE} if unavailable */ float getResolution(); - + /** * Returns the Rwork (if available) of the dataset. * @return the Rwork value or {@value MmtfBean#UNAVAILABLE_R_VALUE} if unavailable */ float getRwork(); - - + + /** * Returns the title of the structure. * @return */ String getTitle(); - + /** * Returns the experimental methods as a list of strings. Normally only one * experimental method is available, but structures solved with hybrid methods will diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 3cd3e64..f791084 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -8,8 +8,6 @@ import org.rcsb.mmtf.api.StructureDecoderInterface; import org.rcsb.mmtf.dataholders.BioAssemblyData; import org.rcsb.mmtf.dataholders.BioAssemblyTrans; -import org.rcsb.mmtf.dataholders.Entity; -import org.rcsb.mmtf.dataholders.PDBGroup; /** * Decode an MMTF structure using a structure inflator. The class also allows access to the unconsumed but parsed and inflated underlying data. @@ -101,14 +99,14 @@ private void addAtomicInformation() { * Add the entity information to a structure. */ private void addEntityInfo() { - for (Entity entity : dataApi.getEntityList()) { - String[] chainIdList = new String[entity.getChainIndexList().length]; + for (int i=0; i atomInfo = currentGroup.getAtomInfo(); - int atomCount = atomInfo.size() / 2; + int atomCount = dataApi.getNumAtomsInGroup(groupInd); int currentGroupNumber = dataApi.getResidueNums()[thisGroupNum]; char insertionCode = dataApi.getInsCodes()[thisGroupNum]; - structInflator.setGroupInfo(currentGroup.getGroupName(), currentGroupNumber, insertionCode, - currentGroup.getChemCompType(), atomCount); + structInflator.setGroupInfo(dataApi.getGroupName(groupInd), currentGroupNumber, insertionCode, + dataApi.getGroupChemCompType(groupInd), atomCount); // A counter for the atom information atomCounter = 0; // Now read the next atoms for (int i = lastAtomCount; i < lastAtomCount + atomCount; i++) { - addAtomData(currentGroup, atomInfo, i); + addAtomData(dataApi.getGroupAtomNames(groupInd), dataApi.getGroupElementNames(groupInd), dataApi.getGroupAtomCharges(groupInd), i); } - addGroupBonds(currentGroup.getBondIndices(), currentGroup.getBondOrders()); + addGroupBonds(dataApi.getGroupBondIndices(groupInd), dataApi.getGroupBondOrders(groupInd)); return atomCount; } @@ -196,11 +192,11 @@ private int addGroup(final int thisGroupNum) { * @param atomInfo The list of strings containing atom level information. * @param currentAtomIndex The index of the current Atom */ - private void addAtomData(PDBGroup currentPdbGroup, List atomInfo, int currentAtomIndex) { + private void addAtomData(String[] atomNames, String[] elementNames, int[] atomCharges, int currentAtomIndex) { // Now get all the relevant atom level information here - String atomName = atomInfo.get(atomCounter * 2 + 1); - String element = atomInfo.get(atomCounter * 2); - int charge = currentPdbGroup.getAtomCharges().get(atomCounter); + String atomName = atomNames[atomCounter]; + String element = elementNames[atomCounter]; + int charge = atomCharges[atomCounter]; int serialNumber = dataApi.getAtomIds()[currentAtomIndex]; char alternativeLocationId = dataApi.getAltLocIds()[currentAtomIndex]; float x = dataApi.getXcoords()[currentAtomIndex]; @@ -220,12 +216,12 @@ private void addAtomData(PDBGroup currentPdbGroup, List atomInfo, int cu * Bond indices are specified internally within the group and start at 0. * @param bondOrders A list of integers specifying the bond orders for each bond. */ - private void addGroupBonds(List bondInds, List bondOrders) { + private void addGroupBonds(int[] bondInds, int[] bondOrders) { // Now add the bond information for this group - for (int thisBond = 0; thisBond < bondOrders.size(); thisBond++) { - int thisBondOrder = bondOrders.get(thisBond); - int thisBondIndOne = bondInds.get(thisBond * 2); - int thisBondIndTwo = bondInds.get(thisBond * 2 + 1); + for (int thisBond = 0; thisBond < bondOrders.length; thisBond++) { + int thisBondOrder = bondOrders[thisBond]; + int thisBondIndOne = bondInds[thisBond * 2]; + int thisBondIndTwo = bondInds[(thisBond * 2 + 1)]; structInflator.setGroupBond(thisBondIndOne, thisBondIndTwo, thisBondOrder); } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 843df4b..c464e17 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -232,11 +232,6 @@ public int[] getResidueNums() { return groupNum; } - @Override - public Map getGroupMap() { - return groupMap; - } - @Override public int[] getGroupIndices() { return groupList; @@ -302,11 +297,6 @@ public String getMmtfProducer() { return mmtfProducer; } - @Override - public Entity[] getEntityList() { - return entityList; - } - @Override public String getPdbId() { return pdbId; @@ -357,6 +347,107 @@ public List getExperimentalMethods() { return experimentalMethods; } + @Override + public String getGroupName(int groupInd) { + return groupMap.get(groupInd).getGroupName(); + } + + public int getNumAtomsInGroup(int groupInd) { + return groupMap.get(groupInd).getAtomCharges().size(); + } + + @Override + public String[] getGroupAtomNames(int groupInd) { + List atomInfo = groupMap.get(groupInd).getAtomInfo(); + String[] outList = new String[atomInfo.size()/2]; + int counter = 0; + for (int i=1; i atomInfo = groupMap.get(groupInd).getAtomInfo(); + String[] outList = new String[atomInfo.size()/2]; + int counter = 0; + for (int i=0; i; + * @param inArray The input List<> of Integers + * @return A primitive int[]. + */ + private int[] convertToIntList(List inArray) { + int[] outArray = new int[inArray.size()]; + for (int i=0; i totChains = new ArrayList<>(); - for (int i=0; i < biojavaStruct.nrModels(); i++) { - totChains.addAll(biojavaStruct.getChains(i)); - } - // Now check it has the same information as BioJava - for(int i=0; i bioJavaChains = biojavaEntity.getChains(); - int[] mmtfList = mmtfEntity.getChainIndexList(); - assertEquals(mmtfList.length, bioJavaChains.size()); - int[] testList = new int[bioJavaChains.size()]; - for(int j=0; j totChains = new ArrayList<>(); + for (int i=0; i < biojavaStruct.nrModels(); i++) { + totChains.addAll(biojavaStruct.getChains(i)); + } + // Now check it has the same information as BioJava + for(int i=0; i bioJavaChains = biojavaEntity.getChains(); + int[] mmtfList = dataApi.getEntityChainIndexList(i); + assertEquals(mmtfList.length, bioJavaChains.size()); + int[] testList = new int[bioJavaChains.size()]; + for(int j=0; j thisChainSeqResList = new ArrayList<>(); - for(Group seqResGroup : currentChain.getSeqResGroups()){ - thisChainSeqResList.add(seqResGroup); - } - // Now go through and check the indices line up - for(int i = 0; i < currentChain.getAtomGroups().size(); i++){ - // Get the group - Group testGroup = currentChain.getAtomGroup(i); - int testGroupInd = thisChainSeqResList.indexOf(testGroup); - assertEquals(testGroupInd, decodedSeqResGroupList[groupCounter]); - groupCounter++; - } - chainCounter++; - } - } - // Otherwise we need to parse in a different - else{ - System.out.println("Using public facing chain ids -> seq res not tested"); - } + /** + * Test of sequence and seqres group level information. At the moment the decoder does not parse this data. + * This test checks to see if the underlying data is how one would expect. + * @param biojavaStruct + * @param params + */ + public void checkIfSeqResInfoSame(Structure biojavaStruct, FileParsingParameters params){ + if(params.isUseInternalChainId()){ + // Get the seqres group list + int[] decodedSeqResGroupList = dataApi.getSeqResGroupIndices(); + // Get the string sequences + int groupCounter = 0; + int chainCounter = 0; + // Get the sequence information - only for the first model + String sequence = null; + for(Chain currentChain : biojavaStruct.getChains()){ + for (int i=0; i thisChainSeqResList = new ArrayList<>(); + for(Group seqResGroup : currentChain.getSeqResGroups()){ + thisChainSeqResList.add(seqResGroup); + } + // Now go through and check the indices line up + for(int i = 0; i < currentChain.getAtomGroups().size(); i++){ + // Get the group + Group testGroup = currentChain.getAtomGroup(i); + int testGroupInd = thisChainSeqResList.indexOf(testGroup); + assertEquals(testGroupInd, decodedSeqResGroupList[groupCounter]); + groupCounter++; + } + chainCounter++; + } + } + // Otherwise we need to parse in a different + else{ + System.out.println("Using public facing chain ids -> seq res not tested"); + } - } + } } From 78c0b1fd409b813e0e155c320f0569da2ae2a690 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Fri, 1 Apr 2016 18:54:02 -0700 Subject: [PATCH 003/108] Updates to remove Bioassembly from the data api and the mmtf-common dependency alltogether --- mmtf-api/pom.xml | 5 --- .../org/rcsb/mmtf/api/DataApiInterface.java | 33 ++++++++++++++++--- .../rcsb/mmtf/decoder/DecodeStructure.java | 13 ++------ .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 25 +++++++++++--- .../org/rcsb/mmtf/examples/HelloWorld.java | 2 +- 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/mmtf-api/pom.xml b/mmtf-api/pom.xml index c267eca..a2140b5 100644 --- a/mmtf-api/pom.xml +++ b/mmtf-api/pom.xml @@ -19,11 +19,6 @@ - - org.rcsb - mmtf-common - 0.0.1-alpha4-SNAPSHOT - junit junit diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java index bb3f79d..7471007 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java @@ -2,8 +2,6 @@ import java.util.List; -import org.rcsb.mmtf.dataholders.BioAssemblyData; - /** * An interface describing the data API. * @@ -206,11 +204,36 @@ public interface DataApiInterface { float[] getUnitCell(); /** - * Returns a list of {@link BioAssemblyData}s corresponding to the structure. - * @return + * Returns the number of bioassemblies in this structure. + * @return an integer specifying the number of bioassemblies. */ - List getBioAssemblyList(); + int getNumBioassemblies(); + /** + * Returns the number of transformations in a given bioassembly. + * @param an integer specifying the bioassembly index (zero indexed). + * @return an integer specifying of transformations in a given bioassembly. + */ + int getNumTransInBioassembly(int bioassemblyIndex); + + /** + * Returns the list of chain ids for the given transformation for the given bioassembly. + * @param an integer specifying the bioassembly index (zero indexed). + * @param an integer specifying the index (zero indexed) for the desired transformation. + * @return a list of strings showing the chains involved in this transformation. + */ + String[] getChainIdListForTrans(int bioassemblyIndex, int transformationIndex); + + + /** + * Returns the transformation matrix for the given transformation for the given bioassembly. + * @param an integer specifying the bioassembly index (zero indexed). + * @param an integer specifying the index (zero indexed) for the desired transformation. + * @return the transformation matrix for this transformation. + */ + double[] getTransMatrixForTrans(int bioassemblyIndex, int transformationIndex); + + /** * Returns an array of inter-group bonds represented with 2 consecutive atom * indices in the array. diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index f791084..576e04d 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -1,13 +1,10 @@ package org.rcsb.mmtf.decoder; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.rcsb.mmtf.api.DataApiInterface; import org.rcsb.mmtf.api.StructureDecoderInterface; -import org.rcsb.mmtf.dataholders.BioAssemblyData; -import org.rcsb.mmtf.dataholders.BioAssemblyTrans; /** * Decode an MMTF structure using a structure inflator. The class also allows access to the unconsumed but parsed and inflated underlying data. @@ -250,13 +247,9 @@ private void addXtalographicInfo() { * Parses the bioassembly data and inputs it to the structure inflator */ private void generateBioAssembly() { - int bioAssemblyId = 0; - for (BioAssemblyData bioassembly : dataApi.getBioAssemblyList()) { - bioAssemblyId++; - List trans = bioassembly.getTransforms(); - for (BioAssemblyTrans bioAssemblyTrans : trans ) { - String[] chainIdList = bioAssemblyTrans.getChainIdList().toArray(new String[0]); - structInflator.setBioAssemblyTrans(bioAssemblyId, chainIdList, bioAssemblyTrans.getTransformation()); + for (int i=0; i getBioAssemblyList() { - return bioAssembly; - } - @Override public int[] getInterGroupBondIndices() { return interGroupBondIndices; @@ -448,6 +443,26 @@ public int getNumEntities() { return entityList.length; } + @Override + public int getNumBioassemblies() { + return bioAssembly.size(); + } + + @Override + public int getNumTransInBioassembly(int bioassemblyIndex) { + return bioAssembly.get(bioassemblyIndex).getTransforms().size(); + } + + @Override + public String[] getChainIdListForTrans(int bioassemblyIndex, int transformationIndex) { + return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getChainIdList().toArray(new String[0]); + } + + @Override + public double[] getTransMatrixForTrans(int bioassemblyIndex, int transformationIndex) { + return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getTransformation(); + } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java index 52bfb3b..b19b51b 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java @@ -9,7 +9,7 @@ public static void main(String[] args) { DataApiInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); System.out.println("PDB Code: "+dataApi.getPdbId()+" has "+dataApi.getNumChains()+" chains"); System.out.println("HET group "+dataApi.getGroupName(0)+" has the following atomic charges: "+dataApi.getGroupAtomCharges(0)); - System.out.println("PDB Code: "+dataApi.getPdbId()+" has "+dataApi.getBioAssemblyList().size()+" bioassemblies"); + System.out.println("PDB Code: "+dataApi.getPdbId()+" has "+dataApi.getNumBioassemblies()+" bioassemblies"); } } From 3b23493d6f0b19dc1ddf1dc264fbab2ffcd44474 Mon Sep 17 00:00:00 2001 From: abradle Date: Sat, 2 Apr 2016 07:05:09 -0700 Subject: [PATCH 004/108] Altered the groupMap to a groupList. Integration tests pass. --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 14 +++++------ .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 23 +++++++++---------- .../mmtf/biojavaencoder/EncoderUtils.java | 19 ++++++++++++++- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 312d388..8536d01 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -2,7 +2,6 @@ import java.io.Serializable; import java.util.List; -import java.util.Map; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -72,9 +71,8 @@ public class MmtfBean implements Serializable { /** The bond order list. */ private byte[] bondOrderList; - /** The group map. */ - // Map of all the data - private Map groupMap; + /** The list of different PDBGroups in the structure. */ + private PDBGroup[] groupList; /** The x coord big. 4 byte integers in pairs. */ private byte[] xCoordBig; @@ -519,8 +517,8 @@ public final void setInsCodeList(final List inputInsertionCodeList) { * * @return the group map */ - public final Map getGroupMap() { - return groupMap; + public final PDBGroup[] getGroupList() { + return groupList; } /** @@ -528,8 +526,8 @@ public final Map getGroupMap() { * * @param inputGroupMap the group map */ - public final void setGroupMap(final Map inputGroupMap) { - this.groupMap = inputGroupMap; + public final void setGroupList(final PDBGroup[] inputGroupMap) { + this.groupList = inputGroupMap; } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 4ee19c8..20f690d 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.msgpack.jackson.dataformat.MessagePackFactory; import org.rcsb.mmtf.api.DataApiInterface; @@ -59,7 +58,7 @@ public SimpleDataApi(byte[] inputByteArr) { // Get the groupNumber groupNum = intRunLengthDelta.decompressByteArray( inputData.getGroupIdList()); - groupMap = inputData.getGroupMap(); + groupMap = inputData.getGroupList(); // Get the seqRes groups seqResGroupList = intRunLengthDelta.decompressByteArray(inputData.getSeqResIdList()); // Get the number of chains per model @@ -122,7 +121,7 @@ public SimpleDataApi(byte[] inputByteArr) { private int[] groupNum; /** The group map. */ - private Map groupMap; + private PDBGroup[] groupMap; /** The group list. */ private int[] groupList; @@ -344,16 +343,16 @@ public List getExperimentalMethods() { @Override public String getGroupName(int groupInd) { - return groupMap.get(groupInd).getGroupName(); + return groupMap[groupInd].getGroupName(); } public int getNumAtomsInGroup(int groupInd) { - return groupMap.get(groupInd).getAtomCharges().size(); + return groupMap[groupInd].getAtomCharges().size(); } @Override public String[] getGroupAtomNames(int groupInd) { - List atomInfo = groupMap.get(groupInd).getAtomInfo(); + List atomInfo = groupMap[groupInd].getAtomInfo(); String[] outList = new String[atomInfo.size()/2]; int counter = 0; for (int i=1; i atomInfo = groupMap.get(groupInd).getAtomInfo(); + List atomInfo = groupMap[groupInd].getAtomInfo(); String[] outList = new String[atomInfo.size()/2]; int counter = 0; for (int i=0; i PDBGroup + * @return A list of PDBGroups, where the previous keys are used as indices. + */ + private PDBGroup[] genGroupList(Map groupMap) { + PDBGroup[] outGroupList = new PDBGroup[Collections.max(groupMap.keySet())+1]; + for (int key : groupMap.keySet()) { + outGroupList[key] = groupMap.get(key); + } + return outGroupList; + } + + /** * Add the required bytearrays to an mmtfbean. * From 61b749d5252de279edbe0c91e9055952625744f5 Mon Sep 17 00:00:00 2001 From: abradle Date: Sat, 2 Apr 2016 07:53:11 -0700 Subject: [PATCH 005/108] Fixed a bug where the same array was being declared in two places --- .../mmtf/dataholders/BioDataStructBean.java | 71 ------------------- 1 file changed, 71 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java index 6d699f6..519356b 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java @@ -29,22 +29,6 @@ public class BioDataStructBean extends NoCoordDataStruct implements BioBean { // The fraction of the atom present at this atom position_ protected List _atom_site_occupancy= new ArrayList(); - /** The secondary structure list. */ - // An array to store the secondary structure data - private List secStruct = new ArrayList(); - - /** The residue order list. */ - // An array to store the sequence of residues - private List resOrder = new ArrayList(); - - /** The inter-group bond indicess. */ - // Arrays to store the indices and bond orders of inter residue bonds - private List interGroupBondInds = new ArrayList(); - - /** The inter-group bond orders. */ - private List interGroupBondOrders = new ArrayList(); - - /** * Gets the _atom_site_id. * @@ -156,59 +140,4 @@ public void set_atom_site_occupancy(ArrayList _atom_site_occupancy) { this._atom_site_occupancy = _atom_site_occupancy; } - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#getResOrder() - */ - public List getResOrder() { - return resOrder; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#setResOrder(java.util.List) - */ - public void setResOrder(List resOrder) { - this.resOrder = resOrder; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#getSecStruct() - */ - public List getSecStruct() { - return secStruct; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#setSecStruct(java.util.List) - */ - public void setSecStruct(List secStruct) { - this.secStruct = secStruct; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#getInterGroupBondOrders() - */ - public List getInterGroupBondOrders() { - return interGroupBondOrders; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#setInterGroupBondOrders(java.util.List) - */ - public void setInterGroupBondOrders(List interGroupBondOrders) { - this.interGroupBondOrders = interGroupBondOrders; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#getInterGroupBondInds() - */ - public List getInterGroupBondInds() { - return interGroupBondInds; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.NoCoordDataStruct#setInterGroupBondInds(java.util.List) - */ - public void setInterGroupBondInds(List interGroupBondInds) { - this.interGroupBondInds = interGroupBondInds; - } } From fa92ea67d92159a1d700ba3b07d446da1e080736 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 4 Apr 2016 12:18:30 -0700 Subject: [PATCH 006/108] Updates to bioassembly handling. However this still fails the tests (as some bioassemblies do not have an index). --- .../org/rcsb/mmtf/api/DataApiInterface.java | 6 +-- .../mmtf/api/StructureDecoderInterface.java | 8 +-- .../mmtf/dataholders/BioAssemblyTrans.java | 21 ++++---- .../rcsb/mmtf/decoder/DecodeStructure.java | 2 +- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 4 +- .../mmtf/biojavaencoder/ParseFromBiojava.java | 53 ++++++++++++++++--- .../rcsb/mmtf/testutils/CheckOnBiojava.java | 2 - .../mmtf/update/IntegrationTestUtils.java | 4 +- 8 files changed, 68 insertions(+), 32 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java index 7471007..315fe5f 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java @@ -217,12 +217,12 @@ public interface DataApiInterface { int getNumTransInBioassembly(int bioassemblyIndex); /** - * Returns the list of chain ids for the given transformation for the given bioassembly. + * Returns the list of chain indices for the given transformation for the given bioassembly. * @param an integer specifying the bioassembly index (zero indexed). * @param an integer specifying the index (zero indexed) for the desired transformation. - * @return a list of strings showing the chains involved in this transformation. + * @return a list of indices showing the chains involved in this transformation. */ - String[] getChainIdListForTrans(int bioassemblyIndex, int transformationIndex); + int[] getChainIndexListForTrans(int bioassemblyIndex, int transformationIndex); /** diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java index 83d7a78..52629ce 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java @@ -69,13 +69,13 @@ void setGroupInfo(String groupName, int groupNumber, char insertionCode, void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, float x, float y, float z, float occupancy, float temperatureFactor, String element, int charge); - /** * Sets a single Bioassembly transformation to a structure. bioAssemblyId indicates the index of the bioassembly. - * - * @param inputBioassemblies + * @param bioAssemblyIndex An integer index of this bioassembly. + * @param inputChainIndices The integer indices of the chains involved in this bioassembly. + * @param inputTransform A list of doubles indicating the transform for this bioassembly. */ - void setBioAssemblyTrans(int bioAssemblyId, String[] inputChainIds, double[] inputTransform); + void setBioAssemblyTrans(int bioAssemblyIndex, int[] inputChainIndices, double[] inputTransform); /** * Sets the space group and unit cell information. diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java index 54f451c..0f9875f 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java @@ -1,10 +1,7 @@ package org.rcsb.mmtf.dataholders; - import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; /** * The transformation needed for generation of biological assemblies @@ -21,8 +18,8 @@ public class BioAssemblyTrans implements Serializable { private static final long serialVersionUID = -8109941242652091495L; - /** The chain id. */ - private List chainIdList = new ArrayList(); + /** The indices of the chains this bioassembly references. */ + private int[] chainIndexList; /** The 4x4 matrix transformation specifying a rotation and a translation. */ private double[] transformation; @@ -51,21 +48,21 @@ public final void setTransformation(final double[] inputTransformation) { } /** - * Gets the chain id list. + * Gets the indices of the chains this bioassembly refers to. * - * @return the chain id list + * @return a list of integers indicating the indices (zero indexed) of the chains this bioassembly refers to. */ - public final List getChainIdList() { - return chainIdList; + public final int[] getChainIndexList() { + return chainIndexList; } /** * Sets the chain id. * - * @param inputChainId the new chain id + * @param a list of integers indicating the indices (zero indexed) of the chains this bioassembly refers to. */ - public final void setChainIdList(final List inputChainId) { - this.chainIdList = inputChainId; + public final void setChainIndexList(final int[] inputChainId) { + this.chainIndexList = inputChainId; } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 576e04d..3bba625 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -249,7 +249,7 @@ private void addXtalographicInfo() { private void generateBioAssembly() { for (int i=0; i inputAtoms, PDBGroup pdbGroup) { * @return a map of the bioassembly information that is serializable */ private List generateSerializableBioAssembly(Structure bioJavaStruct, PDBHeader header) { + // Get a map to reference asym ids to chains + Map chainIdToIndexMap = getChainIdToIndexMap(bioJavaStruct); // Here we need to iterate through and get the chain ids and the matrices Map inputBioAss = header.getBioAssemblies(); List outMap = new ArrayList(); - - for (Map.Entry entry : inputBioAss.entrySet()) { Map matSet = new HashMap(); BioAssemblyInfo value = entry.getValue(); @@ -706,7 +706,6 @@ private List generateSerializableBioAssembly(Structure bioJavaS // Copy across this info List outTrans = new ArrayList(); for(BiologicalAssemblyTransformation transform: value.getTransforms()){ - // Get's the chain id -> this is the asym id String thisChain = transform.getChainId(); // Get the current matrix 4d @@ -720,15 +719,35 @@ private List generateSerializableBioAssembly(Structure bioJavaS } } if(matSet.containsKey(currentTransMat)){ - // Get it + // Get the trasnformation BioAssemblyTrans bioTransNew = matSet.get(currentTransMat); - bioTransNew.getChainIdList().add(thisChain); + // Add this chain index to that list + int[] oldList = bioTransNew.getChainIndexList(); + int oldLen = oldList.length; + int[] newList = new int[oldLen+1]; + for (int i=0; i generateSerializableBioAssembly(Structure bioJavaS return outMap; } + /** + * Get the index of chain given a particular Asym id. Assumes there are more asym ids than auth ids... + * @param thisChain + * @return + */ + private Map getChainIdToIndexMap(Structure bioJavaStruct) { + // First build a map of asymid -> chain index + Map chainIdToIndexMapOne = new HashMap<>(); + int chainCounter = 0; + for (int i=0; i Date: Mon, 4 Apr 2016 16:04:55 -0700 Subject: [PATCH 007/108] Bioassemblies now generate correectly for asym ids. Test - checks to see that any missing chain is actually missing from the structure. If parsing usign auth ids - bioassemby info isn't available - as no way to pass indices to auth chains. --- .../rcsb/mmtf/decoder/DecodeStructure.java | 6 ++- mmtf-encoder/pom.xml | 2 +- .../mmtf/postupdatetests/CheckServer.java | 2 +- .../rcsb/mmtf/testutils/CheckOnBiojava.java | 53 +++++++++++++++---- .../org/rcsb/mmtf/update/TestingUtils.java | 2 +- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 3bba625..dc90cf2 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -65,8 +65,10 @@ public final void getStructFromByteArray(final StructureDecoderInterface inputSt addHeaderInfo(); // Now set the crystallographic information addXtalographicInfo(); - /// Now get the bioassembly information - generateBioAssembly(); + /// Now get the bioassembly information - only if parsing using AsymId + if (parsingParams.isParseInternal()){ + generateBioAssembly(); + } // Now add the other bonds between groups addInterGroupBonds(); // Now add the entity info diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index ce267ca..06b7b6e 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -23,7 +23,7 @@ org.rcsb - mmtf-decoder + mmtf-common 0.0.1-alpha4-SNAPSHOT diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index 57ffb7f..056f6c1 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -85,7 +85,7 @@ private void testParsing(String inputPdb, String inputUrl) throws IOException { e.printStackTrace(); throw new RuntimeException(); } - checkEquiv.checkIfStructuresSame(mmtfStruct, mmcifStruct); + checkEquiv.checkIfStructuresSame(mmtfStruct, mmcifStruct, parsingParms); // Now do the checks on the Raw data CheckOnRawApi checkRaw = new CheckOnRawApi(inputByteArr); checkRaw.checkRawDataConsistency(mmcifStruct, params); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java index 26fb726..600cea1 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java @@ -21,6 +21,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; +import org.rcsb.mmtf.decoder.ParsingParams; public class CheckOnBiojava { @@ -31,11 +32,14 @@ public CheckOnBiojava() { * Broad test of atom similarity * @param structOne * @param structTwo + * @param mmtfParams) * @return */ - private boolean checkIfAtomsSame(Structure structOne, Structure structTwo) { + private boolean checkIfAtomsSame(Structure structOne, Structure structTwo, ParsingParams mmtfParams) { // First check the bioassemblies - checkIfBioassemblySame(structOne, structTwo); + if (mmtfParams.isParseInternal()){ + checkIfBioassemblySame(structOne, structTwo); + } // Now check the pdb header checkIfHederSame(structOne, structTwo); // Now check the entity information @@ -193,8 +197,8 @@ private void checkIfEntitiesSame(Structure structOne, Structure structTwo) { EntityInfo entityInfoOne = entityListOne.get(i); EntityInfo entityInfoTwo = entityListTwo.get(i); assertEquals(entityInfoOne.getDescription(), entityInfoTwo.getDescription()); -// // Need to fix bug in Biojava (entites not allocated to chains when using AuthIds). -// assertEquals(entityInfoOne.toString(), entityInfoTwo.toString()); + // // Need to fix bug in Biojava (entites not allocated to chains when using AuthIds). + // assertEquals(entityInfoOne.toString(), entityInfoTwo.toString()); } } /** @@ -232,10 +236,9 @@ private void checkIfHederSame(Structure structOne, Structure structTwo) { * @param structTwo * @return */ - private void checkIfBioassemblySame(Structure structOne, Structure structTwo){ - + private void checkIfBioassemblySame(Structure structOne, Structure structTwo){ // Get the headers - Map bioassembliesOne = structOne.getPDBHeader().getBioAssemblies(); + Map bioassembliesOne = cleanUpBioass(structOne); Map bioassembliesTwo = structTwo.getPDBHeader().getBioAssemblies(); assertEquals(bioassembliesOne.keySet(), bioassembliesTwo.keySet()); for(Entry entry: bioassembliesOne.entrySet()){ @@ -265,12 +268,44 @@ private void checkIfBioassemblySame(Structure structOne, Structure structTwo){ } } + /** + * Remove any transformation applying to empty chains. + * @param inputStruct The input Biojava Structure to be used. + * @return The bioassemblies cleande up. + */ + private Map cleanUpBioass(Structure inputStruct) { + // Get the bioassemblies + Map bioAssemblies = inputStruct.getPDBHeader().getBioAssemblies(); + // Create a list of chains + List chainList = new ArrayList<>(); + for (int i=0; i entry : bioAssemblies.entrySet()) { + BioAssemblyInfo val = entry.getValue(); + List removeList = new ArrayList<>(); + for (BiologicalAssemblyTransformation bioTrans : val.getTransforms()) { + // Check if it exists + if(!chainList.contains(bioTrans.getChainId())) { + removeList.add(bioTrans); + } + } + val.getTransforms().removeAll(removeList); + } + return bioAssemblies; + } + /** * Check if all features between the two structures are the same * @param biojavaStruct the input biojava structure parsed from the mmcif file * @param structTwo the BioJava structure parsed from the MMTF file + * @param mmtfParams */ - public void checkIfStructuresSame(Structure biojavaStruct, Structure structTwo){ - assertTrue(checkIfAtomsSame(biojavaStruct, structTwo)); + public void checkIfStructuresSame(Structure biojavaStruct, Structure structTwo, ParsingParams mmtfParams){ + assertTrue(checkIfAtomsSame(biojavaStruct, structTwo, mmtfParams)); } } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index f0fb0f7..fe9ae79 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -49,7 +49,7 @@ public void testAll(String[] inputList, FileParsingParameters params, AtomCache public void testOne(String pdbId, FileParsingParameters params, AtomCache cache, ParsingParams mmtfParams) throws IllegalAccessException, InvocationTargetException, IOException, StructureException { CheckOnBiojava checkEquiv = new CheckOnBiojava(); Structure structure = StructureIO.getStructure(pdbId); - checkEquiv.checkIfStructuresSame(structure,roundTripStruct(pdbId, mmtfParams, params, cache)); + checkEquiv.checkIfStructuresSame(structure,roundTripStruct(pdbId, mmtfParams, params, cache),mmtfParams); } /** From 950b785bf70436a9a151e5db5bfda19a07f8c1e5 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 4 Apr 2016 17:07:16 -0700 Subject: [PATCH 008/108] No longer values for missing resolution/rFree/rWork values Null values are missing from the file now. For the API 99.0 is the default for resolution and 1.0 for rfree and rwork. --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 72 +++++++++++-------- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 52 ++++++++------ .../mmtf/biojavaencoder/EncodeStructure.java | 64 ++++++++--------- .../mmtf/biojavaencoder/EncoderUtils.java | 2 + .../mmtf/biojavaencoder/ParseFromBiojava.java | 4 +- .../org/rcsb/mmtf/dataholders/HeaderBean.java | 6 +- .../rcsb/mmtf/testutils/CheckOnBiojava.java | 2 +- .../mmtf/update/IntegrationTestUtils.java | 48 ++++++------- 8 files changed, 135 insertions(+), 115 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 8536d01..cc4f226 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -12,7 +12,7 @@ */ @JsonIgnoreProperties(ignoreUnknown = true) public class MmtfBean implements Serializable { - + /** The number to divide coordinate int values by. */ public static final float COORD_DIVIDER = 1000.0f; /** The number to divide occupancy and bfactor int values by. */ @@ -20,9 +20,10 @@ public class MmtfBean implements Serializable { /** * The default value for Rfree, Rwork and resolution when not available or not applicable */ - public static final float UNAVAILABLE_R_VALUE = -1.0f; + public static final float UNAVAILABLE_R_VALUE = 1.0f; + public static final float UNAVAILABLE_RESOLUTION_VALUE = 99.0f; + - /** Serial id for this version of the format. */ private static final long serialVersionUID = 384559979573830324L; @@ -125,19 +126,19 @@ public class MmtfBean implements Serializable { /** The experimental method(s). */ private List experimentalMethods; - /** The resolution in Angstrom. -1.0 if not applicable*/ + /** The resolution in Angstrom. Null if not applicable*/ private float resolution; - /** The rfree. -1.0 if not applicable */ + /** The rfree. Null if not applicable */ private float rFree; - /** The r-work. -1.0 if not applicable */ + /** The r-work. Null if not applicable */ private float rWork; - + /** The list of entities in this structure. */ private Entity[] entityList; - - + + /** Constructor to set the default values for floats */ public MmtfBean() { @@ -148,11 +149,11 @@ public MmtfBean() { mmtfProducer = "NA"; /** The resolution in Angstrom. -1.0 if not applicable*/ - resolution = UNAVAILABLE_R_VALUE; + resolution = UNAVAILABLE_RESOLUTION_VALUE; - /** The rfree. -1.0 if not applicable */ + /** The rfree. 1.0 if not applicable */ rFree = UNAVAILABLE_R_VALUE; - + rWork = UNAVAILABLE_R_VALUE; /** The number of atoms. Default is -1 indicates error */ @@ -166,7 +167,10 @@ public MmtfBean() { /** * @return the resolution */ - public float getResolution() { + public Float getResolution() { + if (resolution==UNAVAILABLE_RESOLUTION_VALUE) { + return null; + } return resolution; } @@ -180,7 +184,10 @@ public void setResolution(float resolution) { /** * @return the rFree */ - public float getrFree() { + public Float getrFree() { + if (rFree==UNAVAILABLE_R_VALUE) { + return null; + } return rFree; } @@ -194,7 +201,10 @@ public void setrFree(float rFree) { /** * @return the rWork */ - public float getrWork() { + public Float getrWork() { + if (rWork==UNAVAILABLE_R_VALUE) { + return null; + } return rWork; } @@ -206,7 +216,7 @@ public void setrWork(float rWork) { } - /** + /** * Gets the space group. * * @return the space group @@ -794,20 +804,20 @@ public void setSeqResIdList(byte[] seqResGroupIds) { this.seqResIdList = seqResGroupIds; } - /** - * Get the entity list - * @return - */ - public Entity[] getEntityList() { - return entityList; - } - - /** - * Set the entity list - * @param entityList - */ - public void setEntityList(Entity[] entityList) { - this.entityList = entityList; - } + /** + * Get the entity list + * @return + */ + public Entity[] getEntityList() { + return entityList; + } + + /** + * Set the entity list + * @param entityList + */ + public void setEntityList(Entity[] entityList) { + this.entityList = entityList; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 535ad42..b86c9f5 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -18,11 +18,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class SimpleDataApi implements DataApiInterface { - - + + public SimpleDataApi(byte[] inputByteArr) { - - + + MmtfBean inputData = null; try { inputData = new ObjectMapper(new MessagePackFactory()).readValue(inputByteArr, MmtfBean.class); @@ -32,14 +32,14 @@ public SimpleDataApi(byte[] inputByteArr) { e.printStackTrace(); throw new RuntimeException(); } - + // Get the decompressors to build in the data structure DeltaDeCompress deltaDecompress = new DeltaDeCompress(); RunLengthDelta intRunLengthDelta = new RunLengthDelta(); RunLengthDecodeInt intRunLength = new RunLengthDecodeInt(); RunLengthDecodeString stringRunlength = new RunLengthDecodeString(); DecoderUtils decoderUtils = new DecoderUtils(); - + // Get the data try { groupList = decoderUtils.bytesToInts(inputData.getGroupTypeList()); @@ -78,11 +78,12 @@ public SimpleDataApi(byte[] inputByteArr) { pdbId = inputData.getPdbId(); // Now get the header data rFree = inputData.getrFree(); + // Optional fields rWork = inputData.getrWork(); resolution = inputData.getResolution(); title = inputData.getTitle(); experimentalMethods = inputData.getExperimentalMethods(); - + } catch (IOException ioException){ @@ -91,8 +92,8 @@ public SimpleDataApi(byte[] inputByteArr) { throw new RuntimeException(); } } - - + + /** The X coordinates */ private float[] cartnX; @@ -107,7 +108,7 @@ public SimpleDataApi(byte[] inputByteArr) { /** The Y coordinates */ private float[] occupancy; - + /** The atom id. */ private int[] atomId; @@ -170,22 +171,22 @@ public SimpleDataApi(byte[] inputByteArr) { /** The PDB id */ private String pdbId; - + /** The reported resolution of the dataset. */ - private float resolution; + private Float resolution; /** The reported R Free of the model. */ - private float rFree; - + private Float rFree; + /** The reported R Work of the model. */ - private float rWork; - + private Float rWork; + /** The title of the model. */ private String title; /** The list of experimental methods. */ private List experimentalMethods; - + @Override public float[] getXcoords() { return cartnX; @@ -305,7 +306,7 @@ public int getNumResidues() { public int getNumChains() { return this.chainList.length; } - + @Override public int getNumModels() { return this.chainsPerModel.length; @@ -318,16 +319,25 @@ public int getNumAtoms() { @Override public float getRfree() { + if (rFree==null) { + return MmtfBean.UNAVAILABLE_R_VALUE; + } return rFree; } @Override public float getResolution() { + if (resolution==null) { + return MmtfBean.UNAVAILABLE_RESOLUTION_VALUE; + } return resolution; } @Override public float getRwork() { + if (rWork==null) { + return MmtfBean.UNAVAILABLE_R_VALUE; + } return rWork; } @@ -345,7 +355,7 @@ public List getExperimentalMethods() { public String getGroupName(int groupInd) { return groupMap[groupInd].getGroupName(); } - + public int getNumAtomsInGroup(int groupInd) { return groupMap[groupInd].getAtomCharges().size(); } @@ -399,8 +409,8 @@ public String getGroupSingleLetterCode(int groupInd) { public String getGroupChemCompType(int groupInd) { return groupMap[groupInd].getChemCompType(); } - - + + /** * Get a primitive int[] list from a Java List<>; * @param inArray The input List<> of Integers diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java index 8d47404..ec1a825 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java @@ -10,12 +10,12 @@ public class EncodeStructure { - /** - * Get a byte array of the compressed messagepack MMTF data - * from an input PDB id - * @param pdbId - * @return a byte array of compressed data - */ + /** + * Get a byte array of the compressed messagepack MMTF data + * from an input PDB id + * @param pdbId + * @return a byte array of compressed data + */ public byte[] getCompressedMessagePackFromPdbId(String pdbId) { // Get the utility class to get the strucutes ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); @@ -23,43 +23,43 @@ public byte[] getCompressedMessagePackFromPdbId(String pdbId) { // Parse the data into the basic data structure parsedDataStruct.createFromJavaStruct(pdbId, totMap); // Compress the data and get it back out - return buildFromDataStructure(parsedDataStruct); + return buildFromDataStructure(parsedDataStruct); } - + /** * Generate the compressed messagepack MMTF data from a biojava structure * @param bioJavaStruct * @return a byte array of compressed data */ public byte[] encodeFromBiojava(Structure bioJavaStruct){ - // Get the utility class to get the strucutes + // Get the utility class to get the strucutes ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); Map totMap = new HashMap(); // Parse the data into the basic data structure parsedDataStruct.generateDataStructuresFromBioJavaStructure(bioJavaStruct, totMap); return buildFromDataStructure(parsedDataStruct); } - + /** * Build up a byte array from the parsed data * @param parsedDataStruct * @return a byte array of compressed data */ private byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { - EncoderUtils eu = new EncoderUtils(); - // Compress the data and get it back out - try { - MmtfBean mmtfBean = eu.compressMainData(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); - return eu.getMessagePack(mmtfBean); - } catch (IOException e) { - // Here we've failed to read or write a byte array - e.printStackTrace(); - System.err.println("Error reading or writing byte array - file bug report"); - throw new RuntimeException(e); - } - } + EncoderUtils eu = new EncoderUtils(); + // Compress the data and get it back out + try { + MmtfBean mmtfBean = eu.compressMainData(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); + return eu.getMessagePack(mmtfBean); + } catch (IOException e) { + // Here we've failed to read or write a byte array + e.printStackTrace(); + System.err.println("Error reading or writing byte array - file bug report"); + throw new RuntimeException(e); + } + } - /** + /** * Generate the compressed messagepack of the calpha, phospohate and ligand data. * @param pdbId The input pdb id * @return a byte array of compressed calpha data @@ -73,14 +73,14 @@ public byte[] encodeBackBoneFromPdbId(String pdbId){ cbs.createFromJavaStruct(pdbId, totMap); // Compress the data and get it back out try { - return eu.getMessagePack(eu.compCAlpha(cbs.getCalphaStruct(), cbs.getHeaderStruct())); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Error in reading or writing byte array"); - throw new RuntimeException(e); - } + return eu.getMessagePack(eu.compCAlpha(cbs.getCalphaStruct(), cbs.getHeaderStruct())); + } catch (IOException e) { + e.printStackTrace(); + System.err.println("Error in reading or writing byte array"); + throw new RuntimeException(e); + } } - - - + + + } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index b432a64..9605cb3 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -43,6 +43,7 @@ import org.rcsb.mmtf.dataholders.PDBGroup; import org.rcsb.mmtf.gitversion.GetRepoState; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; @@ -97,6 +98,7 @@ public byte[] integersToBytes(List inputList) throws IOException */ public byte[] getMessagePack(Object inputObject) throws JsonProcessingException{ com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(new MessagePackFactory()); + objectMapper.setSerializationInclusion(Include.NON_NULL); byte[] inBuf = objectMapper.writeValueAsBytes(inputObject); return inBuf; } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java index 9fcbe14..030f957 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java @@ -54,7 +54,6 @@ public class ParseFromBiojava { private static final int COORD_MULT = 1000; /** The bio struct. */ - // Instances availble to the class of the main, calpha and header data structures private BioDataStruct bioStruct = new BioDataStruct(); /** The calpha struct. */ @@ -64,7 +63,6 @@ public class ParseFromBiojava { private HeaderBean headerStruct = new HeaderBean(); /** The code holder. */ - // A class to store encoding information private CodeHolders codeHolder = new CodeHolders(); /** The bonds for the structure. Used to keep track of which bonds have already been considered */ @@ -467,7 +465,7 @@ private void setHeaderInfo(Structure bioJavaStruct) { headerStruct.setClassification(header.getClassification()); headerStruct.setDepDate(header.getDepDate()); headerStruct.setModDate(header.getModDate()); - headerStruct.setResolution(header.getResolution()); + headerStruct.setResolution(header.getResolution()); headerStruct.setrFree(header.getRfree()); JournalArticle myJournal = header.getJournalArticle(); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java index c55e851..811b873 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java @@ -111,11 +111,11 @@ public class HeaderBean { private List bioAssembly; public HeaderBean() { - resolution = (float) -1.0; + resolution = MmtfBean.UNAVAILABLE_RESOLUTION_VALUE; - rFree = (float) -1.0; + rFree = MmtfBean.UNAVAILABLE_R_VALUE; - rWork = (float) -1.0; + rWork = MmtfBean.UNAVAILABLE_R_VALUE; } // Getters and setters diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java index 600cea1..251318c 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java @@ -301,7 +301,7 @@ private Map cleanUpBioass(Structure inputStruct) { /** * Check if all features between the two structures are the same - * @param biojavaStruct the input biojava structure parsed from the mmcif file + * @param biojavaStruct the input Biojava structure parsed from the mmcif file * @param structTwo the BioJava structure parsed from the MMTF file * @param mmtfParams */ diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java index 423181f..1a92a0a 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java @@ -8,32 +8,32 @@ public class IntegrationTestUtils { public static final String[] TEST_CASES = new String[] { - // Another weird structure (jose's suggestion) - "3zyb", - //Standard structure - "4cup", +// // Another weird structure (jose's suggestion) +// "3zyb", +// //Standard structure +// "4cup", // Weird NMR structure "1o2f", - // B-DNA structure - "1bna", - // DNA structure - "4y60", - // Sugar structure - "1skm", - // Ribosome - "4v5a", - // Biosynthetic protein - "5emg", - // Calpha atom is missing (not marked as calpha) - "1lpv", - // NMR structure with multiple models - one of which has chain missing - "1msh", - // No ATOM records just HETATM records (in PDB). Opposite true for MMCif. It's a D-Peptide. - "1r9v", - // Micro heterogenity - "4ck4", - // Negative residue numbers - "5esw", +// // B-DNA structure +// "1bna", +// // DNA structure +// "4y60", +// // Sugar structure +// "1skm", +// // Ribosome +// "4v5a", +// // Biosynthetic protein +// "5emg", +// // Calpha atom is missing (not marked as calpha) +// "1lpv", +// // NMR structure with multiple models - one of which has chain missing +// "1msh", +// // No ATOM records just HETATM records (in PDB). Opposite true for MMCif. It's a D-Peptide. +// "1r9v", +// // Micro heterogenity +// "4ck4", +// // Negative residue numbers +// "5esw", // A weird case with incorrect residue numbers. // "3th3" }; From 04980afe73220437e31168181d64d4da3067c102 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 4 Apr 2016 17:16:03 -0700 Subject: [PATCH 009/108] Update to include the deposition date in ISO date format. --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 17 +++++++ .../mmtf/biojavaencoder/EncoderUtils.java | 15 ++++++ .../mmtf/update/IntegrationTestUtils.java | 48 +++++++++---------- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index cc4f226..9c59e36 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -137,6 +137,9 @@ public class MmtfBean implements Serializable { /** The list of entities in this structure. */ private Entity[] entityList; + + /** The deposition date of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ + private String depositionDate; /** Constructor to set the default values for floats */ @@ -820,4 +823,18 @@ public void setEntityList(Entity[] entityList) { this.entityList = entityList; } + /** + * @return the deposition date of the structure in ISO time standard. + */ + public String getDepositionDate() { + return depositionDate; + } + + /** + * @param depositionDate a string indicating the deposition date to set. + */ + public void setDepositionDate(String depositionDate) { + this.depositionDate = depositionDate; + } + } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index 9605cb3..7295175 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -8,8 +8,11 @@ import java.io.IOException; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -121,6 +124,7 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th MmtfBean thisDistBeanTot = new MmtfBean(); NoFloatDataStructBean bioBean = (NoFloatDataStructBean) strucureData.findDataAsBean(); // Copt these things + thisDistBeanTot.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); thisDistBeanTot.setPdbId(bioBean.getPdbCode()); thisDistBeanTot.setInsCodeList(bioBean.get_atom_site_pdbx_PDB_ins_code()); thisDistBeanTot.setAltLabelList(bioBean.get_atom_site_label_alt_id()); @@ -158,6 +162,17 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th return thisDistBeanTot; } + /** + * Covert a Date object to ISO time format. + * @param inputDate The input date object + * @return The time in ISO time format + */ + private String convertToIsoTime(Date inputDate) { + DateFormat dateStringFormat = new SimpleDateFormat("yyyy-MM-dd"); + return dateStringFormat.format(inputDate); + } + + /** * Returns a PDBGroupList from a GroupMap. Uses the key of the map as the index in the list. * @param groupMap The input map of Integer -> PDBGroup diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java index 1a92a0a..423181f 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/IntegrationTestUtils.java @@ -8,32 +8,32 @@ public class IntegrationTestUtils { public static final String[] TEST_CASES = new String[] { -// // Another weird structure (jose's suggestion) -// "3zyb", -// //Standard structure -// "4cup", + // Another weird structure (jose's suggestion) + "3zyb", + //Standard structure + "4cup", // Weird NMR structure "1o2f", -// // B-DNA structure -// "1bna", -// // DNA structure -// "4y60", -// // Sugar structure -// "1skm", -// // Ribosome -// "4v5a", -// // Biosynthetic protein -// "5emg", -// // Calpha atom is missing (not marked as calpha) -// "1lpv", -// // NMR structure with multiple models - one of which has chain missing -// "1msh", -// // No ATOM records just HETATM records (in PDB). Opposite true for MMCif. It's a D-Peptide. -// "1r9v", -// // Micro heterogenity -// "4ck4", -// // Negative residue numbers -// "5esw", + // B-DNA structure + "1bna", + // DNA structure + "4y60", + // Sugar structure + "1skm", + // Ribosome + "4v5a", + // Biosynthetic protein + "5emg", + // Calpha atom is missing (not marked as calpha) + "1lpv", + // NMR structure with multiple models - one of which has chain missing + "1msh", + // No ATOM records just HETATM records (in PDB). Opposite true for MMCif. It's a D-Peptide. + "1r9v", + // Micro heterogenity + "4ck4", + // Negative residue numbers + "5esw", // A weird case with incorrect residue numbers. // "3th3" }; From bcc881eedf9fc16fb4ab7f2138ab48a108119b3d Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 4 Apr 2016 17:19:57 -0700 Subject: [PATCH 010/108] pdbId renmaed to structureId --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 20 +++++++++---------- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 2 +- .../mmtf/biojavaencoder/EncoderUtils.java | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 9c59e36..115ef71 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -36,8 +36,8 @@ public class MmtfBean implements Serializable { /** The number of bonds. */ private int numBonds; - /** The pdb id. */ - private String pdbId; + /** The structure Id. Most commonly this will be the four character PDB id. */ + private String structureId; /** The title. */ private String title; @@ -616,21 +616,21 @@ public final void setTitle(final String inputTitle) { } /** - * Gets the pdb id. + * Gets the structure id. Should be used as a unique identifier of this structure. * - * @return the pdb id + * @return the the structure id a unique String id of this structure. */ - public final String getPdbId() { - return pdbId; + public final String getStructureId() { + return structureId; } /** - * Sets the pdb id. + * Sets the structure id. Should be used as a unique identifier of this structure. * - * @param pdbCode the new pdb id + * @param inputId a unique String id of this structure. */ - public final void setPdbId(final String pdbCode) { - this.pdbId = pdbCode; + public final void setStructureId(final String inputId) { + this.structureId = inputId; } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index b86c9f5..6751bee 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -75,7 +75,7 @@ public SimpleDataApi(byte[] inputByteArr) { mmtfVersion = inputData.getMmtfVersion(); mmtfProducer = inputData.getMmtfProducer(); entityList = inputData.getEntityList(); - pdbId = inputData.getPdbId(); + pdbId = inputData.getStructureId(); // Now get the header data rFree = inputData.getrFree(); // Optional fields diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index 7295175..a06a974 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -125,7 +125,7 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th NoFloatDataStructBean bioBean = (NoFloatDataStructBean) strucureData.findDataAsBean(); // Copt these things thisDistBeanTot.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); - thisDistBeanTot.setPdbId(bioBean.getPdbCode()); + thisDistBeanTot.setStructureId(bioBean.getPdbCode()); thisDistBeanTot.setInsCodeList(bioBean.get_atom_site_pdbx_PDB_ins_code()); thisDistBeanTot.setAltLabelList(bioBean.get_atom_site_label_alt_id()); // Set this experimental data From ad1d951f1fc8e781868ef9f72700b3f2698fca3c Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 4 Apr 2016 17:22:05 -0700 Subject: [PATCH 011/108] Renamed seqResIdList field to sequenceIdList --- .../java/org/rcsb/mmtf/dataholders/MmtfBean.java | 12 ++++++------ .../java/org/rcsb/mmtf/decoder/SimpleDataApi.java | 2 +- .../org/rcsb/mmtf/biojavaencoder/EncoderUtils.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 115ef71..ad73f2e 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -121,7 +121,7 @@ public class MmtfBean implements Serializable { private byte[] atomIdList; /** The SeqRes group ids. */ - private byte[] seqResIdList; + private byte[] sequenceIdList; /** The experimental method(s). */ private List experimentalMethods; @@ -794,17 +794,17 @@ public void setExperimentalMethods(List experimentalMethods) { } /** - * @return the seqResGroupIds + * @return the seqResGroupIds */ - public byte[] getSeqResIdList() { - return seqResIdList; + public byte[] getSequenceIdList() { + return sequenceIdList; } /** * @param seqResGroupIds the seqResGroupIds to set */ - public void setSeqResIdList(byte[] seqResGroupIds) { - this.seqResIdList = seqResGroupIds; + public void setSequenceIdList(byte[] seqResGroupIds) { + this.sequenceIdList = seqResGroupIds; } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 6751bee..bd17af3 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -60,7 +60,7 @@ public SimpleDataApi(byte[] inputByteArr) { inputData.getGroupIdList()); groupMap = inputData.getGroupList(); // Get the seqRes groups - seqResGroupList = intRunLengthDelta.decompressByteArray(inputData.getSeqResIdList()); + seqResGroupList = intRunLengthDelta.decompressByteArray(inputData.getSequenceIdList()); // Get the number of chains per model chainsPerModel = inputData.getChainsPerModel(); groupsPerChain = inputData.getGroupsPerChain(); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index a06a974..c8963a9 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -139,7 +139,7 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th // Get thisDistBeanTot.setEntityList(inHeader.getEntityList()); // Get the seqres information - thisDistBeanTot.setSeqResIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) inHeader.getSeqResGroupIds())))); + thisDistBeanTot.setSequenceIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) inHeader.getSeqResGroupIds())))); thisDistBeanTot.setExperimentalMethods(inHeader.getExperimentalMethods()); // Now get this list thisDistBeanTot.setBondAtomList(cm.integersToBytes(inStruct.getInterGroupBondInds())); From 2a8abe9b59a33a388b684f027c1e75309e4a991a Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 4 Apr 2016 17:45:14 -0700 Subject: [PATCH 012/108] Rename occList field to occupancyList --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 18 +++++++++--------- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 2 +- .../rcsb/mmtf/biojavaencoder/EncoderUtils.java | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index ad73f2e..64f6c3a 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -103,7 +103,7 @@ public class MmtfBean implements Serializable { private byte[] secStructList; /** The occupancy list. */ - private byte[] occList; + private byte[] occupancyList; /** The alt label list. */ private List altLabelList; @@ -490,21 +490,21 @@ public final void setNumAtoms(final int inputNumAtoms) { } /** - * Gets the occ list. + * Gets the occupancy list - an encoded per atom list of occupancy values. * - * @return the occ list + * @return the occupancy list - an encoded per atom list of occupancy values. */ - public final byte[] getOccList() { - return occList; + public final byte[] getOccupancyList() { + return occupancyList; } /** - * Sets the occ list. + * Sets the occupancy list - an encoded per atom list of occupancy values. * - * @param occupancy the new occ list + * @param inputOccupancyList the occupancy list - an encoded per atom list of occupancy values. */ - public final void setOccList(final byte[] occupancy) { - this.occList = occupancy; + public final void setOccupancyList(final byte[] inputOccupancyList) { + this.occupancyList = inputOccupancyList; } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index bd17af3..d2f0eb9 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -48,7 +48,7 @@ public SimpleDataApi(byte[] inputByteArr) { cartnY = decoderUtils.decodeIntsToFloats(deltaDecompress.decompressByteArray(inputData.getyCoordBig(), inputData.getyCoordSmall()), MmtfBean.COORD_DIVIDER); cartnZ = decoderUtils.decodeIntsToFloats(deltaDecompress.decompressByteArray(inputData.getzCoordBig(), inputData.getzCoordSmall()), MmtfBean.COORD_DIVIDER); bFactor = decoderUtils.decodeIntsToFloats(deltaDecompress.decompressByteArray(inputData.getbFactorBig(),inputData.getbFactorSmall()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); - occupancy = decoderUtils.decodeIntsToFloats(intRunLength.decompressByteArray(inputData.getOccList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); + occupancy = decoderUtils.decodeIntsToFloats(intRunLength.decompressByteArray(inputData.getOccupancyList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); atomId = intRunLengthDelta.decompressByteArray(inputData.getAtomIdList()); altId = stringRunlength.stringArrayToChar( (ArrayList) inputData.getAltLabelList()); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index c8963a9..83994da 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -210,7 +210,7 @@ private void addByteArrs(MmtfBean thisDistBeanTot, NoFloatDataStructBean bioBean thisDistBeanTot.setbFactorBig(retArr.get(0)); thisDistBeanTot.setbFactorSmall(retArr.get(1)); // Now the occupancy - thisDistBeanTot.setOccList(cm.integersToBytes(bioBean.get_atom_site_occupancyInt())); + thisDistBeanTot.setOccupancyList(cm.integersToBytes(bioBean.get_atom_site_occupancyInt())); // System.out.println(Collections.max(bioBean.getResOrder())); thisDistBeanTot.setGroupTypeList((cm.integersToBytes(bioBean.getResOrder()))); thisDistBeanTot.setAtomIdList(cm.integersToBytes(bioBean.get_atom_site_id())); From a250522ac43f30c6ff18cc1f7b1fef4388030dc3 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 10:29:04 -0700 Subject: [PATCH 013/108] no "?" to indicate an empty/unknown value in altLabelList, insCodeList We now use " " --- .../src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java | 5 +++++ .../rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java | 4 +++- .../src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java | 6 ++---- .../java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java | 5 +++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 64f6c3a..39a7b56 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -22,6 +22,11 @@ public class MmtfBean implements Serializable { */ public static final float UNAVAILABLE_R_VALUE = 1.0f; public static final float UNAVAILABLE_RESOLUTION_VALUE = 99.0f; + /** + * The default value for a missing or null string field + */ + public static final String UNAVAILABLE_STRING_VALUE = " "; + /** Serial id for this version of the format. */ diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java index 8f2131b..379e19b 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import org.rcsb.mmtf.dataholders.MmtfBean; + /** * Decode string arrays that have been run length encoded. * The input values are in pairs. The first value in each pair @@ -28,7 +30,7 @@ public final char[] stringArrayToChar(final ArrayList inputArray) { // If it's only one long - just take the char if (inputArray.size() == 1) { char[] outArray = new char[1]; - if (inputArray.get(0) == null) { + if (inputArray.get(0) == MmtfBean.UNAVAILABLE_STRING_VALUE) { outChar = "?".charAt(0); } else { String outString = inputArray.get(0); diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index d2f0eb9..de653ca 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -50,11 +50,9 @@ public SimpleDataApi(byte[] inputByteArr) { bFactor = decoderUtils.decodeIntsToFloats(deltaDecompress.decompressByteArray(inputData.getbFactorBig(),inputData.getbFactorSmall()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); occupancy = decoderUtils.decodeIntsToFloats(intRunLength.decompressByteArray(inputData.getOccupancyList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); atomId = intRunLengthDelta.decompressByteArray(inputData.getAtomIdList()); - altId = stringRunlength.stringArrayToChar( - (ArrayList) inputData.getAltLabelList()); + altId = stringRunlength.stringArrayToChar((ArrayList) inputData.getAltLabelList()); // Get the insertion code - insertionCodeList = stringRunlength.stringArrayToChar( - (ArrayList) inputData.getInsCodeList()); + insertionCodeList = stringRunlength.stringArrayToChar((ArrayList) inputData.getInsCodeList()); // Get the groupNumber groupNum = intRunLengthDelta.decompressByteArray( inputData.getGroupIdList()); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java index 030f957..11eb647 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java @@ -40,6 +40,7 @@ import org.rcsb.mmtf.dataholders.CodeHolders; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.HeaderBean; +import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; @@ -337,7 +338,7 @@ public void generateDataStructuresFromBioJavaStructure(Structure bioJavaStruct, // bioStruct data item corresponds to the PDB insertion code. Character insertionCode = residueNum.getInsCode(); if (insertionCode==null){ - bioStruct.get_atom_site_pdbx_PDB_ins_code().add(null); + bioStruct.get_atom_site_pdbx_PDB_ins_code().add(MmtfBean.UNAVAILABLE_STRING_VALUE); } else{ bioStruct.get_atom_site_pdbx_PDB_ins_code().add(insertionCode.toString()); @@ -934,7 +935,7 @@ private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidu // bioStruct item is a uniquely identifies for each alternative site for // bioStruct atom position. if (inputAtom.getAltLoc()==" ".charAt(0)){ - bioStruct.get_atom_site_label_alt_id().add("?"); + bioStruct.get_atom_site_label_alt_id().add(MmtfBean.UNAVAILABLE_STRING_VALUE); } else{ bioStruct.get_atom_site_label_alt_id().add(inputAtom.getAltLoc().toString()); From 09da648a6d566dad19c1570e8d3cc4990a79b0c4 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 11:38:26 -0700 Subject: [PATCH 014/108] Updates to the alt label and ins code lists. They are both now int[] not List. First element is the ASCII id for the character. Second elemnet is the number of elements to be repeated. --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 27 ++++++------- .../arraydecompressors/DeltaDeCompress.java | 2 +- .../RunLengthDecodeString.java | 39 ++++++++----------- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 4 +- .../mmtf/biojavaencoder/EncoderUtils.java | 31 ++++++++++++++- .../mmtf/biojavaencoder/ParseFromBiojava.java | 5 +-- .../mmtf/update/IntegrationTestUtils.java | 4 +- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 39a7b56..cb90324 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -13,20 +13,17 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class MmtfBean implements Serializable { + /** The number to divide coordinate int values by. */ public static final float COORD_DIVIDER = 1000.0f; /** The number to divide occupancy and bfactor int values by. */ public static final float OCCUPANCY_BFACTOR_DIVIDER = 100.0f; - /** - * The default value for Rfree, Rwork and resolution when not available or not applicable - */ + /** The default value for Rfree and Rwork */ public static final float UNAVAILABLE_R_VALUE = 1.0f; + /** The default value for resolution when not available or not applicable */ public static final float UNAVAILABLE_RESOLUTION_VALUE = 99.0f; - /** - * The default value for a missing or null string field - */ - public static final String UNAVAILABLE_STRING_VALUE = " "; - + /** The default value for a missing or null string field */ + public static final char UNAVAILABLE_CHAR_VALUE = '\0'; /** Serial id for this version of the format. */ @@ -78,7 +75,7 @@ public class MmtfBean implements Serializable { private byte[] bondOrderList; /** The list of different PDBGroups in the structure. */ - private PDBGroup[] groupList; + private PDBGroup[] groupList; /** The x coord big. 4 byte integers in pairs. */ private byte[] xCoordBig; @@ -111,10 +108,10 @@ public class MmtfBean implements Serializable { private byte[] occupancyList; /** The alt label list. */ - private List altLabelList; + private int[] altLabelList; /** The insertion code list. */ - private List insCodeList; + private int[] insCodeList; /** The group type list. */ private byte[] groupTypeList; @@ -427,7 +424,7 @@ public final void setbFactorSmall(final byte[] inputSmallBFactor) { * * @return the alt label list */ - public final List getAltLabelList() { + public final int[] getAltLabelList() { return altLabelList; } @@ -436,7 +433,7 @@ public final List getAltLabelList() { * * @param inputAltIdList the new alt id label list */ - public final void setAltLabelList(final List inputAltIdList) { + public final void setAltLabelList(final int[] inputAltIdList) { this.altLabelList = inputAltIdList; } @@ -517,7 +514,7 @@ public final void setOccupancyList(final byte[] inputOccupancyList) { * * @return the insertion code list */ - public final List getInsCodeList() { + public final int[] getInsCodeList() { return insCodeList; } @@ -526,7 +523,7 @@ public final List getInsCodeList() { * * @param inputInsertionCodeList the new insertion code list */ - public final void setInsCodeList(final List inputInsertionCodeList) { + public final void setInsCodeList(final int[] inputInsertionCodeList) { this.insCodeList = inputInsertionCodeList; } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java index 69e357c..0eec729 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java @@ -44,7 +44,7 @@ public final int[] decompressByteArray(final byte[] fourByteInts, for (int i = 0; i < lengthOfBigIntArray; i++) { int bigNum = bigStream.readInt(); int counterNum = bigStream.readInt(); - // Now writ thei sout + // Now write this out totNum++; // Now add to the counter totNum += counterNum; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java index 379e19b..c29387f 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java @@ -17,46 +17,41 @@ public class RunLengthDecodeString implements StringArrayDeCompressorInterface { /** - * Runlength decode a string list and return as a char[]. - * @param inputArray An input string array. - * @return a char array of the strings - * rather than a string array. + * Runlength decode an int[] and return as a char[]. + * @param inputIntArray An input array of integers. + * @return a char array of values runlength decoded. */ - public final char[] stringArrayToChar(final ArrayList inputArray) { + public final char[] intArrayToCharArray(final int[] inputIntArray) { int totNum = 0; - // Define an array to hold chars - char[] outChars = new char[1]; - char outChar = "l".charAt(0); + // Define a default Char value + char outChar = MmtfBean.UNAVAILABLE_CHAR_VALUE; // If it's only one long - just take the char - if (inputArray.size() == 1) { + if (inputIntArray.length == 1) { char[] outArray = new char[1]; - if (inputArray.get(0) == MmtfBean.UNAVAILABLE_STRING_VALUE) { - outChar = "?".charAt(0); + if (Character.toChars(inputIntArray[0])[0] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { + outChar = '?'; } else { - String outString = inputArray.get(0); - outString.getChars(0, 1, outChars, 0); - outChar = outChars[0]; + outChar = Character.toChars(inputIntArray[0])[0]; } outArray[0] = outChar; return outArray; } - for (int i = 0; i < inputArray.size(); i += 2) { - totNum += Integer.parseInt(inputArray.get(i + 1)); + for (int i = 0; i < inputIntArray.length; i += 2) { + totNum += inputIntArray[i + 1]; } char[] outArray = new char[totNum]; int totCounter = 0; - for (int i = 0; i < inputArray.size(); i += 2) { - if (inputArray.get(i) == null) { + for (int i = 0; i < inputIntArray.length; i += 2) { + if (inputIntArray[i] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { outChar = "?".charAt(0); } else { - String outString = inputArray.get(i); - outString.getChars(0, 1, outChars, 0); - outChar = outChars[0]; + // Otherwise get this char + outChar = Character.toChars(inputIntArray[i])[0]; } - int numString = Integer.parseInt(inputArray.get(i + 1)); + int numString = inputIntArray[i + 1]; for (int j = 0; j < numString; j++) { outArray[totCounter] = outChar; totCounter++; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index de653ca..76c71bb 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -50,9 +50,9 @@ public SimpleDataApi(byte[] inputByteArr) { bFactor = decoderUtils.decodeIntsToFloats(deltaDecompress.decompressByteArray(inputData.getbFactorBig(),inputData.getbFactorSmall()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); occupancy = decoderUtils.decodeIntsToFloats(intRunLength.decompressByteArray(inputData.getOccupancyList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); atomId = intRunLengthDelta.decompressByteArray(inputData.getAtomIdList()); - altId = stringRunlength.stringArrayToChar((ArrayList) inputData.getAltLabelList()); + altId = stringRunlength.intArrayToCharArray(inputData.getAltLabelList()); // Get the insertion code - insertionCodeList = stringRunlength.stringArrayToChar((ArrayList) inputData.getInsCodeList()); + insertionCodeList = stringRunlength.intArrayToCharArray(inputData.getInsCodeList()); // Get the groupNumber groupNum = intRunLengthDelta.decompressByteArray( inputData.getGroupIdList()); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index 83994da..385a471 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -126,8 +126,8 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th // Copt these things thisDistBeanTot.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); thisDistBeanTot.setStructureId(bioBean.getPdbCode()); - thisDistBeanTot.setInsCodeList(bioBean.get_atom_site_pdbx_PDB_ins_code()); - thisDistBeanTot.setAltLabelList(bioBean.get_atom_site_label_alt_id()); + thisDistBeanTot.setInsCodeList(convertToIntArr(bioBean.get_atom_site_pdbx_PDB_ins_code())); + thisDistBeanTot.setAltLabelList(convertToIntArr(bioBean.get_atom_site_label_alt_id())); // Set this experimental data thisDistBeanTot.setResolution(inHeader.getResolution()); thisDistBeanTot.setrFree(inHeader.getrFree()); @@ -161,6 +161,33 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th thisDistBeanTot.setMmtfProducer("RCSB-PDB Generator---version: "+grs.getCurrentVersion()); return thisDistBeanTot; } + + /** + * Convert a String list to an int[]. + * @param inputStringArray + * @return An integer array. + */ + private int[] convertToIntArr(List inputStringArray) { + // The output integer array + int[] outArray = new int[inputStringArray.size()]; + // Now loop through the array first value is char. + for (int i=0; i Date: Tue, 5 Apr 2016 13:22:43 -0700 Subject: [PATCH 015/108] Dssp type is now encoded as an Enum. --- .../rcsb/mmtf/dataholders/CodeHolders.java | 85 ---------------- .../org/rcsb/mmtf/dataholders/DsspType.java | 97 +++++++++++++++++++ .../mmtf/biojavaencoder/ParseFromBiojava.java | 14 +-- 3 files changed, 102 insertions(+), 94 deletions(-) delete mode 100644 mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/CodeHolders.java create mode 100644 mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/CodeHolders.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/CodeHolders.java deleted file mode 100644 index 8b02f6b..0000000 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/CodeHolders.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * The encoding of secondary structure types. - * @author Anthony Bradley - * - */ -public class CodeHolders implements Serializable { - - /** Serial id for this version of the format. */ - private static final long serialVersionUID = 8214511379505123391L; - - /** The Constant PI_HELIX_IND. */ - private static final int PI_HELIX_IND = 0; - - /** The Constant BEND_IND. */ - private static final int BEND_IND = 1; - - /** The Constant ALPHA_HELIX_IND. */ - private static final int ALPHA_HELIX_IND = 2; - - /** The Constant EXTENDED_IND. */ - private static final int EXTENDED_IND = 3; - - /** The Constant HELIX_3_10_IND. */ - private static final int HELIX_3_10_IND = 4; - - /** The Constant BRIDGE_IND. */ - private static final int BRIDGE_IND = 5; - - /** The Constant TURN_IND. */ - private static final int TURN_IND = 6; - - /** The Constant COIL_IND. */ - private static final int COIL_IND = 7; - - /** The Constant NULL_ENTRY_IND. */ - private static final int NULL_ENTRY_IND = -1; - - - /** - * A map to store secondary structure to integer mappings. - */ - private Map dsspMap; - - /** - * Constructor initialises the map. - */ - public CodeHolders() { - Map aMap = new HashMap(); - aMap.put("pi Helix", PI_HELIX_IND); - aMap.put("Bend", BEND_IND); - aMap.put("alpha Helix", ALPHA_HELIX_IND); - aMap.put("Extended", EXTENDED_IND); - aMap.put("3-10 Helix", HELIX_3_10_IND); - aMap.put("Bridge", BRIDGE_IND); - aMap.put("Turn", TURN_IND); - aMap.put("Coil", COIL_IND); - aMap.put("NA", NULL_ENTRY_IND); - setDsspMap(Collections.unmodifiableMap(aMap)); - } - - /** - * Gets the dssp map. - * - * @return the dsspMap - */ - public final Map getDsspMap() { - return dsspMap; - } - - /** - * Sets the dssp map. - * - * @param inputDsspMap the dsspMap to set - */ - public final void setDsspMap(final Map inputDsspMap) { - this.dsspMap = inputDsspMap; - } -} diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java new file mode 100644 index 0000000..e7a4025 --- /dev/null +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java @@ -0,0 +1,97 @@ +package org.rcsb.mmtf.dataholders; + + +/** + * The encoding of secondary structure types. + * @author Anthony Bradley + * + */ +public enum DsspType { + + PI_HELIX("pi Helix",0), + BEND("Bend",1), + ALPHA_HELIX("alpha Helix",2), + EXTENDED("Extended",3), + HELIX_3_10("3-10 Helix",4), + BRIDGE("Bridge",5), + TURN("Turn",6), + COIL("Coil",7), + NULL_ENTRY("NA",-1); + + /** The String type of the DSSP*/ + private String dsspType; + /** The index used for encoding secondary structure + * information. One for each type*/ + private int dsspIndex; + + /** + * Constructor (private) of DSSP type + * @param inputDsspType The string type of the DSSP input. + * @param inputDsspIndex The integer index of hte DSSP input. + */ + private DsspType(String inputDsspType, int inputDsspIndex) { + + this.setDsspType(inputDsspType); + this.setDsspIndex(inputDsspIndex); + + } + + /** + * Sets the DSSP index given a particular input value. + * @param inputDsspIndex The input index (as specified above). + */ + private void setDsspIndex(int inputDsspIndex) { + this.dsspIndex = inputDsspIndex; + } + + /** Returns the type of the DSSP as a String + * + * @return String representation of the DSSP type. + */ + public String getDsspType() { + return dsspType; + } + + + /** Returns the index of the Dssp as an integer + * + * @return String representation of the Dssp type. + */ + public int getDsspIndex() { + return dsspIndex; + } + + /** + * Sets the DSSP type using an input String. + * @param inputDsspType The input string used to define the DSSP type. + */ + private void setDsspType(String inputDsspType) { + this.dsspType = inputDsspType; + } + + /** Creates a new DsspType from a String value. + * Returns DsspType.NULL_ENTRY if dsspType is "NA" or not one of the supported + * standard types. + * + * @param dsspType String value , should be one of "pi Helix","Bend","alpha Helix","Extended", + * "3-10 Helix","Bridge","Turn","Coil","NA" + * @return an DsspType object + */ + public static DsspType dsspTypeFromString(String dsspType) + { + + if ( dsspType == null) + return null; + + for(DsspType et : DsspType.values()) + { + if(dsspType.equals(et.dsspType)) + { + return et; + } + } + // Return a null entry. + return DsspType.NULL_ENTRY; + } + +} \ No newline at end of file diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java index 03642af..97d1630 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java @@ -37,7 +37,7 @@ import org.rcsb.mmtf.dataholders.BioDataStruct; import org.rcsb.mmtf.dataholders.BioAssemblyTrans; import org.rcsb.mmtf.dataholders.CalphaBean; -import org.rcsb.mmtf.dataholders.CodeHolders; +import org.rcsb.mmtf.dataholders.DsspType; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.HeaderBean; import org.rcsb.mmtf.dataholders.PDBGroup; @@ -62,9 +62,6 @@ public class ParseFromBiojava { /** The header struct. */ private HeaderBean headerStruct = new HeaderBean(); - /** The code holder. */ - private CodeHolders codeHolder = new CodeHolders(); - /** The bonds for the structure. Used to keep track of which bonds have already been considered */ private List totBonds = new ArrayList(); @@ -347,10 +344,10 @@ public void generateDataStructuresFromBioJavaStructure(Structure bioJavaStruct, // Only assign secondary structure for the first model if(i==0){ if(props==null){ - bioStruct.getSecStruct().add(codeHolder.getDsspMap().get("NA")); + bioStruct.getSecStruct().add(DsspType.dsspTypeFromString("NA").getDsspIndex()); } else{ - bioStruct.getSecStruct().add(codeHolder.getDsspMap().get(props.getType().name)); + bioStruct.getSecStruct().add(DsspType.dsspTypeFromString(props.getType().name).getDsspIndex()); } } // Now add the residue sequnece number @@ -656,11 +653,10 @@ private void addCalpha(Atom a, SecStrucState props, ResidueNumber residueNumber) // Now set the sec structure // if(props==null){ - calphaStruct.getSecStruct().add(codeHolder.getDsspMap().get("NA")); - + calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString("NA").getDsspIndex()); } else{ - calphaStruct.getSecStruct().add(codeHolder.getDsspMap().get(props.getType().name)); + calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString(props.getType().name).getDsspIndex()); } } From b8c1d151f1658fd307bbfbdf048f244e105a60f1 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 13:36:29 -0700 Subject: [PATCH 016/108] Refactored the array decompressor lib to get rid of redundant code --- .../IntArrayDeCompressorInterface.java | 18 ---------- .../RunLengthDecodeInt.java | 19 +---------- .../RunLengthDecodeString.java | 21 +----------- .../StringArrayDeCompressorInterface.java | 20 ----------- .../TestArrayDecompressor.java | 34 ++----------------- 5 files changed, 5 insertions(+), 107 deletions(-) delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/IntArrayDeCompressorInterface.java delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/StringArrayDeCompressorInterface.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/IntArrayDeCompressorInterface.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/IntArrayDeCompressorInterface.java deleted file mode 100644 index f90435b..0000000 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/IntArrayDeCompressorInterface.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.rcsb.mmtf.arraydecompressors; - -import java.util.List; - -/** - * Specify the functions in an decompressort of integer arrays. - * @author Anthony Bradley - * - */ -public interface IntArrayDeCompressorInterface { - - /** - * Decompress an integer array and return an other integer array. - * @param inArray An input list of integers. - * @return A list of Integers. - */ - List decompressIntArray(List inArray); -} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java index 144735c..0b9c50e 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java @@ -11,7 +11,7 @@ * @author Anthony Bradley * */ -public class RunLengthDecodeInt implements IntArrayDeCompressorInterface { +public class RunLengthDecodeInt { /** * The number of bytes in a four byte integers. @@ -61,21 +61,4 @@ public final int[] decompressByteArray(final byte[] inArray) return outArr; } - @Override - public final List decompressIntArray(final List inArray) { - // Make the output array - List outArray = new ArrayList(); - // Loop through the vals - for (int i = 0; i < inArray.size(); i += 2) { - // Get the value out here - int intIn = inArray.get(i); - int numOfInt = inArray.get(i + 1); - // Now add these to the array - for (int j = 0; j < numOfInt; j++) { - outArray.add(intIn); - } - } - return outArray; - } - } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java index c29387f..fac3e86 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java @@ -1,8 +1,5 @@ package org.rcsb.mmtf.arraydecompressors; -import java.util.ArrayList; -import java.util.List; - import org.rcsb.mmtf.dataholders.MmtfBean; /** @@ -13,7 +10,7 @@ * @author Anthony Bradley * */ -public class RunLengthDecodeString implements StringArrayDeCompressorInterface { +public class RunLengthDecodeString { /** @@ -60,21 +57,5 @@ public final char[] intArrayToCharArray(final int[] inputIntArray) { return outArray; } - @Override - public final List deCompressStringArray(final List inArray) { - // Make the output array - List outArray = new ArrayList(); - for (int i = 0; i < inArray.size(); i += 2) { - String outString = inArray.get(i); - int numString = Integer.parseInt(inArray.get(i + 1)); - - for (int j = 0; j < numString; j++) { - outArray.add(outString); - } - } - return outArray; - } - - } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/StringArrayDeCompressorInterface.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/StringArrayDeCompressorInterface.java deleted file mode 100644 index 56c4ef4..0000000 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/StringArrayDeCompressorInterface.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.rcsb.mmtf.arraydecompressors; - -import java.util.List; - -/** - * Generic functions to decompress a list of Strings to another list of Strings. - * @author Anthony Bradley - * - */ -public interface StringArrayDeCompressorInterface { - - /** - * Generic function to decompress a list of Strings to another - * list of Strings. - * @param inArray An input list of strings - * @return A list of strings - */ - List deCompressStringArray(List inArray); - -} diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java index b1927f8..bd695b5 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java @@ -41,43 +41,15 @@ public class TestArrayDecompressor { */ @Test public final void runLengthDecodeIntTest() { - - RunLengthDecodeInt rlds = new RunLengthDecodeInt(); - // Set the size and character - - // Build the test array - ArrayList testArray = new ArrayList(); - for (int i = 0; i < NUMBER_INTS; i++) { - testArray.add(REPEITITONS); - } - // Add the lists - ArrayList otherArray = new ArrayList(); - otherArray.add(REPEITITONS); - otherArray.add(NUMBER_INTS); - // Check theyr'e the same - assertEquals(testArray, rlds.decompressIntArray(otherArray)); + // TODO WRITE TEST THAT TESTS THIS } /** - * Run lenght decode string test. + * Run length decode string test. */ @Test public final void runLenghtDecodeStringTest() { - - RunLengthDecodeString rlds = new RunLengthDecodeString(); - // Set the size and character - String charRep = "A"; - // Build the test array - ArrayList testArray = new ArrayList(); - for (int i = 0; i < NUMBER_CHARS; i++) { - testArray.add(charRep); - } - // Add the lists - ArrayList otherArray = new ArrayList(); - otherArray.add(charRep); - otherArray.add(Integer.toString(NUMBER_CHARS)); - // Check theyr'e the same - assertEquals(testArray, rlds.deCompressStringArray(otherArray)); + // TODO Write test for the new function } /** From fd07dd9baa10048d564c4487861d121e0204fc8f Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 13:55:49 -0700 Subject: [PATCH 017/108] Added improved tests to the decoder --- .../RunLengthDecodeInt.java | 2 -- .../TestArrayDecompressor.java | 31 ++++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java index 0b9c50e..515f5ee 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java @@ -3,8 +3,6 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; /** * Run length decode a list of integers. diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java index bd695b5..56176ba 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java @@ -4,14 +4,13 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.ArrayList; +import java.nio.ByteBuffer; import org.junit.Test; import org.rcsb.mmtf.arraydecompressors.DeltaDeCompress; import org.rcsb.mmtf.arraydecompressors.RunLengthDecodeInt; import org.rcsb.mmtf.arraydecompressors.RunLengthDecodeString; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertArrayEquals; /** @@ -21,27 +20,25 @@ */ public class TestArrayDecompressor { - - /** The Constant NUMBER_INTS. */ - private static final int NUMBER_INTS = 100; - - /** The Constant REPEITITONS. */ - private static final int REPEITITONS = 1000; - - /** The Constant NUMBER_CHARS. */ - private static final int NUMBER_CHARS = 100; - /** The Constant INITIAL_INT. */ private static final int INITIAL_INT = 3000; /** The Constant TOTAL_LENGTH. */ private static final int TOTAL_LENGTH = 100; + + /** * Run length decode int test. + * @throws IOException */ @Test - public final void runLengthDecodeIntTest() { - // TODO WRITE TEST THAT TESTS THIS + public final void runLengthDecodeIntTest() throws IOException { + // Allocate the byte array + byte[] inputData = ByteBuffer.allocate(48).putInt(15).putInt(3).putInt(100).putInt(2).putInt(111).putInt(4).array(); + int[] outPutDataTest = {15,15,15,100,100,111,111,111,111}; + RunLengthDecodeInt runLengthDecodeInt = new RunLengthDecodeInt(); + int[] outPutData = runLengthDecodeInt.decompressByteArray(inputData); + assertArrayEquals(outPutDataTest, outPutData); } /** @@ -49,7 +46,11 @@ public final void runLengthDecodeIntTest() { */ @Test public final void runLenghtDecodeStringTest() { - // TODO Write test for the new function + int[] inputData = {66,4,63,2,67,1}; + char[] outPutDataTest = {'B','B','B','B','?','?','C'}; + RunLengthDecodeString runLengthDecodeString = new RunLengthDecodeString(); + char[] outPutData = runLengthDecodeString.intArrayToCharArray(inputData); + assertArrayEquals(outPutDataTest, outPutData); } /** From 88af555c2c5d269a086ce558ee5c917d9f4c31d2 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 14:14:10 -0700 Subject: [PATCH 018/108] Remove unneeded ArrayList references --- .../mmtf/arraycompressors/FindDeltas.java | 5 ++-- .../arraycompressors/IntArrayCompressor.java | 4 +-- .../arraycompressors/RunLengthEncode.java | 5 ++-- .../RunLengthEncodeString.java | 5 ++-- .../StringArrayCompressor.java | 4 +-- .../mmtf/biojavaencoder/EncoderUtils.java | 26 +++++++++---------- .../TestArrayCompressors.java | 11 ++++---- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java index fe9ab08..5be2657 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java @@ -2,6 +2,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.List; /** * Class to encode an integer array with deltas. @@ -18,9 +19,9 @@ public class FindDeltas implements IntArrayCompressor, Serializable { * @see org.rcsb.mmtf.arraycompressors.IntArray * Compressor#compressIntArray(java.util.ArrayList) */ - public final ArrayList compressIntArray(final ArrayList inArray) { + public final List compressIntArray(final List inArray) { // - ArrayList outArray = new ArrayList(); + List outArray = new ArrayList(); int oldInt = 0; for (int i = 0; i < inArray.size(); i++) { // Get the value out here diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java index e3bd07e..cf3c851 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java @@ -1,6 +1,6 @@ package org.rcsb.mmtf.arraycompressors; -import java.util.ArrayList; +import java.util.List; /** @@ -14,5 +14,5 @@ public interface IntArrayCompressor { * @param inArray the in array * @return the array list */ - public ArrayList compressIntArray(ArrayList inArray); + public List compressIntArray(List inArray); } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java index 97d4a3b..3fbf5b7 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java @@ -2,6 +2,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.List; /** * Class to run length encode an integer array. @@ -17,9 +18,9 @@ public class RunLengthEncode implements IntArrayCompressor, Serializable { /* (non-Javadoc) * @see org.rcsb.mmtf.arraycompressors.IntArrayCompressor#compressIntArray(java.util.ArrayList) */ - public ArrayList compressIntArray(ArrayList inArray) { + public List compressIntArray(List inArray) { - ArrayList outArray = new ArrayList(); + List outArray = new ArrayList(); int oldVal = 0; boolean inSwitch = false; int counter = 0; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java index 5bc011a..9c68dcc 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java @@ -1,6 +1,7 @@ package org.rcsb.mmtf.arraycompressors; import java.util.ArrayList; +import java.util.List; /** * Class to run length encode a string array. @@ -13,8 +14,8 @@ public class RunLengthEncodeString implements StringArrayCompressor { /* (non-Javadoc) * @see org.rcsb.mmtf.arraycompressors.StringArrayCompressor#compressStringArray(java.util.ArrayList) */ - public ArrayList compressStringArray(ArrayList inArray) { - ArrayList outArray = new ArrayList(); + public List compressStringArray(List inArray) { + List outArray = new ArrayList(); String oldVal = ""; int counter = 0; // Loop through the vals diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java index 72e4923..d795ce1 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java @@ -1,6 +1,6 @@ package org.rcsb.mmtf.arraycompressors; -import java.util.ArrayList; +import java.util.List; /** * The Interface StringArrayCompressor. @@ -13,5 +13,5 @@ public interface StringArrayCompressor { * @param inArray the in array * @return the array list */ - ArrayList compressStringArray(ArrayList inArray); + List compressStringArray(List inArray); } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index 385a471..8bd9d8b 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -139,7 +139,7 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th // Get thisDistBeanTot.setEntityList(inHeader.getEntityList()); // Get the seqres information - thisDistBeanTot.setSequenceIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) inHeader.getSeqResGroupIds())))); + thisDistBeanTot.setSequenceIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(inHeader.getSeqResGroupIds())))); thisDistBeanTot.setExperimentalMethods(inHeader.getExperimentalMethods()); // Now get this list thisDistBeanTot.setBondAtomList(cm.integersToBytes(inStruct.getInterGroupBondInds())); @@ -342,27 +342,27 @@ public CoreSingleStructure compressHadoopStruct(BioDataStruct inputBioDataStruct outStruct = doublesToInts.compresStructure(inputBioDataStruct); // Get the input structure NoFloatDataStruct inStruct = (NoFloatDataStruct) outStruct; - ArrayList cartnX = (ArrayList) inStruct.get_atom_site_Cartn_xInt(); - ArrayList cartnY = (ArrayList) inStruct.get_atom_site_Cartn_yInt(); - ArrayList cartnZ = (ArrayList) inStruct.get_atom_site_Cartn_zInt(); + List cartnX = inStruct.get_atom_site_Cartn_xInt(); + List cartnY = inStruct.get_atom_site_Cartn_yInt(); + List cartnZ = inStruct.get_atom_site_Cartn_zInt(); // Get the number of models inStruct.set_atom_site_Cartn_xInt(deltaComp.compressIntArray(cartnX)); inStruct.set_atom_site_Cartn_yInt(deltaComp.compressIntArray(cartnY)); inStruct.set_atom_site_Cartn_zInt(deltaComp.compressIntArray(cartnZ)); // // Now the occupancy and BFACTOR -> VERY SMALL GAIN - inStruct.set_atom_site_B_iso_or_equivInt(deltaComp.compressIntArray((ArrayList) inStruct.get_atom_site_B_iso_or_equivInt())); + inStruct.set_atom_site_B_iso_or_equivInt(deltaComp.compressIntArray(inStruct.get_atom_site_B_iso_or_equivInt())); // SMALL GAIN - inStruct.set_atom_site_occupancyInt(runLengthComp.compressIntArray((ArrayList) inStruct.get_atom_site_occupancyInt())); + inStruct.set_atom_site_occupancyInt(runLengthComp.compressIntArray(inStruct.get_atom_site_occupancyInt())); // Now the sequential numbers - huge gain - new order of good compressors // Now runlength encode the residue order inStruct.setResOrder(inStruct.getResOrder()); // THESE ONES CAN BE RUN LENGTH ON DELTA // Check for negative counters - inStruct.set_atom_site_auth_seq_id(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) inStruct.get_atom_site_auth_seq_id()))); - inStruct.set_atom_site_label_entity_poly_seq_num(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) inStruct.get_atom_site_label_entity_poly_seq_num()))); - inStruct.set_atom_site_id(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) inStruct.get_atom_site_id()))); + inStruct.set_atom_site_auth_seq_id(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_auth_seq_id()))); + inStruct.set_atom_site_label_entity_poly_seq_num(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_label_entity_poly_seq_num()))); + inStruct.set_atom_site_id(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_id()))); //// NOW THE STRINGS - small gain StringArrayCompressor stringRunEncode = new RunLengthEncodeString(); inStruct.set_atom_site_label_alt_id(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_label_alt_id())); @@ -407,9 +407,9 @@ public CalphaDistBean compCAlpha(CalphaBean calphaStruct, HeaderBean inHeader) t calphaOut.setGroupMap(calphaStruct.getGroupMap()); calphaOut.setGroupTypeList(cm.integersToBytes(calphaStruct.getResOrder())); // Get the input structure - ArrayList cartnX = (ArrayList) calphaStruct.getCartn_x(); - ArrayList cartnY = (ArrayList) calphaStruct.getCartn_y(); - ArrayList cartnZ = (ArrayList) calphaStruct.getCartn_z(); + List cartnX = calphaStruct.getCartn_x(); + List cartnY = calphaStruct.getCartn_y(); + List cartnZ = calphaStruct.getCartn_z(); // Now add the X coords List bigAndLittleX = getBigAndLittle(deltaComp.compressIntArray(cartnX)); calphaOut.setxCoordBig(bigAndLittleX.get(0)); @@ -423,7 +423,7 @@ public CalphaDistBean compCAlpha(CalphaBean calphaStruct, HeaderBean inHeader) t calphaOut.setzCoordBig(bigAndLittleZ.get(0)); calphaOut.setzCoordSmall(bigAndLittleZ.get(1)); // THESE ONES CAN BE RUN LENGTH ON DELTA - calphaOut.setGroupIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray((ArrayList) calphaStruct.get_atom_site_auth_seq_id())))); + calphaOut.setGroupIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(calphaStruct.get_atom_site_auth_seq_id())))); return calphaOut; } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java index c6ff8e6..a7521dd 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java @@ -1,6 +1,7 @@ package org.rcsb.mmtf.arraycompressors; import java.util.ArrayList; +import java.util.List; import org.junit.Test; import org.rcsb.mmtf.arraycompressors.FindDeltas; @@ -28,7 +29,7 @@ public void deltaTest() { } } // Compress it - ArrayList deltadArray = fd.compressIntArray(inArray); + List deltadArray = fd.compressIntArray(inArray); // Now check assertEquals(deltadArray, testArray); @@ -39,8 +40,8 @@ public void runLengthTest() { // Generate the array RunLengthEncode rle = new RunLengthEncode(); // Create the two arrays - ArrayList inArray = new ArrayList(); - ArrayList testArray = new ArrayList(); + List inArray = new ArrayList(); + List testArray = new ArrayList(); int length = 1000; for(int i=0; i runlenghtdArray = rle.compressIntArray(inArray); + List runlenghtdArray = rle.compressIntArray(inArray); // Now check assertEquals(runlenghtdArray, testArray); } @@ -73,7 +74,7 @@ public void runLengthStringTest() { } testArray.add(Integer.toString(length)); // Compress it - ArrayList runlenghtdArray = rle.compressStringArray(inArray); + List runlenghtdArray = rle.compressStringArray(inArray); // Now check assertEquals(runlenghtdArray, testArray); } From 5caa76fb45b41636ab905877fac09182ae87455e Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 14:19:58 -0700 Subject: [PATCH 019/108] Some more cleanup --- .../java/org/rcsb/mmtf/decoder/DecoderUtils.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java index 975d9e6..447bb1e 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java @@ -23,28 +23,21 @@ public final String getChainId(final byte[] chainList, final int thisChain) { int incrementor = 0; StringBuilder sb = new StringBuilder(); - byte chainIdOne = chainList[thisChain - * - MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdOne = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; sb.append((char) chainIdOne); // Now get the next byte incrementor += 1; - byte chainIdTwo = chainList[thisChain - * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdTwo = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; if (chainIdTwo != (byte) 0) { sb.append((char) chainIdTwo); } incrementor += 1; - byte chainIdThree = chainList[thisChain - * - MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdThree = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; if (chainIdThree != (byte) 0) { sb.append((char) chainIdThree); } incrementor += 1; - byte chainIdFour = chainList[thisChain - * - MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdFour = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; if (chainIdFour != (byte) 0) { sb.append((char) chainIdFour); } From ce44086ff7ae542fd14cfd6ff975b3211152d8f5 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 14:42:53 -0700 Subject: [PATCH 020/108] Downstream changes from Biojava refactoring --- .../src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java | 4 ++-- .../java/org/rcsb/mmtf/postupdatetests/CheckServer.java | 6 ++---- .../src/main/java/org/rcsb/mmtf/update/TestingUtils.java | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index b280313..6ea1e67 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -9,7 +9,7 @@ import org.apache.spark.api.java.JavaSparkContext; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.io.mmtf.BioJavaStructureDecoder; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.EncoderUtils; import org.rcsb.mmtf.decoder.DecodeStructure; import org.rcsb.mmtf.decoder.ParsingParams; @@ -32,7 +32,7 @@ public class MapperUtils implements Serializable{ * @return */ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) { - BioJavaStructureDecoder bjs = new BioJavaStructureDecoder(); + MmtfStructureDecoder bjs = new MmtfStructureDecoder(); Structure newStruct; ParsingParams pp = new ParsingParams(); try{ diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index 056f6c1..a0284ae 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -8,7 +8,7 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.ParseUsingBioJava; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.EncoderUtils; import org.rcsb.mmtf.decoder.ParsingParams; import org.rcsb.mmtf.examples.HandleIO; @@ -19,7 +19,6 @@ public class CheckServer { private HandleIO handleIo; - private ParseUsingBioJava parseUsingBioJava; private FileParsingParameters params; private CheckOnBiojava checkEquiv; @@ -47,7 +46,6 @@ public static void main(String[] args) throws IOException { */ public void basicParsingTest(String baseUrl) throws IOException { // Get the class to parse and get data - parseUsingBioJava = new ParseUsingBioJava(); handleIo = new HandleIO(); checkEquiv = new CheckOnBiojava(); EncoderUtils encoderUtils = new EncoderUtils(); @@ -70,7 +68,7 @@ private void testParsing(String inputPdb, String inputUrl) throws IOException { byte[] inputByteArr = handleIo.getFromUrl(inputPdb, inputUrl); ParsingParams parsingParms = new ParsingParams(); parsingParms.setParseInternal(params.isUseInternalChainId()); - Structure mmtfStruct = parseUsingBioJava.getBiojavaStruct(inputByteArr, parsingParms); + Structure mmtfStruct = MmtfStructureDecoder.getBiojavaStruct(inputByteArr, parsingParms); // Now parse from the MMCIF file Structure mmcifStruct; try { diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index fe9ae79..3bb9f0c 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -10,7 +10,7 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.BioJavaStructureDecoder; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.EncodeStructure; import org.rcsb.mmtf.decoder.DecodeStructure; import org.rcsb.mmtf.decoder.ParsingParams; @@ -74,7 +74,7 @@ public Structure roundTripStruct(String pdbId, ParsingParams pp, FileParsingPara CheckOnRawApi checkRaw = new CheckOnRawApi(inArr); checkRaw.checkRawDataConsistency(mmcifStruct, params); // Now decode the data and return this new structure - BioJavaStructureDecoder bjsi = new BioJavaStructureDecoder(); + MmtfStructureDecoder bjsi = new MmtfStructureDecoder(); DecodeStructure decodeStructure = new DecodeStructure(inArr); decodeStructure.getStructFromByteArray(bjsi, pp); Structure struct = bjsi.getStructure(); From 08393fed53e01c1f55bf79f514ede2fefada5254 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 15:02:43 -0700 Subject: [PATCH 021/108] Turned the groupType map into an enum. Small refactoring in other modules --- .../org/rcsb/mmtf/dataholders/DsspType.java | 2 +- .../rcsb/mmtf/decoder/DecodeStructure.java | 8 +-- .../org/rcsb/mmtf/decoder/DecoderUtils.java | 4 +- .../arraycompressors/RunLengthEncode.java | 2 +- .../RunLengthEncodeString.java | 2 +- .../mmtf/biocompressors/CompressDoubles.java | 6 +- .../mmtf/biojavaencoder/EncodeStructure.java | 8 +-- .../mmtf/biojavaencoder/EncoderUtils.java | 28 ++++---- .../rcsb/mmtf/biojavaencoder/GroupType.java | 71 +++++++++++++++++++ .../mmtf/biojavaencoder/ParseFromBiojava.java | 20 ++---- 10 files changed, 106 insertions(+), 45 deletions(-) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java index e7a4025..340db39 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java @@ -81,7 +81,7 @@ public static DsspType dsspTypeFromString(String dsspType) { if ( dsspType == null) - return null; + return DsspType.NULL_ENTRY; for(DsspType et : DsspType.values()) { diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index dc90cf2..af53296 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -80,7 +80,7 @@ public final void getStructFromByteArray(final StructureDecoderInterface inputSt /** * Add the main atomic information to the data model */ - private void addAtomicInformation() { + private final void addAtomicInformation() { for (int modelChains: dataApi.getChainsPerModel()) { structInflator.setModelInfo(modelCounter, modelChains); // A list to check if we need to set or update the chains @@ -97,7 +97,7 @@ private void addAtomicInformation() { /** * Add the entity information to a structure. */ - private void addEntityInfo() { + private final void addEntityInfo() { for (int i=0; i compressIntArray(List inArray) { + public final List compressIntArray(List inArray) { List outArray = new ArrayList(); int oldVal = 0; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java index 9c68dcc..360426b 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java @@ -14,7 +14,7 @@ public class RunLengthEncodeString implements StringArrayCompressor { /* (non-Javadoc) * @see org.rcsb.mmtf.arraycompressors.StringArrayCompressor#compressStringArray(java.util.ArrayList) */ - public List compressStringArray(List inArray) { + public final List compressStringArray(List inArray) { List outArray = new ArrayList(); String oldVal = ""; int counter = 0; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java index c1afd96..43ebbe5 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java @@ -23,7 +23,7 @@ public class CompressDoubles implements BioCompressor, Serializable { /* (non-Javadoc) * @see org.rcsb.mmtf.biocompressors.BioCompressor#compresStructure(org.rcsb.mmtf.dataholders.CoreSingleStructure) */ - public CoreSingleStructure compresStructure(CoreSingleStructure coress) { + public final CoreSingleStructure compresStructure(CoreSingleStructure coress) { // Take in the appropriate arrays BioDataStruct bioDataS = (BioDataStruct) coress; NoFloatDataStruct noFloatDataS = new NoFloatDataStruct(); @@ -58,7 +58,7 @@ public CoreSingleStructure compresStructure(CoreSingleStructure coress) { * @param multiplier - the multiplication factor for conversion * @return the integer array after conversion */ - public List getIntArrayFromFloat(List inArray, float multiplier) { + public final List getIntArrayFromFloat(List inArray, float multiplier) { // Initialise the out array List outArray = new ArrayList(inArray.size()); for(Float oldDouble: inArray){ @@ -76,7 +76,7 @@ public List getIntArrayFromFloat(List inArray, float multiplier) * @param multiplier the multiplier * @return the int array from double */ - public List getIntArrayFromDouble(List inArray, Double multiplier){ + public final List getIntArrayFromDouble(List inArray, Double multiplier){ // Initialise the out array List outArray = new ArrayList(inArray.size()); for(Double oldDouble: inArray){ diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java index ec1a825..92b54b4 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java @@ -16,7 +16,7 @@ public class EncodeStructure { * @param pdbId * @return a byte array of compressed data */ - public byte[] getCompressedMessagePackFromPdbId(String pdbId) { + public final byte[] getCompressedMessagePackFromPdbId(String pdbId) { // Get the utility class to get the strucutes ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); Map totMap = new HashMap(); @@ -31,7 +31,7 @@ public byte[] getCompressedMessagePackFromPdbId(String pdbId) { * @param bioJavaStruct * @return a byte array of compressed data */ - public byte[] encodeFromBiojava(Structure bioJavaStruct){ + public final byte[] encodeFromBiojava(Structure bioJavaStruct){ // Get the utility class to get the strucutes ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); Map totMap = new HashMap(); @@ -45,7 +45,7 @@ public byte[] encodeFromBiojava(Structure bioJavaStruct){ * @param parsedDataStruct * @return a byte array of compressed data */ - private byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { + private final byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { EncoderUtils eu = new EncoderUtils(); // Compress the data and get it back out try { @@ -64,7 +64,7 @@ private byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { * @param pdbId The input pdb id * @return a byte array of compressed calpha data */ - public byte[] encodeBackBoneFromPdbId(String pdbId){ + public final byte[] encodeBackBoneFromPdbId(String pdbId){ // Get the two utility classes EncoderUtils eu = new EncoderUtils(); ParseFromBiojava cbs = new ParseFromBiojava(); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index 8bd9d8b..0430bcb 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -99,7 +99,7 @@ public byte[] integersToBytes(List inputList) throws IOException * @throws JsonProcessingException the json processing exception - most likely related * to serialization. */ - public byte[] getMessagePack(Object inputObject) throws JsonProcessingException{ + public final byte[] getMessagePack(Object inputObject) throws JsonProcessingException{ com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(new MessagePackFactory()); objectMapper.setSerializationInclusion(Include.NON_NULL); byte[] inBuf = objectMapper.writeValueAsBytes(inputObject); @@ -116,7 +116,7 @@ public byte[] getMessagePack(Object inputObject) throws JsonProcessingException{ * @throws IOException reading byte array * @throws Exception */ - public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) throws IOException { + public final MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) throws IOException { EncoderUtils cm = new EncoderUtils(); // Compress the protein CoreSingleStructure strucureData = compressHadoopStruct(inStruct); @@ -167,7 +167,7 @@ public MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) th * @param inputStringArray * @return An integer array. */ - private int[] convertToIntArr(List inputStringArray) { + private final int[] convertToIntArr(List inputStringArray) { // The output integer array int[] outArray = new int[inputStringArray.size()]; // Now loop through the array first value is char. @@ -194,7 +194,7 @@ private int[] convertToIntArr(List inputStringArray) { * @param inputDate The input date object * @return The time in ISO time format */ - private String convertToIsoTime(Date inputDate) { + private final String convertToIsoTime(Date inputDate) { DateFormat dateStringFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateStringFormat.format(inputDate); } @@ -205,7 +205,7 @@ private String convertToIsoTime(Date inputDate) { * @param groupMap The input map of Integer -> PDBGroup * @return A list of PDBGroups, where the previous keys are used as indices. */ - private PDBGroup[] genGroupList(Map groupMap) { + private final PDBGroup[] genGroupList(Map groupMap) { PDBGroup[] outGroupList = new PDBGroup[Collections.max(groupMap.keySet())+1]; for (int key : groupMap.keySet()) { outGroupList[key] = groupMap.get(key); @@ -221,7 +221,7 @@ private PDBGroup[] genGroupList(Map groupMap) { * @param bioBean the bio bean * @throws IOException Signals that an I/O exception has occurred. */ - private void addByteArrs(MmtfBean thisDistBeanTot, NoFloatDataStructBean bioBean) throws IOException { + private final void addByteArrs(MmtfBean thisDistBeanTot, NoFloatDataStructBean bioBean) throws IOException { EncoderUtils cm = new EncoderUtils(); // X,Y and Z and Bfactors - set these arrays List retArr = getBigAndLittle(bioBean.get_atom_site_Cartn_xInt()); @@ -256,7 +256,7 @@ private void addByteArrs(MmtfBean thisDistBeanTot, NoFloatDataStructBean bioBean * @return the byte[] * @throws IOException Signals that an I/O exception has occurred. */ - public byte[] integersToSmallBytes(List values) throws IOException { + public final byte[] integersToSmallBytes(List values) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for(int i: values) @@ -273,7 +273,7 @@ public byte[] integersToSmallBytes(List values) throws IOException { * @return the big and little * @throws IOException Signals that an I/O exception has occurred. */ - public List getBigAndLittle(List inArr) throws IOException{ + public final List getBigAndLittle(List inArr) throws IOException{ ListoutArr = new ArrayList(); int counter = 0; ByteArrayOutputStream littleOS = new ByteArrayOutputStream(); @@ -314,7 +314,7 @@ else if(Math.abs(inArr.get(i))>30000){ * @param inputArray the input array * @return the byte[] */ - public byte[] gzipCompress(byte[] inputArray){ + public final byte[] gzipCompress(byte[] inputArray){ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try{ GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream); @@ -336,7 +336,7 @@ public byte[] gzipCompress(byte[] inputArray){ * @throws InvocationTargetException * @throws Exception The bean data copying didn't work - weird. */ - public CoreSingleStructure compressHadoopStruct(BioDataStruct inputBioDataStruct) { + public final CoreSingleStructure compressHadoopStruct(BioDataStruct inputBioDataStruct) { CoreSingleStructure outStruct; outStruct = doublesToInts.compresStructure(inputBioDataStruct); @@ -379,7 +379,7 @@ public CoreSingleStructure compressHadoopStruct(BioDataStruct inputBioDataStruct * @return the calpha dist bean * @throws IOException Signals that an I/O exception has occurred. */ - public CalphaDistBean compCAlpha(CalphaBean calphaStruct, HeaderBean inHeader) throws IOException { + public final CalphaDistBean compCAlpha(CalphaBean calphaStruct, HeaderBean inHeader) throws IOException { EncoderUtils cm = new EncoderUtils(); // Create the object to leave CalphaDistBean calphaOut = new CalphaDistBean(); @@ -472,7 +472,7 @@ public AtomCache setUpBioJava(String extraUrl) { * This sets all microheterogeneous groups (previously alternate location groups) as separate groups. * @param bioJavaStruct */ - public void fixMicroheterogenity(Structure bioJavaStruct) { + public final void fixMicroheterogenity(Structure bioJavaStruct) { // Loop through the models for (int i=0; i getAllAtoms(Structure bioJavaStruct) { + public final List getAllAtoms(Structure bioJavaStruct) { // Get all the atoms List theseAtoms = new ArrayList(); for (int i=0; i getAllAtoms(Structure bioJavaStruct) { * @param inputGroup the Biojava Group to consider * @return the atoms for the input Biojava Group */ - public List getAtomsForGroup(Group inputGroup) { + public final List getAtomsForGroup(Group inputGroup) { Set uniqueAtoms = new HashSet(); List theseAtoms = new ArrayList(); for(Atom a: inputGroup.getAtoms()){ diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java new file mode 100644 index 0000000..fbc380d --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java @@ -0,0 +1,71 @@ +package org.rcsb.mmtf.biojavaencoder; + + +public enum GroupType { + + + HETATM("hetatm","HEATM"), + AMINO("amino","ATOM"), + NUCLEOTIDE("nucleotide","ATOM"); + + private String groupType; + private String groupName; + + + private GroupType(String inputGroupName, String inputGroupType) { + + this.setGroupName(inputGroupName); + this.setGroupType(inputGroupType); + + } + + + /** + * @return the groupType + */ + public String getGroupType() { + return groupType; + } + + + /** + * @param groupType the groupType to set + */ + public void setGroupType(String groupType) { + this.groupType = groupType; + } + + + /** + * @return the groupName + */ + public String getGroupName() { + return groupName; + } + + + /** + * @param groupName the groupName to set + */ + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public static GroupType groupTypeFromString(String groupType) + { + + if ( groupType == null) + return null; + + for(GroupType et : GroupType.values()) + { + if(groupType.equals(et.groupName)) + { + return et; + } + } + // Return a null entry. + return null; + } + +} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java index 97d1630..9d07690 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java @@ -83,16 +83,6 @@ public class ParseFromBiojava { /** The Biojava group currently being parsed. */ private Group currentGroup; - /** The Constant MY_MAP. Relates the group name to the type of atom id */ - private static final Map MY_MAP; - static { - Map aMap = new HashMap(); - aMap.put("hetatm", "HETATM"); - aMap.put("amino", "ATOM"); - aMap.put("nucleotide", "ATOM"); - MY_MAP = Collections.unmodifiableMap(aMap); - } - /** * Gets the bio struct. * @@ -160,7 +150,7 @@ public void setHeaderStruct(HeaderBean headerStruct) { * @param pdbId the pdb id * @param bioStructMap the bio struct map */ - public void createFromJavaStruct(String pdbId, Map bioStructMap) { + public final void createFromJavaStruct(String pdbId, Map bioStructMap) { // Get the structure from here Structure bioJavaStruct; try { @@ -185,7 +175,7 @@ public void createFromJavaStruct(String pdbId, Map bioStructM * @param bioStructMap the map relating hash codes to PDB groups. * input so that a consistent map can be held across several structures */ - public void generateDataStructuresFromBioJavaStructure(Structure bioJavaStruct, Map bioStructMap) { + public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaStruct, Map bioStructMap) { EncoderUtils encoderUtils = new EncoderUtils(); // Reset structure to consider altloc groups with the same residue number but different group names as seperate groups encoderUtils.fixMicroheterogenity(bioJavaStruct); @@ -385,7 +375,7 @@ public void generateDataStructuresFromBioJavaStructure(Structure bioJavaStruct, * Find and store the entity information in the header structure. * @param bioJavaStruct */ - private void findEntityInfo(Structure bioJavaStruct) { + private final void findEntityInfo(Structure bioJavaStruct) { List entities = bioJavaStruct.getEntityInfos(); // Get the list of chains for all the models List structChains = new ArrayList<>(); @@ -926,7 +916,7 @@ private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidu bioStruct.get_atom_site_symbol().add(ele.toString()); bioStruct.get_atom_site_asym_id().add(inputChainId); // identify coordinate records (e.g. ATOM or HETATM). - bioStruct.get_atom_site_group_PDB().add(MY_MAP.get(inputAtom.getGroup().getType().toString())); + bioStruct.get_atom_site_group_PDB().add(GroupType.groupTypeFromString(inputAtom.getGroup().getType().toString()).getGroupType()); // bioStruct item is a uniquely identifies for each alternative site for // bioStruct atom position. if (inputAtom.getAltLoc()==" ".charAt(0)){ @@ -956,7 +946,7 @@ private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidu // category. bioStruct item is used to identify chemically distinct // portions of the molecular structure (e.g. polymer chains, // ligands, solvent). - bioStruct.get_atom_site_label_entity_id().add(MY_MAP.get(inputAtom.getGroup().getType().toString())); + bioStruct.get_atom_site_label_entity_id().add(GroupType.groupTypeFromString(inputAtom.getGroup().getType().toString()).getGroupType()); // bioStruct data item is a reference to _entity_poly_seq.num defined in // the ENTITY_POLY_SEQ category. bioStruct item is used to maintain the // correspondence between the chemical sequence of a polymeric From 1aede7ac279304d4b52522cf48ed2947d4449961 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Tue, 5 Apr 2016 16:37:20 -0700 Subject: [PATCH 022/108] Another review session, thanks everyone! --- ...ace.java => MmtfDecodedDataInterface.java} | 187 +++++++++--------- .../rcsb/mmtf/api/MmtfDecoderInterface.java | 133 +++++++++++++ .../mmtf/api/StructureDecoderInterface.java | 133 ------------- .../rcsb/mmtf/decoder/DecodeStructure.java | 28 +-- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 30 +-- .../java/org/rcsb/mmtf/examples/HandleIO.java | 4 +- .../org/rcsb/mmtf/examples/HelloWorld.java | 8 +- .../rcsb/mmtf/testutils/CheckOnRawApi.java | 6 +- 8 files changed, 270 insertions(+), 259 deletions(-) rename mmtf-api/src/main/java/org/rcsb/mmtf/api/{DataApiInterface.java => MmtfDecodedDataInterface.java} (63%) create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java similarity index 63% rename from mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java rename to mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index 315fe5f..35cdd23 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataApiInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -1,7 +1,5 @@ package org.rcsb.mmtf.api; -import java.util.List; - /** * An interface describing the data API. * @@ -24,31 +22,31 @@ * @author Anthony Bradley * @author Jose Duarte */ -public interface DataApiInterface { +public interface MmtfDecodedDataInterface { /** * Returns an array containing the X coordinates of the atoms in Angstroms. * @return an array of length the number of atoms in the structure, obtainable with {@link #getNumAtoms()} */ - float[] getXcoords(); + float[] getxCoords(); /** * Returns an array containing the Y coordinates of the atoms in Angstroms. * @return an array of length the number of atoms in the structure, obtainable with {@link #getNumAtoms()} */ - float[] getYcoords(); + float[] getyCoords(); /** * Returns an array containing the Z coordinates of the atoms in Angstroms. * @return an array of length the number of atoms in the structure, obtainable with {@link #getNumAtoms()} */ - float[] getZcoords(); + float[] getzCoords(); /** * Returns an array containing the B-factors (temperature factors) of the atoms in Angstroms^2. * @return an array of length the number of atoms in the structure, obtainable with {@link #getNumAtoms()} */ - float[] getBfactors(); + float[] getbFactors(); /** * Returns an array containing the occupancy values of the atoms. @@ -64,117 +62,126 @@ public interface DataApiInterface { /** * Returns an array of location ids of the atoms. - * '?' specifies a lack of alt id. + * '\0' specifies a lack of alt id. * @return an array of length the number of atoms in the structure, obtainable with {@link #getNumAtoms()} */ char[] getAltLocIds(); /** * Returns an array containing the insertion codes (pdbx_PDB_ins_code in mmCIF dictionary) for each residue (group). - * '?' specifies a lack of insertion code. - * @return an array with insertion codes, of size {@link #getNumResidues()} - * @see #getResidueNums() + * '\0' specifies a lack of insertion code. + * @return an array with insertion codes, of size {@link #getNumGroups()} + * @see #getGroupIds() */ char[] getInsCodes(); /** * Returns an array containing residue numbers (auth_seq_id in mmCIF dictionary) for each residue (group). - * @return an array with with residue numbers, of size {@link #getNumResidues()} + * @return an array with with residue numbers, of size {@link #getNumGroups()} * @see #getInsCodes() */ - int[] getResidueNums(); + int[] getGroupIds(); /** - * Returns the group name for the group specified in {@link #getGroupIndices()}. + * Returns the group name for the group specified in {@link #getGroupTypeIndices()}. * to link groups to the 3 letter group name, e.g. HIS. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupTypeIndices()}. * @return a 3 letter string specifiying the group name. */ String getGroupName(int groupInd); /** - * Returns the number of atoms in the group specified in {@link #getGroupIndices()}. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * Returns the number of atoms in the group specified in {@link #getGroupTypeIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupTypeIndices()}. * @return The number of atoms in the group */ int getNumAtomsInGroup(int groupInd); - /** Returns the atom names (e.g. CB) for the group specified in {@link #getGroupIndices()}. + /** + * Returns the atom names (e.g. CB) for the group specified in {@link #getGroupTypeIndices()}. * Atom names are unique for each unique atom in a group. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupTypeIndices()}. * @return A list of strings for the atom names. * */ String[] getGroupAtomNames(int groupInd); - /** Returns the element names (e.g. C is carbon) for the group specified in {@link #getGroupIndices()}. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. - * @return A list of strings for the element information. + /** + * Returns the IUPAC element names (e.g. Ca is calcium) for the group specified in {@link #getGroupTypeIndices()}. + * @param groupInd the index of the group specified in {@link #getGroupTypeIndices()}. + * @return an array of strings for the element information. * */ String[] getGroupElementNames(int groupInd); - /** Returns the bond orders for the group specified in {@link #getGroupIndices()}. + /** + * Returns the bond orders for the group specified in {@link #getGroupTypeIndices()}. * A list of integers indicating the bond orders - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. - * @return A list of integers (1,2 or 3) indicating the bond orders. + * @param groupInd the index of the group specified in {@link #getGroupTypeIndices()}. + * @return an array of integers (1,2 or 3) indicating the bond orders. * */ int[] getGroupBondOrders(int groupInd); - /** Returns the zero-indexed bond indices (in pairs) for the group specified in {@link #getGroupIndices()}. + /** + * Returns the zero-based bond indices (in pairs) for the group specified in {@link #getGroupTypeIndices()}. * (e.g. 0,1 means there is bond between atom 0 and 1). - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. - * @return A list of integers specifying the bond indices (within the group). Indices are zero indexed. + * @param groupInd the index of the group specified in {@link #getGroupTypeIndices()}. + * @return an array of integers specifying the bond indices (within the group). Indices are zero indexed. * */ int[] getGroupBondIndices(int groupInd); - /** Returns the atom charges for the group specified in {@link #getGroupIndices()}. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. - * @return A list of integers indicating the atomic charge for each atom in the group. + /** + * Returns the atom charges for the group specified in {@link #getGroupTypeIndices()}. + * @param groupInd the index of the group specified in {@link #getGroupTypeIndices()}. + * @return an array of integers indicating the atomic charge for each atom in the group. */ int[] getGroupAtomCharges(int groupInd); - /** Returns the single letter amino acid code for the group specified in {@link #getGroupIndices()}. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. - * @return A string indicating the single letter amino acid + /** + * Returns the single letter amino acid code or nucleotide code for the + * group specified in {@link #getGroupTypeIndices()}. + * @param groupInd the index of the group specified in {@link #getGroupTypeIndices()}. + * @return the single letter amino acid or nucleotide, 'X' if non-standard amino acid or nucleotide */ - String getGroupSingleLetterCode(int groupInd); + char getGroupSingleLetterCode(int groupInd); - /** Returns the chemical componenet type for the group specified in {@link #getGroupIndices()}. - * @param groupInd The index of the group specified in {@link #getGroupIndices()}. - * @return A string (taken from the chemical component dictionary) indicating - * the type of the group. Corresponds to -> http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html + /** + * Returns the chemical component type for the group specified in {@link #getGroupTypeIndices()}. + * @param groupInd The index of the group specified in {@link #getGroupTypeIndices()}. + * @return a string (taken from the chemical component dictionary) indicating + * the type of the group. Corresponds to + * http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html */ String getGroupChemCompType(int groupInd); /** - * Returns an array containing indices of all groups in the structure as used in {@link #getGroupMap()}. - * @return an array of length the number of groups (residues) in the structure, obtainable with {@link #getNumResidues()} + * Returns an array containing indices to be used to obtain group level information, + * e.g. through {@link #getGroupAtomCharges(int)}. + * @return an array of length the number of groups (residues) in the structure, obtainable with {@link #getNumGroups()} */ - int[] getGroupIndices(); + int[] getGroupTypeIndices(); /** * Returns an array containing the indices of groups (residues) in their corresponding sequences, * obtainable through {@link #getEntityList()} from the {@link Entity} objects. * The indices are 0-based and specified per entity, -1 indicates the group is not present in the sequence. - * @return an array of length the number of groups (residues) in the structure, obtainable with {@link #getNumResidues()} + * @return an array of length the number of groups (residues) in the structure, obtainable with {@link #getNumGroups()} */ - int[] getSeqResGroupIndices(); + int[] getGroupSequenceIndices(); /** * Returns an array of internal chain identifiers (asym_ids in mmCIF dictionary), of length the - * number of chains (polymeric, non-polymeric and water) in the structure. - * - * The ids have a maximum of 4 chars. + * number of chains (polymeric, non-polymeric and water) in the structure. * @return an array of length the number of chains in the structure, obtainable with {@link #getNumChains()} + * @see #getChainNames() */ String[] getChainIds(); /** * Returns an array of public chain identifiers (auth_ids in mmCIF dictionary), of length the - * number of chains (polymeric, non-polymeric and water) in the structure. - * + * number of chains (polymeric, non-polymeric and water) in the structure. * @return an array of length the number of chains in the structure, obtainable with {@link #getNumChains()} + * @see #getChainIds() */ String[] getChainNames(); @@ -205,7 +212,7 @@ public interface DataApiInterface { /** * Returns the number of bioassemblies in this structure. - * @return an integer specifying the number of bioassemblies. + * @return the number of bioassemblies. */ int getNumBioassemblies(); @@ -222,22 +229,23 @@ public interface DataApiInterface { * @param an integer specifying the index (zero indexed) for the desired transformation. * @return a list of indices showing the chains involved in this transformation. */ - int[] getChainIndexListForTrans(int bioassemblyIndex, int transformationIndex); + int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex); /** - * Returns the transformation matrix for the given transformation for the given bioassembly. + * Returns a 4x4 transformation matrix for the given transformation for the given bioassembly. + * TODO is it column-packed or row-packed, we should use vecmath's convention * @param an integer specifying the bioassembly index (zero indexed). * @param an integer specifying the index (zero indexed) for the desired transformation. * @return the transformation matrix for this transformation. */ - double[] getTransMatrixForTrans(int bioassemblyIndex, int transformationIndex); + double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex); /** - * Returns an array of inter-group bonds represented with 2 consecutive atom - * indices in the array. - * @return an array of length 2 * number of inter-group bonds + * Returns the zero-based bond indices (in pairs) for the structure. + * (e.g. 0,1 means there is bond between atom 0 and 1). + * @return an array of integers specifying the bond indices (within the structure). Indices are zero-based. */ int[] getInterGroupBondIndices(); @@ -249,54 +257,58 @@ public interface DataApiInterface { /** * Returns the MMTF version number (from the specification). - * @return + * @return the version */ String getMmtfVersion(); /** - * Returns a string describing the producer of the MMTF process. - * @return + * Returns a string describing the producer of the MMTF file. + * e.g. "RCSB-PDB Generator---version: 6b8635f8d319beea9cd7cc7f5dd2649578ac01a0" + * @return a string describing the producer */ String getMmtfProducer(); /** - * @return The number of entities in the Structure + * Returns the number of entities (as defined in mmCIF dictionary) in the structure + * @return the number of entities in the structure */ int getNumEntities(); /** - * Returns the entity description for the entity specified by the index. - * @param The index of this entity. - * @return The description based on the PDBx model. + * Returns the entity description (as defined in mmCIF dictionary) + * for the entity specified by the index. + * @param the index of the specified entity. + * @return the description of the entity */ String getEntityDescription(int entityInd); /** - * Returns the the type (polymer, non-polymer, water) for the entity specified by the index. - * @param The index of this entity. - * @return The type (polymer, non-polymer, water) + * Returns the entity type (polymer, non-polymer, water) for the entity specified by the index. + * @param the index of the specified entity. + * @return the entity type (polymer, non-polymer, water) */ String getEntityType(int entityInd); /** * Returns the chain indices for the entity specified by the index. - * @param The index of this entity. - * @return The chain index list - referencing the entity to the chains. + * @param the index of the specified entity. + * @return the chain index list - referencing the entity to the chains. */ int[] getEntityChainIndexList(int entityInd); /** * Returns the sequence for the entity specified by the index. - * @param The index of this entity. - * @return The one letter sequence for this entity. Empty string if no sequence is applicable. + * @param the index of the specified entity. + * @return the one letter sequence for this entity. Empty string if no sequence is applicable. */ String getEntitySequence(int entityInd); /** - * Returns the four character PDB id of the structure. - * @return the PDB identifier + * Returns the identifier of the structure. + * For instance the 4-letter PDB id + * @return the identifier */ - String getPdbId(); + String getStructureId(); /** * Returns the number of models in the structure. @@ -314,36 +326,35 @@ public interface DataApiInterface { /** * Returns the number of groups (residues) in the structure that have * experimentally determined 3D coordinates. - * @return the number of residues in the structure, counting all models and chains + * @return the number of residues in the structure, for all models and chains */ - int getNumResidues(); + int getNumGroups(); /** * Returns the number of atoms in the structure. - * @return the number of atoms in the structure, counting all models and chains + * @return the number of atoms in the structure, for all models and chains */ int getNumAtoms(); /** - * Returns the Rfree (if available) of the dataset. - * @return the Rfree value or {@value MmtfBean#UNAVAILABLE_R_VALUE} if unavailable + * Returns the Rfree of the dataset. + * @return the Rfree value */ float getRfree(); - + /** - * Returns the Resolution (if available) of the dataset. - * @return the resolution value in Angstroms or {@value MmtfBean#UNAVAILABLE_R_VALUE} if unavailable + * Returns the Rwork of the dataset. + * @return the Rwork value */ - float getResolution(); + float getRwork(); /** - * Returns the Rwork (if available) of the dataset. - * @return the Rwork value or {@value MmtfBean#UNAVAILABLE_R_VALUE} if unavailable + * Returns the resolution of the dataset. + * @return the resolution value in Angstroms */ - float getRwork(); - + float getResolution(); /** * Returns the title of the structure. @@ -352,12 +363,12 @@ public interface DataApiInterface { String getTitle(); /** - * Returns the experimental methods as a list of strings. Normally only one + * Returns the experimental methods as an array of strings. Normally only one * experimental method is available, but structures solved with hybrid methods will * have more than one method. * The possible experimental method values are described in * data item _exptl.method of the mmCIF dictionary * @return the list of experimental methods */ - List getExperimentalMethods(); + String[] getExperimentalMethods(); } \ No newline at end of file diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java new file mode 100644 index 0000000..4671c9f --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -0,0 +1,133 @@ +package org.rcsb.mmtf.api; + +/** + * Interface to inflate a given MMTF data source. + * + * @author Anthony Bradley + */ +public interface MmtfDecoderInterface { + + /** + * Used before any additions to do any required pre-processing. + * For example the user could use this to specify the amount of memory to be allocated. + * @param totalNumAtoms the total number of atoms found in the data. + * @param totalNumGroups the total number of groups found in the data. + * @param totalNumChains the total number of chains found in the data. + * @param totalNumModels the total number of models found in the data. + * @param structureId an identifier for the structure (e.g. PDB id). + */ + void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, String structureId); + + /** + * A generic function to be used at the end of all data addition to do required cleanup on the structure + */ + void finalizeStructure(); + + /** + * Sets the number of models. + * @param modelCount Number of models + */ + void setModelCount(int modelCount); + + /** + * Sets the number of chains for a given model. + * @param modelId identifier of the model within the structure + * @param chainCount total number of chains within this model + */ + void setModelInfo(int modelId, int chainCount); + + /** + * Sets the information for a given chain. + * @param chainId chain identifier - length of one to four + * @param groupCount number of groups/residues in chain + */ + void setChainInfo(String chainId, int groupCount); + + /** + * Sets the entity level annotation for a chain(s). ChainIds is a list of strings that indicate the list of chains this information + * refers to. Sequence is the one letter amino acid sequence. Description and title are both free forms strings describing the entity and + * acting as a title for the entity. + * @param chainIds + * @param sequence + * @param description + * @param title + */ + void setEntityInfo(String[] chainIds, String sequence, String description, String title); + + /** + * Sets the information for a given group / residue with atomic data. + * @param groupName 3 letter code name of this group/residue + * @param groupNumber sequence position of this group + * @param insertionCode the one letter insertion code + * @param polymerType a string indicating the type of group (as found in the chemcomp dictionary. Empty string if none available. + * @param atomCount the number of atoms in the group + */ + void setGroupInfo(String groupName, int groupNumber, char insertionCode, + String polymerType, int atomCount); + + + /** + * Sets the atom level information for a given atom. + * @param atomName 1-3 long string of the unique name of the atom + * @param serialNumber a number counting atoms in a structure + * @param alternativeLocationId a character indicating the alternate + * location of the atom + * @param x the x cartesian coordinate + * @param y the y cartesian coordinate + * @param z the z cartesian coordinate + * @param occupancy the atomic occupancy + * @param temperatureFactor the B factor (temperature factor) + * @param element a 1-3 long string indicating the chemical element of the atom + * @param charge the atomic charge + */ + void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, + float x, float y, float z, float occupancy, float temperatureFactor, String element, int charge); + + /** + * Sets a single Bioassembly transformation to a structure. bioAssemblyId indicates the index of the bioassembly. + * @param bioAssemblyIndex An integer index of this bioassembly. + * @param inputChainIndices The integer indices of the chains involved in this bioassembly. + * @param inputTransform A list of doubles indicating the transform for this bioassembly. + */ + void setBioAssemblyTrans(int bioAssemblyIndex, int[] inputChainIndices, double[] inputTransform); + + /** + * Sets the space group and unit cell information. + * + * @param spaceGroup the space group name, e.g. "P 21 21 21" + * @param unitCell an array of length 6 with the unit cell parameters in order: a, b, c, alpha, beta, gamma + */ + void setXtalInfo(String spaceGroup, float[] unitCell); + + /** + * Sets an intra-group bond. + * + * @param thisBondIndOne the atom index of the first partner in the bond + * @param thisBondIndTwo the atom index of the second partner in the bond + * @param thisBondOrder the bond order + */ + void setGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder); + + /** + * Sets an inter-group bond. + * + * @param thisBondIndOne the atom index of the first partner in the bond + * @param thisBondIndTwo the atom index of the second partner in the bond + * @param thisBondOrder the bond order + */ + void setInterGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder); + + + /** + * Sets the header information. + * @param rFree + * @param rWork + * @param resolution + * @param title + * @param experimnetalMethods + */ + void setHeaderInfo(float rFree, float rWork, float resolution, String title, String[] experimnetalMethods); + + + +} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java deleted file mode 100644 index 52629ce..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/StructureDecoderInterface.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.rcsb.mmtf.api; - -import java.util.List; - -/** - * Interface to inflate a given MMTF data source. - * - * @author Anthony Bradley - */ -public interface StructureDecoderInterface { - - /** - * Sets the number of models. - * @param modelCount Number of models - */ - void setModelCount(int modelCount); - - /** - * Sets the number of chains for a given model. - * @param modelId identifier of the model within the structure - * @param chainCount total number of chains within this model - */ - void setModelInfo(int modelId, int chainCount); - - /** - * Sets the information for a given chain. - * @param chainId chain identifier - length of one to four - * @param groupCount number of groups/residues in chain - */ - void setChainInfo(String chainId, int groupCount); - - /** - * Sets the entity level annotation for a chain(s). ChainIds is a list of strings that indicate the list of chains this information - * refers to. Sequence is the one letter amino acid sequence. Description and title are both free forms strings describing the entity and - * acting as a title for the entity. - * @param chainIds - * @param sequence - * @param description - * @param title - */ - void setEntityInfo(String[] chainIds, String sequence, String description, String title); - - /** - * Sets the information for a given group / residue with atomic data. - * @param groupName 3 letter code name of this group/residue - * @param groupNumber sequence position of this group - * @param insertionCode the one letter insertion code - * @param polymerType a string indicating the type of group (as found in the chemcomp dictionary. Empty string if none available. - * @param atomCount the number of atoms in the group - */ - void setGroupInfo(String groupName, int groupNumber, char insertionCode, - String polymerType, int atomCount); - - - /** - * Sets the atom level information for a given atom. - * @param atomName 1-3 long string of the unique name of the atom - * @param serialNumber a number counting atoms in a structure - * @param alternativeLocationId a character indicating the alternate - * location of the atom - * @param x the x cartesian coordinate - * @param y the y cartesian coordinate - * @param z the z cartesian coordinate - * @param occupancy the atomic occupancy - * @param temperatureFactor the B factor (temperature factor) - * @param element a 1-3 long string indicating the chemical element of the atom - * @param charge the atomic charge - */ - void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, - float x, float y, float z, float occupancy, float temperatureFactor, String element, int charge); - - /** - * Sets a single Bioassembly transformation to a structure. bioAssemblyId indicates the index of the bioassembly. - * @param bioAssemblyIndex An integer index of this bioassembly. - * @param inputChainIndices The integer indices of the chains involved in this bioassembly. - * @param inputTransform A list of doubles indicating the transform for this bioassembly. - */ - void setBioAssemblyTrans(int bioAssemblyIndex, int[] inputChainIndices, double[] inputTransform); - - /** - * Sets the space group and unit cell information. - * - * @param spaceGroup the space group name, e.g. "P 21 21 21" - * @param unitCell an array of length 6 with the unit cell parameters in order: a, b, c, alpha, beta, gamma - */ - void setXtalInfo(String spaceGroup, float[] unitCell); - - /** - * Sets an intra-group bond. - * - * @param thisBondIndOne the atom index of the first partner in the bond - * @param thisBondIndTwo the atom index of the second partner in the bond - * @param thisBondOrder the bond order - */ - void setGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder); - - /** - * Sets an inter-group bond. - * - * @param thisBondIndOne the atom index of the first partner in the bond - * @param thisBondIndTwo the atom index of the second partner in the bond - * @param thisBondOrder the bond order - */ - void setInterGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder); - - - /** - * Sets the header information. - * @param rFree - * @param rWork - * @param resolution - * @param title - * @param experimnetalMethods - */ - void setHeaderInfo(float rFree, float rWork, float resolution, String title, List experimnetalMethods); - - /** - * Used before any additions to do any required pre-processing. - * For example the user could use this to specify the amount of memory to be allocated. - * @param totalNumAtoms The total number of atoms found in the data. - * @param totalNumGroups The total number of groups found in the data. - * @param totalNumChains The total number of chains found in the data. - * @param totalNumModels The total number of models found in the data. - * @param modelCode An identifier for this model (e.g. PDB id). - */ - void prepareStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, String modelCode); - - /** - * A generic function to be used at the end of all data addition to do required cleanup on the structure - */ - void cleanUpStructure(); - -} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index af53296..524accf 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -3,8 +3,8 @@ import java.util.HashSet; import java.util.Set; -import org.rcsb.mmtf.api.DataApiInterface; -import org.rcsb.mmtf.api.StructureDecoderInterface; +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; +import org.rcsb.mmtf.api.MmtfDecoderInterface; /** * Decode an MMTF structure using a structure inflator. The class also allows access to the unconsumed but parsed and inflated underlying data. @@ -17,10 +17,10 @@ public class DecodeStructure { /** The struct inflator. */ - private StructureDecoderInterface structInflator; + private MmtfDecoderInterface structInflator; /** The api to the data */ - private DataApiInterface dataApi; + private MmtfDecodedDataInterface dataApi; /* * Initialise the counters @@ -52,11 +52,11 @@ public DecodeStructure(byte[] inputByteArr) { * @param inputStructInflator the input struct inflator * @param parsingParams the parsing params */ - public final void getStructFromByteArray(final StructureDecoderInterface inputStructInflator, final ParsingParams parsingParams) { + public final void getStructFromByteArray(final MmtfDecoderInterface inputStructInflator, final ParsingParams parsingParams) { // Set the inflator structInflator = inputStructInflator; // Do any required preparation - inputStructInflator.prepareStructure(dataApi.getNumAtoms(), dataApi.getNumResidues(), dataApi.getNumChains(), dataApi.getNumModels(), dataApi.getPdbId()); + inputStructInflator.initStructure(dataApi.getNumAtoms(), dataApi.getNumGroups(), dataApi.getNumChains(), dataApi.getNumModels(), dataApi.getStructureId()); // Now get the parsing parameters to do their thing useParseParams(parsingParams); // Now add the atom information @@ -74,7 +74,7 @@ public final void getStructFromByteArray(final StructureDecoderInterface inputSt // Now add the entity info addEntityInfo(); // Now do any required cleanup - structInflator.cleanUpStructure(); + structInflator.finalizeStructure(); } /** @@ -167,10 +167,10 @@ private void addOrUpdateChainInfo(int chainIndex) { */ private int addGroup(final int thisGroupNum) { // Now get the group - int groupInd = dataApi.getGroupIndices()[thisGroupNum]; + int groupInd = dataApi.getGroupTypeIndices()[thisGroupNum]; // Get this info int atomCount = dataApi.getNumAtomsInGroup(groupInd); - int currentGroupNumber = dataApi.getResidueNums()[thisGroupNum]; + int currentGroupNumber = dataApi.getGroupIds()[thisGroupNum]; char insertionCode = dataApi.getInsCodes()[thisGroupNum]; structInflator.setGroupInfo(dataApi.getGroupName(groupInd), currentGroupNumber, insertionCode, dataApi.getGroupChemCompType(groupInd), atomCount); @@ -198,11 +198,11 @@ private void addAtomData(String[] atomNames, String[] elementNames, int[] atomCh int charge = atomCharges[atomCounter]; int serialNumber = dataApi.getAtomIds()[currentAtomIndex]; char alternativeLocationId = dataApi.getAltLocIds()[currentAtomIndex]; - float x = dataApi.getXcoords()[currentAtomIndex]; - float z = dataApi.getZcoords()[currentAtomIndex]; - float y = dataApi.getYcoords()[currentAtomIndex]; + float x = dataApi.getxCoords()[currentAtomIndex]; + float z = dataApi.getzCoords()[currentAtomIndex]; + float y = dataApi.getyCoords()[currentAtomIndex]; float occupancy = dataApi.getOccupancies()[currentAtomIndex]; - float temperatureFactor = dataApi.getBfactors()[currentAtomIndex]; + float temperatureFactor = dataApi.getbFactors()[currentAtomIndex]; structInflator.setAtomInfo(atomName, serialNumber, alternativeLocationId, x, y, z, occupancy, temperatureFactor, element, charge); // Now increment the atom counter for this group @@ -251,7 +251,7 @@ private void addXtalographicInfo() { private void generateBioAssembly() { for (int i=0; i experimentalMethods; @Override - public float[] getXcoords() { + public float[] getxCoords() { return cartnX; } @Override - public float[] getYcoords() { + public float[] getyCoords() { return cartnY; } @Override - public float[] getZcoords() { + public float[] getzCoords() { return cartnZ; } @Override - public float[] getBfactors() { + public float[] getbFactors() { return bFactor; } @@ -226,17 +226,17 @@ public char[] getInsCodes() { } @Override - public int[] getResidueNums() { + public int[] getGroupIds() { return groupNum; } @Override - public int[] getGroupIndices() { + public int[] getGroupTypeIndices() { return groupList; } @Override - public int[] getSeqResGroupIndices() { + public int[] getGroupSequenceIndices() { return seqResGroupList; } @@ -291,12 +291,12 @@ public String getMmtfProducer() { } @Override - public String getPdbId() { + public String getStructureId() { return pdbId; } @Override - public int getNumResidues() { + public int getNumGroups() { return this.groupList.length; } @@ -345,7 +345,7 @@ public String getTitle() { } @Override - public List getExperimentalMethods() { + public String[] getExperimentalMethods() { return experimentalMethods; } @@ -399,7 +399,7 @@ public int[] getGroupAtomCharges(int groupInd) { } @Override - public String getGroupSingleLetterCode(int groupInd) { + public char getGroupSingleLetterCode(int groupInd) { return groupMap[groupInd].getSingleLetterCode(); } @@ -461,12 +461,12 @@ public int getNumTransInBioassembly(int bioassemblyIndex) { } @Override - public int[] getChainIndexListForTrans(int bioassemblyIndex, int transformationIndex) { + public int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex) { return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getChainIndexList(); } @Override - public double[] getTransMatrixForTrans(int bioassemblyIndex, int transformationIndex) { + public double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex) { return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getTransformation(); } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java index 5c81191..cc28647 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java @@ -12,7 +12,7 @@ import java.nio.file.Paths; import java.util.zip.GZIPInputStream; -import org.rcsb.mmtf.api.DataApiInterface; +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.decoder.SimpleDataApi; /** @@ -57,7 +57,7 @@ public final byte[] getByteArrFromUrlOrFile(final String inputCode) { * @param inputCode the input code * @return */ - public final DataApiInterface getDataApiFromUrlOrFile(final String inputCode) { + public final MmtfDecodedDataInterface getDataApiFromUrlOrFile(final String inputCode) { String basePath = getBasePath(); boolean isFile = getFile(basePath, inputCode); // If it's a file on the file system - get it diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java index b19b51b..9701903 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java @@ -1,15 +1,15 @@ package org.rcsb.mmtf.examples; -import org.rcsb.mmtf.api.DataApiInterface; +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; public class HelloWorld { public static void main(String[] args) { HandleIO handleIO = new HandleIO(); - DataApiInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); - System.out.println("PDB Code: "+dataApi.getPdbId()+" has "+dataApi.getNumChains()+" chains"); + MmtfDecodedDataInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); + System.out.println("PDB Code: "+dataApi.getStructureId()+" has "+dataApi.getNumChains()+" chains"); System.out.println("HET group "+dataApi.getGroupName(0)+" has the following atomic charges: "+dataApi.getGroupAtomCharges(0)); - System.out.println("PDB Code: "+dataApi.getPdbId()+" has "+dataApi.getNumBioassemblies()+" bioassemblies"); + System.out.println("PDB Code: "+dataApi.getStructureId()+" has "+dataApi.getNumBioassemblies()+" bioassemblies"); } } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java index 5519415..f0b4078 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java @@ -12,7 +12,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.rcsb.mmtf.api.DataApiInterface; +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.decoder.SimpleDataApi; /** @@ -21,7 +21,7 @@ * */ public class CheckOnRawApi { - DataApiInterface dataApi; + MmtfDecodedDataInterface dataApi; public CheckOnRawApi(byte[] inputData) { dataApi = new SimpleDataApi(inputData); } @@ -82,7 +82,7 @@ public void checkIfEntityInfoSame(Structure biojavaStruct) { public void checkIfSeqResInfoSame(Structure biojavaStruct, FileParsingParameters params){ if(params.isUseInternalChainId()){ // Get the seqres group list - int[] decodedSeqResGroupList = dataApi.getSeqResGroupIndices(); + int[] decodedSeqResGroupList = dataApi.getGroupSequenceIndices(); // Get the string sequences int groupCounter = 0; int chainCounter = 0; From a477d8b956ce0e720a95a1a963131d88b3a37527 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 17:02:00 -0700 Subject: [PATCH 023/108] Updates to the interface from meeting. Fix downstream errors. --- .../src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java | 6 +++--- .../src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java | 4 ++-- .../java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java index 3c62349..3696785 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java @@ -35,7 +35,7 @@ public class PDBGroup implements Serializable { private List atomCharges; /** The single letter code. */ - private String singleLetterCode; + private char singleLetterCode; /** A string (taken from the chemical component dictionary) indicating * the type of the group. Corresponds to -> http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html @@ -149,7 +149,7 @@ public final void setAtomCharges(final List inputAtomCharges) { * * @return the single letter code */ - public final String getSingleLetterCode() { + public final char getSingleLetterCode() { return singleLetterCode; } @@ -158,7 +158,7 @@ public final String getSingleLetterCode() { * * @param inputSingleLetterCode the new single letter code */ - public final void setSingleLetterCode(final String inputSingleLetterCode) { + public final void setSingleLetterCode(final char inputSingleLetterCode) { this.singleLetterCode = inputSingleLetterCode; } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 514601b..e427ad4 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -80,7 +80,7 @@ public SimpleDataApi(byte[] inputByteArr) { rWork = inputData.getrWork(); resolution = inputData.getResolution(); title = inputData.getTitle(); - experimentalMethods = inputData.getExperimentalMethods(); + experimentalMethods = inputData.getExperimentalMethods().toArray(new String[0]); } @@ -183,7 +183,7 @@ public SimpleDataApi(byte[] inputByteArr) { private String title; /** The list of experimental methods. */ - private List experimentalMethods; + private String[] experimentalMethods; @Override public float[] getxCoords() { diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java index 9d07690..34f473d 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java @@ -296,7 +296,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt // Make a new group PDBGroup outGroup = new PDBGroup(); // Set the one letter code - outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code()); + outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code().charAt(0)); // Set the group type outGroup.setChemCompType(currentGroup.getChemComp().getType()); outGroup.setGroupName(atomInfo.remove(0)); @@ -511,8 +511,8 @@ private void addCalphaGroup(List cAlphaGroup,SecStrucState props, ResidueN if (hashToCalphaRes.containsKey(calphaHashCode)==false){ // Make a new group PDBGroup outGroup = new PDBGroup(); - outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code()); - // + outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code().charAt(0)); + // Set the chemical component type. outGroup.setChemCompType(currentGroup.getChemComp().getType()); outGroup.setGroupName(calphaAtomInfo.remove(0)); outGroup.setAtomInfo(calphaAtomInfo); From 5de2874e6aa978b6bfd3d78eabac0aea11b217f6 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 17:18:27 -0700 Subject: [PATCH 024/108] Updates to the documentaion of the functions and some more whitespacing changes. --- .../arraydecompressors/DeltaDeCompress.java | 115 +++++++++--------- .../RunLengthDecodeInt.java | 89 +++++++------- .../RunLengthDecodeString.java | 89 +++++++------- .../arraydecompressors/RunLengthDelta.java | 110 ++++++++--------- .../rcsb/mmtf/decoder/DecodeStructure.java | 7 +- .../org/rcsb/mmtf/decoder/DecoderUtils.java | 49 ++++---- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 10 +- .../rcsb/mmtf/decoder/TestDecoderUtils.java | 2 +- 8 files changed, 233 insertions(+), 238 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java index 0eec729..47ca52f 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java @@ -14,62 +14,61 @@ */ public class DeltaDeCompress { - /** - * The number of bytes in a four byte integers. - */ - private static final int BIG_INT_BYTES = 4; - /** - * Decompress two byte arrays - one containing 4 byte and one 2 byte integers. - * @param fourByteInts An array of four byte integers. - * @param twoByteInts An array of two byte integers. - * @return A decompressed integer array. - * @throws IOException The byte array does not contain - * the information requested. - */ - public final int[] decompressByteArray(final byte[] fourByteInts, - final byte[] twoByteInts) throws IOException { - // Get these data streams - DataInputStream bigStream = new DataInputStream(new - ByteArrayInputStream(fourByteInts)); - // Get the length of the array - int lengthOfBigIntArray = fourByteInts.length / (BIG_INT_BYTES * 2); - // Integers used in the output - int[] fourByteIntArr = new int[lengthOfBigIntArray]; - // Integers used to count from the two byte array - int[] counterInts = new int[lengthOfBigIntArray]; - DataInputStream smallStream = new DataInputStream(new - ByteArrayInputStream(twoByteInts)); - int totNum = 0; - // Loop through these and take every other int - for (int i = 0; i < lengthOfBigIntArray; i++) { - int bigNum = bigStream.readInt(); - int counterNum = bigStream.readInt(); - // Now write this out - totNum++; - // Now add to the counter - totNum += counterNum; - fourByteIntArr[i] = bigNum; - counterInts[i] = counterNum; - } - // Now loop over the total number of ints - int[] outArr = new int[totNum]; - int totCounter = 0; - for (int i = 0; i < fourByteIntArr.length; i++) { - // Now add this to the out array - if (i == 0) { - outArr[totCounter] = fourByteIntArr[i]; - } else { - outArr[totCounter] = outArr[totCounter - 1] + fourByteIntArr[i]; - } - totCounter++; - // Now loop through this - for (int j = 0; j < counterInts[i]; j++) { - // Now add this as a short - int currentInt = (int) smallStream.readShort(); - outArr[totCounter] = outArr[totCounter - 1] + currentInt; - totCounter++; - } - } - return outArr; - } + /** The number of bytes in a four byte integers. */ + private static final int BIG_INT_BYTES = 4; + + + /** + * Decompress two byte arrays - one containing 4 byte and one 2 byte integers. + * @param fourByteInts an array of four byte integers. + * @param twoByteInts an array of two byte integers. + * @return a decompressed integer array. + * @throws IOException the byte array does not contain + * the information requested. + */ + public final int[] decompressByteArray(final byte[] fourByteInts, + final byte[] twoByteInts) throws IOException { + // Get these data streams + DataInputStream bigStream = new DataInputStream(new + ByteArrayInputStream(fourByteInts)); + // Get the length of the array + int lengthOfBigIntArray = fourByteInts.length / (BIG_INT_BYTES * 2); + // Integers used in the output + int[] fourByteIntArr = new int[lengthOfBigIntArray]; + // Integers used to count from the two byte array + int[] counterInts = new int[lengthOfBigIntArray]; + DataInputStream smallStream = new DataInputStream(new ByteArrayInputStream(twoByteInts)); + int totNum = 0; + // Loop through these and take every other int + for (int i = 0; i < lengthOfBigIntArray; i++) { + int bigNum = bigStream.readInt(); + int counterNum = bigStream.readInt(); + // Now write this out + totNum++; + // Now add to the counter + totNum += counterNum; + fourByteIntArr[i] = bigNum; + counterInts[i] = counterNum; + } + // Now loop over the total number of ints + int[] outArr = new int[totNum]; + int totCounter = 0; + for (int i = 0; i < fourByteIntArr.length; i++) { + // Now add this to the out array + if (i == 0) { + outArr[totCounter] = fourByteIntArr[i]; + } else { + outArr[totCounter] = outArr[totCounter - 1] + fourByteIntArr[i]; + } + totCounter++; + // Now loop through this + for (int j = 0; j < counterInts[i]; j++) { + // Now add this as a short + int currentInt = (int) smallStream.readShort(); + outArr[totCounter] = outArr[totCounter - 1] + currentInt; + totCounter++; + } + } + return outArr; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java index 515f5ee..278a54f 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java @@ -11,52 +11,49 @@ */ public class RunLengthDecodeInt { - /** - * The number of bytes in a four byte integers. - */ - private static final int BIG_INT_BYTES = 4; + /** + * The number of bytes in a four byte integers. + */ + private static final int BIG_INT_BYTES = 4; - /** - * Decompress a byte array that is run length encoded. - * @param inArray The input byte array. Integers as 4 bytes long - * @return The decompressed integer array - * @throws IOException The byte array does not contain the - * information requested. - */ - public final int[] decompressByteArray(final byte[] inArray) - throws IOException { - // The length of each of the 4 byte integer arrays - int lengthOfBigIntArr = inArray.length / (BIG_INT_BYTES * 2); - // Array to store all the different numbers - int[] numArr = new int[lengthOfBigIntArr]; - int[] countArr = new int[lengthOfBigIntArr]; - // Get the size - int totCount = 0; - DataInputStream bis = new DataInputStream(new - ByteArrayInputStream(inArray)); - for (int i = 0; i < lengthOfBigIntArr; i++) { - // Get the number - int getNum = bis.readInt(); - int getCount = bis.readInt(); - totCount += getCount; - numArr[i] = getNum; - countArr[i] = getCount; - } - // Now set this output array - int[] outArr = new int[totCount]; - int totCounter = 0; - for (int i = 0; i < numArr.length; i++) { - int thisAns = numArr[i]; - for (int j = 0; j < countArr[i]; j++) { - // Annd then add t is to the array - outArr[totCounter] = thisAns; - // Now add to the counter - totCounter++; - - } - - } - return outArr; - } + /** + * Decompress a byte array that is run length encoded. + * @param inArray the input byte array. Integers as 4 bytes long + * @return the decompressed integer array + * @throws IOException the byte array does not contain the + * information requested. + */ + public final int[] decompressByteArray(final byte[] inArray) throws IOException { + // The length of each of the 4 byte integer arrays + int lengthOfBigIntArr = inArray.length / (BIG_INT_BYTES * 2); + // Array to store all the different numbers + int[] numArr = new int[lengthOfBigIntArr]; + int[] countArr = new int[lengthOfBigIntArr]; + // Get the size + int totCount = 0; + DataInputStream bis = new DataInputStream(new + ByteArrayInputStream(inArray)); + for (int i = 0; i < lengthOfBigIntArr; i++) { + // Get the number + int getNum = bis.readInt(); + int getCount = bis.readInt(); + totCount += getCount; + numArr[i] = getNum; + countArr[i] = getCount; + } + // Now set this output array + int[] outArr = new int[totCount]; + int totCounter = 0; + for (int i = 0; i < numArr.length; i++) { + int thisAns = numArr[i]; + for (int j = 0; j < countArr[i]; j++) { + // Annd then add t is to the array + outArr[totCounter] = thisAns; + // Now add to the counter + totCounter++; + } + } + return outArr; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java index fac3e86..8080cf9 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java @@ -13,49 +13,52 @@ public class RunLengthDecodeString { - /** - * Runlength decode an int[] and return as a char[]. - * @param inputIntArray An input array of integers. - * @return a char array of values runlength decoded. - */ - public final char[] intArrayToCharArray(final int[] inputIntArray) { - int totNum = 0; - // Define a default Char value - char outChar = MmtfBean.UNAVAILABLE_CHAR_VALUE; - // If it's only one long - just take the char - if (inputIntArray.length == 1) { - char[] outArray = new char[1]; - if (Character.toChars(inputIntArray[0])[0] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { - outChar = '?'; - } else { - outChar = Character.toChars(inputIntArray[0])[0]; - } - outArray[0] = outChar; - return outArray; - } - for (int i = 0; i < inputIntArray.length; i += 2) { - totNum += inputIntArray[i + 1]; - } - - char[] outArray = new char[totNum]; - int totCounter = 0; - - - for (int i = 0; i < inputIntArray.length; i += 2) { - if (inputIntArray[i] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { - outChar = "?".charAt(0); - } else { - // Otherwise get this char - outChar = Character.toChars(inputIntArray[i])[0]; - } - int numString = inputIntArray[i + 1]; - for (int j = 0; j < numString; j++) { - outArray[totCounter] = outChar; - totCounter++; - } - } - return outArray; - } + /** + * Runlength decode an int[] and return as a char[]. + * @param inputIntArray an input array of integers. Integers are in pairs. The first in each pair + * is the ASCII code of the character. The second in each pair is the number of copies of this character to + * be added to the list. + * @return a char array of values run length decoded. + */ + public final char[] intArrayToCharArray(final int[] inputIntArray) { + // If it's only one long - just take the char + if (inputIntArray.length == 1) { + char[] outArray = new char[1]; + if (Character.toChars(inputIntArray[0])[0] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { + outArray[0] = '?'; + } else { + outArray[0]= Character.toChars(inputIntArray[0])[0]; + } + return outArray; + } + // If it's longer - count the total number to be put in (to assign the char[]). + int totNum = 0; + for (int i = 0; i < inputIntArray.length; i += 2) { + totNum += inputIntArray[i + 1]; + } + // Assign the output char array. + char[] outArray = new char[totNum]; + // The total counter for the output. + int totCounter = 0; + // Define an empty char with the scope to be used in the for loop. + char outChar = '\0'; + for (int i = 0; i < inputIntArray.length; i += 2) { + if (inputIntArray[i] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { + outChar = "?".charAt(0); + } else { + // Otherwise get this char + outChar = Character.toChars(inputIntArray[i])[0]; + } + // Find the number of repeats. + int numRepeats = inputIntArray[i + 1]; + // Loop through and add these to the list + for (int j = 0; j < numRepeats; j++) { + outArray[totCounter] = outChar; + totCounter++; + } + } + return outArray; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java index 4fe4d79..44d4837 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java @@ -15,61 +15,61 @@ public class RunLengthDelta { - /** - * The number of bytes in a four byte integers. - */ - private static final int BIG_INT_BYTES = 4; + /** + * The number of bytes in a four byte integers. + */ + private static final int BIG_INT_BYTES = 4; - /** - * Decompress a byte a byte array using run length and delta decoding. - * @param inArray The input byte array - * @return A decompressed array of integers. - * @throws IOException If no more data can be read from the byte array. - */ - public final int[] decompressByteArray(final byte[] inArray) - throws IOException { - // The length of the array - int lengthOfBigIntArr = inArray.length / (BIG_INT_BYTES * 2); - // Array to store all the different numbers - int[] numArr = new int[lengthOfBigIntArr]; - int[] countArr = new int[lengthOfBigIntArr]; - // Get the size - int totCount = 0; - DataInputStream bis = new DataInputStream(new - ByteArrayInputStream(inArray)); - for (int i = 0; i < lengthOfBigIntArr; i++) { - // Get the numbers - int getNum = bis.readInt(); - // Get the number of repeats - int getCount = bis.readInt(); - if (getCount < 0) { - System.out.println(getCount); - } - // Get the total count - totCount += getCount; - // Fill the number array - numArr[i] = getNum; - // Fill the count array - countArr[i] = getCount; - } - // Now set this output array - int[] outArr = new int[totCount]; - int totCounter = 0; - int totAns = 0; - for (int i = 0; i < numArr.length; i++) { - // Get the number that is to be repeared - int thisAns = numArr[i]; - // Get the number of repeats - for (int j = 0; j < countArr[i]; j++) { - // Add the delta to get this answer - totAns += thisAns; - // And then add t is to the array - outArr[totCounter] = totAns; - // Now add to the counter - totCounter++; - } - } - return outArr; - } + /** + * Decompress a byte array using run length and delta decoding. + * @param inArray The input byte array + * @return A decompressed array of integers. + * @throws IOException If no more data can be read from the byte array. + */ + public final int[] decompressByteArray(final byte[] inArray) + throws IOException { + // The length of the array + int lengthOfBigIntArr = inArray.length / (BIG_INT_BYTES * 2); + // Array to store all the different numbers + int[] numArr = new int[lengthOfBigIntArr]; + int[] countArr = new int[lengthOfBigIntArr]; + // Get the size + int totCount = 0; + DataInputStream bis = new DataInputStream(new + ByteArrayInputStream(inArray)); + for (int i = 0; i < lengthOfBigIntArr; i++) { + // Get the numbers + int getNum = bis.readInt(); + // Get the number of repeats + int getCount = bis.readInt(); + if (getCount < 0) { + System.out.println(getCount); + } + // Get the total count + totCount += getCount; + // Fill the number array + numArr[i] = getNum; + // Fill the count array + countArr[i] = getCount; + } + // Now set this output array + int[] outArr = new int[totCount]; + int totCounter = 0; + int totAns = 0; + for (int i = 0; i < numArr.length; i++) { + // Get the number that is to be repeared + int thisAns = numArr[i]; + // Get the number of repeats + for (int j = 0; j < countArr[i]; j++) { + // Add the delta to get this answer + totAns += thisAns; + // And then add t is to the array + outArr[totCounter] = totAns; + // Now add to the counter + totCounter++; + } + } + return outArr; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 524accf..41a04b2 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -7,7 +7,8 @@ import org.rcsb.mmtf.api.MmtfDecoderInterface; /** - * Decode an MMTF structure using a structure inflator. The class also allows access to the unconsumed but parsed and inflated underlying data. + * Decode an MMTF structure using a structure inflator. + * The class also allows access to the unconsumed but parsed and inflated underlying data. * * @author Anthony Bradley * @@ -22,9 +23,7 @@ public class DecodeStructure { /** The api to the data */ private MmtfDecodedDataInterface dataApi; - /* - * Initialise the counters - */ + // Intialises the counters. private int modelCounter = 0; private int chainCounter = 0; private int groupCounter = 0; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java index 935b4ff..ce0445e 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java @@ -13,31 +13,30 @@ public class DecoderUtils { private static final int MAX_CHARS_PER_CHAIN_ENTRY = 4; /** - * Function to get the chain id for this chain. - * - * @param chainList the chain list - * @param thisChain the this chain - * @return the chain id + * Return the String of a chain id for a given chain, from a byte array. + * @param chainList the input byte array. Each chain id is stored as four bytes. Each byte encodes a char. + * @param chainIndex the index of the chain for which the id is required. + * @return a String of the chain id for the given chain. */ - public final String getChainId(final byte[] chainList, final int thisChain) { + public final String getChainId(final byte[] chainList, final int chainIndex) { int incrementor = 0; StringBuilder sb = new StringBuilder(); - byte chainIdOne = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdOne = chainList[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; sb.append((char) chainIdOne); // Now get the next byte incrementor += 1; - byte chainIdTwo = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdTwo = chainList[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; if (chainIdTwo != (byte) 0) { sb.append((char) chainIdTwo); } incrementor += 1; - byte chainIdThree = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdThree = chainList[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; if (chainIdThree != (byte) 0) { sb.append((char) chainIdThree); } incrementor += 1; - byte chainIdFour = chainList[thisChain * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; + byte chainIdFour = chainList[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; if (chainIdFour != (byte) 0) { sb.append((char) chainIdFour); } @@ -45,11 +44,10 @@ public final String getChainId(final byte[] chainList, final int thisChain) { } /** - * Function to convert a byte array to an int array. - * - * @param inArray the in array - * @return the int[] - * @throws IOException Signals that an I/O exception has occurred. + * Convert a byte array (each four byte encodes a different integer) to an integer array. + * @param inArray the input byte array + * @return the decoded integer array + * @throws IOException due to byte array not being accesible */ public final int[] bytesToInts(final byte[] inArray) throws IOException { DataInputStream bis = new DataInputStream(new ByteArrayInputStream(inArray)); @@ -64,11 +62,10 @@ public final int[] bytesToInts(final byte[] inArray) throws IOException { } /** - * Function to convert a byte array to byte encoded . - * - * @param inArray the in array - * @return the int[] - * @throws IOException Signals that an I/O exception has occurred. + * Convert a byte array (each byte encodes a different integer) to an integer array. + * @param inArray the input byte array + * @return the decoded integer array + * @throws IOException due to byte array not being accesible */ public final int[] bytesToByteInts(final byte[] inArray) throws IOException { DataInputStream bis = new DataInputStream(new ByteArrayInputStream(inArray)); @@ -84,7 +81,7 @@ public final int[] bytesToByteInts(final byte[] inArray) throws IOException { /** - * Decode chain ids from byte arrays + * Find all the chain ids from a single byte array. Each byte encodes a different ASCII character. * @param currentChainList the byte array of the chain list input. Each chain takes up 4 bytes. * @return the string array of the parsed chain ids */ @@ -98,12 +95,12 @@ public final String[] decodeChainList(byte[] currentChainList) { } /** - * Decode integers to floats by dividing by this float. - * @param decompressByteArray - * @param floatDivider - * @return + * Convert an integer array to a float array by dividing by a float. + * @param inputIntArray the input integer array to be divided + * @param floatDivider the float divider to divide the integers by. + * @return a float array converted from the input. */ - public final float[] decodeIntsToFloats(int[] inputIntArray, float floatDivider) { + public final float[] convertIntsToFloats(int[] inputIntArray, float floatDivider) { // Assign the output array to write float[] outArray = new float[inputIntArray.length]; for (int i=0; i Date: Tue, 5 Apr 2016 17:23:53 -0700 Subject: [PATCH 025/108] More docs and formatting --- .../rcsb/mmtf/decoder/DecodeStructure.java | 37 +++++++++---------- .../org/rcsb/mmtf/decoder/ParsingParams.java | 2 - .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 29 +++++++-------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 41a04b2..a319454 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -38,7 +38,7 @@ public class DecodeStructure { */ public DecodeStructure(byte[] inputByteArr) { - // Data api + // Create the instance of this API dataApi = new SimpleDataApi(inputByteArr); } @@ -46,10 +46,8 @@ public DecodeStructure(byte[] inputByteArr) { /** * Generate a structure from bytes using a structure inflator. - * - * @param myInBytes the my in bytes - * @param inputStructInflator the input struct inflator - * @param parsingParams the parsing params + * @param inputStructInflator the structure inflator to be used + * @param parsingParams the parsing parameters object to be used when inflating. */ public final void getStructFromByteArray(final MmtfDecoderInterface inputStructInflator, final ParsingParams parsingParams) { // Set the inflator @@ -110,7 +108,7 @@ private final void addEntityInfo() { /** - * Function to add ancilliary header information to the structure + * Add ancilliary header information to the structure */ private final void addHeaderInfo() { structInflator.setHeaderInfo(dataApi.getRfree(),dataApi.getRwork(), dataApi.getResolution(), dataApi.getTitle(), dataApi.getExperimentalMethods()); @@ -119,7 +117,7 @@ private final void addHeaderInfo() { /** * Use the parsing parameters to set the scene. - * @param parsingParams + * @param parsingParams the input parsing parameters object */ private final void useParseParams(ParsingParams parsingParams) { if (parsingParams.isParseInternal()) { @@ -134,7 +132,7 @@ private final void useParseParams(ParsingParams parsingParams) { /** * Set the chain level information and then loop through the groups - * @param chainIndex + * @param chainIndex the chain index to be created or updated. */ private void addOrUpdateChainInfo(int chainIndex) { // Get the current c @@ -158,19 +156,17 @@ private void addOrUpdateChainInfo(int chainIndex) { } /** - * Adds the group. - * - * @param thisGroupNum the this group num - * @param nucAcidList the nuc acid list - * @return the int + * Add a group to the structure - return the number of atoms in the structure. + * @param currentGroupIndex the integer indicating the index of the group to be added. + * @return an integer for the number of atoms in the structure. */ - private int addGroup(final int thisGroupNum) { + private int addGroup(final int currentGroupIndex) { // Now get the group - int groupInd = dataApi.getGroupTypeIndices()[thisGroupNum]; + int groupInd = dataApi.getGroupTypeIndices()[currentGroupIndex]; // Get this info int atomCount = dataApi.getNumAtomsInGroup(groupInd); - int currentGroupNumber = dataApi.getGroupIds()[thisGroupNum]; - char insertionCode = dataApi.getInsCodes()[thisGroupNum]; + int currentGroupNumber = dataApi.getGroupIds()[currentGroupIndex]; + char insertionCode = dataApi.getInsCodes()[currentGroupIndex]; structInflator.setGroupInfo(dataApi.getGroupName(groupInd), currentGroupNumber, insertionCode, dataApi.getGroupChemCompType(groupInd), atomCount); // A counter for the atom information @@ -186,9 +182,9 @@ private int addGroup(final int thisGroupNum) { /** * Add atom level data for a given atom. - * @param currentPdbGroup The group being considered. - * @param atomInfo The list of strings containing atom level information. - * @param currentAtomIndex The index of the current Atom + * @param currentPdbGroup the group being considered. + * @param atomInfo the list of strings containing atom level information. + * @param currentAtomIndex the index of the current Atom */ private void addAtomData(String[] atomNames, String[] elementNames, int[] atomCharges, int currentAtomIndex) { // Now get all the relevant atom level information here @@ -227,6 +223,7 @@ private void addGroupBonds(int[] bondInds, int[] bondOrders) { /** * Generate inter group bonds + * Bond indices are specified within the whole structure and start at 0. */ private void addInterGroupBonds() { for (int i = 0; i < dataApi.getInterGroupBondOrders().length; i++) { diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java index dab58bb..0ae7dd7 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java @@ -17,7 +17,6 @@ public ParsingParams() { /** * Checks if is parses the internal chain ids. - * * @return true, if is parses the internal */ public final boolean isParseInternal() { @@ -26,7 +25,6 @@ public final boolean isParseInternal() { /** * Sets whether to parse the internal chain ids. - * * @param ifParseInternal the new parses the internal */ public final void setParseInternal(final boolean ifParseInternal) { diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index ea6a97c..14a99df 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -27,7 +27,6 @@ public SimpleDataApi(byte[] inputByteArr) { try { inputData = new ObjectMapper(new MessagePackFactory()).readValue(inputByteArr, MmtfBean.class); } catch (IOException e) { - // System.err.println("Error converting Byte array to message pack. IOError"); e.printStackTrace(); throw new RuntimeException(); @@ -408,20 +407,6 @@ public String getGroupChemCompType(int groupInd) { return groupMap[groupInd].getChemCompType(); } - - /** - * Get a primitive int[] list from a Java List<>; - * @param inArray The input List<> of Integers - * @return A primitive int[]. - */ - private int[] convertToIntList(List inArray) { - int[] outArray = new int[inArray.size()]; - for (int i=0; i; + * @param inArray The input List<> of Integers + * @return A primitive int[]. + */ + private int[] convertToIntList(List inArray) { + int[] outArray = new int[inArray.size()]; + for (int i=0; i Date: Tue, 5 Apr 2016 17:30:14 -0700 Subject: [PATCH 026/108] Updates to the tests and the fomrating. Some renaming and refactoring. Some changing of whitespace. --- .../TestArrayDecompressor.java | 128 +- .../rcsb/mmtf/decoder/TestDecoderUtils.java | 1 - .../biocompressors/TestBioCompressor.java | 3 - .../mmtf/biocompressors/TestBondFinding.java | 75 - .../mmtf/biojavaencoder/TestBondFinding.java | 79 + .../mmtf/biojavaencoder/TestEncoderUtils.java | 14 +- .../rcsb/mmtf/dataholders/FailureBean.java | 1420 ++++++++--------- .../rcsb/mmtf/gitversion/TestGitVersion.java | 12 +- .../org/rcsb/mmtf/examples/TestHandleIO.java | 125 +- .../rcsb/mmtf/integrationtest/TestBonds.java | 5 + .../mmtf/integrationtest/TestParseMMCif.java | 59 +- .../java/org/rcsb/mmtf/update/TestSpark.java | 5 + 12 files changed, 970 insertions(+), 956 deletions(-) delete mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBondFinding.java create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java index 56176ba..201eb48 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java @@ -20,77 +20,73 @@ */ public class TestArrayDecompressor { - /** The Constant INITIAL_INT. */ - private static final int INITIAL_INT = 3000; + /** The Constant INITIAL_INT. */ + private static final int INITIAL_INT = 3000; - /** The Constant TOTAL_LENGTH. */ - private static final int TOTAL_LENGTH = 100; - - - /** - * Run length decode int test. - * @throws IOException - */ - @Test - public final void runLengthDecodeIntTest() throws IOException { - // Allocate the byte array - byte[] inputData = ByteBuffer.allocate(48).putInt(15).putInt(3).putInt(100).putInt(2).putInt(111).putInt(4).array(); - int[] outPutDataTest = {15,15,15,100,100,111,111,111,111}; - RunLengthDecodeInt runLengthDecodeInt = new RunLengthDecodeInt(); - int[] outPutData = runLengthDecodeInt.decompressByteArray(inputData); - assertArrayEquals(outPutDataTest, outPutData); - } + /** The Constant TOTAL_LENGTH. */ + private static final int TOTAL_LENGTH = 100; - /** - * Run length decode string test. - */ - @Test - public final void runLenghtDecodeStringTest() { - int[] inputData = {66,4,63,2,67,1}; - char[] outPutDataTest = {'B','B','B','B','?','?','C'}; - RunLengthDecodeString runLengthDecodeString = new RunLengthDecodeString(); - char[] outPutData = runLengthDecodeString.intArrayToCharArray(inputData); - assertArrayEquals(outPutDataTest, outPutData); - } - /** - * Delta decompressor test. - * - * @throws IOException Signals that an I/O exception has occurred. - */ - @Test - public final void deltaDecompressorTest() throws IOException { + /** + * Run length decode int test. + * @throws IOException + */ + @Test + public final void runLengthDecodeIntTest() throws IOException { + // Allocate the byte array + byte[] inputData = ByteBuffer.allocate(48).putInt(15).putInt(3).putInt(100).putInt(2).putInt(111).putInt(4).array(); + int[] outPutDataTest = {15,15,15,100,100,111,111,111,111}; + RunLengthDecodeInt runLengthDecodeInt = new RunLengthDecodeInt(); + int[] outPutData = runLengthDecodeInt.decompressByteArray(inputData); + assertArrayEquals(outPutDataTest, outPutData); + } - DeltaDeCompress ddc = new DeltaDeCompress(); - // Now let's generate the byte arrays for the test data - ByteArrayOutputStream bigBos = new ByteArrayOutputStream(); - DataOutputStream bigDos = new DataOutputStream(bigBos); - ByteArrayOutputStream littleBos = new ByteArrayOutputStream(); - DataOutputStream littleDos = new DataOutputStream(littleBos); + /** + * Run length decode string test. + */ + @Test + public final void runLenghtDecodeStringTest() { + int[] inputData = {66,4,63,2,67,1}; + char[] outPutDataTest = {'B','B','B','B','?','?','C'}; + RunLengthDecodeString runLengthDecodeString = new RunLengthDecodeString(); + char[] outPutData = runLengthDecodeString.intArrayToCharArray(inputData); + assertArrayEquals(outPutDataTest, outPutData); + } - // Set the size of the start and lenght of the aray + /** + * Delta decompressor test. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public final void deltaDecompressorTest() throws IOException { - // Make the big byte array - bigDos.writeInt(INITIAL_INT); - bigDos.writeInt(TOTAL_LENGTH); - // Now write the shorts - for (int i = 0; i < TOTAL_LENGTH; i++) { - littleDos.writeShort(1); - } - - // Get the test array - int[] testArray = new int[TOTAL_LENGTH + 1]; - testArray[0] = INITIAL_INT; - int incrementorInt = INITIAL_INT; - for (int i = 1; i < TOTAL_LENGTH + 1; i++) { - incrementorInt += 1; - testArray[i] = incrementorInt; - } - // Now proccess these - int[] outArray = ddc.decompressByteArray(bigBos.toByteArray(), - littleBos.toByteArray()); - // Check if there the same - assertArrayEquals(outArray, testArray); - } + DeltaDeCompress ddc = new DeltaDeCompress(); + // Now let's generate the byte arrays for the test data + ByteArrayOutputStream bigBos = new ByteArrayOutputStream(); + DataOutputStream bigDos = new DataOutputStream(bigBos); + ByteArrayOutputStream littleBos = new ByteArrayOutputStream(); + DataOutputStream littleDos = new DataOutputStream(littleBos); + // Make the big byte array + bigDos.writeInt(INITIAL_INT); + bigDos.writeInt(TOTAL_LENGTH); + // Now write the shorts + for (int i = 0; i < TOTAL_LENGTH; i++) { + littleDos.writeShort(1); + } + // Get the test array + int[] testArray = new int[TOTAL_LENGTH + 1]; + testArray[0] = INITIAL_INT; + int incrementorInt = INITIAL_INT; + for (int i = 1; i < TOTAL_LENGTH + 1; i++) { + incrementorInt += 1; + testArray[i] = incrementorInt; + } + // Now proccess these + int[] outArray = ddc.decompressByteArray(bigBos.toByteArray(), + littleBos.toByteArray()); + // Check if there the same + assertArrayEquals(outArray, testArray); + } } diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java index c222119..40ff81b 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java @@ -27,7 +27,6 @@ public class TestDecoderUtils { @Test public void getChainIdTest() { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); List testList = new ArrayList<>(); //Loop through and add one, two, three and four character strings diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java index 36ce7dd..a064d4b 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java @@ -12,7 +12,6 @@ public class TestBioCompressor { @Test public void floatToInt() { - // CompressDoubles cd = new CompressDoubles(); ArrayList inArray = new ArrayList(); ArrayList testArray = new ArrayList(); @@ -28,8 +27,6 @@ public void floatToInt() { @Test public void doubleToInt() { - - // CompressDoubles cd = new CompressDoubles(); ArrayList inArray = new ArrayList(); ArrayList testArray = new ArrayList(); diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBondFinding.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBondFinding.java deleted file mode 100644 index 3d7802b..0000000 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBondFinding.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.rcsb.mmtf.biocompressors; - -import org.junit.Test; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.List; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Bond; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; - -public class TestBondFinding { - - - @Test - public void testInterGroupBonds() throws IOException, StructureException { - // Normal - assertEquals(getInterBonds("1QMZ"), 2236); - // Disulphide - assertEquals(getInterBonds("2QWO"), 956); - // Covalent ligand - assertEquals(getInterBonds("4QDV"), 2294); - // DNA - assertEquals(getInterBonds("4XSN"), 22); - - } - - public int getInterBonds(String pdbId) throws IOException, StructureException{ - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - cache.setFetchBehavior(FetchBehavior.FETCH_FILES); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - DownloadChemCompProvider dcc = new DownloadChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(dcc); - dcc.checkDoFirstInstall(); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - int counter =0; - // Now get the structure - Structure newStruc = StructureIO.getStructure(pdbId); - // Now loop through the atoms - for(Chain c: newStruc.getChains()){ - for(Group g: c.getAtomGroups()){ - List theseAtoms = g.getAtoms(); - for(Atom a: theseAtoms){ - List theseBonds = a.getBonds(); - if(theseBonds != null){ - for(Bond b: a.getBonds()){ - Atom other = b.getOther(a); - int indexOther = theseAtoms.indexOf(other); - // Check if the index is within the group - if(indexOther<0 || indexOther >= theseAtoms.size()){ - counter++; - } - } - } - } - } - } - return counter; - } -} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java new file mode 100644 index 0000000..23580fc --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java @@ -0,0 +1,79 @@ +package org.rcsb.mmtf.biojavaencoder; + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.List; + +import org.biojava.nbio.structure.Atom; +import org.biojava.nbio.structure.Bond; +import org.biojava.nbio.structure.Chain; +import org.biojava.nbio.structure.Group; +import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; +import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; +import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; + +public class TestBondFinding { + + /** + * Test that the bonds we are finding is consistenty. + * @throws IOException + * @throws StructureException + */ + @Test + public void testInterGroupBonds() throws IOException, StructureException { + // Normal + assertEquals(getInterBonds("1QMZ"), 2236); + // Disulphide + assertEquals(getInterBonds("2QWO"), 956); + // Covalent ligand + assertEquals(getInterBonds("4QDV"), 2294); + // DNA + assertEquals(getInterBonds("4XSN"), 22); + + } + + public int getInterBonds(String pdbId) throws IOException, StructureException{ + AtomCache cache = new AtomCache(); + cache.setUseMmCif(true); + cache.setFetchBehavior(FetchBehavior.FETCH_FILES); + FileParsingParameters params = cache.getFileParsingParams(); + params.setCreateAtomBonds(true); + params.setAlignSeqRes(true); + params.setParseBioAssembly(true); + DownloadChemCompProvider dcc = new DownloadChemCompProvider(); + ChemCompGroupFactory.setChemCompProvider(dcc); + dcc.checkDoFirstInstall(); + cache.setFileParsingParams(params); + StructureIO.setAtomCache(cache); + int counter =0; + // Now get the structure + Structure newStruc = StructureIO.getStructure(pdbId); + // Now loop through the atoms + for(Chain c: newStruc.getChains()){ + for(Group g: c.getAtomGroups()){ + List theseAtoms = g.getAtoms(); + for(Atom a: theseAtoms){ + List theseBonds = a.getBonds(); + if(theseBonds != null){ + for(Bond b: a.getBonds()){ + Atom other = b.getOther(a); + int indexOther = theseAtoms.indexOf(other); + // Check if the index is within the group + if(indexOther<0 || indexOther >= theseAtoms.size()){ + counter++; + } + } + } + } + } + } + return counter; + } +} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestEncoderUtils.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestEncoderUtils.java index dd45d3d..674ae55 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestEncoderUtils.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestEncoderUtils.java @@ -20,7 +20,11 @@ public class TestEncoderUtils { - + /** + * Integration test to see that the microheterogenity is being dealt with correctly. + * @throws IOException + * @throws StructureException + */ @Test public void microHeterogenity() throws IOException, StructureException { EncoderUtils encoderUtils = new EncoderUtils(); @@ -46,7 +50,6 @@ public void microHeterogenity() throws IOException, StructureException { } // Now "fix" the microheterogenity encoderUtils.fixMicroheterogenity(inputStructure); - assertEquals(before, inputStructure.getChains().get(0).getAtomGroup(17)); assertFalse(inputStructure.getChains().get(0).getAtomGroup(17).hasAltLoc()); assertFalse(inputStructure.getChains().get(0).getAtomGroup(18).hasAltLoc()); @@ -64,15 +67,10 @@ public void microHeterogenity() throws IOException, StructureException { } } } - + // Find the atoms after the fix. List totalAtomsAfter = new ArrayList<>(encoderUtils.getAllAtoms(inputStructure)); - System.out.println("Before: "+ totalAtoms.size()); - System.out.println("After: "+ totalAtomsAfter.size()); - System.out.println("Unique before: "+ totAtoms.size()); - System.out.println("Unique after: "+ totAtomsAfter.size()); // Get all of the duplicate atoms Set duplicates = findDuplicates(totalAtomsAfter); - System.out.println(duplicates.size()); for (Atom a : duplicates) { System.out.println(a); } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java index e826975..df8cb4b 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java @@ -13,730 +13,730 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class FailureBean { - /** The mmtf version. */ - private String mmtfVersion = "0.1"; + /** The mmtf version. */ + private String mmtfVersion = "0.1"; - /** The mmtf producer. */ - private String mmtfProducer; + /** The mmtf producer. */ + private String mmtfProducer; - /** The number of bonds. */ - private int numBonds; + /** The number of bonds. */ + private int numBonds; - /** The pdb id. */ - private String pdbId; + /** The pdb id. */ + private String pdbId; - /** The title. */ - private String title; + /** The title. */ + private String title; - /** The number of atoms. */ - private int numAtoms; + /** The number of atoms. */ + private int numAtoms; - /** The number of chains per model. */ - private int[] chainsPerModel; + /** The number of chains per model. */ + private int[] chainsPerModel; - /** The names of the chains. Each chain is allocated four bytes. Chain names can be up to four characters long. 0 bytes indicate the end of the chain name. These are taken from the auth id. */ - private byte[] chainNameList; + /** The names of the chains. Each chain is allocated four bytes. Chain names can be up to four characters long. 0 bytes indicate the end of the chain name. These are taken from the auth id. */ + private byte[] chainNameList; - /** The names of the chains. Each chain is allocated four bytes. Chain names can be up to four characters long. 0 bytes indicate the end of the chain name. These are taken from the asym id. */ - private byte[] chainIdList; + /** The names of the chains. Each chain is allocated four bytes. Chain names can be up to four characters long. 0 bytes indicate the end of the chain name. These are taken from the asym id. */ + private byte[] chainIdList; - /** The internal groups per chain. */ - private int[] groupsPerChain; + /** The internal groups per chain. */ + private int[] groupsPerChain; - /** The space group. */ - private String spaceGroup; + /** The space group. */ + private String spaceGroup; - /** The unit cell. */ - private List unitCell; + /** The unit cell. */ + private List unitCell; - /** The bio assembly. */ - private Map bioAssembly; + /** The bio assembly. */ + private Map bioAssembly; - /** The bond atom (indices) list. */ - private byte[] bondAtomList; + /** The bond atom (indices) list. */ + private byte[] bondAtomList; - /** The bond order list. */ - private byte[] bondOrderList; + /** The bond order list. */ + private byte[] bondOrderList; - /** The group map. */ - // Map of all the data - private Map groupMap; - - /** The x coord big. 4 byte integers in pairs. */ - private byte[] xCoordBig; - - /** The y coord big. 4 byte integers in pairs. */ - private byte[] yCoordBig; - - /** The z coord big. 4 byte integers in pairs. */ - private byte[] zCoordBig; - - /** The b factor big. 4 byte integers in pairs. */ - private byte[] bFactorBig; - - /** The x coord small. 2 byte integers. */ - private byte[] xCoordSmall; - - /** The y coord small. 2 byte integers.*/ - private byte[] yCoordSmall; - - /** The z coord small. 2 byte integers.*/ - private byte[] zCoordSmall; - - /** The b factor small. 2 byte integers.*/ - private byte[] bFactorSmall; - - /** The secondary structure list. Stored as 1 byte ints. */ - private byte[] secStructList; - - /** The occupancy list. */ - private byte[] occList; - - /** The alt label list. */ - private List altLabelList; - - /** The insertion code list. */ - private List insCodeList; - - /** The group type list. */ - private byte[] groupTypeList; - - /** The group id list. Identifies each group along the chain. */ - private byte[] groupIdList; - - /** The atom id list. */ - private byte[] atomIdList; - - /** The SEQRES sequence, per asym chain. */ - private List chainSeqList; - - /** The SeqRes group ids. */ - private byte[] seqResIdList; - - /** The experimental method(s). */ - private List experimentalMethods; - // ADDED FIELDS TO DELIBERATELY FAIL TESTS - @SuppressWarnings("unused") - private List fieldWithNoGetters; - - private List fieldWithRefactoredGetters; - - - /** - * Gets the space group. - * - * @return the space group - */ - public final String getSpaceGroup() { - return spaceGroup; - } - - /** - * Sets the space group. - * - * @param inputSpaceGroup the new space group - */ - public final void setSpaceGroup(final String inputSpaceGroup) { - this.spaceGroup = inputSpaceGroup; - } - - /** - * Gets the unit cell. - * - * @return the unit cell - */ - public final List getUnitCell() { - return unitCell; - } - - /** - * Sets the unit cell. - * - * @param inputUnitCell the new unit cell - */ - public final void setUnitCell(final List inputUnitCell) { - this.unitCell = inputUnitCell; - } - - /** - * Gets the group num list. - * - * @return the group num list - */ - public final byte[] getGroupIdList() { - return groupIdList; - } - - /** - * Sets the group num list. - * - * @param inputGroupNumList the new group num list - */ - public final void setGroupIdList(final byte[] inputGroupNumList) { - this.groupIdList = inputGroupNumList; - } - - /** - * Gets the x coord big. - * - * @return the x coord big - */ - public final byte[] getxCoordBig() { - return xCoordBig; - } - - /** - * Sets the x coord big. - * - * @param inputXCoordBig the new 4 byte integer x coord array - */ - public final void setxCoordBig(final byte[] inputXCoordBig) { - this.xCoordBig = inputXCoordBig; - } - - /** - * Gets the y coord big. - * - * @return the y coord big - */ - public final byte[] getyCoordBig() { - return yCoordBig; - } - - /** - * Sets the y coord big. - * - * @param inputYCoordBig the new 4 byte integer y coord array - */ - public final void setyCoordBig(final byte[] inputYCoordBig) { - this.yCoordBig = inputYCoordBig; - } - - /** - * Gets the z coord big. - * - * @return the z coord big - */ - public final byte[] getzCoordBig() { - return zCoordBig; - } - - /** - * Sets the z coord big. - * - * @param inputZCoordBig the new 4 byte integer z coord array - */ - public final void setzCoordBig(final byte[] inputZCoordBig) { - this.zCoordBig = inputZCoordBig; - } - - /** - * Gets the x coord small. - * - * @return the x coord small - */ - public final byte[] getxCoordSmall() { - return xCoordSmall; - } - - /** - * Sets the x coord small. - * - * @param inputXCoordSmall the new 2 byte integer x coord array - */ - public final void setxCoordSmall(final byte[] inputXCoordSmall) { - this.xCoordSmall = inputXCoordSmall; - } - - /** - * Gets the y coord small. - * - * @return the y coord small - */ - public final byte[] getyCoordSmall() { - return yCoordSmall; - } - - /** - * Sets the y coord small. - * - * @param inputYCoordSmall the new 2 byte integer y coord array - */ - public final void setyCoordSmall(final byte[] inputYCoordSmall) { - this.yCoordSmall = inputYCoordSmall; - } - - /** - * Gets the z coord small. - * - * @return the z coord small - */ - public final byte[] getzCoordSmall() { - return zCoordSmall; - } - - /** - * Sets the z coord small. - * - * @param inputZCoordSmall the new 2 byte integer z coord array - */ - public final void setzCoordSmall(final byte[] inputZCoordSmall) { - this.zCoordSmall = inputZCoordSmall; - } - - /** - * Gets the b factor big. - * - * @return the b factor big - */ - public final byte[] getbFactorBig() { - return bFactorBig; - } - - /** - * Sets the b factor big. - * - * @param inputBigBFactor the new b factor big - */ - public final void setbFactorBig(final byte[] inputBigBFactor) { - this.bFactorBig = inputBigBFactor; - } - - /** - * Gets the b factor small. - * - * @return the b factor small - */ - public final byte[] getbFactorSmall() { - return bFactorSmall; - } - - /** - * Sets the b factor small. - * - * @param inputSmallBFactor the new b factor 2 byte array - */ - public final void setbFactorSmall(final byte[] inputSmallBFactor) { - this.bFactorSmall = inputSmallBFactor; - } - - /** - * Gets the alt label list. - * - * @return the alt label list - */ - public final List getAltLabelList() { - return altLabelList; - } - - /** - * Sets the alt label list. - * - * @param inputAltIdList the new alt id label list - */ - public final void setAltLabelList(final List inputAltIdList) { - this.altLabelList = inputAltIdList; - } - - /** - * Gets the bio assembly. - * - * @return the bio assembly - */ - public final Map getBioAssembly() { - return bioAssembly; - } - - /** - * Gets the chain names. The byte array indicating the (up to four characters) name of the chain. This is taken from the auth id. - * - * @return the chain list - */ - public final byte[] getChainNameList() { - return chainNameList; - } - - /** - * Sets the chain names. The byte array indicating the (up to four characters) name of the chain. This is taken from the auth id. - * - * @param inputChainList the new chain list - */ - public final void setChainNameList(final byte[] inputChainList) { - this.chainNameList = inputChainList; - } - - /** - * Sets the bioassembly information. - * - * @param inputBioAssembly the bio assembly - */ - public final void setBioAssembly(final Map inputBioAssembly) { - this.bioAssembly = inputBioAssembly; - } - - /** - * Gets the num atoms. - * - * @return the num atoms - */ - public final int getNumAtoms() { - return numAtoms; - } - - /** - * Sets the num atoms. - * - * @param inputNumAtoms the new num atoms - */ - public final void setNumAtoms(final int inputNumAtoms) { - this.numAtoms = inputNumAtoms; - } - - /** - * Gets the occ list. - * - * @return the occ list - */ - public final byte[] getOccList() { - return occList; - } - - /** - * Sets the occ list. - * - * @param occupancy the new occ list - */ - public final void setOccList(final byte[] occupancy) { - this.occList = occupancy; - } - - /** - * Gets the insertion code list. - * - * @return the insertion code list - */ - public final List getInsCodeList() { - return insCodeList; - } - - /** - * Sets the ins code list. - * - * @param inputInsertionCodeList the new insertion code list - */ - public final void setInsCodeList(final List inputInsertionCodeList) { - this.insCodeList = inputInsertionCodeList; - } - - /** - * Gets the group map. - * - * @return the group map - */ - public final Map getGroupMap() { - return groupMap; - } - - /** - * Sets the group map. - * - * @param inputGroupMap the group map - */ - public final void setGroupMap(final Map inputGroupMap) { - this.groupMap = inputGroupMap; - } - - /** - * Gets the sec struct list. - * - * @return the sec struct list - */ - public final byte[] getSecStructList() { - return secStructList; - } - - /** - * Sets the sec struct list. - * - * @param secStruct the new sec struct list - */ - public final void setSecStructList(final byte[] secStruct) { - this.secStructList = secStruct; - } - - /** - * Gets the group type list. - * - * @return the group type list - */ - public final byte[] getGroupTypeList() { - return groupTypeList; - } - - /** - * Sets the group type list. - * - * @param resOrder the new group type list - */ - public final void setGroupTypeList(final byte[] resOrder) { - this.groupTypeList = resOrder; - } - - /** - * Gets the atom id list. - * - * @return the atom id list - */ - public final byte[] getAtomIdList() { - return atomIdList; - } - - /** - * Sets the atom id list. - * - * @param inputAtomIdList the new atom id list - */ - public final void setAtomIdList(final byte[] inputAtomIdList) { - this.atomIdList = inputAtomIdList; - } - - /** - * Gets the title. - * - * @return the title - */ - public final String getTitle() { - return title; - } - - /** - * Sets the title. - * - * @param inputTitle the new title - */ - public final void setTitle(final String inputTitle) { - this.title = inputTitle; - } - - /** - * Gets the pdb id. - * - * @return the pdb id - */ - public final String getPdbId() { - return pdbId; - } - - /** - * Sets the pdb id. - * - * @param pdbCode the new pdb id - */ - public final void setPdbId(final String pdbCode) { - this.pdbId = pdbCode; - } - - /** - * Gets the mmtf producer. - * - * @return the mmtf producer - */ - public final String getMmtfProducer() { - return mmtfProducer; - } - - /** - * Sets the mmtf producer. - * - * @param inputMmtfProducer the new mmtf producer - */ - public final void setMmtfProducer(final String inputMmtfProducer) { - this.mmtfProducer = inputMmtfProducer; - } - - /** - * Gets the mmtf version. - * - * @return the mmtf version - */ - public final String getMmtfVersion() { - return mmtfVersion; - } - - /** - * Sets the mmtf version. - * - * @param inputMmtfVersion the new mmtf version - */ - public final void setMmtfVersion(final String inputMmtfVersion) { - this.mmtfVersion = inputMmtfVersion; - } - - /** - * Gets the num bonds. - * - * @return the num bonds - */ - public final int getNumBonds() { - return numBonds; - } - - /** - * Sets the number of bonds. - * - * @param inputNumBonds the new num bonds - */ - public final void setNumBonds(final int inputNumBonds) { - this.numBonds = inputNumBonds; - } - - /** - * Gets the bond atom list. - * - * @return the bond atom list - */ - public final byte[] getBondAtomList() { - return bondAtomList; - } - - /** - * Sets the bond atom list. - * - * @param inputBondAtomList the new bond atom list - */ - public final void setBondAtomList(final byte[] inputBondAtomList) { - this.bondAtomList = inputBondAtomList; - } - - /** - * Gets the bond order list. - * - * @return the bond order list - */ - public final byte[] getBondOrderList() { - return bondOrderList; - } - - /** - * Sets the bond order list. - * - * @param inputBondOrderList the new bond order list - */ - public final void setBondOrderList(final byte[] inputBondOrderList) { - this.bondOrderList = inputBondOrderList; - } - - /** - * Gets the number of chains per model. Chains are currently specified by asym (internal) chain ids. - * - * @return the list of chains per model. - */ - public final int[] getChainsPerModel() { - return chainsPerModel; - } - - /** - * Sets the number of chains per model. Currently specified by asy (internal) chain ids. - * - * @param inputInternalChainsPerModel the new list of chains per model. - */ - public final void setChainsPerModel(final int[] - inputInternalChainsPerModel) { - this.chainsPerModel = inputInternalChainsPerModel; - } - - /** - * Gets the number of groups per chain. - * - * @return the internal groups per chain - */ - public final int[] getGroupsPerChain() { - return groupsPerChain; - } - - /** - * Sets the number of groups in a chain. - * - * @param inputGroupsPerChain the new internal groups per chain - */ - public final void setGroupsPerChain(final int[] - inputGroupsPerChain) { - this.groupsPerChain = inputGroupsPerChain; - } - - /** - * Gets the internal chain list. - * - * @return the internal chain list - */ - public final byte[] getChainIdList() { - return chainIdList; - } - - /** - * Sets the internal chain list. - * - * @param inputInternalChainList the new internal chain list - */ - public final void setChainIdList(final byte[] inputInternalChainList) { - this.chainIdList = inputInternalChainList; - } - - /** - * @return the experimental methods - */ - public List getExperimentalMethods() { - return experimentalMethods; - } - - /** - * @param experimentalMethods the experimental methods to set - */ - public void setExperimentalMethods(List experimentalMethods) { - this.experimentalMethods = experimentalMethods; - } - - /** - * @return the sequence on a per (asym) chain level. - */ - public List getChainSeqList() { - return chainSeqList; - } - - /** - * @param sequence the list of strings (sequences per asym chain) to set. - */ - public void setChainSeqList(List sequence) { - this.chainSeqList = sequence; - } - - /** - * @return the seqResGroupIds - */ - public byte[] getSeqResIdList() { - return seqResIdList; - } - - /** - * @param seqResGroupIds the seqResGroupIds to set - */ - public void setSeqResIdList(byte[] seqResGroupIds) { - this.seqResIdList = seqResGroupIds; - } - - /** - * @return the fieldWithGetters - */ - public List getFieldWithGetters() { - return fieldWithRefactoredGetters; - } - - /** - * @param fieldWithGetters the fieldWithGetters to set - */ - public void setFieldWithGetters(List fieldWithGetters) { - this.fieldWithRefactoredGetters = fieldWithGetters; - } + /** The group map. */ + // Map of all the data + private Map groupMap; + + /** The x coord big. 4 byte integers in pairs. */ + private byte[] xCoordBig; + + /** The y coord big. 4 byte integers in pairs. */ + private byte[] yCoordBig; + + /** The z coord big. 4 byte integers in pairs. */ + private byte[] zCoordBig; + + /** The b factor big. 4 byte integers in pairs. */ + private byte[] bFactorBig; + + /** The x coord small. 2 byte integers. */ + private byte[] xCoordSmall; + + /** The y coord small. 2 byte integers.*/ + private byte[] yCoordSmall; + + /** The z coord small. 2 byte integers.*/ + private byte[] zCoordSmall; + + /** The b factor small. 2 byte integers.*/ + private byte[] bFactorSmall; + + /** The secondary structure list. Stored as 1 byte ints. */ + private byte[] secStructList; + + /** The occupancy list. */ + private byte[] occList; + + /** The alt label list. */ + private List altLabelList; + + /** The insertion code list. */ + private List insCodeList; + + /** The group type list. */ + private byte[] groupTypeList; + + /** The group id list. Identifies each group along the chain. */ + private byte[] groupIdList; + + /** The atom id list. */ + private byte[] atomIdList; + + /** The SEQRES sequence, per asym chain. */ + private List chainSeqList; + + /** The SeqRes group ids. */ + private byte[] seqResIdList; + + /** The experimental method(s). */ + private List experimentalMethods; + // ADDED FIELDS TO DELIBERATELY FAIL TESTS + @SuppressWarnings("unused") + private List fieldWithNoGetters; + + private List fieldWithRefactoredGetters; + + + /** + * Gets the space group. + * + * @return the space group + */ + public final String getSpaceGroup() { + return spaceGroup; + } + + /** + * Sets the space group. + * + * @param inputSpaceGroup the new space group + */ + public final void setSpaceGroup(final String inputSpaceGroup) { + this.spaceGroup = inputSpaceGroup; + } + + /** + * Gets the unit cell. + * + * @return the unit cell + */ + public final List getUnitCell() { + return unitCell; + } + + /** + * Sets the unit cell. + * + * @param inputUnitCell the new unit cell + */ + public final void setUnitCell(final List inputUnitCell) { + this.unitCell = inputUnitCell; + } + + /** + * Gets the group num list. + * + * @return the group num list + */ + public final byte[] getGroupIdList() { + return groupIdList; + } + + /** + * Sets the group num list. + * + * @param inputGroupNumList the new group num list + */ + public final void setGroupIdList(final byte[] inputGroupNumList) { + this.groupIdList = inputGroupNumList; + } + + /** + * Gets the x coord big. + * + * @return the x coord big + */ + public final byte[] getxCoordBig() { + return xCoordBig; + } + + /** + * Sets the x coord big. + * + * @param inputXCoordBig the new 4 byte integer x coord array + */ + public final void setxCoordBig(final byte[] inputXCoordBig) { + this.xCoordBig = inputXCoordBig; + } + + /** + * Gets the y coord big. + * + * @return the y coord big + */ + public final byte[] getyCoordBig() { + return yCoordBig; + } + + /** + * Sets the y coord big. + * + * @param inputYCoordBig the new 4 byte integer y coord array + */ + public final void setyCoordBig(final byte[] inputYCoordBig) { + this.yCoordBig = inputYCoordBig; + } + + /** + * Gets the z coord big. + * + * @return the z coord big + */ + public final byte[] getzCoordBig() { + return zCoordBig; + } + + /** + * Sets the z coord big. + * + * @param inputZCoordBig the new 4 byte integer z coord array + */ + public final void setzCoordBig(final byte[] inputZCoordBig) { + this.zCoordBig = inputZCoordBig; + } + + /** + * Gets the x coord small. + * + * @return the x coord small + */ + public final byte[] getxCoordSmall() { + return xCoordSmall; + } + + /** + * Sets the x coord small. + * + * @param inputXCoordSmall the new 2 byte integer x coord array + */ + public final void setxCoordSmall(final byte[] inputXCoordSmall) { + this.xCoordSmall = inputXCoordSmall; + } + + /** + * Gets the y coord small. + * + * @return the y coord small + */ + public final byte[] getyCoordSmall() { + return yCoordSmall; + } + + /** + * Sets the y coord small. + * + * @param inputYCoordSmall the new 2 byte integer y coord array + */ + public final void setyCoordSmall(final byte[] inputYCoordSmall) { + this.yCoordSmall = inputYCoordSmall; + } + + /** + * Gets the z coord small. + * + * @return the z coord small + */ + public final byte[] getzCoordSmall() { + return zCoordSmall; + } + + /** + * Sets the z coord small. + * + * @param inputZCoordSmall the new 2 byte integer z coord array + */ + public final void setzCoordSmall(final byte[] inputZCoordSmall) { + this.zCoordSmall = inputZCoordSmall; + } + + /** + * Gets the b factor big. + * + * @return the b factor big + */ + public final byte[] getbFactorBig() { + return bFactorBig; + } + + /** + * Sets the b factor big. + * + * @param inputBigBFactor the new b factor big + */ + public final void setbFactorBig(final byte[] inputBigBFactor) { + this.bFactorBig = inputBigBFactor; + } + + /** + * Gets the b factor small. + * + * @return the b factor small + */ + public final byte[] getbFactorSmall() { + return bFactorSmall; + } + + /** + * Sets the b factor small. + * + * @param inputSmallBFactor the new b factor 2 byte array + */ + public final void setbFactorSmall(final byte[] inputSmallBFactor) { + this.bFactorSmall = inputSmallBFactor; + } + + /** + * Gets the alt label list. + * + * @return the alt label list + */ + public final List getAltLabelList() { + return altLabelList; + } + + /** + * Sets the alt label list. + * + * @param inputAltIdList the new alt id label list + */ + public final void setAltLabelList(final List inputAltIdList) { + this.altLabelList = inputAltIdList; + } + + /** + * Gets the bio assembly. + * + * @return the bio assembly + */ + public final Map getBioAssembly() { + return bioAssembly; + } + + /** + * Gets the chain names. The byte array indicating the (up to four characters) name of the chain. This is taken from the auth id. + * + * @return the chain list + */ + public final byte[] getChainNameList() { + return chainNameList; + } + + /** + * Sets the chain names. The byte array indicating the (up to four characters) name of the chain. This is taken from the auth id. + * + * @param inputChainList the new chain list + */ + public final void setChainNameList(final byte[] inputChainList) { + this.chainNameList = inputChainList; + } + + /** + * Sets the bioassembly information. + * + * @param inputBioAssembly the bio assembly + */ + public final void setBioAssembly(final Map inputBioAssembly) { + this.bioAssembly = inputBioAssembly; + } + + /** + * Gets the num atoms. + * + * @return the num atoms + */ + public final int getNumAtoms() { + return numAtoms; + } + + /** + * Sets the num atoms. + * + * @param inputNumAtoms the new num atoms + */ + public final void setNumAtoms(final int inputNumAtoms) { + this.numAtoms = inputNumAtoms; + } + + /** + * Gets the occ list. + * + * @return the occ list + */ + public final byte[] getOccList() { + return occList; + } + + /** + * Sets the occ list. + * + * @param occupancy the new occ list + */ + public final void setOccList(final byte[] occupancy) { + this.occList = occupancy; + } + + /** + * Gets the insertion code list. + * + * @return the insertion code list + */ + public final List getInsCodeList() { + return insCodeList; + } + + /** + * Sets the ins code list. + * + * @param inputInsertionCodeList the new insertion code list + */ + public final void setInsCodeList(final List inputInsertionCodeList) { + this.insCodeList = inputInsertionCodeList; + } + + /** + * Gets the group map. + * + * @return the group map + */ + public final Map getGroupMap() { + return groupMap; + } + + /** + * Sets the group map. + * + * @param inputGroupMap the group map + */ + public final void setGroupMap(final Map inputGroupMap) { + this.groupMap = inputGroupMap; + } + + /** + * Gets the sec struct list. + * + * @return the sec struct list + */ + public final byte[] getSecStructList() { + return secStructList; + } + + /** + * Sets the sec struct list. + * + * @param secStruct the new sec struct list + */ + public final void setSecStructList(final byte[] secStruct) { + this.secStructList = secStruct; + } + + /** + * Gets the group type list. + * + * @return the group type list + */ + public final byte[] getGroupTypeList() { + return groupTypeList; + } + + /** + * Sets the group type list. + * + * @param resOrder the new group type list + */ + public final void setGroupTypeList(final byte[] resOrder) { + this.groupTypeList = resOrder; + } + + /** + * Gets the atom id list. + * + * @return the atom id list + */ + public final byte[] getAtomIdList() { + return atomIdList; + } + + /** + * Sets the atom id list. + * + * @param inputAtomIdList the new atom id list + */ + public final void setAtomIdList(final byte[] inputAtomIdList) { + this.atomIdList = inputAtomIdList; + } + + /** + * Gets the title. + * + * @return the title + */ + public final String getTitle() { + return title; + } + + /** + * Sets the title. + * + * @param inputTitle the new title + */ + public final void setTitle(final String inputTitle) { + this.title = inputTitle; + } + + /** + * Gets the pdb id. + * + * @return the pdb id + */ + public final String getPdbId() { + return pdbId; + } + + /** + * Sets the pdb id. + * + * @param pdbCode the new pdb id + */ + public final void setPdbId(final String pdbCode) { + this.pdbId = pdbCode; + } + + /** + * Gets the mmtf producer. + * + * @return the mmtf producer + */ + public final String getMmtfProducer() { + return mmtfProducer; + } + + /** + * Sets the mmtf producer. + * + * @param inputMmtfProducer the new mmtf producer + */ + public final void setMmtfProducer(final String inputMmtfProducer) { + this.mmtfProducer = inputMmtfProducer; + } + + /** + * Gets the mmtf version. + * + * @return the mmtf version + */ + public final String getMmtfVersion() { + return mmtfVersion; + } + + /** + * Sets the mmtf version. + * + * @param inputMmtfVersion the new mmtf version + */ + public final void setMmtfVersion(final String inputMmtfVersion) { + this.mmtfVersion = inputMmtfVersion; + } + + /** + * Gets the num bonds. + * + * @return the num bonds + */ + public final int getNumBonds() { + return numBonds; + } + + /** + * Sets the number of bonds. + * + * @param inputNumBonds the new num bonds + */ + public final void setNumBonds(final int inputNumBonds) { + this.numBonds = inputNumBonds; + } + + /** + * Gets the bond atom list. + * + * @return the bond atom list + */ + public final byte[] getBondAtomList() { + return bondAtomList; + } + + /** + * Sets the bond atom list. + * + * @param inputBondAtomList the new bond atom list + */ + public final void setBondAtomList(final byte[] inputBondAtomList) { + this.bondAtomList = inputBondAtomList; + } + + /** + * Gets the bond order list. + * + * @return the bond order list + */ + public final byte[] getBondOrderList() { + return bondOrderList; + } + + /** + * Sets the bond order list. + * + * @param inputBondOrderList the new bond order list + */ + public final void setBondOrderList(final byte[] inputBondOrderList) { + this.bondOrderList = inputBondOrderList; + } + + /** + * Gets the number of chains per model. Chains are currently specified by asym (internal) chain ids. + * + * @return the list of chains per model. + */ + public final int[] getChainsPerModel() { + return chainsPerModel; + } + + /** + * Sets the number of chains per model. Currently specified by asy (internal) chain ids. + * + * @param inputInternalChainsPerModel the new list of chains per model. + */ + public final void setChainsPerModel(final int[] + inputInternalChainsPerModel) { + this.chainsPerModel = inputInternalChainsPerModel; + } + + /** + * Gets the number of groups per chain. + * + * @return the internal groups per chain + */ + public final int[] getGroupsPerChain() { + return groupsPerChain; + } + + /** + * Sets the number of groups in a chain. + * + * @param inputGroupsPerChain the new internal groups per chain + */ + public final void setGroupsPerChain(final int[] + inputGroupsPerChain) { + this.groupsPerChain = inputGroupsPerChain; + } + + /** + * Gets the internal chain list. + * + * @return the internal chain list + */ + public final byte[] getChainIdList() { + return chainIdList; + } + + /** + * Sets the internal chain list. + * + * @param inputInternalChainList the new internal chain list + */ + public final void setChainIdList(final byte[] inputInternalChainList) { + this.chainIdList = inputInternalChainList; + } + + /** + * @return the experimental methods + */ + public List getExperimentalMethods() { + return experimentalMethods; + } + + /** + * @param experimentalMethods the experimental methods to set + */ + public void setExperimentalMethods(List experimentalMethods) { + this.experimentalMethods = experimentalMethods; + } + + /** + * @return the sequence on a per (asym) chain level. + */ + public List getChainSeqList() { + return chainSeqList; + } + + /** + * @param sequence the list of strings (sequences per asym chain) to set. + */ + public void setChainSeqList(List sequence) { + this.chainSeqList = sequence; + } + + /** + * @return the seqResGroupIds + */ + public byte[] getSeqResIdList() { + return seqResIdList; + } + + /** + * @param seqResGroupIds the seqResGroupIds to set + */ + public void setSeqResIdList(byte[] seqResGroupIds) { + this.seqResIdList = seqResGroupIds; + } + + /** + * @return the fieldWithGetters + */ + public List getFieldWithGetters() { + return fieldWithRefactoredGetters; + } + + /** + * @param fieldWithGetters the fieldWithGetters to set + */ + public void setFieldWithGetters(List fieldWithGetters) { + this.fieldWithRefactoredGetters = fieldWithGetters; + } } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java index e1ec6ae..d695895 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java @@ -8,11 +8,11 @@ public class TestGitVersion { - - @Test - public void doesGitVersionExist(){ - GetRepoState getCurrentVersion = new GetRepoState(); - assertNotEquals("NA", getCurrentVersion.getCurrentVersion()); - } + + @Test + public void doesGitVersionExist(){ + GetRepoState getCurrentVersion = new GetRepoState(); + assertNotEquals("NA", getCurrentVersion.getCurrentVersion()); + } } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java b/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java index fe59508..3131293 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java @@ -11,66 +11,71 @@ import static org.junit.Assert.assertArrayEquals; +/** + * Test that the file IO is being dealt with appropriately. + * @author Anthony Bradley + * + */ public class TestHandleIO { - private HandleIO handleIo; - - public TestHandleIO() { - // Generate this utility class - handleIo = new HandleIO(); - } - - - /** - * Basic test of being able to reach the server and get a byte array back - * @throws IOException - */ - @Test - public void testGetFileFromServer() throws IOException { - - // Get the base url - byte[] inputArr = handleIo.getFromUrl("4cup"); - assertNotEquals(inputArr, null); - assertNotEquals(inputArr.length, 1); - assertNotEquals(inputArr.length, 0); - // Get the base url - byte[] inputArrTwo = handleIo.getFromUrl("4cup"); - assertArrayEquals(inputArr, inputArrTwo); - // What if we give an nonsense PDB code - byte[] inputArrThree = handleIo.getFromUrl("12345"); - assertEquals(inputArrThree, null); - } - - /** - * Test whether we can read write the files where we want - */ - @Test - public void testReadWriteFiles() { - - IntegrationTestUtils integrationTestUtils = new IntegrationTestUtils(); - Path tmpDir = integrationTestUtils.returnTempDir(); - // If we set it as the tmp directory - System.setProperty("PDB_CACHE_DIR", tmpDir.toAbsolutePath().toString()); - // The input code - String inputCode = "4cup"; - // If we don't set where the cache is this should be empty - assertEquals(handleIo.getFromFile(inputCode), null); - byte[] urlData = handleIo.getByteArrFromUrlOrFile(inputCode); - byte[] fileData = handleIo.getFromFile(inputCode); - // First check neither are null - assertNotEquals(urlData, null); - assertNotEquals(fileData, null); - // Now check they are the same - assertArrayEquals(urlData, fileData); - } - - /** - * Test whether we can update files from the server and the updated file is created. - * Not implemented yet. As functionality isn't there. - */ - @Test - public void testUpdateFiles() { - - } - + private HandleIO handleIo; + + public TestHandleIO() { + // Generate this utility class + handleIo = new HandleIO(); + } + + + /** + * Basic test of being able to reach the server and get a byte array back + * @throws IOException + */ + @Test + public void testGetFileFromServer() throws IOException { + + // Get the base url + byte[] inputArr = handleIo.getFromUrl("4cup"); + assertNotEquals(inputArr, null); + assertNotEquals(inputArr.length, 1); + assertNotEquals(inputArr.length, 0); + // Get the base url + byte[] inputArrTwo = handleIo.getFromUrl("4cup"); + assertArrayEquals(inputArr, inputArrTwo); + // What if we give an nonsense PDB code + byte[] inputArrThree = handleIo.getFromUrl("12345"); + assertEquals(inputArrThree, null); + } + + /** + * Test whether we can read write the files where we want + */ + @Test + public void testReadWriteFiles() { + + IntegrationTestUtils integrationTestUtils = new IntegrationTestUtils(); + Path tmpDir = integrationTestUtils.returnTempDir(); + // If we set it as the tmp directory + System.setProperty("PDB_CACHE_DIR", tmpDir.toAbsolutePath().toString()); + // The input code + String inputCode = "4cup"; + // If we don't set where the cache is this should be empty + assertEquals(handleIo.getFromFile(inputCode), null); + byte[] urlData = handleIo.getByteArrFromUrlOrFile(inputCode); + byte[] fileData = handleIo.getFromFile(inputCode); + // First check neither are null + assertNotEquals(urlData, null); + assertNotEquals(fileData, null); + // Now check they are the same + assertArrayEquals(urlData, fileData); + } + + /** + * Test whether we can update files from the server and the updated file is created. + * Not implemented yet. As functionality isn't there. + */ + @Test + public void testUpdateFiles() { + + } + } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java index fbd75d7..545444b 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java @@ -10,6 +10,11 @@ import org.rcsb.mmtf.testutils.CheckBonds; import org.rcsb.mmtf.update.IntegrationTestUtils; +/** + * Tests to see that all bonds are being generated using Biojava. + * @author Anthony Bradley + * + */ public class TestBonds { diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java index 87af822..59b5b73 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java @@ -12,36 +12,41 @@ import org.rcsb.mmtf.update.IntegrationTestUtils; import org.rcsb.mmtf.update.TestingUtils; +/** + * Tests to see if parsing using Biojava using mmCIF and mmtf produces the same data structure. + * @author Anthony Bradley + * + */ public class TestParseMMCif { - private AtomCache cache; - private FileParsingParameters params; - private TestingUtils testingUtils = new TestingUtils(); + private AtomCache cache; + private FileParsingParameters params; + private TestingUtils testingUtils = new TestingUtils(); - public TestParseMMCif(){ + public TestParseMMCif(){ // Set up the atom cache etc - EncoderUtils encoderUtils = new EncoderUtils(); - cache = encoderUtils.setUpBioJava(); - params = cache.getFileParsingParams(); - } - - - @Test - public void testAsymChainIds() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { - // Set the params - params.setUseInternalChainId(true); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); - } - - @Test - public void testAuthChainIds() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { - // Set the param - params.setUseInternalChainId(false); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); - } + EncoderUtils encoderUtils = new EncoderUtils(); + cache = encoderUtils.setUpBioJava(); + params = cache.getFileParsingParams(); + } + + + @Test + public void testAsymChainIds() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { + // Set the params + params.setUseInternalChainId(true); + cache.setFileParsingParams(params); + StructureIO.setAtomCache(cache); + testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); + } + + @Test + public void testAuthChainIds() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { + // Set the param + params.setUseInternalChainId(false); + cache.setFileParsingParams(params); + StructureIO.setAtomCache(cache); + testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); + } } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java b/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java index 6aa010f..ba84f66 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java @@ -5,6 +5,11 @@ import static org.junit.Assert.*; import org.junit.Test; +/** + * Tests to see if Sparks can be launched succesfully. + * @author Anthony Bradley + * + */ public class TestSpark { JavaSparkContext sc; From a00e19ee7754a1bf905cf670f7d592340ff9c247 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 17:33:11 -0700 Subject: [PATCH 027/108] Update the gitignore to track the file generated by mmtf-update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 77a6522..2bbf215 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.project *.swp release.* +mmtf-update/pathname From 72e13586787110944487691060bac79316c1d3a6 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 17:58:32 -0700 Subject: [PATCH 028/108] White space moving --- .../mmtf/dataholders/TestDataHolders.java | 270 +++++++++--------- 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index bd2572d..295aace 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -30,141 +30,141 @@ public class TestDataHolders { - private EncoderUtils encoderUtils; - private PodamFactory factory; - private AtomCache cache; - private FileParsingParameters params; - - public TestDataHolders() { - encoderUtils = new EncoderUtils(); - factory = new PodamFactoryImpl(); - cache = new AtomCache(); - cache.setUseMmCif(true); - cache.setFetchBehavior(FetchBehavior.FETCH_FILES); - params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - DownloadChemCompProvider dcc = new DownloadChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(dcc); - dcc.setDownloadAll(true); - dcc.checkDoFirstInstall(); - params.setUseInternalChainId(true); - } - - @Test - public void testSerializable() throws JsonParseException, JsonMappingException, IOException { - // MmtfBean - assertTrue(testClass(MmtfBean.class)); - // This one fails - make sure it still does - assertFalse(testClass(BioAssemblyInfo.class)); - // The bean to store calpha data - assertTrue(testClass(CalphaDistBean.class)); - // Now consider the no float data stucuture class - assertTrue(testClass(NoFloatDataStruct.class)); - // Now consider the no bio data structure bean - assertTrue(testClass(BioDataStructBean.class)); - // And the calpha bean - assertTrue(testClass(CalphaBean.class)); - // Now test round tripping data - testDataRoundTrip(MmtfBean.class); - // Now test if all fields in the mmtf are generated - testDataComplete("4cup"); - // Now check that the failure bean fails this - // Now test round tripping data - assertFalse(testDataRoundTrip(FailureBean.class)); - } - - @SuppressWarnings("unchecked") - private boolean testClass(@SuppressWarnings("rawtypes") Class class1) throws IOException { - - - Object inBean = null; - try { - inBean = class1.newInstance(); - } catch (InstantiationException | IllegalAccessException e2) { - // Weirdness - org.junit.Assert.fail("Weirdness in generating instance of generic class"); - } - byte[] outArr = null; - - outArr = encoderUtils.getMessagePack(inBean); - - // - Object outBean = null; - try { - outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); - } catch( JsonMappingException jsonE){ - System.out.println("Error reading messagepack - is part of test if test doesn't fail"); - return false; - } - - // Now check they're the same - ReflectionAssert.assertReflectionEquals(inBean, outBean); - return true; - } - - @SuppressWarnings("unchecked") - /** - * Test round tripping dummy data - * @param class1 - */ - private boolean testDataRoundTrip(@SuppressWarnings("rawtypes") Class class1) throws JsonParseException, JsonMappingException, IOException { - Object inBean = factory.manufacturePojo(class1); - byte[] outArr = null; - - outArr = encoderUtils.getMessagePack(inBean); - - - // - Object outBean = null; - outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); - - // Make the failure bean fail - try{ - ReflectionAssert.assertPropertyReflectionEquals("fieldWithNoGetters",null, outBean); - ReflectionAssert.assertPropertyReflectionEquals("fieldWithRefactoredGetters",null, outBean); - return false; - } - catch(Exception e){ - - } - // Make sure all fields are re-populated - ReflectionAssert.assertPropertiesNotNull("Some properties are null in re-read object", outBean); - - // Now check they're the same - ReflectionAssert.assertReflectionEquals(inBean, outBean); - return true; - } - - /** - * A specific mmtf test - to make sure none of the fields are empty when the thing is encoded - * @throws StructureException - * @throws IOException - */ - private void testDataComplete(String pdbId) throws IOException { - - // Utility functions for encoding stuff - EncoderUtils eu = new EncoderUtils(); - // Get the utility class to get the structures - ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); - Map totMap = new HashMap(); - // Parse the data into the basic data structure - parsedDataStruct.createFromJavaStruct(pdbId, totMap); - MmtfBean mmtfBean = null; - // Compress the data and get it back out - mmtfBean = eu.compressMainData(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); - // Make sure all fields are re-populated - ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); - // Now check the standard ones have been set - assertNotEquals(mmtfBean.getResolution(), (float) -1.0); - assertNotEquals(mmtfBean.getrFree(), (float) -1.0); - // Check that these integer values are set - assertNotEquals(mmtfBean.getNumAtoms(), -1); - assertNotEquals(mmtfBean.getNumBonds(), -1); - // And finally - check this is working - assertNotEquals(mmtfBean.getMmtfProducer(), "NA"); - } + private EncoderUtils encoderUtils; + private PodamFactory factory; + private AtomCache cache; + private FileParsingParameters params; + + public TestDataHolders() { + encoderUtils = new EncoderUtils(); + factory = new PodamFactoryImpl(); + cache = new AtomCache(); + cache.setUseMmCif(true); + cache.setFetchBehavior(FetchBehavior.FETCH_FILES); + params = cache.getFileParsingParams(); + params.setCreateAtomBonds(true); + params.setAlignSeqRes(true); + params.setParseBioAssembly(true); + DownloadChemCompProvider dcc = new DownloadChemCompProvider(); + ChemCompGroupFactory.setChemCompProvider(dcc); + dcc.setDownloadAll(true); + dcc.checkDoFirstInstall(); + params.setUseInternalChainId(true); + } + + @Test + public void testSerializable() throws JsonParseException, JsonMappingException, IOException { + // MmtfBean + assertTrue(testClass(MmtfBean.class)); + // This one fails - make sure it still does + assertFalse(testClass(BioAssemblyInfo.class)); + // The bean to store calpha data + assertTrue(testClass(CalphaDistBean.class)); + // Now consider the no float data stucuture class + assertTrue(testClass(NoFloatDataStruct.class)); + // Now consider the no bio data structure bean + assertTrue(testClass(BioDataStructBean.class)); + // And the calpha bean + assertTrue(testClass(CalphaBean.class)); + // Now test round tripping data + testDataRoundTrip(MmtfBean.class); + // Now test if all fields in the mmtf are generated + testDataComplete("4cup"); + // Now check that the failure bean fails this + // Now test round tripping data + assertFalse(testDataRoundTrip(FailureBean.class)); + } + + @SuppressWarnings("unchecked") + private boolean testClass(@SuppressWarnings("rawtypes") Class class1) throws IOException { + + + Object inBean = null; + try { + inBean = class1.newInstance(); + } catch (InstantiationException | IllegalAccessException e2) { + // Weirdness + org.junit.Assert.fail("Weirdness in generating instance of generic class"); + } + byte[] outArr = null; + + outArr = encoderUtils.getMessagePack(inBean); + + // + Object outBean = null; + try { + outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); + } catch( JsonMappingException jsonE){ + System.out.println("Error reading messagepack - is part of test if test doesn't fail"); + return false; + } + + // Now check they're the same + ReflectionAssert.assertReflectionEquals(inBean, outBean); + return true; + } + + @SuppressWarnings("unchecked") + /** + * Test round tripping dummy data + * @param class1 + */ + private boolean testDataRoundTrip(@SuppressWarnings("rawtypes") Class class1) throws JsonParseException, JsonMappingException, IOException { + Object inBean = factory.manufacturePojo(class1); + byte[] outArr = null; + + outArr = encoderUtils.getMessagePack(inBean); + + + // + Object outBean = null; + outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); + + // Make the failure bean fail + try{ + ReflectionAssert.assertPropertyReflectionEquals("fieldWithNoGetters",null, outBean); + ReflectionAssert.assertPropertyReflectionEquals("fieldWithRefactoredGetters",null, outBean); + return false; + } + catch(Exception e){ + + } + // Make sure all fields are re-populated + ReflectionAssert.assertPropertiesNotNull("Some properties are null in re-read object", outBean); + + // Now check they're the same + ReflectionAssert.assertReflectionEquals(inBean, outBean); + return true; + } + + /** + * A specific mmtf test - to make sure none of the fields are empty when the thing is encoded + * @throws StructureException + * @throws IOException + */ + private void testDataComplete(String pdbId) throws IOException { + + // Utility functions for encoding stuff + EncoderUtils eu = new EncoderUtils(); + // Get the utility class to get the structures + ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); + Map totMap = new HashMap(); + // Parse the data into the basic data structure + parsedDataStruct.createFromJavaStruct(pdbId, totMap); + MmtfBean mmtfBean = null; + // Compress the data and get it back out + mmtfBean = eu.compressMainData(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); + // Make sure all fields are re-populated + ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); + // Now check the standard ones have been set + assertNotEquals(mmtfBean.getResolution(), (float) -1.0); + assertNotEquals(mmtfBean.getrFree(), (float) -1.0); + // Check that these integer values are set + assertNotEquals(mmtfBean.getNumAtoms(), -1); + assertNotEquals(mmtfBean.getNumBonds(), -1); + // And finally - check this is working + assertNotEquals(mmtfBean.getMmtfProducer(), "NA"); + } } From f6ea3bdfacf87faf9e7c49f424639cff9b39a8dd Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 19:07:43 -0700 Subject: [PATCH 029/108] Added a demo of using the DataApi to move through a structure. --- .../mmtf/api/MmtfDecodedDataInterface.java | 7 +-- .../mmtf/examples/DemoUnpackStructure.java | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index 35cdd23..e17697d 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -234,9 +234,10 @@ public interface MmtfDecodedDataInterface { /** * Returns a 4x4 transformation matrix for the given transformation for the given bioassembly. - * TODO is it column-packed or row-packed, we should use vecmath's convention + * It is row-packed as per the convention of vecmath. (The first four elements are in the first row of the + * overall matrix). * @param an integer specifying the bioassembly index (zero indexed). - * @param an integer specifying the index (zero indexed) for the desired transformation. + * @param an integer specifying the index for the desired transformation (zero indexed). * @return the transformation matrix for this transformation. */ double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex); @@ -358,7 +359,7 @@ public interface MmtfDecodedDataInterface { /** * Returns the title of the structure. - * @return + * @return the title of the structure. */ String getTitle(); diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java new file mode 100644 index 0000000..ad892fb --- /dev/null +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java @@ -0,0 +1,47 @@ +package org.rcsb.mmtf.examples; + +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; + +/** + * Demonstration of how to unpack a given structure using the dataApi. + * @author Anthony Bradley + * + */ +public class DemoUnpackStructure { + + + public static void main(String[] args) { + // Create an instance of the handle IO class + HandleIO handleIO = new HandleIO(); + // The index of a given chain + int chainIndex = 0; + int groupIndex = 0; + int atomIndex = 0; + // Create the instance of this API + MmtfDecodedDataInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); + // Now loop through the models + for (int modelIndex=0; modelIndex Date: Tue, 5 Apr 2016 19:17:26 -0700 Subject: [PATCH 030/108] Some refactoring of the demo --- .../mmtf/examples/DemoUnpackStructure.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java index ad892fb..ad346a9 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java @@ -9,31 +9,38 @@ */ public class DemoUnpackStructure { - + /** + * Main function to run the demo class + * @param args no args required + */ public static void main(String[] args) { // Create an instance of the handle IO class HandleIO handleIO = new HandleIO(); // The index of a given chain int chainIndex = 0; int groupIndex = 0; - int atomIndex = 0; - // Create the instance of this API + int structureAtomIndex = 0; + // Create the instance of this API - in this case for the 4cup structure's data. MmtfDecodedDataInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); // Now loop through the models for (int modelIndex=0; modelIndex Date: Tue, 5 Apr 2016 19:28:33 -0700 Subject: [PATCH 031/108] Updated the MMTF bean altLabelList to altLocList --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index cb90324..30129c9 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -107,8 +107,8 @@ public class MmtfBean implements Serializable { /** The occupancy list. */ private byte[] occupancyList; - /** The alt label list. */ - private int[] altLabelList; + /** The list of alternate location ids. */ + private int[] altLocList; /** The insertion code list. */ private int[] insCodeList; @@ -420,21 +420,21 @@ public final void setbFactorSmall(final byte[] inputSmallBFactor) { } /** - * Gets the alt label list. + * Gets the alternate location list. * - * @return the alt label list + * @return the alternate location list */ - public final int[] getAltLabelList() { - return altLabelList; + public final int[] getAltLocList() { + return altLocList; } /** * Sets the alt label list. * - * @param inputAltIdList the new alt id label list + * @param inputAltLocList the new alternation location label list */ - public final void setAltLabelList(final int[] inputAltIdList) { - this.altLabelList = inputAltIdList; + public final void setAltLocList(final int[] inputAltLocList) { + this.altLocList = inputAltLocList; } /** From 00fb2a317a72bbdc5cc8dcc3e30ef3c63964908f Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 5 Apr 2016 19:28:54 -0700 Subject: [PATCH 032/108] Updates and refactoring to the code --- .../src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java | 2 +- .../main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java | 2 +- .../main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 14a99df..2b74ed3 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -49,7 +49,7 @@ public SimpleDataApi(byte[] inputByteArr) { bFactor = decoderUtils.convertIntsToFloats(deltaDecompress.decompressByteArray(inputData.getbFactorBig(),inputData.getbFactorSmall()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); occupancy = decoderUtils.convertIntsToFloats(intRunLength.decompressByteArray(inputData.getOccupancyList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); atomId = intRunLengthDelta.decompressByteArray(inputData.getAtomIdList()); - altId = stringRunlength.intArrayToCharArray(inputData.getAltLabelList()); + altId = stringRunlength.intArrayToCharArray(inputData.getAltLocList()); // Get the insertion code insertionCodeList = stringRunlength.intArrayToCharArray(inputData.getInsCodeList()); // Get the groupNumber diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java index ad346a9..4423824 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java @@ -39,7 +39,7 @@ public static void main(String[] args) { // Use the atomCounter to get group level info String element = dataApi.getGroupElementNames(currentGroupTypeIndex)[groupAtomIndex]; System.out.println("Serial id: "+serialId+" X coordinate: "+xCoord+", B-factor: "+bFactor+", element: "+element); - // Incremenet the atom index + // Increment the atom index structureAtomIndex++; } // Increment the groupIndex diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index 0430bcb..f39bc4b 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -127,7 +127,7 @@ public final MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHead thisDistBeanTot.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); thisDistBeanTot.setStructureId(bioBean.getPdbCode()); thisDistBeanTot.setInsCodeList(convertToIntArr(bioBean.get_atom_site_pdbx_PDB_ins_code())); - thisDistBeanTot.setAltLabelList(convertToIntArr(bioBean.get_atom_site_label_alt_id())); + thisDistBeanTot.setAltLocList(convertToIntArr(bioBean.get_atom_site_label_alt_id())); // Set this experimental data thisDistBeanTot.setResolution(inHeader.getResolution()); thisDistBeanTot.setrFree(inHeader.getrFree()); From fde6dd938ffab082ffcca03b2862eff1df905aa5 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 07:09:14 -0700 Subject: [PATCH 033/108] Minor refactoring --- .../rcsb/mmtf/arraydecompressors/RunLengthDelta.java | 6 +++--- .../main/java/org/rcsb/mmtf/decoder/DecoderUtils.java | 3 --- .../org/rcsb/mmtf/examples/DemoUnpackStructure.java | 10 +++++++--- .../java/org/rcsb/mmtf/update/BuildFirstDataSet.java | 2 -- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java index 44d4837..ee9be19 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java @@ -38,14 +38,14 @@ public final int[] decompressByteArray(final byte[] inArray) DataInputStream bis = new DataInputStream(new ByteArrayInputStream(inArray)); for (int i = 0; i < lengthOfBigIntArr; i++) { - // Get the numbers + // Read the number from the byte array int getNum = bis.readInt(); - // Get the number of repeats + // Read the number of repeats from the byte array int getCount = bis.readInt(); if (getCount < 0) { System.out.println(getCount); } - // Get the total count + // Add to the total count totCount += getCount; // Fill the number array numArr[i] = getNum; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java index ce0445e..51f1fb9 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java @@ -19,7 +19,6 @@ public class DecoderUtils { * @return a String of the chain id for the given chain. */ public final String getChainId(final byte[] chainList, final int chainIndex) { - int incrementor = 0; StringBuilder sb = new StringBuilder(); byte chainIdOne = chainList[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; @@ -57,7 +56,6 @@ public final int[] bytesToInts(final byte[] inArray) throws IOException { for (int i = 0; i < numIntsInArr; i++) { outArray[i] = bis.readInt(); } - return outArray; } @@ -74,7 +72,6 @@ public final int[] bytesToByteInts(final byte[] inArray) throws IOException { for (int i = 0; i < inArray.length; i++) { outArray[i] = (int) bis.readByte(); } - return outArray; } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java index 4423824..42be39e 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java @@ -32,13 +32,17 @@ public static void main(String[] args) { int currentGroupTypeIndex = dataApi.getGroupTypeIndices()[groupIndex]; // Loop through the atoms in every group for (int groupAtomIndex=0; groupAtomIndex Date: Wed, 6 Apr 2016 09:24:18 -0700 Subject: [PATCH 034/108] Updates and refactoring of white space --- .../mmtf/biojavaencoder/EncodeStructure.java | 2 +- .../mmtf/biojavaencoder/EncoderUtils.java | 287 +++++++++--------- .../mmtf/biojavaencoder/ParseFromBiojava.java | 1 - .../mmtf/dataholders/TestDataHolders.java | 2 +- .../mmtf/mappers/DataStructToByteArrs.java | 2 +- 5 files changed, 143 insertions(+), 151 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java index 92b54b4..f0cae2b 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java @@ -49,7 +49,7 @@ private final byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { EncoderUtils eu = new EncoderUtils(); // Compress the data and get it back out try { - MmtfBean mmtfBean = eu.compressMainData(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); + MmtfBean mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); return eu.getMessagePack(mmtfBean); } catch (IOException e) { // Here we've failed to read or write a byte array diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index f39bc4b..ccafcc1 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -51,7 +51,7 @@ /** - * This class finds an mmCIF file and saves it as a csv file . + * A class of functions to help encoding of mmCIF data to other data structures. * * @author Anthony Bradley */ @@ -73,10 +73,10 @@ public class EncoderUtils implements Serializable { private IntArrayCompressor runLengthComp = new RunLengthEncode(); /** - * Take a list of integers (as List). - * + * Take a list of integers (as List) and return as byte array. + * Each integer is stored as four bytes. * @param inputList the input integer array - * @return the byte[] output + * @return the byte array output. Each integer is stored as four bytes. * @throws IOException Occurred writing the int to the stream. */ public byte[] integersToBytes(List inputList) throws IOException @@ -90,12 +90,10 @@ public byte[] integersToBytes(List inputList) throws IOException return baos.toByteArray(); } - /** - * Get a messagepack from a bean. - * - * @param inputObject the input object - * @return the message pack + * Get a messagepack from an input object using the getters and setters. + * @param inputObject the input object. Field names will be set using the getters and setters for private variable.s + * @return the message pack as a byte array. * @throws JsonProcessingException the json processing exception - most likely related * to serialization. */ @@ -109,68 +107,69 @@ public final byte[] getMessagePack(Object inputObject) throws JsonProcessingExce /** * Compress the biological and header data into a combined data structure. - * - * @param inStruct the in struct - * @param inHeader the in header - * @return the byte array for the compressed data + * @param inStruct the BiodataStruct holding the structure data + * @param inHeader the header data + * @return the MmtfBean of the combined (compressed) data. * @throws IOException reading byte array - * @throws Exception */ - public final MmtfBean compressMainData(BioDataStruct inStruct, HeaderBean inHeader) throws IOException { + public final MmtfBean compressToMmtfBean(BioDataStruct inStruct, HeaderBean inHeader) throws IOException { EncoderUtils cm = new EncoderUtils(); - // Compress the protein - CoreSingleStructure strucureData = compressHadoopStruct(inStruct); - // NOW SET UP THE - MmtfBean thisDistBeanTot = new MmtfBean(); + // Compress the data. + CoreSingleStructure strucureData = compressInputData(inStruct); + // Now set up the output MMTF dataholder + MmtfBean outputMmtfBean = new MmtfBean(); NoFloatDataStructBean bioBean = (NoFloatDataStructBean) strucureData.findDataAsBean(); - // Copt these things - thisDistBeanTot.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); - thisDistBeanTot.setStructureId(bioBean.getPdbCode()); - thisDistBeanTot.setInsCodeList(convertToIntArr(bioBean.get_atom_site_pdbx_PDB_ins_code())); - thisDistBeanTot.setAltLocList(convertToIntArr(bioBean.get_atom_site_label_alt_id())); + // Copy these things + outputMmtfBean.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); + outputMmtfBean.setStructureId(bioBean.getPdbCode()); + outputMmtfBean.setInsCodeList(convertRunLengthStringListToIntArray(bioBean.get_atom_site_pdbx_PDB_ins_code())); + outputMmtfBean.setAltLocList(convertRunLengthStringListToIntArray(bioBean.get_atom_site_label_alt_id())); // Set this experimental data - thisDistBeanTot.setResolution(inHeader.getResolution()); - thisDistBeanTot.setrFree(inHeader.getrFree()); - thisDistBeanTot.setrWork(inHeader.getrWork()); + outputMmtfBean.setResolution(inHeader.getResolution()); + outputMmtfBean.setrFree(inHeader.getrFree()); + outputMmtfBean.setrWork(inHeader.getrWork()); // Copy the asym data - thisDistBeanTot.setChainIdList(inHeader.getAsymChainList()); - thisDistBeanTot.setChainsPerModel(inHeader.getAsymChainsPerModel()); - thisDistBeanTot.setGroupsPerChain(inHeader.getAsymGroupsPerChain()); - // Get - thisDistBeanTot.setEntityList(inHeader.getEntityList()); + outputMmtfBean.setChainIdList(inHeader.getAsymChainList()); + outputMmtfBean.setChainsPerModel(inHeader.getAsymChainsPerModel()); + outputMmtfBean.setGroupsPerChain(inHeader.getAsymGroupsPerChain()); + // Set the entity information + outputMmtfBean.setEntityList(inHeader.getEntityList()); // Get the seqres information - thisDistBeanTot.setSequenceIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(inHeader.getSeqResGroupIds())))); - thisDistBeanTot.setExperimentalMethods(inHeader.getExperimentalMethods()); + outputMmtfBean.setSequenceIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(inHeader.getSeqResGroupIds())))); + outputMmtfBean.setExperimentalMethods(inHeader.getExperimentalMethods()); // Now get this list - thisDistBeanTot.setBondAtomList(cm.integersToBytes(inStruct.getInterGroupBondInds())); - thisDistBeanTot.setBondOrderList(cm.integersToSmallBytes(inStruct.getInterGroupBondOrders())); + outputMmtfBean.setBondAtomList(cm.integersToBytes(inStruct.getInterGroupBondInds())); + outputMmtfBean.setBondOrderList(cm.integersToSmallBytes(inStruct.getInterGroupBondOrders())); // Now get these from the headers - thisDistBeanTot.setChainNameList(inHeader.getChainList()); - thisDistBeanTot.setNumAtoms(inHeader.getNumAtoms()); - thisDistBeanTot.setNumBonds(inHeader.getNumBonds()); - // Now get the Xtalographic info from this header - thisDistBeanTot.setSpaceGroup(inHeader.getSpaceGroup()); - thisDistBeanTot.setGroupList(genGroupList(inStruct.getGroupMap())); - thisDistBeanTot.setUnitCell(inHeader.getUnitCell()); - thisDistBeanTot.setBioAssemblyList(inHeader.getBioAssembly()); + outputMmtfBean.setChainNameList(inHeader.getChainList()); + outputMmtfBean.setNumAtoms(inHeader.getNumAtoms()); + outputMmtfBean.setNumBonds(inHeader.getNumBonds()); + // Now get the crystalographic info from this header + outputMmtfBean.setSpaceGroup(inHeader.getSpaceGroup()); + outputMmtfBean.setGroupList(genGroupList(inStruct.getGroupMap())); + outputMmtfBean.setUnitCell(inHeader.getUnitCell()); + outputMmtfBean.setBioAssemblyList(inHeader.getBioAssembly()); // Now set this extra header information - thisDistBeanTot.setTitle(inHeader.getTitle()); + outputMmtfBean.setTitle(inHeader.getTitle()); // Now add the byte arrays to the bean - addByteArrs(thisDistBeanTot, bioBean); + addByteArrs(outputMmtfBean, bioBean); // Now set the version - thisDistBeanTot.setMmtfProducer("RCSB-PDB Generator---version: "+grs.getCurrentVersion()); - return thisDistBeanTot; + outputMmtfBean.setMmtfProducer("RCSB-PDB Generator---version: "+grs.getCurrentVersion()); + return outputMmtfBean; } /** - * Convert a String list to an int[]. - * @param inputStringArray - * @return An integer array. + * Convert the a run length encoded List of strings to an integer array. + * The values are in pairs. The first value of each pair encodes the character. + * The second is a string representing the number of repeats. + * @param inputStringArray The list of strings. Values are in pairs. The first value is a String of length 1. + * The second value encodes an integer as a string. + * @return An integer array of the values having been converted to integers. */ - private final int[] convertToIntArr(List inputStringArray) { + private final int[] convertRunLengthStringListToIntArray(List inputStringArray) { // The output integer array int[] outArray = new int[inputStringArray.size()]; - // Now loop through the array first value is char. + // Now loop through the array first value is char. for (int i=0; i inputStringArray) { /** * Covert a Date object to ISO time format. * @param inputDate The input date object - * @return The time in ISO time format + * @return the time in ISO time format */ private final String convertToIsoTime(Date inputDate) { DateFormat dateStringFormat = new SimpleDateFormat("yyyy-MM-dd"); @@ -202,8 +201,8 @@ private final String convertToIsoTime(Date inputDate) { /** * Returns a PDBGroupList from a GroupMap. Uses the key of the map as the index in the list. - * @param groupMap The input map of Integer -> PDBGroup - * @return A list of PDBGroups, where the previous keys are used as indices. + * @param groupMap the input map of Integer -> PDBGroup + * @return a list of PDBGroups, where the previous keys are used as indices. */ private final PDBGroup[] genGroupList(Map groupMap) { PDBGroup[] outGroupList = new PDBGroup[Collections.max(groupMap.keySet())+1]; @@ -216,50 +215,47 @@ private final PDBGroup[] genGroupList(Map groupMap) { /** * Add the required bytearrays to an mmtfbean. - * - * @param thisDistBeanTot the this dist bean tot - * @param bioBean the bio bean + * @param inputMmtfBean the mmtf bean to which the arrays are to be added. + * @param inputDataBean the bean holding the coordinate information. * @throws IOException Signals that an I/O exception has occurred. */ - private final void addByteArrs(MmtfBean thisDistBeanTot, NoFloatDataStructBean bioBean) throws IOException { + private final void addByteArrs(MmtfBean inputMmtfBean, NoFloatDataStructBean inputDataBean) throws IOException { EncoderUtils cm = new EncoderUtils(); - // X,Y and Z and Bfactors - set these arrays - List retArr = getBigAndLittle(bioBean.get_atom_site_Cartn_xInt()); - thisDistBeanTot.setxCoordBig(retArr.get(0)); - thisDistBeanTot.setxCoordSmall(retArr.get(1)); - retArr = getBigAndLittle(bioBean.get_atom_site_Cartn_yInt()); - thisDistBeanTot.setyCoordBig(retArr.get(0)); - thisDistBeanTot.setyCoordSmall(retArr.get(1)); - retArr = getBigAndLittle(bioBean.get_atom_site_Cartn_zInt()); - thisDistBeanTot.setzCoordBig(retArr.get(0)); - thisDistBeanTot.setzCoordSmall(retArr.get(1)); - retArr = getBigAndLittle(bioBean.get_atom_site_B_iso_or_equivInt()); - thisDistBeanTot.setbFactorBig(retArr.get(0)); - thisDistBeanTot.setbFactorSmall(retArr.get(1)); + // Convert the x,y,z coordinate arrays as 4 and 2 byte arrays. + List retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_Cartn_xInt()); + inputMmtfBean.setxCoordBig(retArr.get(0)); + inputMmtfBean.setxCoordSmall(retArr.get(1)); + retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_Cartn_yInt()); + inputMmtfBean.setyCoordBig(retArr.get(0)); + inputMmtfBean.setyCoordSmall(retArr.get(1)); + retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_Cartn_zInt()); + inputMmtfBean.setzCoordBig(retArr.get(0)); + inputMmtfBean.setzCoordSmall(retArr.get(1)); + // Set the bfactor arrays as 4 and 2 byte arrays + retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_B_iso_or_equivInt()); + inputMmtfBean.setbFactorBig(retArr.get(0)); + inputMmtfBean.setbFactorSmall(retArr.get(1)); // Now the occupancy - thisDistBeanTot.setOccupancyList(cm.integersToBytes(bioBean.get_atom_site_occupancyInt())); + inputMmtfBean.setOccupancyList(cm.integersToBytes(inputDataBean.get_atom_site_occupancyInt())); // System.out.println(Collections.max(bioBean.getResOrder())); - thisDistBeanTot.setGroupTypeList((cm.integersToBytes(bioBean.getResOrder()))); - thisDistBeanTot.setAtomIdList(cm.integersToBytes(bioBean.get_atom_site_id())); - + inputMmtfBean.setGroupTypeList((cm.integersToBytes(inputDataBean.getResOrder()))); + inputMmtfBean.setAtomIdList(cm.integersToBytes(inputDataBean.get_atom_site_id())); // Now the secondary structure - thisDistBeanTot.setSecStructList(cm.integersToSmallBytes(bioBean.getSecStruct())); + inputMmtfBean.setSecStructList(cm.integersToSmallBytes(inputDataBean.getSecStruct())); // Now set the group num list - thisDistBeanTot.setGroupIdList(cm.integersToBytes(bioBean.get_atom_site_auth_seq_id())); + inputMmtfBean.setGroupIdList(cm.integersToBytes(inputDataBean.get_atom_site_auth_seq_id())); } - /** * Write a list of integers to 1 byte integers. - * - * @param values the values - * @return the byte[] + * @param inputList the input list of integers. + * @return the byte array, each byte is a different integer. * @throws IOException Signals that an I/O exception has occurred. */ - public final byte[] integersToSmallBytes(List values) throws IOException { + public final byte[] integersToSmallBytes(List inputList) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); - for(int i: values) + for(int i: inputList) { dos.writeByte(i); } @@ -267,50 +263,54 @@ public final byte[] integersToSmallBytes(List values) throws IOExceptio } /** - * Split an array into small (2 byte) and big (4 byte) integers. - * - * @param inArr the in arr - * @return the big and little + * Split a list of integers into small (2 byte) and big (4 byte) integers. + * @param inputList the input list of 4 byte integers. + * @return a list (length two) of byte arrays. The first array is the four byte integers. + * The second is the two byte integers. * @throws IOException Signals that an I/O exception has occurred. */ - public final List getBigAndLittle(List inArr) throws IOException{ - ListoutArr = new ArrayList(); + public final List splitListIntsToByteArrays(List inputList) throws IOException{ + // Initialise the list to return + List outputList = new ArrayList<>(); + // The counter keeps track of every short (two byte int) that has been added after a four byte int. int counter = 0; - ByteArrayOutputStream littleOS = new ByteArrayOutputStream(); - DataOutputStream littleDOS = new DataOutputStream(littleOS); - ByteArrayOutputStream bigOS = new ByteArrayOutputStream(); - DataOutputStream bigDOS = new DataOutputStream(bigOS); - for(int i=0;i30000){ - // Counter added to the big list - bigDOS.writeInt(counter); - // Big number added to big list - bigDOS.writeInt(inArr.get(i)); - // Counter set to zero + // If the number is greater than the maximum for a two byte integer. Store as a four byte integer. + else if(Math.abs(inputList.get(i))>Short.MAX_VALUE){ + // Add the counter to the four byte list. + fourByteDataOutputStream.writeInt(counter); + // Add the number to the four byte list. + fourByteDataOutputStream.writeInt(inputList.get(i)); + // Set the counter to zero. counter = 0; } else{ - // Little number added to little list - littleDOS.writeShort(inArr.get(i)); - // Add to the counter + // Add the two byte integer to the two byte list. + twoByteDataOutputStream.writeShort(inputList.get(i)); + // Add one to the counter. counter+=1; } } - // Finally add the counter to the big list - bigDOS.writeInt(counter); - - outArr.add(bigOS.toByteArray()); - outArr.add(littleOS.toByteArray()); - return outArr; + // Finally add the final counter to the four byte list. + fourByteDataOutputStream.writeInt(counter); + // Add the two byte arrays to the out put list. + outputList.add(fourByteOutputStream.toByteArray()); + outputList.add(twoByteOutputStream.toByteArray()); + return outputList; } /** * Utility function to gzip compress a byte[]. - * * @param inputArray the input array * @return the byte[] */ @@ -329,41 +329,35 @@ public final byte[] gzipCompress(byte[] inputArray){ /** * Function to compress the input biological data. - * * @param inputBioDataStruct the input data structure * @return a core single structure * @throws IllegalAccessException * @throws InvocationTargetException * @throws Exception The bean data copying didn't work - weird. */ - public final CoreSingleStructure compressHadoopStruct(BioDataStruct inputBioDataStruct) { - - CoreSingleStructure outStruct; - outStruct = doublesToInts.compresStructure(inputBioDataStruct); - // Get the input structure - NoFloatDataStruct inStruct = (NoFloatDataStruct) outStruct; + public final CoreSingleStructure compressInputData(BioDataStruct inputBioDataStruct) { + // Convert the arrays to integers. + NoFloatDataStruct inStruct = (NoFloatDataStruct) doublesToInts.compresStructure(inputBioDataStruct); + // Get the lists of coordinates. List cartnX = inStruct.get_atom_site_Cartn_xInt(); List cartnY = inStruct.get_atom_site_Cartn_yInt(); List cartnZ = inStruct.get_atom_site_Cartn_zInt(); - // Get the number of models inStruct.set_atom_site_Cartn_xInt(deltaComp.compressIntArray(cartnX)); inStruct.set_atom_site_Cartn_yInt(deltaComp.compressIntArray(cartnY)); inStruct.set_atom_site_Cartn_zInt(deltaComp.compressIntArray(cartnZ)); - // // Now the occupancy and BFACTOR -> VERY SMALL GAIN + // Compress the b factors using delta compression. inStruct.set_atom_site_B_iso_or_equivInt(deltaComp.compressIntArray(inStruct.get_atom_site_B_iso_or_equivInt())); - // SMALL GAIN + // Run length compress the occupanct inStruct.set_atom_site_occupancyInt(runLengthComp.compressIntArray(inStruct.get_atom_site_occupancyInt())); // Now the sequential numbers - huge gain - new order of good compressors // Now runlength encode the residue order inStruct.setResOrder(inStruct.getResOrder()); - // THESE ONES CAN BE RUN LENGTH ON DELTA - // Check for negative counters inStruct.set_atom_site_auth_seq_id(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_auth_seq_id()))); inStruct.set_atom_site_label_entity_poly_seq_num(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_label_entity_poly_seq_num()))); inStruct.set_atom_site_id(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_id()))); - //// NOW THE STRINGS - small gain + // Now run length decode the strings StringArrayCompressor stringRunEncode = new RunLengthEncodeString(); inStruct.set_atom_site_label_alt_id(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_label_alt_id())); //inStruct.set_atom_site_label_entity_id(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_label_entity_id())); @@ -372,14 +366,13 @@ public final CoreSingleStructure compressHadoopStruct(BioDataStruct inputBioData } /** - * Comp c alpha. - * - * @param calphaStruct the calpha struct - * @param inHeader the in header - * @return the calpha dist bean + * Compress Calpha data to the output format. + * @param calphaData the calpha struct + * @param inHeader the header data + * @return the compressed calpha data * @throws IOException Signals that an I/O exception has occurred. */ - public final CalphaDistBean compCAlpha(CalphaBean calphaStruct, HeaderBean inHeader) throws IOException { + public final CalphaDistBean compCAlpha(CalphaBean calphaData, HeaderBean inHeader) throws IOException { EncoderUtils cm = new EncoderUtils(); // Create the object to leave CalphaDistBean calphaOut = new CalphaDistBean(); @@ -395,35 +388,35 @@ public final CalphaDistBean compCAlpha(CalphaBean calphaStruct, HeaderBean inHea // A map of Bioassembly -> new class so serializable calphaOut.setBioAssembly(inHeader.getBioAssembly()); // Now set the number of bonds - calphaOut.setNumBonds(calphaStruct.getNumBonds()); - calphaOut.setGroupsPerChain(calphaStruct.getGroupsPerChain()); + calphaOut.setNumBonds(calphaData.getNumBonds()); + calphaOut.setGroupsPerChain(calphaData.getGroupsPerChain()); // Set this header info calphaOut.setChainsPerModel(inHeader.getChainsPerModel()); - calphaOut.setGroupsPerChain(calphaStruct.getGroupsPerChain()); + calphaOut.setGroupsPerChain(calphaData.getGroupsPerChain()); calphaOut.setChainIdList(inHeader.getChainList()); - calphaOut.setNumAtoms(calphaStruct.getNumAtoms()); + calphaOut.setNumAtoms(calphaData.getNumAtoms()); // Write the secondary stucture out - calphaOut.setSecStructList(cm.integersToSmallBytes(calphaStruct.getSecStruct())); - calphaOut.setGroupMap(calphaStruct.getGroupMap()); - calphaOut.setGroupTypeList(cm.integersToBytes(calphaStruct.getResOrder())); + calphaOut.setSecStructList(cm.integersToSmallBytes(calphaData.getSecStruct())); + calphaOut.setGroupMap(calphaData.getGroupMap()); + calphaOut.setGroupTypeList(cm.integersToBytes(calphaData.getResOrder())); // Get the input structure - List cartnX = calphaStruct.getCartn_x(); - List cartnY = calphaStruct.getCartn_y(); - List cartnZ = calphaStruct.getCartn_z(); + List cartnX = calphaData.getCartn_x(); + List cartnY = calphaData.getCartn_y(); + List cartnZ = calphaData.getCartn_z(); // Now add the X coords - List bigAndLittleX = getBigAndLittle(deltaComp.compressIntArray(cartnX)); + List bigAndLittleX = splitListIntsToByteArrays(deltaComp.compressIntArray(cartnX)); calphaOut.setxCoordBig(bigAndLittleX.get(0)); calphaOut.setxCoordSmall(bigAndLittleX.get(1)); // No add they Y coords - List bigAndLittleY = getBigAndLittle(deltaComp.compressIntArray(cartnY)); + List bigAndLittleY = splitListIntsToByteArrays(deltaComp.compressIntArray(cartnY)); calphaOut.setyCoordBig(bigAndLittleY.get(0)); calphaOut.setyCoordSmall(bigAndLittleY.get(1)); // Now add the Z coords - List bigAndLittleZ = getBigAndLittle(deltaComp.compressIntArray(cartnZ)); + List bigAndLittleZ = splitListIntsToByteArrays(deltaComp.compressIntArray(cartnZ)); calphaOut.setzCoordBig(bigAndLittleZ.get(0)); calphaOut.setzCoordSmall(bigAndLittleZ.get(1)); // THESE ONES CAN BE RUN LENGTH ON DELTA - calphaOut.setGroupIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(calphaStruct.get_atom_site_auth_seq_id())))); + calphaOut.setGroupIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(calphaData.get_atom_site_auth_seq_id())))); return calphaOut; } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java index 34f473d..440c2ed 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java @@ -670,7 +670,6 @@ private void getCharges(List inputAtoms, PDBGroup pdbGroup) { /** * Generate a serializable biotransformation for storing * in the messagepack. - * * @param bioJavaStruct the Biojava structure * @param header the header * @return a map of the bioassembly information that is serializable diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index 295aace..8498304 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -153,7 +153,7 @@ private void testDataComplete(String pdbId) throws IOException { parsedDataStruct.createFromJavaStruct(pdbId, totMap); MmtfBean mmtfBean = null; // Compress the data and get it back out - mmtfBean = eu.compressMainData(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); + mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); // Make sure all fields are re-populated ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); // Now check the standard ones have been set diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java index 62b04c1..3295180 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java @@ -36,7 +36,7 @@ public Iterable> call(Tuple2 t) BioDataStruct thisBS = cbs.getBioStruct(); CalphaDistBean calphaDistStruct = cm.compCAlpha(cbs.getCalphaStruct(), cbs.getHeaderStruct()); // NOW JUST WRITE THE KEY VALUE PAIRS HERE - byte[] totBytes = cm.getMessagePack(cm.compressMainData(thisBS, headerData)); + byte[] totBytes = cm.getMessagePack(cm.compressToMmtfBean(thisBS, headerData)); byte[] headerBytes = cm.getMessagePack(headerData); byte[] calphaBytes = cm.getMessagePack(calphaDistStruct); // Add the total data From f0921f08f37e3ee3d09243720cddb5f8ca01eb8c Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 09:56:04 -0700 Subject: [PATCH 035/108] Updates and some refactoring to the encoder --- .../mmtf/biojavaencoder/EncoderUtils.java | 190 ++++++++++++++ .../mmtf/biojavaencoder/ParseFromBiojava.java | 234 ++---------------- 2 files changed, 209 insertions(+), 215 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java index ccafcc1..93ec8d5 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java @@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; @@ -13,20 +14,33 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.zip.GZIPOutputStream; +import javax.vecmath.Matrix4d; + import org.biojava.nbio.structure.Atom; import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; +import org.biojava.nbio.structure.JournalArticle; +import org.biojava.nbio.structure.PDBCrystallographicInfo; +import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; +import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; +import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; +import org.biojava.nbio.structure.secstruc.DSSPParser; +import org.biojava.nbio.structure.secstruc.SecStrucCalc; +import org.biojava.nbio.structure.xtal.CrystalCell; +import org.biojava.nbio.structure.xtal.SpaceGroup; import org.msgpack.jackson.dataformat.MessagePackFactory; import org.rcsb.mmtf.arraycompressors.FindDeltas; import org.rcsb.mmtf.arraycompressors.IntArrayCompressor; @@ -35,6 +49,8 @@ import org.rcsb.mmtf.arraycompressors.StringArrayCompressor; import org.rcsb.mmtf.biocompressors.BioCompressor; import org.rcsb.mmtf.biocompressors.CompressDoubles; +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.BioAssemblyTrans; import org.rcsb.mmtf.dataholders.BioDataStruct; import org.rcsb.mmtf.dataholders.CalphaBean; import org.rcsb.mmtf.dataholders.CalphaDistBean; @@ -540,5 +556,179 @@ public final List getAtomsForGroup(Group inputGroup) { } return theseAtoms; } + + + /** + * Function to generate the secondary structuee for a biojava structure object. + * @param bioJavaStruct the bio java struct + */ + public void genSecStruct(Structure bioJavaStruct) { + SecStrucCalc ssp = new SecStrucCalc(); + try{ + ssp.calculate(bioJavaStruct, true); + } + + catch(StructureException e) { + try{ + DSSPParser.fetch(bioJavaStruct.getPDBCode(), bioJavaStruct, true); //download from PDB the DSSP result + } + catch(FileNotFoundException enew){ + } + catch(Exception bige){ + System.out.println(bige); + } + } + + } + + /** + * Sets the header information. + * @param bioJavaStruct the new header info + */ + public void setHeaderInfo(Structure bioJavaStruct, HeaderBean headerStruct) { + headerStruct.setPdbCode(bioJavaStruct.getPDBCode()); + // Now get hte xtalographic info + PDBCrystallographicInfo xtalInfo = bioJavaStruct.getCrystallographicInfo(); + CrystalCell xtalCell = xtalInfo.getCrystalCell(); + SpaceGroup spaceGroup = xtalInfo.getSpaceGroup(); + float[] inputUnitCell = new float[6]; + if(xtalCell==null){ + + }else{ + headerStruct.setUnitCell(inputUnitCell); + inputUnitCell[0] = (float) xtalCell.getA(); + inputUnitCell[1] = (float) xtalCell.getB(); + inputUnitCell[2] = (float) xtalCell.getC(); + inputUnitCell[3] = (float) xtalCell.getAlpha(); + inputUnitCell[4] = (float) xtalCell.getBeta(); + inputUnitCell[5] = (float) xtalCell.getGamma(); + if(spaceGroup==null){ + // This could be the I21 shown here + headerStruct.setSpaceGroup("NA"); + } + else{ + headerStruct.setSpaceGroup(spaceGroup.getShortSymbol()); + } + } + // GET THE HEADER INFORMATION + PDBHeader header = bioJavaStruct.getPDBHeader(); + List outMap = generateSerializableBioAssembly(bioJavaStruct, header); + headerStruct.setBioAssembly(outMap); + headerStruct.setTitle(header.getTitle()); + headerStruct.setDescription(header.getDescription()); + headerStruct.setClassification(header.getClassification()); + headerStruct.setDepDate(header.getDepDate()); + headerStruct.setModDate(header.getModDate()); + headerStruct.setResolution(header.getResolution()); + headerStruct.setrFree(header.getRfree()); + + JournalArticle myJournal = header.getJournalArticle(); + if( myJournal==null){ + + } + else{ + headerStruct.setDoi(myJournal.getDoi()); + } + } + + /** + * Generate a serializable biotransformation for storing + * in the messagepack. + * @param bioJavaStruct the Biojava structure + * @param header the header + * @return a map of the bioassembly information that is serializable + */ + private List generateSerializableBioAssembly(Structure bioJavaStruct, PDBHeader header) { + // Get a map to reference asym ids to chains + Map chainIdToIndexMap = getChainIdToIndexMap(bioJavaStruct); + // Here we need to iterate through and get the chain ids and the matrices + Map inputBioAss = header.getBioAssemblies(); + List outMap = new ArrayList(); + for (Map.Entry entry : inputBioAss.entrySet()) { + Map matSet = new HashMap(); + BioAssemblyInfo value = entry.getValue(); + // Make a new one of these + BioAssemblyData newValue = new BioAssemblyData(); + outMap.add(newValue); + // Copy across this info + List outTrans = new ArrayList(); + for(BiologicalAssemblyTransformation transform: value.getTransforms()){ + // Get's the chain id -> this is the asym id + String thisChain = transform.getChainId(); + // Get the current matrix 4d + Matrix4d currentTransMat = transform.getTransformationMatrix(); + double[] outList = new double[16]; + // Iterate over the matrix + for(int i=0; i<4; i++){ + for(int j=0; j<4; j++){ + // Now set this element + outList[i*4+j] = currentTransMat.getElement(i,j); + } + } + if(matSet.containsKey(currentTransMat)){ + // Get the trasnformation + BioAssemblyTrans bioTransNew = matSet.get(currentTransMat); + // Add this chain index to that list + int[] oldList = bioTransNew.getChainIndexList(); + int oldLen = oldList.length; + int[] newList = new int[oldLen+1]; + for (int i=0; i getChainIdToIndexMap(Structure bioJavaStruct) { + // First build a map of asymid -> chain index + Map chainIdToIndexMapOne = new HashMap<>(); + int chainCounter = 0; + for (int i=0; i bioS /** * Function to generate a main, calpha and header data form a biojava structure. * - * @param bioJavaStruct the Biojava structure + * @param inputBiojavaStruct the Biojava structure * @param bioStructMap the map relating hash codes to PDB groups. * input so that a consistent map can be held across several structures */ - public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaStruct, Map bioStructMap) { + public final void generateDataStructuresFromBioJavaStructure(Structure inputBiojavaStruct, Map bioStructMap) { EncoderUtils encoderUtils = new EncoderUtils(); // Reset structure to consider altloc groups with the same residue number but different group names as seperate groups - encoderUtils.fixMicroheterogenity(bioJavaStruct); + encoderUtils.fixMicroheterogenity(inputBiojavaStruct); // Generate the secondary structure - genSecStruct(bioJavaStruct); + encoderUtils.genSecStruct(inputBiojavaStruct); // Set the header information - setHeaderInfo(bioJavaStruct); + encoderUtils.setHeaderInfo(inputBiojavaStruct, headerStruct); // Get the number of models - Integer numModels = bioJavaStruct.nrModels(); + Integer numModels = inputBiojavaStruct.nrModels(); bioStruct.setNumModels(numModels); // Set these maps and lists List> bioStructList= new ArrayList>(); @@ -197,7 +184,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt int totAsymChains = 0; // Get the total number of chains for (int i=0; i(); @@ -218,7 +205,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt headerStruct.setGroupsPerChain(groupsPerChain); headerStruct.setSequence(new ArrayList()); // Find the experimental techniques - Set techniqueSet = bioJavaStruct.getPDBHeader().getExperimentalTechniques(); + Set techniqueSet = inputBiojavaStruct.getPDBHeader().getExperimentalTechniques(); headerStruct.setExperimentalMethods(new ArrayList()); for (ExperimentalTechnique currentTechnique : techniqueSet){ headerStruct.getExperimentalMethods().add(currentTechnique.toString()); @@ -232,14 +219,14 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt } calphaStruct.setGroupsPerChain(calphaGroupsPerChain); // Now let's find the entity infomration - findEntityInfo(bioJavaStruct); + findEntityInfo(inputBiojavaStruct); // Get all the atoms - List totAtoms = encoderUtils.getAllAtoms(bioJavaStruct); + List totAtoms = encoderUtils.getAllAtoms(inputBiojavaStruct); for (int i=0; i chains = bioJavaStruct.getModel(i); + List chains = inputBiojavaStruct.getModel(i); // Set the PDB Code - bioStruct.setPdbCode(bioJavaStruct.getPDBCode()); + bioStruct.setPdbCode(inputBiojavaStruct.getPDBCode()); ArrayList chainList = new ArrayList(); // Set the number of chains in this model internalChainsPerModel[i] = chains.size(); @@ -285,9 +272,8 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt getInterGroupBond(atomsInThisGroup, totAtoms, atomCounter); // Count the number of bonds // Now loop through and get the coords - // Generate the group level data - // Get the + // Get the atomic data for the group List atomInfo = getAtomInfo(atomsInThisGroup); // Get the atomic info required - bioStruct is the unique identifier of the group int hashCode = getHashFromStringList(atomInfo); @@ -304,7 +290,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt // Now get the bond list (lengths, orders and indices) createBondList(atomsInThisGroup, outGroup); getCharges(atomsInThisGroup, outGroup); - // + // Put the residue information into this bio structure map bioStructMap.put(resCounter, outGroup); hashToRes.put(hashCode, resCounter); bioStruct.getResOrder().add(resCounter); @@ -367,7 +353,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure bioJavaSt headerStruct.setNumBonds(bondCounter+bioStruct.getInterGroupBondInds().size()); headerStruct.setNumAtoms(atomCounter); headerStruct.setNumChains(chainCounter); - headerStruct.setPdbCode(bioJavaStruct.getPDBCode()); + headerStruct.setPdbCode(inputBiojavaStruct.getPDBCode()); } @@ -411,89 +397,8 @@ private final void findEntityInfo(Structure bioJavaStruct) { } - - - /** - * Sets the header info. - * - * @param bioJavaStruct the new header info - */ - private void setHeaderInfo(Structure bioJavaStruct) { - headerStruct.setPdbCode(bioJavaStruct.getPDBCode()); - // Now get hte xtalographic info - PDBCrystallographicInfo xtalInfo = bioJavaStruct.getCrystallographicInfo(); - CrystalCell xtalCell = xtalInfo.getCrystalCell(); - SpaceGroup spaceGroup = xtalInfo.getSpaceGroup(); - float[] inputUnitCell = new float[6]; - if(xtalCell==null){ - - }else{ - headerStruct.setUnitCell(inputUnitCell); - inputUnitCell[0] = (float) xtalCell.getA(); - inputUnitCell[1] = (float) xtalCell.getB(); - inputUnitCell[2] = (float) xtalCell.getC(); - inputUnitCell[3] = (float) xtalCell.getAlpha(); - inputUnitCell[4] = (float) xtalCell.getBeta(); - inputUnitCell[5] = (float) xtalCell.getGamma(); - if(spaceGroup==null){ - // This could be the I21 shown here - headerStruct.setSpaceGroup("NA"); - } - else{ - headerStruct.setSpaceGroup(spaceGroup.getShortSymbol()); - } - } - // GET THE HEADER INFORMATION - PDBHeader header = bioJavaStruct.getPDBHeader(); - List outMap = generateSerializableBioAssembly(bioJavaStruct, header); - headerStruct.setBioAssembly(outMap); - headerStruct.setTitle(header.getTitle()); - headerStruct.setDescription(header.getDescription()); - headerStruct.setClassification(header.getClassification()); - headerStruct.setDepDate(header.getDepDate()); - headerStruct.setModDate(header.getModDate()); - headerStruct.setResolution(header.getResolution()); - headerStruct.setrFree(header.getRfree()); - - JournalArticle myJournal = header.getJournalArticle(); - if( myJournal==null){ - - } - else{ - headerStruct.setDoi(myJournal.getDoi()); - } - } - - - /** - * - * Function to generate the secondary structuee for a biojava structure object. - * - * @param bioJavaStruct the bio java struct - */ - private void genSecStruct(Structure bioJavaStruct) { - SecStrucCalc ssp = new SecStrucCalc(); - try{ - ssp.calculate(bioJavaStruct, true); - } - - catch(StructureException e) { - try{ - DSSPParser.fetch(bioJavaStruct.getPDBCode(), bioJavaStruct, true); //download from PDB the DSSP result - } - catch(FileNotFoundException enew){ - } - catch(Exception bige){ - System.out.println(bige); - } - } - - } - - /** * Adds the calpha group. - * * @param cAlphaGroup the c alpha group * @param props the props * @param residueNum the residue number Biojava objext @@ -653,10 +558,9 @@ private void addCalpha(Atom a, SecStrucState props, ResidueNumber residueNumber) /** - * Find the atomic charge information. - * - * @param inputAtoms the atoms - * @param pdbGroup the PDBGroup being considered + * Find and store the atomic charge information. + * @param inputAtoms the atoms being coisdered. + * @param pdbGroup the PDBGroup to be modified. * @return the atomic charges */ private void getCharges(List inputAtoms, PDBGroup pdbGroup) { @@ -667,106 +571,6 @@ private void getCharges(List inputAtoms, PDBGroup pdbGroup) { } - /** - * Generate a serializable biotransformation for storing - * in the messagepack. - * @param bioJavaStruct the Biojava structure - * @param header the header - * @return a map of the bioassembly information that is serializable - */ - private List generateSerializableBioAssembly(Structure bioJavaStruct, PDBHeader header) { - // Get a map to reference asym ids to chains - Map chainIdToIndexMap = getChainIdToIndexMap(bioJavaStruct); - // Here we need to iterate through and get the chain ids and the matrices - Map inputBioAss = header.getBioAssemblies(); - List outMap = new ArrayList(); - for (Map.Entry entry : inputBioAss.entrySet()) { - Map matSet = new HashMap(); - BioAssemblyInfo value = entry.getValue(); - // Make a new one of these - BioAssemblyData newValue = new BioAssemblyData(); - outMap.add(newValue); - // Copy across this info - List outTrans = new ArrayList(); - for(BiologicalAssemblyTransformation transform: value.getTransforms()){ - // Get's the chain id -> this is the asym id - String thisChain = transform.getChainId(); - // Get the current matrix 4d - Matrix4d currentTransMat = transform.getTransformationMatrix(); - double[] outList = new double[16]; - // Iterate over the matrix - for(int i=0; i<4; i++){ - for(int j=0; j<4; j++){ - // Now set this element - outList[i*4+j] = currentTransMat.getElement(i,j); - } - } - if(matSet.containsKey(currentTransMat)){ - // Get the trasnformation - BioAssemblyTrans bioTransNew = matSet.get(currentTransMat); - // Add this chain index to that list - int[] oldList = bioTransNew.getChainIndexList(); - int oldLen = oldList.length; - int[] newList = new int[oldLen+1]; - for (int i=0; i getChainIdToIndexMap(Structure bioJavaStruct) { - // First build a map of asymid -> chain index - Map chainIdToIndexMapOne = new HashMap<>(); - int chainCounter = 0; - for (int i=0; i Date: Wed, 6 Apr 2016 12:00:57 -0700 Subject: [PATCH 036/108] Introducing logging in dependencies, now let's use it! --- mmtf-decoder/pom.xml | 28 +++++++++++++++++++++++--- mmtf-encoder/pom.xml | 24 ++++++++++++++++++++-- mmtf-update/pom.xml | 23 +++++++++++++++++++++- pom.xml | 47 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 110 insertions(+), 12 deletions(-) diff --git a/mmtf-decoder/pom.xml b/mmtf-decoder/pom.xml index 69b2094..d7a23fa 100644 --- a/mmtf-decoder/pom.xml +++ b/mmtf-decoder/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.rcsb @@ -36,12 +37,33 @@ jackson-dataformat-msgpack 0.7.1 + + junit junit - 4.11 - test + + + + org.slf4j + slf4j-api + + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index 06b7b6e..65ee8e7 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -36,12 +36,32 @@ jackson-dataformat-msgpack 0.7.1 + junit junit - 4.11 - test + + + + org.slf4j + slf4j-api + + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + org.unitils unitils-core diff --git a/mmtf-update/pom.xml b/mmtf-update/pom.xml index 46d4ce0..290876e 100644 --- a/mmtf-update/pom.xml +++ b/mmtf-update/pom.xml @@ -31,11 +31,32 @@ mmtf-common 0.0.1-alpha4-SNAPSHOT + junit junit - 4.11 + + + + org.slf4j + slf4j-api + + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + org.biojava biojava-structure diff --git a/pom.xml b/pom.xml index 951d3f2..46f996b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + @@ -35,7 +36,7 @@ UTF-8 UTF-8 512M - 1.7.14 + 1.7.20 2.5 @@ -135,10 +136,6 @@ -Xdoclint:none 256m -
<script src="http://www.google-analytics.com/urchin.js" - type="text/javascript"></script><script - type="text/javascript">_uacct = - "UA-1326640-1";urchinTracker();</script>
@@ -315,6 +312,44 @@ + + + + junit + junit + 4.12 + test + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + runtime + + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + runtime + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + runtime + + + From fadbd6b348fdada887c62837a409fc5a28a88e70 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 12:08:54 -0700 Subject: [PATCH 037/108] Fairly extensive refactoring and setting of a series of tests to be written. --- .../mmtf/biojavaencoder/BiojavaUtils.java | 336 ++++++++++++++++ .../rcsb/mmtf/biojavaencoder/GroupType.java | 8 +- .../mmtf/biojavaencoder/ParseFromBiojava.java | 217 ++++------- .../EncodeStructure.java | 3 +- .../EncoderUtils.java | 363 ++---------------- ...ncoderUtils.java => TestBiojavaUtils.java} | 28 +- .../mmtf/dataholders/TestDataHolders.java | 2 +- .../rcsb/mmtf/encoder/TestEncoderUtils.java | 18 + .../mmtf/mappers/DataStructToByteArrs.java | 2 +- .../org/rcsb/mmtf/mappers/MapperUtils.java | 6 +- .../mmtf/postupdatetests/CheckServer.java | 6 +- .../preupdatetests/DataConsistencyCheck.java | 6 +- .../org/rcsb/mmtf/testutils/CheckBonds.java | 8 +- .../org/rcsb/mmtf/update/TestingUtils.java | 2 +- .../rcsb/mmtf/integrationtest/TestBonds.java | 6 +- .../mmtf/integrationtest/TestParseMMCif.java | 8 +- 16 files changed, 524 insertions(+), 495 deletions(-) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{biojavaencoder => encoder}/EncodeStructure.java (97%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{biojavaencoder => encoder}/EncoderUtils.java (63%) rename mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/{TestEncoderUtils.java => TestBiojavaUtils.java} (86%) create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java new file mode 100644 index 0000000..c47ec88 --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java @@ -0,0 +1,336 @@ +package org.rcsb.mmtf.biojavaencoder; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.vecmath.Matrix4d; + +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.BioAssemblyTrans; +import org.rcsb.mmtf.dataholders.HeaderBean; + +import org.biojava.nbio.structure.Atom; +import org.biojava.nbio.structure.Chain; +import org.biojava.nbio.structure.Group; +import org.biojava.nbio.structure.JournalArticle; +import org.biojava.nbio.structure.PDBCrystallographicInfo; +import org.biojava.nbio.structure.PDBHeader; +import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; +import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; +import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; +import org.biojava.nbio.structure.secstruc.DSSPParser; +import org.biojava.nbio.structure.secstruc.SecStrucCalc; +import org.biojava.nbio.structure.xtal.CrystalCell; +import org.biojava.nbio.structure.xtal.SpaceGroup; + +/** + * A utils class of functions needed for Biojava. + * @author Anthony Bradley + * + */ +public class BiojavaUtils { + /** + * Set up the configuration parameters for BioJava. + */ + public AtomCache setUpBioJava() { + // Set up the atom cache etc + AtomCache cache = new AtomCache(); + cache.setUseMmCif(true); + FileParsingParameters params = cache.getFileParsingParams(); + params.setCreateAtomBonds(true); + params.setAlignSeqRes(true); + params.setParseBioAssembly(true); + params.setUseInternalChainId(true); + CustomChemCompProvider cc = new CustomChemCompProvider(); + ChemCompGroupFactory.setChemCompProvider(cc); + cc.checkDoFirstInstall(); + cache.setFileParsingParams(params); + StructureIO.setAtomCache(cache); + return cache; + } + + /** + * Set up the configuration parameters for BioJava. - with an extra URL + */ + public AtomCache setUpBioJava(String extraUrl) { + // Set up the atom cache etc + AtomCache cache = new AtomCache(); + cache.setUseMmCif(true); + FileParsingParameters params = cache.getFileParsingParams(); + params.setCreateAtomBonds(true); + params.setAlignSeqRes(true); + params.setParseBioAssembly(true); + params.setUseInternalChainId(true); + CustomChemCompProvider cc = new CustomChemCompProvider(extraUrl); + ChemCompGroupFactory.setChemCompProvider(cc); + cc.checkDoFirstInstall(); + cache.setFileParsingParams(params); + StructureIO.setAtomCache(cache); + return cache; + } + + + /** + * This sets all microheterogeneous groups (previously alternate location groups) as separate groups. + * @param bioJavaStruct + */ + public final void fixMicroheterogenity(Structure bioJavaStruct) { + // Loop through the models + for (int i=0; i chains = bioJavaStruct.getModel(i); + for (Chain c : chains) { + // Build a new list of groups + List outGroups = new ArrayList<>(); + for (Group g : c.getAtomGroups()) { + List removeList = new ArrayList<>(); + for (Group altLoc : g.getAltLocs()) { + // Check if they are not equal -> microheterogenity + if(! altLoc.getPDBName().equals(g.getPDBName())) { + // Now add this group to the main list + removeList.add(altLoc); + } + } + // Add this group + outGroups.add(g); + // Remove any microhet alt locs + g.getAltLocs().removeAll(removeList); + // Add these microhet alt locs + outGroups.addAll(removeList); + } + c.setAtomGroups(outGroups); + } + } + } + + /** + * Function to get all the atoms in the strucutre as a list. + * + * @param bioJavaStruct the bio java struct + * @return the all atoms + */ + public final List getAllAtoms(Structure bioJavaStruct) { + // Get all the atoms + List theseAtoms = new ArrayList(); + for (int i=0; i chains = bioJavaStruct.getModel(i); + for (Chain c : chains) { + for (Group g : c.getAtomGroups()) { + for(Atom a: getAtomsForGroup(g)){ + theseAtoms.add(a); + } + } + } + } + return theseAtoms; + } + + /** + * Function to get a list of atoms for a group. + * + * @param inputGroup the Biojava Group to consider + * @return the atoms for the input Biojava Group + */ + public final List getAtomsForGroup(Group inputGroup) { + Set uniqueAtoms = new HashSet(); + List theseAtoms = new ArrayList(); + for(Atom a: inputGroup.getAtoms()){ + theseAtoms.add(a); + uniqueAtoms.add(a); + } + List altLocs = inputGroup.getAltLocs(); + for(Group thisG: altLocs){ + for(Atom a: thisG.getAtoms()){ + if(uniqueAtoms.contains(a)){ + continue; + } + theseAtoms.add(a); + } + } + return theseAtoms; + } + + + /** + * Function to generate the secondary structure for a Biojava structure object. + * @param bioJavaStruct the Biojava structure for which it is to be calculate. + */ + public void calculateDsspSecondaryStructure(Structure bioJavaStruct) { + SecStrucCalc ssp = new SecStrucCalc(); + try{ + ssp.calculate(bioJavaStruct, true); + } + catch(StructureException e) { + try{ + DSSPParser.fetch(bioJavaStruct.getPDBCode(), bioJavaStruct, true); //download from PDB the DSSP result + } + catch(FileNotFoundException enew){ + } + catch(Exception bige){ + System.out.println(bige); + } + } + + } + + /** + * Adds the header information to a HeaderBean from a biojava structure object. + * @param bioJavaStruct the input Biojava structure + * @param headerStruct the input headerbean object + */ + public void setHeaderInfo(Structure bioJavaStruct, HeaderBean headerStruct) { + headerStruct.setPdbCode(bioJavaStruct.getPDBCode()); + // Now get hte xtalographic info + PDBCrystallographicInfo xtalInfo = bioJavaStruct.getCrystallographicInfo(); + CrystalCell xtalCell = xtalInfo.getCrystalCell(); + SpaceGroup spaceGroup = xtalInfo.getSpaceGroup(); + float[] inputUnitCell = new float[6]; + if(xtalCell==null){ + + }else{ + headerStruct.setUnitCell(inputUnitCell); + inputUnitCell[0] = (float) xtalCell.getA(); + inputUnitCell[1] = (float) xtalCell.getB(); + inputUnitCell[2] = (float) xtalCell.getC(); + inputUnitCell[3] = (float) xtalCell.getAlpha(); + inputUnitCell[4] = (float) xtalCell.getBeta(); + inputUnitCell[5] = (float) xtalCell.getGamma(); + if(spaceGroup==null){ + // This could be the I21 shown here + headerStruct.setSpaceGroup("NA"); + } + else{ + headerStruct.setSpaceGroup(spaceGroup.getShortSymbol()); + } + } + // GET THE HEADER INFORMATION + PDBHeader header = bioJavaStruct.getPDBHeader(); + List outMap = generateSerializableBioAssembly(bioJavaStruct, header); + headerStruct.setBioAssembly(outMap); + headerStruct.setTitle(header.getTitle()); + headerStruct.setDescription(header.getDescription()); + headerStruct.setClassification(header.getClassification()); + headerStruct.setDepDate(header.getDepDate()); + headerStruct.setModDate(header.getModDate()); + headerStruct.setResolution(header.getResolution()); + headerStruct.setrFree(header.getRfree()); + + JournalArticle myJournal = header.getJournalArticle(); + if( myJournal==null){ + + } + else{ + headerStruct.setDoi(myJournal.getDoi()); + } + } + + /** + * Generate a serializable biotransformation for storing + * in the messagepack. + * @param bioJavaStruct the Biojava structure + * @param header the header + * @return a map of the bioassembly information that is serializable + */ + private List generateSerializableBioAssembly(Structure bioJavaStruct, PDBHeader header) { + // Get a map to reference asym ids to chains + Map chainIdToIndexMap = getChainIdToIndexMap(bioJavaStruct); + // Here we need to iterate through and get the chain ids and the matrices + Map inputBioAss = header.getBioAssemblies(); + List outMap = new ArrayList(); + for (Map.Entry entry : inputBioAss.entrySet()) { + Map matSet = new HashMap(); + BioAssemblyInfo value = entry.getValue(); + // Make a new one of these + BioAssemblyData newValue = new BioAssemblyData(); + outMap.add(newValue); + // Copy across this info + List outTrans = new ArrayList(); + for(BiologicalAssemblyTransformation transform: value.getTransforms()){ + // Get's the chain id -> this is the asym id + String thisChain = transform.getChainId(); + // Get the current matrix 4d + Matrix4d currentTransMat = transform.getTransformationMatrix(); + double[] outList = new double[16]; + // Iterate over the matrix + for(int i=0; i<4; i++){ + for(int j=0; j<4; j++){ + // Now set this element + outList[i*4+j] = currentTransMat.getElement(i,j); + } + } + if(matSet.containsKey(currentTransMat)){ + // Get the trasnformation + BioAssemblyTrans bioTransNew = matSet.get(currentTransMat); + // Add this chain index to that list + int[] oldList = bioTransNew.getChainIndexList(); + int oldLen = oldList.length; + int[] newList = new int[oldLen+1]; + for (int i=0; i getChainIdToIndexMap(Structure bioJavaStruct) { + // First build a map of asymid -> chain index + Map chainIdToIndexMapOne = new HashMap<>(); + int chainCounter = 0; + for (int i=0; i bioS */ public final void generateDataStructuresFromBioJavaStructure(Structure inputBiojavaStruct, Map bioStructMap) { EncoderUtils encoderUtils = new EncoderUtils(); + BiojavaUtils biojavaUtils = new BiojavaUtils(); // Reset structure to consider altloc groups with the same residue number but different group names as seperate groups - encoderUtils.fixMicroheterogenity(inputBiojavaStruct); + biojavaUtils.fixMicroheterogenity(inputBiojavaStruct); // Generate the secondary structure - encoderUtils.genSecStruct(inputBiojavaStruct); + biojavaUtils.calculateDsspSecondaryStructure(inputBiojavaStruct); // Set the header information - encoderUtils.setHeaderInfo(inputBiojavaStruct, headerStruct); + biojavaUtils.setHeaderInfo(inputBiojavaStruct, headerStruct); // Get the number of models Integer numModels = inputBiojavaStruct.nrModels(); bioStruct.setNumModels(numModels); @@ -221,7 +219,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure inputBioj // Now let's find the entity infomration findEntityInfo(inputBiojavaStruct); // Get all the atoms - List totAtoms = encoderUtils.getAllAtoms(inputBiojavaStruct); + List totAtoms = biojavaUtils.getAllAtoms(inputBiojavaStruct); for (int i=0; i chains = inputBiojavaStruct.getModel(i); @@ -246,37 +244,34 @@ public final void generateDataStructuresFromBioJavaStructure(Structure inputBioj headerStruct.getSequence().add(biojavaChain.getSeqResSequence()); } // Set the auth chain id - setChainId(biojavaChain.getInternalChainID(), charChainList, chainCounter); + encoderUtils.setChainId(biojavaChain.getInternalChainID(), charChainList, chainCounter); // Set the asym chain id - setChainId(biojavaChain.getChainID(), charInternalChainList, chainCounter); + encoderUtils.setChainId(biojavaChain.getChainID(), charInternalChainList, chainCounter); // Set the number of groups per chain groupsPerChain[chainCounter] += biojavaChain.getAtomGroups().size(); // Set the number of groups per internal chain groupsPerInternalChain[chainCounter] = biojavaChain.getAtomGroups().size(); // Add this chain to the list chainList.add(biojavaChain.getChainID()); - // Get the groups - String currentChainId = biojavaChain.getChainID(); + // Reset the number of bonds counter for this chain int numBonds = 0; for (Group loopGroup : biojavaChain.getAtomGroups()) { currentGroup = loopGroup; // Set the seq res group id if(i==0){ headerStruct.getSeqResGroupIds().add(seqResGroups.indexOf(currentGroup)); - } - // Get the pdb id - String res_id = currentGroup.getPDBName(); + } // Get the atoms for this group - List atomsInThisGroup = encoderUtils.getAtomsForGroup(currentGroup); + List atomsInThisGroup = biojavaUtils.getAtomsForGroup(currentGroup); // Get any bonds between groups - getInterGroupBond(atomsInThisGroup, totAtoms, atomCounter); + getInterGroupBond(atomsInThisGroup, totAtoms); // Count the number of bonds // Now loop through and get the coords // Generate the group level data - // Get the atomic data for the group - List atomInfo = getAtomInfo(atomsInThisGroup); + // Get the data that defines a group + List groupInfo = getGroupData(atomsInThisGroup); // Get the atomic info required - bioStruct is the unique identifier of the group - int hashCode = getHashFromStringList(atomInfo); + int hashCode = getHashFromStringList(groupInfo); // If we need bioStruct new information if (hashToRes.containsKey(hashCode)==false){ // Make a new group @@ -285,8 +280,8 @@ public final void generateDataStructuresFromBioJavaStructure(Structure inputBioj outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code().charAt(0)); // Set the group type outGroup.setChemCompType(currentGroup.getChemComp().getType()); - outGroup.setGroupName(atomInfo.remove(0)); - outGroup.setAtomInfo(atomInfo); + outGroup.setGroupName(groupInfo.remove(0)); + outGroup.setAtomInfo(groupInfo); // Now get the bond list (lengths, orders and indices) createBondList(atomsInThisGroup, outGroup); getCharges(atomsInThisGroup, outGroup); @@ -332,7 +327,7 @@ public final void generateDataStructuresFromBioJavaStructure(Structure inputBioj List cAlphaGroup = new ArrayList(); for (Atom currentAtom : atomsInThisGroup) { // Update the structure - addAtomInfo(currentAtom, currentChainId, res_id, residueNum, biojavaChain); + addAtomInfo(currentAtom, loopGroup, biojavaChain); // Update the calpha updateCalpha(cAlphaGroup, currentAtom); // Increment the atom counter @@ -409,7 +404,7 @@ private void addCalphaGroup(List cAlphaGroup,SecStrucState props, ResidueN int thisResNum; if(cAlphaGroup.size()>0){ calphaGroupsPerChain[chainCounter] = calphaGroupsPerChain[chainCounter]+1; - List calphaAtomInfo = getAtomInfo(cAlphaGroup); + List calphaAtomInfo = getGroupData(cAlphaGroup); /// Now consider the C-Alpha, phosophate and ligand cases int calphaHashCode = getHashFromStringList(calphaAtomInfo); // If we need bioStruct new information @@ -470,90 +465,50 @@ private void addCalphaGroup(List cAlphaGroup,SecStrucState props, ResidueN /** - * Update calpha. - * - * @param totG the tot g - * @param cAlphaGroup the c alpha group - * @param a the a + * Add the calpha/phosphate/ligand backbone data to a group. If it is a calpha/phosphate or ligand. + * @param inputAtomData the input list of atoms associated to this group + * @param inputAtom the atom to be added */ - private void updateCalpha(List cAlphaGroup, Atom a) { - // NOW THE CALPHA / PHOSPHATE / LIGAND STUFF - // GET THE CALPHA - if (a.getName().equals("CA") && a.getElement().toString().equals("C")){ + private void updateCalpha(List inputAtomData, Atom inputAtom) { + // Check if it is a calpha + if (inputAtom.getName().equals("CA") && inputAtom.getElement().toString().equals("C")){ // Now add the calpha - cAlphaGroup.add(a); + inputAtomData.add(inputAtom); } - // GET THE PHOSPHATE - if(a.getName().equals("P")){ - cAlphaGroup.add(a); + // Check if it is a phosphate + else if(inputAtom.getName().equals("P")){ + inputAtomData.add(inputAtom); } - // GET THE LIGANDS - if(currentGroup.isWater()==false && currentGroup.getType().name().equals("HETATM")){ - cAlphaGroup.add(a); + // Check if it is a ligand + else if(currentGroup.isWater()==false && currentGroup.getType().name().equals("HETATM")){ + inputAtomData.add(inputAtom); } } /** - * Functon to set the chain id. - * - * @param chainId the chain id - * @param charChainList the char chain list - * @param chainCounter the chain counter + * Add a calpha atom to the C-alpha structure. + * @param inputAtom the input atom data. + * @param secondaryStructureInfo the secondary structure information (DSSP) for the group this atom is related to. + * @param residueNumber the residue number of the group this atom is part of. */ - private void setChainId(String chainId, byte[] charChainList, int chainCounter) { - // A char array to store the chars - char[] outChar = new char[4]; - // The lenght of this chain id - int chainIdLen = chainId.length(); - chainId.getChars(0, chainIdLen, outChar, 0); - // Set the bytrarray - chain ids can be up to 4 chars - pad with empty bytes - charChainList[chainCounter*4+0] = (byte) outChar[0]; - if(chainIdLen>1){ - charChainList[chainCounter*4+1] = (byte) outChar[1]; - } - else{ - charChainList[chainCounter*4+1] = (byte) 0; - } - if(chainIdLen>2){ - charChainList[chainCounter*4+2] = (byte) outChar[2]; - } - else{ - charChainList[chainCounter*4+2] = (byte) 0; - } - if(chainIdLen>3){ - charChainList[chainCounter*4+3] = (byte) outChar[3]; - } - else{ - charChainList[chainCounter*4+3] = (byte) 0; - } - } - - - /** - * Add a new calpha / phosophate / ligand atom. - * - * @param a the a - * @param props the props - * @param residueNumber the residue number (Biojava group) - */ - private void addCalpha(Atom a, SecStrucState props, ResidueNumber residueNumber) { - calphaStruct.setNumAtoms(calphaStruct.getNumAtoms()+1); - calphaStruct.getCartn_x().add((int) Math.round(a.getX()*COORD_MULT)); - calphaStruct.getCartn_y().add((int) Math.round(a.getY()*COORD_MULT)); - calphaStruct.getCartn_z().add((int) Math.round(a.getZ()*COORD_MULT)); + private void addCalpha(Atom inputAtom, SecStrucState secondaryStructureInfo, ResidueNumber residueNumber) { + // Set the number of atoms in the group + calphaStruct.setNumAtoms(calphaStruct.getNumAtoms()+1); + // Covert the cooridnates for this group + calphaStruct.getCartn_x().add((int) Math.round(inputAtom.getX()*COORD_MULT)); + calphaStruct.getCartn_y().add((int) Math.round(inputAtom.getY()*COORD_MULT)); + calphaStruct.getCartn_z().add((int) Math.round(inputAtom.getZ()*COORD_MULT)); // Get the residue name calphaStruct.get_atom_site_auth_seq_id().add(residueNumber.getSeqNum()); calphaStruct.get_atom_site_label_entity_poly_seq_num().add(residueNumber.getSeqNum()); // Now set the sec structure - // - if(props==null){ + if(secondaryStructureInfo==null){ calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString("NA").getDsspIndex()); } else{ - calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString(props.getType().name).getDsspIndex()); + calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString(secondaryStructureInfo.getType().name).getDsspIndex()); } - } @@ -572,15 +527,18 @@ private void getCharges(List inputAtoms, PDBGroup pdbGroup) { /** - * Function to find a hash code from a list of strings. - * - * @param strings the strings - * @return the hash from string list + * Find a unique hash code from a list of strings. + * Multiplies the hashcode of each string in the list by a prime number. + * Finds the product of this. + * @param inputStrings the input strings + * @return the integer hashcode from this string list */ - private int getHashFromStringList(List strings){ + private int getHashFromStringList(List inputStrings){ + // A prime number need for multiplication. int prime = 31; + // The starting number int result = 1; - for( String s : strings ) + for( String s : inputStrings ) { result = result * prime + s.hashCode(); } @@ -592,11 +550,11 @@ private int getHashFromStringList(List strings){ /** * Get the atomic information from a list of Atoms. - * - * @param atomList the atom list - * @return the atom info + * @param atomList the input atom list. + * @return a string list of atomic info comprising the element and name (in pairs) of + * each atom in the input list. */ - private List getAtomInfo(List atomList){ + private List getGroupData(List atomList){ int numAtoms = atomList.size(); int arraySize = numAtoms*2+2; List outString = new ArrayList(arraySize); @@ -611,14 +569,11 @@ private List getAtomInfo(List atomList){ /** - * Find bonds between groups. - * - * @param atoms the atoms - * @param totAtoms the tot atoms - * @param atomCounter the atom counter - * @return the inter group bond + * Finds the atoms between groups in a given input list of atoms + * @param inputAtomsInThisGroup the atoms in the group being considered + * @param totAtoms the total list of atoms across the whole structure. */ - private void getInterGroupBond(List inputAtomsInThisGroup, List totAtoms, int atomCounter){ + private void getInterGroupBond(List inputAtomsInThisGroup, List totAtoms){ // Get the atoms for (Atom currentAtom : inputAtomsInThisGroup) { // Get the atom @@ -651,13 +606,12 @@ private void getInterGroupBond(List inputAtomsInThisGroup, List totA } /** - * Generate lists for the bonds in the group. - * - * @param atoms the atoms - * @param outGroup the out group + * Creates the bond list for a given PDBGroup object. + * @param inputAtoms a list of atoms in the group + * @param pdbGroup a PDBGroup object to update the information to */ - private void createBondList(List atoms, PDBGroup outGroup) { - int n = atoms.size(); + private void createBondList(List inputAtoms, PDBGroup pdbGroup) { + int n = inputAtoms.size(); if (n == 0) { System.out.println("creating empty bond list"); } @@ -670,12 +624,12 @@ private void createBondList(List atoms, PDBGroup outGroup) { for (int i = 0; i < n; i++) { // Get the atom - Atom a = atoms.get(i); + Atom a = inputAtoms.get(i); List thisAtomBonds = a.getBonds(); if(thisAtomBonds!=null){ for (Bond b: thisAtomBonds) { Atom other = b.getOther(a); - int index = atoms.indexOf(other); + int index = inputAtoms.indexOf(other); int order = b.getBondOrder(); // Now build this to check if the indices List thisArr = new ArrayList(); @@ -696,28 +650,23 @@ private void createBondList(List atoms, PDBGroup outGroup) { } } } - outGroup.setBondOrders(bondOrder); - outGroup.setBondIndices(bondList); + pdbGroup.setBondOrders(bondOrder); + pdbGroup.setBondIndices(bondList); } /** - * Adds the atom info. - * - * @param inputAtom the input atom - * @param inputChainId the input chain id - * @param inputResidueId the input residue id - * @param residueNumber the residue number - * @param biojavaChain the input chain + * Add the information for a given atom to the overall structure. + * @param inputAtom the atom to be added + * @param inputGroup the group to be added + * @param inputChain the chain to be added */ - private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidueId, - ResidueNumber residueNumber, Chain biojavaChain) { - + private void addAtomInfo(Atom inputAtom, Group inputGroup, Chain inputChain) { bioStruct.get_atom_site_id().add(inputAtom.getPDBserial()); // Atom symbol Element ele = inputAtom.getElement(); bioStruct.get_atom_site_symbol().add(ele.toString()); - bioStruct.get_atom_site_asym_id().add(inputChainId); + bioStruct.get_atom_site_asym_id().add(inputChain.getChainID()); // identify coordinate records (e.g. ATOM or HETATM). bioStruct.get_atom_site_group_PDB().add(GroupType.groupTypeFromString(inputAtom.getGroup().getType().toString()).getGroupType()); // bioStruct item is a uniquely identifies for each alternative site for @@ -734,7 +683,7 @@ private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidu // structure determined by crystallographic method bioStruct corresponds // to a unique identifier within the cyrstallographic asymmetric // unit. - bioStruct.get_atom_site_label_asym_id().add(biojavaChain.getInternalChainID().toString()); + bioStruct.get_atom_site_label_asym_id().add(inputChain.getInternalChainID().toString()); // bioStruct data item is a reference to item _chem_comp_atom.atom_id // defined in category CHEM_COMP_ATOM which is stored in the // Chemical Component Dictionary. bioStruct atom identifier uniquely @@ -756,7 +705,7 @@ private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidu // entity and the sequence information in the coordinate list and in // may other structural categories. bioStruct identifier has no meaning // for non-polymer entities. - bioStruct.get_atom_site_label_entity_poly_seq_num().add(residueNumber.getSeqNum()); + bioStruct.get_atom_site_label_entity_poly_seq_num().add(inputGroup.getResidueNumber().getSeqNum()); // Cartesian coordinate components describing the position of bioStruct // atom site. bioStruct.get_atom_site_Cartn_x().add(inputAtom.getX()); @@ -768,8 +717,4 @@ private void addAtomInfo(Atom inputAtom, String inputChainId, String inputResidu bioStruct.get_atom_site_occupancy().add(inputAtom.getOccupancy()); // The net integer charge assigned to bioStruct atom. } - - - - } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java similarity index 97% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java index f0cae2b..32df517 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java @@ -1,10 +1,11 @@ -package org.rcsb.mmtf.biojavaencoder; +package org.rcsb.mmtf.encoder; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.biojava.nbio.structure.Structure; +import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java similarity index 63% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java index 93ec8d5..0f86e48 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java @@ -1,11 +1,7 @@ -package org.rcsb.mmtf.biojavaencoder; - - - +package org.rcsb.mmtf.encoder; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; @@ -14,33 +10,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.zip.GZIPOutputStream; -import javax.vecmath.Matrix4d; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.JournalArticle; -import org.biojava.nbio.structure.PDBCrystallographicInfo; -import org.biojava.nbio.structure.PDBHeader; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; -import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; -import org.biojava.nbio.structure.secstruc.DSSPParser; -import org.biojava.nbio.structure.secstruc.SecStrucCalc; -import org.biojava.nbio.structure.xtal.CrystalCell; -import org.biojava.nbio.structure.xtal.SpaceGroup; import org.msgpack.jackson.dataformat.MessagePackFactory; import org.rcsb.mmtf.arraycompressors.FindDeltas; import org.rcsb.mmtf.arraycompressors.IntArrayCompressor; @@ -49,8 +22,6 @@ import org.rcsb.mmtf.arraycompressors.StringArrayCompressor; import org.rcsb.mmtf.biocompressors.BioCompressor; import org.rcsb.mmtf.biocompressors.CompressDoubles; -import org.rcsb.mmtf.dataholders.BioAssemblyData; -import org.rcsb.mmtf.dataholders.BioAssemblyTrans; import org.rcsb.mmtf.dataholders.BioDataStruct; import org.rcsb.mmtf.dataholders.CalphaBean; import org.rcsb.mmtf.dataholders.CalphaDistBean; @@ -343,6 +314,43 @@ public final byte[] gzipCompress(byte[] inputArray){ return byteArrayOutputStream.toByteArray(); } + + /** + * Set the chain id of a given chain to the byte array comprising the chain ids (as chars). + * Chain ids can be up to four chars long. If they are shorter they are padded using 0 bytes. + * @param chainId the string chain id. + * @param charChainList the char chain list. The current chain list of chars. + * @param chainIndex the chain index. The current chain index. + */ + public void setChainId(String chainId, byte[] charChainList, int chainIndex) { + // A char array to store the chars + char[] outChar = new char[4]; + // The length of this chain id + int chainIdLen = chainId.length(); + chainId.getChars(0, chainIdLen, outChar, 0); + // Set the bytrarray - chain ids can be up to 4 chars - pad with empty bytes + charChainList[chainIndex*4+0] = (byte) outChar[0]; + if(chainIdLen>1){ + charChainList[chainIndex*4+1] = (byte) outChar[1]; + } + else{ + charChainList[chainIndex*4+1] = (byte) 0; + } + if(chainIdLen>2){ + charChainList[chainIndex*4+2] = (byte) outChar[2]; + } + else{ + charChainList[chainIndex*4+2] = (byte) 0; + } + if(chainIdLen>3){ + charChainList[chainIndex*4+3] = (byte) outChar[3]; + } + else{ + charChainList[chainIndex*4+3] = (byte) 0; + } + } + + /** * Function to compress the input biological data. * @param inputBioDataStruct the input data structure @@ -436,299 +444,4 @@ public final CalphaDistBean compCAlpha(CalphaBean calphaData, HeaderBean inHeade return calphaOut; } - /** - * Set up the configuration parameters for BioJava. - */ - public AtomCache setUpBioJava() { - // Set up the atom cache etc - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - params.setUseInternalChainId(true); - CustomChemCompProvider cc = new CustomChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(cc); - cc.checkDoFirstInstall(); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - return cache; - } - - /** - * Set up the configuration parameters for BioJava. - with an extra URL - */ - public AtomCache setUpBioJava(String extraUrl) { - // Set up the atom cache etc - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - params.setUseInternalChainId(true); - CustomChemCompProvider cc = new CustomChemCompProvider(extraUrl); - ChemCompGroupFactory.setChemCompProvider(cc); - cc.checkDoFirstInstall(); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - return cache; - } - - - /** - * This sets all microheterogeneous groups (previously alternate location groups) as separate groups. - * @param bioJavaStruct - */ - public final void fixMicroheterogenity(Structure bioJavaStruct) { - // Loop through the models - for (int i=0; i chains = bioJavaStruct.getModel(i); - for (Chain c : chains) { - // Build a new list of groups - List outGroups = new ArrayList<>(); - for (Group g : c.getAtomGroups()) { - List removeList = new ArrayList<>(); - for (Group altLoc : g.getAltLocs()) { - // Check if they are not equal -> microheterogenity - if(! altLoc.getPDBName().equals(g.getPDBName())) { - // Now add this group to the main list - removeList.add(altLoc); - } - } - // Add this group - outGroups.add(g); - // Remove any microhet alt locs - g.getAltLocs().removeAll(removeList); - // Add these microhet alt locs - outGroups.addAll(removeList); - } - c.setAtomGroups(outGroups); - } - } - } - - /** - * Function to get all the atoms in the strucutre as a list. - * - * @param bioJavaStruct the bio java struct - * @return the all atoms - */ - public final List getAllAtoms(Structure bioJavaStruct) { - // Get all the atoms - List theseAtoms = new ArrayList(); - for (int i=0; i chains = bioJavaStruct.getModel(i); - for (Chain c : chains) { - for (Group g : c.getAtomGroups()) { - for(Atom a: getAtomsForGroup(g)){ - theseAtoms.add(a); - } - } - } - } - return theseAtoms; - } - - /** - * Function to get a list of atoms for a group. - * - * @param inputGroup the Biojava Group to consider - * @return the atoms for the input Biojava Group - */ - public final List getAtomsForGroup(Group inputGroup) { - Set uniqueAtoms = new HashSet(); - List theseAtoms = new ArrayList(); - for(Atom a: inputGroup.getAtoms()){ - theseAtoms.add(a); - uniqueAtoms.add(a); - } - List altLocs = inputGroup.getAltLocs(); - for(Group thisG: altLocs){ - for(Atom a: thisG.getAtoms()){ - if(uniqueAtoms.contains(a)){ - continue; - } - theseAtoms.add(a); - } - } - return theseAtoms; - } - - - /** - * Function to generate the secondary structuee for a biojava structure object. - * @param bioJavaStruct the bio java struct - */ - public void genSecStruct(Structure bioJavaStruct) { - SecStrucCalc ssp = new SecStrucCalc(); - try{ - ssp.calculate(bioJavaStruct, true); - } - - catch(StructureException e) { - try{ - DSSPParser.fetch(bioJavaStruct.getPDBCode(), bioJavaStruct, true); //download from PDB the DSSP result - } - catch(FileNotFoundException enew){ - } - catch(Exception bige){ - System.out.println(bige); - } - } - - } - - /** - * Sets the header information. - * @param bioJavaStruct the new header info - */ - public void setHeaderInfo(Structure bioJavaStruct, HeaderBean headerStruct) { - headerStruct.setPdbCode(bioJavaStruct.getPDBCode()); - // Now get hte xtalographic info - PDBCrystallographicInfo xtalInfo = bioJavaStruct.getCrystallographicInfo(); - CrystalCell xtalCell = xtalInfo.getCrystalCell(); - SpaceGroup spaceGroup = xtalInfo.getSpaceGroup(); - float[] inputUnitCell = new float[6]; - if(xtalCell==null){ - - }else{ - headerStruct.setUnitCell(inputUnitCell); - inputUnitCell[0] = (float) xtalCell.getA(); - inputUnitCell[1] = (float) xtalCell.getB(); - inputUnitCell[2] = (float) xtalCell.getC(); - inputUnitCell[3] = (float) xtalCell.getAlpha(); - inputUnitCell[4] = (float) xtalCell.getBeta(); - inputUnitCell[5] = (float) xtalCell.getGamma(); - if(spaceGroup==null){ - // This could be the I21 shown here - headerStruct.setSpaceGroup("NA"); - } - else{ - headerStruct.setSpaceGroup(spaceGroup.getShortSymbol()); - } - } - // GET THE HEADER INFORMATION - PDBHeader header = bioJavaStruct.getPDBHeader(); - List outMap = generateSerializableBioAssembly(bioJavaStruct, header); - headerStruct.setBioAssembly(outMap); - headerStruct.setTitle(header.getTitle()); - headerStruct.setDescription(header.getDescription()); - headerStruct.setClassification(header.getClassification()); - headerStruct.setDepDate(header.getDepDate()); - headerStruct.setModDate(header.getModDate()); - headerStruct.setResolution(header.getResolution()); - headerStruct.setrFree(header.getRfree()); - - JournalArticle myJournal = header.getJournalArticle(); - if( myJournal==null){ - - } - else{ - headerStruct.setDoi(myJournal.getDoi()); - } - } - - /** - * Generate a serializable biotransformation for storing - * in the messagepack. - * @param bioJavaStruct the Biojava structure - * @param header the header - * @return a map of the bioassembly information that is serializable - */ - private List generateSerializableBioAssembly(Structure bioJavaStruct, PDBHeader header) { - // Get a map to reference asym ids to chains - Map chainIdToIndexMap = getChainIdToIndexMap(bioJavaStruct); - // Here we need to iterate through and get the chain ids and the matrices - Map inputBioAss = header.getBioAssemblies(); - List outMap = new ArrayList(); - for (Map.Entry entry : inputBioAss.entrySet()) { - Map matSet = new HashMap(); - BioAssemblyInfo value = entry.getValue(); - // Make a new one of these - BioAssemblyData newValue = new BioAssemblyData(); - outMap.add(newValue); - // Copy across this info - List outTrans = new ArrayList(); - for(BiologicalAssemblyTransformation transform: value.getTransforms()){ - // Get's the chain id -> this is the asym id - String thisChain = transform.getChainId(); - // Get the current matrix 4d - Matrix4d currentTransMat = transform.getTransformationMatrix(); - double[] outList = new double[16]; - // Iterate over the matrix - for(int i=0; i<4; i++){ - for(int j=0; j<4; j++){ - // Now set this element - outList[i*4+j] = currentTransMat.getElement(i,j); - } - } - if(matSet.containsKey(currentTransMat)){ - // Get the trasnformation - BioAssemblyTrans bioTransNew = matSet.get(currentTransMat); - // Add this chain index to that list - int[] oldList = bioTransNew.getChainIndexList(); - int oldLen = oldList.length; - int[] newList = new int[oldLen+1]; - for (int i=0; i getChainIdToIndexMap(Structure bioJavaStruct) { - // First build a map of asymid -> chain index - Map chainIdToIndexMapOne = new HashMap<>(); - int chainCounter = 0; - for (int i=0; i totalAtoms = new ArrayList<>(encoderUtils.getAllAtoms(inputStructure)); + List totalAtoms = new ArrayList<>(biojavaUtils.getAllAtoms(inputStructure)); int totGroups = 0; int totAtomsCounter = 0; Set totAtoms = new HashSet<>(); @@ -49,7 +51,7 @@ public void microHeterogenity() throws IOException, StructureException { } } // Now "fix" the microheterogenity - encoderUtils.fixMicroheterogenity(inputStructure); + biojavaUtils.fixMicroheterogenity(inputStructure); assertEquals(before, inputStructure.getChains().get(0).getAtomGroup(17)); assertFalse(inputStructure.getChains().get(0).getAtomGroup(17).hasAltLoc()); assertFalse(inputStructure.getChains().get(0).getAtomGroup(18).hasAltLoc()); @@ -68,7 +70,7 @@ public void microHeterogenity() throws IOException, StructureException { } } // Find the atoms after the fix. - List totalAtomsAfter = new ArrayList<>(encoderUtils.getAllAtoms(inputStructure)); + List totalAtomsAfter = new ArrayList<>(biojavaUtils.getAllAtoms(inputStructure)); // Get all of the duplicate atoms Set duplicates = findDuplicates(totalAtomsAfter); for (Atom a : duplicates) { @@ -86,6 +88,20 @@ public void microHeterogenity() throws IOException, StructureException { } + +//TODO ADD TESTS FOR THESE FUNCTIONS +// getAllAtoms +// +// getAtomsForGroup +// +// calculateDsspSecondaryStructure +// +// setHeaderInfo +// +// generateSerializableBioAssembly +// +// getChainIdToIndexMap + private Set findDuplicates(List listContainingDuplicates) { final Set setToReturn = new HashSet<>(); diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index 8498304..56e1ba1 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -17,8 +17,8 @@ import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.junit.Test; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.biojavaencoder.EncoderUtils; import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; +import org.rcsb.mmtf.encoder.EncoderUtils; import org.unitils.reflectionassert.ReflectionAssert; import com.fasterxml.jackson.core.JsonParseException; diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java new file mode 100644 index 0000000..b02a5bd --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java @@ -0,0 +1,18 @@ +package org.rcsb.mmtf.encoder; + +public class TestEncoderUtils { +// integersToBytes +// getMessagePack +// compressToMmtfBean +// convertRunLengthStringListToIntArray +// convertToIsoTime +// genGroupList +// addByteArrs +// integersToSmallBytes +// splitListIntsToByteArrays +// gzipCompress +// setChainId +// // These two should be moved out +// compressInputData +// compCAlpha +} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java index 3295180..a9129d4 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java @@ -6,11 +6,11 @@ import java.util.List; import org.apache.spark.api.java.function.PairFlatMapFunction; -import org.rcsb.mmtf.biojavaencoder.EncoderUtils; import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; import org.rcsb.mmtf.dataholders.BioDataStruct; import org.rcsb.mmtf.dataholders.CalphaDistBean; import org.rcsb.mmtf.dataholders.HeaderBean; +import org.rcsb.mmtf.encoder.EncoderUtils; import scala.Tuple2; diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index 6ea1e67..37e3655 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -10,7 +10,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; -import org.rcsb.mmtf.biojavaencoder.EncoderUtils; +import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.decoder.DecodeStructure; import org.rcsb.mmtf.decoder.ParsingParams; @@ -56,8 +56,8 @@ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) */ public JavaPairRDD generateRDD(JavaSparkContext sparkContext, List inputList, String inputUrl) { // Set up Biojava appropriateyl - EncoderUtils encoderUtils = new EncoderUtils(); - encoderUtils.setUpBioJava(inputUrl); + BiojavaUtils biojavaUtils = new BiojavaUtils(); + biojavaUtils.setUpBioJava(inputUrl); return sparkContext.parallelize(inputList) .mapToPair(new PdbIdToDataStruct()) .flatMapToPair(new DataStructToByteArrs()) diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index a0284ae..5326f0a 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -9,7 +9,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; -import org.rcsb.mmtf.biojavaencoder.EncoderUtils; +import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.decoder.ParsingParams; import org.rcsb.mmtf.examples.HandleIO; import org.rcsb.mmtf.testutils.CheckOnBiojava; @@ -48,8 +48,8 @@ public void basicParsingTest(String baseUrl) throws IOException { // Get the class to parse and get data handleIo = new HandleIO(); checkEquiv = new CheckOnBiojava(); - EncoderUtils encoderUtils = new EncoderUtils(); - AtomCache cache = encoderUtils.setUpBioJava(); + BiojavaUtils biojavaUtils = new BiojavaUtils(); + AtomCache cache = biojavaUtils.setUpBioJava(); params = cache.getFileParsingParams(); // Test it for a series of structures for (String pdbId : IntegrationTestUtils.TEST_CASES) { diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java index 0779a21..da924ce 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java @@ -9,7 +9,7 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.rcsb.mmtf.biojavaencoder.EncoderUtils; +import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.update.ServerUtils; import org.rcsb.mmtf.update.TestingUtils; import org.rcsb.mmtf.update.WeeklyUpdateUtils; @@ -37,9 +37,9 @@ public static void main(String[] args) throws IllegalAccessException, Invocation // Set up the atom cache etc - EncoderUtils encoderUtils = new EncoderUtils(); + BiojavaUtils biojavaUtils = new BiojavaUtils(); ServerUtils serverUtils = new ServerUtils(); - AtomCache cache = encoderUtils.setUpBioJava(args[3]); + AtomCache cache = biojavaUtils.setUpBioJava(args[3]); // Now get the list of PDB ids to ignore List ignoreList = new ArrayList<>(); for (int i=4; i Date: Wed, 6 Apr 2016 13:47:05 -0700 Subject: [PATCH 038/108] Updates and refactoring to the encoder. Extract an interface from the encoder. Biojava is the first implementation of that interface. --- ...omBiojava.java => BiojavaEncoderImpl.java} | 71 ++++++++----------- .../rcsb/mmtf/encoder/EncodeStructure.java | 18 ++--- .../rcsb/mmtf/encoder/EncoderInterface.java | 62 ++++++++++++++++ .../mmtf/dataholders/TestDataHolders.java | 7 +- .../mmtf/mappers/DataStructToByteArrs.java | 9 +-- .../rcsb/mmtf/mappers/PdbIdToDataStruct.java | 14 ++-- .../org/rcsb/mmtf/update/TestingUtils.java | 2 +- 7 files changed, 119 insertions(+), 64 deletions(-) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/{ParseFromBiojava.java => BiojavaEncoderImpl.java} (94%) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java similarity index 94% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java index 429e629..3c36cca 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/ParseFromBiojava.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java @@ -26,15 +26,14 @@ import org.rcsb.mmtf.dataholders.DsspType; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.HeaderBean; +import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; +import org.rcsb.mmtf.encoder.EncoderInterface; import org.rcsb.mmtf.encoder.EncoderUtils; /** A class to use biojava to parse MMCIF data and produce a data structure that can be fed into the MMTF. */ -public class ParseFromBiojava { - - /** The multiplication factor for coordinate information */ - private static final int COORD_MULT = 1000; +public class BiojavaEncoderImpl implements EncoderInterface { /** The bio struct. */ private BioDataStruct bioStruct = new BioDataStruct(); @@ -46,7 +45,7 @@ public class ParseFromBiojava { private HeaderBean headerStruct = new HeaderBean(); /** The bonds for the structure. Used to keep track of which bonds have already been considered */ - private List totBonds = new ArrayList(); + private List totBonds = new ArrayList(); /** The number of groups per calpha chain. */ private int[] calphaGroupsPerChain; @@ -67,74 +66,66 @@ public class ParseFromBiojava { private Group currentGroup; - /** - * Gets the bio struct. - * - * @return the bio struct + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#getBioStruct() */ + @Override public BioDataStruct getBioStruct() { return bioStruct; } - /** - * Sets the bio struct. - * - * @param bioStruct the new bio struct + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#setBioStruct(org.rcsb.mmtf.dataholders.BioDataStruct) */ + @Override public void setBioStruct(BioDataStruct bioStruct) { this.bioStruct = bioStruct; } - /** - * Gets the calpha struct. - * - * @return the calpha struct + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#getCalphaStruct() */ + @Override public CalphaBean getCalphaStruct() { return calphaStruct; } - /** - * Sets the calpha struct. - * - * @param calphaStruct the new calpha struct + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#setCalphaStruct(org.rcsb.mmtf.dataholders.CalphaBean) */ + @Override public void setCalphaStruct(CalphaBean calphaStruct) { this.calphaStruct = calphaStruct; } - /** - * Gets the header struct. - * - * @return the header struct + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#getHeaderStruct() */ + @Override public HeaderBean getHeaderStruct() { return headerStruct; } - /** - * Sets the header struct. - * - * @param headerStruct the new header struct + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#setHeaderStruct(org.rcsb.mmtf.dataholders.HeaderBean) */ + @Override public void setHeaderStruct(HeaderBean headerStruct) { this.headerStruct = headerStruct; } - /** - * Helper function to generate a main, calpha and header data form a PDB id. - * - * @param pdbId the pdb id - * @param bioStructMap the bio struct map + /* (non-Javadoc) + * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#generateDataStructuresFromPdbId(java.lang.String, java.util.Map) */ - public final void createFromJavaStruct(String pdbId, Map bioStructMap) { + @Override + public final void generateDataStructuresFromPdbId(String pdbId, Map bioStructMap) { // Get the structure from here Structure bioJavaStruct; try { @@ -148,7 +139,7 @@ public final void createFromJavaStruct(String pdbId, Map bioS System.err.println("Error in parsing structure for input: "+pdbId); throw new RuntimeException(e); } - generateDataStructuresFromBioJavaStructure(bioJavaStruct, bioStructMap); + generateDataStructuresFromPdbId(bioJavaStruct, bioStructMap); } @@ -159,7 +150,7 @@ public final void createFromJavaStruct(String pdbId, Map bioS * @param bioStructMap the map relating hash codes to PDB groups. * input so that a consistent map can be held across several structures */ - public final void generateDataStructuresFromBioJavaStructure(Structure inputBiojavaStruct, Map bioStructMap) { + public final void generateDataStructuresFromPdbId(Structure inputBiojavaStruct, Map bioStructMap) { EncoderUtils encoderUtils = new EncoderUtils(); BiojavaUtils biojavaUtils = new BiojavaUtils(); // Reset structure to consider altloc groups with the same residue number but different group names as seperate groups @@ -496,9 +487,9 @@ private void addCalpha(Atom inputAtom, SecStrucState secondaryStructureInfo, Res // Set the number of atoms in the group calphaStruct.setNumAtoms(calphaStruct.getNumAtoms()+1); // Covert the cooridnates for this group - calphaStruct.getCartn_x().add((int) Math.round(inputAtom.getX()*COORD_MULT)); - calphaStruct.getCartn_y().add((int) Math.round(inputAtom.getY()*COORD_MULT)); - calphaStruct.getCartn_z().add((int) Math.round(inputAtom.getZ()*COORD_MULT)); + calphaStruct.getCartn_x().add((int) Math.round(inputAtom.getX()*MmtfBean.COORD_DIVIDER)); + calphaStruct.getCartn_y().add((int) Math.round(inputAtom.getY()*MmtfBean.COORD_DIVIDER)); + calphaStruct.getCartn_z().add((int) Math.round(inputAtom.getZ()*MmtfBean.COORD_DIVIDER)); // Get the residue name calphaStruct.get_atom_site_auth_seq_id().add(residueNumber.getSeqNum()); calphaStruct.get_atom_site_label_entity_poly_seq_num().add(residueNumber.getSeqNum()); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java index 32df517..8bf4094 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java @@ -5,7 +5,7 @@ import java.util.Map; import org.biojava.nbio.structure.Structure; -import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; +import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; @@ -19,10 +19,10 @@ public class EncodeStructure { */ public final byte[] getCompressedMessagePackFromPdbId(String pdbId) { // Get the utility class to get the strucutes - ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); + EncoderInterface parsedDataStruct = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - parsedDataStruct.createFromJavaStruct(pdbId, totMap); + parsedDataStruct.generateDataStructuresFromPdbId(pdbId, totMap); // Compress the data and get it back out return buildFromDataStructure(parsedDataStruct); } @@ -32,12 +32,12 @@ public final byte[] getCompressedMessagePackFromPdbId(String pdbId) { * @param bioJavaStruct * @return a byte array of compressed data */ - public final byte[] encodeFromBiojava(Structure bioJavaStruct){ + public final byte[] encodeFromPdbId(Structure bioJavaStruct){ // Get the utility class to get the strucutes - ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); + BiojavaEncoderImpl parsedDataStruct = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - parsedDataStruct.generateDataStructuresFromBioJavaStructure(bioJavaStruct, totMap); + parsedDataStruct.generateDataStructuresFromPdbId(bioJavaStruct, totMap); return buildFromDataStructure(parsedDataStruct); } @@ -46,7 +46,7 @@ public final byte[] encodeFromBiojava(Structure bioJavaStruct){ * @param parsedDataStruct * @return a byte array of compressed data */ - private final byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { + private final byte[] buildFromDataStructure(EncoderInterface parsedDataStruct) { EncoderUtils eu = new EncoderUtils(); // Compress the data and get it back out try { @@ -68,10 +68,10 @@ private final byte[] buildFromDataStructure(ParseFromBiojava parsedDataStruct) { public final byte[] encodeBackBoneFromPdbId(String pdbId){ // Get the two utility classes EncoderUtils eu = new EncoderUtils(); - ParseFromBiojava cbs = new ParseFromBiojava(); + EncoderInterface cbs = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - cbs.createFromJavaStruct(pdbId, totMap); + cbs.generateDataStructuresFromPdbId(pdbId, totMap); // Compress the data and get it back out try { return eu.getMessagePack(eu.compCAlpha(cbs.getCalphaStruct(), cbs.getHeaderStruct())); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java new file mode 100644 index 0000000..5d9db24 --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java @@ -0,0 +1,62 @@ +package org.rcsb.mmtf.encoder; + +import java.util.Map; + +import org.rcsb.mmtf.dataholders.BioDataStruct; +import org.rcsb.mmtf.dataholders.CalphaBean; +import org.rcsb.mmtf.dataholders.HeaderBean; +import org.rcsb.mmtf.dataholders.PDBGroup; + +public interface EncoderInterface { + + /** + * Gets the bio struct. + * + * @return the bio struct + */ + BioDataStruct getBioStruct(); + + /** + * Sets the bio struct. + * + * @param bioStruct the new bio struct + */ + void setBioStruct(BioDataStruct bioStruct); + + /** + * Gets the calpha struct. + * + * @return the calpha struct + */ + CalphaBean getCalphaStruct(); + + /** + * Sets the calpha struct. + * + * @param calphaStruct the new calpha struct + */ + void setCalphaStruct(CalphaBean calphaStruct); + + /** + * Gets the header struct. + * + * @return the header struct + */ + HeaderBean getHeaderStruct(); + + /** + * Sets the header struct. + * + * @param headerStruct the new header struct + */ + void setHeaderStruct(HeaderBean headerStruct); + + /** + * Helper function to generate a main, calpha and header data form a PDB id. + * + * @param pdbId the pdb id + * @param bioStructMap the bio struct map + */ + void generateDataStructuresFromPdbId(String pdbId, Map bioStructMap); + +} \ No newline at end of file diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index 56e1ba1..b8c1173 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -17,7 +17,8 @@ import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.junit.Test; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; +import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; +import org.rcsb.mmtf.encoder.EncoderInterface; import org.rcsb.mmtf.encoder.EncoderUtils; import org.unitils.reflectionassert.ReflectionAssert; @@ -147,10 +148,10 @@ private void testDataComplete(String pdbId) throws IOException { // Utility functions for encoding stuff EncoderUtils eu = new EncoderUtils(); // Get the utility class to get the structures - ParseFromBiojava parsedDataStruct = new ParseFromBiojava(); + EncoderInterface parsedDataStruct = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - parsedDataStruct.createFromJavaStruct(pdbId, totMap); + parsedDataStruct.generateDataStructuresFromPdbId(pdbId, totMap); MmtfBean mmtfBean = null; // Compress the data and get it back out mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java index a9129d4..042d3c7 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java @@ -6,10 +6,11 @@ import java.util.List; import org.apache.spark.api.java.function.PairFlatMapFunction; -import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; +import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.dataholders.BioDataStruct; import org.rcsb.mmtf.dataholders.CalphaDistBean; import org.rcsb.mmtf.dataholders.HeaderBean; +import org.rcsb.mmtf.encoder.EncoderInterface; import org.rcsb.mmtf.encoder.EncoderUtils; import scala.Tuple2; @@ -20,16 +21,16 @@ * @author Anthony Bradley * */ -public class DataStructToByteArrs implements PairFlatMapFunction, String, byte[]>{ +public class DataStructToByteArrs implements PairFlatMapFunction, String, byte[]>{ private static final long serialVersionUID = 2066093446043635571L; @Override - public Iterable> call(Tuple2 t) throws IOException, IllegalAccessException, InvocationTargetException { + public Iterable> call(Tuple2 t) throws IOException, IllegalAccessException, InvocationTargetException { // First generate the list to return List> outList = new ArrayList>(); EncoderUtils cm = new EncoderUtils(); - ParseFromBiojava cbs = t._2; + EncoderInterface cbs = t._2; String pdbCode = t._1; // Now get the header too HeaderBean headerData = cbs.getHeaderStruct(); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java index 44dbf3e..67321cd 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.spark.api.java.function.PairFunction; -import org.rcsb.mmtf.biojavaencoder.ParseFromBiojava; +import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.dataholders.PDBGroup; import scala.Tuple2; @@ -14,25 +14,25 @@ * @author Anthony Bradley * */ -public class PdbIdToDataStruct implements PairFunction{ +public class PdbIdToDataStruct implements PairFunction{ private static final long serialVersionUID = 786599975302506694L; @Override - public Tuple2 call(String t) throws Exception { - ParseFromBiojava cbs = new ParseFromBiojava(); + public Tuple2 call(String t) throws Exception { + BiojavaEncoderImpl cbs = new BiojavaEncoderImpl(); Map totMap = new HashMap(); try{ - cbs.createFromJavaStruct(t, totMap); + cbs.generateDataStructuresFromPdbId(t, totMap); } catch(Exception e){ // Just return the object System.out.println(e+" :: "+t); System.out.println(e.getMessage()); - return new Tuple2(t,cbs); + return new Tuple2(t,cbs); } // If it doesn't fail also return the object - return new Tuple2(t,cbs); + return new Tuple2(t,cbs); } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index fa8a996..2d6c7b7 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -68,7 +68,7 @@ public Structure roundTripStruct(String pdbId, ParsingParams pp, FileParsingPara StructureIO.setAtomCache(cache); EncodeStructure es = new EncodeStructure(); Structure mmcifStruct = StructureIO.getStructure(pdbId); - FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromBiojava(mmcifStruct)); + FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromPdbId(mmcifStruct)); byte[] inArr = FileUtils.readFileToByteArray(new File("pathname")); // Now do the checks on the Raw data CheckOnRawApi checkRaw = new CheckOnRawApi(inArr); From 1c729ac9e65990497f8129df7306fe66f3b346b7 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 13:55:19 -0700 Subject: [PATCH 039/108] Updates to remove warnings and to refactor --- mmtf-api/pom.xml | 2 -- mmtf-common/pom.xml | 2 -- .../rcsb/mmtf/encoder/EncodeStructure.java | 23 ++++++++----------- .../rcsb/mmtf/encoder/EncoderInterface.java | 5 ++++ .../org/rcsb/mmtf/encoder/EncoderUtils.java | 2 +- .../mmtf/mappers/DataStructToByteArrs.java | 2 +- .../org/rcsb/mmtf/update/TestingUtils.java | 5 ++-- 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/mmtf-api/pom.xml b/mmtf-api/pom.xml index a2140b5..515363f 100644 --- a/mmtf-api/pom.xml +++ b/mmtf-api/pom.xml @@ -22,8 +22,6 @@ junit junit - 4.11 - test diff --git a/mmtf-common/pom.xml b/mmtf-common/pom.xml index 3094fc7..7ba2cbc 100644 --- a/mmtf-common/pom.xml +++ b/mmtf-common/pom.xml @@ -24,8 +24,6 @@ junit junit - 4.11 - test diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java index 8bf4094..ff17ccc 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java @@ -4,8 +4,6 @@ import java.util.HashMap; import java.util.Map; -import org.biojava.nbio.structure.Structure; -import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; @@ -17,14 +15,13 @@ public class EncodeStructure { * @param pdbId * @return a byte array of compressed data */ - public final byte[] getCompressedMessagePackFromPdbId(String pdbId) { + public final byte[] getCompressedMessagePackFromPdbId(String pdbId, EncoderInterface encoderInterface) { // Get the utility class to get the strucutes - EncoderInterface parsedDataStruct = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - parsedDataStruct.generateDataStructuresFromPdbId(pdbId, totMap); + encoderInterface.generateDataStructuresFromPdbId(pdbId, totMap); // Compress the data and get it back out - return buildFromDataStructure(parsedDataStruct); + return buildFromDataStructure(encoderInterface); } /** @@ -32,13 +29,12 @@ public final byte[] getCompressedMessagePackFromPdbId(String pdbId) { * @param bioJavaStruct * @return a byte array of compressed data */ - public final byte[] encodeFromPdbId(Structure bioJavaStruct){ + public final byte[] encodeFromPdbId(String pdbId, EncoderInterface encoderInterface){ // Get the utility class to get the strucutes - BiojavaEncoderImpl parsedDataStruct = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - parsedDataStruct.generateDataStructuresFromPdbId(bioJavaStruct, totMap); - return buildFromDataStructure(parsedDataStruct); + encoderInterface.generateDataStructuresFromPdbId(pdbId, totMap); + return buildFromDataStructure(encoderInterface); } /** @@ -65,16 +61,15 @@ private final byte[] buildFromDataStructure(EncoderInterface parsedDataStruct) { * @param pdbId The input pdb id * @return a byte array of compressed calpha data */ - public final byte[] encodeBackBoneFromPdbId(String pdbId){ + public final byte[] encodeBackBoneFromPdbId(String pdbId,EncoderInterface encoderInterface){ // Get the two utility classes EncoderUtils eu = new EncoderUtils(); - EncoderInterface cbs = new BiojavaEncoderImpl(); Map totMap = new HashMap(); // Parse the data into the basic data structure - cbs.generateDataStructuresFromPdbId(pdbId, totMap); + encoderInterface.generateDataStructuresFromPdbId(pdbId, totMap); // Compress the data and get it back out try { - return eu.getMessagePack(eu.compCAlpha(cbs.getCalphaStruct(), cbs.getHeaderStruct())); + return eu.getMessagePack(eu.compressCalpha(encoderInterface.getCalphaStruct(), encoderInterface.getHeaderStruct())); } catch (IOException e) { e.printStackTrace(); System.err.println("Error in reading or writing byte array"); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java index 5d9db24..20fa4f7 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java @@ -7,6 +7,11 @@ import org.rcsb.mmtf.dataholders.HeaderBean; import org.rcsb.mmtf.dataholders.PDBGroup; +/** + * An interface to be used in encoding structures + * @author Anthony Bradley + * + */ public interface EncoderInterface { /** diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java index 0f86e48..5a1794f 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java @@ -396,7 +396,7 @@ public final CoreSingleStructure compressInputData(BioDataStruct inputBioDataStr * @return the compressed calpha data * @throws IOException Signals that an I/O exception has occurred. */ - public final CalphaDistBean compCAlpha(CalphaBean calphaData, HeaderBean inHeader) throws IOException { + public final CalphaDistBean compressCalpha(CalphaBean calphaData, HeaderBean inHeader) throws IOException { EncoderUtils cm = new EncoderUtils(); // Create the object to leave CalphaDistBean calphaOut = new CalphaDistBean(); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java index 042d3c7..feca12d 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java @@ -35,7 +35,7 @@ public Iterable> call(Tuple2 // Now get the header too HeaderBean headerData = cbs.getHeaderStruct(); BioDataStruct thisBS = cbs.getBioStruct(); - CalphaDistBean calphaDistStruct = cm.compCAlpha(cbs.getCalphaStruct(), cbs.getHeaderStruct()); + CalphaDistBean calphaDistStruct = cm.compressCalpha(cbs.getCalphaStruct(), cbs.getHeaderStruct()); // NOW JUST WRITE THE KEY VALUE PAIRS HERE byte[] totBytes = cm.getMessagePack(cm.compressToMmtfBean(thisBS, headerData)); byte[] headerBytes = cm.getMessagePack(headerData); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index 2d6c7b7..0c5daf9 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -11,6 +11,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; +import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.decoder.DecodeStructure; import org.rcsb.mmtf.decoder.ParsingParams; import org.rcsb.mmtf.encoder.EncodeStructure; @@ -67,8 +68,8 @@ public Structure roundTripStruct(String pdbId, ParsingParams pp, FileParsingPara cache.setFileParsingParams(params); StructureIO.setAtomCache(cache); EncodeStructure es = new EncodeStructure(); - Structure mmcifStruct = StructureIO.getStructure(pdbId); - FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromPdbId(mmcifStruct)); + Structure mmcifStruct = StructureIO.getStructure(pdbId); + FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromPdbId(pdbId, new BiojavaEncoderImpl())); byte[] inArr = FileUtils.readFileToByteArray(new File("pathname")); // Now do the checks on the Raw data CheckOnRawApi checkRaw = new CheckOnRawApi(inArr); From adf06cdcde780508f7b1958d8170e611606568f0 Mon Sep 17 00:00:00 2001 From: abradle Date: Wed, 6 Apr 2016 16:00:00 -0700 Subject: [PATCH 040/108] Refactoring after another group meeting. --- .../rcsb/mmtf/api/MmtfDecoderInterface.java | 6 +++- .../org/rcsb/mmtf/dataholders/DsspType.java | 27 +++++++------- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 4 ++- .../DeltaDecompress.java} | 4 +-- .../RunLengthDecodeInt.java | 5 ++- .../RunLengthDecodeString.java | 2 +- .../RunLengthDelta.java | 2 +- .../package-info.java | 2 +- .../rcsb/mmtf/decoder/DecodeStructure.java | 30 ++++------------ .../org/rcsb/mmtf/decoder/ParsingParams.java | 36 ------------------- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 12 +++---- .../TestArrayDecompressor.java | 8 ++--- .../FindDeltas.java | 4 +-- .../IntArrayCompressor.java | 2 +- .../RunLengthEncode.java | 4 +-- .../RunLengthEncodeString.java | 2 +- .../StringArrayCompressor.java | 2 +- .../package-info.java | 2 +- .../rcsb/mmtf/biojavaencoder/GroupType.java | 25 ++----------- .../rcsb/mmtf/encoder/EncodeStructure.java | 2 +- .../org/rcsb/mmtf/encoder/EncoderUtils.java | 21 +++++------ .../TestArrayCompressors.java | 6 ++-- .../org/rcsb/mmtf/mappers/MapperUtils.java | 5 +-- .../mmtf/postupdatetests/CheckServer.java | 7 ++-- .../rcsb/mmtf/testutils/CheckOnBiojava.java | 11 +++--- .../org/rcsb/mmtf/update/TestingUtils.java | 13 +++---- 26 files changed, 83 insertions(+), 161 deletions(-) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/{arraydecompressors/DeltaDeCompress.java => arraydecoders/DeltaDecompress.java} (97%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/{arraydecompressors => arraydecoders}/RunLengthDecodeInt.java (92%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/{arraydecompressors => arraydecoders}/RunLengthDecodeString.java (97%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/{arraydecompressors => arraydecoders}/RunLengthDelta.java (98%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/{arraydecompressors => arraydecoders}/package-info.java (68%) delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{arraycompressors => arrayencoders}/FindDeltas.java (92%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{arraycompressors => arrayencoders}/IntArrayCompressor.java (88%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{arraycompressors => arrayencoders}/RunLengthEncode.java (96%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{arraycompressors => arrayencoders}/RunLengthEncodeString.java (96%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{arraycompressors => arrayencoders}/StringArrayCompressor.java (88%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/{arraycompressors => arrayencoders}/package-info.java (65%) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index 4671c9f..0ade3b0 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -39,9 +39,10 @@ public interface MmtfDecoderInterface { /** * Sets the information for a given chain. * @param chainId chain identifier - length of one to four + * @param chainName chain name - public chain id * @param groupCount number of groups/residues in chain */ - void setChainInfo(String chainId, int groupCount); + void setChainInfo(String chainId, String chainName, int groupCount); /** * Sets the entity level annotation for a chain(s). ChainIds is a list of strings that indicate the list of chains this information @@ -124,6 +125,9 @@ void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, * @param rWork * @param resolution * @param title +// TODO Add date information to the API +// * @param depositionDate +// * @param releaseDate * @param experimnetalMethods */ void setHeaderInfo(float rFree, float rWork, float resolution, String title, String[] experimnetalMethods); diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java index 340db39..6821ea4 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/DsspType.java @@ -3,8 +3,10 @@ /** * The encoding of secondary structure types. + * Based on DSSP: Kabsch W, Sander C (1983). + * "Dictionary of protein secondary structure: pattern recognition of hydrogen-bonded and geometrical features". + * Biopolymers 22 (12): 2577–637. doi:10.1002/bip.360221211. PMID 6667333. * @author Anthony Bradley - * */ public enum DsspType { @@ -20,8 +22,11 @@ public enum DsspType { /** The String type of the DSSP*/ private String dsspType; - /** The index used for encoding secondary structure - * information. One for each type*/ + + /** + * The index used for encoding secondary structure + * information. One for each type + * */ private int dsspIndex; /** @@ -30,7 +35,6 @@ public enum DsspType { * @param inputDsspIndex The integer index of hte DSSP input. */ private DsspType(String inputDsspType, int inputDsspIndex) { - this.setDsspType(inputDsspType); this.setDsspIndex(inputDsspIndex); @@ -44,8 +48,8 @@ private void setDsspIndex(int inputDsspIndex) { this.dsspIndex = inputDsspIndex; } - /** Returns the type of the DSSP as a String - * + /** + * Returns the type of the DSSP as a String * @return String representation of the DSSP type. */ public String getDsspType() { @@ -54,7 +58,6 @@ public String getDsspType() { /** Returns the index of the Dssp as an integer - * * @return String representation of the Dssp type. */ public int getDsspIndex() { @@ -69,10 +72,10 @@ private void setDsspType(String inputDsspType) { this.dsspType = inputDsspType; } - /** Creates a new DsspType from a String value. - * Returns DsspType.NULL_ENTRY if dsspType is "NA" or not one of the supported - * standard types. - * + /** + * Creates a new DsspType from a String value. + * Returns DsspType.NULL_ENTRY if dsspType is "NA" or not one of the supported + * standard types. * @param dsspType String value , should be one of "pi Helix","Bend","alpha Helix","Extended", * "3-10 Helix","Bridge","Turn","Coil","NA" * @return an DsspType object @@ -80,7 +83,7 @@ private void setDsspType(String inputDsspType) { public static DsspType dsspTypeFromString(String dsspType) { - if ( dsspType == null) + if (dsspType == null) return DsspType.NULL_ENTRY; for(DsspType et : DsspType.values()) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 30129c9..5225571 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -142,7 +142,9 @@ public class MmtfBean implements Serializable { /** The deposition date of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ private String depositionDate; - + + /** The release date of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ + private String releaseDate; /** Constructor to set the default values for floats */ public MmtfBean() { diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/DeltaDecompress.java similarity index 97% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/DeltaDecompress.java index 47ca52f..dc54d02 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/DeltaDeCompress.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/DeltaDecompress.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraydecompressors; +package org.rcsb.mmtf.arraydecoders; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -12,7 +12,7 @@ * @author Anthony Bradley * */ -public class DeltaDeCompress { +public class DeltaDecompress { /** The number of bytes in a four byte integers. */ private static final int BIG_INT_BYTES = 4; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java similarity index 92% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java index 278a54f..3319112 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeInt.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraydecompressors; +package org.rcsb.mmtf.arraydecoders; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -31,8 +31,7 @@ public final int[] decompressByteArray(final byte[] inArray) throws IOException int[] countArr = new int[lengthOfBigIntArr]; // Get the size int totCount = 0; - DataInputStream bis = new DataInputStream(new - ByteArrayInputStream(inArray)); + DataInputStream bis = new DataInputStream(new ByteArrayInputStream(inArray)); for (int i = 0; i < lengthOfBigIntArr; i++) { // Get the number int getNum = bis.readInt(); diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java similarity index 97% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java index 8080cf9..eaced3a 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDecodeString.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraydecompressors; +package org.rcsb.mmtf.arraydecoders; import org.rcsb.mmtf.dataholders.MmtfBean; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDelta.java similarity index 98% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDelta.java index ee9be19..b15316e 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/RunLengthDelta.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDelta.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraydecompressors; +package org.rcsb.mmtf.arraydecoders; import java.io.ByteArrayInputStream; import java.io.DataInputStream; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/package-info.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/package-info.java similarity index 68% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/package-info.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/package-info.java index f6ad2df..8be19c1 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecompressors/package-info.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/package-info.java @@ -5,4 +5,4 @@ * @author Anthony Bradley * */ -package org.rcsb.mmtf.arraydecompressors; +package org.rcsb.mmtf.arraydecoders; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index a319454..2b47e50 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -49,13 +49,11 @@ public DecodeStructure(byte[] inputByteArr) { * @param inputStructInflator the structure inflator to be used * @param parsingParams the parsing parameters object to be used when inflating. */ - public final void getStructFromByteArray(final MmtfDecoderInterface inputStructInflator, final ParsingParams parsingParams) { + public final void getStructFromByteArray(final MmtfDecoderInterface inputStructInflator) { // Set the inflator structInflator = inputStructInflator; // Do any required preparation inputStructInflator.initStructure(dataApi.getNumAtoms(), dataApi.getNumGroups(), dataApi.getNumChains(), dataApi.getNumModels(), dataApi.getStructureId()); - // Now get the parsing parameters to do their thing - useParseParams(parsingParams); // Now add the atom information addAtomicInformation(); // Now add the header information. @@ -63,9 +61,7 @@ public final void getStructFromByteArray(final MmtfDecoderInterface inputStructI // Now set the crystallographic information addXtalographicInfo(); /// Now get the bioassembly information - only if parsing using AsymId - if (parsingParams.isParseInternal()){ - generateBioAssembly(); - } + generateBioAssembly(); // Now add the other bonds between groups addInterGroupBonds(); // Now add the entity info @@ -115,34 +111,20 @@ private final void addHeaderInfo() { } - /** - * Use the parsing parameters to set the scene. - * @param parsingParams the input parsing parameters object - */ - private final void useParseParams(ParsingParams parsingParams) { - if (parsingParams.isParseInternal()) { - System.out.println("Using asym ids"); - chainList = dataApi.getChainIds(); - } else { - System.out.println("Using auth ids"); - chainList = dataApi.getChainNames(); - } - } - - /** * Set the chain level information and then loop through the groups * @param chainIndex the chain index to be created or updated. */ private void addOrUpdateChainInfo(int chainIndex) { // Get the current c - String currentChainId = chainList[chainIndex]; + String currentChainId = dataApi.getChainIds()[chainIndex]; + String currentChainName = dataApi.getChainNames()[chainIndex]; int groupsThisChain = dataApi.getGroupsPerChain()[chainIndex]; // If we've already seen this chain -> just update it if (chainIdSet.contains(currentChainId)) { - structInflator.setChainInfo(currentChainId, groupsThisChain); + structInflator.setChainInfo(currentChainId, currentChainName, groupsThisChain); } else { - structInflator.setChainInfo(currentChainId, groupsThisChain); + structInflator.setChainInfo(currentChainId, currentChainName, groupsThisChain); chainIdSet.add(currentChainId); } int nextInd = groupCounter + groupsThisChain; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java deleted file mode 100644 index 0ae7dd7..0000000 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ParsingParams.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.rcsb.mmtf.decoder; - -/** - * The Class ParsingParams. - */ -public class ParsingParams { - - /** Whether to use internal chain ids or not. */ - private boolean parseInternal; - - /** - * Instantiates a new parsing params. - */ - public ParsingParams() { - parseInternal = false; - } - - /** - * Checks if is parses the internal chain ids. - * @return true, if is parses the internal - */ - public final boolean isParseInternal() { - return parseInternal; - } - - /** - * Sets whether to parse the internal chain ids. - * @param ifParseInternal the new parses the internal - */ - public final void setParseInternal(final boolean ifParseInternal) { - this.parseInternal = ifParseInternal; - } - - - -} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 2b74ed3..d9029db 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -6,10 +6,10 @@ import org.msgpack.jackson.dataformat.MessagePackFactory; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.arraydecompressors.DeltaDeCompress; -import org.rcsb.mmtf.arraydecompressors.RunLengthDecodeInt; -import org.rcsb.mmtf.arraydecompressors.RunLengthDecodeString; -import org.rcsb.mmtf.arraydecompressors.RunLengthDelta; +import org.rcsb.mmtf.arraydecoders.DeltaDecompress; +import org.rcsb.mmtf.arraydecoders.RunLengthDecodeInt; +import org.rcsb.mmtf.arraydecoders.RunLengthDecodeString; +import org.rcsb.mmtf.arraydecoders.RunLengthDelta; import org.rcsb.mmtf.dataholders.BioAssemblyData; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.MmtfBean; @@ -22,7 +22,7 @@ public class SimpleDataApi implements MmtfDecodedDataInterface { public SimpleDataApi(byte[] inputByteArr) { - + // TODO Extract this from the instantiation of the object. MmtfBean inputData = null; try { inputData = new ObjectMapper(new MessagePackFactory()).readValue(inputByteArr, MmtfBean.class); @@ -33,7 +33,7 @@ public SimpleDataApi(byte[] inputByteArr) { } // Get the decompressors to build in the data structure - DeltaDeCompress deltaDecompress = new DeltaDeCompress(); + DeltaDecompress deltaDecompress = new DeltaDecompress(); RunLengthDelta intRunLengthDelta = new RunLengthDelta(); RunLengthDecodeInt intRunLength = new RunLengthDecodeInt(); RunLengthDecodeString stringRunlength = new RunLengthDecodeString(); diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java index 201eb48..b99e72c 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java @@ -7,9 +7,9 @@ import java.nio.ByteBuffer; import org.junit.Test; -import org.rcsb.mmtf.arraydecompressors.DeltaDeCompress; -import org.rcsb.mmtf.arraydecompressors.RunLengthDecodeInt; -import org.rcsb.mmtf.arraydecompressors.RunLengthDecodeString; +import org.rcsb.mmtf.arraydecoders.DeltaDecompress; +import org.rcsb.mmtf.arraydecoders.RunLengthDecodeInt; +import org.rcsb.mmtf.arraydecoders.RunLengthDecodeString; import static org.junit.Assert.assertArrayEquals; @@ -61,7 +61,7 @@ public final void runLenghtDecodeStringTest() { @Test public final void deltaDecompressorTest() throws IOException { - DeltaDeCompress ddc = new DeltaDeCompress(); + DeltaDecompress ddc = new DeltaDecompress(); // Now let's generate the byte arrays for the test data ByteArrayOutputStream bigBos = new ByteArrayOutputStream(); DataOutputStream bigDos = new DataOutputStream(bigBos); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java similarity index 92% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java index 5be2657..b219fa6 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/FindDeltas.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.arrayencoders; import java.io.Serializable; import java.util.ArrayList; @@ -20,12 +20,12 @@ public class FindDeltas implements IntArrayCompressor, Serializable { * Compressor#compressIntArray(java.util.ArrayList) */ public final List compressIntArray(final List inArray) { - // List outArray = new ArrayList(); int oldInt = 0; for (int i = 0; i < inArray.size(); i++) { // Get the value out here int numInt = inArray.get(i); + // TODO Remove the if statement. if (i==0){ oldInt = numInt; outArray.add(numInt); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java similarity index 88% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java index cf3c851..18ed741 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/IntArrayCompressor.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.arrayencoders; import java.util.List; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java similarity index 96% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java index 4734f54..1b8efff 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncode.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.arrayencoders; import java.io.Serializable; import java.util.ArrayList; @@ -28,8 +28,6 @@ public final List compressIntArray(List inArray) { for (int i = 0; i < inArray.size(); i++) { // Get the value out here int num_int = inArray.get(i); - - if(inSwitch==false){ inSwitch=true; // If it's a new number add it to the array diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java similarity index 96% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java index 360426b..7f2902c 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/RunLengthEncodeString.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.arrayencoders; import java.util.ArrayList; import java.util.List; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java similarity index 88% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java index d795ce1..275c995 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/StringArrayCompressor.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java @@ -1,4 +1,4 @@ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.arrayencoders; import java.util.List; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/package-info.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java similarity index 65% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/package-info.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java index 845718a..0922315 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arraycompressors/package-info.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java @@ -5,4 +5,4 @@ * @author Anthony Bradley * */ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.arrayencoders; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java index dd1c44b..6f3d28f 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java @@ -13,13 +13,11 @@ public enum GroupType { private String groupType; private String groupName; - - private GroupType(String inputGroupName, String inputGroupType) { - this.setGroupName(inputGroupName); - this.setGroupType(inputGroupType); + private GroupType(String groupName, String groupType) { + this.groupName = groupName; + this.groupType = groupType; } - /** * @return the groupType */ @@ -27,15 +25,6 @@ public String getGroupType() { return groupType; } - - /** - * @param groupType the groupType to set - */ - public void setGroupType(String groupType) { - this.groupType = groupType; - } - - /** * @return the groupName */ @@ -43,14 +32,6 @@ public String getGroupName() { return groupName; } - - /** - * @param groupName the groupName to set - */ - public void setGroupName(String groupName) { - this.groupName = groupName; - } - public static GroupType groupTypeFromString(String groupType) { diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java index ff17ccc..76bf901 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java @@ -61,7 +61,7 @@ private final byte[] buildFromDataStructure(EncoderInterface parsedDataStruct) { * @param pdbId The input pdb id * @return a byte array of compressed calpha data */ - public final byte[] encodeBackBoneFromPdbId(String pdbId,EncoderInterface encoderInterface){ + public final byte[] encodeBackBoneFromPdbId(String pdbId, EncoderInterface encoderInterface){ // Get the two utility classes EncoderUtils eu = new EncoderUtils(); Map totMap = new HashMap(); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java index 5a1794f..2222441 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java @@ -15,11 +15,11 @@ import java.util.zip.GZIPOutputStream; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.arraycompressors.FindDeltas; -import org.rcsb.mmtf.arraycompressors.IntArrayCompressor; -import org.rcsb.mmtf.arraycompressors.RunLengthEncode; -import org.rcsb.mmtf.arraycompressors.RunLengthEncodeString; -import org.rcsb.mmtf.arraycompressors.StringArrayCompressor; +import org.rcsb.mmtf.arrayencoders.FindDeltas; +import org.rcsb.mmtf.arrayencoders.IntArrayCompressor; +import org.rcsb.mmtf.arrayencoders.RunLengthEncode; +import org.rcsb.mmtf.arrayencoders.RunLengthEncodeString; +import org.rcsb.mmtf.arrayencoders.StringArrayCompressor; import org.rcsb.mmtf.biocompressors.BioCompressor; import org.rcsb.mmtf.biocompressors.CompressDoubles; import org.rcsb.mmtf.dataholders.BioDataStruct; @@ -35,6 +35,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; /** @@ -85,7 +86,7 @@ public byte[] integersToBytes(List inputList) throws IOException * to serialization. */ public final byte[] getMessagePack(Object inputObject) throws JsonProcessingException{ - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(new MessagePackFactory()); + ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); objectMapper.setSerializationInclusion(Include.NON_NULL); byte[] inBuf = objectMapper.writeValueAsBytes(inputObject); return inBuf; @@ -100,7 +101,7 @@ public final byte[] getMessagePack(Object inputObject) throws JsonProcessingExce * @throws IOException reading byte array */ public final MmtfBean compressToMmtfBean(BioDataStruct inStruct, HeaderBean inHeader) throws IOException { - EncoderUtils cm = new EncoderUtils(); + EncoderUtils encoderUtils = new EncoderUtils(); // Compress the data. CoreSingleStructure strucureData = compressInputData(inStruct); // Now set up the output MMTF dataholder @@ -122,11 +123,11 @@ public final MmtfBean compressToMmtfBean(BioDataStruct inStruct, HeaderBean inHe // Set the entity information outputMmtfBean.setEntityList(inHeader.getEntityList()); // Get the seqres information - outputMmtfBean.setSequenceIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(inHeader.getSeqResGroupIds())))); + outputMmtfBean.setSequenceIdList(encoderUtils.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(inHeader.getSeqResGroupIds())))); outputMmtfBean.setExperimentalMethods(inHeader.getExperimentalMethods()); // Now get this list - outputMmtfBean.setBondAtomList(cm.integersToBytes(inStruct.getInterGroupBondInds())); - outputMmtfBean.setBondOrderList(cm.integersToSmallBytes(inStruct.getInterGroupBondOrders())); + outputMmtfBean.setBondAtomList(encoderUtils.integersToBytes(inStruct.getInterGroupBondInds())); + outputMmtfBean.setBondOrderList(encoderUtils.integersToSmallBytes(inStruct.getInterGroupBondOrders())); // Now get these from the headers outputMmtfBean.setChainNameList(inHeader.getChainList()); outputMmtfBean.setNumAtoms(inHeader.getNumAtoms()); diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java index a7521dd..c5b7d04 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java @@ -4,9 +4,9 @@ import java.util.List; import org.junit.Test; -import org.rcsb.mmtf.arraycompressors.FindDeltas; -import org.rcsb.mmtf.arraycompressors.RunLengthEncode; -import org.rcsb.mmtf.arraycompressors.RunLengthEncodeString; +import org.rcsb.mmtf.arrayencoders.FindDeltas; +import org.rcsb.mmtf.arrayencoders.RunLengthEncode; +import org.rcsb.mmtf.arrayencoders.RunLengthEncodeString; import static org.junit.Assert.*; diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index 37e3655..80bd43e 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -12,8 +12,6 @@ import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.decoder.DecodeStructure; -import org.rcsb.mmtf.decoder.ParsingParams; - /** * A class to preserve the log if the functions in mappers. @@ -34,10 +32,9 @@ public class MapperUtils implements Serializable{ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) { MmtfStructureDecoder bjs = new MmtfStructureDecoder(); Structure newStruct; - ParsingParams pp = new ParsingParams(); try{ DecodeStructure ds = new DecodeStructure(inputByteArr); - ds.getStructFromByteArray(bjs, pp); + ds.getStructFromByteArray(bjs); newStruct = bjs.getStructure(); newStruct.setPDBCode(pdbCodePlus.substring(0,4));} catch(Exception e){ diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index 5326f0a..a03921e 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -10,7 +10,6 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; -import org.rcsb.mmtf.decoder.ParsingParams; import org.rcsb.mmtf.examples.HandleIO; import org.rcsb.mmtf.testutils.CheckOnBiojava; import org.rcsb.mmtf.testutils.CheckOnRawApi; @@ -66,9 +65,7 @@ public void basicParsingTest(String baseUrl) throws IOException { private void testParsing(String inputPdb, String inputUrl) throws IOException { System.out.println("TESTING: "+inputPdb); byte[] inputByteArr = handleIo.getFromUrl(inputPdb, inputUrl); - ParsingParams parsingParms = new ParsingParams(); - parsingParms.setParseInternal(params.isUseInternalChainId()); - Structure mmtfStruct = MmtfStructureDecoder.getBiojavaStruct(inputByteArr, parsingParms); + Structure mmtfStruct = MmtfStructureDecoder.getBiojavaStruct(inputByteArr); // Now parse from the MMCIF file Structure mmcifStruct; try { @@ -83,7 +80,7 @@ private void testParsing(String inputPdb, String inputUrl) throws IOException { e.printStackTrace(); throw new RuntimeException(); } - checkEquiv.checkIfStructuresSame(mmtfStruct, mmcifStruct, parsingParms); + checkEquiv.checkIfStructuresSame(mmtfStruct, mmcifStruct); // Now do the checks on the Raw data CheckOnRawApi checkRaw = new CheckOnRawApi(inputByteArr); checkRaw.checkRawDataConsistency(mmcifStruct, params); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java index 251318c..2d4e27c 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java @@ -21,7 +21,6 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; -import org.rcsb.mmtf.decoder.ParsingParams; public class CheckOnBiojava { @@ -35,11 +34,9 @@ public CheckOnBiojava() { * @param mmtfParams) * @return */ - private boolean checkIfAtomsSame(Structure structOne, Structure structTwo, ParsingParams mmtfParams) { + private boolean checkIfAtomsSame(Structure structOne, Structure structTwo) { // First check the bioassemblies - if (mmtfParams.isParseInternal()){ - checkIfBioassemblySame(structOne, structTwo); - } + checkIfBioassemblySame(structOne, structTwo); // Now check the pdb header checkIfHederSame(structOne, structTwo); // Now check the entity information @@ -305,7 +302,7 @@ private Map cleanUpBioass(Structure inputStruct) { * @param structTwo the BioJava structure parsed from the MMTF file * @param mmtfParams */ - public void checkIfStructuresSame(Structure biojavaStruct, Structure structTwo, ParsingParams mmtfParams){ - assertTrue(checkIfAtomsSame(biojavaStruct, structTwo, mmtfParams)); + public void checkIfStructuresSame(Structure biojavaStruct, Structure structTwo){ + assertTrue(checkIfAtomsSame(biojavaStruct, structTwo)); } } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index 0c5daf9..519e536 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -13,7 +13,6 @@ import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.decoder.DecodeStructure; -import org.rcsb.mmtf.decoder.ParsingParams; import org.rcsb.mmtf.encoder.EncodeStructure; import org.rcsb.mmtf.testutils.CheckOnBiojava; import org.rcsb.mmtf.testutils.CheckOnRawApi; @@ -27,11 +26,9 @@ public class TestingUtils { * @throws StructureException */ public void testAll(String[] inputList, FileParsingParameters params, AtomCache cache) throws IllegalAccessException, InvocationTargetException, IOException, StructureException{ - ParsingParams mmtfParams = new ParsingParams(); - mmtfParams.setParseInternal(params.isUseInternalChainId()); StructureIO.setAtomCache(cache); for (String pdbId : inputList){ - testOne(pdbId, params, cache, mmtfParams); + testOne(pdbId, params, cache); } } @@ -47,10 +44,10 @@ public void testAll(String[] inputList, FileParsingParameters params, AtomCache * @throws IOException * @throws StructureException */ - public void testOne(String pdbId, FileParsingParameters params, AtomCache cache, ParsingParams mmtfParams) throws IllegalAccessException, InvocationTargetException, IOException, StructureException { + public void testOne(String pdbId, FileParsingParameters params, AtomCache cache) throws IllegalAccessException, InvocationTargetException, IOException, StructureException { CheckOnBiojava checkEquiv = new CheckOnBiojava(); Structure structure = StructureIO.getStructure(pdbId); - checkEquiv.checkIfStructuresSame(structure,roundTripStruct(pdbId, mmtfParams, params, cache),mmtfParams); + checkEquiv.checkIfStructuresSame(structure,roundTripStruct(pdbId, params, cache)); } /** @@ -61,7 +58,7 @@ public void testOne(String pdbId, FileParsingParameters params, AtomCache cache, * @throws InvocationTargetException * @throws IllegalAccessException */ - public Structure roundTripStruct(String pdbId, ParsingParams pp, FileParsingParameters params, AtomCache cache) throws IOException, IllegalAccessException, InvocationTargetException, StructureException{ + public Structure roundTripStruct(String pdbId, FileParsingParameters params, AtomCache cache) throws IOException, IllegalAccessException, InvocationTargetException, StructureException{ // We need to set the parsing params to this boolean oldValue = params.isUseInternalChainId(); params.setUseInternalChainId(true); @@ -77,7 +74,7 @@ public Structure roundTripStruct(String pdbId, ParsingParams pp, FileParsingPara // Now decode the data and return this new structure MmtfStructureDecoder bjsi = new MmtfStructureDecoder(); DecodeStructure decodeStructure = new DecodeStructure(inArr); - decodeStructure.getStructFromByteArray(bjsi, pp); + decodeStructure.getStructFromByteArray(bjsi); Structure struct = bjsi.getStructure(); // Revert back params.setUseInternalChainId(oldValue); From b2061686314f25fe961ada7a658a491904ace947 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 17:23:52 -0700 Subject: [PATCH 041/108] Updates to pass the data information through the data chain --- .../org/rcsb/mmtf/api/MmtfDecodedDataInterface.java | 9 +++++++++ .../org/rcsb/mmtf/api/MmtfDecoderInterface.java | 6 ++---- .../java/org/rcsb/mmtf/dataholders/MmtfBean.java | 3 +-- .../java/org/rcsb/mmtf/decoder/DecodeStructure.java | 7 +++---- .../java/org/rcsb/mmtf/decoder/SimpleDataApi.java | 13 +++++++++++-- .../org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java | 1 + .../java/org/rcsb/mmtf/dataholders/HeaderBean.java | 6 ++++-- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index e17697d..02eb66d 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -372,4 +372,13 @@ public interface MmtfDecodedDataInterface { * @return the list of experimental methods */ String[] getExperimentalMethods(); + + /** + * Returns the deposition date of the structure as a string + * in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html + * @return the deposition date of the structure. + */ + String getDepositionDate(); + + } \ No newline at end of file diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index 0ade3b0..b09f593 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -125,12 +125,10 @@ void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, * @param rWork * @param resolution * @param title -// TODO Add date information to the API -// * @param depositionDate -// * @param releaseDate + * @param depositionDate * @param experimnetalMethods */ - void setHeaderInfo(float rFree, float rWork, float resolution, String title, String[] experimnetalMethods); + void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, String[] experimnetalMethods); diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 5225571..7af8161 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -143,8 +143,6 @@ public class MmtfBean implements Serializable { /** The deposition date of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ private String depositionDate; - /** The release date of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ - private String releaseDate; /** Constructor to set the default values for floats */ public MmtfBean() { @@ -841,4 +839,5 @@ public void setDepositionDate(String depositionDate) { this.depositionDate = depositionDate; } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 2b47e50..12115ed 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -30,14 +30,12 @@ public class DecodeStructure { private int atomCounter = 0; private int lastAtomCount = 0; private Set chainIdSet; - private String[] chainList; /** * The constructor requires a byte array to fill the data. This will decompress the arrays using our bespoke methods. * @param inputByteArr An unentropy encoded byte array with the data as found in the MMTF format */ public DecodeStructure(byte[] inputByteArr) { - // Create the instance of this API dataApi = new SimpleDataApi(inputByteArr); @@ -95,7 +93,7 @@ private final void addEntityInfo() { String[] chainIdList = new String[dataApi.getEntityChainIndexList(i).length]; int counter = 0; for (int chainInd : dataApi.getEntityChainIndexList(i)) { - chainIdList[counter] = chainList[chainInd]; + chainIdList[counter] = dataApi.getChainIds()[chainInd]; counter++; } structInflator.setEntityInfo(chainIdList, dataApi.getEntitySequence(i), dataApi.getEntityDescription(i), dataApi.getEntityType(i)); @@ -107,7 +105,8 @@ private final void addEntityInfo() { * Add ancilliary header information to the structure */ private final void addHeaderInfo() { - structInflator.setHeaderInfo(dataApi.getRfree(),dataApi.getRwork(), dataApi.getResolution(), dataApi.getTitle(), dataApi.getExperimentalMethods()); + structInflator.setHeaderInfo(dataApi.getRfree(),dataApi.getRwork(), dataApi.getResolution(), + dataApi.getTitle(), dataApi.getDepositionDate(), dataApi.getExperimentalMethods()); } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index d9029db..74304ab 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -80,8 +80,8 @@ public SimpleDataApi(byte[] inputByteArr) { resolution = inputData.getResolution(); title = inputData.getTitle(); experimentalMethods = inputData.getExperimentalMethods().toArray(new String[0]); - - + // Now get the relase information + depositionDate = inputData.getDepositionDate(); } catch (IOException ioException){ System.err.println("Error reading in byte arrays from message pack"); @@ -183,6 +183,10 @@ public SimpleDataApi(byte[] inputByteArr) { /** The list of experimental methods. */ private String[] experimentalMethods; + + /** The deposition date of hte structure */ + private String depositionDate; + @Override public float[] getxCoords() { @@ -468,5 +472,10 @@ private int[] convertToIntList(List inArray) { return outArray; } + @Override + public String getDepositionDate() { + return depositionDate; + } + } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java index c47ec88..955cb28 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java @@ -221,6 +221,7 @@ public void setHeaderInfo(Structure bioJavaStruct, HeaderBean headerStruct) { headerStruct.setDescription(header.getDescription()); headerStruct.setClassification(header.getClassification()); headerStruct.setDepDate(header.getDepDate()); + //headerStruct.setReleaseDate(header.getReleaseDate()); headerStruct.setModDate(header.getModDate()); headerStruct.setResolution(header.getResolution()); headerStruct.setrFree(header.getRfree()); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java index 811b873..5b1c70e 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java @@ -41,7 +41,8 @@ public class HeaderBean { /** The depositon date. */ private Date depDate; - + + /** The modified date. */ private Date modDate; @@ -627,5 +628,6 @@ public Entity[] getEntityList() { public void setEntityList(Entity[] entityList) { this.entityList = entityList; - } + } + } From e8953af5f18ed8689bf95d0cf5e8919f8169fee0 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 17:37:54 -0700 Subject: [PATCH 042/108] Refactored the array compressors into a single class. I've moved this class into the encoder package. --- .../rcsb/mmtf/arrayencoders/FindDeltas.java | 43 --------- .../arrayencoders/IntArrayCompressor.java | 18 ---- .../mmtf/arrayencoders/RunLengthEncode.java | 59 ------------ .../arrayencoders/RunLengthEncodeString.java | 42 -------- .../arrayencoders/StringArrayCompressor.java | 17 ---- .../rcsb/mmtf/arrayencoders/package-info.java | 8 -- .../org/rcsb/mmtf/encoder/ArrayEncoders.java | 96 +++++++++++++++++++ .../org/rcsb/mmtf/encoder/EncoderUtils.java | 41 +++----- .../TestArrayCompressors.java | 16 +--- 9 files changed, 116 insertions(+), 224 deletions(-) delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java rename mmtf-encoder/src/test/java/org/rcsb/mmtf/{arraycompressors => encoder}/TestArrayCompressors.java (72%) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java deleted file mode 100644 index b219fa6..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/FindDeltas.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.rcsb.mmtf.arrayencoders; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * Class to encode an integer array with deltas. - * - * @author Anthony Bradley - */ -public class FindDeltas implements IntArrayCompressor, Serializable { - - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = -8404400061650470813L; - - /* (non-Javadoc) - * @see org.rcsb.mmtf.arraycompressors.IntArray - * Compressor#compressIntArray(java.util.ArrayList) - */ - public final List compressIntArray(final List inArray) { - List outArray = new ArrayList(); - int oldInt = 0; - for (int i = 0; i < inArray.size(); i++) { - // Get the value out here - int numInt = inArray.get(i); - // TODO Remove the if statement. - if (i==0){ - oldInt = numInt; - outArray.add(numInt); - } - else{ - int this_int = numInt - oldInt; - outArray.add((int) this_int); - oldInt = numInt; - } - } - return outArray; - } - - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java deleted file mode 100644 index 18ed741..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/IntArrayCompressor.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.rcsb.mmtf.arrayencoders; - -import java.util.List; - - -/** - * The Interface IntArrayCompressor. - */ -public interface IntArrayCompressor { - - /** - * Generic function to compress an integer array. - * - * @param inArray the in array - * @return the array list - */ - public List compressIntArray(List inArray); -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java deleted file mode 100644 index 1b8efff..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncode.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.rcsb.mmtf.arrayencoders; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * Class to run length encode an integer array. - * @author Anthony Bradley - * - */ -public class RunLengthEncode implements IntArrayCompressor, Serializable { - - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = -793325266722283046L; - - /* (non-Javadoc) - * @see org.rcsb.mmtf.arraycompressors.IntArrayCompressor#compressIntArray(java.util.ArrayList) - */ - public final List compressIntArray(List inArray) { - - List outArray = new ArrayList(); - int oldVal = 0; - boolean inSwitch = false; - int counter = 0; - // Loop through the vals - for (int i = 0; i < inArray.size(); i++) { - // Get the value out here - int num_int = inArray.get(i); - if(inSwitch==false){ - inSwitch=true; - // If it's a new number add it to the array - outArray.add(num_int); - counter=1; - oldVal=num_int; - } - else if (num_int!=oldVal){ - // Add the counter to the array - outArray.add(counter); - if(counter<0){ - System.out.println("THIS ERROR - "+counter); - } - // If it's a new number add it to the array - outArray.add(num_int); - counter=1; - oldVal=num_int; - } - else{ - counter+=1; - } - } - outArray.add(counter); - return outArray; - } - - - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java deleted file mode 100644 index 7f2902c..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/RunLengthEncodeString.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.rcsb.mmtf.arrayencoders; - -import java.util.ArrayList; -import java.util.List; - -/** - * Class to run length encode a string array. - * @author Anthony Bradley - * - */ -public class RunLengthEncodeString implements StringArrayCompressor { - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.arraycompressors.StringArrayCompressor#compressStringArray(java.util.ArrayList) - */ - public final List compressStringArray(List inArray) { - List outArray = new ArrayList(); - String oldVal = ""; - int counter = 0; - // Loop through the vals - for (int i = 0; i < inArray.size(); i++) { - // Get the value out here - String inString = inArray.get(i); - if (inString != oldVal){ - if(oldVal != ""){ - // Add the counter to the array - outArray.add(Integer.toString(counter)); - } - // If it's a new number add it to the array - outArray.add(inString); - counter = 1; - oldVal = inString; - } else { - counter += 1; - } - } - outArray.add(Integer.toString(counter)); - return outArray; - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java deleted file mode 100644 index 275c995..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/StringArrayCompressor.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.rcsb.mmtf.arrayencoders; - -import java.util.List; - -/** - * The Interface StringArrayCompressor. - */ -public interface StringArrayCompressor { - - /** - * Generic function to compress a string array. - * - * @param inArray the in array - * @return the array list - */ - List compressStringArray(List inArray); -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java deleted file mode 100644 index 0922315..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/arrayencoders/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Package to compress arrays - */ -/** - * @author Anthony Bradley - * - */ -package org.rcsb.mmtf.arrayencoders; diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java new file mode 100644 index 0000000..ecab364 --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java @@ -0,0 +1,96 @@ +package org.rcsb.mmtf.encoder; + +import java.util.ArrayList; +import java.util.List; + +/** + * A class of methods that can be used to encode arrays. + * @author Anthony Bradley + * + */ +public class ArrayEncoders { + + + public static List deltaEncode(final List inArray) { + List outArray = new ArrayList(); + int oldInt = 0; + for (int i = 0; i < inArray.size(); i++) { + // Get the value out here + int numInt = inArray.get(i); + // TODO Remove the if statement. + if (i==0){ + oldInt = numInt; + outArray.add(numInt); + } + else{ + int this_int = numInt - oldInt; + outArray.add((int) this_int); + oldInt = numInt; + } + } + return outArray; + } + + + public static List runlengthEncodeIntegers(List inArray) { + + List outArray = new ArrayList(); + int oldVal = 0; + boolean inSwitch = false; + int counter = 0; + // Loop through the vals + for (int i = 0; i < inArray.size(); i++) { + // Get the value out here + int num_int = inArray.get(i); + if(inSwitch==false){ + inSwitch=true; + // If it's a new number add it to the array + outArray.add(num_int); + counter=1; + oldVal=num_int; + } + else if (num_int!=oldVal){ + // Add the counter to the array + outArray.add(counter); + if(counter<0){ + System.out.println("THIS ERROR - "+counter); + } + // If it's a new number add it to the array + outArray.add(num_int); + counter=1; + oldVal=num_int; + } + else{ + counter+=1; + } + } + outArray.add(counter); + return outArray; + } + + + public static List runlengthEncodeStrings(List inArray) { + List outArray = new ArrayList(); + String oldVal = ""; + int counter = 0; + // Loop through the vals + for (int i = 0; i < inArray.size(); i++) { + // Get the value out here + String inString = inArray.get(i); + if (inString != oldVal){ + if(oldVal != ""){ + // Add the counter to the array + outArray.add(Integer.toString(counter)); + } + // If it's a new number add it to the array + outArray.add(inString); + counter = 1; + oldVal = inString; + } else { + counter += 1; + } + } + outArray.add(Integer.toString(counter)); + return outArray; + } +} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java index 2222441..610c2ca 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java @@ -15,11 +15,6 @@ import java.util.zip.GZIPOutputStream; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.arrayencoders.FindDeltas; -import org.rcsb.mmtf.arrayencoders.IntArrayCompressor; -import org.rcsb.mmtf.arrayencoders.RunLengthEncode; -import org.rcsb.mmtf.arrayencoders.RunLengthEncodeString; -import org.rcsb.mmtf.arrayencoders.StringArrayCompressor; import org.rcsb.mmtf.biocompressors.BioCompressor; import org.rcsb.mmtf.biocompressors.CompressDoubles; import org.rcsb.mmtf.dataholders.BioDataStruct; @@ -54,11 +49,6 @@ public class EncoderUtils implements Serializable { /** A converter of doubles to ints. */ private BioCompressor doublesToInts = new CompressDoubles(); - /** The delta compressor of arrays. */ - private IntArrayCompressor deltaComp = new FindDeltas(); - - /** The run length compressor of arrays. */ - private IntArrayCompressor runLengthComp = new RunLengthEncode(); /** * Take a list of integers (as List) and return as byte array. @@ -123,7 +113,7 @@ public final MmtfBean compressToMmtfBean(BioDataStruct inStruct, HeaderBean inHe // Set the entity information outputMmtfBean.setEntityList(inHeader.getEntityList()); // Get the seqres information - outputMmtfBean.setSequenceIdList(encoderUtils.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(inHeader.getSeqResGroupIds())))); + outputMmtfBean.setSequenceIdList(encoderUtils.integersToBytes(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inHeader.getSeqResGroupIds())))); outputMmtfBean.setExperimentalMethods(inHeader.getExperimentalMethods()); // Now get this list outputMmtfBean.setBondAtomList(encoderUtils.integersToBytes(inStruct.getInterGroupBondInds())); @@ -368,25 +358,24 @@ public final CoreSingleStructure compressInputData(BioDataStruct inputBioDataStr List cartnY = inStruct.get_atom_site_Cartn_yInt(); List cartnZ = inStruct.get_atom_site_Cartn_zInt(); // Get the number of models - inStruct.set_atom_site_Cartn_xInt(deltaComp.compressIntArray(cartnX)); - inStruct.set_atom_site_Cartn_yInt(deltaComp.compressIntArray(cartnY)); - inStruct.set_atom_site_Cartn_zInt(deltaComp.compressIntArray(cartnZ)); + inStruct.set_atom_site_Cartn_xInt(ArrayEncoders.deltaEncode(cartnX)); + inStruct.set_atom_site_Cartn_yInt(ArrayEncoders.deltaEncode(cartnY)); + inStruct.set_atom_site_Cartn_zInt(ArrayEncoders.deltaEncode(cartnZ)); // Compress the b factors using delta compression. - inStruct.set_atom_site_B_iso_or_equivInt(deltaComp.compressIntArray(inStruct.get_atom_site_B_iso_or_equivInt())); + inStruct.set_atom_site_B_iso_or_equivInt(ArrayEncoders.deltaEncode(inStruct.get_atom_site_B_iso_or_equivInt())); // Run length compress the occupanct - inStruct.set_atom_site_occupancyInt(runLengthComp.compressIntArray(inStruct.get_atom_site_occupancyInt())); + inStruct.set_atom_site_occupancyInt(ArrayEncoders.runlengthEncodeIntegers(inStruct.get_atom_site_occupancyInt())); // Now the sequential numbers - huge gain - new order of good compressors // Now runlength encode the residue order inStruct.setResOrder(inStruct.getResOrder()); // Check for negative counters - inStruct.set_atom_site_auth_seq_id(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_auth_seq_id()))); - inStruct.set_atom_site_label_entity_poly_seq_num(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_label_entity_poly_seq_num()))); - inStruct.set_atom_site_id(runLengthComp.compressIntArray(deltaComp.compressIntArray(inStruct.get_atom_site_id()))); + inStruct.set_atom_site_auth_seq_id(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inStruct.get_atom_site_auth_seq_id()))); + inStruct.set_atom_site_label_entity_poly_seq_num(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inStruct.get_atom_site_label_entity_poly_seq_num()))); + inStruct.set_atom_site_id(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inStruct.get_atom_site_id()))); // Now run length decode the strings - StringArrayCompressor stringRunEncode = new RunLengthEncodeString(); - inStruct.set_atom_site_label_alt_id(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_label_alt_id())); + inStruct.set_atom_site_label_alt_id(ArrayEncoders.runlengthEncodeStrings(inStruct.get_atom_site_label_alt_id())); //inStruct.set_atom_site_label_entity_id(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_label_entity_id())); - inStruct.set_atom_site_pdbx_PDB_ins_code(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_pdbx_PDB_ins_code())); + inStruct.set_atom_site_pdbx_PDB_ins_code(ArrayEncoders.runlengthEncodeStrings(inStruct.get_atom_site_pdbx_PDB_ins_code())); return inStruct; } @@ -429,19 +418,19 @@ public final CalphaDistBean compressCalpha(CalphaBean calphaData, HeaderBean inH List cartnY = calphaData.getCartn_y(); List cartnZ = calphaData.getCartn_z(); // Now add the X coords - List bigAndLittleX = splitListIntsToByteArrays(deltaComp.compressIntArray(cartnX)); + List bigAndLittleX = splitListIntsToByteArrays(ArrayEncoders.deltaEncode(cartnX)); calphaOut.setxCoordBig(bigAndLittleX.get(0)); calphaOut.setxCoordSmall(bigAndLittleX.get(1)); // No add they Y coords - List bigAndLittleY = splitListIntsToByteArrays(deltaComp.compressIntArray(cartnY)); + List bigAndLittleY = splitListIntsToByteArrays(ArrayEncoders.deltaEncode(cartnY)); calphaOut.setyCoordBig(bigAndLittleY.get(0)); calphaOut.setyCoordSmall(bigAndLittleY.get(1)); // Now add the Z coords - List bigAndLittleZ = splitListIntsToByteArrays(deltaComp.compressIntArray(cartnZ)); + List bigAndLittleZ = splitListIntsToByteArrays(ArrayEncoders.deltaEncode(cartnZ)); calphaOut.setzCoordBig(bigAndLittleZ.get(0)); calphaOut.setzCoordSmall(bigAndLittleZ.get(1)); // THESE ONES CAN BE RUN LENGTH ON DELTA - calphaOut.setGroupIdList(cm.integersToBytes(runLengthComp.compressIntArray(deltaComp.compressIntArray(calphaData.get_atom_site_auth_seq_id())))); + calphaOut.setGroupIdList(cm.integersToBytes(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(calphaData.get_atom_site_auth_seq_id())))); return calphaOut; } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java similarity index 72% rename from mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java rename to mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java index c5b7d04..49c0aee 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/arraycompressors/TestArrayCompressors.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java @@ -1,13 +1,9 @@ -package org.rcsb.mmtf.arraycompressors; +package org.rcsb.mmtf.encoder; import java.util.ArrayList; import java.util.List; import org.junit.Test; -import org.rcsb.mmtf.arrayencoders.FindDeltas; -import org.rcsb.mmtf.arrayencoders.RunLengthEncode; -import org.rcsb.mmtf.arrayencoders.RunLengthEncodeString; - import static org.junit.Assert.*; public class TestArrayCompressors { @@ -15,7 +11,7 @@ public class TestArrayCompressors { @Test public void deltaTest() { // Generate the array - FindDeltas fd = new FindDeltas(); + // Create the two arrays ArrayList inArray = new ArrayList(); ArrayList testArray = new ArrayList(); @@ -29,7 +25,7 @@ public void deltaTest() { } } // Compress it - List deltadArray = fd.compressIntArray(inArray); + List deltadArray = ArrayEncoders.deltaEncode(inArray); // Now check assertEquals(deltadArray, testArray); @@ -38,7 +34,6 @@ public void deltaTest() { @Test public void runLengthTest() { // Generate the array - RunLengthEncode rle = new RunLengthEncode(); // Create the two arrays List inArray = new ArrayList(); List testArray = new ArrayList(); @@ -51,7 +46,7 @@ public void runLengthTest() { } testArray.add(length); // Compress it - List runlenghtdArray = rle.compressIntArray(inArray); + List runlenghtdArray = ArrayEncoders.runlengthEncodeIntegers(inArray); // Now check assertEquals(runlenghtdArray, testArray); } @@ -61,7 +56,6 @@ public void runLengthTest() { @Test public void runLengthStringTest() { // Generate the array - RunLengthEncodeString rle = new RunLengthEncodeString(); // Create the two arrays ArrayList inArray = new ArrayList(); ArrayList testArray = new ArrayList(); @@ -74,7 +68,7 @@ public void runLengthStringTest() { } testArray.add(Integer.toString(length)); // Compress it - List runlenghtdArray = rle.compressStringArray(inArray); + List runlenghtdArray = ArrayEncoders.runlengthEncodeStrings(inArray); // Now check assertEquals(runlenghtdArray, testArray); } From 00e1f38bce525972187c9f105252e03fbfb15121 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 18:23:34 -0700 Subject: [PATCH 043/108] Updates to the docs on the decoded data api interface --- .../mmtf/api/MmtfDecodedDataInterface.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index 02eb66d..575f2c8 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -218,15 +218,15 @@ public interface MmtfDecodedDataInterface { /** * Returns the number of transformations in a given bioassembly. - * @param an integer specifying the bioassembly index (zero indexed). + * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). * @return an integer specifying of transformations in a given bioassembly. */ int getNumTransInBioassembly(int bioassemblyIndex); /** * Returns the list of chain indices for the given transformation for the given bioassembly. - * @param an integer specifying the bioassembly index (zero indexed). - * @param an integer specifying the index (zero indexed) for the desired transformation. + * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). + * @param transformationIndex an integer specifying the index (zero indexed) for the desired transformation. * @return a list of indices showing the chains involved in this transformation. */ int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex); @@ -236,8 +236,8 @@ public interface MmtfDecodedDataInterface { * Returns a 4x4 transformation matrix for the given transformation for the given bioassembly. * It is row-packed as per the convention of vecmath. (The first four elements are in the first row of the * overall matrix). - * @param an integer specifying the bioassembly index (zero indexed). - * @param an integer specifying the index for the desired transformation (zero indexed). + * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). + * @param transformationIndex an integer specifying the index for the desired transformation (zero indexed). * @return the transformation matrix for this transformation. */ double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex); @@ -252,7 +252,7 @@ public interface MmtfDecodedDataInterface { /** * Returns an array of bond orders (1,2,3) of inter-group bonds with length number of inter-group bonds - * @return + * @return the bond orders for bonds within a group */ int[] getInterGroupBondOrders(); @@ -278,28 +278,28 @@ public interface MmtfDecodedDataInterface { /** * Returns the entity description (as defined in mmCIF dictionary) * for the entity specified by the index. - * @param the index of the specified entity. + * @param entityInd the index of the specified entity. * @return the description of the entity */ String getEntityDescription(int entityInd); /** * Returns the entity type (polymer, non-polymer, water) for the entity specified by the index. - * @param the index of the specified entity. + * @param entityInd the index of the specified entity. * @return the entity type (polymer, non-polymer, water) */ String getEntityType(int entityInd); /** * Returns the chain indices for the entity specified by the index. - * @param the index of the specified entity. + * @param entityInd the index of the specified entity. * @return the chain index list - referencing the entity to the chains. */ int[] getEntityChainIndexList(int entityInd); /** * Returns the sequence for the entity specified by the index. - * @param the index of the specified entity. + * @param entityInd the index of the specified entity. * @return the one letter sequence for this entity. Empty string if no sequence is applicable. */ String getEntitySequence(int entityInd); From a6a532a168eb9f16ee1188dd176a01de1530b46d Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 18:33:25 -0700 Subject: [PATCH 044/108] First commit of an interface of setters for setting the data into the data model --- .../mmtf/api/MmtfInitialDataInterface.java | 364 ++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java new file mode 100644 index 0000000..65083c3 --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java @@ -0,0 +1,364 @@ +package org.rcsb.mmtf.api; + +/** + * + * @author Anthony Bradley + * @author Jose Duarte + */ +public interface MmtfInitialDataInterface { + + /** + * Sets an array containing the X coordinates of the atoms in Angstroms. + * @param an array of length the number of atoms in the structure + */ + void setxCoords(float[] xCoords); + + /** + * Sets an array containing the Y coordinates of the atoms in Angstroms. + * @param an array of length the number of atoms in the structure + */ + void setyCoords(float[] yCoords); + + /** + * Sets an array containing the Z coordinates of the atoms in Angstroms. + * @param an array of length the number of atoms in the structure + */ + void setzCoords(float[] zCoords); + + /** + * Sets an array containing the B-factors (temperature factors) of the atoms in Angstroms^2. + * @param an array of length the number of atoms in the structure + */ + void setbFactors(float[] bFactors); + + /** + * Sets an array containing the occupancy values of the atoms. + * @param an array of length the number of atoms in the structure + */ + void setOccupancies(float[] occupancies); + + /** + * Sets an array of atom serial ids (_atom_site.id in mmCIF dictionary). + * @param an array of length the number of atoms in the structure + */ + void setAtomIds(int[] atomIds); + + /** + * Sets an array of location ids of the atoms. + * '\0' specifies a lack of alt id. + * @param an array of length the number of atoms in the structure + */ + void setAltLocIds(char[] altLocIds); + + /** + * Sets an array containing the insertion codes (pdbx_PDB_ins_code in mmCIF dictionary) for each residue (group). + * '\0' specifies a lack of insertion code. + * @param an array with insertion codes + * @see #setGroupIds() + */ + void setInsCodes(char[] insCodes); + + /** + * Sets an array containing residue numbers (auth_seq_id in mmCIF dictionary) for each residue (group). + * @param an array with with residue numbers + * @see #setInsCodes() + */ + void setGroupIds(int[] groupIds); + + + /** + * Sets the group name for the group specified in {@link #setGroupTypeIndices()}. + * to link groups to the 3 letter group name, e.g. HIS. + * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. + * @param a 3 letter string specifiying the group name. + */ + void setGroupName(int groupInd, String groupName); + + /** + * Sets the number of atoms in the group specified in {@link #setGroupTypeIndices()}. + * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. + * @param numAtomsInGroup The number of atoms in the group + */ + void setNumAtomsInGroup(int groupInd, int numAtomsInGroup); + + + /** + * Sets the atom names (e.g. CB) for the group specified in {@link #setGroupTypeIndices()}. + * Atom names are unique for each unique atom in a group. + * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. + * @param groupAtomNames A list of strings for the atom names. + * */ + void setGroupAtomNames(int groupInd, String[] groupAtomNames); + + /** + * Sets the IUPAC element names (e.g. Ca is calcium) for the group specified in {@link #setGroupTypeIndices()}. + * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. + * @param groupElements an array of strings for the element information. + * */ + void setGroupElementNames(int groupInd, String[] groupElements); + + /** + * Sets the bond orders for the group specified in {@link #setGroupTypeIndices()}. + * A list of integers indicating the bond orders + * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. + * @param groupBondOrders an array of integers (1,2 or 3) indicating the bond orders. + * */ + void setGroupBondOrders(int groupInd, int[] groupBondOrders); + + /** + * Sets the zero-based bond indices (in pairs) for the group specified in {@link #setGroupTypeIndices()}. + * (e.g. 0,1 means there is bond between atom 0 and 1). + * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. + * @param groupBondIndices an array of integers specifying the bond indices (within the group). Indices are zero indexed. + * */ + void setGroupBondIndices(int groupInd, int[] groupBondIndices); + + /** + * Sets the atom charges for the group specified in {@link #setGroupTypeIndices()}. + * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. + * @param groupAtomCharges an array of integers indicating the atomic charge for each atom in the group. + */ + void setGroupAtomCharges(int groupInd, int[] groupAtomCharges); + + /** + * Sets the single letter amino acid code or nucleotide code for the + * group specified in {@link #setGroupTypeIndices()}. + * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. + * @param groupSingleLetterCode the single letter amino acid or nucleotide, 'X' if non-standard amino acid or nucleotide + */ + void setGroupSingleLetterCode(int groupInd, char groupSingleLetterCode); + + /** + * Sets the chemical component type for the group specified in {@link #setGroupTypeIndices()}. + * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. + * @param a string (taken from the chemical component dictionary) indicating + * the type of the group. Corresponds to + * http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html + */ + void setGroupChemCompType(int groupInd, String groupChemCompType); + + /** + * Sets an array containing indices to be used to obtain group level information + * @param an array of length the number of groups (residues) in the structure + */ + void setGroupTypeIndices(int[] groupTypeIndices); + + /** + * Sets an array containing the indices of groups (residues) in their corresponding sequences. + * The indices are 0-based and specified per entity, -1 indicates the group is not present in the sequence. + * @param groupSequenceIndices an array of length the number of groups (residues) in the structure + */ + void setGroupSequenceIndices(int[] groupSequenceIndices); + + /** + * Sets an array of internal chain identifiers (asym_ids in mmCIF dictionary), of length the + * number of chains (polymeric, non-polymeric and water) in the structure. + * @param chainIds an array of length the number of chains in the structur + * @see #setChainNames() + */ + void setChainIds(String[] chainIds); + + /** + * Sets an array of public chain identifiers (auth_ids in mmCIF dictionary), of length the + * number of chains (polymeric, non-polymeric and water) in the structure. + * @param chainNames an array of length the number of chains in the structur + * @see #setChainIds() + */ + void setChainNames(String[] chainNames); + + /** + * Sets an array containing the number of chains (polymeric/non-polymeric/water) in each model. + * @param chainsPerModel an array of length the number of models in the structure + */ + void setChainsPerModel(int[] chainsPerModel); + + /** + * Sets an array containing the number of groups (residues) in each chain. + * @param groupsPerChain an array of length the number of chains in the structur + */ + void setGroupsPerChain(int[] groupsPerChain); + + /** + * Sets the space group of the structure. + * @param spaceGroup the space group name (e.g. "P 21 21 21") or null if the structure is not crystallographic + */ + void setSpaceGroup(String spaceGroup); + + /** + * Sets the 6 floats that describe the unit cell. + * @param unitCell an array of size 6 with the unit cell parameters in order: a, b, c, alpha, beta, gamma + */ + void setUnitCell(float[] unitCell); + + /** + * Sets the number of bioassemblies in this structure. + * @param numBioassemblies the number of bioassemblies. + */ + void setNumBioassemblies(int numBioassemblies); + + /** + * Sets the number of transformations in a given bioassembly. + * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). + * @param numTransInBioassembly an integer specifying of transformations in a given bioassembly. + */ + void setNumTransInBioassembly(int bioassemblyIndex, int numTransInBioassembly); + + /** + * Sets the list of chain indices for the given transformation for the given bioassembly. + * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). + * @param transformationIndex an integer specifying the index (zero indexed) for the desired transformation. + * @param transChainIndexList a list of indices showing the chains involved in this transformation. + */ + void setChainIndexListForTransform(int bioassemblyIndex, int transformationIndex, int[] transChainIndexList); + + + /** + * Sets a 4x4 transformation matrix for the given transformation for the given bioassembly. + * It is row-packed as per the convention of vecmath. (The first four elements are in the first row of the + * overall matrix). + * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). + * @param transformationIndex an integer specifying the index for the desired transformation (zero indexed). + * @param transformationMatrix the transformation matrix for this transformation. + */ + void setMatrixForTransform(int bioassemblyIndex, int transformationIndex, double[] transformationMatrix); + + + /** + * Sets the zero-based bond indices (in pairs) for the structure. + * (e.g. 0,1 means there is bond between atom 0 and 1). + * @param interGroupBondIndices an array of integers specifying the bond indices (within the structure). Indices are zero-based. + */ + void setInterGroupBondIndices(int[] interGroupBondIndices); + + /** + * Sets an array of bond orders (1,2,3) of inter-group bonds with length number of inter-group bonds + * @param interGroupBondOrders the bond orders for bonds within a group + */ + void setInterGroupBondOrders(int[] interGroupBondOrders); + + /** + * Sets the MMTF version number (from the specification). + * @param mmtfVersion the version of the file. + */ + void setMmtfVersion(String mmtfVersion); + + /** + * Sets a string describing the producer of the MMTF file. + * e.g. "RCSB-PDB Generator---version: 6b8635f8d319beea9cd7cc7f5dd2649578ac01a0" + * @param mmtfProducer a string describing the producer + */ + void setMmtfProducer(String mmtfProducer); + + /** + * Sets the number of entities (as defined in mmCIF dictionary) in the structure + * @param numEntities the number of entities in the structure + */ + void setNumEntities(int numEntities); + + /** + * Sets the entity description (as defined in mmCIF dictionary) + * for the entity specified by the index. + * @param entityInd the index of the specified entity. + * @param entityDescription the description of the entity + */ + void setEntityDescription(int entityInd, String entityDescription); + + /** + * Sets the entity type (polymer, non-polymer, water) for the entity specified by the index. + * @param entityInd the index of the specified entity. + * @param entityType the entity type (polymer, non-polymer, water) + */ + void setEntityType(int entityInd, String entityType); + + /** + * Sets the chain indices for the entity specified by the index. + * @param entityInd the index of the specified entity. + * @param chainIndexList the chain index list - referencing the entity to the chains. + */ + void setEntityChainIndexList(int entityInd,int[] chainIndexList); + + /** + * Sets the sequence for the entity specified by the index. + * @param entityInd the index of the specified entity. + * @param sequence the one letter sequence for this entity. Empty string if no sequence is applicable. + */ + void setEntitySequence(int entityInd, String sequence); + + /** + * Sets the identifier of the structure. + * For instance the 4-letter PDB id + * @param structureId the identifier for the structure + */ + void setStructureId(String structureId); + + /** + * Sets the number of models in the structure. + * @param numModels the number of models + */ + void setNumModels(int numModels); + + /** + * Sets the number of chains (for all models) in the structure. + * @param numChains the number of chains for all models + * @see #setChainsPerModel() + */ + void setNumChains(int numChains); + + /** + * Sets the number of groups (residues) in the structure that have + * experimentally determined 3D coordinates. + * @param numGroups the number of residues in the structure, for all models and chains + */ + void setNumGroups(int numGroups); + + + /** + * Sets the number of atoms in the structure. + * @param numAtoms the number of atoms in the structure, for all models and chains + */ + void setNumAtoms(int numAtoms); + + + /** + * Sets the Rfree of the dataset. + * @param rFree the R-free value + */ + void setRfree(float rFree); + + /** + * Sets the Rwork of the dataset. + * @param rWork the R-work value + */ + void setRwork(float rWork); + + /** + * Sets the resolution of the dataset. + * @param resolution the resolution value in Angstroms + */ + void setResolution(float resolution); + + /** + * Sets the title of the structure. + * @param title the title of the structure. + */ + void setTitle(String title); + + /** + * Sets the experimental methods as an array of strings. Normally only one + * experimental method is available, but structures solved with hybrid methods will + * have more than one method. + * The possible experimental method values are described in + * data item _exptl.method of the mmCIF dictionary + * @param experimentalMethods the list of experimental methods + */ + void setExperimentalMethods(String[] experimentalMethods); + + /** + * Sets the deposition date of the structure as a string + * in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html + * @param depositionDate the deposition date of the structure. + */ + void setDepositionDate(String depositionDate); + + +} \ No newline at end of file From 825ce34e5a56eaf0f7a22319c479dcae29498157 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 18:34:24 -0700 Subject: [PATCH 045/108] Added a new array decoders class to hold the array decoders and map one to one onto arrayencoders --- .../src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java new file mode 100644 index 0000000..e6dc1a2 --- /dev/null +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java @@ -0,0 +1,5 @@ +package org.rcsb.mmtf.decoder; + +public class ArrayDecoders { + +} From 7044be2d2ce7fdaec40957e865f600d11307fb45 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 18:34:46 -0700 Subject: [PATCH 046/108] Minor changes and refactoring --- .../java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java | 2 +- .../test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java index 3319112..088378c 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java @@ -23,7 +23,7 @@ public class RunLengthDecodeInt { * @throws IOException the byte array does not contain the * information requested. */ - public final int[] decompressByteArray(final byte[] inArray) throws IOException { + public int[] decompressByteArray(byte[] inArray) throws IOException { // The length of each of the 4 byte integer arrays int lengthOfBigIntArr = inArray.length / (BIG_INT_BYTES * 2); // Array to store all the different numbers diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java index 49c0aee..fb53e4a 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java @@ -10,8 +10,6 @@ public class TestArrayCompressors { @Test public void deltaTest() { - // Generate the array - // Create the two arrays ArrayList inArray = new ArrayList(); ArrayList testArray = new ArrayList(); From 7e8aa5e848d0af5921a334cc3e43c52bfedca9b2 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 6 Apr 2016 19:03:50 -0700 Subject: [PATCH 047/108] Some more updates to the decoder library. --- .../org/rcsb/mmtf/decoder/ArrayDecoders.java | 62 +++++++++++++++++++ .../org/rcsb/mmtf/decoder/DecoderUtils.java | 24 +++---- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 23 ++++--- 3 files changed, 85 insertions(+), 24 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java index e6dc1a2..102b6d1 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java @@ -1,5 +1,67 @@ package org.rcsb.mmtf.decoder; +import org.rcsb.mmtf.dataholders.MmtfBean; + public class ArrayDecoders { + + public static int[] deltaDecode(int[] integerArray) { + return integerArray; + + } + + + public static int[] runLengthDecodeIntegers(int[] integerArray) { + return integerArray; + + } + + + /** + * Runlength decode an int[] and return as a char[]. + * @param integerArray an input array of integers. Integers are in pairs. The first in each pair + * is the ASCII code of the character. The second in each pair is the number of copies of this character to + * be added to the list. + * @return a char array of values run length decoded. + */ + public static char[] runLengthDecodeStrings(int[] integerArray) { + // If it's only one long - just take the char + if (integerArray.length == 1) { + char[] outArray = new char[1]; + if (Character.toChars(integerArray[0])[0] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { + outArray[0] = '?'; + } else { + outArray[0]= Character.toChars(integerArray[0])[0]; + } + return outArray; + } + // If it's longer - count the total number to be put in (to assign the char[]). + int totNum = 0; + for (int i = 0; i < integerArray.length; i += 2) { + totNum += integerArray[i + 1]; + } + // Assign the output char array. + char[] outArray = new char[totNum]; + // The total counter for the output. + int totCounter = 0; + // Define an empty char with the scope to be used in the for loop. + char outChar = '\0'; + for (int i = 0; i < integerArray.length; i += 2) { + if (integerArray[i] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { + outChar = "?".charAt(0); + } else { + // Otherwise get this char + outChar = Character.toChars(integerArray[i])[0]; + } + // Find the number of repeats. + int numRepeats = integerArray[i + 1]; + // Loop through and add these to the list + for (int j = 0; j < numRepeats; j++) { + outArray[totCounter] = outChar; + totCounter++; + } + } + return outArray; + } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java index 51f1fb9..4cbd729 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java @@ -18,7 +18,7 @@ public class DecoderUtils { * @param chainIndex the index of the chain for which the id is required. * @return a String of the chain id for the given chain. */ - public final String getChainId(final byte[] chainList, final int chainIndex) { + public static String getChainId(byte[] chainList,int chainIndex) { int incrementor = 0; StringBuilder sb = new StringBuilder(); byte chainIdOne = chainList[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor]; @@ -44,13 +44,13 @@ public final String getChainId(final byte[] chainList, final int chainIndex) { /** * Convert a byte array (each four byte encodes a different integer) to an integer array. - * @param inArray the input byte array + * @param byteArray the input byte array * @return the decoded integer array * @throws IOException due to byte array not being accesible */ - public final int[] bytesToInts(final byte[] inArray) throws IOException { - DataInputStream bis = new DataInputStream(new ByteArrayInputStream(inArray)); - int numIntsInArr = inArray.length / NUM_BYTES_IN_INT; + public static int[] bytesToInts(byte[] byteArray) throws IOException { + DataInputStream bis = new DataInputStream(new ByteArrayInputStream(byteArray)); + int numIntsInArr = byteArray.length / NUM_BYTES_IN_INT; // Define an array to return int[] outArray = new int[numIntsInArr]; for (int i = 0; i < numIntsInArr; i++) { @@ -61,15 +61,15 @@ public final int[] bytesToInts(final byte[] inArray) throws IOException { /** * Convert a byte array (each byte encodes a different integer) to an integer array. - * @param inArray the input byte array + * @param byteArray the input byte array * @return the decoded integer array * @throws IOException due to byte array not being accesible */ - public final int[] bytesToByteInts(final byte[] inArray) throws IOException { - DataInputStream bis = new DataInputStream(new ByteArrayInputStream(inArray)); + public static int[] bytesToByteInts(byte[] byteArray) throws IOException { + DataInputStream bis = new DataInputStream(new ByteArrayInputStream(byteArray)); // Define an array to return - int[] outArray = new int[inArray.length]; - for (int i = 0; i < inArray.length; i++) { + int[] outArray = new int[byteArray.length]; + for (int i = 0; i < byteArray.length; i++) { outArray[i] = (int) bis.readByte(); } return outArray; @@ -82,7 +82,7 @@ public final int[] bytesToByteInts(final byte[] inArray) throws IOException { * @param currentChainList the byte array of the chain list input. Each chain takes up 4 bytes. * @return the string array of the parsed chain ids */ - public final String[] decodeChainList(byte[] currentChainList) { + public static String[] decodeChainList(byte[] currentChainList) { int outputLength = currentChainList.length/4; String[] outArray = new String[outputLength]; for (int i = 0; i < outputLength; i++){ @@ -97,7 +97,7 @@ public final String[] decodeChainList(byte[] currentChainList) { * @param floatDivider the float divider to divide the integers by. * @return a float array converted from the input. */ - public final float[] convertIntsToFloats(int[] inputIntArray, float floatDivider) { + public static float[] convertIntsToFloats(int[] inputIntArray, float floatDivider) { // Assign the output array to write float[] outArray = new float[inputIntArray.length]; for (int i=0; i Date: Wed, 6 Apr 2016 19:06:40 -0700 Subject: [PATCH 048/108] Updates to the tests to remove warnings --- .../main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java | 2 +- .../java/org/rcsb/mmtf/decoder/TestDecoderUtils.java | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java index 102b6d1..ec4ac43 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java @@ -10,7 +10,7 @@ public static int[] deltaDecode(int[] integerArray) { } - + public static int[] runLengthDecodeIntegers(int[] integerArray) { return integerArray; diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java index 40ff81b..564be1d 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java @@ -22,7 +22,6 @@ public class TestDecoderUtils { private static final int NUM_EXAMPLES = 100; private static final int MAX_CHARS_PER_CHAIN = 4; - private DecoderUtils decoderUtils = new DecoderUtils(); private Random randGenerator = new Random(); @Test @@ -52,7 +51,7 @@ public void getChainIdTest() { int counter = 0; byte[] testByteArr = bos.toByteArray(); for(String testChainId : testList){ - assertEquals(testChainId, decoderUtils.getChainId(testByteArr, counter)); + assertEquals(testChainId, DecoderUtils.getChainId(testByteArr, counter)); counter += 1; } @@ -71,7 +70,7 @@ public void bytesToIntsTests() throws IOException { testIntArr[i] = currInt; } // Now check they are the same - assertArrayEquals(testIntArr, decoderUtils.bytesToInts(bos.toByteArray())); + assertArrayEquals(testIntArr, DecoderUtils.bytesToInts(bos.toByteArray())); } @@ -88,14 +87,14 @@ public void bytesToByteIntsTests() throws IOException { inputByteArr[i] = (byte) currInt; testIntArr[i] = currInt; } - assertArrayEquals(testIntArr, decoderUtils.bytesToByteInts(inputByteArr)); + assertArrayEquals(testIntArr, DecoderUtils.bytesToByteInts(inputByteArr)); } @Test public void convertIntToFloatTest() { int[] inputData = {10213, 20303, 102, 183, 1021}; float[] outPutData = {(float) 10.213, (float) 20.303, (float) 0.102, (float) 0.183, (float) 1.021}; - float [] outPutToTest = decoderUtils.convertIntsToFloats(inputData, (float) 1000.0); + float [] outPutToTest = DecoderUtils.convertIntsToFloats(inputData, (float) 1000.0); // Test they are the same length assertEquals(outPutData.length, outPutToTest.length); assertTrue(Arrays.equals(outPutData, outPutToTest)); From 015731d3d613eeeddfc4fd80579179b955ba40e5 Mon Sep 17 00:00:00 2001 From: abradle Date: Thu, 7 Apr 2016 06:02:54 -0700 Subject: [PATCH 049/108] More elegant handling and improvements 1) Conversion from and to byte[] 2) Using Biojava to encode data --- .../ByteArrayToObjectConverterInterface.java | 12 +++++++ .../mmtf/api/MmtfDecodedDataInterface.java | 4 +++ ...rface.java => MmtfInputDataInterface.java} | 8 +++-- .../ObjectToByteArrayConverterInterface.java | 11 +++++++ .../ByteArrayMessagePackConverter.java | 31 +++++++++++++++++++ .../rcsb/mmtf/decoder/DecodeStructure.java | 6 ++-- .../org/rcsb/mmtf/decoder/SimpleDataApi.java | 22 +++++-------- .../java/org/rcsb/mmtf/examples/HandleIO.java | 5 +-- 8 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java rename mmtf-api/src/main/java/org/rcsb/mmtf/api/{MmtfInitialDataInterface.java => MmtfInputDataInterface.java} (98%) create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java create mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java new file mode 100644 index 0000000..ef14129 --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java @@ -0,0 +1,12 @@ +package org.rcsb.mmtf.api; + +public interface ByteArrayToObjectConverterInterface { + + /** + * Convert a byte array to an object to then be procesed. + * e.g. a messagepack byte array can be coverted to an MMTFBean. + * @param byteArray the input byte data + * @return the object with defined getters and setters + */ + Object convert(byte[] byteArray); +} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index 575f2c8..e1bf739 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -380,5 +380,9 @@ public interface MmtfDecodedDataInterface { */ String getDepositionDate(); + /** + * Enter the data as a byte array along with an interface to convert a byte array to an object. + */ + void setInputData(byte[] byteArray, ByteArrayToObjectConverterInterface byteArrayConverter); } \ No newline at end of file diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java similarity index 98% rename from mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java rename to mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java index 65083c3..ba079a8 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInitialDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java @@ -1,11 +1,11 @@ package org.rcsb.mmtf.api; /** - * + * An interface to take the data from another data structure and insert it into the MmmtfDecodedApi. * @author Anthony Bradley * @author Jose Duarte */ -public interface MmtfInitialDataInterface { +public interface MmtfInputDataInterface { /** * Sets an array containing the X coordinates of the atoms in Angstroms. @@ -360,5 +360,9 @@ public interface MmtfInitialDataInterface { */ void setDepositionDate(String depositionDate); + /** + * Returns the data as a decoded data interface. To then be encoded. + */ + MmtfDecodedDataInterface getDataAsDecodedDataInterface(); } \ No newline at end of file diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java new file mode 100644 index 0000000..1a2bf7c --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java @@ -0,0 +1,11 @@ +package org.rcsb.mmtf.api; + +public interface ObjectToByteArrayConverterInterface { + + /** + * Convert an object to a byte array using reflection. + * @param object an object with getters and setters + * @return a byte array of the serialised object + */ + byte[] convert(Object object); +} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java new file mode 100644 index 0000000..48e19a4 --- /dev/null +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java @@ -0,0 +1,31 @@ +package org.rcsb.mmtf.decoder; + +import java.io.IOException; + +import org.msgpack.jackson.dataformat.MessagePackFactory; +import org.rcsb.mmtf.api.ByteArrayToObjectConverterInterface; +import org.rcsb.mmtf.dataholders.MmtfBean; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Class to covert a byte array to an object using message pack conversion. + * @author Anthony Bradley + * + */ +public class ByteArrayMessagePackConverter implements ByteArrayToObjectConverterInterface { + + @Override + public MmtfBean convert(byte[] byteArray) { + MmtfBean mmtfBean = null; + try { + mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(byteArray, MmtfBean.class); + } catch (IOException e) { + System.err.println("Error converting Byte array to message pack. IOError"); + e.printStackTrace(); + throw new RuntimeException(); + } + return mmtfBean; + } + +} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java index 12115ed..6b00664 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecodeStructure.java @@ -33,11 +33,11 @@ public class DecodeStructure { /** * The constructor requires a byte array to fill the data. This will decompress the arrays using our bespoke methods. - * @param inputByteArr An unentropy encoded byte array with the data as found in the MMTF format + * @param byteArray An unentropy encoded byte array with the data as found in the MMTF format */ - public DecodeStructure(byte[] inputByteArr) { + public DecodeStructure(byte[] byteArray) { // Create the instance of this API - dataApi = new SimpleDataApi(inputByteArr); + dataApi = new SimpleDataApi(new ByteArrayMessagePackConverter().convert(byteArray)); } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java index 74e78d6..920ad61 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; -import org.msgpack.jackson.dataformat.MessagePackFactory; +import org.rcsb.mmtf.api.ByteArrayToObjectConverterInterface; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.arraydecoders.DeltaDecompress; import org.rcsb.mmtf.arraydecoders.RunLengthDecodeInt; @@ -15,22 +15,10 @@ import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; -import com.fasterxml.jackson.databind.ObjectMapper; - public class SimpleDataApi implements MmtfDecodedDataInterface { - public SimpleDataApi(byte[] inputByteArr) { - - // TODO Extract this from the instantiation of the object. - MmtfBean inputData = null; - try { - inputData = new ObjectMapper(new MessagePackFactory()).readValue(inputByteArr, MmtfBean.class); - } catch (IOException e) { - System.err.println("Error converting Byte array to message pack. IOError"); - e.printStackTrace(); - throw new RuntimeException(); - } + public SimpleDataApi(MmtfBean inputData) { // Get the decompressors to build in the data structure DeltaDecompress deltaDecompress = new DeltaDecompress(); @@ -476,5 +464,11 @@ public String getDepositionDate() { return depositionDate; } + @Override + public void setInputData(byte[] byteArray, ByteArrayToObjectConverterInterface byteArrayConverter) { + // TODO Auto-generated method stub + + } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java index cc28647..aa9692b 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java @@ -13,6 +13,7 @@ import java.util.zip.GZIPInputStream; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; +import org.rcsb.mmtf.decoder.ByteArrayMessagePackConverter; import org.rcsb.mmtf.decoder.SimpleDataApi; /** @@ -62,10 +63,10 @@ public final MmtfDecodedDataInterface getDataApiFromUrlOrFile(final String input boolean isFile = getFile(basePath, inputCode); // If it's a file on the file system - get it if (isFile) { - return new SimpleDataApi(getFromFileSystem(basePath, inputCode)); + return new SimpleDataApi(new ByteArrayMessagePackConverter().convert(getFromFileSystem(basePath, inputCode))); } try { - return new SimpleDataApi(getFromUrl(inputCode)); + return new SimpleDataApi(new ByteArrayMessagePackConverter().convert(getFromUrl(inputCode))); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); From 759458e46057274b76b465743ef3899850d41ec1 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 10:45:19 -0700 Subject: [PATCH 050/108] Updates and refactoring on the way towards restructuring the Decoder and Encoder and removin Biojava as a dependency --- .../arraydecoders/RunLengthDecodeString.java | 64 --------------- .../{SimpleDataApi.java => BeanToGetApi.java} | 28 ++++--- ...re.java => GetApiToInflatorInterface.java} | 8 +- .../java/org/rcsb/mmtf/examples/HandleIO.java | 6 +- .../TestArrayDecompressor.java | 5 +- .../rcsb/mmtf/decoder/TestDecoderUtils.java | 1 - mmtf-encoder/pom.xml | 10 +-- .../biojavaencoder/BiojavaEncoderImpl.java | 20 ++--- .../rcsb/mmtf/encoder/EncodeStructure.java | 82 ------------------- .../rcsb/mmtf/encoder/EncoderInterface.java | 67 --------------- .../org/rcsb/mmtf/encoder/GetApiToBean.java | 24 ++++++ mmtf-update/pom.xml | 26 ++---- .../org/rcsb/mmtf/mappers/MapperUtils.java | 4 +- .../rcsb/mmtf/testutils/CheckOnRawApi.java | 4 +- .../org/rcsb/mmtf/update/TestingUtils.java | 8 +- 15 files changed, 75 insertions(+), 282 deletions(-) delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java rename mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/{SimpleDataApi.java => BeanToGetApi.java} (93%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/{DecodeStructure.java => GetApiToInflatorInterface.java} (97%) delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java deleted file mode 100644 index eaced3a..0000000 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeString.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.rcsb.mmtf.arraydecoders; - -import org.rcsb.mmtf.dataholders.MmtfBean; - -/** - * Decode string arrays that have been run length encoded. - * The input values are in pairs. The first value in each pair - * is the string to be used in the output array. The second value - * is the number of repetitions of that value. - * @author Anthony Bradley - * - */ -public class RunLengthDecodeString { - - - /** - * Runlength decode an int[] and return as a char[]. - * @param inputIntArray an input array of integers. Integers are in pairs. The first in each pair - * is the ASCII code of the character. The second in each pair is the number of copies of this character to - * be added to the list. - * @return a char array of values run length decoded. - */ - public final char[] intArrayToCharArray(final int[] inputIntArray) { - // If it's only one long - just take the char - if (inputIntArray.length == 1) { - char[] outArray = new char[1]; - if (Character.toChars(inputIntArray[0])[0] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { - outArray[0] = '?'; - } else { - outArray[0]= Character.toChars(inputIntArray[0])[0]; - } - return outArray; - } - // If it's longer - count the total number to be put in (to assign the char[]). - int totNum = 0; - for (int i = 0; i < inputIntArray.length; i += 2) { - totNum += inputIntArray[i + 1]; - } - // Assign the output char array. - char[] outArray = new char[totNum]; - // The total counter for the output. - int totCounter = 0; - // Define an empty char with the scope to be used in the for loop. - char outChar = '\0'; - for (int i = 0; i < inputIntArray.length; i += 2) { - if (inputIntArray[i] == MmtfBean.UNAVAILABLE_CHAR_VALUE) { - outChar = "?".charAt(0); - } else { - // Otherwise get this char - outChar = Character.toChars(inputIntArray[i])[0]; - } - // Find the number of repeats. - int numRepeats = inputIntArray[i + 1]; - // Loop through and add these to the list - for (int j = 0; j < numRepeats; j++) { - outArray[totCounter] = outChar; - totCounter++; - } - } - return outArray; - } - - -} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java similarity index 93% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java index 920ad61..9eb1e17 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/SimpleDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java @@ -8,23 +8,26 @@ import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.arraydecoders.DeltaDecompress; import org.rcsb.mmtf.arraydecoders.RunLengthDecodeInt; -import org.rcsb.mmtf.arraydecoders.RunLengthDecodeString; import org.rcsb.mmtf.arraydecoders.RunLengthDelta; import org.rcsb.mmtf.dataholders.BioAssemblyData; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.dataholders.PDBGroup; -public class SimpleDataApi implements MmtfDecodedDataInterface { +/** + * Takes an input MMTF bean and converts to a data API. + * @author Anthony Bradley + * + */ +public class BeanToGetApi implements MmtfDecodedDataInterface { - public SimpleDataApi(MmtfBean inputData) { + public BeanToGetApi(MmtfBean inputData) { // Get the decompressors to build in the data structure DeltaDecompress deltaDecompress = new DeltaDecompress(); RunLengthDelta intRunLengthDelta = new RunLengthDelta(); RunLengthDecodeInt intRunLength = new RunLengthDecodeInt(); - RunLengthDecodeString stringRunlength = new RunLengthDecodeString(); // Get the data try { @@ -36,9 +39,9 @@ public SimpleDataApi(MmtfBean inputData) { bFactor = DecoderUtils.convertIntsToFloats(deltaDecompress.decompressByteArray(inputData.getbFactorBig(),inputData.getbFactorSmall()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); occupancy = DecoderUtils.convertIntsToFloats(intRunLength.decompressByteArray(inputData.getOccupancyList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); atomId = intRunLengthDelta.decompressByteArray(inputData.getAtomIdList()); - altId = stringRunlength.intArrayToCharArray(inputData.getAltLocList()); + altId = ArrayDecoders.runLengthDecodeStrings(inputData.getAltLocList()); // Get the insertion code - insertionCodeList = stringRunlength.intArrayToCharArray(inputData.getInsCodeList()); + insertionCodeList = ArrayDecoders.runLengthDecodeStrings(inputData.getInsCodeList()); // Get the groupNumber groupNum = intRunLengthDelta.decompressByteArray( inputData.getGroupIdList()); @@ -77,7 +80,6 @@ public SimpleDataApi(MmtfBean inputData) { } } - /** The X coordinates */ private float[] cartnX; @@ -345,12 +347,12 @@ public String getGroupName(int groupInd) { } public int getNumAtomsInGroup(int groupInd) { - return groupMap[groupInd].getAtomCharges().size(); + return groupMap[groupInd].getAtomChargeList().size(); } @Override public String[] getGroupAtomNames(int groupInd) { - List atomInfo = groupMap[groupInd].getAtomInfo(); + List atomInfo = groupMap[groupInd].getAtomNameList(); String[] outList = new String[atomInfo.size()/2]; int counter = 0; for (int i=1; i atomInfo = groupMap[groupInd].getAtomInfo(); + List atomInfo = groupMap[groupInd].getAtomNameList(); String[] outList = new String[atomInfo.size()/2]; int counter = 0; for (int i=0; immtf-common 0.0.1-alpha4-SNAPSHOT
- - org.biojava - biojava-structure - 5.0.0-SNAPSHOT - + + org.rcsb + mmtf-api + 0.0.1-alpha4-SNAPSHOT + org.msgpack jackson-dataformat-msgpack diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java index 3c36cca..71a46f5 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java @@ -272,7 +272,7 @@ public final void generateDataStructuresFromPdbId(Structure inputBiojavaStruct, // Set the group type outGroup.setChemCompType(currentGroup.getChemComp().getType()); outGroup.setGroupName(groupInfo.remove(0)); - outGroup.setAtomInfo(groupInfo); + outGroup.setAtomNameList(groupInfo); // Now get the bond list (lengths, orders and indices) createBondList(atomsInThisGroup, outGroup); getCharges(atomsInThisGroup, outGroup); @@ -281,12 +281,12 @@ public final void generateDataStructuresFromPdbId(Structure inputBiojavaStruct, hashToRes.put(hashCode, resCounter); bioStruct.getResOrder().add(resCounter); resCounter+=1; - numBonds = outGroup.getBondOrders().size(); + numBonds = outGroup.getBondOrderList().size(); } else{ // Add this to the residue order bioStruct.getResOrder().add(hashToRes.get(hashCode)); - numBonds = bioStructMap.get(hashToRes.get(hashCode)).getBondOrders().size(); + numBonds = bioStructMap.get(hashToRes.get(hashCode)).getBondOrderList().size(); } // Add the number of bonds bondCounter+=numBonds; @@ -406,7 +406,7 @@ private void addCalphaGroup(List cAlphaGroup,SecStrucState props, ResidueN // Set the chemical component type. outGroup.setChemCompType(currentGroup.getChemComp().getType()); outGroup.setGroupName(calphaAtomInfo.remove(0)); - outGroup.setAtomInfo(calphaAtomInfo); + outGroup.setAtomNameList(calphaAtomInfo); // Now get the bond list (lengths, orders and indices) and atom charges List bondIndices = new ArrayList(); List bondOrders = new ArrayList(); @@ -431,9 +431,9 @@ private void addCalphaGroup(List cAlphaGroup,SecStrucState props, ResidueN } } // Now set them - outGroup.setBondIndices(bondIndices); - outGroup.setBondOrders(bondOrders); - outGroup.setAtomCharges(atomCharges); + outGroup.setBondAtomList(bondIndices); + outGroup.setBondOrderList(bondOrders); + outGroup.setAtomChargeList(atomCharges); // calphaHashCodeToGroupMap.put(calphaResCounter, outGroup); hashToCalphaRes.put(calphaHashCode, calphaResCounter); @@ -511,7 +511,7 @@ private void addCalpha(Atom inputAtom, SecStrucState secondaryStructureInfo, Res */ private void getCharges(List inputAtoms, PDBGroup pdbGroup) { for(Atom a: inputAtoms){ - pdbGroup.getAtomCharges().add((int) a.getCharge()); + pdbGroup.getAtomChargeList().add((int) a.getCharge()); } } @@ -641,8 +641,8 @@ private void createBondList(List inputAtoms, PDBGroup pdbGroup) { } } } - pdbGroup.setBondOrders(bondOrder); - pdbGroup.setBondIndices(bondList); + pdbGroup.setBondOrderList(bondOrder); + pdbGroup.setBondAtomList(bondList); } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java deleted file mode 100644 index 76bf901..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncodeStructure.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.rcsb.mmtf.encoder; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.dataholders.PDBGroup; - -public class EncodeStructure { - - /** - * Get a byte array of the compressed messagepack MMTF data - * from an input PDB id - * @param pdbId - * @return a byte array of compressed data - */ - public final byte[] getCompressedMessagePackFromPdbId(String pdbId, EncoderInterface encoderInterface) { - // Get the utility class to get the strucutes - Map totMap = new HashMap(); - // Parse the data into the basic data structure - encoderInterface.generateDataStructuresFromPdbId(pdbId, totMap); - // Compress the data and get it back out - return buildFromDataStructure(encoderInterface); - } - - /** - * Generate the compressed messagepack MMTF data from a biojava structure - * @param bioJavaStruct - * @return a byte array of compressed data - */ - public final byte[] encodeFromPdbId(String pdbId, EncoderInterface encoderInterface){ - // Get the utility class to get the strucutes - Map totMap = new HashMap(); - // Parse the data into the basic data structure - encoderInterface.generateDataStructuresFromPdbId(pdbId, totMap); - return buildFromDataStructure(encoderInterface); - } - - /** - * Build up a byte array from the parsed data - * @param parsedDataStruct - * @return a byte array of compressed data - */ - private final byte[] buildFromDataStructure(EncoderInterface parsedDataStruct) { - EncoderUtils eu = new EncoderUtils(); - // Compress the data and get it back out - try { - MmtfBean mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); - return eu.getMessagePack(mmtfBean); - } catch (IOException e) { - // Here we've failed to read or write a byte array - e.printStackTrace(); - System.err.println("Error reading or writing byte array - file bug report"); - throw new RuntimeException(e); - } - } - - /** - * Generate the compressed messagepack of the calpha, phospohate and ligand data. - * @param pdbId The input pdb id - * @return a byte array of compressed calpha data - */ - public final byte[] encodeBackBoneFromPdbId(String pdbId, EncoderInterface encoderInterface){ - // Get the two utility classes - EncoderUtils eu = new EncoderUtils(); - Map totMap = new HashMap(); - // Parse the data into the basic data structure - encoderInterface.generateDataStructuresFromPdbId(pdbId, totMap); - // Compress the data and get it back out - try { - return eu.getMessagePack(eu.compressCalpha(encoderInterface.getCalphaStruct(), encoderInterface.getHeaderStruct())); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Error in reading or writing byte array"); - throw new RuntimeException(e); - } - } - - - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java deleted file mode 100644 index 20fa4f7..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderInterface.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.rcsb.mmtf.encoder; - -import java.util.Map; - -import org.rcsb.mmtf.dataholders.BioDataStruct; -import org.rcsb.mmtf.dataholders.CalphaBean; -import org.rcsb.mmtf.dataholders.HeaderBean; -import org.rcsb.mmtf.dataholders.PDBGroup; - -/** - * An interface to be used in encoding structures - * @author Anthony Bradley - * - */ -public interface EncoderInterface { - - /** - * Gets the bio struct. - * - * @return the bio struct - */ - BioDataStruct getBioStruct(); - - /** - * Sets the bio struct. - * - * @param bioStruct the new bio struct - */ - void setBioStruct(BioDataStruct bioStruct); - - /** - * Gets the calpha struct. - * - * @return the calpha struct - */ - CalphaBean getCalphaStruct(); - - /** - * Sets the calpha struct. - * - * @param calphaStruct the new calpha struct - */ - void setCalphaStruct(CalphaBean calphaStruct); - - /** - * Gets the header struct. - * - * @return the header struct - */ - HeaderBean getHeaderStruct(); - - /** - * Sets the header struct. - * - * @param headerStruct the new header struct - */ - void setHeaderStruct(HeaderBean headerStruct); - - /** - * Helper function to generate a main, calpha and header data form a PDB id. - * - * @param pdbId the pdb id - * @param bioStructMap the bio struct map - */ - void generateDataStructuresFromPdbId(String pdbId, Map bioStructMap); - -} \ No newline at end of file diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java new file mode 100644 index 0000000..3be215d --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java @@ -0,0 +1,24 @@ +package org.rcsb.mmtf.encoder; + +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; +import org.rcsb.mmtf.dataholders.MmtfBean; + +/** + * Class to take a generic data structure (mmtfDecodedDataInterface) and encode to an mmtf bean. + * @author Anthony Bradley + * + */ +public class GetApiToBean { + + private MmtfBean mmtfBean; + + public GetApiToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) { + + // DO THE ENCODING LOGIC HERE -> CONVERTING TO AN MMTF BEAN + } + + public MmtfBean getMmtfBean() { + return mmtfBean; + } + +} diff --git a/mmtf-update/pom.xml b/mmtf-update/pom.xml index 290876e..9c02c55 100644 --- a/mmtf-update/pom.xml +++ b/mmtf-update/pom.xml @@ -16,21 +16,11 @@ - - org.rcsb - mmtf-api - 0.0.1-alpha4-SNAPSHOT - - - org.rcsb - mmtf-encoder - 0.0.1-alpha4-SNAPSHOT - - - org.rcsb - mmtf-common - 0.0.1-alpha4-SNAPSHOT - + + org.biojava + biojava-structure + 5.0.0-SNAPSHOT + junit @@ -56,12 +46,6 @@ org.apache.logging.log4j log4j-core - - - org.biojava - biojava-structure - 5.0.0-SNAPSHOT - org.apache.spark spark-core_2.11 diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index 80bd43e..a8ec1f3 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -11,7 +11,7 @@ import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; -import org.rcsb.mmtf.decoder.DecodeStructure; +import org.rcsb.mmtf.decoder.GetApiToInflatorInterface; /** * A class to preserve the log if the functions in mappers. @@ -33,7 +33,7 @@ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) MmtfStructureDecoder bjs = new MmtfStructureDecoder(); Structure newStruct; try{ - DecodeStructure ds = new DecodeStructure(inputByteArr); + GetApiToInflatorInterface ds = new GetApiToInflatorInterface(inputByteArr); ds.getStructFromByteArray(bjs); newStruct = bjs.getStructure(); newStruct.setPDBCode(pdbCodePlus.substring(0,4));} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java index f0b4078..b983f16 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java @@ -13,7 +13,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.io.FileParsingParameters; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.decoder.SimpleDataApi; +import org.rcsb.mmtf.decoder.BeanToGetApi; /** * Class to test the raw API @@ -23,7 +23,7 @@ public class CheckOnRawApi { MmtfDecodedDataInterface dataApi; public CheckOnRawApi(byte[] inputData) { - dataApi = new SimpleDataApi(inputData); + dataApi = new BeanToGetApi(inputData); } /** diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index 519e536..a098cfb 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -12,8 +12,8 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; -import org.rcsb.mmtf.decoder.DecodeStructure; -import org.rcsb.mmtf.encoder.EncodeStructure; +import org.rcsb.mmtf.decoder.GetApiToInflatorInterface; +import org.rcsb.mmtf.encoder.GetApiToBean; import org.rcsb.mmtf.testutils.CheckOnBiojava; import org.rcsb.mmtf.testutils.CheckOnRawApi; @@ -64,7 +64,7 @@ public Structure roundTripStruct(String pdbId, FileParsingParameters params, Ato params.setUseInternalChainId(true); cache.setFileParsingParams(params); StructureIO.setAtomCache(cache); - EncodeStructure es = new EncodeStructure(); + GetApiToBean es = new GetApiToBean(); Structure mmcifStruct = StructureIO.getStructure(pdbId); FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromPdbId(pdbId, new BiojavaEncoderImpl())); byte[] inArr = FileUtils.readFileToByteArray(new File("pathname")); @@ -73,7 +73,7 @@ public Structure roundTripStruct(String pdbId, FileParsingParameters params, Ato checkRaw.checkRawDataConsistency(mmcifStruct, params); // Now decode the data and return this new structure MmtfStructureDecoder bjsi = new MmtfStructureDecoder(); - DecodeStructure decodeStructure = new DecodeStructure(inArr); + GetApiToInflatorInterface decodeStructure = new GetApiToInflatorInterface(inArr); decodeStructure.getStructFromByteArray(bjsi); Structure struct = bjsi.getStructure(); // Revert back From b383256049038d484fcdc84582e7941dfbd7a71c Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 10:45:55 -0700 Subject: [PATCH 051/108] Refactored API as per Alex's suggestions --- .../org/rcsb/mmtf/dataholders/PDBGroup.java | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java index 3696785..4f1193e 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java @@ -20,19 +20,23 @@ public class PDBGroup implements Serializable { /** The group name. (e.g. HIS) */ private String groupName; - /** The atom info. A list of strings indicating - * the atominfo (Atom name and element name). */ - private List atomInfo; + /** The atom names. A list of strings indicating + * the atom names (e.g. CA for C-alpha). */ + private List atomNameList; + /** The element names. A list of strings indicating + * the element names (e.g. Ca for Calcium). */ + private List elementList; + /** The bond orders. A list of integers indicating the bond orders*/ - private List bondOrders; + private List bondOrderList; /** The bond indices (in pairs). * (e.g. 0,1 means there is bond between atom 0 and 1).*/ - private List bondIndices; + private List bondAtomList; /** The atom charges. */ - private List atomCharges; + private List atomChargeList; /** The single letter code. */ private char singleLetterCode; @@ -47,10 +51,10 @@ public class PDBGroup implements Serializable { */ public PDBGroup(){ groupName = new String(); - atomInfo = new ArrayList(); - bondOrders = new ArrayList(); - bondIndices = new ArrayList(); - atomCharges = new ArrayList(); + atomNameList = new ArrayList(); + bondOrderList = new ArrayList(); + bondAtomList = new ArrayList(); + atomChargeList = new ArrayList(); } /** @@ -59,8 +63,8 @@ public PDBGroup(){ * @return the atom info */ // Generic getter and setter functions - public final List getAtomInfo() { - return atomInfo; + public final List getAtomNameList() { + return atomNameList; } /** @@ -68,8 +72,8 @@ public final List getAtomInfo() { * * @param inputAtomInfo the new atom info */ - public final void setAtomInfo(final List inputAtomInfo) { - this.atomInfo = inputAtomInfo; + public final void setAtomNameList(final List inputAtomInfo) { + this.atomNameList = inputAtomInfo; } /** @@ -77,8 +81,8 @@ public final void setAtomInfo(final List inputAtomInfo) { * * @return the bond orders */ - public final List getBondOrders() { - return bondOrders; + public final List getBondOrderList() { + return bondOrderList; } /** @@ -86,8 +90,8 @@ public final List getBondOrders() { * * @param inputBondOrders the new bond orders */ - public final void setBondOrders(final List inputBondOrders) { - this.bondOrders = inputBondOrders; + public final void setBondOrderList(final List inputBondOrders) { + this.bondOrderList = inputBondOrders; } /** @@ -95,8 +99,8 @@ public final void setBondOrders(final List inputBondOrders) { * * @return the bond indices */ - public final List getBondIndices() { - return bondIndices; + public final List getBondAtomList() { + return bondAtomList; } /** @@ -104,8 +108,8 @@ public final List getBondIndices() { * * @param inputBondIndices the new bond indices */ - public final void setBondIndices(final List inputBondIndices) { - this.bondIndices = inputBondIndices; + public final void setBondAtomList(final List inputBondIndices) { + this.bondAtomList = inputBondIndices; } /** @@ -131,8 +135,8 @@ public final void setGroupName(final String resName) { * * @return the atom charges */ - public final List getAtomCharges() { - return atomCharges; + public final List getAtomChargeList() { + return atomChargeList; } /** @@ -140,8 +144,8 @@ public final List getAtomCharges() { * * @param inputAtomCharges the new atom charges */ - public final void setAtomCharges(final List inputAtomCharges) { - this.atomCharges = inputAtomCharges; + public final void setAtomChargeList(final List inputAtomCharges) { + this.atomChargeList = inputAtomCharges; } /** @@ -175,4 +179,18 @@ public String getChemCompType() { public void setChemCompType(String groupType) { this.chemCompType = groupType; } + +/** + * @return the elementList + */ +public List getElementList() { + return elementList; +} + +/** + * @param elementList the elementList to set + */ +public void setElementList(List elementList) { + this.elementList = elementList; +} } From 9b2cbeaf06fed022c04c70ae5c14c3c4e8f1f303 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 10:47:01 -0700 Subject: [PATCH 052/108] New class to fill a get API from an arbitrary data source using the inflator interface --- .../encoder/InflatorInterfaceToGetApi.java | 517 ++++++++++++++++++ 1 file changed, 517 insertions(+) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java new file mode 100644 index 0000000..f559a70 --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java @@ -0,0 +1,517 @@ +package org.rcsb.mmtf.encoder; + +import java.util.ArrayList; +import java.util.List; + +import org.rcsb.mmtf.api.ByteArrayToObjectConverterInterface; +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; +import org.rcsb.mmtf.api.MmtfDecoderInterface; +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.Entity; +import org.rcsb.mmtf.dataholders.PDBGroup; + +/** + * A class for the encoding data api. + * @author Anthony Bradley + * + */ +public class InflatorInterfaceToGetApi implements MmtfDecodedDataInterface, MmtfDecoderInterface { + + + /** The X coordinates */ + private float[] cartnX; + + /** The Y coordinates */ + private float[] cartnY; + + /** The Z coordinates */ + private float[] cartnZ; + + /** The X coordinates */ + private float[] bFactor; + + /** The Y coordinates */ + private float[] occupancy; + + /** The atom id. */ + private int[] atomId; + + /** The alt id. */ + private char[] altId; + + /** The ins code. */ + private char[] insertionCodeList; + + /** The group num. */ + private int[] groupNum; + + /** The group map. */ + private PDBGroup[] groupMap; + + /** The group list. */ + private int[] groupList; + + /** The sequence ids of the groups */ + private int[] seqResGroupList; + + /** The public facing chain ids*/ + private String[] publicChainIds; + + /** The number of chains per model*/ + private int[] chainsPerModel; + + /** The number of groups per (internal) chain*/ + private int[] groupsPerChain; + + /** The space group of the structure*/ + private String spaceGroup; + + /** The unit cell of the structure*/ + private float[] unitCell; + + /** The bioassembly information for the structure*/ + private List bioAssembly; + + /** The bond indices for bonds between groups*/ + private int[] interGroupBondIndices; + + /** The bond orders for bonds between groups*/ + private int[] interGroupBondOrders; + + /** The chosen list of chain ids */ + private String[] chainList; + + /** The mmtf version */ + private String mmtfVersion; + + /** The mmtf prodcuer */ + private String mmtfProducer; + + /** The list of entities in this structure. */ + private Entity[] entityList; + + /** The PDB id */ + private String pdbId; + + /** The reported resolution of the dataset. */ + private Float resolution; + + /** The reported R Free of the model. */ + private Float rFree; + + /** The reported R Work of the model. */ + private Float rWork; + + /** The title of the model. */ + private String title; + + /** The list of experimental methods. */ + private String[] experimentalMethods; + + /** The deposition date of hte structure */ + private String depositionDate; + + + + /** The atom counter */ + int atomCounter = 0; + + + @Override + public float[] getxCoords() { + return cartnX; + } + + @Override + public float[] getyCoords() { + return cartnY; + + } + + @Override + public float[] getzCoords() { + return cartnZ; + } + + @Override + public float[] getbFactors() { + return bFactor; + } + + @Override + public float[] getOccupancies() { + return occupancy; + } + + @Override + public int[] getAtomIds() { + return atomId; + } + + @Override + public char[] getAltLocIds() { + return altId; + } + + @Override + public char[] getInsCodes() { + return insertionCodeList; + } + + @Override + public int[] getGroupIds() { + return groupNum; + } + + @Override + public String getGroupName(int groupInd) { + return groupMap[groupList[groupInd]].getGroupName(); + } + + @Override + public int getNumAtomsInGroup(int groupInd) { + return groupMap[groupList[groupInd]].getAtomChargeList().size(); + } + + @Override + public String[] getGroupAtomNames(int groupInd) { + groupMap[groupList[groupInd]].getAtomNames(); + } + + @Override + public String[] getGroupElementNames(int groupInd) { + groupMap[groupList[groupInd]].getElementNames(); + + } + + @Override + public int[] getGroupBondOrders(int groupInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getGroupBondIndices(int groupInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getGroupAtomCharges(int groupInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public char getGroupSingleLetterCode(int groupInd) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getGroupChemCompType(int groupInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getGroupTypeIndices() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getGroupSequenceIndices() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getChainIds() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getChainNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getChainsPerModel() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getGroupsPerChain() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getSpaceGroup() { + // TODO Auto-generated method stub + return null; + } + + @Override + public float[] getUnitCell() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getNumBioassemblies() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getNumTransInBioassembly(int bioassemblyIndex) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex) { + // TODO Auto-generated method stub + return null; + } + + @Override + public double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getInterGroupBondIndices() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getInterGroupBondOrders() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getMmtfVersion() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getMmtfProducer() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getNumEntities() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getEntityDescription(int entityInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getEntityType(int entityInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] getEntityChainIndexList(int entityInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getEntitySequence(int entityInd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getStructureId() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getNumModels() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getNumChains() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getNumGroups() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getNumAtoms() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getRfree() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getRwork() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getResolution() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getTitle() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getExperimentalMethods() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getDepositionDate() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setInputData(byte[] byteArray, ByteArrayToObjectConverterInterface byteArrayConverter) { + // TODO Auto-generated method stub + + } + + + // Now provide the capability to fill this data. + @Override + public void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, + String structureId) { + cartnX = new float[totalNumAtoms]; + cartnY= new float[totalNumAtoms]; + cartnZ = new float[totalNumAtoms]; + occupancy = new float[totalNumAtoms]; + bFactor = new float[totalNumAtoms]; + atomId = new int[totalNumAtoms]; + altId = new char[totalNumAtoms]; + insertionCodeList = new char[totalNumAtoms]; + + + } + + @Override + public void finalizeStructure() { + // TODO Auto-generated method stub + + } + + @Override + public void setModelCount(int modelCount) { + // TODO Auto-generated method stub + this.modelCount=modelCount; + } + + @Override + public void setModelInfo(int modelId, int chainCount) { + // TODO Auto-generated method stub + + modelIndex++; + } + + @Override + public void setChainInfo(String chainId, String chainName, int groupCount) { + // TODO Auto-generated method stub + + chainIndex++; + } + + @Override + public void setEntityInfo(String[] chainIds, String sequence, String description, String title) { + // TODO Auto-generated method stub + + entityIndex++; + } + + @Override + public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String polymerType, int atomCount) { + // TODO Auto-generated method stub + + groupIndex++; + } + + @Override + public void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, float x, float y, float z, + float occupancy, float temperatureFactor, String element, int charge) { + + + atomIndex++; + + } + + @Override + public void setBioAssemblyTrans(int bioAssemblyIndex, int[] inputChainIndices, double[] inputTransform) { + // TODO Auto-generated method stub + + } + + @Override + public void setXtalInfo(String spaceGroup, float[] unitCell) { + // TODO Auto-generated method stub + + } + + @Override + public void setGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder) { + // TODO Auto-generated method stub + + } + + @Override + public void setInterGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder) { + // TODO Auto-generated method stub + + } + + @Override + public void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, + String[] experimnetalMethods) { + this.rFree = rFree; + this.rWork = rWork; + this.resolution = resolution; + this.title = title; + this.depositionDate = depositionDate; + this.experimentalMethods = experimnetalMethods; + + } + +} From c6f9ee174d640a59240657805c1dc79e4d43dc2f Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 10:56:35 -0700 Subject: [PATCH 053/108] Make PDBGroup primitive types --- .../org/rcsb/mmtf/dataholders/PDBGroup.java | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java index 4f1193e..c9f9a7e 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java @@ -1,8 +1,6 @@ package org.rcsb.mmtf.dataholders; import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -22,21 +20,21 @@ public class PDBGroup implements Serializable { /** The atom names. A list of strings indicating * the atom names (e.g. CA for C-alpha). */ - private List atomNameList; + private String[] atomNameList; /** The element names. A list of strings indicating * the element names (e.g. Ca for Calcium). */ - private List elementList; + private String[] elementList; /** The bond orders. A list of integers indicating the bond orders*/ - private List bondOrderList; + private int[] bondOrderList; /** The bond indices (in pairs). * (e.g. 0,1 means there is bond between atom 0 and 1).*/ - private List bondAtomList; + private int[] bondAtomList; /** The atom charges. */ - private List atomChargeList; + private int[] atomChargeList; /** The single letter code. */ private char singleLetterCode; @@ -46,16 +44,6 @@ public class PDBGroup implements Serializable { */ private String chemCompType; - /** - * Constructor for the PDB group. Makes empty lists. - */ - public PDBGroup(){ - groupName = new String(); - atomNameList = new ArrayList(); - bondOrderList = new ArrayList(); - bondAtomList = new ArrayList(); - atomChargeList = new ArrayList(); - } /** * Gets the atom info. @@ -63,7 +51,7 @@ public PDBGroup(){ * @return the atom info */ // Generic getter and setter functions - public final List getAtomNameList() { + public String[] getAtomNameList() { return atomNameList; } @@ -72,7 +60,7 @@ public final List getAtomNameList() { * * @param inputAtomInfo the new atom info */ - public final void setAtomNameList(final List inputAtomInfo) { + public void setAtomNameList(String[] inputAtomInfo) { this.atomNameList = inputAtomInfo; } @@ -81,7 +69,7 @@ public final void setAtomNameList(final List inputAtomInfo) { * * @return the bond orders */ - public final List getBondOrderList() { + public int[] getBondOrderList() { return bondOrderList; } @@ -90,7 +78,7 @@ public final List getBondOrderList() { * * @param inputBondOrders the new bond orders */ - public final void setBondOrderList(final List inputBondOrders) { + public void setBondOrderList(int[] inputBondOrders) { this.bondOrderList = inputBondOrders; } @@ -99,7 +87,7 @@ public final void setBondOrderList(final List inputBondOrders) { * * @return the bond indices */ - public final List getBondAtomList() { + public int[] getBondAtomList() { return bondAtomList; } @@ -108,7 +96,7 @@ public final List getBondAtomList() { * * @param inputBondIndices the new bond indices */ - public final void setBondAtomList(final List inputBondIndices) { + public void setBondAtomList(int[] inputBondIndices) { this.bondAtomList = inputBondIndices; } @@ -117,7 +105,7 @@ public final void setBondAtomList(final List inputBondIndices) { * * @return the group name */ - public final String getGroupName() { + public String getGroupName() { return groupName; } @@ -126,7 +114,7 @@ public final String getGroupName() { * * @param resName the new group name */ - public final void setGroupName(final String resName) { + public void setGroupName(String resName) { this.groupName = resName; } @@ -135,7 +123,7 @@ public final void setGroupName(final String resName) { * * @return the atom charges */ - public final List getAtomChargeList() { + public int[] getAtomChargeList() { return atomChargeList; } @@ -144,7 +132,7 @@ public final List getAtomChargeList() { * * @param inputAtomCharges the new atom charges */ - public final void setAtomChargeList(final List inputAtomCharges) { + public void setAtomChargeList(int[] inputAtomCharges) { this.atomChargeList = inputAtomCharges; } @@ -153,7 +141,7 @@ public final void setAtomChargeList(final List inputAtomCharges) { * * @return the single letter code */ - public final char getSingleLetterCode() { + public char getSingleLetterCode() { return singleLetterCode; } @@ -162,7 +150,7 @@ public final char getSingleLetterCode() { * * @param inputSingleLetterCode the new single letter code */ - public final void setSingleLetterCode(final char inputSingleLetterCode) { + public void setSingleLetterCode(char inputSingleLetterCode) { this.singleLetterCode = inputSingleLetterCode; } @@ -183,14 +171,14 @@ public void setChemCompType(String groupType) { /** * @return the elementList */ -public List getElementList() { +public String[] getElementList() { return elementList; } /** * @param elementList the elementList to set */ -public void setElementList(List elementList) { +public void setElementList(String[] elementList) { this.elementList = elementList; } } From 13d462728e5e001c45f147681401a842d1b90389 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 11:06:56 -0700 Subject: [PATCH 054/108] Update the Interface to not require a data setter. Updated the Implementation to have proper getters. --- .../mmtf/api/MmtfDecodedDataInterface.java | 5 - .../encoder/InflatorInterfaceToGetApi.java | 129 +++++++----------- 2 files changed, 46 insertions(+), 88 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index e1bf739..0a34537 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -380,9 +380,4 @@ public interface MmtfDecodedDataInterface { */ String getDepositionDate(); - /** - * Enter the data as a byte array along with an interface to convert a byte array to an object. - */ - void setInputData(byte[] byteArray, ByteArrayToObjectConverterInterface byteArrayConverter); - } \ No newline at end of file diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java index f559a70..52f670a 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java @@ -170,246 +170,209 @@ public String getGroupName(int groupInd) { @Override public int getNumAtomsInGroup(int groupInd) { - return groupMap[groupList[groupInd]].getAtomChargeList().size(); + return groupMap[groupList[groupInd]].getAtomChargeList().length; } @Override public String[] getGroupAtomNames(int groupInd) { - groupMap[groupList[groupInd]].getAtomNames(); + return groupMap[groupList[groupInd]].getAtomNameList(); } @Override public String[] getGroupElementNames(int groupInd) { - groupMap[groupList[groupInd]].getElementNames(); + return groupMap[groupList[groupInd]].getElementList(); } @Override public int[] getGroupBondOrders(int groupInd) { - // TODO Auto-generated method stub - return null; + return groupMap[groupList[groupInd]].getBondOrderList(); + } @Override public int[] getGroupBondIndices(int groupInd) { - // TODO Auto-generated method stub - return null; + return groupMap[groupList[groupInd]].getBondAtomList(); } @Override public int[] getGroupAtomCharges(int groupInd) { - // TODO Auto-generated method stub - return null; + return groupMap[groupList[groupInd]].getAtomChargeList(); } @Override public char getGroupSingleLetterCode(int groupInd) { - // TODO Auto-generated method stub - return 0; + return groupMap[groupList[groupInd]].getSingleLetterCode(); } @Override public String getGroupChemCompType(int groupInd) { - // TODO Auto-generated method stub - return null; + return groupMap[groupList[groupInd]].getChemCompType(); } @Override public int[] getGroupTypeIndices() { - // TODO Auto-generated method stub - return null; + return groupList; } @Override public int[] getGroupSequenceIndices() { - // TODO Auto-generated method stub - return null; + return seqResGroupList; } @Override public String[] getChainIds() { - // TODO Auto-generated method stub - return null; + return chainList; } @Override public String[] getChainNames() { - // TODO Auto-generated method stub - return null; + return publicChainIds; } @Override public int[] getChainsPerModel() { - // TODO Auto-generated method stub - return null; + return chainsPerModel; } @Override public int[] getGroupsPerChain() { - // TODO Auto-generated method stub - return null; + return groupsPerChain; } @Override public String getSpaceGroup() { - // TODO Auto-generated method stub - return null; + return spaceGroup; } @Override public float[] getUnitCell() { - // TODO Auto-generated method stub - return null; + return unitCell; } @Override public int getNumBioassemblies() { - // TODO Auto-generated method stub - return 0; + return bioAssembly.size(); } @Override public int getNumTransInBioassembly(int bioassemblyIndex) { - // TODO Auto-generated method stub - return 0; + return bioAssembly.get(bioassemblyIndex).getTransforms().size(); } @Override public int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex) { - // TODO Auto-generated method stub - return null; + return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getChainIndexList(); } @Override public double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex) { - // TODO Auto-generated method stub - return null; + return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getTransformation(); } @Override public int[] getInterGroupBondIndices() { - // TODO Auto-generated method stub - return null; + return interGroupBondIndices; } @Override public int[] getInterGroupBondOrders() { - // TODO Auto-generated method stub - return null; + return interGroupBondOrders; } @Override public String getMmtfVersion() { - // TODO Auto-generated method stub - return null; + return mmtfVersion; } @Override public String getMmtfProducer() { - // TODO Auto-generated method stub - return null; + return mmtfProducer; } @Override public int getNumEntities() { - // TODO Auto-generated method stub - return 0; + return entityList.length; } @Override public String getEntityDescription(int entityInd) { - // TODO Auto-generated method stub - return null; + return entityList[entityInd].getDescription(); } @Override public String getEntityType(int entityInd) { - // TODO Auto-generated method stub - return null; + return entityList[entityInd].getType(); + } @Override public int[] getEntityChainIndexList(int entityInd) { - // TODO Auto-generated method stub - return null; + return entityList[entityInd].getChainIndexList(); } @Override public String getEntitySequence(int entityInd) { - // TODO Auto-generated method stub - return null; + return entityList[entityInd].getSequence(); } @Override public String getStructureId() { - // TODO Auto-generated method stub - return null; + return pdbId; } @Override public int getNumModels() { - // TODO Auto-generated method stub - return 0; + return chainsPerModel.length; } @Override public int getNumChains() { - // TODO Auto-generated method stub - return 0; + int sum = 0; + for (int numChainsInModel : chainsPerModel) { + sum+=numChainsInModel; + } + return sum; } @Override public int getNumGroups() { - // TODO Auto-generated method stub - return 0; + return insertionCodeList.length; } @Override public int getNumAtoms() { - // TODO Auto-generated method stub - return 0; + return cartnX.length; } @Override public float getRfree() { - // TODO Auto-generated method stub - return 0; + return rFree; } @Override public float getRwork() { - // TODO Auto-generated method stub - return 0; + return rWork; } @Override public float getResolution() { - // TODO Auto-generated method stub - return 0; + return resolution; } @Override public String getTitle() { - // TODO Auto-generated method stub - return null; + return title; } @Override public String[] getExperimentalMethods() { - // TODO Auto-generated method stub - return null; + return experimentalMethods; } @Override public String getDepositionDate() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setInputData(byte[] byteArray, ByteArrayToObjectConverterInterface byteArrayConverter) { - // TODO Auto-generated method stub - + return depositionDate; } From 3cd83bfdc20e8b5d7611e3424e3f96d594e5c208 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 16:26:37 -0700 Subject: [PATCH 055/108] Extensive refactoring and cleanup of the decoder and the PDBGroup. Upstream changes to the APIs based on spotting some missing data. --- .../rcsb/mmtf/api/MmtfDecoderInterface.java | 21 +- .../rcsb/mmtf/api/MmtfInputDataInterface.java | 368 ---------------- .../org/rcsb/mmtf/dataholders/PDBGroup.java | 393 ++++++++++-------- .../org/rcsb/mmtf/decoder/BeanToGetApi.java | 47 +-- .../decoder/GetApiToInflatorInterface.java | 4 +- .../encoder/InflatorInterfaceToGetApi.java | 195 ++++++--- 6 files changed, 377 insertions(+), 651 deletions(-) delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index b09f593..0e9bbab 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -23,12 +23,6 @@ public interface MmtfDecoderInterface { */ void finalizeStructure(); - /** - * Sets the number of models. - * @param modelCount Number of models - */ - void setModelCount(int modelCount); - /** * Sets the number of chains for a given model. * @param modelId identifier of the model within the structure @@ -45,26 +39,27 @@ public interface MmtfDecoderInterface { void setChainInfo(String chainId, String chainName, int groupCount); /** - * Sets the entity level annotation for a chain(s). ChainIds is a list of strings that indicate the list of chains this information + * Sets the entity level annotation for a chain(s). ChainIds is a list of integers that indicate the chains this information * refers to. Sequence is the one letter amino acid sequence. Description and title are both free forms strings describing the entity and * acting as a title for the entity. - * @param chainIds - * @param sequence - * @param description + * @param chainIndices the indices of the chain this refers to. + * @param sequence the full sequence of the entity + * @param description the text description of the entity * @param title */ - void setEntityInfo(String[] chainIds, String sequence, String description, String title); + void setEntityInfo(int[] chainIndices, String sequence, String description, String title); /** * Sets the information for a given group / residue with atomic data. * @param groupName 3 letter code name of this group/residue * @param groupNumber sequence position of this group * @param insertionCode the one letter insertion code - * @param polymerType a string indicating the type of group (as found in the chemcomp dictionary. Empty string if none available. + * @param groupType a string indicating the type of group (as found in the chemcomp dictionary. Empty string if none available. * @param atomCount the number of atoms in the group + * @param singleLetterCode the single letter code of the group */ void setGroupInfo(String groupName, int groupNumber, char insertionCode, - String polymerType, int atomCount); + String groupType, int atomCount, char singleLetterCode); /** diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java deleted file mode 100644 index ba079a8..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfInputDataInterface.java +++ /dev/null @@ -1,368 +0,0 @@ -package org.rcsb.mmtf.api; - -/** - * An interface to take the data from another data structure and insert it into the MmmtfDecodedApi. - * @author Anthony Bradley - * @author Jose Duarte - */ -public interface MmtfInputDataInterface { - - /** - * Sets an array containing the X coordinates of the atoms in Angstroms. - * @param an array of length the number of atoms in the structure - */ - void setxCoords(float[] xCoords); - - /** - * Sets an array containing the Y coordinates of the atoms in Angstroms. - * @param an array of length the number of atoms in the structure - */ - void setyCoords(float[] yCoords); - - /** - * Sets an array containing the Z coordinates of the atoms in Angstroms. - * @param an array of length the number of atoms in the structure - */ - void setzCoords(float[] zCoords); - - /** - * Sets an array containing the B-factors (temperature factors) of the atoms in Angstroms^2. - * @param an array of length the number of atoms in the structure - */ - void setbFactors(float[] bFactors); - - /** - * Sets an array containing the occupancy values of the atoms. - * @param an array of length the number of atoms in the structure - */ - void setOccupancies(float[] occupancies); - - /** - * Sets an array of atom serial ids (_atom_site.id in mmCIF dictionary). - * @param an array of length the number of atoms in the structure - */ - void setAtomIds(int[] atomIds); - - /** - * Sets an array of location ids of the atoms. - * '\0' specifies a lack of alt id. - * @param an array of length the number of atoms in the structure - */ - void setAltLocIds(char[] altLocIds); - - /** - * Sets an array containing the insertion codes (pdbx_PDB_ins_code in mmCIF dictionary) for each residue (group). - * '\0' specifies a lack of insertion code. - * @param an array with insertion codes - * @see #setGroupIds() - */ - void setInsCodes(char[] insCodes); - - /** - * Sets an array containing residue numbers (auth_seq_id in mmCIF dictionary) for each residue (group). - * @param an array with with residue numbers - * @see #setInsCodes() - */ - void setGroupIds(int[] groupIds); - - - /** - * Sets the group name for the group specified in {@link #setGroupTypeIndices()}. - * to link groups to the 3 letter group name, e.g. HIS. - * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. - * @param a 3 letter string specifiying the group name. - */ - void setGroupName(int groupInd, String groupName); - - /** - * Sets the number of atoms in the group specified in {@link #setGroupTypeIndices()}. - * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. - * @param numAtomsInGroup The number of atoms in the group - */ - void setNumAtomsInGroup(int groupInd, int numAtomsInGroup); - - - /** - * Sets the atom names (e.g. CB) for the group specified in {@link #setGroupTypeIndices()}. - * Atom names are unique for each unique atom in a group. - * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. - * @param groupAtomNames A list of strings for the atom names. - * */ - void setGroupAtomNames(int groupInd, String[] groupAtomNames); - - /** - * Sets the IUPAC element names (e.g. Ca is calcium) for the group specified in {@link #setGroupTypeIndices()}. - * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. - * @param groupElements an array of strings for the element information. - * */ - void setGroupElementNames(int groupInd, String[] groupElements); - - /** - * Sets the bond orders for the group specified in {@link #setGroupTypeIndices()}. - * A list of integers indicating the bond orders - * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. - * @param groupBondOrders an array of integers (1,2 or 3) indicating the bond orders. - * */ - void setGroupBondOrders(int groupInd, int[] groupBondOrders); - - /** - * Sets the zero-based bond indices (in pairs) for the group specified in {@link #setGroupTypeIndices()}. - * (e.g. 0,1 means there is bond between atom 0 and 1). - * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. - * @param groupBondIndices an array of integers specifying the bond indices (within the group). Indices are zero indexed. - * */ - void setGroupBondIndices(int groupInd, int[] groupBondIndices); - - /** - * Sets the atom charges for the group specified in {@link #setGroupTypeIndices()}. - * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. - * @param groupAtomCharges an array of integers indicating the atomic charge for each atom in the group. - */ - void setGroupAtomCharges(int groupInd, int[] groupAtomCharges); - - /** - * Sets the single letter amino acid code or nucleotide code for the - * group specified in {@link #setGroupTypeIndices()}. - * @param groupInd the index of the group specified in {@link #setGroupTypeIndices()}. - * @param groupSingleLetterCode the single letter amino acid or nucleotide, 'X' if non-standard amino acid or nucleotide - */ - void setGroupSingleLetterCode(int groupInd, char groupSingleLetterCode); - - /** - * Sets the chemical component type for the group specified in {@link #setGroupTypeIndices()}. - * @param groupInd The index of the group specified in {@link #setGroupTypeIndices()}. - * @param a string (taken from the chemical component dictionary) indicating - * the type of the group. Corresponds to - * http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html - */ - void setGroupChemCompType(int groupInd, String groupChemCompType); - - /** - * Sets an array containing indices to be used to obtain group level information - * @param an array of length the number of groups (residues) in the structure - */ - void setGroupTypeIndices(int[] groupTypeIndices); - - /** - * Sets an array containing the indices of groups (residues) in their corresponding sequences. - * The indices are 0-based and specified per entity, -1 indicates the group is not present in the sequence. - * @param groupSequenceIndices an array of length the number of groups (residues) in the structure - */ - void setGroupSequenceIndices(int[] groupSequenceIndices); - - /** - * Sets an array of internal chain identifiers (asym_ids in mmCIF dictionary), of length the - * number of chains (polymeric, non-polymeric and water) in the structure. - * @param chainIds an array of length the number of chains in the structur - * @see #setChainNames() - */ - void setChainIds(String[] chainIds); - - /** - * Sets an array of public chain identifiers (auth_ids in mmCIF dictionary), of length the - * number of chains (polymeric, non-polymeric and water) in the structure. - * @param chainNames an array of length the number of chains in the structur - * @see #setChainIds() - */ - void setChainNames(String[] chainNames); - - /** - * Sets an array containing the number of chains (polymeric/non-polymeric/water) in each model. - * @param chainsPerModel an array of length the number of models in the structure - */ - void setChainsPerModel(int[] chainsPerModel); - - /** - * Sets an array containing the number of groups (residues) in each chain. - * @param groupsPerChain an array of length the number of chains in the structur - */ - void setGroupsPerChain(int[] groupsPerChain); - - /** - * Sets the space group of the structure. - * @param spaceGroup the space group name (e.g. "P 21 21 21") or null if the structure is not crystallographic - */ - void setSpaceGroup(String spaceGroup); - - /** - * Sets the 6 floats that describe the unit cell. - * @param unitCell an array of size 6 with the unit cell parameters in order: a, b, c, alpha, beta, gamma - */ - void setUnitCell(float[] unitCell); - - /** - * Sets the number of bioassemblies in this structure. - * @param numBioassemblies the number of bioassemblies. - */ - void setNumBioassemblies(int numBioassemblies); - - /** - * Sets the number of transformations in a given bioassembly. - * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). - * @param numTransInBioassembly an integer specifying of transformations in a given bioassembly. - */ - void setNumTransInBioassembly(int bioassemblyIndex, int numTransInBioassembly); - - /** - * Sets the list of chain indices for the given transformation for the given bioassembly. - * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). - * @param transformationIndex an integer specifying the index (zero indexed) for the desired transformation. - * @param transChainIndexList a list of indices showing the chains involved in this transformation. - */ - void setChainIndexListForTransform(int bioassemblyIndex, int transformationIndex, int[] transChainIndexList); - - - /** - * Sets a 4x4 transformation matrix for the given transformation for the given bioassembly. - * It is row-packed as per the convention of vecmath. (The first four elements are in the first row of the - * overall matrix). - * @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed). - * @param transformationIndex an integer specifying the index for the desired transformation (zero indexed). - * @param transformationMatrix the transformation matrix for this transformation. - */ - void setMatrixForTransform(int bioassemblyIndex, int transformationIndex, double[] transformationMatrix); - - - /** - * Sets the zero-based bond indices (in pairs) for the structure. - * (e.g. 0,1 means there is bond between atom 0 and 1). - * @param interGroupBondIndices an array of integers specifying the bond indices (within the structure). Indices are zero-based. - */ - void setInterGroupBondIndices(int[] interGroupBondIndices); - - /** - * Sets an array of bond orders (1,2,3) of inter-group bonds with length number of inter-group bonds - * @param interGroupBondOrders the bond orders for bonds within a group - */ - void setInterGroupBondOrders(int[] interGroupBondOrders); - - /** - * Sets the MMTF version number (from the specification). - * @param mmtfVersion the version of the file. - */ - void setMmtfVersion(String mmtfVersion); - - /** - * Sets a string describing the producer of the MMTF file. - * e.g. "RCSB-PDB Generator---version: 6b8635f8d319beea9cd7cc7f5dd2649578ac01a0" - * @param mmtfProducer a string describing the producer - */ - void setMmtfProducer(String mmtfProducer); - - /** - * Sets the number of entities (as defined in mmCIF dictionary) in the structure - * @param numEntities the number of entities in the structure - */ - void setNumEntities(int numEntities); - - /** - * Sets the entity description (as defined in mmCIF dictionary) - * for the entity specified by the index. - * @param entityInd the index of the specified entity. - * @param entityDescription the description of the entity - */ - void setEntityDescription(int entityInd, String entityDescription); - - /** - * Sets the entity type (polymer, non-polymer, water) for the entity specified by the index. - * @param entityInd the index of the specified entity. - * @param entityType the entity type (polymer, non-polymer, water) - */ - void setEntityType(int entityInd, String entityType); - - /** - * Sets the chain indices for the entity specified by the index. - * @param entityInd the index of the specified entity. - * @param chainIndexList the chain index list - referencing the entity to the chains. - */ - void setEntityChainIndexList(int entityInd,int[] chainIndexList); - - /** - * Sets the sequence for the entity specified by the index. - * @param entityInd the index of the specified entity. - * @param sequence the one letter sequence for this entity. Empty string if no sequence is applicable. - */ - void setEntitySequence(int entityInd, String sequence); - - /** - * Sets the identifier of the structure. - * For instance the 4-letter PDB id - * @param structureId the identifier for the structure - */ - void setStructureId(String structureId); - - /** - * Sets the number of models in the structure. - * @param numModels the number of models - */ - void setNumModels(int numModels); - - /** - * Sets the number of chains (for all models) in the structure. - * @param numChains the number of chains for all models - * @see #setChainsPerModel() - */ - void setNumChains(int numChains); - - /** - * Sets the number of groups (residues) in the structure that have - * experimentally determined 3D coordinates. - * @param numGroups the number of residues in the structure, for all models and chains - */ - void setNumGroups(int numGroups); - - - /** - * Sets the number of atoms in the structure. - * @param numAtoms the number of atoms in the structure, for all models and chains - */ - void setNumAtoms(int numAtoms); - - - /** - * Sets the Rfree of the dataset. - * @param rFree the R-free value - */ - void setRfree(float rFree); - - /** - * Sets the Rwork of the dataset. - * @param rWork the R-work value - */ - void setRwork(float rWork); - - /** - * Sets the resolution of the dataset. - * @param resolution the resolution value in Angstroms - */ - void setResolution(float resolution); - - /** - * Sets the title of the structure. - * @param title the title of the structure. - */ - void setTitle(String title); - - /** - * Sets the experimental methods as an array of strings. Normally only one - * experimental method is available, but structures solved with hybrid methods will - * have more than one method. - * The possible experimental method values are described in - * data item _exptl.method of the mmCIF dictionary - * @param experimentalMethods the list of experimental methods - */ - void setExperimentalMethods(String[] experimentalMethods); - - /** - * Sets the deposition date of the structure as a string - * in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html - * @param depositionDate the deposition date of the structure. - */ - void setDepositionDate(String depositionDate); - - /** - * Returns the data as a decoded data interface. To then be encoded. - */ - MmtfDecodedDataInterface getDataAsDecodedDataInterface(); - -} \ No newline at end of file diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java index c9f9a7e..e74c7c7 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/PDBGroup.java @@ -1,6 +1,7 @@ package org.rcsb.mmtf.dataholders; import java.io.Serializable; +import java.util.Arrays; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -12,173 +13,227 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PDBGroup implements Serializable { - /** Serial id for this version of the format. */ - private static final long serialVersionUID = 2880633780569899800L; - - /** The group name. (e.g. HIS) */ - private String groupName; - - /** The atom names. A list of strings indicating - * the atom names (e.g. CA for C-alpha). */ - private String[] atomNameList; - - /** The element names. A list of strings indicating - * the element names (e.g. Ca for Calcium). */ - private String[] elementList; - - /** The bond orders. A list of integers indicating the bond orders*/ - private int[] bondOrderList; - - /** The bond indices (in pairs). - * (e.g. 0,1 means there is bond between atom 0 and 1).*/ - private int[] bondAtomList; - - /** The atom charges. */ - private int[] atomChargeList; - - /** The single letter code. */ - private char singleLetterCode; - - /** A string (taken from the chemical component dictionary) indicating - * the type of the group. Corresponds to -> http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html - */ - private String chemCompType; - - - /** - * Gets the atom info. - * - * @return the atom info - */ - // Generic getter and setter functions - public String[] getAtomNameList() { - return atomNameList; - } - - /** - * Sets the atom info. - * - * @param inputAtomInfo the new atom info - */ - public void setAtomNameList(String[] inputAtomInfo) { - this.atomNameList = inputAtomInfo; - } - - /** - * Gets the bond orders. - * - * @return the bond orders - */ - public int[] getBondOrderList() { - return bondOrderList; - } - - /** - * Sets the bond orders. - * - * @param inputBondOrders the new bond orders - */ - public void setBondOrderList(int[] inputBondOrders) { - this.bondOrderList = inputBondOrders; - } - - /** - * Gets the bond indices. - * - * @return the bond indices - */ - public int[] getBondAtomList() { - return bondAtomList; - } - - /** - * Sets the bond indices. - * - * @param inputBondIndices the new bond indices - */ - public void setBondAtomList(int[] inputBondIndices) { - this.bondAtomList = inputBondIndices; - } - - /** - * Gets the group name. - * - * @return the group name - */ - public String getGroupName() { - return groupName; - } - - /** - * Sets the group name. - * - * @param resName the new group name - */ - public void setGroupName(String resName) { - this.groupName = resName; - } - - /** - * Gets the atom charges. - * - * @return the atom charges - */ - public int[] getAtomChargeList() { - return atomChargeList; - } - - /** - * Sets the atom charges. - * - * @param inputAtomCharges the new atom charges - */ - public void setAtomChargeList(int[] inputAtomCharges) { - this.atomChargeList = inputAtomCharges; - } - - /** - * Gets the single letter code. - * - * @return the single letter code - */ - public char getSingleLetterCode() { - return singleLetterCode; - } - - /** - * Sets the single letter code. - * - * @param inputSingleLetterCode the new single letter code - */ - public void setSingleLetterCode(char inputSingleLetterCode) { - this.singleLetterCode = inputSingleLetterCode; - } - - /** - * @return the groupType - corresponds to _chem_comp.type - */ - public String getChemCompType() { - return chemCompType; - } - - /** - * @param groupType the groupType (corresponds to _chem_comp.type) to set - */ - public void setChemCompType(String groupType) { - this.chemCompType = groupType; - } - -/** - * @return the elementList - */ -public String[] getElementList() { - return elementList; -} - -/** - * @param elementList the elementList to set - */ -public void setElementList(String[] elementList) { - this.elementList = elementList; -} + /** Serial id for this version of the format. */ + private static final long serialVersionUID = 2880633780569899800L; + + /** The group name. (e.g. HIS) */ + private String groupName; + + /** The atom names. A list of strings indicating + * the atom names (e.g. CA for C-alpha). */ + private String[] atomNameList; + + /** The element names. A list of strings indicating + * the element names (e.g. Ca for Calcium). */ + private String[] elementList; + + /** The bond orders. A list of integers indicating the bond orders*/ + private int[] bondOrderList; + + /** The bond indices (in pairs). + * (e.g. 0,1 means there is bond between atom 0 and 1).*/ + private int[] bondAtomList; + + /** The atom charges. */ + private int[] atomChargeList; + + /** The single letter code. */ + private char singleLetterCode; + + /** A string (taken from the chemical component dictionary) indicating + * the type of the group. Corresponds to -> http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx.dic/Items/_chem_comp.type.html + */ + private String chemCompType; + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(atomChargeList); + result = prime * result + Arrays.hashCode(atomNameList); + result = prime * result + Arrays.hashCode(bondAtomList); + result = prime * result + Arrays.hashCode(bondOrderList); + result = prime * result + ((chemCompType == null) ? 0 : chemCompType.hashCode()); + result = prime * result + Arrays.hashCode(elementList); + result = prime * result + ((groupName == null) ? 0 : groupName.hashCode()); + result = prime * result + singleLetterCode; + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PDBGroup other = (PDBGroup) obj; + if (!Arrays.equals(atomChargeList, other.atomChargeList)) + return false; + if (!Arrays.equals(atomNameList, other.atomNameList)) + return false; + if (!Arrays.equals(bondAtomList, other.bondAtomList)) + return false; + if (!Arrays.equals(bondOrderList, other.bondOrderList)) + return false; + if (chemCompType == null) { + if (other.chemCompType != null) + return false; + } else if (!chemCompType.equals(other.chemCompType)) + return false; + if (!Arrays.equals(elementList, other.elementList)) + return false; + if (groupName == null) { + if (other.groupName != null) + return false; + } else if (!groupName.equals(other.groupName)) + return false; + if (singleLetterCode != other.singleLetterCode) + return false; + return true; + } + + /** + * Gets the atom info. + * + * @return the atom info + */ + // Generic getter and setter functions + public String[] getAtomNameList() { + return atomNameList; + } + + /** + * Sets the atom info. + * + * @param inputAtomInfo the new atom info + */ + public void setAtomNameList(String[] inputAtomInfo) { + this.atomNameList = inputAtomInfo; + } + + /** + * Gets the bond orders. + * + * @return the bond orders + */ + public int[] getBondOrderList() { + return bondOrderList; + } + + /** + * Sets the bond orders. + * + * @param inputBondOrders the new bond orders + */ + public void setBondOrderList(int[] inputBondOrders) { + this.bondOrderList = inputBondOrders; + } + + /** + * Gets the bond indices. + * + * @return the bond indices + */ + public int[] getBondAtomList() { + return bondAtomList; + } + + /** + * Sets the bond indices. + * + * @param inputBondIndices the new bond indices + */ + public void setBondAtomList(int[] inputBondIndices) { + this.bondAtomList = inputBondIndices; + } + + /** + * Gets the group name. + * + * @return the group name + */ + public String getGroupName() { + return groupName; + } + + /** + * Sets the group name. + * + * @param resName the new group name + */ + public void setGroupName(String resName) { + this.groupName = resName; + } + + /** + * Gets the atom charges. + * + * @return the atom charges + */ + public int[] getAtomChargeList() { + return atomChargeList; + } + + /** + * Sets the atom charges. + * + * @param inputAtomCharges the new atom charges + */ + public void setAtomChargeList(int[] inputAtomCharges) { + this.atomChargeList = inputAtomCharges; + } + + /** + * Gets the single letter code. + * + * @return the single letter code + */ + public char getSingleLetterCode() { + return singleLetterCode; + } + + /** + * Sets the single letter code. + * + * @param inputSingleLetterCode the new single letter code + */ + public void setSingleLetterCode(char inputSingleLetterCode) { + this.singleLetterCode = inputSingleLetterCode; + } + + /** + * @return the groupType - corresponds to _chem_comp.type + */ + public String getChemCompType() { + return chemCompType; + } + + /** + * @param groupType the groupType (corresponds to _chem_comp.type) to set + */ + public void setChemCompType(String groupType) { + this.chemCompType = groupType; + } + + /** + * @return the elementList + */ + public String[] getElementList() { + return elementList; + } + + /** + * @param elementList the elementList to set + */ + public void setElementList(String[] elementList) { + this.elementList = elementList; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java index 9eb1e17..ea90e3c 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGetApi.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; -import org.rcsb.mmtf.api.ByteArrayToObjectConverterInterface; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.arraydecoders.DeltaDecompress; import org.rcsb.mmtf.arraydecoders.RunLengthDecodeInt; @@ -347,47 +346,34 @@ public String getGroupName(int groupInd) { } public int getNumAtomsInGroup(int groupInd) { - return groupMap[groupInd].getAtomChargeList().size(); + return groupMap[groupInd].getAtomChargeList().length; } @Override public String[] getGroupAtomNames(int groupInd) { - List atomInfo = groupMap[groupInd].getAtomNameList(); - String[] outList = new String[atomInfo.size()/2]; - int counter = 0; - for (int i=1; i atomInfo = groupMap[groupInd].getAtomNameList(); - String[] outList = new String[atomInfo.size()/2]; - int counter = 0; - for (int i=0; i; - * @param inArray The input List<> of Integers - * @return A primitive int[]. - */ - private int[] convertToIntList(List inArray) { - int[] outArray = new int[inArray.size()]; - for (int i=0; i groupMap; /** The group list. */ private int[] groupList; @@ -107,16 +107,31 @@ public class InflatorInterfaceToGetApi implements MmtfDecodedDataInterface, Mmtf /** The list of experimental methods. */ private String[] experimentalMethods; - + /** The deposition date of hte structure */ private String depositionDate; - - - + + /** The total number of models */ + private int numModels; + /** The atom counter */ - int atomCounter = 0; - - + int atomIndex = 0; + /** The atom counter within a group*/ + int groupAtomIndex = 0; + /** The group counter */ + int groupIndex = 0; + /** The chain counter */ + int chainIndex = 0; + /** The model counter */ + int modelIndex = 0; + /** The entity counter */ + int entityIndex = 0; + /** Add the atom information for the current group */ + PDBGroup pdbGroup; + /** A List for Entities as the number of entities is not defined*/ + List entities = new ArrayList<>(); + + @Override public float[] getxCoords() { return cartnX; @@ -165,51 +180,52 @@ public int[] getGroupIds() { @Override public String getGroupName(int groupInd) { - return groupMap[groupList[groupInd]].getGroupName(); + return getGroup(groupInd).getGroupName(); } @Override public int getNumAtomsInGroup(int groupInd) { - return groupMap[groupList[groupInd]].getAtomChargeList().length; + return getGroup(groupInd).getAtomChargeList().length; } @Override public String[] getGroupAtomNames(int groupInd) { - return groupMap[groupList[groupInd]].getAtomNameList(); + return getGroup(groupInd).getAtomNameList(); } @Override public String[] getGroupElementNames(int groupInd) { - return groupMap[groupList[groupInd]].getElementList(); + return getGroup(groupInd).getElementList(); } @Override public int[] getGroupBondOrders(int groupInd) { - return groupMap[groupList[groupInd]].getBondOrderList(); + return getGroup(groupInd).getBondOrderList(); } @Override public int[] getGroupBondIndices(int groupInd) { - return groupMap[groupList[groupInd]].getBondAtomList(); + return getGroup(groupInd).getBondAtomList(); } @Override public int[] getGroupAtomCharges(int groupInd) { - return groupMap[groupList[groupInd]].getAtomChargeList(); + return getGroup(groupInd).getAtomChargeList(); } @Override public char getGroupSingleLetterCode(int groupInd) { - return groupMap[groupList[groupInd]].getSingleLetterCode(); + return getGroup(groupInd).getSingleLetterCode(); } @Override public String getGroupChemCompType(int groupInd) { - return groupMap[groupList[groupInd]].getChemCompType(); + return getGroup(groupInd).getChemCompType(); } + @Override public int[] getGroupTypeIndices() { return groupList; @@ -323,7 +339,7 @@ public String getStructureId() { @Override public int getNumModels() { - return chainsPerModel.length; + return numModels; } @Override @@ -374,95 +390,152 @@ public String[] getExperimentalMethods() { public String getDepositionDate() { return depositionDate; } - - + + // Now provide the capability to fill this data. @Override public void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, String structureId) { + // Intitialise the atom level arrays cartnX = new float[totalNumAtoms]; cartnY= new float[totalNumAtoms]; cartnZ = new float[totalNumAtoms]; occupancy = new float[totalNumAtoms]; bFactor = new float[totalNumAtoms]; - atomId = new int[totalNumAtoms]; - altId = new char[totalNumAtoms]; - insertionCodeList = new char[totalNumAtoms]; - - - } + atomId = new int[totalNumAtoms]; + // Initialise the group level data + altId = new char[totalNumGroups]; + insertionCodeList = new char[totalNumGroups]; + groupList = new int[totalNumGroups]; + // Intialise the chain level data + // Initialise the model level information + numModels = totalNumModels; + // Set the name + pdbId = structureId; - @Override - public void finalizeStructure() { - // TODO Auto-generated method stub - } @Override - public void setModelCount(int modelCount) { - // TODO Auto-generated method stub - this.modelCount=modelCount; + public void finalizeStructure() { + // Convert the entities array to a list + entityList = entities.toArray(new Entity[0]); } @Override public void setModelInfo(int modelId, int chainCount) { - // TODO Auto-generated method stub - + chainsPerModel[modelIndex] = chainCount; modelIndex++; } @Override public void setChainInfo(String chainId, String chainName, int groupCount) { - // TODO Auto-generated method stub - + chainList[chainIndex] = chainId; + publicChainIds[chainIndex] = chainName; + groupsPerChain[chainIndex] = groupCount; chainIndex++; } @Override - public void setEntityInfo(String[] chainIds, String sequence, String description, String title) { - // TODO Auto-generated method stub - + public void setEntityInfo(int[] chainIndices, String sequence, String description, String title) { + Entity entity = new Entity(); + entity.setChainIndexList(chainIndices); + entity.setSequence(sequence); + entity.setDescription(description); + entity.setType(title); + // Add this entity + entities.add(entity); entityIndex++; } @Override - public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String polymerType, int atomCount) { - // TODO Auto-generated method stub + public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String polymerType, int atomCount, char singleAtomCode) { + // If it's not the first go + if(pdbGroup!=null) { + // Now add this to the list or find it in the list + if (!groupMap.contains(pdbGroup)) { + groupMap.add(pdbGroup); + } + // Add this index to the group list + groupList[groupIndex-1] = groupMap.indexOf(pdbGroup); + } + // Make a new PDBGroup to store the repeated information + pdbGroup = new PDBGroup(); + pdbGroup.setAtomChargeList(new int[atomCount]); + pdbGroup.setAtomNameList(new String[atomCount]); + pdbGroup.setBondAtomList(new int[atomCount]); + pdbGroup.setBondOrderList(new int[atomCount]); + pdbGroup.setChemCompType(polymerType); + pdbGroup.setElementList(new String[atomCount]); + pdbGroup.setGroupName(groupName); + pdbGroup.setSingleLetterCode(insertionCode); + groupAtomIndex=0; + + // Store the group level data + groupNum[groupIndex] = groupNumber; groupIndex++; } @Override public void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, float x, float y, float z, float occupancy, float temperatureFactor, String element, int charge) { - - + // Set the group level data + pdbGroup.getAtomChargeList()[groupAtomIndex] = charge; + pdbGroup.getAtomNameList()[groupAtomIndex] = atomName; + pdbGroup.getElementList()[groupAtomIndex] = element; + // Set the atom level data + cartnX[atomIndex] = x; + cartnY[atomIndex] = y; + cartnZ[atomIndex] = z; + this.occupancy[atomIndex] = occupancy; + bFactor[atomIndex] = temperatureFactor; + atomId[atomIndex] = serialNumber; + altId[atomIndex] = alternativeLocationId; + // Increment both counters + groupAtomIndex++; atomIndex++; - } @Override - public void setBioAssemblyTrans(int bioAssemblyIndex, int[] inputChainIndices, double[] inputTransform) { - // TODO Auto-generated method stub - + public void setBioAssemblyTrans(int bioAssemblyIndex, int[] chainIndices, double[] transform) { + BioAssemblyData bioAssemblyData; + List bioAssemblyTranList; + if (bioAssembly.size()>bioAssemblyIndex) { + bioAssemblyTranList = bioAssembly.get(bioAssemblyIndex).getTransforms(); + } + else{ + bioAssemblyData = new BioAssemblyData(); + bioAssemblyTranList = new ArrayList<>(); + bioAssemblyData.setTransforms(bioAssemblyTranList); + bioAssembly.add(bioAssemblyData); + } + BioAssemblyTrans bioAssemblyTrans = new BioAssemblyTrans(); + bioAssemblyTrans.setChainIndexList(chainIndices); + bioAssemblyTrans.setTransformation(transform); } @Override public void setXtalInfo(String spaceGroup, float[] unitCell) { - // TODO Auto-generated method stub - + this.spaceGroup = spaceGroup; + this.unitCell = unitCell; } @Override - public void setGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder) { - // TODO Auto-generated method stub - + public void setGroupBond(int firstAtomIndex, int secondAtomIndex, int bondOrder) { + // Set the bond indices + pdbGroup.getBondAtomList()[groupAtomIndex*2] = firstAtomIndex; + pdbGroup.getBondAtomList()[groupAtomIndex*2+1] = secondAtomIndex; + // Set the bond order + pdbGroup.getBondOrderList()[groupAtomIndex] = bondOrder; } @Override - public void setInterGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder) { - // TODO Auto-generated method stub - + public void setInterGroupBond(int firstAtomIndex, int secondAtomIndex, int bondOrder) { + // Set the bond indices + interGroupBondIndices[atomIndex*2] = firstAtomIndex; + interGroupBondIndices[atomIndex*2+1] = secondAtomIndex; + // Set the bond order + interGroupBondOrders[atomIndex] = bondOrder; } @Override @@ -474,7 +547,11 @@ public void setHeaderInfo(float rFree, float rWork, float resolution, String tit this.title = title; this.depositionDate = depositionDate; this.experimentalMethods = experimnetalMethods; - + + } + + private PDBGroup getGroup(int groupInd) { + return groupMap.get(groupList[groupInd]); } } From f586496d5e9f91c6534e482b134d65b9b87506aa Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Thu, 7 Apr 2016 19:20:00 -0700 Subject: [PATCH 056/108] Downstream refactoring the update --- .../src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java | 4 ++-- .../main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java | 4 ++-- .../src/main/java/org/rcsb/mmtf/update/TestingUtils.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index a8ec1f3..05ab040 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -9,7 +9,7 @@ import org.apache.spark.api.java.JavaSparkContext; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.decoder.GetApiToInflatorInterface; @@ -30,7 +30,7 @@ public class MapperUtils implements Serializable{ * @return */ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) { - MmtfStructureDecoder bjs = new MmtfStructureDecoder(); + MmtfStructureReader bjs = new MmtfStructureReader(); Structure newStruct; try{ GetApiToInflatorInterface ds = new GetApiToInflatorInterface(inputByteArr); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index a03921e..2fa2a19 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -8,7 +8,7 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.examples.HandleIO; import org.rcsb.mmtf.testutils.CheckOnBiojava; @@ -65,7 +65,7 @@ public void basicParsingTest(String baseUrl) throws IOException { private void testParsing(String inputPdb, String inputUrl) throws IOException { System.out.println("TESTING: "+inputPdb); byte[] inputByteArr = handleIo.getFromUrl(inputPdb, inputUrl); - Structure mmtfStruct = MmtfStructureDecoder.getBiojavaStruct(inputByteArr); + Structure mmtfStruct = MmtfStructureReader.getBiojavaStruct(inputByteArr); // Now parse from the MMCIF file Structure mmcifStruct; try { diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index a098cfb..6ef1318 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -10,7 +10,7 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureDecoder; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; import org.rcsb.mmtf.decoder.GetApiToInflatorInterface; import org.rcsb.mmtf.encoder.GetApiToBean; @@ -72,7 +72,7 @@ public Structure roundTripStruct(String pdbId, FileParsingParameters params, Ato CheckOnRawApi checkRaw = new CheckOnRawApi(inArr); checkRaw.checkRawDataConsistency(mmcifStruct, params); // Now decode the data and return this new structure - MmtfStructureDecoder bjsi = new MmtfStructureDecoder(); + MmtfStructureReader bjsi = new MmtfStructureReader(); GetApiToInflatorInterface decodeStructure = new GetApiToInflatorInterface(inArr); decodeStructure.getStructFromByteArray(bjsi); Structure struct = bjsi.getStructure(); From f15d295eebb3b132eb6f7542d0fc67c22cac32ec Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 06:31:30 -0700 Subject: [PATCH 057/108] Further refactoring and modifications. Added the map of group to sequence. --- .../main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java | 3 ++- .../org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java | 5 +++-- .../org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index 0e9bbab..ced5987 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -57,9 +57,10 @@ public interface MmtfDecoderInterface { * @param groupType a string indicating the type of group (as found in the chemcomp dictionary. Empty string if none available. * @param atomCount the number of atoms in the group * @param singleLetterCode the single letter code of the group + * @param sequenceIndex the index of this group in the sequence */ void setGroupInfo(String groupName, int groupNumber, char insertionCode, - String groupType, int atomCount, char singleLetterCode); + String groupType, int atomCount, char singleLetterCode, int sequenceIndex); /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java index f58c5c2..58189e8 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java @@ -139,7 +139,7 @@ private void addOrUpdateChainInfo(int chainIndex) { * @param currentGroupIndex the integer indicating the index of the group to be added. * @return an integer for the number of atoms in the structure. */ - private int addGroup(final int currentGroupIndex) { + private int addGroup(int currentGroupIndex) { // Now get the group int groupInd = dataApi.getGroupTypeIndices()[currentGroupIndex]; // Get this info @@ -147,7 +147,8 @@ private int addGroup(final int currentGroupIndex) { int currentGroupNumber = dataApi.getGroupIds()[currentGroupIndex]; char insertionCode = dataApi.getInsCodes()[currentGroupIndex]; structInflator.setGroupInfo(dataApi.getGroupName(groupInd), currentGroupNumber, insertionCode, - dataApi.getGroupChemCompType(groupInd), atomCount, dataApi.getGroupSingleLetterCode(groupInd)); + dataApi.getGroupChemCompType(groupInd), atomCount, dataApi.getGroupSingleLetterCode(groupInd), + dataApi.getGroupSequenceIndices()[currentGroupIndex]); // A counter for the atom information atomCounter = 0; // Now read the next atoms diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java index 15e35da..ec319a6 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java @@ -406,6 +406,7 @@ public void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumCha // Initialise the group level data altId = new char[totalNumGroups]; insertionCodeList = new char[totalNumGroups]; + seqResGroupList = new int[totalNumGroups]; groupList = new int[totalNumGroups]; // Intialise the chain level data // Initialise the model level information @@ -448,7 +449,8 @@ public void setEntityInfo(int[] chainIndices, String sequence, String descriptio } @Override - public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String polymerType, int atomCount, char singleAtomCode) { + public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String polymerType, + int atomCount, char singleAtomCode, int sequenceIndex) { // If it's not the first go if(pdbGroup!=null) { // Now add this to the list or find it in the list @@ -473,6 +475,7 @@ public void setGroupInfo(String groupName, int groupNumber, char insertionCode, // Store the group level data groupNum[groupIndex] = groupNumber; + seqResGroupList[groupIndex] = sequenceIndex; groupIndex++; } From 93ba67cf6b329f4ad637107b60b1008f654db021 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 06:38:12 -0700 Subject: [PATCH 058/108] Removed all dependeices on Biojava from the encoder. Moved some tests to the integration tests. --- .../biojavaencoder/BiojavaEncoderImpl.java | 711 ------------------ .../mmtf/biojavaencoder/BiojavaUtils.java | 337 --------- .../CustomChemCompProvider.java | 469 ------------ .../rcsb/mmtf/biojavaencoder/GroupType.java | 52 -- .../mmtf/biojavaencoder/package-info.java | 6 - .../mmtf/biojavaencoder/TestBiojavaUtils.java | 120 --- .../mmtf/biojavaencoder/TestBondFinding.java | 79 -- .../mmtf/dataholders/TestDataHolders.java | 65 +- .../mmtf/integrationtest/TestParseMMCif.java | 39 + 9 files changed, 42 insertions(+), 1836 deletions(-) delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/CustomChemCompProvider.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/package-info.java delete mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBiojavaUtils.java delete mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java deleted file mode 100644 index 71a46f5..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaEncoderImpl.java +++ /dev/null @@ -1,711 +0,0 @@ -package org.rcsb.mmtf.biojavaencoder; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Bond; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Element; -import org.biojava.nbio.structure.EntityInfo; -import org.biojava.nbio.structure.ExperimentalTechnique; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.ResidueNumber; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.secstruc.SecStrucState; -import org.rcsb.mmtf.dataholders.BioDataStruct; -import org.rcsb.mmtf.dataholders.CalphaBean; -import org.rcsb.mmtf.dataholders.DsspType; -import org.rcsb.mmtf.dataholders.Entity; -import org.rcsb.mmtf.dataholders.HeaderBean; -import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.dataholders.PDBGroup; -import org.rcsb.mmtf.encoder.EncoderInterface; -import org.rcsb.mmtf.encoder.EncoderUtils; - - -/** A class to use biojava to parse MMCIF data and produce a data structure that can be fed into the MMTF. */ -public class BiojavaEncoderImpl implements EncoderInterface { - - /** The bio struct. */ - private BioDataStruct bioStruct = new BioDataStruct(); - - /** The calpha struct. */ - private CalphaBean calphaStruct = new CalphaBean(); - - /** The header struct. */ - private HeaderBean headerStruct = new HeaderBean(); - - /** The bonds for the structure. Used to keep track of which bonds have already been considered */ - private List totBonds = new ArrayList(); - - /** The number of groups per calpha chain. */ - private int[] calphaGroupsPerChain; - - /** The hash to calpha res. */ - private Map hashToCalphaRes; - - /** The a map relating hash codes to groups. For calphas */ - private Map calphaHashCodeToGroupMap; - - /** The chain counter. */ - private int chainCounter; - - /** The calpha group / residue counter. */ - private int calphaResCounter; - - /** The Biojava group currently being parsed. */ - private Group currentGroup; - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#getBioStruct() - */ - @Override - public BioDataStruct getBioStruct() { - return bioStruct; - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#setBioStruct(org.rcsb.mmtf.dataholders.BioDataStruct) - */ - @Override - public void setBioStruct(BioDataStruct bioStruct) { - this.bioStruct = bioStruct; - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#getCalphaStruct() - */ - @Override - public CalphaBean getCalphaStruct() { - return calphaStruct; - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#setCalphaStruct(org.rcsb.mmtf.dataholders.CalphaBean) - */ - @Override - public void setCalphaStruct(CalphaBean calphaStruct) { - this.calphaStruct = calphaStruct; - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#getHeaderStruct() - */ - @Override - public HeaderBean getHeaderStruct() { - return headerStruct; - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#setHeaderStruct(org.rcsb.mmtf.dataholders.HeaderBean) - */ - @Override - public void setHeaderStruct(HeaderBean headerStruct) { - this.headerStruct = headerStruct; - } - - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biojavaencoder.EncoderInterface#generateDataStructuresFromPdbId(java.lang.String, java.util.Map) - */ - @Override - public final void generateDataStructuresFromPdbId(String pdbId, Map bioStructMap) { - // Get the structure from here - Structure bioJavaStruct; - try { - bioJavaStruct = StructureIO.getStructure(pdbId); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Could not find/open data file for input: "+pdbId); - throw new RuntimeException(e); - } catch (StructureException e) { - e.printStackTrace(); - System.err.println("Error in parsing structure for input: "+pdbId); - throw new RuntimeException(e); - } - generateDataStructuresFromPdbId(bioJavaStruct, bioStructMap); - } - - - /** - * Function to generate a main, calpha and header data form a biojava structure. - * - * @param inputBiojavaStruct the Biojava structure - * @param bioStructMap the map relating hash codes to PDB groups. - * input so that a consistent map can be held across several structures - */ - public final void generateDataStructuresFromPdbId(Structure inputBiojavaStruct, Map bioStructMap) { - EncoderUtils encoderUtils = new EncoderUtils(); - BiojavaUtils biojavaUtils = new BiojavaUtils(); - // Reset structure to consider altloc groups with the same residue number but different group names as seperate groups - biojavaUtils.fixMicroheterogenity(inputBiojavaStruct); - // Generate the secondary structure - biojavaUtils.calculateDsspSecondaryStructure(inputBiojavaStruct); - // Set the header information - biojavaUtils.setHeaderInfo(inputBiojavaStruct, headerStruct); - // Get the number of models - Integer numModels = inputBiojavaStruct.nrModels(); - bioStruct.setNumModels(numModels); - // Set these maps and lists - List> bioStructList= new ArrayList>(); - Map hashToRes = new HashMap(); - hashToCalphaRes = new HashMap(); - // Set these counters - int atomCounter = 0; - chainCounter = 0; - int resCounter = 0; - int totAsymChains = 0; - // Get the total number of chains - for (int i=0; i(); - // Get these lists to keep track of everthing - and to give a datastrcutrue at the end - // List of chains per model - int[] chainsPerModel = new int[numModels]; - int[] internalChainsPerModel = new int[numModels]; - // Set this list - headerStruct.setChainsPerModel(chainsPerModel); - headerStruct.setAsymChainsPerModel(internalChainsPerModel); - byte[] charChainList = new byte[totAsymChains*4]; - byte[] charInternalChainList = new byte[totAsymChains*4]; - headerStruct.setChainList(charChainList); - headerStruct.setAsymChainList(charInternalChainList); - int[] groupsPerChain = new int[totAsymChains]; - int[] groupsPerInternalChain = new int[totAsymChains]; - headerStruct.setAsymGroupsPerChain(groupsPerInternalChain); - headerStruct.setGroupsPerChain(groupsPerChain); - headerStruct.setSequence(new ArrayList()); - // Find the experimental techniques - Set techniqueSet = inputBiojavaStruct.getPDBHeader().getExperimentalTechniques(); - headerStruct.setExperimentalMethods(new ArrayList()); - for (ExperimentalTechnique currentTechnique : techniqueSet){ - headerStruct.getExperimentalMethods().add(currentTechnique.toString()); - } - headerStruct.setSeqResGroupIds(new ArrayList()); - int bondCounter = 0; - - calphaGroupsPerChain = new int[totAsymChains]; - for(int i=0; i totAtoms = biojavaUtils.getAllAtoms(inputBiojavaStruct); - for (int i=0; i chains = inputBiojavaStruct.getModel(i); - // Set the PDB Code - bioStruct.setPdbCode(inputBiojavaStruct.getPDBCode()); - ArrayList chainList = new ArrayList(); - // Set the number of chains in this model - internalChainsPerModel[i] = chains.size(); - // Get the number of unique ones - Set chainIdSet = new HashSet(); - for(Chain c : chains){ - String intChainId = c.getInternalChainID(); - chainIdSet.add(intChainId); - } - chainsPerModel[i] = chainIdSet.size(); - // Take the atomic information and place in a Hashmap - for (Chain biojavaChain: chains) { - // Get the seq res groups for this chain - List seqResGroups = biojavaChain.getSeqResGroups(); - // Set the sequence - if it's the first model... - if(i==0){ - headerStruct.getSequence().add(biojavaChain.getSeqResSequence()); - } - // Set the auth chain id - encoderUtils.setChainId(biojavaChain.getInternalChainID(), charChainList, chainCounter); - // Set the asym chain id - encoderUtils.setChainId(biojavaChain.getChainID(), charInternalChainList, chainCounter); - // Set the number of groups per chain - groupsPerChain[chainCounter] += biojavaChain.getAtomGroups().size(); - // Set the number of groups per internal chain - groupsPerInternalChain[chainCounter] = biojavaChain.getAtomGroups().size(); - // Add this chain to the list - chainList.add(biojavaChain.getChainID()); - // Reset the number of bonds counter for this chain - int numBonds = 0; - for (Group loopGroup : biojavaChain.getAtomGroups()) { - currentGroup = loopGroup; - // Set the seq res group id - if(i==0){ - headerStruct.getSeqResGroupIds().add(seqResGroups.indexOf(currentGroup)); - } - // Get the atoms for this group - List atomsInThisGroup = biojavaUtils.getAtomsForGroup(currentGroup); - // Get any bonds between groups - getInterGroupBond(atomsInThisGroup, totAtoms); - // Count the number of bonds - // Now loop through and get the coords - // Generate the group level data - // Get the data that defines a group - List groupInfo = getGroupData(atomsInThisGroup); - // Get the atomic info required - bioStruct is the unique identifier of the group - int hashCode = getHashFromStringList(groupInfo); - // If we need bioStruct new information - if (hashToRes.containsKey(hashCode)==false){ - // Make a new group - PDBGroup outGroup = new PDBGroup(); - // Set the one letter code - outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code().charAt(0)); - // Set the group type - outGroup.setChemCompType(currentGroup.getChemComp().getType()); - outGroup.setGroupName(groupInfo.remove(0)); - outGroup.setAtomNameList(groupInfo); - // Now get the bond list (lengths, orders and indices) - createBondList(atomsInThisGroup, outGroup); - getCharges(atomsInThisGroup, outGroup); - // Put the residue information into this bio structure map - bioStructMap.put(resCounter, outGroup); - hashToRes.put(hashCode, resCounter); - bioStruct.getResOrder().add(resCounter); - resCounter+=1; - numBonds = outGroup.getBondOrderList().size(); - } - else{ - // Add this to the residue order - bioStruct.getResOrder().add(hashToRes.get(hashCode)); - numBonds = bioStructMap.get(hashToRes.get(hashCode)).getBondOrderList().size(); - } - // Add the number of bonds - bondCounter+=numBonds; - - ResidueNumber residueNum = currentGroup.getResidueNumber(); - - // bioStruct data item corresponds to the PDB insertion code. - Character insertionCode = residueNum.getInsCode(); - if (insertionCode==null){ - bioStruct.get_atom_site_pdbx_PDB_ins_code().add(null); - } - else{ - bioStruct.get_atom_site_pdbx_PDB_ins_code().add(insertionCode.toString()); - } - - SecStrucState props = (SecStrucState) currentGroup.getProperty("secstruc"); - // Only assign secondary structure for the first model - if(i==0){ - if(props==null){ - bioStruct.getSecStruct().add(DsspType.dsspTypeFromString("NA").getDsspIndex()); - } - else{ - bioStruct.getSecStruct().add(DsspType.dsspTypeFromString(props.getType().name).getDsspIndex()); - } - } - // Now add the residue sequnece number - bioStruct.get_atom_site_auth_seq_id().add(residueNum.getSeqNum()); - // Set whether or not this is a calpha - List cAlphaGroup = new ArrayList(); - for (Atom currentAtom : atomsInThisGroup) { - // Update the structure - addAtomInfo(currentAtom, loopGroup, biojavaChain); - // Update the calpha - updateCalpha(cAlphaGroup, currentAtom); - // Increment the atom counter - atomCounter+=1; - } - // Now add this group - if there is something to consider - addCalphaGroup(cAlphaGroup, props, residueNum); - } - // Increment again by one - chainCounter+=1; - } - } - // Set this final information in the total datastruct - bioStruct.setGroupList(bioStructList); - bioStruct.setGroupMap(bioStructMap); - calphaStruct.setGroupMap(calphaHashCodeToGroupMap); - // Now set this header info - headerStruct.setNumBonds(bondCounter+bioStruct.getInterGroupBondInds().size()); - headerStruct.setNumAtoms(atomCounter); - headerStruct.setNumChains(chainCounter); - headerStruct.setPdbCode(inputBiojavaStruct.getPDBCode()); - } - - - /** - * Find and store the entity information in the header structure. - * @param bioJavaStruct - */ - private final void findEntityInfo(Structure bioJavaStruct) { - List entities = bioJavaStruct.getEntityInfos(); - // Get the list of chains for all the models - List structChains = new ArrayList<>(); - for (int i=0; i < bioJavaStruct.nrModels(); i++) { - structChains.addAll(bioJavaStruct.getChains(i)); - } - Entity[] entityList = new Entity[entities.size()]; - int entityCounter = 0; - for(EntityInfo entityInfo : entities) { - Entity newEntity = new Entity(); - // Get the indices for the chains in this guy - List entChains = entityInfo.getChains(); - int[] indexList = new int[entChains.size()]; - int counter = 0; - for(Chain entChain : entChains) { - int indexChain = structChains.indexOf(entChain); - indexList[counter] = indexChain; - counter++; - } - newEntity.setChainIndexList(indexList); - newEntity.setDescription(entityInfo.getDescription()); - newEntity.setType(entityInfo.getType().toString()); - if (entityInfo.getChains().size()==0){ - newEntity.setSequence(""); - } - else { - newEntity.setSequence(entityInfo.getChains().get(0).getSeqResSequence()); - } - entityList[entityCounter] = newEntity; - entityCounter++; - } - headerStruct.setEntityList(entityList); - } - - - /** - * Adds the calpha group. - * @param cAlphaGroup the c alpha group - * @param props the props - * @param residueNum the residue number Biojava objext - * @param singleLetterCode the single letter code - */ - private void addCalphaGroup(List cAlphaGroup,SecStrucState props, ResidueNumber residueNum) { - // Generate a variable of the residue number - int thisResNum; - if(cAlphaGroup.size()>0){ - calphaGroupsPerChain[chainCounter] = calphaGroupsPerChain[chainCounter]+1; - List calphaAtomInfo = getGroupData(cAlphaGroup); - /// Now consider the C-Alpha, phosophate and ligand cases - int calphaHashCode = getHashFromStringList(calphaAtomInfo); - // If we need bioStruct new information - if (hashToCalphaRes.containsKey(calphaHashCode)==false){ - // Make a new group - PDBGroup outGroup = new PDBGroup(); - outGroup.setSingleLetterCode(currentGroup.getChemComp().getOne_letter_code().charAt(0)); - // Set the chemical component type. - outGroup.setChemCompType(currentGroup.getChemComp().getType()); - outGroup.setGroupName(calphaAtomInfo.remove(0)); - outGroup.setAtomNameList(calphaAtomInfo); - // Now get the bond list (lengths, orders and indices) and atom charges - List bondIndices = new ArrayList(); - List bondOrders = new ArrayList(); - List atomCharges = new ArrayList(); - for(Atom a : cAlphaGroup){ - atomCharges.add((int) a.getCharge()); - List thisAtomBonds = a.getBonds(); - if(thisAtomBonds!=null){ - for (Bond b: thisAtomBonds) { - // Get the index - int thisInd = cAlphaGroup.indexOf(a); - int otherInd = cAlphaGroup.indexOf(b.getOther(a)); - if(otherInd!=-1){ - if(thisInd inputAtomData, Atom inputAtom) { - // Check if it is a calpha - if (inputAtom.getName().equals("CA") && inputAtom.getElement().toString().equals("C")){ - // Now add the calpha - inputAtomData.add(inputAtom); - } - // Check if it is a phosphate - else if(inputAtom.getName().equals("P")){ - inputAtomData.add(inputAtom); - } - // Check if it is a ligand - else if(currentGroup.isWater()==false && currentGroup.getType().name().equals("HETATM")){ - inputAtomData.add(inputAtom); - } - } - - - /** - * Add a calpha atom to the C-alpha structure. - * @param inputAtom the input atom data. - * @param secondaryStructureInfo the secondary structure information (DSSP) for the group this atom is related to. - * @param residueNumber the residue number of the group this atom is part of. - */ - private void addCalpha(Atom inputAtom, SecStrucState secondaryStructureInfo, ResidueNumber residueNumber) { - // Set the number of atoms in the group - calphaStruct.setNumAtoms(calphaStruct.getNumAtoms()+1); - // Covert the cooridnates for this group - calphaStruct.getCartn_x().add((int) Math.round(inputAtom.getX()*MmtfBean.COORD_DIVIDER)); - calphaStruct.getCartn_y().add((int) Math.round(inputAtom.getY()*MmtfBean.COORD_DIVIDER)); - calphaStruct.getCartn_z().add((int) Math.round(inputAtom.getZ()*MmtfBean.COORD_DIVIDER)); - // Get the residue name - calphaStruct.get_atom_site_auth_seq_id().add(residueNumber.getSeqNum()); - calphaStruct.get_atom_site_label_entity_poly_seq_num().add(residueNumber.getSeqNum()); - // Now set the sec structure - if(secondaryStructureInfo==null){ - calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString("NA").getDsspIndex()); - } - else{ - calphaStruct.getSecStruct().add(DsspType.dsspTypeFromString(secondaryStructureInfo.getType().name).getDsspIndex()); - } - } - - - /** - * Find and store the atomic charge information. - * @param inputAtoms the atoms being coisdered. - * @param pdbGroup the PDBGroup to be modified. - * @return the atomic charges - */ - private void getCharges(List inputAtoms, PDBGroup pdbGroup) { - for(Atom a: inputAtoms){ - pdbGroup.getAtomChargeList().add((int) a.getCharge()); - } - - } - - - /** - * Find a unique hash code from a list of strings. - * Multiplies the hashcode of each string in the list by a prime number. - * Finds the product of this. - * @param inputStrings the input strings - * @return the integer hashcode from this string list - */ - private int getHashFromStringList(List inputStrings){ - // A prime number need for multiplication. - int prime = 31; - // The starting number - int result = 1; - for( String s : inputStrings ) - { - result = result * prime + s.hashCode(); - } - return result; - } - - - - - /** - * Get the atomic information from a list of Atoms. - * @param atomList the input atom list. - * @return a string list of atomic info comprising the element and name (in pairs) of - * each atom in the input list. - */ - private List getGroupData(List atomList){ - int numAtoms = atomList.size(); - int arraySize = numAtoms*2+2; - List outString = new ArrayList(arraySize); - // Get the group name - outString.add(atomList.get(0).getGroup().getPDBName()); - for (Atom a: atomList){ - outString.add(a.getElement().toString()); - outString.add(a.getName()); - } - return outString; - } - - - /** - * Finds the atoms between groups in a given input list of atoms - * @param inputAtomsInThisGroup the atoms in the group being considered - * @param totAtoms the total list of atoms across the whole structure. - */ - private void getInterGroupBond(List inputAtomsInThisGroup, List totAtoms){ - // Get the atoms - for (Atom currentAtom : inputAtomsInThisGroup) { - // Get the atom - List currentAtomBonds = currentAtom.getBonds(); - if(currentAtomBonds!=null){ - for (Bond currentBond: currentAtomBonds) { - Atom other = currentBond.getOther(currentAtom); - int index = inputAtomsInThisGroup.indexOf(other); - int order = currentBond.getBondOrder(); - if (index<0 || index >= totAtoms.size()){ - // Get the index of hte atom ins the total list - int newInd = totAtoms.indexOf(other); - if(newInd > -1){ - // Check if it exists in tot bonds - if(totBonds.indexOf(currentBond)!=-1){ - continue; - } - // Otherwise add it to the list - totBonds.add(currentBond); - // Then add this inter group bond - bioStruct.getInterGroupBondInds().add(newInd); - bioStruct.getInterGroupBondInds().add(totAtoms.indexOf(currentAtom)); - bioStruct.getInterGroupBondOrders().add(order); - } - } - } - } - - } - } - - /** - * Creates the bond list for a given PDBGroup object. - * @param inputAtoms a list of atoms in the group - * @param pdbGroup a PDBGroup object to update the information to - */ - private void createBondList(List inputAtoms, PDBGroup pdbGroup) { - int n = inputAtoms.size(); - if (n == 0) { - System.out.println("creating empty bond list"); - } - - // Lists to hold bond indices and orders - List bondList = new ArrayList(); - List bondOrder = new ArrayList(); - - List> totalBondList = new ArrayList>(); - - for (int i = 0; i < n; i++) { - // Get the atom - Atom a = inputAtoms.get(i); - List thisAtomBonds = a.getBonds(); - if(thisAtomBonds!=null){ - for (Bond b: thisAtomBonds) { - Atom other = b.getOther(a); - int index = inputAtoms.indexOf(other); - int order = b.getBondOrder(); - // Now build this to check if the indices - List thisArr = new ArrayList(); - thisArr.add(index); - thisArr.add(i); - Collections.sort(thisArr); - // Now check if we've done it - if(totalBondList.contains(thisArr)){ - continue; - } - if (index != -1) { - // Add the information - bondList.add(index); - bondList.add(i); - bondOrder.add(order); - } - totalBondList.add(thisArr); - } - } - } - pdbGroup.setBondOrderList(bondOrder); - pdbGroup.setBondAtomList(bondList); - } - - - /** - * Add the information for a given atom to the overall structure. - * @param inputAtom the atom to be added - * @param inputGroup the group to be added - * @param inputChain the chain to be added - */ - private void addAtomInfo(Atom inputAtom, Group inputGroup, Chain inputChain) { - bioStruct.get_atom_site_id().add(inputAtom.getPDBserial()); - // Atom symbol - Element ele = inputAtom.getElement(); - bioStruct.get_atom_site_symbol().add(ele.toString()); - bioStruct.get_atom_site_asym_id().add(inputChain.getChainID()); - // identify coordinate records (e.g. ATOM or HETATM). - bioStruct.get_atom_site_group_PDB().add(GroupType.groupTypeFromString(inputAtom.getGroup().getType().toString()).getGroupType()); - // bioStruct item is a uniquely identifies for each alternative site for - // bioStruct atom position. - if (inputAtom.getAltLoc()==" ".charAt(0)){ - bioStruct.get_atom_site_label_alt_id().add(null); - } - else{ - bioStruct.get_atom_site_label_alt_id().add(inputAtom.getAltLoc().toString()); - } - // bioStruct data item is reference to item _struct_asym.id defined in - // category STRUCT_ASYM. bioStruct item identifies an instance of - // particular entity in the deposited coordinate set. For a - // structure determined by crystallographic method bioStruct corresponds - // to a unique identifier within the cyrstallographic asymmetric - // unit. - bioStruct.get_atom_site_label_asym_id().add(inputChain.getInternalChainID().toString()); - // bioStruct data item is a reference to item _chem_comp_atom.atom_id - // defined in category CHEM_COMP_ATOM which is stored in the - // Chemical Component Dictionary. bioStruct atom identifier uniquely - // identifies each atom within each chemical component. - bioStruct.get_atom_site_label_atom_id().add(inputAtom.getName()); - // bioStruct data item is a reference to item _chem_comp.id defined in - // category CHEM_COMP. bioStruct item is the primary identifier for - // chemical components which may either be mononers in a polymeric - // entity or complete non-polymer entities. - bioStruct.get_atom_site_label_comp_id().add(inputAtom.getGroup().getPDBName()); - // bioStruct data item is a reference to _entity.id defined in the ENTITY - // category. bioStruct item is used to identify chemically distinct - // portions of the molecular structure (e.g. polymer chains, - // ligands, solvent). - bioStruct.get_atom_site_label_entity_id().add(GroupType.groupTypeFromString(inputAtom.getGroup().getType().toString()).getGroupType()); - // bioStruct data item is a reference to _entity_poly_seq.num defined in - // the ENTITY_POLY_SEQ category. bioStruct item is used to maintain the - // correspondence between the chemical sequence of a polymeric - // entity and the sequence information in the coordinate list and in - // may other structural categories. bioStruct identifier has no meaning - // for non-polymer entities. - bioStruct.get_atom_site_label_entity_poly_seq_num().add(inputGroup.getResidueNumber().getSeqNum()); - // Cartesian coordinate components describing the position of bioStruct - // atom site. - bioStruct.get_atom_site_Cartn_x().add(inputAtom.getX()); - bioStruct.get_atom_site_Cartn_y().add(inputAtom.getY()); - bioStruct.get_atom_site_Cartn_z().add(inputAtom.getZ()); - // Isotropic atomic displacement parameter - bioStruct.get_atom_site_B_iso_or_equiv().add(inputAtom.getTempFactor()); - // The fraction of the atom present at bioStruct atom position. - bioStruct.get_atom_site_occupancy().add(inputAtom.getOccupancy()); - // The net integer charge assigned to bioStruct atom. - } -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java deleted file mode 100644 index 955cb28..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/BiojavaUtils.java +++ /dev/null @@ -1,337 +0,0 @@ -package org.rcsb.mmtf.biojavaencoder; - -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.vecmath.Matrix4d; - -import org.rcsb.mmtf.dataholders.BioAssemblyData; -import org.rcsb.mmtf.dataholders.BioAssemblyTrans; -import org.rcsb.mmtf.dataholders.HeaderBean; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.JournalArticle; -import org.biojava.nbio.structure.PDBCrystallographicInfo; -import org.biojava.nbio.structure.PDBHeader; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; -import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; -import org.biojava.nbio.structure.secstruc.DSSPParser; -import org.biojava.nbio.structure.secstruc.SecStrucCalc; -import org.biojava.nbio.structure.xtal.CrystalCell; -import org.biojava.nbio.structure.xtal.SpaceGroup; - -/** - * A utils class of functions needed for Biojava. - * @author Anthony Bradley - * - */ -public class BiojavaUtils { - /** - * Set up the configuration parameters for BioJava. - */ - public AtomCache setUpBioJava() { - // Set up the atom cache etc - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - params.setUseInternalChainId(true); - CustomChemCompProvider cc = new CustomChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(cc); - cc.checkDoFirstInstall(); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - return cache; - } - - /** - * Set up the configuration parameters for BioJava. - with an extra URL - */ - public AtomCache setUpBioJava(String extraUrl) { - // Set up the atom cache etc - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - params.setUseInternalChainId(true); - CustomChemCompProvider cc = new CustomChemCompProvider(extraUrl); - ChemCompGroupFactory.setChemCompProvider(cc); - cc.checkDoFirstInstall(); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - return cache; - } - - - /** - * This sets all microheterogeneous groups (previously alternate location groups) as separate groups. - * @param bioJavaStruct - */ - public final void fixMicroheterogenity(Structure bioJavaStruct) { - // Loop through the models - for (int i=0; i chains = bioJavaStruct.getModel(i); - for (Chain c : chains) { - // Build a new list of groups - List outGroups = new ArrayList<>(); - for (Group g : c.getAtomGroups()) { - List removeList = new ArrayList<>(); - for (Group altLoc : g.getAltLocs()) { - // Check if they are not equal -> microheterogenity - if(! altLoc.getPDBName().equals(g.getPDBName())) { - // Now add this group to the main list - removeList.add(altLoc); - } - } - // Add this group - outGroups.add(g); - // Remove any microhet alt locs - g.getAltLocs().removeAll(removeList); - // Add these microhet alt locs - outGroups.addAll(removeList); - } - c.setAtomGroups(outGroups); - } - } - } - - /** - * Function to get all the atoms in the strucutre as a list. - * - * @param bioJavaStruct the bio java struct - * @return the all atoms - */ - public final List getAllAtoms(Structure bioJavaStruct) { - // Get all the atoms - List theseAtoms = new ArrayList(); - for (int i=0; i chains = bioJavaStruct.getModel(i); - for (Chain c : chains) { - for (Group g : c.getAtomGroups()) { - for(Atom a: getAtomsForGroup(g)){ - theseAtoms.add(a); - } - } - } - } - return theseAtoms; - } - - /** - * Function to get a list of atoms for a group. - * - * @param inputGroup the Biojava Group to consider - * @return the atoms for the input Biojava Group - */ - public final List getAtomsForGroup(Group inputGroup) { - Set uniqueAtoms = new HashSet(); - List theseAtoms = new ArrayList(); - for(Atom a: inputGroup.getAtoms()){ - theseAtoms.add(a); - uniqueAtoms.add(a); - } - List altLocs = inputGroup.getAltLocs(); - for(Group thisG: altLocs){ - for(Atom a: thisG.getAtoms()){ - if(uniqueAtoms.contains(a)){ - continue; - } - theseAtoms.add(a); - } - } - return theseAtoms; - } - - - /** - * Function to generate the secondary structure for a Biojava structure object. - * @param bioJavaStruct the Biojava structure for which it is to be calculate. - */ - public void calculateDsspSecondaryStructure(Structure bioJavaStruct) { - SecStrucCalc ssp = new SecStrucCalc(); - try{ - ssp.calculate(bioJavaStruct, true); - } - catch(StructureException e) { - try{ - DSSPParser.fetch(bioJavaStruct.getPDBCode(), bioJavaStruct, true); //download from PDB the DSSP result - } - catch(FileNotFoundException enew){ - } - catch(Exception bige){ - System.out.println(bige); - } - } - - } - - /** - * Adds the header information to a HeaderBean from a biojava structure object. - * @param bioJavaStruct the input Biojava structure - * @param headerStruct the input headerbean object - */ - public void setHeaderInfo(Structure bioJavaStruct, HeaderBean headerStruct) { - headerStruct.setPdbCode(bioJavaStruct.getPDBCode()); - // Now get hte xtalographic info - PDBCrystallographicInfo xtalInfo = bioJavaStruct.getCrystallographicInfo(); - CrystalCell xtalCell = xtalInfo.getCrystalCell(); - SpaceGroup spaceGroup = xtalInfo.getSpaceGroup(); - float[] inputUnitCell = new float[6]; - if(xtalCell==null){ - - }else{ - headerStruct.setUnitCell(inputUnitCell); - inputUnitCell[0] = (float) xtalCell.getA(); - inputUnitCell[1] = (float) xtalCell.getB(); - inputUnitCell[2] = (float) xtalCell.getC(); - inputUnitCell[3] = (float) xtalCell.getAlpha(); - inputUnitCell[4] = (float) xtalCell.getBeta(); - inputUnitCell[5] = (float) xtalCell.getGamma(); - if(spaceGroup==null){ - // This could be the I21 shown here - headerStruct.setSpaceGroup("NA"); - } - else{ - headerStruct.setSpaceGroup(spaceGroup.getShortSymbol()); - } - } - // GET THE HEADER INFORMATION - PDBHeader header = bioJavaStruct.getPDBHeader(); - List outMap = generateSerializableBioAssembly(bioJavaStruct, header); - headerStruct.setBioAssembly(outMap); - headerStruct.setTitle(header.getTitle()); - headerStruct.setDescription(header.getDescription()); - headerStruct.setClassification(header.getClassification()); - headerStruct.setDepDate(header.getDepDate()); - //headerStruct.setReleaseDate(header.getReleaseDate()); - headerStruct.setModDate(header.getModDate()); - headerStruct.setResolution(header.getResolution()); - headerStruct.setrFree(header.getRfree()); - - JournalArticle myJournal = header.getJournalArticle(); - if( myJournal==null){ - - } - else{ - headerStruct.setDoi(myJournal.getDoi()); - } - } - - /** - * Generate a serializable biotransformation for storing - * in the messagepack. - * @param bioJavaStruct the Biojava structure - * @param header the header - * @return a map of the bioassembly information that is serializable - */ - private List generateSerializableBioAssembly(Structure bioJavaStruct, PDBHeader header) { - // Get a map to reference asym ids to chains - Map chainIdToIndexMap = getChainIdToIndexMap(bioJavaStruct); - // Here we need to iterate through and get the chain ids and the matrices - Map inputBioAss = header.getBioAssemblies(); - List outMap = new ArrayList(); - for (Map.Entry entry : inputBioAss.entrySet()) { - Map matSet = new HashMap(); - BioAssemblyInfo value = entry.getValue(); - // Make a new one of these - BioAssemblyData newValue = new BioAssemblyData(); - outMap.add(newValue); - // Copy across this info - List outTrans = new ArrayList(); - for(BiologicalAssemblyTransformation transform: value.getTransforms()){ - // Get's the chain id -> this is the asym id - String thisChain = transform.getChainId(); - // Get the current matrix 4d - Matrix4d currentTransMat = transform.getTransformationMatrix(); - double[] outList = new double[16]; - // Iterate over the matrix - for(int i=0; i<4; i++){ - for(int j=0; j<4; j++){ - // Now set this element - outList[i*4+j] = currentTransMat.getElement(i,j); - } - } - if(matSet.containsKey(currentTransMat)){ - // Get the trasnformation - BioAssemblyTrans bioTransNew = matSet.get(currentTransMat); - // Add this chain index to that list - int[] oldList = bioTransNew.getChainIndexList(); - int oldLen = oldList.length; - int[] newList = new int[oldLen+1]; - for (int i=0; i getChainIdToIndexMap(Structure bioJavaStruct) { - // First build a map of asymid -> chain index - Map chainIdToIndexMapOne = new HashMap<>(); - int chainCounter = 0; - for (int i=0; i protectedIDs = new ArrayList (); - static { - protectedIDs.add("CON"); - protectedIDs.add("PRN"); - protectedIDs.add("AUX"); - protectedIDs.add("NUL"); - } - - /** by default we will download only some of the files. User has to request that all files should be downloaded... - * - */ - boolean downloadAll = false; - public CustomChemCompProvider(){ - logger.debug("Initialising DownloadChemCompProvider"); - extraServerLocation = null; - - // note that path is static, so this is just to make sure that all non-static methods will have path initialised - initPath(); - } - public CustomChemCompProvider(String extraUrl){ - logger.debug("Initialising DownloadChemCompProvider"); - extraServerLocation = extraUrl; - - // note that path is static, so this is just to make sure that all non-static methods will have path initialised - initPath(); - } - - public CustomChemCompProvider(String cacheFilePath, String extraUrl){ - logger.debug("Initialising DownloadChemCompProvider"); - - // note that path is static, so this is just to make sure that all non-static methods will have path initialised - path = new File(cacheFilePath); - extraServerLocation = extraUrl; - } - - private static void initPath(){ - - if (path==null) { - UserConfiguration config = new UserConfiguration(); - path = new File(config.getCacheFilePath()); - } - } - - /** - * Checks if the chemical components already have been installed into the PDB directory. - * If not, will download the chemical components definitions file and split it up into small - * subfiles. - */ - public void checkDoFirstInstall(){ - - if ( ! downloadAll ) { - return; - } - - - // this makes sure there is a file separator between every component, - // if path has a trailing file separator or not, it will work for both cases - File dir = new File(path, CHEM_COMP_CACHE_DIRECTORY); - File f = new File(dir, "components.cif.gz"); - - if ( ! f.exists()) { - - downloadAllDefinitions(); - - } else { - // file exists.. did it get extracted? - - FilenameFilter filter =new FilenameFilter() { - - @Override - public boolean accept(File dir, String file) { - return file.endsWith(".cif.gz"); - } - }; - String[] files = dir.list(filter); - if ( files.length < 500) { - // not all did get unpacked - try { - split(); - } catch (IOException e) { - logger.error("Could not split file {} into individual chemical component files. Error: {}", - f.toString(), e.getMessage()); - } - } - } - } - - private void split() throws IOException { - - logger.info("Installing individual chem comp files ..."); - - File dir = new File(path, CHEM_COMP_CACHE_DIRECTORY); - File f = new File(dir, "components.cif.gz"); - - - int counter = 0; - InputStreamProvider prov = new InputStreamProvider(); - - try( BufferedReader buf = new BufferedReader (new InputStreamReader (prov.getInputStream(f))); - ) { - String line = null; - line = buf.readLine (); - StringWriter writer = new StringWriter(); - - String currentID = null; - while (line != null){ - - if ( line.startsWith("data_")) { - // a new record found! - - if ( currentID != null) { - writeID(writer.toString(), currentID); - counter++; - } - - currentID = line.substring(5); - writer = new StringWriter(); - } - - writer.append(line); - writer.append(NEWLINE); - - line = buf.readLine (); - } - - // write the last record... - writeID(writer.toString(),currentID); - counter++; - - } - - logger.info("Created " + counter + " chemical component files."); - } - - /** - * Output chemical contents to a file - * @param contents File contents - * @param currentID Chemical ID, used to determine the filename - * @throws IOException - */ - private void writeID(String contents, String currentID) throws IOException{ - - String localName = DownloadChemCompProvider.getLocalFileName(currentID); - - try ( PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(localName))) ) { - - pw.print(contents.toString()); - pw.flush(); - } - } - - /** - * Loads the definitions for this {@link ChemComp} from a local file and instantiates a new object. - * - * @param recordName the ID of the {@link ChemComp} - * @return a new {@link ChemComp} definition. - */ - @Override - public ChemComp getChemComp(String recordName) { - - // make sure we work with upper case records - recordName = recordName.toUpperCase().trim(); - - boolean haveFile = true; - if ( recordName.equals("?")){ - return null; - } - - if ( ! fileExists(recordName)) { - // check if we should install all components - checkDoFirstInstall(); - } - if ( ! fileExists(recordName)) { - // we previously have installed already the definitions, - // just do an incrememntal update - haveFile = downloadChemCompRecord(recordName); - } - - // Added check that download was successful and chemical component is available. - if (haveFile) { - String filename = getLocalFileName(recordName); - InputStream inStream = null; - try { - - InputStreamProvider isp = new InputStreamProvider(); - - inStream = isp.getInputStream(filename); - - MMcifParser parser = new SimpleMMcifParser(); - - ChemCompConsumer consumer = new ChemCompConsumer(); - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - ChemicalComponentDictionary dict = consumer.getDictionary(); - - ChemComp chemComp = dict.getChemComp(recordName); - - return chemComp; - - } catch (IOException e) { - - logger.error("Could not parse chemical component file {}. Error: {}. " - + "There will be no chemical component info available for {}", filename, e.getMessage(), recordName); - - } - finally{ - // Now close it - if(inStream!=null){ - try { - inStream.close(); - } catch (IOException e) { - // This would be weird... - logger.error("Could not close chemical component file {}. A resource leak could occur!!", filename); - } - } - - } - } - - // see https://github.com/biojava/biojava/issues/315 - // probably a network error happened. Try to use the ReducedChemCOmpProvider - ReducedChemCompProvider reduced = new ReducedChemCompProvider(); - - return reduced.getChemComp(recordName); - - } - - /** Returns the file name that contains the definition for this {@link ChemComp} - * - * @param recordName the ID of the {@link ChemComp} - * @return full path to the file - */ - public static String getLocalFileName(String recordName){ - - if ( protectedIDs.contains(recordName)){ - recordName = "_" + recordName; - } - - initPath(); - - File f = new File(path, CHEM_COMP_CACHE_DIRECTORY); - if (! f.exists()){ - logger.info("Creating directory " + f); - - boolean success = f.mkdir(); - // we've checked in initPath that path is writable, so there's no need to check if it succeeds - // in the unlikely case that in the meantime it isn't writable at least we log an error - if (!success) logger.error("Directory {} could not be created",f); - - } - - File theFile = new File(f,recordName + ".cif.gz"); - - return theFile.toString(); - } - - private static boolean fileExists(String recordName){ - - String fileName = getLocalFileName(recordName); - - File f = new File(fileName); - - return f.exists(); - - } - - /** - * @param recordName : three-letter name - * @return true if successful download - */ - private static boolean downloadChemCompRecord(String recordName) { - - String localName = getLocalFileName(recordName); - File newFile; - try{ - newFile = File.createTempFile("chemcomp"+recordName, "cif"); - } - catch(IOException e){ - logger.error("Could not write to temp directory {} to create the chemical component download temp file", System.getProperty("java.io.tmpdir")); - return false; - } - // If there is no input server - just leave - if (extraServerLocation == null) { - return false; - } - String inputUrl = extraServerLocation + recordName.charAt(0) + "/" + recordName + "/" + recordName + ".cif"; - - logger.debug("downloading " + inputUrl); - - URL url = null; - - - try { - url = new URL(inputUrl); - - HttpURLConnection uconn = HTTPConnectionTools.openHttpURLConnection(url); - - try( PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(newFile))); - BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(uconn.getInputStream())); - ) { - - String line; - - while ((line = fileBuffer.readLine()) != null) { - pw.println(line); - } - - pw.flush(); - // Now we move this across to where it actually wants to be - boolean couldRename = newFile.renameTo(new File(localName)); - - if (!couldRename) { - - throw new IOException("Could not rename temp file "+newFile.toString()+" to file " + localName); - } - - return true; - } - } catch (IOException e){ - logger.error("Could not download "+url.toString()+" OR store locally to "+localName+" Error ="+e.getMessage()); - newFile.delete(); - } - return false; - } - - private void downloadAllDefinitions() { - - if ( loading.get()){ - logger.info("Waiting for other thread to install chemical components..."); - } - - while ( loading.get() ) { - - // another thread is already downloading the components definitions - // wait for the other thread to finish... - - try { - // wait half a second - - Thread.sleep(500); - } catch (InterruptedException e) { - //e.printStackTrace(); - logger.error("Thread interrupted "+e.getMessage()); - } - - logger.info("Another thread installed the chemical components."); - return; - - } - - loading.set(true); - long timeS = System.currentTimeMillis(); - - logger.info("Performing first installation of chemical components."); - logger.info("Downloading components.cif.gz ..."); - - - try { - AllChemCompProvider.downloadFile(); - } catch (IOException e){ - logger.error("Could not download the all chemical components file. Error: {}. " - + "Chemical components information won't be available", e.getMessage()); - // no point in trying to split if the file could not be downloaded - loading.set(false); - return; - } - try { - split(); - } catch (IOException e) { - logger.error("Could not split all chem comp file into individual chemical component files. Error: {}", - e.getMessage()); - // no point in reporting time - loading.set(false); - return; - } - long timeE = System.currentTimeMillis(); - logger.info("time to install chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); - loading.set(false); - - } - - /** By default this provider will download only some of the {@link ChemComp} files. - * The user has to request that all files should be downloaded by setting this parameter to true. - * - * @return flag if the all components should be downloaded and installed at startup. (default: false) - */ - public boolean isDownloadAll() { - return downloadAll; - } - - /** By default this provider will download only some of the {@link ChemComp} files. - * The user has to request that all files should be downloaded by setting this parameter to true. - * - * @param flag if the all components should be downloaded and installed at startup. (default: false) - */ - public void setDownloadAll(boolean downloadAll) { - this.downloadAll = downloadAll; - } - - - - -} - diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java deleted file mode 100644 index 6f3d28f..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/GroupType.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.rcsb.mmtf.biojavaencoder; - -/** - * An enum to specify the group type of a PDBGroup. - * @author Anthony Bradley - */ -public enum GroupType { - - HETATM("hetatm","HEATM"), - AMINO("amino","ATOM"), - NUCLEOTIDE("nucleotide","ATOM"); - - private String groupType; - private String groupName; - - private GroupType(String groupName, String groupType) { - this.groupName = groupName; - this.groupType = groupType; - } - - /** - * @return the groupType - */ - public String getGroupType() { - return groupType; - } - - /** - * @return the groupName - */ - public String getGroupName() { - return groupName; - } - - public static GroupType groupTypeFromString(String groupType) - { - - if ( groupType == null) - return null; - - for(GroupType et : GroupType.values()) - { - if(groupType.equals(et.groupName)) - { - return et; - } - } - // Return a null entry. - return null; - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/package-info.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/package-info.java deleted file mode 100644 index cad8d86..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biojavaencoder/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * The core package to encode a structure to MMTF - * @author Anthony Bradley - * - */ -package org.rcsb.mmtf.biojavaencoder; \ No newline at end of file diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBiojavaUtils.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBiojavaUtils.java deleted file mode 100644 index 113a936..0000000 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBiojavaUtils.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.rcsb.mmtf.biojavaencoder; - - -import org.junit.Test; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; - -public class TestBiojavaUtils { - - private BiojavaUtils biojavaUtils = new BiojavaUtils(); - - - /** - * Integration test to see that the microheterogenity is being dealt with correctly. - * @throws IOException - * @throws StructureException - */ - @Test - public void microHeterogenity() throws IOException, StructureException { - biojavaUtils.setUpBioJava(); - Structure inputStructure = StructureIO.getStructure("4ck4"); - // Count the number of groups - Group before = inputStructure.getChains().get(0).getAtomGroup(17); - assertTrue(inputStructure.getChains().get(0).getAtomGroup(17).hasAltLoc()); - List totalAtoms = new ArrayList<>(biojavaUtils.getAllAtoms(inputStructure)); - int totGroups = 0; - int totAtomsCounter = 0; - Set totAtoms = new HashSet<>(); - for (Chain c : inputStructure.getChains()) { - totGroups += c.getAtomGroups().size(); - for (Group g: c.getAtomGroups() ){ - totAtomsCounter+=g.getAtoms().size(); - totAtoms.addAll(g.getAtoms()); - for (Group alt : g.getAltLocs()) { - totAtomsCounter+=alt.getAtoms().size(); - totAtoms.addAll(alt.getAtoms()); - } - } - } - // Now "fix" the microheterogenity - biojavaUtils.fixMicroheterogenity(inputStructure); - assertEquals(before, inputStructure.getChains().get(0).getAtomGroup(17)); - assertFalse(inputStructure.getChains().get(0).getAtomGroup(17).hasAltLoc()); - assertFalse(inputStructure.getChains().get(0).getAtomGroup(18).hasAltLoc()); - int totGroupsAfter = 0; - int totAtomsCounterAfter = 0; - Set totAtomsAfter = new HashSet<>(); - for (Chain c : inputStructure.getChains()) { - totGroupsAfter += c.getAtomGroups().size(); - for (Group g: c.getAtomGroups() ){ - totAtomsCounterAfter+=g.getAtoms().size(); - totAtomsAfter.addAll(g.getAtoms()); - for (Group alt : g.getAltLocs()) { - totAtomsAfter.addAll(alt.getAtoms()); - totAtomsCounterAfter+=alt.getAtoms().size(); - } - } - } - // Find the atoms after the fix. - List totalAtomsAfter = new ArrayList<>(biojavaUtils.getAllAtoms(inputStructure)); - // Get all of the duplicate atoms - Set duplicates = findDuplicates(totalAtomsAfter); - for (Atom a : duplicates) { - System.out.println(a); - } - // There should be no duplicates - assertEquals(duplicates.size(), 0); - assertEquals(totalAtoms.size(), totalAtomsAfter.size()); - // Check there are two more groups afterwards - assertEquals(totGroupsAfter-2, totGroups); - // Check there are no more atoms afterwards - assertEquals(totAtomsAfter.size(), totAtoms.size()); - // Check the counter are the same too - assertEquals(totAtomsCounterAfter, totAtomsCounter); - - } - - -//TODO ADD TESTS FOR THESE FUNCTIONS -// getAllAtoms -// -// getAtomsForGroup -// -// calculateDsspSecondaryStructure -// -// setHeaderInfo -// -// generateSerializableBioAssembly -// -// getChainIdToIndexMap - - private Set findDuplicates(List listContainingDuplicates) - { - final Set setToReturn = new HashSet<>(); - final Set set1 = new HashSet<>(); - - for (Atom yourInt : listContainingDuplicates) - { - if (!set1.add(yourInt)) - { - setToReturn.add(yourInt); - } - } - return setToReturn; - } -} - diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java deleted file mode 100644 index 23580fc..0000000 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biojavaencoder/TestBondFinding.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.rcsb.mmtf.biojavaencoder; - -import org.junit.Test; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.List; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Bond; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; - -public class TestBondFinding { - - /** - * Test that the bonds we are finding is consistenty. - * @throws IOException - * @throws StructureException - */ - @Test - public void testInterGroupBonds() throws IOException, StructureException { - // Normal - assertEquals(getInterBonds("1QMZ"), 2236); - // Disulphide - assertEquals(getInterBonds("2QWO"), 956); - // Covalent ligand - assertEquals(getInterBonds("4QDV"), 2294); - // DNA - assertEquals(getInterBonds("4XSN"), 22); - - } - - public int getInterBonds(String pdbId) throws IOException, StructureException{ - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - cache.setFetchBehavior(FetchBehavior.FETCH_FILES); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - DownloadChemCompProvider dcc = new DownloadChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(dcc); - dcc.checkDoFirstInstall(); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - int counter =0; - // Now get the structure - Structure newStruc = StructureIO.getStructure(pdbId); - // Now loop through the atoms - for(Chain c: newStruc.getChains()){ - for(Group g: c.getAtomGroups()){ - List theseAtoms = g.getAtoms(); - for(Atom a: theseAtoms){ - List theseBonds = a.getBonds(); - if(theseBonds != null){ - for(Bond b: a.getBonds()){ - Atom other = b.getOther(a); - int indexOther = theseAtoms.indexOf(other); - // Check if the index is within the group - if(indexOther<0 || indexOther >= theseAtoms.size()){ - counter++; - } - } - } - } - } - } - return counter; - } -} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index b8c1173..2825547 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -2,23 +2,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNotEquals; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; + import org.junit.Test; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; -import org.rcsb.mmtf.encoder.EncoderInterface; import org.rcsb.mmtf.encoder.EncoderUtils; import org.unitils.reflectionassert.ReflectionAssert; @@ -27,30 +15,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import uk.co.jemos.podam.api.PodamFactory; -import uk.co.jemos.podam.api.PodamFactoryImpl; public class TestDataHolders { private EncoderUtils encoderUtils; private PodamFactory factory; - private AtomCache cache; - private FileParsingParameters params; public TestDataHolders() { - encoderUtils = new EncoderUtils(); - factory = new PodamFactoryImpl(); - cache = new AtomCache(); - cache.setUseMmCif(true); - cache.setFetchBehavior(FetchBehavior.FETCH_FILES); - params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - DownloadChemCompProvider dcc = new DownloadChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(dcc); - dcc.setDownloadAll(true); - dcc.checkDoFirstInstall(); - params.setUseInternalChainId(true); + } @Test @@ -58,7 +30,7 @@ public void testSerializable() throws JsonParseException, JsonMappingException, // MmtfBean assertTrue(testClass(MmtfBean.class)); // This one fails - make sure it still does - assertFalse(testClass(BioAssemblyInfo.class)); + assertFalse(testClass(BioAssemblyData.class)); // The bean to store calpha data assertTrue(testClass(CalphaDistBean.class)); // Now consider the no float data stucuture class @@ -69,8 +41,6 @@ public void testSerializable() throws JsonParseException, JsonMappingException, assertTrue(testClass(CalphaBean.class)); // Now test round tripping data testDataRoundTrip(MmtfBean.class); - // Now test if all fields in the mmtf are generated - testDataComplete("4cup"); // Now check that the failure bean fails this // Now test round tripping data assertFalse(testDataRoundTrip(FailureBean.class)); @@ -137,35 +107,6 @@ private boolean testDataRoundTrip(@SuppressWarnings("rawtypes") Class class1) t ReflectionAssert.assertReflectionEquals(inBean, outBean); return true; } - - /** - * A specific mmtf test - to make sure none of the fields are empty when the thing is encoded - * @throws StructureException - * @throws IOException - */ - private void testDataComplete(String pdbId) throws IOException { - - // Utility functions for encoding stuff - EncoderUtils eu = new EncoderUtils(); - // Get the utility class to get the structures - EncoderInterface parsedDataStruct = new BiojavaEncoderImpl(); - Map totMap = new HashMap(); - // Parse the data into the basic data structure - parsedDataStruct.generateDataStructuresFromPdbId(pdbId, totMap); - MmtfBean mmtfBean = null; - // Compress the data and get it back out - mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); - // Make sure all fields are re-populated - ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); - // Now check the standard ones have been set - assertNotEquals(mmtfBean.getResolution(), (float) -1.0); - assertNotEquals(mmtfBean.getrFree(), (float) -1.0); - // Check that these integer values are set - assertNotEquals(mmtfBean.getNumAtoms(), -1); - assertNotEquals(mmtfBean.getNumBonds(), -1); - // And finally - check this is working - assertNotEquals(mmtfBean.getMmtfProducer(), "NA"); - } } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java index 5cc16a7..fd43714 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java @@ -1,7 +1,11 @@ package org.rcsb.mmtf.integrationtest; +import static org.junit.Assert.assertNotEquals; + import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; @@ -9,8 +13,14 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.junit.Test; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; +import org.rcsb.mmtf.dataholders.BiojavaEncoderImpl; +import org.rcsb.mmtf.dataholders.EncoderInterface; +import org.rcsb.mmtf.dataholders.MmtfBean; +import org.rcsb.mmtf.dataholders.PDBGroup; +import org.rcsb.mmtf.encoder.EncoderUtils; import org.rcsb.mmtf.update.IntegrationTestUtils; import org.rcsb.mmtf.update.TestingUtils; +import org.unitils.reflectionassert.ReflectionAssert; /** * Tests to see if parsing using Biojava using mmCIF and mmtf produces the same data structure. @@ -48,5 +58,34 @@ public void testAuthChainIds() throws IOException, StructureException, IllegalAc StructureIO.setAtomCache(cache); testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); } + + /** + * A specific mmtf test - to make sure none of the fields are empty when the thing is encoded + * @throws StructureException + * @throws IOException + */ + private void testDataComplete(String pdbId) throws IOException { + + // Utility functions for encoding stuff + EncoderUtils eu = new EncoderUtils(); + // Get the utility class to get the structures + EncoderInterface parsedDataStruct = new BiojavaEncoderImpl(); + Map totMap = new HashMap(); + // Parse the data into the basic data structure + parsedDataStruct.generateDataStructuresFromPdbId(pdbId, totMap); + MmtfBean mmtfBean = null; + // Compress the data and get it back out + mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); + // Make sure all fields are re-populated + ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); + // Now check the standard ones have been set + assertNotEquals(mmtfBean.getResolution(), (float) -1.0); + assertNotEquals(mmtfBean.getrFree(), (float) -1.0); + // Check that these integer values are set + assertNotEquals(mmtfBean.getNumAtoms(), -1); + assertNotEquals(mmtfBean.getNumBonds(), -1); + // And finally - check this is working + assertNotEquals(mmtfBean.getMmtfProducer(), "NA"); + } } From d35310e21370c925ebf7bb374c9f088d14b7537f Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 07:16:13 -0700 Subject: [PATCH 059/108] Downstream refactoring of the update module. Altered the two serializer apis intio one interface. --- .../ByteArrayToObjectConverterInterface.java | 12 ----------- .../ObjectToByteArrayConverterInterface.java | 11 ---------- .../rcsb/mmtf/api/SerializerInterface.java | 20 +++++++++++++++++++ .../ByteArrayMessagePackConverter.java | 15 ++++++++++---- .../decoder/GetApiToInflatorInterface.java | 3 ++- .../java/org/rcsb/mmtf/examples/HandleIO.java | 6 +++--- .../mmtf/postupdatetests/CheckServer.java | 5 ++--- .../preupdatetests/DataConsistencyCheck.java | 5 ++--- .../org/rcsb/mmtf/testutils/CheckBonds.java | 7 +++---- .../org/rcsb/mmtf/update/TestingUtils.java | 1 - .../mmtf/integrationtest/TestParseMMCif.java | 13 +++--------- 11 files changed, 46 insertions(+), 52 deletions(-) delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java rename {mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder => mmtf-common/src/main/java/org/rcsb/mmtf/sedeserializers}/ByteArrayMessagePackConverter.java (68%) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java deleted file mode 100644 index ef14129..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/ByteArrayToObjectConverterInterface.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.rcsb.mmtf.api; - -public interface ByteArrayToObjectConverterInterface { - - /** - * Convert a byte array to an object to then be procesed. - * e.g. a messagepack byte array can be coverted to an MMTFBean. - * @param byteArray the input byte data - * @return the object with defined getters and setters - */ - Object convert(byte[] byteArray); -} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java deleted file mode 100644 index 1a2bf7c..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/ObjectToByteArrayConverterInterface.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.rcsb.mmtf.api; - -public interface ObjectToByteArrayConverterInterface { - - /** - * Convert an object to a byte array using reflection. - * @param object an object with getters and setters - * @return a byte array of the serialised object - */ - byte[] convert(Object object); -} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java new file mode 100644 index 0000000..db42c85 --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java @@ -0,0 +1,20 @@ +package org.rcsb.mmtf.api; + +public interface SerializerInterface { + + /** + * Convert a byte array to an object to then be procesed. + * e.g. a messagepack byte array can be coverted to an MMTFBean. + * @param byteArray the input byte data + * @return the object with defined getters and setters + */ + Object deserialize(byte[] byteArray); + + + /** + * Convert an object to a byte array using reflection. + * @param object an object with getters and setters + * @return a byte array of the serialised object + */ + byte[] serialize(Object object); +} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java b/mmtf-common/src/main/java/org/rcsb/mmtf/sedeserializers/ByteArrayMessagePackConverter.java similarity index 68% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java rename to mmtf-common/src/main/java/org/rcsb/mmtf/sedeserializers/ByteArrayMessagePackConverter.java index 48e19a4..99fffe4 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ByteArrayMessagePackConverter.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/sedeserializers/ByteArrayMessagePackConverter.java @@ -1,9 +1,9 @@ -package org.rcsb.mmtf.decoder; +package org.rcsb.mmtf.sedeserializers; import java.io.IOException; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.api.ByteArrayToObjectConverterInterface; +import org.rcsb.mmtf.api.SerializerInterface; import org.rcsb.mmtf.dataholders.MmtfBean; import com.fasterxml.jackson.databind.ObjectMapper; @@ -13,10 +13,10 @@ * @author Anthony Bradley * */ -public class ByteArrayMessagePackConverter implements ByteArrayToObjectConverterInterface { +public class ByteArrayMessagePackConverter implements SerializerInterface { @Override - public MmtfBean convert(byte[] byteArray) { + public MmtfBean deserialize(byte[] byteArray) { MmtfBean mmtfBean = null; try { mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(byteArray, MmtfBean.class); @@ -27,5 +27,12 @@ public MmtfBean convert(byte[] byteArray) { } return mmtfBean; } + + @Override + public byte[] serialize(MmtfBean mmtfBean) { + return new byte[0]; + + } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java index 58189e8..513b305 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetApiToInflatorInterface.java @@ -5,6 +5,7 @@ import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.api.MmtfDecoderInterface; +import org.rcsb.mmtf.sedeserializers.ByteArrayMessagePackConverter; /** * Decode an MMTF structure using a structure inflator. @@ -37,7 +38,7 @@ public class GetApiToInflatorInterface { */ public GetApiToInflatorInterface(byte[] byteArray) { // Create the instance of this API - dataApi = new BeanToGetApi(new ByteArrayMessagePackConverter().convert(byteArray)); + dataApi = new BeanToGetApi(new ByteArrayMessagePackConverter().deserialize(byteArray)); } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java index 05321d5..b218fd3 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java @@ -13,8 +13,8 @@ import java.util.zip.GZIPInputStream; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.decoder.ByteArrayMessagePackConverter; import org.rcsb.mmtf.decoder.BeanToGetApi; +import org.rcsb.mmtf.sedeserializers.ByteArrayMessagePackConverter; /** * Some helper functions and utility functions to get structures from BioJava. @@ -63,10 +63,10 @@ public final MmtfDecodedDataInterface getDataApiFromUrlOrFile(final String input boolean isFile = getFile(basePath, inputCode); // If it's a file on the file system - get it if (isFile) { - return new BeanToGetApi(new ByteArrayMessagePackConverter().convert(getFromFileSystem(basePath, inputCode))); + return new BeanToGetApi(new ByteArrayMessagePackConverter().deserialize(getFromFileSystem(basePath, inputCode))); } try { - return new BeanToGetApi(new ByteArrayMessagePackConverter().convert(getFromUrl(inputCode))); + return new BeanToGetApi(new ByteArrayMessagePackConverter().deserialize(getFromUrl(inputCode))); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index 2fa2a19..f3e9036 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -9,7 +9,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; -import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; +import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.examples.HandleIO; import org.rcsb.mmtf.testutils.CheckOnBiojava; import org.rcsb.mmtf.testutils.CheckOnRawApi; @@ -47,8 +47,7 @@ public void basicParsingTest(String baseUrl) throws IOException { // Get the class to parse and get data handleIo = new HandleIO(); checkEquiv = new CheckOnBiojava(); - BiojavaUtils biojavaUtils = new BiojavaUtils(); - AtomCache cache = biojavaUtils.setUpBioJava(); + AtomCache cache = MmtfUtils.setUpBioJava(); params = cache.getFileParsingParams(); // Test it for a series of structures for (String pdbId : IntegrationTestUtils.TEST_CASES) { diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java index da924ce..3fd4913 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java @@ -9,7 +9,7 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; +import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.update.ServerUtils; import org.rcsb.mmtf.update.TestingUtils; import org.rcsb.mmtf.update.WeeklyUpdateUtils; @@ -37,9 +37,8 @@ public static void main(String[] args) throws IllegalAccessException, Invocation // Set up the atom cache etc - BiojavaUtils biojavaUtils = new BiojavaUtils(); ServerUtils serverUtils = new ServerUtils(); - AtomCache cache = biojavaUtils.setUpBioJava(args[3]); + AtomCache cache = MmtfUtils.setUpBioJava(args[3]); // Now get the list of PDB ids to ignore List ignoreList = new ArrayList<>(); for (int i=4; i totMap = new HashMap(); - // Parse the data into the basic data structure - parsedDataStruct.generateDataStructuresFromPdbId(pdbId, totMap); + MmtfBean mmtfBean = null; // Compress the data and get it back out mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); From 7514650a35a9bf2ab786aab8baf1f666c4ce5977 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 07:32:29 -0700 Subject: [PATCH 060/108] Culling of all the data beans and moving around of tests. --- mmtf-common/pom.xml | 15 +- .../rcsb/mmtf/dataholders/FailureBean.java | 0 .../mmtf/dataholders/TestDataHolders.java | 8 - mmtf-encoder/pom.xml | 31 +- .../mmtf/biocompressors/BioCompressor.java | 18 - .../mmtf/biocompressors/CompressDoubles.java | 90 --- .../org/rcsb/mmtf/dataholders/BioBean.java | 10 - .../rcsb/mmtf/dataholders/BioDataStruct.java | 56 -- .../mmtf/dataholders/BioDataStructBean.java | 143 ---- .../org/rcsb/mmtf/dataholders/CalphaBean.java | 255 ------- .../rcsb/mmtf/dataholders/CalphaDistBean.java | 519 -------------- .../rcsb/mmtf/dataholders/CoreDataStruct.java | 54 -- .../mmtf/dataholders/CoreSingleStructure.java | 33 - .../org/rcsb/mmtf/dataholders/HeaderBean.java | 633 ------------------ .../mmtf/dataholders/NoCoordDataStruct.java | 408 ----------- .../mmtf/dataholders/NoFloatDataStruct.java | 53 -- .../dataholders/NoFloatDataStructBean.java | 143 ---- .../rcsb/mmtf/dataholders/package-info.java | 8 - .../org/rcsb/mmtf/encoder/EncoderUtils.java | 437 ------------ .../biocompressors/TestBioCompressor.java | 42 -- 20 files changed, 24 insertions(+), 2932 deletions(-) rename {mmtf-encoder => mmtf-common}/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java (100%) rename {mmtf-encoder => mmtf-common}/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java (89%) delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/BioCompressor.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioBean.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStruct.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaBean.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaDistBean.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreDataStruct.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreSingleStructure.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoCoordDataStruct.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStruct.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStructBean.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/package-info.java delete mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java delete mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java diff --git a/mmtf-common/pom.xml b/mmtf-common/pom.xml index 7ba2cbc..3a182dc 100644 --- a/mmtf-common/pom.xml +++ b/mmtf-common/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.rcsb @@ -16,6 +17,18 @@ + + org.unitils + unitils-core + 3.4.2 + test + + + uk.co.jemos.podam + podam + 2.3.5.RELEASE + test + org.msgpack jackson-dataformat-msgpack diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java similarity index 100% rename from mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java rename to mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java similarity index 89% rename from mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java rename to mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index 2825547..b028dad 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -31,14 +31,6 @@ public void testSerializable() throws JsonParseException, JsonMappingException, assertTrue(testClass(MmtfBean.class)); // This one fails - make sure it still does assertFalse(testClass(BioAssemblyData.class)); - // The bean to store calpha data - assertTrue(testClass(CalphaDistBean.class)); - // Now consider the no float data stucuture class - assertTrue(testClass(NoFloatDataStruct.class)); - // Now consider the no bio data structure bean - assertTrue(testClass(BioDataStructBean.class)); - // And the calpha bean - assertTrue(testClass(CalphaBean.class)); // Now test round tripping data testDataRoundTrip(MmtfBean.class); // Now check that the failure bean fails this diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index aaefcda..8dd669f 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.rcsb @@ -17,20 +18,15 @@ - commons-beanutils - commons-beanutils - 1.8.3 + org.rcsb + mmtf-common + 0.0.1-alpha4-SNAPSHOT org.rcsb - mmtf-common + mmtf-api 0.0.1-alpha4-SNAPSHOT - - org.rcsb - mmtf-api - 0.0.1-alpha4-SNAPSHOT - org.msgpack jackson-dataformat-msgpack @@ -61,19 +57,12 @@ org.apache.logging.log4j log4j-core - - org.unitils - unitils-core - 3.4.2 - test - - - uk.co.jemos.podam - podam - 2.3.5.RELEASE - test + commons-beanutils + commons-beanutils + 1.8.3 + diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/BioCompressor.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/BioCompressor.java deleted file mode 100644 index ef3c755..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/BioCompressor.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.rcsb.mmtf.biocompressors; - -import java.lang.reflect.InvocationTargetException; - -import org.rcsb.mmtf.dataholders.CoreSingleStructure; - -public interface BioCompressor { - - /** - * Generic function to modify the data structure of a protein to enhance compression - * @param coress - * @return The updated data structure - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public CoreSingleStructure compresStructure(CoreSingleStructure coress); - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java deleted file mode 100644 index 43ebbe5..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/biocompressors/CompressDoubles.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.rcsb.mmtf.biocompressors; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.beanutils.BeanUtils; -import org.rcsb.mmtf.dataholders.BioDataStruct; -import org.rcsb.mmtf.dataholders.CoreSingleStructure; -import org.rcsb.mmtf.dataholders.NoFloatDataStruct; - -/** - * Class to compress a structure by turning doubles to integers. - * @author Anthony Bradley - * - */ -public class CompressDoubles implements BioCompressor, Serializable { - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = -8942639615818134183L; - - /* (non-Javadoc) - * @see org.rcsb.mmtf.biocompressors.BioCompressor#compresStructure(org.rcsb.mmtf.dataholders.CoreSingleStructure) - */ - public final CoreSingleStructure compresStructure(CoreSingleStructure coress) { - // Take in the appropriate arrays - BioDataStruct bioDataS = (BioDataStruct) coress; - NoFloatDataStruct noFloatDataS = new NoFloatDataStruct(); - - try { - BeanUtils.copyProperties(noFloatDataS, bioDataS); - } catch (IllegalAccessException e) { - System.err.println("Unknown bug - copying bean data. Report as bug."); - e.printStackTrace(); - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - System.err.println("Unknown bug - copying bean data. Report as bug."); - e.printStackTrace(); - throw new RuntimeException(e); - } - // Get all the arrays we want to compress - // Set the coordinates - noFloatDataS.set_atom_site_Cartn_xInt(getIntArrayFromDouble(bioDataS.get_atom_site_Cartn_x(),1000.0)); - noFloatDataS.set_atom_site_Cartn_yInt(getIntArrayFromDouble(bioDataS.get_atom_site_Cartn_y(),1000.0)); - noFloatDataS.set_atom_site_Cartn_zInt(getIntArrayFromDouble(bioDataS.get_atom_site_Cartn_z(),1000.0)); - // Now set the temperature factors and occupancy - noFloatDataS.set_atom_site_B_iso_or_equivInt(getIntArrayFromFloat(bioDataS.get_atom_site_B_iso_or_equiv(),(float) 100.0)); - noFloatDataS.set_atom_site_occupancyInt(getIntArrayFromFloat(bioDataS.get_atom_site_occupancy(),(float) 100.0)); - // Now assign these to the new dataStructure - return noFloatDataS; - } - - /** - * Function to return an int array from a float array. - * - * @param inArray the input array of floats - * @param multiplier - the multiplication factor for conversion - * @return the integer array after conversion - */ - public final List getIntArrayFromFloat(List inArray, float multiplier) { - // Initialise the out array - List outArray = new ArrayList(inArray.size()); - for(Float oldDouble: inArray){ - Integer newInt = (int) Math.round(oldDouble * multiplier); - outArray.add(newInt); - } - return outArray; - - } - - /** - * Function to return an int array from a double array. - * - * @param inArray the input array of doubles - * @param multiplier the multiplier - * @return the int array from double - */ - public final List getIntArrayFromDouble(List inArray, Double multiplier){ - // Initialise the out array - List outArray = new ArrayList(inArray.size()); - for(Double oldDouble: inArray){ - Integer newInt = (int) Math.round(oldDouble * multiplier); - outArray.add(newInt); - } - return outArray; - - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioBean.java deleted file mode 100644 index 96d078c..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioBean.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -/** - * An interface to the basic data structure for a data structure - * @author Anthony Bradley - * - */ -public interface BioBean { - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStruct.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStruct.java deleted file mode 100644 index ee65e52..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStruct.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.rcsb.mmtf.dataholders; -import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.beanutils.BeanUtils; - -/** - * Class to store the basic biological data from an MMCIF file. - * - * @author Anthony Bradley - */ -public class BioDataStruct extends BioDataStructBean implements CoreSingleStructure { - - /** - * Instantiates a new bio data struct. - */ - public BioDataStruct() { - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.CoreSingleStructure#findDataAsBean() - */ - public BioDataStructBean findDataAsBean() { - // Cast this to the pure data - BioDataStructBean newData = new BioDataStructBean(); - try { - BeanUtils.copyProperties(newData, this); - } catch (IllegalAccessException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - return newData; - } - - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.CoreSingleStructure#findNumAtoms() - */ - public int findNumAtoms() { - return get_atom_site_Cartn_x().size(); - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.CoreSingleStructure#findStructureCode() - */ - @Override - public String findStructureCode() { - // Get the PDB code - return this.getPdbCode(); - } - - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java deleted file mode 100644 index 519356b..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/BioDataStructBean.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.util.ArrayList; -import java.util.List; - -/** - * A bean to store the information about the protein structure. - * - * @author Anthony Bradley - */ -public class BioDataStructBean extends NoCoordDataStruct implements BioBean { - - - // Coordinate infroramtion - /** The _atom_site_cartn_x. */ - protected List _atom_site_Cartn_x = new ArrayList(); - - /** The _atom_site_ cartn_y. */ - protected List _atom_site_Cartn_y = new ArrayList(); - - /** The _atom_site_ cartn_z. */ - protected List _atom_site_Cartn_z = new ArrayList(); - - /** The _atom_site_ b_iso_or_equiv. */ - // Isotropic atomic displacement parameter - protected List _atom_site_B_iso_or_equiv= new ArrayList(); - - /** The _atom_site_occupancy. */ - // The fraction of the atom present at this atom position_ - protected List _atom_site_occupancy= new ArrayList(); - - /** - * Gets the _atom_site_id. - * - * @return the _atom_site_id - */ - public List get_atom_site_id() { - return _atom_site_id; - } - - /** - * Sets the _atom_site_id. - * - * @param _atom_site_id the new _atom_site_id - */ - public void set_atom_site_id(List _atom_site_id) { - this._atom_site_id = _atom_site_id; - } - - /** The _atom_site_id. */ - private List _atom_site_id = new ArrayList(); - - /** - * Gets the _atom_site_ cartn_x. - * - * @return the _atom_site_ cartn_x - */ - public List get_atom_site_Cartn_x() { - return _atom_site_Cartn_x; - } - - /** - * Sets the _atom_site_ cartn_x. - * - * @param _atom_site_Cartn_x the new _atom_site_ cartn_x - */ - public void set_atom_site_Cartn_x(ArrayList _atom_site_Cartn_x) { - this._atom_site_Cartn_x = _atom_site_Cartn_x; - } - - /** - * Gets the _atom_site_ cartn_y. - * - * @return the _atom_site_ cartn_y - */ - public List get_atom_site_Cartn_y() { - return _atom_site_Cartn_y; - } - - /** - * Sets the _atom_site_ cartn_y. - * - * @param _atom_site_Cartn_y the new _atom_site_ cartn_y - */ - public void set_atom_site_Cartn_y(ArrayList _atom_site_Cartn_y) { - this._atom_site_Cartn_y = _atom_site_Cartn_y; - } - - /** - * Gets the _atom_site_ cartn_z. - * - * @return the _atom_site_ cartn_z - */ - public List get_atom_site_Cartn_z() { - return _atom_site_Cartn_z; - } - - /** - * Sets the _atom_site_ cartn_z. - * - * @param _atom_site_Cartn_z the new _atom_site_ cartn_z - */ - public void set_atom_site_Cartn_z(ArrayList _atom_site_Cartn_z) { - this._atom_site_Cartn_z = _atom_site_Cartn_z; - } - - /** - * Gets the _atom_site_ b_iso_or_equiv. - * - * @return the _atom_site_ b_iso_or_equiv - */ - public List get_atom_site_B_iso_or_equiv() { - return _atom_site_B_iso_or_equiv; - } - - /** - * Sets the _atom_site_ b_iso_or_equiv. - * - * @param _atom_site_B_iso_or_equiv the new _atom_site_ b_iso_or_equiv - */ - public void set_atom_site_B_iso_or_equiv(ArrayList _atom_site_B_iso_or_equiv) { - this._atom_site_B_iso_or_equiv = _atom_site_B_iso_or_equiv; - } - - /** - * Gets the _atom_site_occupancy. - * - * @return the _atom_site_occupancy - */ - public List get_atom_site_occupancy() { - return _atom_site_occupancy; - } - - /** - * Sets the _atom_site_occupancy. - * - * @param _atom_site_occupancy the new _atom_site_occupancy - */ - public void set_atom_site_occupancy(ArrayList _atom_site_occupancy) { - this._atom_site_occupancy = _atom_site_occupancy; - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaBean.java deleted file mode 100644 index 738f80a..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaBean.java +++ /dev/null @@ -1,255 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.rcsb.mmtf.dataholders.PDBGroup; - -/** - * A bean to store C-Alpha / DNA backbone and ligand information. - * - * @author Anthony Bradley - */ -public class CalphaBean { - - /** The number of bonds. */ - // Two integers to store the number of bonds and numeb - private int numBonds = 0; - - /** The number of atoms. */ - private int numAtoms = 0; - - /** The map of residue codes to groups. */ - // Convert this information - private Map groupMap = new HashMap(); - - /** The _atom_site_auth_seq_id. */ - // Delta and run length - private List _atom_site_auth_seq_id = new ArrayList(); - - /** The _atom_site_label_entity_poly_seq_num. */ - // Delta and run length encoded - private List _atom_site_label_entity_poly_seq_num = new ArrayList(); - - /** The residue order. */ - private List resOrder = new ArrayList(); - - /** The X coords. */ - // The list of c-alpha coords - private List cartn_x = new ArrayList(); - - /** The Y coords. */ - private List cartn_y = new ArrayList(); - - /** The Z coords. */ - private List cartn_z = new ArrayList(); - - /** The secondary structure list. */ - //secondary structure (on a per reisude basis - private List secStruct = new ArrayList(); - - /** The number of groups per chain. */ - // A list of integers indicating the number of groups in a chain - private int[] groupsPerChain; - - /** - * Gets the cartn_x. - * - * @return the cartn_x - */ - // Now the getters and setters - public List getCartn_x() { - return cartn_x; - } - - /** - * Sets the cartn_x. - * - * @param cartn_x the new cartn_x - */ - public void setCartn_x(List cartn_x) { - this.cartn_x = cartn_x; - } - - /** - * Gets the cartn_y. - * - * @return the cartn_y - */ - public List getCartn_y() { - return cartn_y; - } - - /** - * Sets the cartn_y. - * - * @param cartn_y the new cartn_y - */ - public void setCartn_y(List cartn_y) { - this.cartn_y = cartn_y; - } - - /** - * Gets the cartn_z. - * - * @return the cartn_z - */ - public List getCartn_z() { - return cartn_z; - } - - /** - * Sets the cartn_z. - * - * @param cartn_z the new cartn_z - */ - public void setCartn_z(List cartn_z) { - this.cartn_z = cartn_z; - } - - /** - * Gets the sec struct. - * - * @return the sec struct - */ - public List getSecStruct() { - return secStruct; - } - - /** - * Sets the sec struct. - * - * @param secStruct the new sec struct - */ - public void setSecStruct(List secStruct) { - this.secStruct = secStruct; - } - - /** - * Gets the _atom_site_auth_seq_id. - * - * @return the _atom_site_auth_seq_id - */ - public List get_atom_site_auth_seq_id() { - return _atom_site_auth_seq_id; - } - - /** - * Sets the _atom_site_auth_seq_id. - * - * @param _atom_site_auth_seq_id the new _atom_site_auth_seq_id - */ - public void set_atom_site_auth_seq_id(List _atom_site_auth_seq_id) { - this._atom_site_auth_seq_id = _atom_site_auth_seq_id; - } - - /** - * Gets the _atom_site_label_entity_poly_seq_num. - * - * @return the _atom_site_label_entity_poly_seq_num - */ - public List get_atom_site_label_entity_poly_seq_num() { - return _atom_site_label_entity_poly_seq_num; - } - - /** - * Sets the _atom_site_label_entity_poly_seq_num. - * - * @param _atom_site_label_entity_poly_seq_num the new _atom_site_label_entity_poly_seq_num - */ - public void set_atom_site_label_entity_poly_seq_num(List _atom_site_label_entity_poly_seq_num) { - this._atom_site_label_entity_poly_seq_num = _atom_site_label_entity_poly_seq_num; - } - - /** - * Gets the res order. - * - * @return the res order - */ - public List getResOrder() { - return resOrder; - } - - /** - * Sets the res order. - * - * @param resOrder the new res order - */ - public void setResOrder(List resOrder) { - this.resOrder = resOrder; - } - - /** - * Gets the group map. - * - * @return the group map - */ - public Map getGroupMap() { - return groupMap; - } - - /** - * Sets the group map. - * - * @param groupMap the group map - */ - public void setGroupMap(Map groupMap) { - this.groupMap = groupMap; - } - - /** - * Gets the groups per chain. - * - * @return the groups per chain - */ - public int[] getGroupsPerChain() { - return groupsPerChain; - } - - /** - * Sets the groups per chain. - * - * @param groupsPerChain the new groups per chain - */ - public void setGroupsPerChain(int[] groupsPerChain) { - this.groupsPerChain = groupsPerChain; - } - - /** - * Gets the num atoms. - * - * @return the num atoms - */ - public int getNumAtoms() { - return numAtoms; - } - - /** - * Sets the num atoms. - * - * @param numAtoms the new num atoms - */ - public void setNumAtoms(int numAtoms) { - this.numAtoms = numAtoms; - } - - /** - * Gets the num bonds. - * - * @return the num bonds - */ - public int getNumBonds() { - return numBonds; - } - - /** - * Sets the num bonds. - * - * @param numBonds the new num bonds - */ - public void setNumBonds(int numBonds) { - this.numBonds = numBonds; - } -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaDistBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaDistBean.java deleted file mode 100644 index 7dc085b..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CalphaDistBean.java +++ /dev/null @@ -1,519 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.rcsb.mmtf.dataholders.BioAssemblyData; -import org.rcsb.mmtf.dataholders.PDBGroup; - -/** - * A bean to store C-Alpha / DNA backbone and ligand information - in a format that can - * then be efficiently sent as messagepack. - * - * @author abradley - */ -public class CalphaDistBean { - - /** The mmtf version. */ - // The version of the format - private String mmtfVersion = "0.1"; - - /** The mmtf producer. */ - // The producer - private String mmtfProducer; - - /** The num bonds. */ - // The number of bonds - private int numBonds; - - /** The pdb id. */ - // The PDBCode - private String pdbId; - - /** The title. */ - // The title of the structure - private String title; - - /** The space group. */ - // String for the space group - private String spaceGroup; - - /** The unit cell. */ - // The unit cell information - private float[] unitCell; - - /** The bio assembly. */ - // A map of Bioassembly -> new class so serializable - private List bioAssembly = new ArrayList(); - - /** The group map. */ - // The list of sequence information - private Map groupMap = new HashMap(); - - /** The group num list. */ - // Delta and run length - private byte[] groupIdList; - - /** The group type list. */ - private byte[] groupTypeList; - - /** The sec struct list. */ - private byte[] secStructList; - - /** The x coord big. */ - // For the big arrays split into two -> one of 32 bit ints, one of 16 - private byte[] xCoordBig; - - /** The y coord big. */ - private byte[] yCoordBig; - - /** The z coord big. */ - private byte[] zCoordBig; - - /** The x coord small. */ - // Now for the small ints -> 16 bit - private byte[] xCoordSmall; - - /** The y coord small. */ - private byte[] yCoordSmall; - - /** The z coord small. */ - private byte[] zCoordSmall; - // Add this header info - /** The num atoms. */ - // Total data for memory allocation - private int numAtoms; - - /** The chains per model. */ - // Add this to store the model information - private int[] chainsPerModel; - - /** The chain list. */ - // List to store the chainids - private byte[] chainIdList; - - /** The groups per chain. */ - // List to store the number of groups per chain - private int[] groupsPerChain; - - /** The one letter amin seq. */ - // Store the one letter amino acid sequence of the protein - private char[] oneLetterAminSeq; - - /** - * Gets the pdb id. - * - * @return the pdb id - */ - public String getPdbId() { - return pdbId; - } - - /** - * Sets the pdb id. - * - * @param pdbId the new pdb id - */ - public void setPdbId(String pdbId) { - this.pdbId = pdbId; - } - - /** - * Gets the title. - * - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * Sets the title. - * - * @param title the new title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * Gets the space group. - * - * @return the space group - */ - public String getSpaceGroup() { - return spaceGroup; - } - - /** - * Sets the space group. - * - * @param spaceGroup the new space group - */ - public void setSpaceGroup(String spaceGroup) { - this.spaceGroup = spaceGroup; - } - - /** - * Gets the unit cell. - * - * @return the unit cell - */ - public float[] getUnitCell() { - return unitCell; - } - - /** - * Sets the unit cell. - * - * @param unitCell the new unit cell - */ - public void setUnitCell(float[] inputUnitCell) { - this.unitCell = inputUnitCell; - } - - /** - * Gets the bio assembly. - * - * @return the bio assembly - */ - public List getBioAssembly() { - return bioAssembly; - } - - /** - * Sets the bio assembly. - * - * @param bioAssembly the bio assembly - */ - public void setBioAssembly(List bioAssembly) { - this.bioAssembly = bioAssembly; - } - - /** - * Gets the num atoms. - * - * @return the num atoms - */ - public int getNumAtoms() { - return numAtoms; - } - - /** - * Sets the num atoms. - * - * @param numAtoms the new num atoms - */ - public void setNumAtoms(int numAtoms) { - this.numAtoms = numAtoms; - } - - /** - * Gets the chains per model. - * - * @return the chains per model - */ - public int[] getChainsPerModel() { - return chainsPerModel; - } - - /** - * Sets the chains per model. - * - * @param chainsPerModel the new chains per model - */ - public void setChainsPerModel(int[] chainsPerModel) { - this.chainsPerModel = chainsPerModel; - } - - /** - * Gets the chain list. - * - * @return the chain list - */ - public byte[] getChainIdList() { - return chainIdList; - } - - /** - * Sets the chain list. - * - * @param chainList the new chain list - */ - public void setChainIdList(byte[] chainList) { - this.chainIdList = chainList; - } - - /** - * Gets the groups per chain. - * - * @return the groups per chain - */ - public int[] getGroupsPerChain() { - return groupsPerChain; - } - - /** - * Sets the groups per chain. - * - * @param groupsPerChain the new groups per chain - */ - public void setGroupsPerChain(int[] groupsPerChain) { - this.groupsPerChain = groupsPerChain; - } - - /** - * Gets the group map. - * - * @return the group map - */ - public Map getGroupMap() { - return groupMap; - } - - /** - * Sets the group map. - * - * @param groupMap the group map - */ - public void setGroupMap(Map groupMap) { - this.groupMap = groupMap; - } - - /** - * Gets the group num list. - * - * @return the group num list - */ - public byte[] getGroupIdList() { - return groupIdList; - } - - /** - * Sets the group num list. - * - * @param _atom_site_auth_seq_id the new group num list - */ - public void setGroupIdList(byte[] _atom_site_auth_seq_id) { - this.groupIdList = _atom_site_auth_seq_id; - } - - /** - * Gets the group type list. - * - * @return the group type list - */ - public byte[] getGroupTypeList() { - return groupTypeList; - } - - /** - * Sets the group type list. - * - * @param resOrder the new group type list - */ - public void setGroupTypeList(byte[] resOrder) { - this.groupTypeList = resOrder; - } - - /** - * Gets the sec struct list. - * - * @return the sec struct list - */ - public byte[] getSecStructList() { - return secStructList; - } - - /** - * Sets the sec struct list. - * - * @param secStruct the new sec struct list - */ - public void setSecStructList(byte[] secStruct) { - this.secStructList = secStruct; - } - - /** - * Gets the x coord big. - * - * @return the x coord big - */ - public byte[] getxCoordBig() { - return xCoordBig; - } - - /** - * Sets the x coord big. - * - * @param cartn_x_big the new x coord big - */ - public void setxCoordBig(byte[] cartn_x_big) { - this.xCoordBig = cartn_x_big; - } - - /** - * Gets the y coord big. - * - * @return the y coord big - */ - public byte[] getyCoordBig() { - return yCoordBig; - } - - /** - * Sets the y coord big. - * - * @param cartn_y_big the new y coord big - */ - public void setyCoordBig(byte[] cartn_y_big) { - this.yCoordBig = cartn_y_big; - } - - /** - * Gets the z coord big. - * - * @return the z coord big - */ - public byte[] getzCoordBig() { - return zCoordBig; - } - - /** - * Sets the z coord big. - * - * @param cartn_z_big the new z coord big - */ - public void setzCoordBig(byte[] cartn_z_big) { - this.zCoordBig = cartn_z_big; - } - - /** - * Gets the x coord small. - * - * @return the x coord small - */ - public byte[] getxCoordSmall() { - return xCoordSmall; - } - - /** - * Sets the x coord small. - * - * @param cartn_x_small the new x coord small - */ - public void setxCoordSmall(byte[] cartn_x_small) { - this.xCoordSmall = cartn_x_small; - } - - /** - * Gets the y coord small. - * - * @return the y coord small - */ - public byte[] getyCoordSmall() { - return yCoordSmall; - } - - /** - * Sets the y coord small. - * - * @param cartn_y_small the new y coord small - */ - public void setyCoordSmall(byte[] cartn_y_small) { - this.yCoordSmall = cartn_y_small; - } - - /** - * Gets the z coord small. - * - * @return the z coord small - */ - public byte[] getzCoordSmall() { - return zCoordSmall; - } - - /** - * Sets the z coord small. - * - * @param cartn_z_small the new z coord small - */ - public void setzCoordSmall(byte[] cartn_z_small) { - this.zCoordSmall = cartn_z_small; - } - - /** - * Gets the mmtf version. - * - * @return the mmtf version - */ - public String getMmtfVersion() { - return mmtfVersion; - } - - /** - * Sets the mmtf version. - * - * @param mmtfVersion the new mmtf version - */ - public void setMmtfVersion(String mmtfVersion) { - this.mmtfVersion = mmtfVersion; - } - - /** - * Gets the mmtf producer. - * - * @return the mmtf producer - */ - public String getMmtfProducer() { - return mmtfProducer; - } - - /** - * Sets the mmtf producer. - * - * @param mmtfProducer the new mmtf producer - */ - public void setMmtfProducer(String mmtfProducer) { - this.mmtfProducer = mmtfProducer; - } - - /** - * Gets the num bonds. - * - * @return the num bonds - */ - public int getNumBonds() { - return numBonds; - } - - /** - * Sets the num bonds. - * - * @param numBonds the new num bonds - */ - public void setNumBonds(int numBonds) { - this.numBonds = numBonds; - } - - /** - * Gets the one letter amin seq. - * - * @return the one letter amin seq - */ - public char[] getOneLetterAminSeq() { - return oneLetterAminSeq; - } - - /** - * Sets the one letter amin seq. - * - * @param oneLetterAminSeq the new one letter amin seq - */ - public void setOneLetterAminSeq(char[] oneLetterAminSeq) { - this.oneLetterAminSeq = oneLetterAminSeq; - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreDataStruct.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreDataStruct.java deleted file mode 100644 index 9aadaf2..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreDataStruct.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.rcsb.mmtf.dataholders; - - -/** - * A basic class to hold the basic information about a protein. - * - * @author Anthony Bradley - */ -public class CoreDataStruct { - - /** The pdb code. */ - // The core data in all modules - protected String pdbCode = null; - - /** - * Gets the pdb code. - * - * @return the pdb code - */ - public String getPdbCode() { - return pdbCode; - } - - /** - * Sets the pdb code. - * - * @param pdbCode the new pdb code - */ - public void setPdbCode(String pdbCode) { - this.pdbCode = pdbCode; - } - - /** The number of models. */ - private int numModels = 0; - - /** - * Gets the num models. - * - * @return the num models - */ - public int getNumModels() { - return numModels; - } - - /** - * Sets the num models. - * - * @param numModels the new num models - */ - public void setNumModels(int numModels) { - this.numModels = numModels; - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreSingleStructure.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreSingleStructure.java deleted file mode 100644 index 412afb3..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/CoreSingleStructure.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.lang.reflect.InvocationTargetException; - -/** - * An interface required for core single structure types - * @author abradley - * - */ -public interface CoreSingleStructure { - // Interface to deal with core structural data - // Return the data as a HashMap - - /** - * Function to return the data as a bean - * @return the data as a bean - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - BioBean findDataAsBean(); - - /** - * Function to return the structure code - * @return - */ - String findStructureCode(); - - /** - * Function to return the number of atoms - * @return - */ - int findNumAtoms(); -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java deleted file mode 100644 index 5b1c70e..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/HeaderBean.java +++ /dev/null @@ -1,633 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.util.Date; -import java.util.List; - -import org.rcsb.mmtf.dataholders.BioAssemblyData; - -/** - * Class to store header information in a bean that can be converted to a messagepack. - * - * @author abradley - */ -public class HeaderBean { - - /** The number of chains. */ - // The number of chains - private int numChains; - - /** The number of atoms. */ - // The number of atoms - private int numAtoms; - - /** The number of bonds. */ - // The number of bonds - private int numBonds; - - /** The id code. */ - // The PDBCode - private String idCode; - - /** The title. */ - // The title of the structure - private String title; - - /** The description. */ - // PDB HEADER INFORMATION - private String description; - - /** The classification. */ - private String classification; - - /** The depositon date. */ - private Date depDate; - - - /** The modified date. */ - private Date modDate; - - /** The resolution.-1.0 if not available */ - private float resolution; - - /** The r free. -1.0 if not available*/ - private float rFree; - - /** The r work. -1.0 if not available */ - private float rWork; - - /** The doi. */ - private String doi; - - /** The authors. */ - private String authors; - - /** The SEQRES sequence, per asym chain. */ - private List sequence; - - /** The SeqRes group ids. */ - private List seqResGroupIds; - - /** The experimental method(s). */ - private List experimentalMethods; - - /** The chains per model. */ - // Add this to store the model information - private int[] chainsPerModel; - - /** The asym chains per model. */ - private int[] asymChainsPerModel; - - /** The chain list. */ - // List to store the chainids - private byte[] chainList; - - /** The asym chain list. */ - // List to store the chainids - private byte[] asymChainList; - - /** The groups per chain. */ - // List to store the number of groups per chain - private int[] groupsPerChain; - - /** The asym groups per chain. */ - private int[] asymGroupsPerChain; - - /** The space group. */ - // LOTS OF OTHER STUFF HERE -> TBD - private String spaceGroup; - - /** The list of entities in this structure. */ - private Entity[] entityList; - - /** The pdbx_description of a given chain (entity) */ - private String[] chainDescriptionList; - - /** The type of a given chain (entity) */ - private String[] chainTypeList; - - /** The unit cell. */ - private float[] unitCell; - - /** The bio assembly. */ - private List bioAssembly; - - public HeaderBean() { - resolution = MmtfBean.UNAVAILABLE_RESOLUTION_VALUE; - - rFree = MmtfBean.UNAVAILABLE_R_VALUE; - - rWork = MmtfBean.UNAVAILABLE_R_VALUE; - } - - // Getters and setters - /** - * Gets the number of chains. - * - * @return the number of chains - */ - public int getNumChains() { - return numChains; - } - - /** - * Sets the number of chains. - * - * @param numChains the new number of chains - */ - public void setNumChains(int numChains) { - this.numChains = numChains; - } - - /** - * Gets the number of atoms. - * - * @return the number of atoms - */ - public int getNumAtoms() { - return numAtoms; - } - - /** - * Sets the number of atoms. - * - * @param numAtoms the new number of atoms - */ - public void setNumAtoms(int numAtoms) { - this.numAtoms = numAtoms; - } - - /** - * Gets the pdb code. - * - * @return the pdb code - */ - public String getPdbCode() { - return idCode; - } - - /** - * Sets the pdb code. - * - * @param pdbCode the new pdb code - */ - public void setPdbCode(String pdbCode) { - this.idCode = pdbCode; - } - - /** - * Gets the space group. - * - * @return the space group - */ - public String getSpaceGroup() { - return spaceGroup; - } - - /** - * Sets the space group. - * - * @param spaceGroup the new space group - */ - public void setSpaceGroup(String spaceGroup) { - this.spaceGroup = spaceGroup; - } - - /** - * Gets the unit cell. - * - * @return the unit cell - */ - public float[] getUnitCell() { - return unitCell; - } - - /** - * Sets the unit cell. - * - * @param unitCell the new unit cell - */ - public void setUnitCell(float[] inputUnitCell) { - this.unitCell = inputUnitCell; - } - - /** - * Gets the chains per model. - * - * @return the chains per model - */ - public int[] getChainsPerModel() { - return chainsPerModel; - } - - /** - * Sets the chains per model. - * - * @param chainsPerModel the new chains per model - */ - public void setChainsPerModel(int[] chainsPerModel) { - this.chainsPerModel = chainsPerModel; - } - - /** - * Gets the groups per chain. - * - * @return the groups per chain - */ - public int[] getGroupsPerChain() { - return groupsPerChain; - } - - /** - * Sets the groups per chain. - * - * @param groupsPerChain the new groups per chain - */ - public void setGroupsPerChain(int[] groupsPerChain) { - this.groupsPerChain = groupsPerChain; - } - - /** - * Gets the id code. - * - * @return the id code - */ - public String getIdCode() { - return idCode; - } - - /** - * Sets the id code. - * - * @param idCode the new id code - */ - public void setIdCode(String idCode) { - this.idCode = idCode; - } - - /** - * Gets the description. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * Sets the description. - * - * @param description the new description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Gets the classification. - * - * @return the classification - */ - public String getClassification() { - return classification; - } - - /** - * Sets the classification. - * - * @param classification the new classification - */ - public void setClassification(String classification) { - this.classification = classification; - } - - /** - * Gets the dep date. - * - * @return the dep date - */ - public Date getDepDate() { - return depDate; - } - - /** - * Sets the dep date. - * - * @param depDate the new dep date - */ - public void setDepDate(Date depDate) { - this.depDate = depDate; - } - - /** - * Gets the mod date. - * - * @return the mod date - */ - public Date getModDate() { - return modDate; - } - - /** - * Sets the mod date. - * - * @param modDate the new mod date - */ - public void setModDate(Date modDate) { - this.modDate = modDate; - } - - /** - * Gets the resolution. - * - * @return the resolution - */ - public float getResolution() { - return resolution; - } - - /** - * Sets the resolution. - * - * @param resolution the new resolution - */ - public void setResolution(float resolution) { - this.resolution = resolution; - } - - /** - * Gets the r free. - * - * @return the r free - */ - public float getrFree() { - return rFree; - } - - /** - * Sets the r free. - * - * @param rFree the new r free - */ - public void setrFree(float rFree) { - this.rFree = rFree; - } - - /** - * Gets the doi. - * - * @return the doi - */ - public String getDoi() { - return doi; - } - - /** - * Sets the doi. - * - * @param doi the new doi - */ - public void setDoi(String doi) { - this.doi = doi; - } - - /** - * Gets the authors. - * - * @return the authors - */ - public String getAuthors() { - return authors; - } - - /** - * Sets the authors. - * - * @param authors the new authors - */ - public void setAuthors(String authors) { - this.authors = authors; - } - - /** - * Gets the bio assembly. - * - * @return the bio assembly - */ - public List getBioAssembly() { - return bioAssembly; - } - - /** - * Sets the bio assembly. - * - * @param bioAssembly the bio assembly - */ - public void setBioAssembly(List inputBioAssembly) { - this.bioAssembly = inputBioAssembly; - } - - /** - * Gets the chain list. - * - * @return the chain list - */ - public byte[] getChainList() { - return chainList; - } - - /** - * Sets the chain list. - * - * @param chainList the new chain list - */ - public void setChainList(byte[] chainList) { - this.chainList = chainList; - } - - /** - * Gets the asym chain list. - * - * @return the asym chain list - */ - public byte[] getAsymChainList() { - return asymChainList; - } - - /** - * Sets the asym chain list. - * - * @param asymChainList the new asym chain list - */ - public void setAsymChainList(byte[] asymChainList) { - this.asymChainList = asymChainList; - } - - /** - * Gets the title. - * - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * Sets the title. - * - * @param title the new title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * Gets the sequence. - * - * @return the sequence - */ - public List getSequence() { - return sequence; - } - - /** - * Sets the sequence. - * - * @param sequence the new sequence - */ - public void setSequence(List sequence) { - this.sequence = sequence; - } - - /** - * Gets the number of bonds. - * - * @return the number of bonds - */ - public int getNumBonds() { - return numBonds; - } - - /** - * Sets the number of bonds. - * - * @param numBonds the new number of bonds - */ - public void setNumBonds(int numBonds) { - this.numBonds = numBonds; - } - - /** - * Gets the asym chains per model. - * - * @return the asym chains per model - */ - public int[] getAsymChainsPerModel() { - return asymChainsPerModel; - } - - /** - * Sets the asym chains per model. - * - * @param asymChainsPerModel the new asym chains per model - */ - public void setAsymChainsPerModel(int[] asymChainsPerModel) { - this.asymChainsPerModel = asymChainsPerModel; - } - - /** - * Gets the asym groups per chain. - * - * @return the asym groups per chain - */ - public int[] getAsymGroupsPerChain() { - return asymGroupsPerChain; - } - - /** - * Sets the asym groups per chain. - * - * @param asymGroupsPerChain the new asym groups per chain - */ - public void setAsymGroupsPerChain(int[] asymGroupsPerChain) { - this.asymGroupsPerChain = asymGroupsPerChain; - } - - /** - * @return the seqResGroupIds - */ - public List getSeqResGroupIds() { - return seqResGroupIds; - } - - /** - * @param seqResGroupIds the seqResGroupIds to set - */ - public void setSeqResGroupIds(List seqResGroupIds) { - this.seqResGroupIds = seqResGroupIds; - } - - /** - * @return the experimental methods - */ - public List getExperimentalMethods() { - return experimentalMethods; - } - - /** - * @param experimentalMethods the experimental methods to set - */ - public void setExperimentalMethods(List experimentalMethods) { - this.experimentalMethods = experimentalMethods; - } - - /** - * @return the rWork - */ - public float getrWork() { - return rWork; - } - - /** - * @param rWork the rWork to set - */ - public void setrWork(float rWork) { - this.rWork = rWork; - } - - /** - * @return the chainDescriptionList - */ - public String[] getChainDescriptionList() { - return chainDescriptionList; - } - - /** - * @param chainDescriptionList the chainDescriptionList to set - */ - public void setChainDescriptionList(String[] chainDescriptionList) { - this.chainDescriptionList = chainDescriptionList; - } - - /** - * @return the chainTypeList - */ - public String[] getChainTypeList() { - return chainTypeList; - } - - /** - * @param chainTypeList the chainTypeList to set - */ - public void setChainTypeList(String[] chainTypeList) { - this.chainTypeList = chainTypeList; - } - - public Entity[] getEntityList() { - return entityList; - } - - public void setEntityList(Entity[] entityList) { - this.entityList = entityList; - } - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoCoordDataStruct.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoCoordDataStruct.java deleted file mode 100644 index 001a573..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoCoordDataStruct.java +++ /dev/null @@ -1,408 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.rcsb.mmtf.dataholders.PDBGroup; - -/** - * A bean to store information about non coordinate information - fields are related strongly - * to the mmCif field they come from. - * - * @author anthony - */ -public class NoCoordDataStruct extends CoreDataStruct { - - /** The _atom_site_symbol. */ - // The symbol of thae atom - private List _atom_site_symbol = new ArrayList(); - // This data item is an author defined alternative to the value of - // _atom_site_label_asym_id_ This item holds the PDB chain - /** The _atom_site_asym_id. */ - // identifier_ - private List _atom_site_asym_id = new ArrayList(); - // This data item is an author defined alternative to the value of - // _atom_site_label_atom_id_ This item holds the PDB atom name_ -// private List _atom_site_auth_atom_id = new ArrayList(); - // This data item is an author defined alternative to the value of - // _atom_site_label_comp_id_ This item holds the PDB 3-letter-code - // residue names -// private List _atom_site_auth_comp_id = new ArrayList(); - // This data item is an author defined alternative to the value of - /** The _atom_site_auth_seq_id. */ - // _atom_site_label_seq_id_ This item holds the PDB residue number_ - private List _atom_site_auth_seq_id = new ArrayList(); - - /** The _atom_site_label_entity_poly_seq_num. */ - private List _atom_site_label_entity_poly_seq_num= new ArrayList(); - - /** The _atom_site_pdbx_ pd b_ins_code. */ - // This data item corresponds to the PDB insertion code_ - private List _atom_site_pdbx_PDB_ins_code = new ArrayList(); - // This data item identifies the model number in an ensemble of - // coordinate data_ -// private List _atom_site_pdbx_PDB_model_num = new ArrayList(); - // This data item is a place holder for the tags used by the PDB to - /** The _atom_site_group_ pdb. */ - // identify coordinate records (e_g_ ATOM or HETATM)_ - private List _atom_site_group_PDB = new ArrayList(); - // This item is a uniquely identifies for each alternative site for - /** The _atom_site_label_alt_id. */ - // this atom position_ - private List _atom_site_label_alt_id= new ArrayList(); - - /** The _atom_site_label_asym_id. */ - // This data item is reference to item _struct_asym_id defined in - private List _atom_site_label_asym_id= new ArrayList(); - // This data item is a reference to item _chem_comp_atom_atom_id - // defined in category CHEM_COMP_ATOM which is stored in the - // Chemical Component Dictionary_ This atom identifier uniquely - /** The _atom_site_label_atom_id. */ - // identifies each atom within each chemical component_ - private List _atom_site_label_atom_id= new ArrayList(); - // This data item is a reference to item _chem_comp_id defined in - // category CHEM_COMP_ This item is the primary identifier for - // chemical components which may either be mononers in a polymeric - /** The _atom_site_label_comp_id. */ - // entity or complete non-polymer entities_ - private List _atom_site_label_comp_id= new ArrayList(); - // This data item is a reference to _entity_id defined in the ENTITY - // category_ This item is used to identify chemically distinct - // portions of the molecular structure (e_g_ polymer chains, - // ligands, solvent)_ - // This data item is a reference to _entity_poly_seq_num defined in - // the ENTITY_POLY_SEQ category_ This item is used to maintain the - // correspondence between the chemical sequence of a polymeric - // entity and the sequence information in the coordinate list and in - // may other structural categories_ This identifier has no meaning - /** The _atom_site_label_entity_id. */ - // for non-polymer entities_ - private List _atom_site_label_entity_id= new ArrayList(); - - /** The inter group bond inds. */ - // The indices and orders of bonds between groups - private List interGroupBondInds = new ArrayList(); - - /** The inter group bond orders. */ - private List interGroupBondOrders = new ArrayList(); - - /** The sec struct. */ - private List secStruct = new ArrayList(); - - /** The res order. */ - private List resOrder = new ArrayList(); - - /** The group list. */ - private List> groupList = new ArrayList>(); - - /** - * Gets the _atom_site_symbol. - * - * @return the _atom_site_symbol - */ - public List get_atom_site_symbol() { - return _atom_site_symbol; - } - - /** - * Sets the _atom_site_symbol. - * - * @param _atom_site_symbol the new _atom_site_symbol - */ - public void set_atom_site_symbol(List _atom_site_symbol) { - this._atom_site_symbol = _atom_site_symbol; - } - - /** - * Gets the _atom_site_asym_id. - * - * @return the _atom_site_asym_id - */ - public List get_atom_site_asym_id() { - return _atom_site_asym_id; - } - - /** - * Sets the _atom_site_asym_id. - * - * @param _atom_site_asym_id the new _atom_site_asym_id - */ - public void set_atom_site_asym_id(List _atom_site_asym_id) { - this._atom_site_asym_id = _atom_site_asym_id; - } - - /** - * Gets the _atom_site_auth_seq_id. - * - * @return the _atom_site_auth_seq_id - */ - public List get_atom_site_auth_seq_id() { - return _atom_site_auth_seq_id; - } - - /** - * Sets the _atom_site_auth_seq_id. - * - * @param _atom_site_auth_seq_id the new _atom_site_auth_seq_id - */ - public void set_atom_site_auth_seq_id(List _atom_site_auth_seq_id) { - this._atom_site_auth_seq_id = _atom_site_auth_seq_id; - } - - /** - * Gets the _atom_site_pdbx_ pd b_ins_code. - * - * @return the _atom_site_pdbx_ pd b_ins_code - */ - public List get_atom_site_pdbx_PDB_ins_code() { - return _atom_site_pdbx_PDB_ins_code; - } - - /** - * Sets the _atom_site_pdbx_ pd b_ins_code. - * - * @param _atom_site_pdbx_PDB_ins_code the new _atom_site_pdbx_ pd b_ins_code - */ - public void set_atom_site_pdbx_PDB_ins_code(List _atom_site_pdbx_PDB_ins_code) { - this._atom_site_pdbx_PDB_ins_code = _atom_site_pdbx_PDB_ins_code; - } - - /** - * Gets the _atom_site_group_ pdb. - * - * @return the _atom_site_group_ pdb - */ - public List get_atom_site_group_PDB() { - return _atom_site_group_PDB; - } - - /** - * Sets the _atom_site_group_ pdb. - * - * @param _atom_site_group_PDB the new _atom_site_group_ pdb - */ - public void set_atom_site_group_PDB(List _atom_site_group_PDB) { - this._atom_site_group_PDB = _atom_site_group_PDB; - } - - /** - * Gets the _atom_site_label_alt_id. - * - * @return the _atom_site_label_alt_id - */ - public List get_atom_site_label_alt_id() { - return _atom_site_label_alt_id; - } - - /** - * Sets the _atom_site_label_alt_id. - * - * @param _atom_site_label_alt_id the new _atom_site_label_alt_id - */ - public void set_atom_site_label_alt_id(List _atom_site_label_alt_id) { - this._atom_site_label_alt_id = _atom_site_label_alt_id; - } - - /** - * Gets the _atom_site_label_asym_id. - * - * @return the _atom_site_label_asym_id - */ - public List get_atom_site_label_asym_id() { - return _atom_site_label_asym_id; - } - - /** - * Sets the _atom_site_label_asym_id. - * - * @param _atom_site_label_asym_id the new _atom_site_label_asym_id - */ - public void set_atom_site_label_asym_id(List _atom_site_label_asym_id) { - this._atom_site_label_asym_id = _atom_site_label_asym_id; - } - - /** - * Gets the _atom_site_label_atom_id. - * - * @return the _atom_site_label_atom_id - */ - public List get_atom_site_label_atom_id() { - return _atom_site_label_atom_id; - } - - /** - * Sets the _atom_site_label_atom_id. - * - * @param _atom_site_label_atom_id the new _atom_site_label_atom_id - */ - public void set_atom_site_label_atom_id(List _atom_site_label_atom_id) { - this._atom_site_label_atom_id = _atom_site_label_atom_id; - } - - /** - * Gets the _atom_site_label_comp_id. - * - * @return the _atom_site_label_comp_id - */ - public List get_atom_site_label_comp_id() { - return _atom_site_label_comp_id; - } - - /** - * Sets the _atom_site_label_comp_id. - * - * @param _atom_site_label_comp_id the new _atom_site_label_comp_id - */ - public void set_atom_site_label_comp_id(List _atom_site_label_comp_id) { - this._atom_site_label_comp_id = _atom_site_label_comp_id; - } - - /** - * Gets the _atom_site_label_entity_id. - * - * @return the _atom_site_label_entity_id - */ - public List get_atom_site_label_entity_id() { - return _atom_site_label_entity_id; - } - - /** - * Sets the _atom_site_label_entity_id. - * - * @param _atom_site_label_entity_id the new _atom_site_label_entity_id - */ - public void set_atom_site_label_entity_id(List _atom_site_label_entity_id) { - this._atom_site_label_entity_id = _atom_site_label_entity_id; - } - - /** - * Gets the _atom_site_label_entity_poly_seq_num. - * - * @return the _atom_site_label_entity_poly_seq_num - */ - public List get_atom_site_label_entity_poly_seq_num() { - return _atom_site_label_entity_poly_seq_num; - } - - /** - * Sets the _atom_site_label_entity_poly_seq_num. - * - * @param _atom_site_label_entity_poly_seq_num the new _atom_site_label_entity_poly_seq_num - */ - public void set_atom_site_label_entity_poly_seq_num(List _atom_site_label_entity_poly_seq_num) { - this._atom_site_label_entity_poly_seq_num = _atom_site_label_entity_poly_seq_num; - } - - /** - * Gets the group map. - * - * @return the group map - */ - public Map getGroupMap() { - return groupMap; - } - - /** - * Sets the group map. - * - * @param groupMap the group map - */ - public void setGroupMap(Map groupMap) { - this.groupMap = groupMap; - } - - /** - * Gets the group list. - * - * @return the group list - */ - public List> getGroupList() { - return groupList; - } - - /** - * Sets the group list. - * - * @param groupList the new group list - */ - public void setGroupList(List> groupList) { - this.groupList = groupList; - } - - /** - * Gets the res order. - * - * @return the res order - */ - public List getResOrder() { - return resOrder; - } - - /** - * Sets the res order. - * - * @param resOrder the new res order - */ - public void setResOrder(List resOrder) { - this.resOrder = resOrder; - } - - /** - * Gets the sec struct. - * - * @return the sec struct - */ - public List getSecStruct() { - return secStruct; - } - - /** - * Sets the sec struct. - * - * @param secStruct the new sec struct - */ - public void setSecStruct(List secStruct) { - this.secStruct = secStruct; - } - - /** - * Gets the inter group bond inds. - * - * @return the inter group bond inds - */ - public List getInterGroupBondInds() { - return interGroupBondInds; - } - - /** - * Sets the inter group bond inds. - * - * @param interGroupBondInds the new inter group bond inds - */ - public void setInterGroupBondInds(List interGroupBondInds) { - this.interGroupBondInds = interGroupBondInds; - } - - /** - * Gets the inter group bond orders. - * - * @return the inter group bond orders - */ - public List getInterGroupBondOrders() { - return interGroupBondOrders; - } - - /** - * Sets the inter group bond orders. - * - * @param interGroupBondOrders the new inter group bond orders - */ - public void setInterGroupBondOrders(List interGroupBondOrders) { - this.interGroupBondOrders = interGroupBondOrders; - } - - /** The group map. */ - protected Map groupMap = new HashMap(); -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStruct.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStruct.java deleted file mode 100644 index b897355..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStruct.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.lang.reflect.InvocationTargetException; -import org.apache.commons.beanutils.BeanUtils; - - -/** - * Class to extend the NoFloatDataStructBean with functions - * - * @author Anthony Bradley - */ -public class NoFloatDataStruct extends NoFloatDataStructBean implements CoreSingleStructure { - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.CoreSingleStructure#findDataAsBean() - */ - @SuppressWarnings("static-access") - public BioBean findDataAsBean() { - // Cast this to the pure data - NoFloatDataStructBean newData = new NoFloatDataStructBean(); - BeanUtils bu = new BeanUtils(); - try { - bu.copyProperties(newData, this); - } catch (IllegalAccessException e) { - System.err.println("Unknown bug - copying bean data. Report as bug."); - e.printStackTrace(); - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - System.err.println("Unknown bug - copying bean data. Report as bug."); - e.printStackTrace(); - throw new RuntimeException(e); - } - return newData; - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.CoreSingleStructure#findStructureCode() - */ - @Override - public String findStructureCode() { - return this.findStructureCode(); - } - - /* (non-Javadoc) - * @see org.rcsb.mmtf.dataholders.CoreSingleStructure#findNumAtoms() - */ - @Override - public int findNumAtoms() { - return this.findNumAtoms(); - } - - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStructBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStructBean.java deleted file mode 100644 index f85c1f8..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/NoFloatDataStructBean.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.rcsb.mmtf.dataholders; - -import java.util.ArrayList; -import java.util.List; - -/** - * Class to store the data after removal of floats. - * - * @author Anthony Bradley - */ -public class NoFloatDataStructBean extends NoCoordDataStruct implements BioBean { - - /** The _atom_site_cartn_x_int. */ - // All this information is stored as Integer arrays - private List _atom_site_Cartn_xInt = new ArrayList(); - - /** The _atom_site_cartn_y_int. */ - private List _atom_site_Cartn_yInt = new ArrayList(); - - /** The _atom_site_cartn_z_int. */ - private List _atom_site_Cartn_zInt = new ArrayList(); - - /** The _atom_site_b_iso_or_equiv_int. */ - // Isotropic atomic displacement parameter - private List _atom_site_B_iso_or_equivInt = new ArrayList(); - - /** The _atom_site_occupancy_int. */ - // The fraction of the atom present at this atom position_ - private List _atom_site_occupancyInt = new ArrayList(); - - /** - * Gets the atom serial ids. - * - * @return the atom serial ids - */ - public List get_atom_site_id() { - return _atom_site_id; - } - - /** - * Sets the atom serial ids. - * - * @param _atom_site_id the new atom serial ids. - */ - public void set_atom_site_id(List _atom_site_id) { - this._atom_site_id = _atom_site_id; - } - - /** The the atom serial ids. */ - private List _atom_site_id = new ArrayList(); - - /** - * Gets the _atom_site_cartn_x_int. - * - * @return the _atom_site_cartn_x_int - */ - public List get_atom_site_Cartn_xInt() { - return _atom_site_Cartn_xInt; - } - - /** - * Sets the X coordinates stored as integers. - * - * @param _atom_site_Cartn_xInt the new X coordinates stored as integers. - */ - public void set_atom_site_Cartn_xInt(List _atom_site_Cartn_xInt) { - this._atom_site_Cartn_xInt = _atom_site_Cartn_xInt; - } - - /** - * Gets the Y coordinates stored as integers. - * - * @return the Y coordinates stored as integers. - */ - public List get_atom_site_Cartn_yInt() { - return _atom_site_Cartn_yInt; - } - - /** - * Sets the Y coordinates stored as integers. - * - * @param _atom_site_Cartn_yInt the new Y coordinates stored as integers. - */ - public void set_atom_site_Cartn_yInt(List _atom_site_Cartn_yInt) { - this._atom_site_Cartn_yInt = _atom_site_Cartn_yInt; - } - - /** - * Gets the Z coordinates stored as integers. - * - * @return the Z coordinates stored as integers. - */ - public List get_atom_site_Cartn_zInt() { - return _atom_site_Cartn_zInt; - } - - /** - * Sets the Z coordinates stored as integers. - * - * @param _atom_site_Cartn_zInt the new Z coordinates stored as integers. - */ - public void set_atom_site_Cartn_zInt(List _atom_site_Cartn_zInt) { - this._atom_site_Cartn_zInt = _atom_site_Cartn_zInt; - } - - /** - * Gets the B factor stored as integers. - * - * @return the B factor stored as integers. - */ - public List get_atom_site_B_iso_or_equivInt() { - return _atom_site_B_iso_or_equivInt; - } - - /** - * Sets the B factor data stored as integers. - * - * @param _atom_site_B_iso_or_equivInt the new B factor data stored as integers. - */ - public void set_atom_site_B_iso_or_equivInt(List _atom_site_B_iso_or_equivInt) { - this._atom_site_B_iso_or_equivInt = _atom_site_B_iso_or_equivInt; - } - - /** - * Gets the occupancy data stored as integers. - * - * @return the occupancy data stored as integers - */ - public List get_atom_site_occupancyInt() { - return _atom_site_occupancyInt; - } - - /** - * Sets the occupancy data stored as integers. - * - * @param _atom_site_occupancyInt the new the occupancy data stored as integers. - */ - public void set_atom_site_occupancyInt(List _atom_site_occupancyInt) { - this._atom_site_occupancyInt = _atom_site_occupancyInt; - } - - -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/package-info.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/package-info.java deleted file mode 100644 index e7333a5..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/dataholders/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author Anthony Bradley - * - */ -package org.rcsb.mmtf.dataholders; \ No newline at end of file diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java deleted file mode 100644 index 610c2ca..0000000 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java +++ /dev/null @@ -1,437 +0,0 @@ -package org.rcsb.mmtf.encoder; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPOutputStream; - -import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.biocompressors.BioCompressor; -import org.rcsb.mmtf.biocompressors.CompressDoubles; -import org.rcsb.mmtf.dataholders.BioDataStruct; -import org.rcsb.mmtf.dataholders.CalphaBean; -import org.rcsb.mmtf.dataholders.CalphaDistBean; -import org.rcsb.mmtf.dataholders.CoreSingleStructure; -import org.rcsb.mmtf.dataholders.HeaderBean; -import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.dataholders.NoFloatDataStruct; -import org.rcsb.mmtf.dataholders.NoFloatDataStructBean; -import org.rcsb.mmtf.dataholders.PDBGroup; -import org.rcsb.mmtf.gitversion.GetRepoState; - -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - - -/** - * A class of functions to help encoding of mmCIF data to other data structures. - * - * @author Anthony Bradley - */ -public class EncoderUtils implements Serializable { - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = 376413981384858130L; - - /** The class to get the git repo start */ - private GetRepoState grs = new GetRepoState(); - - /** A converter of doubles to ints. */ - private BioCompressor doublesToInts = new CompressDoubles(); - - - /** - * Take a list of integers (as List) and return as byte array. - * Each integer is stored as four bytes. - * @param inputList the input integer array - * @return the byte array output. Each integer is stored as four bytes. - * @throws IOException Occurred writing the int to the stream. - */ - public byte[] integersToBytes(List inputList) throws IOException - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - for(Integer i: inputList) - { - dos.writeInt(i); - } - return baos.toByteArray(); - } - - /** - * Get a messagepack from an input object using the getters and setters. - * @param inputObject the input object. Field names will be set using the getters and setters for private variable.s - * @return the message pack as a byte array. - * @throws JsonProcessingException the json processing exception - most likely related - * to serialization. - */ - public final byte[] getMessagePack(Object inputObject) throws JsonProcessingException{ - ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); - objectMapper.setSerializationInclusion(Include.NON_NULL); - byte[] inBuf = objectMapper.writeValueAsBytes(inputObject); - return inBuf; - } - - - /** - * Compress the biological and header data into a combined data structure. - * @param inStruct the BiodataStruct holding the structure data - * @param inHeader the header data - * @return the MmtfBean of the combined (compressed) data. - * @throws IOException reading byte array - */ - public final MmtfBean compressToMmtfBean(BioDataStruct inStruct, HeaderBean inHeader) throws IOException { - EncoderUtils encoderUtils = new EncoderUtils(); - // Compress the data. - CoreSingleStructure strucureData = compressInputData(inStruct); - // Now set up the output MMTF dataholder - MmtfBean outputMmtfBean = new MmtfBean(); - NoFloatDataStructBean bioBean = (NoFloatDataStructBean) strucureData.findDataAsBean(); - // Copy these things - outputMmtfBean.setDepositionDate(convertToIsoTime(inHeader.getDepDate())); - outputMmtfBean.setStructureId(bioBean.getPdbCode()); - outputMmtfBean.setInsCodeList(convertRunLengthStringListToIntArray(bioBean.get_atom_site_pdbx_PDB_ins_code())); - outputMmtfBean.setAltLocList(convertRunLengthStringListToIntArray(bioBean.get_atom_site_label_alt_id())); - // Set this experimental data - outputMmtfBean.setResolution(inHeader.getResolution()); - outputMmtfBean.setrFree(inHeader.getrFree()); - outputMmtfBean.setrWork(inHeader.getrWork()); - // Copy the asym data - outputMmtfBean.setChainIdList(inHeader.getAsymChainList()); - outputMmtfBean.setChainsPerModel(inHeader.getAsymChainsPerModel()); - outputMmtfBean.setGroupsPerChain(inHeader.getAsymGroupsPerChain()); - // Set the entity information - outputMmtfBean.setEntityList(inHeader.getEntityList()); - // Get the seqres information - outputMmtfBean.setSequenceIdList(encoderUtils.integersToBytes(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inHeader.getSeqResGroupIds())))); - outputMmtfBean.setExperimentalMethods(inHeader.getExperimentalMethods()); - // Now get this list - outputMmtfBean.setBondAtomList(encoderUtils.integersToBytes(inStruct.getInterGroupBondInds())); - outputMmtfBean.setBondOrderList(encoderUtils.integersToSmallBytes(inStruct.getInterGroupBondOrders())); - // Now get these from the headers - outputMmtfBean.setChainNameList(inHeader.getChainList()); - outputMmtfBean.setNumAtoms(inHeader.getNumAtoms()); - outputMmtfBean.setNumBonds(inHeader.getNumBonds()); - // Now get the crystalographic info from this header - outputMmtfBean.setSpaceGroup(inHeader.getSpaceGroup()); - outputMmtfBean.setGroupList(genGroupList(inStruct.getGroupMap())); - outputMmtfBean.setUnitCell(inHeader.getUnitCell()); - outputMmtfBean.setBioAssemblyList(inHeader.getBioAssembly()); - // Now set this extra header information - outputMmtfBean.setTitle(inHeader.getTitle()); - // Now add the byte arrays to the bean - addByteArrs(outputMmtfBean, bioBean); - // Now set the version - outputMmtfBean.setMmtfProducer("RCSB-PDB Generator---version: "+grs.getCurrentVersion()); - return outputMmtfBean; - } - - /** - * Convert the a run length encoded List of strings to an integer array. - * The values are in pairs. The first value of each pair encodes the character. - * The second is a string representing the number of repeats. - * @param inputStringArray The list of strings. Values are in pairs. The first value is a String of length 1. - * The second value encodes an integer as a string. - * @return An integer array of the values having been converted to integers. - */ - private final int[] convertRunLengthStringListToIntArray(List inputStringArray) { - // The output integer array - int[] outArray = new int[inputStringArray.size()]; - // Now loop through the array first value is char. - for (int i=0; i PDBGroup - * @return a list of PDBGroups, where the previous keys are used as indices. - */ - private final PDBGroup[] genGroupList(Map groupMap) { - PDBGroup[] outGroupList = new PDBGroup[Collections.max(groupMap.keySet())+1]; - for (int key : groupMap.keySet()) { - outGroupList[key] = groupMap.get(key); - } - return outGroupList; - } - - - /** - * Add the required bytearrays to an mmtfbean. - * @param inputMmtfBean the mmtf bean to which the arrays are to be added. - * @param inputDataBean the bean holding the coordinate information. - * @throws IOException Signals that an I/O exception has occurred. - */ - private final void addByteArrs(MmtfBean inputMmtfBean, NoFloatDataStructBean inputDataBean) throws IOException { - EncoderUtils cm = new EncoderUtils(); - // Convert the x,y,z coordinate arrays as 4 and 2 byte arrays. - List retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_Cartn_xInt()); - inputMmtfBean.setxCoordBig(retArr.get(0)); - inputMmtfBean.setxCoordSmall(retArr.get(1)); - retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_Cartn_yInt()); - inputMmtfBean.setyCoordBig(retArr.get(0)); - inputMmtfBean.setyCoordSmall(retArr.get(1)); - retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_Cartn_zInt()); - inputMmtfBean.setzCoordBig(retArr.get(0)); - inputMmtfBean.setzCoordSmall(retArr.get(1)); - // Set the bfactor arrays as 4 and 2 byte arrays - retArr = splitListIntsToByteArrays(inputDataBean.get_atom_site_B_iso_or_equivInt()); - inputMmtfBean.setbFactorBig(retArr.get(0)); - inputMmtfBean.setbFactorSmall(retArr.get(1)); - // Now the occupancy - inputMmtfBean.setOccupancyList(cm.integersToBytes(inputDataBean.get_atom_site_occupancyInt())); - // System.out.println(Collections.max(bioBean.getResOrder())); - inputMmtfBean.setGroupTypeList((cm.integersToBytes(inputDataBean.getResOrder()))); - inputMmtfBean.setAtomIdList(cm.integersToBytes(inputDataBean.get_atom_site_id())); - // Now the secondary structure - inputMmtfBean.setSecStructList(cm.integersToSmallBytes(inputDataBean.getSecStruct())); - // Now set the group num list - inputMmtfBean.setGroupIdList(cm.integersToBytes(inputDataBean.get_atom_site_auth_seq_id())); - } - - /** - * Write a list of integers to 1 byte integers. - * @param inputList the input list of integers. - * @return the byte array, each byte is a different integer. - * @throws IOException Signals that an I/O exception has occurred. - */ - public final byte[] integersToSmallBytes(List inputList) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - for(int i: inputList) - { - dos.writeByte(i); - } - return baos.toByteArray(); - } - - /** - * Split a list of integers into small (2 byte) and big (4 byte) integers. - * @param inputList the input list of 4 byte integers. - * @return a list (length two) of byte arrays. The first array is the four byte integers. - * The second is the two byte integers. - * @throws IOException Signals that an I/O exception has occurred. - */ - public final List splitListIntsToByteArrays(List inputList) throws IOException{ - // Initialise the list to return - List outputList = new ArrayList<>(); - // The counter keeps track of every short (two byte int) that has been added after a four byte int. - int counter = 0; - // Generate the output streams and data output streams. - ByteArrayOutputStream twoByteOutputStream = new ByteArrayOutputStream(); - DataOutputStream twoByteDataOutputStream = new DataOutputStream(twoByteOutputStream); - ByteArrayOutputStream fourByteOutputStream = new ByteArrayOutputStream(); - DataOutputStream fourByteDataOutputStream = new DataOutputStream(fourByteOutputStream); - // Iterate through the input list. - for(int i=0;iShort.MAX_VALUE){ - // Add the counter to the four byte list. - fourByteDataOutputStream.writeInt(counter); - // Add the number to the four byte list. - fourByteDataOutputStream.writeInt(inputList.get(i)); - // Set the counter to zero. - counter = 0; - } - else{ - // Add the two byte integer to the two byte list. - twoByteDataOutputStream.writeShort(inputList.get(i)); - // Add one to the counter. - counter+=1; - } - } - // Finally add the final counter to the four byte list. - fourByteDataOutputStream.writeInt(counter); - // Add the two byte arrays to the out put list. - outputList.add(fourByteOutputStream.toByteArray()); - outputList.add(twoByteOutputStream.toByteArray()); - return outputList; - } - - /** - * Utility function to gzip compress a byte[]. - * @param inputArray the input array - * @return the byte[] - */ - public final byte[] gzipCompress(byte[] inputArray){ - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - try{ - GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream); - gzipOutputStream.write(inputArray); - gzipOutputStream.close(); - } catch(IOException e){ - throw new RuntimeException(e); - } - System.out.printf("Compression %f\n", (1.0f * inputArray.length/byteArrayOutputStream.size())); - return byteArrayOutputStream.toByteArray(); - } - - - /** - * Set the chain id of a given chain to the byte array comprising the chain ids (as chars). - * Chain ids can be up to four chars long. If they are shorter they are padded using 0 bytes. - * @param chainId the string chain id. - * @param charChainList the char chain list. The current chain list of chars. - * @param chainIndex the chain index. The current chain index. - */ - public void setChainId(String chainId, byte[] charChainList, int chainIndex) { - // A char array to store the chars - char[] outChar = new char[4]; - // The length of this chain id - int chainIdLen = chainId.length(); - chainId.getChars(0, chainIdLen, outChar, 0); - // Set the bytrarray - chain ids can be up to 4 chars - pad with empty bytes - charChainList[chainIndex*4+0] = (byte) outChar[0]; - if(chainIdLen>1){ - charChainList[chainIndex*4+1] = (byte) outChar[1]; - } - else{ - charChainList[chainIndex*4+1] = (byte) 0; - } - if(chainIdLen>2){ - charChainList[chainIndex*4+2] = (byte) outChar[2]; - } - else{ - charChainList[chainIndex*4+2] = (byte) 0; - } - if(chainIdLen>3){ - charChainList[chainIndex*4+3] = (byte) outChar[3]; - } - else{ - charChainList[chainIndex*4+3] = (byte) 0; - } - } - - - /** - * Function to compress the input biological data. - * @param inputBioDataStruct the input data structure - * @return a core single structure - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws Exception The bean data copying didn't work - weird. - */ - public final CoreSingleStructure compressInputData(BioDataStruct inputBioDataStruct) { - // Convert the arrays to integers. - NoFloatDataStruct inStruct = (NoFloatDataStruct) doublesToInts.compresStructure(inputBioDataStruct); - // Get the lists of coordinates. - List cartnX = inStruct.get_atom_site_Cartn_xInt(); - List cartnY = inStruct.get_atom_site_Cartn_yInt(); - List cartnZ = inStruct.get_atom_site_Cartn_zInt(); - // Get the number of models - inStruct.set_atom_site_Cartn_xInt(ArrayEncoders.deltaEncode(cartnX)); - inStruct.set_atom_site_Cartn_yInt(ArrayEncoders.deltaEncode(cartnY)); - inStruct.set_atom_site_Cartn_zInt(ArrayEncoders.deltaEncode(cartnZ)); - // Compress the b factors using delta compression. - inStruct.set_atom_site_B_iso_or_equivInt(ArrayEncoders.deltaEncode(inStruct.get_atom_site_B_iso_or_equivInt())); - // Run length compress the occupanct - inStruct.set_atom_site_occupancyInt(ArrayEncoders.runlengthEncodeIntegers(inStruct.get_atom_site_occupancyInt())); - // Now the sequential numbers - huge gain - new order of good compressors - // Now runlength encode the residue order - inStruct.setResOrder(inStruct.getResOrder()); - // Check for negative counters - inStruct.set_atom_site_auth_seq_id(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inStruct.get_atom_site_auth_seq_id()))); - inStruct.set_atom_site_label_entity_poly_seq_num(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inStruct.get_atom_site_label_entity_poly_seq_num()))); - inStruct.set_atom_site_id(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(inStruct.get_atom_site_id()))); - // Now run length decode the strings - inStruct.set_atom_site_label_alt_id(ArrayEncoders.runlengthEncodeStrings(inStruct.get_atom_site_label_alt_id())); - //inStruct.set_atom_site_label_entity_id(stringRunEncode.compressStringArray((ArrayList) inStruct.get_atom_site_label_entity_id())); - inStruct.set_atom_site_pdbx_PDB_ins_code(ArrayEncoders.runlengthEncodeStrings(inStruct.get_atom_site_pdbx_PDB_ins_code())); - return inStruct; - } - - /** - * Compress Calpha data to the output format. - * @param calphaData the calpha struct - * @param inHeader the header data - * @return the compressed calpha data - * @throws IOException Signals that an I/O exception has occurred. - */ - public final CalphaDistBean compressCalpha(CalphaBean calphaData, HeaderBean inHeader) throws IOException { - EncoderUtils cm = new EncoderUtils(); - // Create the object to leave - CalphaDistBean calphaOut = new CalphaDistBean(); - calphaOut.setMmtfProducer("RCSB-PDB Generator---version: "+grs.getCurrentVersion()); - // The PDBCode - calphaOut.setPdbId(inHeader.getPdbCode()); - // The title of the structure - calphaOut.setTitle(inHeader.getTitle()); - // String for the space group - calphaOut.setSpaceGroup(inHeader.getSpaceGroup()); - // The unit cell information - calphaOut.setUnitCell(inHeader.getUnitCell()); - // A map of Bioassembly -> new class so serializable - calphaOut.setBioAssembly(inHeader.getBioAssembly()); - // Now set the number of bonds - calphaOut.setNumBonds(calphaData.getNumBonds()); - calphaOut.setGroupsPerChain(calphaData.getGroupsPerChain()); - // Set this header info - calphaOut.setChainsPerModel(inHeader.getChainsPerModel()); - calphaOut.setGroupsPerChain(calphaData.getGroupsPerChain()); - calphaOut.setChainIdList(inHeader.getChainList()); - calphaOut.setNumAtoms(calphaData.getNumAtoms()); - // Write the secondary stucture out - calphaOut.setSecStructList(cm.integersToSmallBytes(calphaData.getSecStruct())); - calphaOut.setGroupMap(calphaData.getGroupMap()); - calphaOut.setGroupTypeList(cm.integersToBytes(calphaData.getResOrder())); - // Get the input structure - List cartnX = calphaData.getCartn_x(); - List cartnY = calphaData.getCartn_y(); - List cartnZ = calphaData.getCartn_z(); - // Now add the X coords - List bigAndLittleX = splitListIntsToByteArrays(ArrayEncoders.deltaEncode(cartnX)); - calphaOut.setxCoordBig(bigAndLittleX.get(0)); - calphaOut.setxCoordSmall(bigAndLittleX.get(1)); - // No add they Y coords - List bigAndLittleY = splitListIntsToByteArrays(ArrayEncoders.deltaEncode(cartnY)); - calphaOut.setyCoordBig(bigAndLittleY.get(0)); - calphaOut.setyCoordSmall(bigAndLittleY.get(1)); - // Now add the Z coords - List bigAndLittleZ = splitListIntsToByteArrays(ArrayEncoders.deltaEncode(cartnZ)); - calphaOut.setzCoordBig(bigAndLittleZ.get(0)); - calphaOut.setzCoordSmall(bigAndLittleZ.get(1)); - // THESE ONES CAN BE RUN LENGTH ON DELTA - calphaOut.setGroupIdList(cm.integersToBytes(ArrayEncoders.runlengthEncodeIntegers(ArrayEncoders.deltaEncode(calphaData.get_atom_site_auth_seq_id())))); - return calphaOut; - } - -} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java deleted file mode 100644 index a064d4b..0000000 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/biocompressors/TestBioCompressor.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.rcsb.mmtf.biocompressors; - -import java.util.ArrayList; - -import org.junit.Test; -import org.rcsb.mmtf.biocompressors.CompressDoubles; - -import static org.junit.Assert.*; - - -public class TestBioCompressor { - - @Test - public void floatToInt() { - CompressDoubles cd = new CompressDoubles(); - ArrayList inArray = new ArrayList(); - ArrayList testArray = new ArrayList(); - for(int i=0; i<1000;i++){ - inArray.add((float) 100.12); - testArray.add(10012); - - } - assertEquals(cd.getIntArrayFromFloat(inArray, (float) 100.0),testArray); - - } - - - @Test - public void doubleToInt() { - CompressDoubles cd = new CompressDoubles(); - ArrayList inArray = new ArrayList(); - ArrayList testArray = new ArrayList(); - for(int i=0; i<1000;i++){ - inArray.add(100.12); - testArray.add(10012); - - } - assertEquals(cd.getIntArrayFromDouble(inArray, 100.0),testArray); - - } - -} From b5ec23fd4b2c5b39971cb692b233c6e469499bb9 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 11:19:07 -0700 Subject: [PATCH 061/108] Refactoring and restructuring. Addition of unit testing to map onto the new Decoders,Encoders and Converters --- .../rcsb/mmtf/api/DeserializerInterface.java | 12 + .../rcsb/mmtf/api/SerializerInterface.java | 8 - .../java/org/rcsb/mmtf/utils/CodecUtils.java | 19 ++ .../mmtf/dataholders/TestDataHolders.java | 208 +++++++++--------- .../mmtf/arraydecoders/DeltaDecompress.java | 74 ------- .../arraydecoders/RunLengthDecodeInt.java | 58 ----- .../mmtf/arraydecoders/RunLengthDelta.java | 75 ------- .../rcsb/mmtf/arraydecoders/package-info.java | 8 - .../rcsb/mmtf/decoder/ArrayConverters.java | 166 ++++++++++++++ .../org/rcsb/mmtf/decoder/ArrayDecoders.java | 86 +++----- .../{BeanToGetApi.java => BeanToGet.java} | 9 +- .../org/rcsb/mmtf/decoder/DecoderUtils.java | 108 --------- ...latorInterface.java => GetToInflator.java} | 8 +- .../MessagePackDeserializer.java | 19 +- .../java/org/rcsb/mmtf/examples/HandleIO.java | 8 +- .../TestArrayDecompressor.java | 91 -------- .../mmtf/decoder/TestArrayConverters.java | 134 +++++++++++ .../rcsb/mmtf/decoder/TestArrayDecoders.java | 42 ++++ .../rcsb/mmtf/decoder/TestDecoderUtils.java | 102 --------- .../rcsb/mmtf/encoder/ArrayConverters.java | 125 +++++++++++ .../org/rcsb/mmtf/encoder/ArrayEncoders.java | 119 ++++------ .../{GetApiToBean.java => GetToBean.java} | 4 +- ...erfaceToGetApi.java => InflatorToGet.java} | 2 +- .../serializers/MessagePackSerializer.java | 26 +++ .../mmtf/encoder/TestArrayCompressors.java | 73 ------ .../mmtf/encoder/TestArrayConverters.java | 5 + .../rcsb/mmtf/encoder/TestArrayEncoders.java | 37 ++++ .../rcsb/mmtf/encoder/TestEncoderUtils.java | 18 -- .../org/rcsb/mmtf/mappers/MapperUtils.java | 4 +- .../rcsb/mmtf/testutils/CheckOnRawApi.java | 4 +- .../org/rcsb/mmtf/update/TestingUtils.java | 8 +- 31 files changed, 765 insertions(+), 895 deletions(-) create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java create mode 100644 mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/DeltaDecompress.java delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDecodeInt.java delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/RunLengthDelta.java delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/arraydecoders/package-info.java create mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayConverters.java rename mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/{BeanToGetApi.java => BeanToGet.java} (96%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/{GetApiToInflatorInterface.java => GetToInflator.java} (97%) rename mmtf-common/src/main/java/org/rcsb/mmtf/sedeserializers/ByteArrayMessagePackConverter.java => mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java (60%) delete mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/arraydecompressors/TestArrayDecompressor.java create mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java create mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java delete mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDecoderUtils.java create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java rename mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/{GetApiToBean.java => GetToBean.java} (80%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/{InflatorInterfaceToGetApi.java => InflatorToGet.java} (99%) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java delete mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java delete mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java new file mode 100644 index 0000000..533d148 --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java @@ -0,0 +1,12 @@ +package org.rcsb.mmtf.api; + +public interface DeserializerInterface { + + /** + * Convert a byte array to an object to then be procesed. + * e.g. a messagepack byte array can be coverted to an MMTFBean. + * @param byteArray the input byte data + * @return the object with defined getters and setters + */ + Object deserialize(byte[] byteArray); +} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java index db42c85..75087c6 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java @@ -1,14 +1,6 @@ package org.rcsb.mmtf.api; public interface SerializerInterface { - - /** - * Convert a byte array to an object to then be procesed. - * e.g. a messagepack byte array can be coverted to an MMTFBean. - * @param byteArray the input byte data - * @return the object with defined getters and setters - */ - Object deserialize(byte[] byteArray); /** diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java b/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java new file mode 100644 index 0000000..1844fc0 --- /dev/null +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java @@ -0,0 +1,19 @@ +package org.rcsb.mmtf.utils; + +import java.util.List; + +public class CodecUtils { + + /** + * Convert a List to an int[] + * @param integerList the input list + * @return the output array + */ + public static int[] convertToIntArray(List integerList) { + int[] integerArray = new int[integerList.size()]; + for(int i=0; i outList = new ArrayList<>(); + for (int i=0; i testList = new ArrayList<>(); - //Loop through and add one, two, three and four character strings - for(int i = 0; i < NUM_EXAMPLES; i++){ - int numChars = randGenerator.nextInt(MAX_CHARS_PER_CHAIN); - if(numChars==0){ - numChars = 1; - } - int numBlank = MAX_CHARS_PER_CHAIN - numChars; - StringBuilder stringBuild = new StringBuilder(); - for(int j=0; j< numChars; j++){ - char c = (char)(randGenerator.nextInt(26) + 'a'); - stringBuild.append(c); - bos.write(c); - } - for(int j=0; j< numBlank; j++){ - - bos.write((byte) 0); - - } - testList.add(stringBuild.toString()); - } - int counter = 0; - byte[] testByteArr = bos.toByteArray(); - for(String testChainId : testList){ - assertEquals(testChainId, DecoderUtils.getChainId(testByteArr, counter)); - counter += 1; - } - - } - - @Test - public void bytesToIntsTests() throws IOException { - - // The input byte array of one byte integers - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int[] testIntArr = new int[NUM_EXAMPLES]; - // Get the int stream of random numbers - for(int i = 0; i < NUM_EXAMPLES; i++){ - int currInt = randGenerator.nextInt(); - bos.write(ByteBuffer.allocate(4).putInt(currInt).array()); - testIntArr[i] = currInt; - } - // Now check they are the same - assertArrayEquals(testIntArr, DecoderUtils.bytesToInts(bos.toByteArray())); - - - } - - @Test - public void bytesToByteIntsTests() throws IOException { - // The input byte array of one byte integers - byte[] inputByteArr = new byte[NUM_EXAMPLES]; - int[] testIntArr = new int[NUM_EXAMPLES]; - // Get the int stream of random numbers - for(int i = 0; i < NUM_EXAMPLES; i++){ - int currInt = randGenerator.nextInt(Byte.MAX_VALUE); - inputByteArr[i] = (byte) currInt; - testIntArr[i] = currInt; - } - assertArrayEquals(testIntArr, DecoderUtils.bytesToByteInts(inputByteArr)); - } - - @Test - public void convertIntToFloatTest() { - int[] inputData = {10213, 20303, 102, 183, 1021}; - float[] outPutData = {(float) 10.213, (float) 20.303, (float) 0.102, (float) 0.183, (float) 1.021}; - float [] outPutToTest = DecoderUtils.convertIntsToFloats(inputData, (float) 1000.0); - // Test they are the same length - assertEquals(outPutData.length, outPutToTest.length); - assertTrue(Arrays.equals(outPutData, outPutToTest)); - - } -} diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java new file mode 100644 index 0000000..08ade59 --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java @@ -0,0 +1,125 @@ +package org.rcsb.mmtf.encoder; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.rcsb.mmtf.utils.CodecUtils; + +/** + * A class of array converters. + * @author Anthony Bradley + * + */ +public class ArrayConverters { + + + /** + * Convert an integer array to byte array, where each integer is encoded by a + * single byte. + * @param intArray the input array of integers + * @return the byte array of the integers + * @throws IOException the byte array cannot be read + */ + public static byte[] convertIntegersToBytes(int[] intArray) throws IOException{ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + for(int i=0; i < intArray.length; ++i) + { + dos.writeByte(intArray[i]); + } + + return baos.toByteArray(); + } + + /** + * Convert an integer array to byte array, where each integer is encoded by a + * two bytes. + * @param intArray the input array of integers + * @return the byte array of the integers + * @throws IOException the byte array cannot be read + */ + public static byte[] convertIntegersToTwoBytes(int[] intArray) throws IOException{ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + for(int i=0; i < intArray.length; ++i) + { + dos.writeShort(intArray[i]); + } + + return baos.toByteArray(); + } + + /** + * Convert an integer array to byte array, where each integer is encoded by a + * four bytes. + * @param intArray the input array of integers + * @return the byte array of the integers + * @throws IOException the byte array cannot be read + */ + public static byte[] convertIntegersToFourByte(int[] intArray) throws IOException{ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + for(int i=0; i < intArray.length; ++i) + { + dos.writeShort(intArray[i]); + } + + return baos.toByteArray(); + } + + /** + * Convert an input array of integers to two arrays. The first output array is a + * four byte integer array. The integers in this array are in pairs. The first in + * each pair is part of the + * @param inputArray + * @return + */ + public static List splitIntegers(int[] inputArray) { + // set the two output arrays + List fourByteInts = new ArrayList<>(); + List twoByteInts = new ArrayList<>(); + // First element goes in the four byte integer array. + fourByteInts.add(inputArray[0]); + // Set the counter + int counter =0; + for(int i=1;iShort.MAX_VALUE || inputArray[i] < Short.MIN_VALUE){ + // Add the counter + fourByteInts.add(counter); + // Add the new four byte integer + fourByteInts.add(inputArray[i]); + // Counter set to zero + counter = 0; + } + else{ + // Little number added to little list + twoByteInts.add(inputArray[i]); + // Add to the counter + counter++; + } + } + // Finally add the counter to the big list + fourByteInts.add(counter); + // Now add these to a list - big first + List outputList = new ArrayList<>(); + outputList.add(CodecUtils.convertToIntArray(fourByteInts)); + outputList.add(CodecUtils.convertToIntArray(twoByteInts)); + return outputList; + } + + /** + * Convert a char array to an integer array using the ASCII code for characters + * @param charArray the input character array + * @return an integer array of ASCII decoded chars + */ + public static int[] convertCharToIntegers(char[] charArray) { + int[] outArray = new int[charArray.length]; + for (int i=0; i deltaEncode(final List inArray) { - List outArray = new ArrayList(); - int oldInt = 0; - for (int i = 0; i < inArray.size(); i++) { - // Get the value out here - int numInt = inArray.get(i); - // TODO Remove the if statement. - if (i==0){ - oldInt = numInt; - outArray.add(numInt); - } - else{ - int this_int = numInt - oldInt; - outArray.add((int) this_int); - oldInt = numInt; - } - } - return outArray; - } - - - public static List runlengthEncodeIntegers(List inArray) { + /** + * Delta encode an array of integers. + * @param intArray the input array + * @return the encoded array + */ + public static int[] deltaEncode(int[] intArray) { + int[] out = new int[intArray.length]; + System.arraycopy(intArray, 0, out, 0, intArray.length); + for (int i = out.length-1; i > 0; i--) { + out[i] = out[i] - out[i-1]; + } + return out; + } - List outArray = new ArrayList(); - int oldVal = 0; - boolean inSwitch = false; - int counter = 0; - // Loop through the vals - for (int i = 0; i < inArray.size(); i++) { - // Get the value out here - int num_int = inArray.get(i); - if(inSwitch==false){ - inSwitch=true; - // If it's a new number add it to the array - outArray.add(num_int); - counter=1; - oldVal=num_int; - } - else if (num_int!=oldVal){ - // Add the counter to the array - outArray.add(counter); - if(counter<0){ - System.out.println("THIS ERROR - "+counter); - } - // If it's a new number add it to the array - outArray.add(num_int); - counter=1; - oldVal=num_int; - } - else{ - counter+=1; - } + /** + * Run length encode an array of integers. + * @param intArray the input array + * @return the encoded integer array + */ + public static int[] runlengthEncode(int[] intArray) { + // We don't know the length so use + List outList = new ArrayList<>(); + int lastInt = intArray[0]; + int counter = 1; + for (int i=1; i runlengthEncodeStrings(List inArray) { - List outArray = new ArrayList(); - String oldVal = ""; - int counter = 0; - // Loop through the vals - for (int i = 0; i < inArray.size(); i++) { - // Get the value out here - String inString = inArray.get(i); - if (inString != oldVal){ - if(oldVal != ""){ - // Add the counter to the array - outArray.add(Integer.toString(counter)); - } - // If it's a new number add it to the array - outArray.add(inString); - counter = 1; - oldVal = inString; - } else { - counter += 1; - } - } - outArray.add(Integer.toString(counter)); - return outArray; - } + return CodecUtils.convertToIntArray(outList); + } } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java similarity index 80% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java index 3be215d..7fbaa97 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetApiToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java @@ -8,11 +8,11 @@ * @author Anthony Bradley * */ -public class GetApiToBean { +public class GetToBean { private MmtfBean mmtfBean; - public GetApiToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) { + public GetToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) { // DO THE ENCODING LOGIC HERE -> CONVERTING TO AN MMTF BEAN } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java similarity index 99% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java rename to mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java index ec319a6..de1dabf 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorInterfaceToGetApi.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java @@ -15,7 +15,7 @@ * @author Anthony Bradley * */ -public class InflatorInterfaceToGetApi implements MmtfDecodedDataInterface, MmtfDecoderInterface { +public class InflatorToGet implements MmtfDecodedDataInterface, MmtfDecoderInterface { /** The X coordinates */ diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java new file mode 100644 index 0000000..1a6ad3b --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java @@ -0,0 +1,26 @@ +package org.rcsb.mmtf.serializers; + +import org.msgpack.jackson.dataformat.MessagePackFactory; +import org.rcsb.mmtf.api.SerializerInterface; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class MessagePackSerializer implements SerializerInterface { + + @Override + public byte[] serialize(Object object) { + + ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); + byte[] byteArray; + try { + byteArray = objectMapper.writeValueAsBytes(object); + } catch (JsonProcessingException e) { + e.printStackTrace(); + byteArray = new byte[0]; + } + return byteArray; + } + + +} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java deleted file mode 100644 index fb53e4a..0000000 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayCompressors.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.rcsb.mmtf.encoder; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import static org.junit.Assert.*; - -public class TestArrayCompressors { - - @Test - public void deltaTest() { - // Create the two arrays - ArrayList inArray = new ArrayList(); - ArrayList testArray = new ArrayList(); - for(int i=0; i<1000;i++){ - inArray.add(i); - if(i==0){ - testArray.add(i); - } - else{ - testArray.add(1); - } - } - // Compress it - List deltadArray = ArrayEncoders.deltaEncode(inArray); - // Now check - assertEquals(deltadArray, testArray); - - } - - @Test - public void runLengthTest() { - // Generate the array - // Create the two arrays - List inArray = new ArrayList(); - List testArray = new ArrayList(); - int length = 1000; - for(int i=0; i runlenghtdArray = ArrayEncoders.runlengthEncodeIntegers(inArray); - // Now check - assertEquals(runlenghtdArray, testArray); - } - - - - @Test - public void runLengthStringTest() { - // Generate the array - // Create the two arrays - ArrayList inArray = new ArrayList(); - ArrayList testArray = new ArrayList(); - int length = 1000; - for(int i=0; i runlenghtdArray = ArrayEncoders.runlengthEncodeStrings(inArray); - // Now check - assertEquals(runlenghtdArray, testArray); - } -} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java new file mode 100644 index 0000000..60dee68 --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java @@ -0,0 +1,5 @@ +package org.rcsb.mmtf.encoder; + +public class TestArrayConverters { + +} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java new file mode 100644 index 0000000..9d49b77 --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java @@ -0,0 +1,37 @@ +package org.rcsb.mmtf.encoder; + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; + +/** + * Tests for the array decompressor library. + * @author Anthony Bradley + * + */ +public class TestArrayEncoders { + + /** + * Run length decode int test. + */ + @Test + public final void runLengthDecodeIntTest() { + // Allocate the byte array + int[] inputData = {15,15,15,100,100,111,111,111,111}; + int[] outputDataTest = {15,3,100,1,111,4}; + int[] outputData = ArrayEncoders.runlengthEncode(inputData); + assertArrayEquals(outputDataTest, outputData); + } + + /** + * Delta decode int test. + */ + @Test + public final void deltaDecodeIntTest() { + // Allocate the byte array + int[] inputData = {15,18,118,117,128,132}; + int[] outputDataTest = {15,3,100,-1,11,4}; + int[] outputData = ArrayEncoders.deltaEncode(inputData); + assertArrayEquals(outputDataTest, outputData); + } +} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java deleted file mode 100644 index b02a5bd..0000000 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.rcsb.mmtf.encoder; - -public class TestEncoderUtils { -// integersToBytes -// getMessagePack -// compressToMmtfBean -// convertRunLengthStringListToIntArray -// convertToIsoTime -// genGroupList -// addByteArrs -// integersToSmallBytes -// splitListIntsToByteArrays -// gzipCompress -// setChainId -// // These two should be moved out -// compressInputData -// compCAlpha -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index 05ab040..f35485f 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -11,7 +11,7 @@ import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; -import org.rcsb.mmtf.decoder.GetApiToInflatorInterface; +import org.rcsb.mmtf.decoder.GetToInflator; /** * A class to preserve the log if the functions in mappers. @@ -33,7 +33,7 @@ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) MmtfStructureReader bjs = new MmtfStructureReader(); Structure newStruct; try{ - GetApiToInflatorInterface ds = new GetApiToInflatorInterface(inputByteArr); + GetToInflator ds = new GetToInflator(inputByteArr); ds.getStructFromByteArray(bjs); newStruct = bjs.getStructure(); newStruct.setPDBCode(pdbCodePlus.substring(0,4));} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java index b983f16..73d14b6 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java @@ -13,7 +13,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.io.FileParsingParameters; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.decoder.BeanToGetApi; +import org.rcsb.mmtf.decoder.BeanToGet; /** * Class to test the raw API @@ -23,7 +23,7 @@ public class CheckOnRawApi { MmtfDecodedDataInterface dataApi; public CheckOnRawApi(byte[] inputData) { - dataApi = new BeanToGetApi(inputData); + dataApi = new BeanToGet(inputData); } /** diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index 4d612a7..c1ff762 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -11,8 +11,8 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; -import org.rcsb.mmtf.decoder.GetApiToInflatorInterface; -import org.rcsb.mmtf.encoder.GetApiToBean; +import org.rcsb.mmtf.decoder.GetToInflator; +import org.rcsb.mmtf.encoder.GetToBean; import org.rcsb.mmtf.testutils.CheckOnBiojava; import org.rcsb.mmtf.testutils.CheckOnRawApi; @@ -63,7 +63,7 @@ public Structure roundTripStruct(String pdbId, FileParsingParameters params, Ato params.setUseInternalChainId(true); cache.setFileParsingParams(params); StructureIO.setAtomCache(cache); - GetApiToBean es = new GetApiToBean(); + GetToBean es = new GetToBean(); Structure mmcifStruct = StructureIO.getStructure(pdbId); FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromPdbId(pdbId, new BiojavaEncoderImpl())); byte[] inArr = FileUtils.readFileToByteArray(new File("pathname")); @@ -72,7 +72,7 @@ public Structure roundTripStruct(String pdbId, FileParsingParameters params, Ato checkRaw.checkRawDataConsistency(mmcifStruct, params); // Now decode the data and return this new structure MmtfStructureReader bjsi = new MmtfStructureReader(); - GetApiToInflatorInterface decodeStructure = new GetApiToInflatorInterface(inArr); + GetToInflator decodeStructure = new GetToInflator(inArr); decodeStructure.getStructFromByteArray(bjsi); Structure struct = bjsi.getStructure(); // Revert back From b276a24e13ca7bd020ab6f9ccc21643f337ad667 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 11:45:44 -0700 Subject: [PATCH 062/108] Updated the decoder to the new static methods --- .../java/org/rcsb/mmtf/decoder/BeanToGet.java | 78 +++++++++++++------ .../org/rcsb/mmtf/decoder/DecoderUtils.java | 0 2 files changed, 54 insertions(+), 24 deletions(-) delete mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java index 6932da3..2549178 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java @@ -5,9 +5,6 @@ import java.util.List; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.arraydecoders.DeltaDecompress; -import org.rcsb.mmtf.arraydecoders.RunLengthDecodeInt; -import org.rcsb.mmtf.arraydecoders.RunLengthDelta; import org.rcsb.mmtf.dataholders.BioAssemblyData; import org.rcsb.mmtf.dataholders.Entity; import org.rcsb.mmtf.dataholders.MmtfBean; @@ -20,39 +17,72 @@ */ public class BeanToGet implements MmtfDecodedDataInterface { - public BeanToGet(MmtfBean inputData) { - + // Get the data try { - groupList = DecoderUtils.bytesToInts(inputData.getGroupTypeList()); - // Read the byte arrays as int arrays - cartnX = DecoderUtils.convertIntsToFloats(deltaDecompress.decompressByteArray(inputData.getxCoordBig(), inputData.getxCoordSmall()), MmtfBean.COORD_DIVIDER); - cartnY = DecoderUtils.convertIntsToFloats(deltaDecompress.decompressByteArray(inputData.getyCoordBig(), inputData.getyCoordSmall()), MmtfBean.COORD_DIVIDER); - cartnZ = DecoderUtils.convertIntsToFloats(deltaDecompress.decompressByteArray(inputData.getzCoordBig(), inputData.getzCoordSmall()), MmtfBean.COORD_DIVIDER); - bFactor = DecoderUtils.convertIntsToFloats(deltaDecompress.decompressByteArray(inputData.getbFactorBig(),inputData.getbFactorSmall()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); - occupancy = DecoderUtils.convertIntsToFloats(intRunLength.decompressByteArray(inputData.getOccupancyList()), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); - atomId = intRunLengthDelta.decompressByteArray(inputData.getAtomIdList()); - altId = ArrayDecoders.runLengthDecodeStrings(inputData.getAltLocList()); - // Get the insertion code - insertionCodeList = ArrayDecoders.runLengthDecodeStrings(inputData.getInsCodeList()); + groupList = ArrayConverters.convertByteToIntegers(inputData.getGroupTypeList()); + // Decode the coordinate and B-factor arrays. + cartnX = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getxCoordBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getxCoordSmall()))), + MmtfBean.COORD_DIVIDER); + cartnY = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getyCoordBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getyCoordSmall()))), + MmtfBean.COORD_DIVIDER); + cartnZ = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getzCoordBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getzCoordSmall()))), + MmtfBean.COORD_DIVIDER); + bFactor = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getbFactorBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getbFactorSmall()))), + MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); + // Run length decode the occupancy array + occupancy = ArrayConverters.convertIntsToFloats( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers(inputData.getOccupancyList())), + MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); + // Run length and delta + atomId = ArrayDecoders.deltaDecode( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers(inputData.getAtomIdList()))); + // Run length encoded + altId = ArrayConverters.convertIntegerToChar( + ArrayDecoders.runlengthDecode(inputData.getAltLocList())); + insertionCodeList = ArrayConverters.convertIntegerToChar( + ArrayDecoders.runlengthDecode(inputData.getInsCodeList())); + // Get the groupNumber - groupNum = intRunLengthDelta.decompressByteArray( + groupNum = ArrayConverters.convertByteToIntegers( inputData.getGroupIdList()); + // Get the group map (all the unique groups in the structure). groupMap = inputData.getGroupList(); // Get the seqRes groups - seqResGroupList = intRunLengthDelta.decompressByteArray(inputData.getSequenceIdList()); + seqResGroupList = ArrayDecoders.deltaDecode( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers( + inputData.getSequenceIdList()))); // Get the number of chains per model chainsPerModel = inputData.getChainsPerModel(); groupsPerChain = inputData.getGroupsPerChain(); // Get the internal and public facing chain ids - publicChainIds = DecoderUtils.decodeChainList(inputData.getChainNameList()); - chainList = DecoderUtils.decodeChainList(inputData.getChainIdList()); + publicChainIds = ArrayConverters.decodeChainList(inputData.getChainNameList()); + chainList = ArrayConverters.decodeChainList(inputData.getChainIdList()); spaceGroup = inputData.getSpaceGroup(); unitCell = inputData.getUnitCell(); bioAssembly = inputData.getBioAssemblyList(); - interGroupBondIndices = DecoderUtils.bytesToInts(inputData.getBondAtomList()); - interGroupBondOrders = DecoderUtils.bytesToByteInts(inputData.getBondOrderList()); + interGroupBondIndices = ArrayConverters.convertFourByteToIntegers(inputData.getBondAtomList()); + interGroupBondOrders = ArrayConverters.convertByteToIntegers(inputData.getBondOrderList()); mmtfVersion = inputData.getMmtfVersion(); mmtfProducer = inputData.getMmtfProducer(); entityList = inputData.getEntityList(); @@ -166,10 +196,10 @@ public BeanToGet(MmtfBean inputData) { /** The list of experimental methods. */ private String[] experimentalMethods; - + /** The deposition date of hte structure */ private String depositionDate; - + @Override public float[] getxCoords() { diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java deleted file mode 100644 index e69de29..0000000 From 3d10c62fa0ffd1c253cb57697f4624ad2003b832 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 13:06:54 -0700 Subject: [PATCH 063/108] Update to the encoder to follow the same path as the decoder. Upstream refactoring too. --- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 7 +- .../java/org/rcsb/mmtf/utils/CodecUtils.java | 18 +- .../java/org/rcsb/mmtf/decoder/BeanToGet.java | 161 +++++++++--------- .../org/rcsb/mmtf/decoder/GetToInflator.java | 4 +- .../mmtf/examples/DemoUnpackStructure.java | 5 +- .../java/org/rcsb/mmtf/examples/HandleIO.java | 3 +- .../org/rcsb/mmtf/examples/HelloWorld.java | 4 +- .../rcsb/mmtf/encoder/ArrayConverters.java | 59 +++++++ .../org/rcsb/mmtf/encoder/EncoderUtils.java | 85 +++++++++ .../java/org/rcsb/mmtf/encoder/GetToBean.java | 117 ++++++++++++- .../org/rcsb/mmtf/encoder/InflatorToGet.java | 2 +- 11 files changed, 365 insertions(+), 100 deletions(-) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 7af8161..81b4c95 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -126,7 +126,7 @@ public class MmtfBean implements Serializable { private byte[] sequenceIdList; /** The experimental method(s). */ - private List experimentalMethods; + private String[] experimentalMethods; /** The resolution in Angstrom. Null if not applicable*/ private float resolution; @@ -784,14 +784,14 @@ public final void setChainIdList(final byte[] inputInternalChainList) { /** * @return the experimental methods */ - public List getExperimentalMethods() { + public String[] getExperimentalMethods() { return experimentalMethods; } /** * @param experimentalMethods the experimental methods to set */ - public void setExperimentalMethods(List experimentalMethods) { + public void setExperimentalMethods(String[] experimentalMethods) { this.experimentalMethods = experimentalMethods; } @@ -840,4 +840,5 @@ public void setDepositionDate(String depositionDate) { } + } diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java b/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java index 1844fc0..231520f 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java @@ -5,7 +5,7 @@ public class CodecUtils { /** - * Convert a List to an int[] + * Convert an integer list to an integer array * @param integerList the input list * @return the output array */ @@ -16,4 +16,20 @@ public static int[] convertToIntArray(List integerList) { } return integerArray; } + + /** + * Find the highest value in an integer array. + * @param intArray the integer array + * @return the highester value in the array + */ + public static int findMaxInIntArray(int[] intArray){ + int max=intArray[0]; + + for (int i = 0; i < intArray.length; i++) { + if (intArray[i] > max) { + max = intArray[i]; + } + } + return max; + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java index 2549178..c011c92 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToGet.java @@ -17,91 +17,82 @@ */ public class BeanToGet implements MmtfDecodedDataInterface { - public BeanToGet(MmtfBean inputData) { - - // Get the data - try { - groupList = ArrayConverters.convertByteToIntegers(inputData.getGroupTypeList()); - // Decode the coordinate and B-factor arrays. - cartnX = ArrayConverters.convertIntsToFloats( - ArrayDecoders.deltaDecode( - ArrayConverters.combineIntegers( - ArrayConverters.convertTwoByteToIntegers(inputData.getxCoordBig()), - ArrayConverters.convertFourByteToIntegers(inputData.getxCoordSmall()))), - MmtfBean.COORD_DIVIDER); - cartnY = ArrayConverters.convertIntsToFloats( - ArrayDecoders.deltaDecode( - ArrayConverters.combineIntegers( - ArrayConverters.convertTwoByteToIntegers(inputData.getyCoordBig()), - ArrayConverters.convertFourByteToIntegers(inputData.getyCoordSmall()))), - MmtfBean.COORD_DIVIDER); - cartnZ = ArrayConverters.convertIntsToFloats( - ArrayDecoders.deltaDecode( - ArrayConverters.combineIntegers( - ArrayConverters.convertTwoByteToIntegers(inputData.getzCoordBig()), - ArrayConverters.convertFourByteToIntegers(inputData.getzCoordSmall()))), - MmtfBean.COORD_DIVIDER); - bFactor = ArrayConverters.convertIntsToFloats( - ArrayDecoders.deltaDecode( - ArrayConverters.combineIntegers( - ArrayConverters.convertTwoByteToIntegers(inputData.getbFactorBig()), - ArrayConverters.convertFourByteToIntegers(inputData.getbFactorSmall()))), - MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); - // Run length decode the occupancy array - occupancy = ArrayConverters.convertIntsToFloats( - ArrayDecoders.runlengthDecode( - ArrayConverters.convertFourByteToIntegers(inputData.getOccupancyList())), - MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); - // Run length and delta - atomId = ArrayDecoders.deltaDecode( - ArrayDecoders.runlengthDecode( - ArrayConverters.convertFourByteToIntegers(inputData.getAtomIdList()))); - // Run length encoded - altId = ArrayConverters.convertIntegerToChar( - ArrayDecoders.runlengthDecode(inputData.getAltLocList())); - insertionCodeList = ArrayConverters.convertIntegerToChar( - ArrayDecoders.runlengthDecode(inputData.getInsCodeList())); - - // Get the groupNumber - groupNum = ArrayConverters.convertByteToIntegers( - inputData.getGroupIdList()); - // Get the group map (all the unique groups in the structure). - groupMap = inputData.getGroupList(); - // Get the seqRes groups - seqResGroupList = ArrayDecoders.deltaDecode( - ArrayDecoders.runlengthDecode( - ArrayConverters.convertFourByteToIntegers( - inputData.getSequenceIdList()))); - // Get the number of chains per model - chainsPerModel = inputData.getChainsPerModel(); - groupsPerChain = inputData.getGroupsPerChain(); - // Get the internal and public facing chain ids - publicChainIds = ArrayConverters.decodeChainList(inputData.getChainNameList()); - chainList = ArrayConverters.decodeChainList(inputData.getChainIdList()); - spaceGroup = inputData.getSpaceGroup(); - unitCell = inputData.getUnitCell(); - bioAssembly = inputData.getBioAssemblyList(); - interGroupBondIndices = ArrayConverters.convertFourByteToIntegers(inputData.getBondAtomList()); - interGroupBondOrders = ArrayConverters.convertByteToIntegers(inputData.getBondOrderList()); - mmtfVersion = inputData.getMmtfVersion(); - mmtfProducer = inputData.getMmtfProducer(); - entityList = inputData.getEntityList(); - pdbId = inputData.getStructureId(); - // Now get the header data - rFree = inputData.getrFree(); - // Optional fields - rWork = inputData.getrWork(); - resolution = inputData.getResolution(); - title = inputData.getTitle(); - experimentalMethods = inputData.getExperimentalMethods().toArray(new String[0]); - // Now get the relase information - depositionDate = inputData.getDepositionDate(); - } - catch (IOException ioException){ - System.err.println("Error reading in byte arrays from message pack"); - ioException.printStackTrace(); - throw new RuntimeException(); - } + public BeanToGet(MmtfBean inputData) throws IOException { + groupList = ArrayConverters.convertFourByteToIntegers(inputData.getGroupTypeList()); + // Decode the coordinate and B-factor arrays. + cartnX = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getxCoordBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getxCoordSmall()))), + MmtfBean.COORD_DIVIDER); + cartnY = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getyCoordBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getyCoordSmall()))), + MmtfBean.COORD_DIVIDER); + cartnZ = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getzCoordBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getzCoordSmall()))), + MmtfBean.COORD_DIVIDER); + bFactor = ArrayConverters.convertIntsToFloats( + ArrayDecoders.deltaDecode( + ArrayConverters.combineIntegers( + ArrayConverters.convertTwoByteToIntegers(inputData.getbFactorBig()), + ArrayConverters.convertFourByteToIntegers(inputData.getbFactorSmall()))), + MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); + // Run length decode the occupancy array + occupancy = ArrayConverters.convertIntsToFloats( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers(inputData.getOccupancyList())), + MmtfBean.OCCUPANCY_BFACTOR_DIVIDER); + // Run length and delta + atomId = ArrayDecoders.deltaDecode( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers(inputData.getAtomIdList()))); + // Run length encoded + altId = ArrayConverters.convertIntegerToChar( + ArrayDecoders.runlengthDecode(inputData.getAltLocList())); + insertionCodeList = ArrayConverters.convertIntegerToChar( + ArrayDecoders.runlengthDecode(inputData.getInsCodeList())); + + // Get the groupNumber + groupNum = ArrayConverters.convertByteToIntegers( + inputData.getGroupIdList()); + // Get the group map (all the unique groups in the structure). + groupMap = inputData.getGroupList(); + // Get the seqRes groups + seqResGroupList = ArrayDecoders.deltaDecode( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers( + inputData.getSequenceIdList()))); + // Get the number of chains per model + chainsPerModel = inputData.getChainsPerModel(); + groupsPerChain = inputData.getGroupsPerChain(); + // Get the internal and public facing chain ids + publicChainIds = ArrayConverters.decodeChainList(inputData.getChainNameList()); + chainList = ArrayConverters.decodeChainList(inputData.getChainIdList()); + spaceGroup = inputData.getSpaceGroup(); + unitCell = inputData.getUnitCell(); + bioAssembly = inputData.getBioAssemblyList(); + interGroupBondIndices = ArrayConverters.convertFourByteToIntegers(inputData.getBondAtomList()); + interGroupBondOrders = ArrayConverters.convertByteToIntegers(inputData.getBondOrderList()); + mmtfVersion = inputData.getMmtfVersion(); + mmtfProducer = inputData.getMmtfProducer(); + entityList = inputData.getEntityList(); + pdbId = inputData.getStructureId(); + // Now get the header data + rFree = inputData.getrFree(); + // Optional fields + rWork = inputData.getrWork(); + resolution = inputData.getResolution(); + title = inputData.getTitle(); + experimentalMethods = inputData.getExperimentalMethods(); + // Now get the relase information + depositionDate = inputData.getDepositionDate(); } /** The X coordinates */ diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java index 9ff1556..f12343a 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java @@ -1,5 +1,6 @@ package org.rcsb.mmtf.decoder; +import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -35,8 +36,9 @@ public class GetToInflator { /** * The constructor requires a byte array to fill the data. This will decompress the arrays using our bespoke methods. * @param byteArray An unentropy encoded byte array with the data as found in the MMTF format + * @throws IOException */ - public GetToInflator(byte[] byteArray) { + public GetToInflator(byte[] byteArray) throws IOException { // Create the instance of this API dataApi = new BeanToGet(new MessagePackDeserializer().deserialize(byteArray)); } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java index 42be39e..50ef6cc 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java @@ -1,5 +1,7 @@ package org.rcsb.mmtf.examples; +import java.io.IOException; + import org.rcsb.mmtf.api.MmtfDecodedDataInterface; /** @@ -12,8 +14,9 @@ public class DemoUnpackStructure { /** * Main function to run the demo class * @param args no args required + * @throws IOException */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { // Create an instance of the handle IO class HandleIO handleIO = new HandleIO(); // The index of a given chain diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java index 62c62d4..45b07b2 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java @@ -57,8 +57,9 @@ public final byte[] getByteArrFromUrlOrFile(final String inputCode) { * Gets the data API from a url. * @param inputCode the input code * @return + * @throws IOException */ - public final MmtfDecodedDataInterface getDataApiFromUrlOrFile(final String inputCode) { + public final MmtfDecodedDataInterface getDataApiFromUrlOrFile(final String inputCode) throws IOException { String basePath = getBasePath(); boolean isFile = getFile(basePath, inputCode); // If it's a file on the file system - get it diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java index 9701903..a370795 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java @@ -1,10 +1,12 @@ package org.rcsb.mmtf.examples; +import java.io.IOException; + import org.rcsb.mmtf.api.MmtfDecodedDataInterface; public class HelloWorld { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { HandleIO handleIO = new HandleIO(); MmtfDecodedDataInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); System.out.println("PDB Code: "+dataApi.getStructureId()+" has "+dataApi.getNumChains()+" chains"); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java index 08ade59..38c6081 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java @@ -69,6 +69,21 @@ public static byte[] convertIntegersToFourByte(int[] intArray) throws IOExceptio return baos.toByteArray(); } + + /** + * Convert a float array to an integer array by multiplying by a float. + * @param intArray the input integer array to be divided + * @param floatDivider the float divider to divide the integers by. + * @return a float array converted from the input. + */ + public static int[] convertFloatsToInts(float[] floatArray, float floatMultiplier) { + // Assign the output array to write + int[] outArray = new int[floatArray.length]; + for (int i=0; i1){ + byteArr[chainIndex*4+1] = (byte) outChar[1]; + } + else{ + byteArr[chainIndex*4+1] = (byte) 0; + } + if(chainIdLen>2){ + byteArr[chainIndex*4+2] = (byte) outChar[2]; + } + else{ + byteArr[chainIndex*4+2] = (byte) 0; + } + if(chainIdLen>3){ + byteArr[chainIndex*4+3] = (byte) outChar[3]; + } + else{ + byteArr[chainIndex*4+3] = (byte) 0; + } + } } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java new file mode 100644 index 0000000..f40f3e5 --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java @@ -0,0 +1,85 @@ +package org.rcsb.mmtf.encoder; + +import java.util.ArrayList; +import java.util.List; + +import org.rcsb.mmtf.api.MmtfDecodedDataInterface; +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.BioAssemblyTrans; +import org.rcsb.mmtf.dataholders.Entity; +import org.rcsb.mmtf.dataholders.PDBGroup; +import org.rcsb.mmtf.utils.CodecUtils; + +public class EncoderUtils { + + /** + * Regenerate a group map from the decoded data interface. + * @param mmtfDecodedDataInterface the input interface + * @return a list of all the groups in the molecule + */ + public static PDBGroup[] generateGroupMap(MmtfDecodedDataInterface mmtfDecodedDataInterface) { + int[] groupTypeIndices = mmtfDecodedDataInterface.getGroupTypeIndices(); + int maxIndex = CodecUtils.findMaxInIntArray(groupTypeIndices); + PDBGroup[] outGroupList = new PDBGroup[maxIndex+1]; + for (int i=0; i generateBioassemblies(MmtfDecodedDataInterface mmtfDecodedDataInterface) { + int numBioassemblies = mmtfDecodedDataInterface.getNumBioassemblies(); + List outList = new ArrayList<>(); + for (int i=0; i transformList = new ArrayList<>(); + bioAssemblyData.setTransforms(transformList); + int numTrans = mmtfDecodedDataInterface.getNumTransInBioassembly(i); + for (int j=0; j xCoords = ArrayConverters.splitIntegers( + ArrayEncoders.deltaEncode( + ArrayConverters.convertFloatsToInts( + mmtfDecodedDataInterface.getxCoords(), + MmtfBean.COORD_DIVIDER))); + mmtfBean.setxCoordBig(ArrayConverters.convertIntegersToFourByte(xCoords.get(0))); + mmtfBean.setxCoordSmall(ArrayConverters.convertIntegersToTwoBytes(xCoords.get(1))); + + List yCoords = ArrayConverters.splitIntegers( + ArrayEncoders.deltaEncode( + ArrayConverters.convertFloatsToInts( + mmtfDecodedDataInterface.getyCoords(), + MmtfBean.COORD_DIVIDER))); + mmtfBean.setyCoordBig(ArrayConverters.convertIntegersToFourByte(yCoords.get(0))); + mmtfBean.setyCoordSmall(ArrayConverters.convertIntegersToTwoBytes(yCoords.get(1))); + + List zCoords = ArrayConverters.splitIntegers( + ArrayEncoders.deltaEncode( + ArrayConverters.convertFloatsToInts( + mmtfDecodedDataInterface.getzCoords(), + MmtfBean.COORD_DIVIDER))); + mmtfBean.setzCoordBig(ArrayConverters.convertIntegersToFourByte(zCoords.get(0))); + mmtfBean.setzCoordSmall(ArrayConverters.convertIntegersToTwoBytes(zCoords.get(1))); + + + List bFactor = ArrayConverters.splitIntegers( + ArrayEncoders.deltaEncode( + ArrayConverters.convertFloatsToInts( + mmtfDecodedDataInterface.getbFactors(), + MmtfBean.OCCUPANCY_BFACTOR_DIVIDER))); + mmtfBean.setbFactorBig(ArrayConverters.convertIntegersToFourByte(bFactor.get(0))); + mmtfBean.setbFactorSmall(ArrayConverters.convertIntegersToTwoBytes(bFactor.get(1))); + + + // Run length decode the occupancy array + mmtfBean.setOccupancyList(ArrayConverters.convertIntegersToFourByte( + ArrayEncoders.runlengthEncode( + ArrayConverters.convertFloatsToInts( + mmtfDecodedDataInterface.getOccupancies(), + MmtfBean.OCCUPANCY_BFACTOR_DIVIDER)))); + + // Run length and delta + mmtfBean.setAtomIdList(ArrayConverters.convertIntegersToFourByte( + ArrayEncoders.runlengthEncode( + ArrayEncoders.deltaEncode(mmtfDecodedDataInterface.getAtomIds())))); + // Run length encoded + mmtfBean.setAltLocList(ArrayEncoders.runlengthEncode( + ArrayConverters.convertCharToIntegers(mmtfDecodedDataInterface.getAltLocIds()))); + mmtfBean.setInsCodeList(ArrayEncoders.runlengthEncode( + ArrayConverters.convertCharToIntegers(mmtfDecodedDataInterface.getInsCodes()))); + + // Get the groupNumber + mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( + mmtfDecodedDataInterface.getGroupTypeIndices())); + + // Get the group map (all the unique groups in the structure). + mmtfBean.setGroupList(EncoderUtils.generateGroupMap(mmtfDecodedDataInterface)); + // Get the seqRes groups + mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( + ArrayEncoders.deltaEncode( + ArrayEncoders.runlengthEncode( + mmtfDecodedDataInterface.getGroupIds())))); + // Get the number of chains per model + mmtfBean.setChainsPerModel(mmtfDecodedDataInterface.getChainsPerModel()); + mmtfBean.setGroupsPerChain(mmtfDecodedDataInterface.getGroupsPerChain()); + // Get the internal and public facing chain ids + mmtfBean.setChainNameList(ArrayConverters.encodeChainList(mmtfDecodedDataInterface.getChainNames())); + mmtfBean.setChainIdList(ArrayConverters.encodeChainList(mmtfDecodedDataInterface.getChainIds())); + + mmtfBean.setSpaceGroup(mmtfDecodedDataInterface.getSpaceGroup()); + mmtfBean.setUnitCell(mmtfDecodedDataInterface.getUnitCell()); + + mmtfBean.setBioAssemblyList( + EncoderUtils.generateBioassemblies(mmtfDecodedDataInterface)); + mmtfBean.setEntityList( + EncoderUtils.generateEntityList(mmtfDecodedDataInterface) + ); - // DO THE ENCODING LOGIC HERE -> CONVERTING TO AN MMTF BEAN + mmtfBean.setBondOrderList(ArrayConverters.convertIntegersToFourByte( + mmtfDecodedDataInterface.getInterGroupBondOrders())); + mmtfBean.setBondAtomList(ArrayConverters.convertIntegersToFourByte( + mmtfDecodedDataInterface.getInterGroupBondIndices())); + + mmtfBean.setMmtfVersion(mmtfDecodedDataInterface.getMmtfVersion()); + mmtfBean.setMmtfProducer(mmtfDecodedDataInterface.getMmtfProducer()); + mmtfBean.setStructureId(mmtfDecodedDataInterface.getStructureId()); + // Now get the header data + mmtfBean.setrFree(mmtfDecodedDataInterface.getRfree()); + // Optional fields + mmtfBean.setrWork(mmtfDecodedDataInterface.getRwork()); + mmtfBean.setResolution(mmtfDecodedDataInterface.getResolution()); + mmtfBean.setTitle(mmtfDecodedDataInterface.getTitle()); + mmtfBean.setExperimentalMethods(mmtfDecodedDataInterface.getExperimentalMethods()); + // Now get the relase information + mmtfBean.setDepositionDate(mmtfDecodedDataInterface.getDepositionDate()); } - + public MmtfBean getMmtfBean() { return mmtfBean; } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java index de1dabf..2468a15 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java @@ -11,7 +11,7 @@ import org.rcsb.mmtf.dataholders.PDBGroup; /** - * A class for the encoding data api. + * A class to move data from the DecoderInterface to the DecodedDataInterface * @author Anthony Bradley * */ From c0b0fde0b997d0e6562bbe07db07252b34306ca6 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 13:30:44 -0700 Subject: [PATCH 064/108] Finished writing unit tests (tests pass) and the Encoder converters and encoders. --- .../mmtf/decoder/TestArrayConverters.java | 2 +- .../rcsb/mmtf/encoder/ArrayConverters.java | 2 +- .../org/rcsb/mmtf/encoder/ArrayEncoders.java | 4 + .../mmtf/encoder/TestArrayConverters.java | 129 ++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java index 33fb6a4..cc54588 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java @@ -46,7 +46,7 @@ public final void testConvertIntToFloat() { @Test public final void oneByteToIntegersTest() throws IOException { int[] testIntArray = {12,123,24}; - byte[] byteArray = getByteArray(testIntArray,1); + byte[] byteArray = {(byte) 12, (byte) 123, (byte) 24}; int[] intArray = ArrayConverters.convertByteToIntegers(byteArray); assertArrayEquals(testIntArray, intArray); } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java index 38c6081..5a7998a 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java @@ -64,7 +64,7 @@ public static byte[] convertIntegersToFourByte(int[] intArray) throws IOExceptio DataOutputStream dos = new DataOutputStream(baos); for(int i=0; i < intArray.length; ++i) { - dos.writeShort(intArray[i]); + dos.writeInt(intArray[i]); } return baos.toByteArray(); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java index ad92e18..44a6e83 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java @@ -50,6 +50,10 @@ public static int[] runlengthEncode(int[] intArray) { lastInt = intArray[i]; } } + // Now add the last two + outList.add(lastInt); + outList.add(counter+1); + return CodecUtils.convertToIntArray(outList); } } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java index 60dee68..915364c 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java @@ -1,5 +1,134 @@ package org.rcsb.mmtf.encoder; +import static org.junit.Assert.assertArrayEquals; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; + +import org.junit.Test; + public class TestArrayConverters { + + /** + * Test the decoding of the chain list + */ + @Test + public final void testSetChain() { + String[] stringList = {"A","ABC","abc"}; + byte[] testByteArray = {'A','\0','\0','\0', + 'A','B','C','\0', + 'a','b','c','\0'}; + byte[] byteArray = ArrayConverters.encodeChainList(stringList); + assertArrayEquals(testByteArray, byteArray); + } + + + /** + * Test the conversion of the integer array to a float + */ + @Test + public final void testConvertFloatToInt() { + float[] floatArray = {10.001f,100.203f,124.542f}; + int[] testIntArray = {10001,100203,124542}; + float multiplier = 1000.0f; + int[] intArray = ArrayConverters.convertFloatsToInts(floatArray, multiplier); + assertArrayEquals(testIntArray, intArray); + } + + + /** + * Test the conversion of byte arrays to one byte integer arrays + * @throws IOException + */ + @Test + public final void integersToOneByteTest() throws IOException { + int[] intArray = {12,123,24}; + byte[] testByteArray = {(byte) 12,(byte) 123, (byte) 24}; + byte[] byteArray = ArrayConverters.convertIntegersToBytes(intArray); + assertArrayEquals(testByteArray, byteArray); + } + + /** + * Test the conversion of byte arrays to two byte integer arrays + * @throws IOException + */ + @Test + public final void integersToTwoByteTest() throws IOException { + int[] intArray = {1000,1002,546}; + byte[] testByteArray = getByteArray(intArray,2); + byte[] byteArray = ArrayConverters.convertIntegersToTwoBytes(intArray); + assertArrayEquals(testByteArray, byteArray); + } + + /** + * Test the conversion of byte arrays to four byte integer arrays + * @throws IOException + */ + @Test + public final void integersToFourByteTest() throws IOException { + int[] intArray = {32403,11200,100090}; + byte[] testByteArray = getByteArray(intArray,4); + byte[] byteArray = ArrayConverters.convertIntegersToFourByte(intArray); + assertArrayEquals(testByteArray, byteArray); + } + + + /** + * Test the conversion of integer arrays to char arrays. + */ + @Test + public final void splitArraysTest() { + // Initialise the two input arrays + int[] testTwoByteIntArray = {1,2,5,4,50,0}; + int[] testFourByteIntArray = {10002,4,1303040,2}; + // The expected output + int[] combinedArray = {10002,1,2,5,4,1303040,50,0}; + List outVal = ArrayConverters.splitIntegers(combinedArray); + assertArrayEquals(testFourByteIntArray, outVal.get(0)); + assertArrayEquals(testTwoByteIntArray, outVal.get(1)); + } + + + /** + * Test the conversion of integer arrays to char arrays. + */ + @Test + public final void charToIntTest() { + int[] testIntArray = {66,63,67}; + char[] charArray= {'B','?','C'}; + int[] intArray = ArrayConverters.convertCharToIntegers(charArray); + assertArrayEquals(testIntArray, intArray); + } + + /** + * Utiliy function to get a byte array. I don't really like this but at least + * it's an orthogonal approach. + * @param inArray the input int array + * @param numBytes the number of bytes per integer + * @return the output byte array + */ + private byte[] getByteArray(int[] inArray, int numBytes) { + byte[] outBytes = new byte[inArray.length*numBytes]; + for(int i=0; i Date: Fri, 8 Apr 2016 13:39:20 -0700 Subject: [PATCH 065/108] Set the group to sequence mapping indices better. --- .../java/org/rcsb/mmtf/encoder/GetToBean.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java index 281d282..c3bff35 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java @@ -77,16 +77,16 @@ public GetToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws IOExc ArrayConverters.convertCharToIntegers(mmtfDecodedDataInterface.getInsCodes()))); // Get the groupNumber - mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( - mmtfDecodedDataInterface.getGroupTypeIndices())); - - // Get the group map (all the unique groups in the structure). - mmtfBean.setGroupList(EncoderUtils.generateGroupMap(mmtfDecodedDataInterface)); - // Get the seqRes groups mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.deltaEncode( ArrayEncoders.runlengthEncode( mmtfDecodedDataInterface.getGroupIds())))); + + // Get the group map (all the unique groups in the structure). + mmtfBean.setGroupList(EncoderUtils.generateGroupMap(mmtfDecodedDataInterface)); + // Get the indices for the groups mapping to the sequence + mmtfBean.setSequenceIdList(ArrayConverters.convertIntegersToFourByte( + mmtfDecodedDataInterface.getGroupSequenceIndices())); // Get the number of chains per model mmtfBean.setChainsPerModel(mmtfDecodedDataInterface.getChainsPerModel()); mmtfBean.setGroupsPerChain(mmtfDecodedDataInterface.getGroupsPerChain()); @@ -120,6 +120,9 @@ public GetToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws IOExc mmtfBean.setExperimentalMethods(mmtfDecodedDataInterface.getExperimentalMethods()); // Now get the relase information mmtfBean.setDepositionDate(mmtfDecodedDataInterface.getDepositionDate()); + // + mmtfBean.setSequenceIdList(ArrayConverters.convertIntegersToFourByte( + mmtfDecodedDataInterface.getGroupSequenceIndices())); } public MmtfBean getMmtfBean() { From b4fcd119dbb060c9de0f4b4351b99bd5fe82b1ba Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 13:41:59 -0700 Subject: [PATCH 066/108] Remove setter repetition --- .../java/org/rcsb/mmtf/encoder/GetToBean.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java index c3bff35..edda9a2 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/GetToBean.java @@ -59,7 +59,7 @@ public GetToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws IOExc mmtfBean.setbFactorSmall(ArrayConverters.convertIntegersToTwoBytes(bFactor.get(1))); - // Run length decode the occupancy array + // Run length encode the occupancy array mmtfBean.setOccupancyList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( ArrayConverters.convertFloatsToInts( @@ -76,53 +76,48 @@ public GetToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws IOExc mmtfBean.setInsCodeList(ArrayEncoders.runlengthEncode( ArrayConverters.convertCharToIntegers(mmtfDecodedDataInterface.getInsCodes()))); - // Get the groupNumber + // Set the groupNumber mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.deltaEncode( ArrayEncoders.runlengthEncode( mmtfDecodedDataInterface.getGroupIds())))); - // Get the group map (all the unique groups in the structure). + // Set the group map (all the unique groups in the structure). mmtfBean.setGroupList(EncoderUtils.generateGroupMap(mmtfDecodedDataInterface)); - // Get the indices for the groups mapping to the sequence + // Set the indices for the groups mapping to the sequence mmtfBean.setSequenceIdList(ArrayConverters.convertIntegersToFourByte( mmtfDecodedDataInterface.getGroupSequenceIndices())); - // Get the number of chains per model + // Set the number of chains per model mmtfBean.setChainsPerModel(mmtfDecodedDataInterface.getChainsPerModel()); mmtfBean.setGroupsPerChain(mmtfDecodedDataInterface.getGroupsPerChain()); - // Get the internal and public facing chain ids + // Set the internal and public facing chain ids mmtfBean.setChainNameList(ArrayConverters.encodeChainList(mmtfDecodedDataInterface.getChainNames())); mmtfBean.setChainIdList(ArrayConverters.encodeChainList(mmtfDecodedDataInterface.getChainIds())); - + // Set the space group information mmtfBean.setSpaceGroup(mmtfDecodedDataInterface.getSpaceGroup()); mmtfBean.setUnitCell(mmtfDecodedDataInterface.getUnitCell()); - + // Set the bioassembly and entity information mmtfBean.setBioAssemblyList( EncoderUtils.generateBioassemblies(mmtfDecodedDataInterface)); mmtfBean.setEntityList( EncoderUtils.generateEntityList(mmtfDecodedDataInterface) ); - + // Set the bond orders and indcices mmtfBean.setBondOrderList(ArrayConverters.convertIntegersToFourByte( mmtfDecodedDataInterface.getInterGroupBondOrders())); mmtfBean.setBondAtomList(ArrayConverters.convertIntegersToFourByte( mmtfDecodedDataInterface.getInterGroupBondIndices())); - + // Set the version and producer information mmtfBean.setMmtfVersion(mmtfDecodedDataInterface.getMmtfVersion()); mmtfBean.setMmtfProducer(mmtfDecodedDataInterface.getMmtfProducer()); mmtfBean.setStructureId(mmtfDecodedDataInterface.getStructureId()); - // Now get the header data + // Set some header data mmtfBean.setrFree(mmtfDecodedDataInterface.getRfree()); - // Optional fields mmtfBean.setrWork(mmtfDecodedDataInterface.getRwork()); mmtfBean.setResolution(mmtfDecodedDataInterface.getResolution()); mmtfBean.setTitle(mmtfDecodedDataInterface.getTitle()); mmtfBean.setExperimentalMethods(mmtfDecodedDataInterface.getExperimentalMethods()); - // Now get the relase information mmtfBean.setDepositionDate(mmtfDecodedDataInterface.getDepositionDate()); - // - mmtfBean.setSequenceIdList(ArrayConverters.convertIntegersToFourByte( - mmtfDecodedDataInterface.getGroupSequenceIndices())); } public MmtfBean getMmtfBean() { From 7fe0b97a44c786d9b95804c43db529c0548175da Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 14:21:57 -0700 Subject: [PATCH 067/108] Moved the serializer tests to update --- .../mmtf/dataholders/TestDataHolders.java | 103 ----------------- .../mmtf/mappers/DataStructToByteArrs.java | 6 +- .../mmtf/sedeserializers}/FailureBean.java | 5 +- .../mmtf/sedeserializers/TestDataHolders.java | 105 ++++++++++++++++++ 4 files changed, 112 insertions(+), 107 deletions(-) delete mode 100644 mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java rename {mmtf-common/src/test/java/org/rcsb/mmtf/dataholders => mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers}/FailureBean.java (99%) create mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java deleted file mode 100644 index eaebbe5..0000000 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ /dev/null @@ -1,103 +0,0 @@ -//package org.rcsb.mmtf.dataholders; -// TODO FIX THESE TESTS -// -//import static org.junit.Assert.assertFalse; -//import static org.junit.Assert.assertTrue; -// -//import java.io.IOException; -// -//import org.junit.Test; -//import org.msgpack.jackson.dataformat.MessagePackFactory; -//import org.unitils.reflectionassert.ReflectionAssert; -// -//import com.fasterxml.jackson.core.JsonParseException; -//import com.fasterxml.jackson.databind.JsonMappingException; -//import com.fasterxml.jackson.databind.ObjectMapper; -// -//import uk.co.jemos.podam.api.PodamFactory; -// -//public class TestDataHolders { -// -// private PodamFactory factory; -// -// public TestDataHolders() { -// -// } -// -// @Test -// public void testSerializable() throws JsonParseException, JsonMappingException, IOException { -// // MmtfBean -// assertTrue(testClass(MmtfBean.class)); -// // This one fails - make sure it still does -// assertFalse(testClass(BioAssemblyData.class)); -// // Now test round tripping data -// testDataRoundTrip(MmtfBean.class); -// // Now check that the failure bean fails this -// // Now test round tripping data -// assertFalse(testDataRoundTrip(FailureBean.class)); -// } -// -// @SuppressWarnings("unchecked") -// private boolean testClass(@SuppressWarnings("rawtypes") Class class1) throws IOException { -// -// -// Object inBean = null; -// try { -// inBean = class1.newInstance(); -// } catch (InstantiationException | IllegalAccessException e2) { -// // Weirdness -// org.junit.Assert.fail("Weirdness in generating instance of generic class"); -// } -// byte[] outArr = null; -// -// outArr = encoderUtils.getMessagePack(inBean); -// -// // -// Object outBean = null; -// try { -// outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); -// } catch( JsonMappingException jsonE){ -// System.out.println("Error reading messagepack - is part of test if test doesn't fail"); -// return false; -// } -// -// // Now check they're the same -// ReflectionAssert.assertReflectionEquals(inBean, outBean); -// return true; -// } -// -// /** -// * Test round tripping dummy data -// * @param class1 -// */ -// private boolean testDataRoundTrip(@SuppressWarnings("rawtypes") Class class1) throws JsonParseException, JsonMappingException, IOException { -// Object inBean = factory.manufacturePojo(class1); -// byte[] outArr = null; -// -// outArr = encoderUtils.getMessagePack(inBean); -// -// -// // -// Object outBean = null; -// outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); -// -// // Make the failure bean fail -// try{ -// ReflectionAssert.assertPropertyReflectionEquals("fieldWithNoGetters",null, outBean); -// ReflectionAssert.assertPropertyReflectionEquals("fieldWithRefactoredGetters",null, outBean); -// return false; -// } -// catch(Exception e){ -// -// } -// // Make sure all fields are re-populated -// ReflectionAssert.assertPropertiesNotNull("Some properties are null in re-read object", outBean); -// -// // Now check they're the same -// ReflectionAssert.assertReflectionEquals(inBean, outBean); -// return true; -// } -//} -// -// -// diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java index feca12d..92f5744 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java @@ -7,11 +7,11 @@ import org.apache.spark.api.java.function.PairFlatMapFunction; import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; -import org.rcsb.mmtf.dataholders.BioDataStruct; -import org.rcsb.mmtf.dataholders.CalphaDistBean; -import org.rcsb.mmtf.dataholders.HeaderBean; import org.rcsb.mmtf.encoder.EncoderInterface; import org.rcsb.mmtf.encoder.EncoderUtils; +import org.rcsb.mmtf.sedeserializers.BioDataStruct; +import org.rcsb.mmtf.sedeserializers.CalphaDistBean; +import org.rcsb.mmtf.sedeserializers.HeaderBean; import scala.Tuple2; diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/FailureBean.java similarity index 99% rename from mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java rename to mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/FailureBean.java index df8cb4b..bfbaf75 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/FailureBean.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/FailureBean.java @@ -1,8 +1,11 @@ -package org.rcsb.mmtf.dataholders; +package org.rcsb.mmtf.sedeserializers; import java.util.List; import java.util.Map; +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.PDBGroup; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java new file mode 100644 index 0000000..5aef1c1 --- /dev/null +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java @@ -0,0 +1,105 @@ +package org.rcsb.mmtf.sedeserializers; +// TODO FIX THESE TESTS + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Test; +import org.msgpack.jackson.dataformat.MessagePackFactory; +import org.rcsb.mmtf.dataholders.BioAssemblyData; +import org.rcsb.mmtf.dataholders.MmtfBean; +import org.unitils.reflectionassert.ReflectionAssert; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import uk.co.jemos.podam.api.PodamFactory; + +public class TestDataHolders { + + private PodamFactory factory; + + public TestDataHolders() { + + } + + @Test + public void testSerializable() throws JsonParseException, JsonMappingException, IOException { + // MmtfBean + assertTrue(testClass(MmtfBean.class)); + // This one fails - make sure it still does + assertFalse(testClass(BioAssemblyData.class)); + // Now test round tripping data + testDataRoundTrip(MmtfBean.class); + // Now check that the failure bean fails this + // Now test round tripping data + assertFalse(testDataRoundTrip(FailureBean.class)); + } + + @SuppressWarnings("unchecked") + private boolean testClass(@SuppressWarnings("rawtypes") Class class1) throws IOException { + + + Object inBean = null; + try { + inBean = class1.newInstance(); + } catch (InstantiationException | IllegalAccessException e2) { + // Weirdness + org.junit.Assert.fail("Weirdness in generating instance of generic class"); + } + byte[] outArr = null; + + outArr = encoderUtils.getMessagePack(inBean); + + // + Object outBean = null; + try { + outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); + } catch( JsonMappingException jsonE){ + System.out.println("Error reading messagepack - is part of test if test doesn't fail"); + return false; + } + + // Now check they're the same + ReflectionAssert.assertReflectionEquals(inBean, outBean); + return true; + } + + /** + * Test round tripping dummy data + * @param class1 + */ + private boolean testDataRoundTrip(@SuppressWarnings("rawtypes") Class class1) throws JsonParseException, JsonMappingException, IOException { + Object inBean = factory.manufacturePojo(class1); + byte[] outArr = null; + + outArr = encoderUtils.getMessagePack(inBean); + + + // + Object outBean = null; + outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); + + // Make the failure bean fail + try{ + ReflectionAssert.assertPropertyReflectionEquals("fieldWithNoGetters",null, outBean); + ReflectionAssert.assertPropertyReflectionEquals("fieldWithRefactoredGetters",null, outBean); + return false; + } + catch(Exception e){ + + } + // Make sure all fields are re-populated + ReflectionAssert.assertPropertiesNotNull("Some properties are null in re-read object", outBean); + + // Now check they're the same + ReflectionAssert.assertReflectionEquals(inBean, outBean); + return true; + } +} + + + From c49bfe73ac2bed6f5b3bfe521a3688371728b429 Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 15:45:35 -0700 Subject: [PATCH 068/108] Added a reader and writer interface. GettoInflator now implements the reader interface --- .../java/org/rcsb/mmtf/api/MmtfReader.java | 6 +++++ .../java/org/rcsb/mmtf/api/MmtfWriter.java | 7 +++++ .../org/rcsb/mmtf/decoder/GetToInflator.java | 27 +++++++++---------- 3 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java create mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java new file mode 100644 index 0000000..62ab3ad --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java @@ -0,0 +1,6 @@ +package org.rcsb.mmtf.api; + +public interface MmtfReader { + + public void read(MmtfDecodedDataInterface mmtfDecodedDataInterface, MmtfDecoderInterface mmtfDecoderInterface); +} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java new file mode 100644 index 0000000..7b1c213 --- /dev/null +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java @@ -0,0 +1,7 @@ +package org.rcsb.mmtf.api; + +public interface MmtfWriter { + + public void write(MmtfDecoderInterface decoder); + +} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java index f12343a..8273019 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/GetToInflator.java @@ -6,7 +6,7 @@ import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.api.MmtfDecoderInterface; -import org.rcsb.mmtf.deserializers.MessagePackDeserializer; +import org.rcsb.mmtf.api.MmtfReader; /** * Decode an MMTF structure using a structure inflator. @@ -15,9 +15,7 @@ * @author Anthony Bradley * */ -public class GetToInflator { - - +public class GetToInflator implements MmtfReader { /** The struct inflator. */ private MmtfDecoderInterface structInflator; @@ -38,21 +36,19 @@ public class GetToInflator { * @param byteArray An unentropy encoded byte array with the data as found in the MMTF format * @throws IOException */ - public GetToInflator(byte[] byteArray) throws IOException { - // Create the instance of this API - dataApi = new BeanToGet(new MessagePackDeserializer().deserialize(byteArray)); + public GetToInflator() throws IOException { + } /** - * Generate a structure from bytes using a structure inflator. - * @param inputStructInflator the structure inflator to be used - * @param parsingParams the parsing parameters object to be used when inflating. + * Passes data from the data interface to the inflator interface. */ - public final void getStructFromByteArray(final MmtfDecoderInterface inputStructInflator) { - // Set the inflator - structInflator = inputStructInflator; + public void read(MmtfDecodedDataInterface inputApi, MmtfDecoderInterface inputInflator){ + // Set the api and the inflator + dataApi = inputApi; + structInflator = inputInflator; // Do any required preparation - inputStructInflator.initStructure(dataApi.getNumAtoms(), dataApi.getNumGroups(), dataApi.getNumChains(), dataApi.getNumModels(), dataApi.getStructureId()); + structInflator.initStructure(dataApi.getNumAtoms(), dataApi.getNumGroups(), dataApi.getNumChains(), dataApi.getNumModels(), dataApi.getStructureId()); // Now add the atom information addAtomicInformation(); // Now add the header information. @@ -68,7 +64,7 @@ public final void getStructFromByteArray(final MmtfDecoderInterface inputStructI // Now do any required cleanup structInflator.finalizeStructure(); } - + /** * Add the main atomic information to the data model */ @@ -237,4 +233,5 @@ private void generateBioAssembly() { + } From 2f179c003412d2a05d017d5fc727cd4aec3e498e Mon Sep 17 00:00:00 2001 From: abradle Date: Fri, 8 Apr 2016 19:53:43 -0700 Subject: [PATCH 069/108] Refactoring of the code and tests in mmtf-update. All compile errors and warnings removed. --- mmtf-common/pom.xml | 12 --- .../org/rcsb/mmtf/encoder/InflatorToGet.java | 17 +-- mmtf-update/pom.xml | 31 ++++-- .../mmtf/mappers/DataStructToByteArrs.java | 52 --------- .../org/rcsb/mmtf/mappers/MapperUtils.java | 20 ++-- .../rcsb/mmtf/mappers/PdbIdToDataStruct.java | 40 ------- .../org/rcsb/mmtf/mappers/PdbIdToMmtf.java | 25 +++++ .../mmtf/postupdatetests/CheckServer.java | 4 +- .../preupdatetests/DataConsistencyCheck.java | 8 +- .../rcsb/mmtf/testutils/CheckOnRawApi.java | 6 +- .../rcsb/mmtf/update/BuildFirstDataSet.java | 6 +- .../org/rcsb/mmtf/update/TestingUtils.java | 101 +++++------------- .../rcsb/mmtf/integrationtest/TestBonds.java | 5 +- .../mmtf/integrationtest/TestParseMMCif.java | 51 ++------- .../mmtf/sedeserializers/TestDataHolders.java | 55 ++-------- 15 files changed, 121 insertions(+), 312 deletions(-) delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java create mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java diff --git a/mmtf-common/pom.xml b/mmtf-common/pom.xml index 3a182dc..ab70836 100644 --- a/mmtf-common/pom.xml +++ b/mmtf-common/pom.xml @@ -17,18 +17,6 @@ - - org.unitils - unitils-core - 3.4.2 - test - - - uk.co.jemos.podam - podam - 2.3.5.RELEASE - test - org.msgpack jackson-dataformat-msgpack diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java index 2468a15..ed23f62 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/InflatorToGet.java @@ -129,7 +129,7 @@ public class InflatorToGet implements MmtfDecodedDataInterface, MmtfDecoderInter /** Add the atom information for the current group */ PDBGroup pdbGroup; /** A List for Entities as the number of entities is not defined*/ - List entities = new ArrayList<>(); + List entities; @Override @@ -394,8 +394,8 @@ public String getDepositionDate() { // Now provide the capability to fill this data. @Override - public void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, - String structureId) { + public void initStructure(int totalNumAtoms, int totalNumGroups, + int totalNumChains, int totalNumModels, String structureId) { // Intitialise the atom level arrays cartnX = new float[totalNumAtoms]; cartnY= new float[totalNumAtoms]; @@ -409,11 +409,16 @@ public void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumCha seqResGroupList = new int[totalNumGroups]; groupList = new int[totalNumGroups]; // Intialise the chain level data + chainList = new String[totalNumChains]; + publicChainIds = new String[totalNumChains]; + groupsPerChain = new int[totalNumChains]; // Initialise the model level information numModels = totalNumModels; // Set the name pdbId = structureId; - + bioAssembly = new ArrayList<>(); + entities = new ArrayList<>(); + chainsPerModel = new int[totalNumModels]; } @Override @@ -471,8 +476,6 @@ public void setGroupInfo(String groupName, int groupNumber, char insertionCode, pdbGroup.setGroupName(groupName); pdbGroup.setSingleLetterCode(insertionCode); groupAtomIndex=0; - - // Store the group level data groupNum[groupIndex] = groupNumber; seqResGroupList[groupIndex] = sequenceIndex; @@ -503,7 +506,7 @@ public void setAtomInfo(String atomName, int serialNumber, char alternativeLocat public void setBioAssemblyTrans(int bioAssemblyIndex, int[] chainIndices, double[] transform) { BioAssemblyData bioAssemblyData; List bioAssemblyTranList; - if (bioAssembly.size()>bioAssemblyIndex) { + if (bioAssembly.size() + 4.0.0 org.rcsb @@ -16,11 +17,11 @@ - - org.biojava - biojava-structure - 5.0.0-SNAPSHOT - + + org.biojava + biojava-structure + 5.0.0-SNAPSHOT + junit @@ -51,6 +52,18 @@ spark-core_2.11 1.6.0 + + org.unitils + unitils-core + 3.4.2 + test + + + uk.co.jemos.podam + podam + 2.3.5.RELEASE + test + @@ -88,10 +101,12 @@ - + reference.conf - + akka.Main diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java deleted file mode 100644 index 92f5744..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/DataStructToByteArrs.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.rcsb.mmtf.mappers; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.spark.api.java.function.PairFlatMapFunction; -import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; -import org.rcsb.mmtf.encoder.EncoderInterface; -import org.rcsb.mmtf.encoder.EncoderUtils; -import org.rcsb.mmtf.sedeserializers.BioDataStruct; -import org.rcsb.mmtf.sedeserializers.CalphaDistBean; -import org.rcsb.mmtf.sedeserializers.HeaderBean; - -import scala.Tuple2; - -/** - * A class to generate the three (or more) byte arrays from the data structure parsed by the MMCIF. - * Returns three byte arrays per PDB id. - * @author Anthony Bradley - * - */ -public class DataStructToByteArrs implements PairFlatMapFunction, String, byte[]>{ - - private static final long serialVersionUID = 2066093446043635571L; - - @Override - public Iterable> call(Tuple2 t) throws IOException, IllegalAccessException, InvocationTargetException { - // First generate the list to return - List> outList = new ArrayList>(); - EncoderUtils cm = new EncoderUtils(); - EncoderInterface cbs = t._2; - String pdbCode = t._1; - // Now get the header too - HeaderBean headerData = cbs.getHeaderStruct(); - BioDataStruct thisBS = cbs.getBioStruct(); - CalphaDistBean calphaDistStruct = cm.compressCalpha(cbs.getCalphaStruct(), cbs.getHeaderStruct()); - // NOW JUST WRITE THE KEY VALUE PAIRS HERE - byte[] totBytes = cm.getMessagePack(cm.compressToMmtfBean(thisBS, headerData)); - byte[] headerBytes = cm.getMessagePack(headerData); - byte[] calphaBytes = cm.getMessagePack(calphaDistStruct); - // Add the total data - outList.add(new Tuple2(pdbCode+"_total", totBytes)); - // Add the header - outList.add(new Tuple2(pdbCode+"_header", headerBytes)); - // Add the calpha - outList.add(new Tuple2(pdbCode+"_calpha", calphaBytes)); - return outList; - - } -} \ No newline at end of file diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index f35485f..4667a16 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -9,9 +9,8 @@ import org.apache.spark.api.java.JavaSparkContext; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; -import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; -import org.rcsb.mmtf.decoder.GetToInflator; +import org.biojava.nbio.structure.io.mmtf.MmtfActions; +import org.biojava.nbio.structure.io.mmtf.MmtfUtils; /** * A class to preserve the log if the functions in mappers. @@ -30,13 +29,10 @@ public class MapperUtils implements Serializable{ * @return */ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) { - MmtfStructureReader bjs = new MmtfStructureReader(); Structure newStruct; try{ - GetToInflator ds = new GetToInflator(inputByteArr); - ds.getStructFromByteArray(bjs); - newStruct = bjs.getStructure(); - newStruct.setPDBCode(pdbCodePlus.substring(0,4));} + newStruct = MmtfActions.getBiojavaStruct(inputByteArr); + } catch(Exception e){ System.out.println(e); System.out.println(pdbCodePlus); @@ -52,12 +48,10 @@ public Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) * @return */ public JavaPairRDD generateRDD(JavaSparkContext sparkContext, List inputList, String inputUrl) { - // Set up Biojava appropriateyl - BiojavaUtils biojavaUtils = new BiojavaUtils(); - biojavaUtils.setUpBioJava(inputUrl); + // Set up Biojava appropriateyl + MmtfUtils.setUpBioJava(); return sparkContext.parallelize(inputList) - .mapToPair(new PdbIdToDataStruct()) - .flatMapToPair(new DataStructToByteArrs()) + .mapToPair(new PdbIdToMmtf()) .mapToPair(new StringByteToTextByteWriter()); } } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java deleted file mode 100644 index 67321cd..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToDataStruct.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.rcsb.mmtf.mappers; - - -import java.util.HashMap; -import java.util.Map; -import org.apache.spark.api.java.function.PairFunction; -import org.rcsb.mmtf.biojavaencoder.BiojavaEncoderImpl; -import org.rcsb.mmtf.dataholders.PDBGroup; - -import scala.Tuple2; - -/** - * Generate the internal data structure (using biojava) from a PDB code. - * @author Anthony Bradley - * - */ -public class PdbIdToDataStruct implements PairFunction{ - - private static final long serialVersionUID = 786599975302506694L; - - @Override - public Tuple2 call(String t) throws Exception { - BiojavaEncoderImpl cbs = new BiojavaEncoderImpl(); - Map totMap = new HashMap(); - try{ - cbs.generateDataStructuresFromPdbId(t, totMap); - } - catch(Exception e){ - // Just return the object - System.out.println(e+" :: "+t); - System.out.println(e.getMessage()); - return new Tuple2(t,cbs); - } - // If it doesn't fail also return the object - return new Tuple2(t,cbs); - } - - -} - diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java new file mode 100644 index 0000000..42713b5 --- /dev/null +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java @@ -0,0 +1,25 @@ +package org.rcsb.mmtf.mappers; + + +import org.apache.spark.api.java.function.PairFunction; +import org.biojava.nbio.structure.io.mmtf.MmtfActions; + +import scala.Tuple2; + +/** + * Generate the internal data structure (using biojava) from a PDB code. + * @author Anthony Bradley + * + */ +public class PdbIdToMmtf implements PairFunction{ + + private static final long serialVersionUID = 786599975302506694L; + + @Override + public Tuple2 call(String t) throws Exception { + return new Tuple2(t, MmtfActions.getByteArray(t)); + } + + +} + diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index f3e9036..ebdc642 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -8,7 +8,7 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; +import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.examples.HandleIO; import org.rcsb.mmtf.testutils.CheckOnBiojava; @@ -64,7 +64,7 @@ public void basicParsingTest(String baseUrl) throws IOException { private void testParsing(String inputPdb, String inputUrl) throws IOException { System.out.println("TESTING: "+inputPdb); byte[] inputByteArr = handleIo.getFromUrl(inputPdb, inputUrl); - Structure mmtfStruct = MmtfStructureReader.getBiojavaStruct(inputByteArr); + Structure mmtfStruct = MmtfActions.getBiojavaStruct(inputByteArr); // Now parse from the MMCIF file Structure mmcifStruct; try { diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java index 3fd4913..6da0306 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java @@ -7,8 +7,6 @@ import java.util.List; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.update.ServerUtils; import org.rcsb.mmtf.update.TestingUtils; @@ -38,14 +36,13 @@ public static void main(String[] args) throws IllegalAccessException, Invocation // Set up the atom cache etc ServerUtils serverUtils = new ServerUtils(); - AtomCache cache = MmtfUtils.setUpBioJava(args[3]); + MmtfUtils.setUpBioJava(args[3]); // Now get the list of PDB ids to ignore List ignoreList = new ArrayList<>(); for (int i=4; i distData = sc.parallelize(pdbCodeList) - .mapToPair(new PdbIdToDataStruct()) - .flatMapToPair(new DataStructToByteArrs()) + .mapToPair(new PdbIdToMmtf()) .mapToPair(new StringByteToTextByteWriter()); // Now save this as a Hadoop sequence file String uri = args[1]; diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index c1ff762..5b6222b 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -1,86 +1,41 @@ package org.rcsb.mmtf.update; -import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import org.apache.commons.io.FileUtils; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; -import org.rcsb.mmtf.decoder.GetToInflator; -import org.rcsb.mmtf.encoder.GetToBean; +import org.biojava.nbio.structure.io.mmtf.MmtfActions; +import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.testutils.CheckOnBiojava; -import org.rcsb.mmtf.testutils.CheckOnRawApi; public class TestingUtils { - /** - * Function to round trip everything based on the current params - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws IOException - * @throws StructureException - */ - public void testAll(String[] inputList, FileParsingParameters params, AtomCache cache) throws IllegalAccessException, InvocationTargetException, IOException, StructureException{ - StructureIO.setAtomCache(cache); - for (String pdbId : inputList){ - testOne(pdbId, params, cache); - } - - } - - /** - * Function just to test one structure. - * @param pdbId - * @param params - * @param cache - * @param mmtfParams - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws IOException - * @throws StructureException - */ - public void testOne(String pdbId, FileParsingParameters params, AtomCache cache) throws IllegalAccessException, InvocationTargetException, IOException, StructureException { - CheckOnBiojava checkEquiv = new CheckOnBiojava(); - Structure structure = StructureIO.getStructure(pdbId); - checkEquiv.checkIfStructuresSame(structure,roundTripStruct(pdbId, params, cache)); - } - /** - * - * @return - * @throws IOException - * @throws StructureException - * @throws InvocationTargetException - * @throws IllegalAccessException - */ - public Structure roundTripStruct(String pdbId, FileParsingParameters params, AtomCache cache) throws IOException, IllegalAccessException, InvocationTargetException, StructureException{ - // We need to set the parsing params to this - boolean oldValue = params.isUseInternalChainId(); - params.setUseInternalChainId(true); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - GetToBean es = new GetToBean(); - Structure mmcifStruct = StructureIO.getStructure(pdbId); - FileUtils.writeByteArrayToFile(new File("pathname"), es.encodeFromPdbId(pdbId, new BiojavaEncoderImpl())); - byte[] inArr = FileUtils.readFileToByteArray(new File("pathname")); - // Now do the checks on the Raw data - CheckOnRawApi checkRaw = new CheckOnRawApi(inArr); - checkRaw.checkRawDataConsistency(mmcifStruct, params); - // Now decode the data and return this new structure - MmtfStructureReader bjsi = new MmtfStructureReader(); - GetToInflator decodeStructure = new GetToInflator(inArr); - decodeStructure.getStructFromByteArray(bjsi); - Structure struct = bjsi.getStructure(); - // Revert back - params.setUseInternalChainId(oldValue); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - return struct; - } - + /** + * Test a set of PDB ids found in the string list + * @param inputList the list of PDB ids to test + * @throws IOException + * @throws StructureException + */ + public static void testList(String[] inputList) throws IOException, StructureException{ + MmtfUtils.setUpBioJava(); + for (String pdbId : inputList){ + testSingleStructure(pdbId); + } + } + + /** + * Round trip and check a structure given by its PDB id + * @param pdbId the string PDB id for the structure + * @throws IOException + * @throws StructureException + */ + public static void testSingleStructure(String pdbId) throws IOException, StructureException { + CheckOnBiojava checkEquiv = new CheckOnBiojava(); + Structure structure = StructureIO.getStructure(pdbId); + checkEquiv.checkIfStructuresSame(structure,MmtfActions.roundTrip(structure)); + } + + } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java index ad6e43b..23d7d5a 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java @@ -5,8 +5,8 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.junit.Test; -import org.rcsb.mmtf.biojavaencoder.BiojavaUtils; import org.rcsb.mmtf.testutils.CheckBonds; import org.rcsb.mmtf.update.IntegrationTestUtils; @@ -28,8 +28,7 @@ public class TestBonds { public void testBondConsistency() throws IOException, StructureException { CheckBonds testUtils = new CheckBonds(); // Set up biojava - BiojavaUtils biojavaUtils = new BiojavaUtils(); - biojavaUtils.setUpBioJava(); + MmtfUtils.setUpBioJava(); for (String testCase : IntegrationTestUtils.TEST_CASES) { Structure structure = StructureIO.getStructure(testCase); testUtils.checkIfBondsExist(structure); diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java index 03168b8..1e4a25d 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java @@ -4,20 +4,14 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; +import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.junit.Test; import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.dataholders.PDBGroup; -import org.rcsb.mmtf.encoder.EncoderUtils; import org.rcsb.mmtf.update.IntegrationTestUtils; import org.rcsb.mmtf.update.TestingUtils; +import org.unitils.reflectionassert.ReflectionAssert; /** * Tests to see if parsing using Biojava using mmCIF and mmtf produces the same data structure. @@ -26,33 +20,10 @@ */ public class TestParseMMCif { - private AtomCache cache; - private FileParsingParameters params; - private TestingUtils testingUtils = new TestingUtils(); - - public TestParseMMCif(){ - // Set up biojava - cache = MmtfUtils.setUpBioJava(); - params = cache.getFileParsingParams(); - } - - @Test - public void testAsymChainIds() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { - // Set the params - params.setUseInternalChainId(true); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); - } - - @Test - public void testAuthChainIds() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { - // Set the param - params.setUseInternalChainId(false); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - testingUtils.testAll(IntegrationTestUtils.TEST_CASES, params, cache); + public void testAll() throws IOException, StructureException, IllegalAccessException, InvocationTargetException { + TestingUtils.testList(IntegrationTestUtils.TEST_CASES); + testDataComplete("4cup"); } /** @@ -60,15 +31,9 @@ public void testAuthChainIds() throws IOException, StructureException, IllegalAc * @throws StructureException * @throws IOException */ - private void testDataComplete(String pdbId) throws IOException { - - // Utility functions for encoding stuff - EncoderUtils eu = new EncoderUtils(); - // Get the utility class to get the structures - - MmtfBean mmtfBean = null; - // Compress the data and get it back out - mmtfBean = eu.compressToMmtfBean(parsedDataStruct.getBioStruct(), parsedDataStruct.getHeaderStruct()); + private void testDataComplete(String pdbId) throws IOException, StructureException { + // Get an mmtfBean + MmtfBean mmtfBean = MmtfActions.getBean(pdbId); // Make sure all fields are re-populated ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); // Now check the standard ones have been set diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java index 5aef1c1..6cb3cf2 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java @@ -2,19 +2,17 @@ // TODO FIX THESE TESTS import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import java.io.IOException; import org.junit.Test; -import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.dataholders.BioAssemblyData; import org.rcsb.mmtf.dataholders.MmtfBean; +import org.rcsb.mmtf.deserializers.MessagePackDeserializer; +import org.rcsb.mmtf.serializers.MessagePackSerializer; import org.unitils.reflectionassert.ReflectionAssert; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; import uk.co.jemos.podam.api.PodamFactory; @@ -28,61 +26,24 @@ public TestDataHolders() { @Test public void testSerializable() throws JsonParseException, JsonMappingException, IOException { - // MmtfBean - assertTrue(testClass(MmtfBean.class)); - // This one fails - make sure it still does - assertFalse(testClass(BioAssemblyData.class)); - // Now test round tripping data + // Now test the data round tripping testDataRoundTrip(MmtfBean.class); // Now check that the failure bean fails this // Now test round tripping data assertFalse(testDataRoundTrip(FailureBean.class)); } - @SuppressWarnings("unchecked") - private boolean testClass(@SuppressWarnings("rawtypes") Class class1) throws IOException { - - - Object inBean = null; - try { - inBean = class1.newInstance(); - } catch (InstantiationException | IllegalAccessException e2) { - // Weirdness - org.junit.Assert.fail("Weirdness in generating instance of generic class"); - } - byte[] outArr = null; - - outArr = encoderUtils.getMessagePack(inBean); - - // - Object outBean = null; - try { - outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); - } catch( JsonMappingException jsonE){ - System.out.println("Error reading messagepack - is part of test if test doesn't fail"); - return false; - } - - // Now check they're the same - ReflectionAssert.assertReflectionEquals(inBean, outBean); - return true; - } - /** * Test round tripping dummy data * @param class1 */ private boolean testDataRoundTrip(@SuppressWarnings("rawtypes") Class class1) throws JsonParseException, JsonMappingException, IOException { + @SuppressWarnings("unchecked") Object inBean = factory.manufacturePojo(class1); - byte[] outArr = null; - - outArr = encoderUtils.getMessagePack(inBean); - - - // - Object outBean = null; - outBean = new ObjectMapper(new MessagePackFactory()).readValue(outArr, class1); - + MessagePackSerializer messagePackSerializer = new MessagePackSerializer(); + byte[] outArr = messagePackSerializer.serialize(inBean); + MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); + Object outBean = messagePackDeserializer.deserialize(outArr); // Make the failure bean fail try{ ReflectionAssert.assertPropertyReflectionEquals("fieldWithNoGetters",null, outBean); From 830ae39608eb46deaaced866074b68596697295b Mon Sep 17 00:00:00 2001 From: abradle Date: Sat, 9 Apr 2016 00:58:11 -0700 Subject: [PATCH 070/108] Some more refactoring and lyering to get the update module to work. Improvements in te deflator and some debugging. --- .../mmtf/api/MmtfDecodedDataInterface.java | 7 ++++- .../rcsb/mmtf/api/MmtfDecoderInterface.java | 7 +++-- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 2 +- .../org/rcsb/mmtf/decoder/ArrayDecoders.java | 2 +- .../java/org/rcsb/mmtf/decoder/BeanToGet.java | 28 ++++++++++++------- .../org/rcsb/mmtf/decoder/GetToInflator.java | 5 ++-- .../java/org/rcsb/mmtf/encoder/GetToBean.java | 1 + .../org/rcsb/mmtf/encoder/InflatorToGet.java | 25 +++++++++++++---- mmtf-update/pom.xml | 1 + .../mmtf/preupdatetests/FtpServerTest.java | 3 +- .../preupdatetests/SandboxAccessTest.java | 6 ++-- .../org/rcsb/mmtf/update/ServerUtils.java | 2 +- 12 files changed, 59 insertions(+), 30 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index 0a34537..44c8568 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -82,7 +82,6 @@ public interface MmtfDecodedDataInterface { */ int[] getGroupIds(); - /** * Returns the group name for the group specified in {@link #getGroupTypeIndices()}. * to link groups to the 3 letter group name, e.g. HIS. @@ -317,6 +316,12 @@ public interface MmtfDecodedDataInterface { */ int getNumModels(); + /** + * Returns the total number of bonds in the structure + * @resturn the number of bonds + */ + int getNumBonds(); + /** * Returns the number of chains (for all models) in the structure. * @return the number of chains for all models diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index ced5987..8c7b86e 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -10,13 +10,15 @@ public interface MmtfDecoderInterface { /** * Used before any additions to do any required pre-processing. * For example the user could use this to specify the amount of memory to be allocated. + * @param totalNumBonds the total number of bonds in the structure * @param totalNumAtoms the total number of atoms found in the data. * @param totalNumGroups the total number of groups found in the data. * @param totalNumChains the total number of chains found in the data. * @param totalNumModels the total number of models found in the data. * @param structureId an identifier for the structure (e.g. PDB id). */ - void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, String structureId); + void initStructure(int totalNumBonds, int totalNumAtoms, int totalNumGroups, int totalNumChains, + int totalNumModels, String structureId); /** * A generic function to be used at the end of all data addition to do required cleanup on the structure @@ -56,11 +58,12 @@ public interface MmtfDecoderInterface { * @param insertionCode the one letter insertion code * @param groupType a string indicating the type of group (as found in the chemcomp dictionary. Empty string if none available. * @param atomCount the number of atoms in the group + * @param bondCount the number of unique bonds in the group * @param singleLetterCode the single letter code of the group * @param sequenceIndex the index of this group in the sequence */ void setGroupInfo(String groupName, int groupNumber, char insertionCode, - String groupType, int atomCount, char singleLetterCode, int sequenceIndex); + String groupType, int atomCount, int boundCount, char singleLetterCode, int sequenceIndex); /** diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 81b4c95..300b7bf 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -577,7 +577,7 @@ public final byte[] getGroupTypeList() { * * @param resOrder the new group type list */ - public final void setGroupTypeList(final byte[] resOrder) { + public final void setGroupTypeList(byte[] resOrder) { this.groupTypeList = resOrder; } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java index f349643..e1c5297 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java @@ -33,7 +33,7 @@ public static int[] deltaDecode(int[] intArray) { * @return the decoded integer array */ public static int[] runlengthDecode(int[] integerArray) { - // We don't know the lenght so need a List + // We don't know the length so need a List List outList = new ArrayList<>(); for (int i=0; i entities; + int totalNumBonds; @Override @@ -394,17 +395,23 @@ public String getDepositionDate() { // Now provide the capability to fill this data. @Override - public void initStructure(int totalNumAtoms, int totalNumGroups, + public void initStructure(int totalNumBonds, int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, String structureId) { + this.totalNumBonds = totalNumBonds; + // Intitialise the bond level info + interGroupBondIndices = new int[totalNumBonds*2]; + interGroupBondOrders = new int[totalNumBonds]; // Intitialise the atom level arrays cartnX = new float[totalNumAtoms]; cartnY= new float[totalNumAtoms]; cartnZ = new float[totalNumAtoms]; occupancy = new float[totalNumAtoms]; bFactor = new float[totalNumAtoms]; - atomId = new int[totalNumAtoms]; + atomId = new int[totalNumAtoms]; + altId = new char[totalNumAtoms]; // Initialise the group level data - altId = new char[totalNumGroups]; + groupNum = new int[totalNumGroups]; + groupMap = new ArrayList<>(); insertionCodeList = new char[totalNumGroups]; seqResGroupList = new int[totalNumGroups]; groupList = new int[totalNumGroups]; @@ -455,7 +462,7 @@ public void setEntityInfo(int[] chainIndices, String sequence, String descriptio @Override public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String polymerType, - int atomCount, char singleAtomCode, int sequenceIndex) { + int atomCount, int bondCount, char singleAtomCode, int sequenceIndex) { // If it's not the first go if(pdbGroup!=null) { // Now add this to the list or find it in the list @@ -469,8 +476,8 @@ public void setGroupInfo(String groupName, int groupNumber, char insertionCode, pdbGroup = new PDBGroup(); pdbGroup.setAtomChargeList(new int[atomCount]); pdbGroup.setAtomNameList(new String[atomCount]); - pdbGroup.setBondAtomList(new int[atomCount]); - pdbGroup.setBondOrderList(new int[atomCount]); + pdbGroup.setBondAtomList(new int[bondCount*2]); + pdbGroup.setBondOrderList(new int[bondCount]); pdbGroup.setChemCompType(polymerType); pdbGroup.setElementList(new String[atomCount]); pdbGroup.setGroupName(groupName); @@ -560,4 +567,10 @@ private PDBGroup getGroup(int groupInd) { return groupMap.get(groupList[groupInd]); } + + @Override + public int getNumBonds() { + return totalNumBonds; + } + } diff --git a/mmtf-update/pom.xml b/mmtf-update/pom.xml index e672813..a5c7fec 100644 --- a/mmtf-update/pom.xml +++ b/mmtf-update/pom.xml @@ -26,6 +26,7 @@ junit junit + build + ${project.basedir}/.git + + + git + + + dd.MM.yyyy '@' HH:mm:ss z + + + + ${user.timezone} + + + false + + + + + + true + + + ${project.build.outputDirectory}/git.properties + + + properties + + + true + + + + false + + + + true + + + + true + + + + false + + + + false + + + + + + + + + + + + + + + + false + + + + 7 + + + + + flat + + + + + + + false + + + false + + 7 + + + -dirty + + + * + + + false + + + + + true + + + ${project.build.outputDirectory}/git.properties + + + + + + + diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/gitversion/GetRepoState.java b/mmtf-common/src/main/java/org/rcsb/mmtf/gitversion/GetRepoState.java similarity index 100% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/gitversion/GetRepoState.java rename to mmtf-common/src/main/java/org/rcsb/mmtf/gitversion/GetRepoState.java diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/gitversion/GitRepositoryState.java b/mmtf-common/src/main/java/org/rcsb/mmtf/gitversion/GitRepositoryState.java similarity index 100% rename from mmtf-encoder/src/main/java/org/rcsb/mmtf/gitversion/GitRepositoryState.java rename to mmtf-common/src/main/java/org/rcsb/mmtf/gitversion/GitRepositoryState.java diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java b/mmtf-common/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java similarity index 100% rename from mmtf-encoder/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java rename to mmtf-common/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index a012dc5..d7ead59 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -69,237 +69,6 @@ - - - - org.apache.maven.plugins - maven-jar-plugin - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - true - - - - pl.project13.maven - git-commit-id-plugin - 2.2.0 - - - - revision - - - - - - - ${project.basedir}/.git - - - git - - - dd.MM.yyyy '@' HH:mm:ss z - - - - ${user.timezone} - - - false - - - - - - true - - - ${project.build.outputDirectory}/git.properties - - - properties - - - true - - - - false - - - - true - - - - true - - - - false - - - - false - - - - - - - - - - - - - - - - false - - - - 7 - - - - - flat - - - - - - - false - - - false - - 7 - - - -dirty - - - * - - - false - - - - - true - - - ${project.build.outputDirectory}/git.properties - - - - - - - - From b105b9ea481eb32dc8bcf50afbbbd7f0511e95a9 Mon Sep 17 00:00:00 2001 From: abradle Date: Mon, 11 Apr 2016 15:53:35 -0700 Subject: [PATCH 079/108] Refacotred the examples package into mmtf-update --- .../src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java | 0 .../src/main/java/org/rcsb/mmtf/examples/HandleIO.java | 0 .../src/main/java/org/rcsb/mmtf/examples/HelloWorld.java | 0 .../src/main/java/org/rcsb/mmtf/examples/package-info.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {mmtf-decoder => mmtf-update}/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java (100%) rename {mmtf-decoder => mmtf-update}/src/main/java/org/rcsb/mmtf/examples/HandleIO.java (100%) rename {mmtf-decoder => mmtf-update}/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java (100%) rename {mmtf-decoder => mmtf-update}/src/main/java/org/rcsb/mmtf/examples/package-info.java (100%) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java similarity index 100% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java rename to mmtf-update/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java similarity index 100% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HandleIO.java rename to mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java similarity index 100% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java rename to mmtf-update/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/package-info.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/package-info.java similarity index 100% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/examples/package-info.java rename to mmtf-update/src/main/java/org/rcsb/mmtf/examples/package-info.java From e56bdce0e8ae01f92746d4b69e60238824d4dc44 Mon Sep 17 00:00:00 2001 From: abradle Date: Mon, 11 Apr 2016 16:05:41 -0700 Subject: [PATCH 080/108] Refactored functions out of DataApiToReader into a Utils class --- .../rcsb/mmtf/decoder/DataApiToReader.java | 68 ++----------------- .../org/rcsb/mmtf/decoder/DecoderUtils.java | 68 +++++++++++++++++++ 2 files changed, 73 insertions(+), 63 deletions(-) create mode 100644 mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java index 77870f3..083a379 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java @@ -53,15 +53,15 @@ public void read(MmtfDecodedDataInterface inputApi, MmtfDecoderInterface inputIn // Now add the atom information addAtomicInformation(); // Now add the header information. - addHeaderInfo(); + DecoderUtils.addHeaderInfo(dataApi, structInflator); // Now set the crystallographic information - addXtalographicInfo(); + DecoderUtils.addXtalographicInfo(dataApi, structInflator); /// Now get the bioassembly information - only if parsing using AsymId - generateBioAssembly(); + DecoderUtils.generateBioAssembly(dataApi, structInflator); // Now add the other bonds between groups - addInterGroupBonds(); + DecoderUtils.addInterGroupBonds(dataApi, structInflator); // Now add the entity info - addEntityInfo(); + DecoderUtils.addEntityInfo(dataApi, structInflator); // Now do any required cleanup structInflator.finalizeStructure(); } @@ -83,32 +83,6 @@ private final void addAtomicInformation() { } } - - /** - * Add the entity information to a structure. - */ - private final void addEntityInfo() { - for (int i=0; i Date: Mon, 11 Apr 2016 16:38:45 -0700 Subject: [PATCH 081/108] Updated the names of test. Made a new download utils class in common for downloading data. --- .../org/rcsb/mmtf/utils/DownloadUtils.java | 99 +++++++++++++++++++ .../rcsb/mmtf/decoder/DataApiToReader.java | 1 - .../rcsb/mmtf/decoder/TestArrayDecoders.java | 4 +- .../rcsb/mmtf/encoder/TestArrayEncoders.java | 4 +- .../java/org/rcsb/mmtf/examples/HandleIO.java | 4 - 5 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java b/mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java new file mode 100644 index 0000000..54827d5 --- /dev/null +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java @@ -0,0 +1,99 @@ +package org.rcsb.mmtf.utils; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.zip.GZIPInputStream; + +public class DownloadUtils { + + /** The base url. */ + public static final String BASE_URL = "http://mmtf.rcsb.org/full/"; + /** The size of a chunk for a byte buffer. */ + private static final int BYTE_BUFFER_CHUNK_SIZE = 4096; + + /** + * Find the message pack byte array from the web using the input code and a base url. + * Caches the file if possible. + * @param inputCode + * @return the byte array + * @throws IOException + */ + public static byte[] getDataFromUrl(String inputCode) throws IOException { + // Get these as an inputstream + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + InputStream is = null; + URL url = new URL(BASE_URL + inputCode); + try { + is = url.openStream(); + byte[] byteChunk = new byte[BYTE_BUFFER_CHUNK_SIZE]; // Or whatever size you want to read in at a time. + int n; + + while ( (n = is.read(byteChunk)) > 0 ) { + baos.write(byteChunk, 0, n); + } + } + catch (IOException e) { + System.err.printf ("Failed while reading bytes from %s: %s", url.toExternalForm(), e.getMessage()); + e.printStackTrace (); + // Perform any other exception handling that's appropriate. + } + finally { + if (is != null) { is.close(); } + } + byte[] b = baos.toByteArray(); + // Now return the gzip deflated byte array + return deflateGzip(b); + } + + /** + * Deflate a gzip byte array. + * @param inputBytes -> gzip compressed byte + * array + * @return A deflated byte array + * @throws IOException Signals that an I/O exception has occurred. + */ + private static byte[] deflateGzip(final byte[] inputBytes){ + // Start the byte input stream + ByteArrayInputStream bis = new ByteArrayInputStream(inputBytes); + GZIPInputStream gis; + try { + gis = new GZIPInputStream(bis); + } catch (IOException e) { + System.err.println("Error in opening byte array."); + e.printStackTrace(); + return null; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // Make a buffer + byte[] tmp = new byte[BYTE_BUFFER_CHUNK_SIZE]; + try { + while (gis.available() == 1) { + int size = gis.read(tmp); + if(size==-1){ + break; + } + baos.write(tmp, 0, size); + } + } + catch (Exception ex) { + ex.printStackTrace(); + return null; + } + finally { + try { + if (baos != null) { + baos.close(); + } + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } + // Get the bytes + byte[] outArr = baos.toByteArray(); + return outArr; + } +} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java index 083a379..2fca2c7 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java @@ -11,7 +11,6 @@ /** * Decode an MMTF structure using a structure inflator. * The class also allows access to the unconsumed but parsed and inflated underlying data. - * * @author Anthony Bradley * */ diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java index 65ae4c8..ce04fa4 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java @@ -15,7 +15,7 @@ public class TestArrayDecoders { * Run length decode int test. */ @Test - public final void runLengthDecodeIntTest() { + public final void runLengthDecodeTest() { // Allocate the byte array int[] inputData = {15,3,100,2,111,4,10000,6}; int[] outputDataTest = {15,15,15,100,100,111,111,111,111,10000,10000,10000,10000,10000,10000}; @@ -27,7 +27,7 @@ public final void runLengthDecodeIntTest() { * Delta decode int test. */ @Test - public final void deltaDecodeIntTest() { + public final void deltaDecodeTest() { // Allocate the byte array int[] inputData = {15,3,100,-1,11,4}; int[] outputDataTest = {15,18,118,117,128,132}; diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java index d637749..90eea65 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java @@ -15,7 +15,7 @@ public class TestArrayEncoders { * Run length decode int test. */ @Test - public final void runLengthDecodeIntTest() { + public final void runLengthDecodeTest() { // Allocate the byte array int[] inputData = {15,15,15,100,100,111,111,111,111}; int[] outputDataTest = {15,3,100,2,111,4}; @@ -27,7 +27,7 @@ public final void runLengthDecodeIntTest() { * Delta decode int test. */ @Test - public final void deltaDecodeIntTest() { + public final void deltaDecodeTest() { // Allocate the byte array int[] inputData = {15,18,118,117,128,132}; int[] outputDataTest = {15,3,100,-1,11,4}; diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java index 4edbdc8..49ddb96 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java @@ -73,8 +73,6 @@ public final MmtfDecodedDataInterface getDataApiFromUrlOrFile(final String input throw new RuntimeException(e); } } - - /** * Get from a cached file on the file system. @@ -85,8 +83,6 @@ public final byte[] getFromFile(final String inputCode) { String basePath = getBasePath(); String fullPath = constructPath(basePath, inputCode); return getFromFileSystem(fullPath); - - } /** From 1bd09f1c438f312130493ae2e9be6d96cdac0ff2 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 09:30:30 -0700 Subject: [PATCH 082/108] Updates to consider alt loc and insertion code information better. --- .../src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java | 2 -- .../main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java | 1 + .../main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java | 7 +++---- .../java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java | 3 +-- .../java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java | 3 +-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java index 455d3ed..3551742 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java @@ -24,8 +24,6 @@ public DataApiToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws I mmtfBean.setGroupTypeList( ArrayConverters.convertIntegersToFourByte( mmtfDecodedDataInterface.getGroupTypeIndices())); - - // Encode the coordinate and B-factor arrays. List xCoords = ArrayConverters.splitIntegers( ArrayEncoders.deltaEncode( diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java index ce61d56..51c2d91 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java @@ -492,6 +492,7 @@ public void setGroupInfo(String groupName, int groupNumber, char insertionCode, groupAtomIndex=0; groupBondIndex=0; // Store the group level data + insertionCodeList[groupIndex] = insertionCode; groupNum[groupIndex] = groupNumber; seqResGroupList[groupIndex] = sequenceIndex; secStructInfo[groupIndex] = secStructType; diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java index 0587054..cefa818 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java @@ -71,6 +71,7 @@ private boolean checkIfAtomsSame(Structure structOne, Structure structTwo) { System.out.println(groupTwo.getPDBName() + " and type: "+groupTwo.getType());; } assertEquals(groupOne.getType(), groupTwo.getType()); + assertEquals(groupOne.getResidueNumber().getSeqNum(), groupTwo.getResidueNumber().getSeqNum()); // Get the first conf List atomsOne = new ArrayList<>(groupOne.getAtoms()); List atomsTwo = new ArrayList<>(groupTwo.getAtoms()); @@ -112,8 +113,6 @@ public int compare(Atom o1, Atom o2) { return 1; } } - - }); atomsTwo.sort(new Comparator() { @@ -127,12 +126,11 @@ public int compare(Atom o1, Atom o2) { return 1; } } - - }); for(int l=0;l Date: Tue, 12 Apr 2016 09:47:10 -0700 Subject: [PATCH 083/108] Refactored removed the pointless Reader and Writer interfaces --- mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java | 6 ------ mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java | 7 ------- .../main/java/org/rcsb/mmtf/decoder/DataApiToReader.java | 3 +-- 3 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java deleted file mode 100644 index 62ab3ad..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfReader.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.rcsb.mmtf.api; - -public interface MmtfReader { - - public void read(MmtfDecodedDataInterface mmtfDecodedDataInterface, MmtfDecoderInterface mmtfDecoderInterface); -} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java deleted file mode 100644 index 7b1c213..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfWriter.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.rcsb.mmtf.api; - -public interface MmtfWriter { - - public void write(MmtfDecoderInterface decoder); - -} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java index 2fca2c7..6bcf6fa 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java @@ -6,7 +6,6 @@ import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.api.MmtfDecoderInterface; -import org.rcsb.mmtf.api.MmtfReader; /** * Decode an MMTF structure using a structure inflator. @@ -14,7 +13,7 @@ * @author Anthony Bradley * */ -public class DataApiToReader implements MmtfReader { +public class DataApiToReader { /** The struct inflator. */ private MmtfDecoderInterface structInflator; From d4cc25536794d9298bccda26100c0ece630d7f6e Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 09:57:34 -0700 Subject: [PATCH 084/108] Update to store insCodeList & altLocList as byte arrays --- .../java/org/rcsb/mmtf/dataholders/MmtfBean.java | 12 ++++++------ .../java/org/rcsb/mmtf/decoder/BeanToDataApi.java | 8 ++++++-- .../java/org/rcsb/mmtf/encoder/DataApiToBean.java | 12 ++++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 3ecc767..93356ed 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -108,10 +108,10 @@ public class MmtfBean implements Serializable { private byte[] occupancyList; /** The list of alternate location ids. */ - private int[] altLocList; + private byte[] altLocList; /** The insertion code list. */ - private int[] insCodeList; + private byte[] insCodeList; /** The group type list. */ private byte[] groupTypeList; @@ -439,7 +439,7 @@ public final void setbFactorSmall(final byte[] inputSmallBFactor) { * * @return the alternate location list */ - public final int[] getAltLocList() { + public final byte[] getAltLocList() { return altLocList; } @@ -448,7 +448,7 @@ public final int[] getAltLocList() { * * @param inputAltLocList the new alternation location label list */ - public final void setAltLocList(final int[] inputAltLocList) { + public final void setAltLocList(final byte[] inputAltLocList) { this.altLocList = inputAltLocList; } @@ -529,7 +529,7 @@ public final void setOccupancyList(final byte[] inputOccupancyList) { * * @return the insertion code list */ - public final int[] getInsCodeList() { + public final byte[] getInsCodeList() { return insCodeList; } @@ -538,7 +538,7 @@ public final int[] getInsCodeList() { * * @param inputInsertionCodeList the new insertion code list */ - public final void setInsCodeList(final int[] inputInsertionCodeList) { + public final void setInsCodeList(final byte[] inputInsertionCodeList) { this.insCodeList = inputInsertionCodeList; } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java index 36ef33b..880fe21 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java @@ -55,9 +55,13 @@ public BeanToDataApi(MmtfBean inputData) throws IOException { ArrayConverters.convertFourByteToIntegers(inputData.getAtomIdList()))); // Run length encoded altId = ArrayConverters.convertIntegerToChar( - ArrayDecoders.runlengthDecode(inputData.getAltLocList())); + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers( + inputData.getAltLocList()))); insertionCodeList = ArrayConverters.convertIntegerToChar( - ArrayDecoders.runlengthDecode(inputData.getInsCodeList())); + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers( + inputData.getInsCodeList()))); // Get the groupNumber groupNum = ArrayDecoders.deltaDecode( ArrayDecoders.runlengthDecode( diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java index 3551742..c8da4aa 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java @@ -71,10 +71,14 @@ public DataApiToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws I ArrayEncoders.runlengthEncode( ArrayEncoders.deltaEncode(mmtfDecodedDataInterface.getAtomIds())))); // Run length encoded - mmtfBean.setAltLocList(ArrayEncoders.runlengthEncode( - ArrayConverters.convertCharToIntegers(mmtfDecodedDataInterface.getAltLocIds()))); - mmtfBean.setInsCodeList(ArrayEncoders.runlengthEncode( - ArrayConverters.convertCharToIntegers(mmtfDecodedDataInterface.getInsCodes()))); + mmtfBean.setAltLocList(ArrayConverters.convertIntegersToFourByte( + ArrayEncoders.runlengthEncode( + ArrayConverters.convertCharToIntegers( + mmtfDecodedDataInterface.getAltLocIds())))); + mmtfBean.setInsCodeList(ArrayConverters.convertIntegersToFourByte( + ArrayEncoders.runlengthEncode( + ArrayConverters.convertCharToIntegers( + mmtfDecodedDataInterface.getInsCodes())))); // Set the groupNumber mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( From 84e6edf15beea0c5f24e27745f07e6a4e0326c63 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 10:08:13 -0700 Subject: [PATCH 085/108] Updates to the naming of bioassembly related fields --- .../java/org/rcsb/mmtf/api/MmtfDecoderInterface.java | 2 +- .../org/rcsb/mmtf/dataholders/BioAssemblyData.java | 10 +++++----- .../org/rcsb/mmtf/dataholders/BioAssemblyTrans.java | 6 +++--- .../java/org/rcsb/mmtf/decoder/BeanToDataApi.java | 6 +++--- .../java/org/rcsb/mmtf/encoder/EncoderUtils.java | 4 ++-- .../java/org/rcsb/mmtf/encoder/WriterToDataApi.java | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index 5005a38..645be5d 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -61,7 +61,7 @@ void initStructure(int totalNumBonds, int totalNumAtoms, int totalNumGroups, int * @param bondCount the number of unique bonds in the group * @param singleLetterCode the single letter code of the group * @param sequenceIndex the index of this group in the sequence - * @param the type of secondary structure used (types are according to DSSP and number to + * @param secondaryStructureType the type of secondary structure used (types are according to DSSP and number to * type mappings are defined in the specification) */ void setGroupInfo(String groupName, int groupNumber, char insertionCode, diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyData.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyData.java index 52dac78..651d8dd 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyData.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyData.java @@ -21,7 +21,7 @@ public class BioAssemblyData implements Serializable { /** * The specific transformations of this bioassembly. */ - private List transforms; + private List transformList; /** @@ -29,8 +29,8 @@ public class BioAssemblyData implements Serializable { * * @return the transforms */ - public final List getTransforms() { - return transforms; + public final List getTransformList() { + return transformList; } /** @@ -38,9 +38,9 @@ public final List getTransforms() { * * @param inputTransforms the new transforms */ - public final void setTransforms(final + public final void setTransformList(final List inputTransforms) { - this.transforms = inputTransforms; + this.transformList = inputTransforms; } } diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java index 0f9875f..5854ca0 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java @@ -32,7 +32,7 @@ public class BioAssemblyTrans implements Serializable { * * @return the transformation */ - public final double[] getTransformation() { + public final double[] getMatrix() { return transformation; } @@ -43,8 +43,8 @@ public final double[] getTransformation() { * * @param inputTransformation the new transformation */ - public final void setTransformation(final double[] inputTransformation) { - this.transformation = inputTransformation; + public final void setMatrix(final double[] transformation) { + this.transformation = transformation; } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java index 880fe21..2f837e0 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java @@ -443,17 +443,17 @@ public int getNumBioassemblies() { @Override public int getNumTransInBioassembly(int bioassemblyIndex) { - return bioAssembly.get(bioassemblyIndex).getTransforms().size(); + return bioAssembly.get(bioassemblyIndex).getTransformList().size(); } @Override public int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex) { - return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getChainIndexList(); + return bioAssembly.get(bioassemblyIndex).getTransformList().get(transformationIndex).getChainIndexList(); } @Override public double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex) { - return bioAssembly.get(bioassemblyIndex).getTransforms().get(transformationIndex).getTransformation(); + return bioAssembly.get(bioassemblyIndex).getTransformList().get(transformationIndex).getMatrix(); } @Override diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java index f40f3e5..203266e 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java @@ -49,14 +49,14 @@ public static List generateBioassemblies(MmtfDecodedDataInterfa BioAssemblyData bioAssemblyData = new BioAssemblyData(); outList.add(bioAssemblyData); List transformList = new ArrayList<>(); - bioAssemblyData.setTransforms(transformList); + bioAssemblyData.setTransformList(transformList); int numTrans = mmtfDecodedDataInterface.getNumTransInBioassembly(i); for (int j=0; j bioAssemblyTranList; if (bioAssembly.size()>bioAssemblyIndex) { - bioAssemblyTranList = bioAssembly.get(bioAssemblyIndex).getTransforms(); + bioAssemblyTranList = bioAssembly.get(bioAssemblyIndex).getTransformList(); } else{ bioAssemblyData = new BioAssemblyData(); bioAssemblyTranList = new ArrayList<>(); - bioAssemblyData.setTransforms(bioAssemblyTranList); + bioAssemblyData.setTransformList(bioAssemblyTranList); bioAssembly.add(bioAssemblyData); } BioAssemblyTrans bioAssemblyTrans = new BioAssemblyTrans(); bioAssemblyTrans.setChainIndexList(chainIndices); - bioAssemblyTrans.setTransformation(transform); + bioAssemblyTrans.setMatrix(transform); bioAssemblyTranList.add(bioAssemblyTrans); } From aa8d07001bff86a7c21741f55e6dae904a6eb8b6 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 10:13:39 -0700 Subject: [PATCH 086/108] Unit tests that check array encoder/decoders handle empty arrays correctly --- .../rcsb/mmtf/decoder/TestArrayDecoders.java | 25 +++++++++++++++++++ .../org/rcsb/mmtf/encoder/ArrayEncoders.java | 4 +++ .../rcsb/mmtf/encoder/TestArrayEncoders.java | 25 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java index ce04fa4..9030aee 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayDecoders.java @@ -23,6 +23,18 @@ public final void runLengthDecodeTest() { assertArrayEquals(outputDataTest, outputData); } + /** + * Check run length encoding on empty arrays + */ + @Test + public final void emptyRunLengthDecodeTest() { + // Allocate the byte array + int[] inputData = {}; + int[] outputDataTest = {}; + int[] outputData = ArrayDecoders.runlengthDecode(inputData); + assertArrayEquals(outputDataTest, outputData); + } + /** * Delta decode int test. */ @@ -34,4 +46,17 @@ public final void deltaDecodeTest() { int[] outputData = ArrayDecoders.deltaDecode(inputData); assertArrayEquals(outputDataTest, outputData); } + + + /** + * Check delta decoding on empty array + */ + @Test + public final void emptyDeltaDecodeTest() { + // Allocate the byte array + int[] inputData = {}; + int[] outputDataTest = {}; + int[] outputData = ArrayDecoders.deltaDecode(inputData); + assertArrayEquals(outputDataTest, outputData); + } } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java index b744b58..fbfccbb 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayEncoders.java @@ -32,6 +32,10 @@ public static int[] deltaEncode(int[] intArray) { * @return the encoded integer array */ public static int[] runlengthEncode(int[] intArray) { + // If it's length zero + if (intArray.length==0){ + return new int[0]; + } // We don't know the length so use List outList = new ArrayList<>(); int lastInt = intArray[0]; diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java index 90eea65..fb6d048 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayEncoders.java @@ -23,6 +23,18 @@ public final void runLengthDecodeTest() { assertArrayEquals(outputDataTest, outputData); } + /** + * Run length decode int test on empty arrays. + */ + @Test + public final void emptyRunLengthDecodeTest() { + // Allocate the byte array + int[] inputData = {}; + int[] outputDataTest = {}; + int[] outputData = ArrayEncoders.runlengthEncode(inputData); + assertArrayEquals(outputDataTest, outputData); + } + /** * Delta decode int test. */ @@ -34,4 +46,17 @@ public final void deltaDecodeTest() { int[] outputData = ArrayEncoders.deltaEncode(inputData); assertArrayEquals(outputDataTest, outputData); } + + + /** + * Delta decode int test on empty arrays. + */ + @Test + public final void emptyDeltaDecodeTest() { + // Allocate the byte array + int[] inputData = {}; + int[] outputDataTest = {}; + int[] outputData = ArrayEncoders.deltaEncode(inputData); + assertArrayEquals(outputDataTest, outputData); + } } From 4c38e19f345a8579a6dcfead88d2057994896d80 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 10:26:33 -0700 Subject: [PATCH 087/108] Updates to incluide release date into the format --- .../mmtf/api/MmtfDecodedDataInterface.java | 7 ++++ .../rcsb/mmtf/api/MmtfDecoderInterface.java | 33 ++++++++++--------- .../org/rcsb/mmtf/dataholders/MmtfBean.java | 16 +++++++++ .../org/rcsb/mmtf/decoder/BeanToDataApi.java | 11 ++++++- .../org/rcsb/mmtf/decoder/DecoderUtils.java | 2 +- .../rcsb/mmtf/encoder/WriterToDataApi.java | 12 ++++++- 6 files changed, 62 insertions(+), 19 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java index 78c5aaa..d335852 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java @@ -385,6 +385,13 @@ public interface MmtfDecodedDataInterface { */ String getDepositionDate(); + /** + * Returns the release date of the structure as a string + * in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html + * @return the release date of the structure. + */ + String getReleaseDate(); + /** * The secondary structure information for the structure as a list of integers * @return the array of secondary structure informations diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java index 645be5d..7dd5718 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java @@ -105,32 +105,33 @@ void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, /** * Sets an intra-group bond. * - * @param thisBondIndOne the atom index of the first partner in the bond - * @param thisBondIndTwo the atom index of the second partner in the bond - * @param thisBondOrder the bond order + * @param atomIndexOne the atom index of the first partner in the bond + * @param atomIndexTwo the atom index of the second partner in the bond + * @param bondOrder the bond order */ - void setGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder); + void setGroupBond(int atomIndexOne, int atomIndexTwo, int bondOrder); /** * Sets an inter-group bond. - * - * @param thisBondIndOne the atom index of the first partner in the bond - * @param thisBondIndTwo the atom index of the second partner in the bond - * @param thisBondOrder the bond order + * @param atomIndexOne the atom index of the first partner in the bond + * @param atomIndexTwo the atom index of the second partner in the bond + * @param bondOrder the bond order */ - void setInterGroupBond(int thisBondIndOne, int thisBondIndTwo, int thisBondOrder); + void setInterGroupBond(int atomIndexOne, int atomIndexTwo, int bondOrder); /** * Sets the header information. - * @param rFree - * @param rWork - * @param resolution - * @param title - * @param depositionDate - * @param experimnetalMethods + * @param rFree the measured R-Free for the structure + * @param rWork the measure R-Work for the structure + * @param resolution the resolution of the structure + * @param title the title of the structure + * @param depositionDate the deposition date of the structure + * @param releaseDate the release date of the structure + * @param experimnetalMethods the list of experimental methods in the structure */ - void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, String[] experimnetalMethods); + void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, + String releaseDate, String[] experimnetalMethods); diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 93356ed..2516ca8 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -143,6 +143,8 @@ public class MmtfBean implements Serializable { /** The deposition date of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ private String depositionDate; + /** The release data of the structure in ISO time standard format. https://www.cl.cam.ac.uk/~mgk25/iso-time.html */ + private String releaseDate; /** Constructor to set the default values for floats */ public MmtfBean() { @@ -854,6 +856,20 @@ public void setDepositionDate(String depositionDate) { this.depositionDate = depositionDate; } + /** + * @return the release date of the structure in ISO time standard. + */ + public String getReleaseDate() { + return releaseDate; + } + + /** + * @param releaseDate a string indicating the deposition date to set. + */ + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java index 2f837e0..b7be733 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java @@ -96,6 +96,7 @@ public BeanToDataApi(MmtfBean inputData) throws IOException { experimentalMethods = inputData.getExperimentalMethods(); // Now get the relase information depositionDate = inputData.getDepositionDate(); + releaseDate = inputData.getReleaseDate(); secStructInfo = ArrayConverters.convertFourByteToIntegers(inputData.getSecStructList()); } @@ -192,9 +193,12 @@ public BeanToDataApi(MmtfBean inputData) throws IOException { /** The list of experimental methods. */ private String[] experimentalMethods; - /** The deposition date of hte structure */ + /** The deposition date of the structure */ private String depositionDate; + /** The release date of the structure */ + private String releaseDate; + private int[] secStructInfo; @@ -475,5 +479,10 @@ public int[] getSecStructList() { return secStructInfo; } + @Override + public String getReleaseDate() { + return releaseDate; + } + } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java index 5f87d0b..c6c0c3e 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java @@ -32,7 +32,7 @@ public static void addInterGroupBonds(MmtfDecodedDataInterface dataApi, MmtfDeco */ public static void addHeaderInfo(MmtfDecodedDataInterface dataApi, MmtfDecoderInterface structInflator) { structInflator.setHeaderInfo(dataApi.getRfree(),dataApi.getRwork(), dataApi.getResolution(), - dataApi.getTitle(), dataApi.getDepositionDate(), dataApi.getExperimentalMethods()); + dataApi.getTitle(), dataApi.getDepositionDate(), dataApi.getReleaseDate(), dataApi.getExperimentalMethods()); } diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java index 15c1672..1daac00 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToDataApi.java @@ -112,6 +112,9 @@ public class WriterToDataApi implements MmtfDecodedDataInterface, MmtfDecoderInt /** The deposition date of hte structure */ private String depositionDate; + + /** The release date of the structure */ + private String releaseDate; /** The total number of models */ private int numModels; @@ -564,13 +567,14 @@ public void setInterGroupBond(int firstAtomIndex, int secondAtomIndex, int bondO } @Override - public void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, + public void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, String releaseDate, String[] experimnetalMethods) { this.rFree = rFree; this.rWork = rWork; this.resolution = resolution; this.title = title; this.depositionDate = depositionDate; + this.releaseDate = releaseDate; this.experimentalMethods = experimnetalMethods; } @@ -590,4 +594,10 @@ public int[] getSecStructList() { return secStructInfo; } + + @Override + public String getReleaseDate() { + return releaseDate; + } + } From a817843ab7ea873dec9ce2d80db83f7aee627183 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 10:29:20 -0700 Subject: [PATCH 088/108] Rename sequenceIdList to sequenceIndexList --- .../main/java/org/rcsb/mmtf/dataholders/MmtfBean.java | 10 +++++----- .../main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java | 2 +- .../main/java/org/rcsb/mmtf/encoder/DataApiToBean.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java index 2516ca8..be01cc3 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/MmtfBean.java @@ -123,7 +123,7 @@ public class MmtfBean implements Serializable { private byte[] atomIdList; /** The SeqRes group ids. */ - private byte[] sequenceIdList; + private byte[] sequenceIndexList; /** The experimental method(s). */ private String[] experimentalMethods; @@ -815,15 +815,15 @@ public void setExperimentalMethods(String[] experimentalMethods) { /** * @return the seqResGroupIds */ - public byte[] getSequenceIdList() { - return sequenceIdList; + public byte[] getSequenceIndexList() { + return sequenceIndexList; } /** * @param seqResGroupIds the seqResGroupIds to set */ - public void setSequenceIdList(byte[] seqResGroupIds) { - this.sequenceIdList = seqResGroupIds; + public void setSequenceIndexList(byte[] seqResGroupIds) { + this.sequenceIndexList = seqResGroupIds; } /** diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java index b7be733..b8ed1c3 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/BeanToDataApi.java @@ -71,7 +71,7 @@ public BeanToDataApi(MmtfBean inputData) throws IOException { groupMap = inputData.getGroupList(); // Get the seqRes groups seqResGroupList = ArrayConverters.convertFourByteToIntegers( - inputData.getSequenceIdList()); + inputData.getSequenceIndexList()); // Get the number of chains per model chainsPerModel = inputData.getChainsPerModel(); groupsPerChain = inputData.getGroupsPerChain(); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java index c8da4aa..de97b5c 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java @@ -89,7 +89,7 @@ public DataApiToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws I // Set the group map (all the unique groups in the structure). mmtfBean.setGroupList(EncoderUtils.generateGroupMap(mmtfDecodedDataInterface)); // Set the indices for the groups mapping to the sequence - mmtfBean.setSequenceIdList(ArrayConverters.convertIntegersToFourByte( + mmtfBean.setSequenceIndexList(ArrayConverters.convertIntegersToFourByte( mmtfDecodedDataInterface.getGroupSequenceIndices())); // Set the number of chains per model mmtfBean.setChainsPerModel(mmtfDecodedDataInterface.getChainsPerModel()); From 5bef90b5441964961f03c2b329714cd33a439964 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 10:43:03 -0700 Subject: [PATCH 089/108] Update to include to pass releaseDate into the mmtf bean --- .../src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java | 1 + .../java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java index de97b5c..ee37041 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DataApiToBean.java @@ -123,6 +123,7 @@ public DataApiToBean(MmtfDecodedDataInterface mmtfDecodedDataInterface) throws I mmtfBean.setTitle(mmtfDecodedDataInterface.getTitle()); mmtfBean.setExperimentalMethods(mmtfDecodedDataInterface.getExperimentalMethods()); mmtfBean.setDepositionDate(mmtfDecodedDataInterface.getDepositionDate()); + mmtfBean.setReleaseDate(mmtfDecodedDataInterface.getReleaseDate()); mmtfBean.setSecStructList(ArrayConverters.convertIntegersToFourByte(mmtfDecodedDataInterface.getSecStructList())); } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java index f6818df..43f57c5 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java @@ -6,6 +6,7 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.io.mmtf.MmtfActions; +import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.junit.Test; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.testutils.IntegrationTestUtils; @@ -21,8 +22,8 @@ public class TestParseMMCif { @Test public void testAll() throws IOException, StructureException{ - TestingUtils.testList(IntegrationTestUtils.TEST_CASES); testDataComplete("4cup"); + TestingUtils.testList(IntegrationTestUtils.TEST_CASES); } /** @@ -31,6 +32,7 @@ public void testAll() throws IOException, StructureException{ * @throws IOException */ private void testDataComplete(String pdbId) throws IOException, StructureException { + MmtfUtils.setUpBioJava(); // Get an mmtfBean MmtfBean mmtfBean = MmtfActions.getBean(pdbId); // Make sure all fields are re-populated From 7aa79912e71ae873c30c7d04608324c3a1f3ed57 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 15:37:42 -0700 Subject: [PATCH 090/108] Updates to remove any mention of the Messagepack serializer /deserializer --- .../rcsb/mmtf/decoder/DataApiToReader.java | 8 +- .../org/rcsb/mmtf/decoder/ReaderUtils.java | 35 +++++++-- .../mmtf/decoder/TestArrayConverters.java | 2 - .../org/rcsb/mmtf/encoder/WriterUtils.java | 31 ++++++++ .../org/rcsb/mmtf/mappers/MapperUtils.java | 43 ++++++++++- .../org/rcsb/mmtf/mappers/PdbIdToMmtf.java | 3 +- .../mmtf/postupdatetests/CheckServer.java | 4 +- .../java/org/rcsb/mmtf/testutils/Utils.java | 74 +++++++++++++++++++ .../org/rcsb/mmtf/update/TestingUtils.java | 4 +- .../mmtf/integrationtest/TestParseMMCif.java | 4 +- .../mmtf/integrationtest/TestRoundTrip.java | 10 ++- .../mmtf/sedeserializers/TestDataHolders.java | 13 +++- 12 files changed, 201 insertions(+), 30 deletions(-) rename mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java => mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java (68%) create mode 100644 mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java create mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java index 6bcf6fa..ba481a1 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java @@ -1,6 +1,5 @@ package org.rcsb.mmtf.decoder; -import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -29,12 +28,7 @@ public class DataApiToReader { private int currentAtomIndex = 0; private Set chainIdSet; - /** - * The constructor requires a byte array to fill the data. This will decompress the arrays using our bespoke methods. - * @param byteArray An unentropy encoded byte array with the data as found in the MMTF format - * @throws IOException - */ - public DataApiToReader() throws IOException { + public DataApiToReader(){ } diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java similarity index 68% rename from mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java index 54827d5..dc01091 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/utils/DownloadUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java @@ -1,13 +1,19 @@ -package org.rcsb.mmtf.utils; +package org.rcsb.mmtf.decoder; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.zip.GZIPInputStream; -public class DownloadUtils { +import org.rcsb.mmtf.dataholders.MmtfBean; +import org.rcsb.mmtf.deserializers.MessagePackDeserializer; + +public class ReaderUtils { /** The base url. */ public static final String BASE_URL = "http://mmtf.rcsb.org/full/"; @@ -21,7 +27,7 @@ public class DownloadUtils { * @return the byte array * @throws IOException */ - public static byte[] getDataFromUrl(String inputCode) throws IOException { + public static MmtfBean getDataFromUrl(String inputCode) throws IOException { // Get these as an inputstream ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = null; @@ -44,8 +50,9 @@ public static byte[] getDataFromUrl(String inputCode) throws IOException { if (is != null) { is.close(); } } byte[] b = baos.toByteArray(); - // Now return the gzip deflated byte array - return deflateGzip(b); + // Now return the gzip deflated and deserialized byte array + MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); + return messagePackDeserializer.deserialize(deflateGzip(b)); } /** @@ -96,4 +103,22 @@ private static byte[] deflateGzip(final byte[] inputBytes){ byte[] outArr = baos.toByteArray(); return outArr; } + + /** + * A function to get MMTF data from a file path + * @param filePath + * @return the deserialized mmtfBean + * @throws IOException + */ + public static MmtfBean getDataFromFile(String filePath) throws IOException { + // Now return the gzip deflated and deserialized byte array + MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); + return messagePackDeserializer.deserialize(readFile(filePath)); + } + + private static byte[] readFile(String filePath) throws IOException { + Path path = Paths.get(filePath); + byte[] data = Files.readAllBytes(path); + return data; + } } diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java index cc54588..7509d1a 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestArrayConverters.java @@ -37,8 +37,6 @@ public final void testConvertIntToFloat() { assertArrayEquals(testFloatArray, floatArray, 0.0f); } - - /** * Test the conversion of byte arrays to one byte integer arrays * @throws IOException diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java new file mode 100644 index 0000000..1b1cc3d --- /dev/null +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java @@ -0,0 +1,31 @@ +package org.rcsb.mmtf.encoder; + +import java.io.FileOutputStream; +import java.io.IOException; + +import org.rcsb.mmtf.serializers.MessagePackSerializer; + +public class WriterUtils { + + /** + * Function to write data to a file + * @param inflatorToGet + * @param path + * @throws IOException + */ + public static void writeDataToFile(WriterToDataApi inflatorToGet, String path) throws IOException { + byte[] byteArray = getDataAsByteArr(inflatorToGet); + FileOutputStream fos = new FileOutputStream(path); + fos.write(byteArray); + fos.close(); + } + + + public static byte[] getDataAsByteArr(WriterToDataApi inflatorToGet) throws IOException { + MessagePackSerializer messagePackSerializer = new MessagePackSerializer(); + // Get to bean + DataApiToBean getToBean = new DataApiToBean(inflatorToGet); + return messagePackSerializer.serialize(getToBean.getMmtfBean()); + } + +} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java index 812be08..3c2397c 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java @@ -1,5 +1,6 @@ package org.rcsb.mmtf.mappers; +import java.io.IOException; import java.io.Serializable; import java.util.List; @@ -8,9 +9,17 @@ import org.apache.spark.api.java.JavaPairRDD; import org.apache.spark.api.java.JavaSparkContext; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; +import org.rcsb.mmtf.decoder.BeanToDataApi; +import org.rcsb.mmtf.decoder.DataApiToReader; +import org.rcsb.mmtf.deserializers.MessagePackDeserializer; +import org.rcsb.mmtf.encoder.WriterToDataApi; +import org.rcsb.mmtf.encoder.WriterUtils; /** * A class to preserve the log if the functions in mappers. @@ -27,11 +36,20 @@ public class MapperUtils implements Serializable{ * @param pdbCodePlus The pdb code is the first four characters. Additional characters can be used. * @param inputByteArr The message pack bytre array to be decoded. * @return + * @throws IOException */ - public static Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) { + public static Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) throws IOException { + MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); + // Get the reader - this is the bit that people need to implement. + MmtfStructureReader mmtfStructureReader = new MmtfStructureReader(); + // Set up the inflator + DataApiToReader getToInflator = new DataApiToReader(); Structure newStruct; try{ - newStruct = MmtfActions.getBiojavaStruct(inputByteArr); + // Do the inflation + getToInflator.read(new BeanToDataApi( messagePackDeserializer.deserialize(inputByteArr)), mmtfStructureReader); + // Get the structue + newStruct = mmtfStructureReader.getStructure();; } catch(Exception e){ System.out.println(e); @@ -54,4 +72,23 @@ public JavaPairRDD generateRDD(JavaSparkContext sparkContex .mapToPair(new PdbIdToMmtf()) .mapToPair(new StringByteToTextByteWriter()); } + + /** + * Get the available data as a byte array + * @param pdbId + * @return the data as a byte array + * @throws StructureException + * @throws IOException + */ + public static byte[] getByteArray(String pdbId) throws IOException, StructureException { + Structure structure = StructureIO.getStructure(pdbId); + // Set up this writer + WriterToDataApi inflatorToGet = new WriterToDataApi(); + // Get the writer - this is what people implement + MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); + // Now pass to the get API + mmtfStructureWriter.write(inflatorToGet); + // Now write this dat to file + return WriterUtils.getDataAsByteArr(inflatorToGet); + } } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java index 42713b5..de00179 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java @@ -2,7 +2,6 @@ import org.apache.spark.api.java.function.PairFunction; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; import scala.Tuple2; @@ -17,7 +16,7 @@ public class PdbIdToMmtf implements PairFunction{ @Override public Tuple2 call(String t) throws Exception { - return new Tuple2(t, MmtfActions.getByteArray(t)); + return new Tuple2(t, MapperUtils.getByteArray(t)); } diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java index 36bced8..d0b702e 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java @@ -8,12 +8,12 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.examples.HandleIO; import org.rcsb.mmtf.testutils.CheckOnBiojava; import org.rcsb.mmtf.testutils.CheckOnRawApi; import org.rcsb.mmtf.testutils.IntegrationTestUtils; +import org.rcsb.mmtf.testutils.Utils; public class CheckServer { @@ -64,7 +64,7 @@ public void basicParsingTest(String baseUrl) throws IOException { private void testParsing(String inputPdb, String inputUrl) throws IOException { System.out.println("TESTING: "+inputPdb); byte[] inputByteArr = handleIo.getFromUrl(inputPdb, inputUrl); - Structure mmtfStruct = MmtfActions.getBiojavaStruct(inputByteArr); + Structure mmtfStruct = Utils.readFromByteArr(inputByteArr); // Now parse from the MMCIF file Structure mmcifStruct; try { diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java new file mode 100644 index 0000000..c9283ee --- /dev/null +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java @@ -0,0 +1,74 @@ +package org.rcsb.mmtf.testutils; + +import java.io.IOException; + +import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; +import org.rcsb.mmtf.dataholders.MmtfBean; +import org.rcsb.mmtf.decoder.BeanToDataApi; +import org.rcsb.mmtf.decoder.DataApiToReader; +import org.rcsb.mmtf.deserializers.MessagePackDeserializer; +import org.rcsb.mmtf.encoder.DataApiToBean; +import org.rcsb.mmtf.encoder.WriterToDataApi; +import org.rcsb.mmtf.encoder.WriterUtils; + +public class Utils { + + public static Structure readFromByteArr(byte[] inputByteArr) throws IOException { + // Get the reader - this is the bit that people need to implement. + MmtfStructureReader mmtfStructureReader = new MmtfStructureReader(); + // Set up the inflator + DataApiToReader getToInflator = new DataApiToReader(); + // Now do the deserializer + MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); + // Do the inflation + getToInflator.read(new BeanToDataApi(messagePackDeserializer.deserialize(inputByteArr)), mmtfStructureReader); + // Get the structue + return mmtfStructureReader.getStructure(); + } + + + public static byte[] writeToByteArr(Structure structure) throws IOException { + // Set up this writer + WriterToDataApi inflatorToGet = new WriterToDataApi(); + // Get the writer - this is what people implement + MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); + // Now pass to the get API + mmtfStructureWriter.write(inflatorToGet); + return WriterUtils.getDataAsByteArr(inflatorToGet); + } + + /** + * Round trip a biojava structuree + * @param structure + * @return + * @throws IOException + */ + public static Structure roundTrip(Structure structure) throws IOException { + return readFromByteArr(writeToByteArr(structure)); + } + + + /** + * Get an MMTF bean from a pdb ID + * @param pdbId + * @return + * @throws StructureException + * @throws IOException + */ + public static MmtfBean getBean(String pdbId) throws IOException, StructureException { + Structure structure = StructureIO.getStructure(pdbId); + // Set up this writer + WriterToDataApi inflatorToGet = new WriterToDataApi(); + // Get the writer - this is what people implement + MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); + mmtfStructureWriter.write(inflatorToGet); + DataApiToBean dataApiToBean = new DataApiToBean(inflatorToGet); + return dataApiToBean.getMmtfBean(); + + } + +} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java index 3fbb8e0..1e58ff6 100644 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java @@ -5,9 +5,9 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.rcsb.mmtf.testutils.CheckOnBiojava; +import org.rcsb.mmtf.testutils.Utils; public class TestingUtils { @@ -35,7 +35,7 @@ public static void testSingleStructure(String pdbId) throws IOException, Structu MmtfUtils.setUpBioJava(); CheckOnBiojava checkEquiv = new CheckOnBiojava(); Structure mmcif = StructureIO.getStructure(pdbId); - checkEquiv.checkIfStructuresSame(mmcif,MmtfActions.roundTrip(StructureIO.getStructure(pdbId))); + checkEquiv.checkIfStructuresSame(mmcif,Utils.roundTrip(StructureIO.getStructure(pdbId))); } } diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java index 43f57c5..e5b7cf6 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java @@ -5,11 +5,11 @@ import java.io.IOException; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.junit.Test; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.testutils.IntegrationTestUtils; +import org.rcsb.mmtf.testutils.Utils; import org.rcsb.mmtf.update.TestingUtils; import org.unitils.reflectionassert.ReflectionAssert; @@ -34,7 +34,7 @@ public void testAll() throws IOException, StructureException{ private void testDataComplete(String pdbId) throws IOException, StructureException { MmtfUtils.setUpBioJava(); // Get an mmtfBean - MmtfBean mmtfBean = MmtfActions.getBean(pdbId); + MmtfBean mmtfBean = Utils.getBean(pdbId); // Make sure all fields are re-populated ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); // Now check the standard ones have been set diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java index 0aa5a45..98c28fe 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java @@ -1,18 +1,20 @@ package org.rcsb.mmtf.integrationtest; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import java.io.IOException; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.junit.Test; import org.rcsb.mmtf.api.MmtfDecodedDataInterface; import org.rcsb.mmtf.decoder.BeanToDataApi; import org.rcsb.mmtf.encoder.DataApiToBean; +import org.rcsb.mmtf.encoder.WriterToDataApi; import org.rcsb.mmtf.update.TestingUtils; @@ -25,7 +27,9 @@ public void testApiRoundTrip() throws IOException, StructureException, IllegalAr // First set up Biojava MmtfUtils.setUpBioJava(); Structure structure = StructureIO.getStructure("1O2F"); - MmtfDecodedDataInterface mmtfApi = MmtfActions.getApi(structure); + MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); + WriterToDataApi mmtfApi = new WriterToDataApi(); + mmtfStructureWriter.write(mmtfApi); DataApiToBean getToBean = new DataApiToBean(mmtfApi); MmtfDecodedDataInterface beanToGet = new BeanToDataApi(getToBean.getMmtfBean()); assertArrayEquals(beanToGet.getGroupTypeIndices(), mmtfApi.getGroupTypeIndices()); diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java index 9e47c7f..3f574a4 100644 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java +++ b/mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java @@ -1,12 +1,16 @@ package org.rcsb.mmtf.sedeserializers; import java.io.IOException; +import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; +import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; import org.biojava.nbio.structure.io.mmtf.MmtfUtils; import org.junit.Test; import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.deserializers.MessagePackDeserializer; +import org.rcsb.mmtf.encoder.DataApiToBean; +import org.rcsb.mmtf.encoder.WriterToDataApi; import org.rcsb.mmtf.serializers.MessagePackSerializer; import org.unitils.reflectionassert.ReflectionAssert; @@ -32,7 +36,12 @@ public void testSerializable() throws IOException, StructureException { */ private boolean testDeReSerialize() throws IOException, StructureException { MmtfUtils.setUpBioJava(); - MmtfBean inBean = MmtfActions.getBean("4cup"); + Structure structure = StructureIO.getStructure("4cup"); + MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); + WriterToDataApi mmtfApi = new WriterToDataApi(); + mmtfStructureWriter.write(mmtfApi); + DataApiToBean getToBean = new DataApiToBean(mmtfApi); + MmtfBean inBean = getToBean.getMmtfBean(); MessagePackSerializer messagePackSerializer = new MessagePackSerializer(); byte[] outArr = messagePackSerializer.serialize(inBean); MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); From a3ff0b5e2bbc4aa58c5834f4cdb42a6b1e20d190 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 17:40:47 -0700 Subject: [PATCH 091/108] Added coveralls integration --- pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 46f996b..7bcdb04 100644 --- a/pom.xml +++ b/pom.xml @@ -214,7 +214,11 @@ - + + org.eluder.coveralls + coveralls-maven-plugin + 4.1.0 + org.sonatype.plugins From 46ffe47869fbd6c0864db470cde78527e0e9dbe8 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 17:48:44 -0700 Subject: [PATCH 092/108] Added cobertura integration --- pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pom.xml b/pom.xml index 7bcdb04..760d0c6 100644 --- a/pom.xml +++ b/pom.xml @@ -214,6 +214,17 @@ + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + xml + 256m + + true + + org.eluder.coveralls coveralls-maven-plugin From 44807e691530b563696624d8c3a3ebd73535cf0a Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 17:49:13 -0700 Subject: [PATCH 093/108] Run cobertura on travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index adc4ff8..5991ecf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,5 @@ language: java jdk: - oraclejdk8 sudo: false +after_success: + - mvn clean cobertura:cobertura coveralls:report From 4a2d18521ddd4cc8cab274da610a0fb10eb91af8 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 17:29:14 -0700 Subject: [PATCH 094/108] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bdf158d..f0569a6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Build Status](https://travis-ci.org/rcsb/mmtf-java.svg?branch=master)](https://travis-ci.org/rcsb/mmtf-java) [![Dependency Status](https://www.versioneye.com/user/projects/56feb8e5fcd19a0039f1553c/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56feb8e5fcd19a0039f1553c) [![Version](http://img.shields.io/badge/version-0.0.1alpha3-blue.svg?style=flat)](http://biojava.org/wiki/BioJava:Download) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt) +[![Coverage Status](https://coveralls.io/repos/github/rcsb/mmtf-java/badge.svg?branch=master)](https://coveralls.io/github/rcsb/mmtf-java?branch=master) The **m**acro**m**olecular **t**ransmission **f**ormat (MMTF) is a binary encoding of biological structures. From db82ccab0ae1b2a2c44f7188aed323d646c3fef7 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Tue, 12 Apr 2016 19:01:57 -0700 Subject: [PATCH 095/108] Refactored the mmtf-update project out of mmtf-java. This is due to the dependency issues. It will be moved to mmtf-update repo --- mmtf-update/README.md | 2 - mmtf-update/pom.xml | 159 --------- .../mmtf/examples/DemoUnpackStructure.java | 60 ---- .../java/org/rcsb/mmtf/examples/HandleIO.java | 306 ----------------- .../org/rcsb/mmtf/examples/HelloWorld.java | 17 - .../org/rcsb/mmtf/examples/package-info.java | 8 - .../BiojavaStructureToBiojavaGroups.java | 40 --- .../ByteArrayToBioJavaStructMapper.java | 23 -- .../rcsb/mmtf/mappers/ByteWriteToByteArr.java | 25 -- .../org/rcsb/mmtf/mappers/GroupToSDF.java | 24 -- .../org/rcsb/mmtf/mappers/MapperUtils.java | 94 ------ .../org/rcsb/mmtf/mappers/PdbIdToMmtf.java | 24 -- .../mappers/StringByteToTextByteWriter.java | 30 -- .../mmtf/postupdatetests/CheckHadoopFile.java | 61 ---- .../mmtf/postupdatetests/CheckServer.java | 88 ----- .../preupdatetests/DataConsistencyCheck.java | 63 ---- .../mmtf/preupdatetests/FtpServerTest.java | 65 ---- .../preupdatetests/SandboxAccessTest.java | 20 -- .../org/rcsb/mmtf/testutils/CheckBonds.java | 315 ------------------ .../rcsb/mmtf/testutils/CheckOnBiojava.java | 304 ----------------- .../rcsb/mmtf/testutils/CheckOnRawApi.java | 124 ------- .../mmtf/testutils/IntegrationTestUtils.java | 51 --- .../java/org/rcsb/mmtf/testutils/Utils.java | 74 ---- .../rcsb/mmtf/update/BuildFirstDataSet.java | 72 ---- .../org/rcsb/mmtf/update/BuildSDFFile.java | 62 ---- .../org/rcsb/mmtf/update/FileWriters.java | 63 ---- .../java/org/rcsb/mmtf/update/OldFilter.java | 1 - .../rcsb/mmtf/update/ProcessHadoopFile.java | 128 ------- .../org/rcsb/mmtf/update/PullFtpData.java | 258 -------------- .../org/rcsb/mmtf/update/RemoveSuffix.java | 23 -- .../rcsb/mmtf/update/RemoveSuffixAndGzip.java | 52 --- .../org/rcsb/mmtf/update/ServerUtils.java | 41 --- .../org/rcsb/mmtf/update/TestingUtils.java | 41 --- .../org/rcsb/mmtf/update/WeeklyUpdateRun.java | 59 ---- .../rcsb/mmtf/update/WeeklyUpdateUtils.java | 116 ------- .../org/rcsb/mmtf/update/WriteHashMap.java | 112 ------- .../org/rcsb/mmtf/examples/TestHandleIO.java | 81 ----- .../rcsb/mmtf/integrationtest/TestBonds.java | 38 --- .../mmtf/integrationtest/TestParseMMCif.java | 50 --- .../mmtf/integrationtest/TestRoundTrip.java | 50 --- .../mmtf/sedeserializers/TestDataHolders.java | 55 --- .../org/rcsb/mmtf/update/TestReadWrite.java | 279 ---------------- .../java/org/rcsb/mmtf/update/TestSpark.java | 35 -- pom.xml | 6 +- 44 files changed, 2 insertions(+), 3597 deletions(-) delete mode 100644 mmtf-update/README.md delete mode 100644 mmtf-update/pom.xml delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/examples/HandleIO.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/examples/package-info.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/BiojavaStructureToBiojavaGroups.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteArrayToBioJavaStructMapper.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteWriteToByteArr.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/GroupToSDF.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/mappers/StringByteToTextByteWriter.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckHadoopFile.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/FtpServerTest.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/SandboxAccessTest.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckBonds.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/testutils/IntegrationTestUtils.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildFirstDataSet.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildSDFFile.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/FileWriters.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/OldFilter.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/ProcessHadoopFile.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/PullFtpData.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffix.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffixAndGzip.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/ServerUtils.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateRun.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateUtils.java delete mode 100644 mmtf-update/src/main/java/org/rcsb/mmtf/update/WriteHashMap.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/sedeserializers/TestDataHolders.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/update/TestReadWrite.java delete mode 100644 mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java diff --git a/mmtf-update/README.md b/mmtf-update/README.md deleted file mode 100644 index f1a1282..0000000 --- a/mmtf-update/README.md +++ /dev/null @@ -1,2 +0,0 @@ -Functions to run the weekly update using a given build of the project -This project is under development and is not fully documented. However it provides the template for running a weekly update of all available PDB data. diff --git a/mmtf-update/pom.xml b/mmtf-update/pom.xml deleted file mode 100644 index 5abc80f..0000000 --- a/mmtf-update/pom.xml +++ /dev/null @@ -1,159 +0,0 @@ - - 4.0.0 - - org.rcsb - mmtf - 0.0.1-alpha4-SNAPSHOT - - mmtf-update - jar - - mmtf-update - http://maven.apache.org - - - UTF-8 - - - - - org.biojava - biojava-structure - 5.0.0-SNAPSHOT - - - - junit - junit - compile - - - - - org.slf4j - slf4j-api - - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.apache.logging.log4j - log4j-api - - - org.apache.logging.log4j - log4j-core - - - org.apache.spark - spark-core_2.11 - 1.6.0 - - - org.unitils - unitils-core - 3.4.2 - test - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - true - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - true - allinone - - - *:* - - - - - reference.conf - - - - akka.Main - - - - - - - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - - uber-${project.artifactId}-${project.version} - - - - - - - - - maven-javadoc-plugin - 2.10.1 - - true - true - true - 1.8 - false - true - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.3 - - - - - - diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java deleted file mode 100644 index 50ef6cc..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/DemoUnpackStructure.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.rcsb.mmtf.examples; - -import java.io.IOException; - -import org.rcsb.mmtf.api.MmtfDecodedDataInterface; - -/** - * Demonstration of how to unpack a given structure using the dataApi. - * @author Anthony Bradley - * - */ -public class DemoUnpackStructure { - - /** - * Main function to run the demo class - * @param args no args required - * @throws IOException - */ - public static void main(String[] args) throws IOException { - // Create an instance of the handle IO class - HandleIO handleIO = new HandleIO(); - // The index of a given chain - int chainIndex = 0; - int groupIndex = 0; - int structureAtomIndex = 0; - // Create the instance of this API - in this case for the 4cup structure's data. - MmtfDecodedDataInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); - // Now loop through the models - for (int modelIndex=0; modelIndex 0 ) { - baos.write(byteChunk, 0, n); - } - } - catch (IOException e) { - System.err.printf ("Failed while reading bytes from %s: %s", url.toExternalForm(), e.getMessage()); - e.printStackTrace (); - // Perform any other exception handling that's appropriate. - } - finally { - if (is != null) { is.close(); } - } - byte[] b = baos.toByteArray(); - // Cache the data on the file system - cacheFile(b, basePath, inputCode); - // Now return the gzip deflated byte array - return deflateGzip(b); - } - - /** - * Gets the file from the file system. Specify the pdb id and the base path - * - * @param basePath the base path - * @param pdbCode the pdb code - * @return the from file system - * @throws FileNotFoundException the file not found exception - * @throws IOException Signals that an I/O exception has occurred. - */ - private final byte[] getFromFileSystem(final String basePath, final String pdbCode) { - - String fullFilePath = constructPath(basePath, pdbCode); - // Now return the message pack byte[] - return getFromFileSystem(fullFilePath); - } - - /** - * Construct the full path for the file to be stored on the file system. - * @param basePath The base directory (PDB_DIR in Biojava) - * @param pdbCode The four letter pdb code - * @return The full path, including suffic to be written out. - */ - private String constructPath(String basePath, String pdbCode) { - return basePath + "/data/structures/divided/msgpack" + "/" + pdbCode.substring(1, END_ID_FOR_MID_PDB) + "/" + pdbCode + ".mmtf"; - } - - /** - * Function to get a file from the file system - full path supplied. - * - * @param fullPath the full path - * @return the from file system - * @throws FileNotFoundException the file not found exception - * @throws IOException Signals that an I/O exception has occurred. - */ - private final byte[] getFromFileSystem(final String fullPath) { - // Get these as an inputstream - byte[] inputByteArr; - try { - inputByteArr = Files.readAllBytes(Paths.get(fullPath)); - } catch (IOException e) { - System.err.println("Could not find file: "+fullPath); - return null; - } - // Now return it - return deflateGzip(inputByteArr); - } - - /** - * Gets the file form the file system - * - * @param basePath the base path - * @param pdbId the pdb id - * @return the file - */ - private boolean getFile(final String basePath, final String pdbId) { - // Set the path for the file - if (basePath == null) { - System.out.println("Can't get - PDB_DIR and PDB_CACHE_DIR not specified"); - return false; - } - String dirPath = basePath - + "/data/structures/divided/msgpack/" - + pdbId.substring(1, END_ID_FOR_MID_PDB) + "/"; - String filePath = dirPath + pdbId + ".mmtf"; - File thisFile = new File(filePath); - return thisFile.exists(); - } - - /** - * Cache file. - * - * @param b the b - * @param basePath the base path - * @param pdbId the pdb id - * @throws IOException Signals that an I/O exception has occurred. - */ - private void cacheFile(final byte[] b, final String basePath, final String pdbId) { - // Set the path for the file - if (basePath == null) { - System.out.println("Not caching - PDB_DIR and PDB_CACHE_DIR not specified"); - return; - } - String dirPath = basePath - + "/data/structures/divided/msgpack/" - + pdbId.substring(1, END_ID_FOR_MID_PDB) + "/"; - String filePath = dirPath + pdbId + ".mmtf"; - - File thisFile = new File(dirPath); - boolean success = thisFile.mkdirs(); - if(success){ - System.out.println("Made base files"); - } - try { - FileOutputStream fos = new FileOutputStream(filePath); - fos.write(b); - fos.close(); - } catch (IOException e) { - // Error in caching the file - System.err.println("Error in caching file on file system: " + filePath); - return; - } - - } - - /** - * Deflate a gzip byte array. - * - * @param inputBytes -> gzip compressed byte - * array - * @return A deflated byte array - * @throws IOException Signals that an I/O exception has occurred. - */ - private byte[] deflateGzip(final byte[] inputBytes){ - // Start the byte input stream - ByteArrayInputStream bis = new ByteArrayInputStream(inputBytes); - GZIPInputStream gis; - try { - gis = new GZIPInputStream(bis); - } catch (IOException e) { - System.err.println("Error in opening byte array."); - e.printStackTrace(); - return null; - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - // Make a buffer - byte[] tmp = new byte[BYTE_BUFFER_CHUNK_SIZE]; - try { - while (gis.available() == 1) { - int size = gis.read(tmp); - if(size==-1){ - break; - } - baos.write(tmp, 0, size); - } - } - catch (Exception ex) { - ex.printStackTrace(); - return null; - } - finally { - try { - if (baos != null) { - baos.close(); - } - } catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } - // Get the bytes - byte[] outArr = baos.toByteArray(); - return outArr; - } - - /** - * Get the base path to cache the data in - * @return The base path to store the data in. Defined by environment variables. - */ - private String getBasePath() { - // First try to get it from a local file - String basePath = System.getProperty("PDB_CACHE_DIR"); - if (basePath == null) { - System.out.println("PDB_CACHE_DIR not available"); - basePath = System.getProperty("PDB_DIR"); - } - return basePath; - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java deleted file mode 100644 index a370795..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/HelloWorld.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.rcsb.mmtf.examples; - -import java.io.IOException; - -import org.rcsb.mmtf.api.MmtfDecodedDataInterface; - -public class HelloWorld { - - public static void main(String[] args) throws IOException { - HandleIO handleIO = new HandleIO(); - MmtfDecodedDataInterface dataApi = handleIO.getDataApiFromUrlOrFile("4cup"); - System.out.println("PDB Code: "+dataApi.getStructureId()+" has "+dataApi.getNumChains()+" chains"); - System.out.println("HET group "+dataApi.getGroupName(0)+" has the following atomic charges: "+dataApi.getGroupAtomCharges(0)); - System.out.println("PDB Code: "+dataApi.getStructureId()+" has "+dataApi.getNumBioassemblies()+" bioassemblies"); - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/package-info.java b/mmtf-update/src/main/java/org/rcsb/mmtf/examples/package-info.java deleted file mode 100644 index ae4a2d6..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/examples/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Example functions using the decoder. - */ -/** - * @author Anthony Bradley - * - */ -package org.rcsb.mmtf.examples; diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/BiojavaStructureToBiojavaGroups.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/BiojavaStructureToBiojavaGroups.java deleted file mode 100644 index c3c37c7..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/BiojavaStructureToBiojavaGroups.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.rcsb.mmtf.mappers; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.spark.api.java.function.PairFlatMapFunction; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.Structure; - -import scala.Tuple2; - -/** - * Extracts all of the groups from a given Biojava structure - * @author Anthony Bradley - * - */ -public class BiojavaStructureToBiojavaGroups implements PairFlatMapFunction, String, Group>{ - - private static final long serialVersionUID = 9211500299985679809L; - - @Override - public Iterable> call(Tuple2 t) throws Exception { - // The list to return - List> outList = new ArrayList>(); - for(int modelNr=0; modelNr myGroups = c.getAtomGroups(); - // Now loop through these groups and add them to the outputlist - for(Group g: myGroups){ - // Now generate the unique id - String uniqId = modelNr+"_"+c.getChainID()+"_"+g.getResidueNumber(); - outList.add(new Tuple2(uniqId, g)); - } - } - } - return outList; - } -} \ No newline at end of file diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteArrayToBioJavaStructMapper.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteArrayToBioJavaStructMapper.java deleted file mode 100644 index 6bfb4ce..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteArrayToBioJavaStructMapper.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.rcsb.mmtf.mappers; - -import org.apache.spark.api.java.function.PairFunction; -import org.biojava.nbio.structure.Structure; - -import scala.Tuple2; - -/** - * Maps a String byte[] of a message pack to a String Structure of the biojava structure - * @author Anthony Bradley - * - */ -public class ByteArrayToBioJavaStructMapper implements PairFunction,String, Structure> { - - private static final long serialVersionUID = -1671280971380509379L; - - - @Override - public Tuple2 call(Tuple2 t) throws Exception { - // Now return this - return new Tuple2(t._1, MapperUtils.byteArrToBiojavaStruct(t._1, t._2)); - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteWriteToByteArr.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteWriteToByteArr.java deleted file mode 100644 index 0aadfc1..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/ByteWriteToByteArr.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.rcsb.mmtf.mappers; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.api.java.function.PairFunction; - -import scala.Tuple2; - -/** - * Maps the input of a Hadoop sequence file (Text/Bytes Writeable) to a String, byte[] - * @author Anthony Bradley - * - */ -public class ByteWriteToByteArr implements PairFunction,String, byte[]> { - - - private static final long serialVersionUID = 1466772536507675533L; - - @Override - public Tuple2 call(Tuple2 t) throws Exception { - // Simply return the byte array - return new Tuple2(t._1.toString(), t._2.copyBytes()); - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/GroupToSDF.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/GroupToSDF.java deleted file mode 100644 index 596f38b..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/GroupToSDF.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.rcsb.mmtf.mappers; - - -import org.apache.spark.api.java.function.PairFunction; -import org.biojava.nbio.structure.Group; - - -import scala.Tuple2; - -public class GroupToSDF implements PairFunction,String, String> { - - /** - * - */ - private static final long serialVersionUID = 1L; - - @Override - public Tuple2 call(Tuple2 t) throws Exception { - // Now just return the group as the SDF - return new Tuple2(t._1, t._2.toSDF()); - } - -} - diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java deleted file mode 100644 index 3c2397c..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/MapperUtils.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.rcsb.mmtf.mappers; - -import java.io.IOException; -import java.io.Serializable; -import java.util.List; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.rcsb.mmtf.decoder.BeanToDataApi; -import org.rcsb.mmtf.decoder.DataApiToReader; -import org.rcsb.mmtf.deserializers.MessagePackDeserializer; -import org.rcsb.mmtf.encoder.WriterToDataApi; -import org.rcsb.mmtf.encoder.WriterUtils; - -/** - * A class to preserve the log if the functions in mappers. - * Mappers should not contain logic - as they are hard to test. - * @author Anthony Bradley - * - */ -public class MapperUtils implements Serializable{ - - private static final long serialVersionUID = -4717807367698811030L; - - /** - * Converts a byte array of the messagepack (mmtf) to a Biojava structure. - * @param pdbCodePlus The pdb code is the first four characters. Additional characters can be used. - * @param inputByteArr The message pack bytre array to be decoded. - * @return - * @throws IOException - */ - public static Structure byteArrToBiojavaStruct(String pdbCodePlus, byte[] inputByteArr) throws IOException { - MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); - // Get the reader - this is the bit that people need to implement. - MmtfStructureReader mmtfStructureReader = new MmtfStructureReader(); - // Set up the inflator - DataApiToReader getToInflator = new DataApiToReader(); - Structure newStruct; - try{ - // Do the inflation - getToInflator.read(new BeanToDataApi( messagePackDeserializer.deserialize(inputByteArr)), mmtfStructureReader); - // Get the structue - newStruct = mmtfStructureReader.getStructure();; - } - catch(Exception e){ - System.out.println(e); - System.out.println(pdbCodePlus); - Structure thisStruct = new StructureImpl(); - return thisStruct; - } - return newStruct; - } - - /** - * PDB RDD gnerateor. Converts a list of pdb ids to a writeable RDD - * @param sparkContext - * @return - */ - public JavaPairRDD generateRDD(JavaSparkContext sparkContext, List inputList, String inputUrl) { - // Set up Biojava appropriateyl - MmtfUtils.setUpBioJava(); - return sparkContext.parallelize(inputList) - .mapToPair(new PdbIdToMmtf()) - .mapToPair(new StringByteToTextByteWriter()); - } - - /** - * Get the available data as a byte array - * @param pdbId - * @return the data as a byte array - * @throws StructureException - * @throws IOException - */ - public static byte[] getByteArray(String pdbId) throws IOException, StructureException { - Structure structure = StructureIO.getStructure(pdbId); - // Set up this writer - WriterToDataApi inflatorToGet = new WriterToDataApi(); - // Get the writer - this is what people implement - MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); - // Now pass to the get API - mmtfStructureWriter.write(inflatorToGet); - // Now write this dat to file - return WriterUtils.getDataAsByteArr(inflatorToGet); - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java deleted file mode 100644 index de00179..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/PdbIdToMmtf.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.rcsb.mmtf.mappers; - - -import org.apache.spark.api.java.function.PairFunction; - -import scala.Tuple2; - -/** - * Generate the internal data structure (using biojava) from a PDB code. - * @author Anthony Bradley - * - */ -public class PdbIdToMmtf implements PairFunction{ - - private static final long serialVersionUID = 786599975302506694L; - - @Override - public Tuple2 call(String t) throws Exception { - return new Tuple2(t, MapperUtils.getByteArray(t)); - } - - -} - diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/StringByteToTextByteWriter.java b/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/StringByteToTextByteWriter.java deleted file mode 100644 index 7482863..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/mappers/StringByteToTextByteWriter.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.rcsb.mmtf.mappers; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.api.java.function.PairFunction; - -import scala.Tuple2; - -/** - * Converts a tuple of string and byte array, to a Text and Bytes writeable. - * This is required for writing hadoop sequence files of data in this format. - * @author Anthony Bradley - * - */ -public class StringByteToTextByteWriter implements PairFunction, Text, BytesWritable>{ - - private static final long serialVersionUID = 8149053011560186912L; - - @Override - public Tuple2 call(Tuple2 t) throws Exception { - // TODO Auto-generated method stub - Text outT = new Text(); - outT.set(t._1); - BytesWritable outBytes = new BytesWritable(); - byte[] theseBytes = t._2; - outBytes.set(theseBytes, 0, theseBytes.length); - return new Tuple2(outT,outBytes); - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckHadoopFile.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckHadoopFile.java deleted file mode 100644 index 9e04810..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckHadoopFile.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.rcsb.mmtf.postupdatetests; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Serializable; -import java.util.List; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.biojava.nbio.structure.Structure; -import org.rcsb.mmtf.mappers.ByteArrayToBioJavaStructMapper; -import org.rcsb.mmtf.mappers.ByteWriteToByteArr; - - -public class CheckHadoopFile implements Serializable { - - - private static final long serialVersionUID = 3037567648753603114L; - - /** - * A function to read a hadoop sequence file to Biojava structures. - * 1) The input path of the available data - * 2) The output path indicating the number of PDB ids and a list of the ids. - * @param args - * @throws IOException - */ - public static void main(String[] args ) throws IOException - { - // The input path for the data is the fist - String inPath = args[0]; - String pdbIdList = args[1]; - - // This is the default 2 line structure for Spark applications - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(CheckHadoopFile.class.getSimpleName()); - // Set the config for the spark context - JavaSparkContext sc = new JavaSparkContext(conf); - JavaPairRDD jprdd = sc - .sequenceFile(inPath, Text.class, BytesWritable.class, 24) - .mapToPair(new ByteWriteToByteArr()) - // Now get the structure - .mapToPair(new ByteArrayToBioJavaStructMapper()); - JavaRDD values = jprdd.keys(); - List outValues = values.collect(); - // Write the PDB files to a file - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(pdbIdList))); - writer.write(outValues.size()+"\n"); - for (String pdbId : outValues) { - writer.write(pdbId+","); - } - writer.close(); - // Now move the folder - sc.close(); - } -} \ No newline at end of file diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java b/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java deleted file mode 100644 index d0b702e..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/postupdatetests/CheckServer.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.rcsb.mmtf.postupdatetests; - -import java.io.File; -import java.io.IOException; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.rcsb.mmtf.examples.HandleIO; -import org.rcsb.mmtf.testutils.CheckOnBiojava; -import org.rcsb.mmtf.testutils.CheckOnRawApi; -import org.rcsb.mmtf.testutils.IntegrationTestUtils; -import org.rcsb.mmtf.testutils.Utils; - -public class CheckServer { - - private HandleIO handleIo; - private FileParsingParameters params; - private CheckOnBiojava checkEquiv; - - /** - * Java class to check if data can be parsed from the server. - * 1) Arg one is the server - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException { - String baseUrl = args[0]; - String outPutFile = args[1]; - CheckServer checkServer = new CheckServer(); - checkServer.basicParsingTest(baseUrl); - File f = new File(outPutFile); - f.getParentFile().mkdirs(); - f.createNewFile(); - } - - - /** - * Basic test to go through a series of PDBs and make sure they are the same. - * Should be run at the end of the weekly update to ensure data integrity. - * @throws IOException - */ - public void basicParsingTest(String baseUrl) throws IOException { - // Get the class to parse and get data - handleIo = new HandleIO(); - checkEquiv = new CheckOnBiojava(); - AtomCache cache = MmtfUtils.setUpBioJava(); - params = cache.getFileParsingParams(); - // Test it for a series of structures - for (String pdbId : IntegrationTestUtils.TEST_CASES) { - testParsing(pdbId, HandleIO.BASE_URL); - } - } - - /** - * This tests whether the data on the website can be decoded to produce the same - * data as parsing the mmcif data. - * @param inputPdb - * @throws IOException - */ - private void testParsing(String inputPdb, String inputUrl) throws IOException { - System.out.println("TESTING: "+inputPdb); - byte[] inputByteArr = handleIo.getFromUrl(inputPdb, inputUrl); - Structure mmtfStruct = Utils.readFromByteArr(inputByteArr); - // Now parse from the MMCIF file - Structure mmcifStruct; - try { - mmcifStruct = StructureIO.getStructure(inputPdb); - } catch (IOException e) { - // Error accessing mmcif - System.err.println("Error accessing MMCIF"); - e.printStackTrace(); - throw new RuntimeException(); - } catch (StructureException e) { - System.err.println("Error parsing/consuming MMCIF"); - e.printStackTrace(); - throw new RuntimeException(); - } - checkEquiv.checkIfStructuresSame(mmtfStruct, mmcifStruct); - // Now do the checks on the Raw data - CheckOnRawApi checkRaw = new CheckOnRawApi(inputByteArr); - checkRaw.checkRawDataConsistency(mmcifStruct, params); - - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java deleted file mode 100644 index 6da0306..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/DataConsistencyCheck.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.rcsb.mmtf.preupdatetests; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.rcsb.mmtf.update.ServerUtils; -import org.rcsb.mmtf.update.TestingUtils; -import org.rcsb.mmtf.update.WeeklyUpdateUtils; - -/** - * Is the data to be added on the FTP site available, parseable and consistent when roundtripped. - * @author Anthony Bradley - * - */ -public class DataConsistencyCheck { - - /** - * 1) Argument one is the FTP server for the update lists - * 2) Argumnet two is the server for the mmcif.gz files - * 3) Argument three is the file to write at the end - * 4) The URL for the CCD data - * 5+ The pdbs to ignore - * @param args - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws IOException - * @throws StructureException - */ - public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, IOException, StructureException { - - - // Set up the atom cache etc - ServerUtils serverUtils = new ServerUtils(); - MmtfUtils.setUpBioJava(args[3]); - // Now get the list of PDB ids to ignore - List ignoreList = new ArrayList<>(); - for (int i=4; i listToAdd = weeklyUpdate.getAddedList(); - String[] urlList = new String[listToAdd.size()]; - for (int i =0; i< listToAdd.size(); i++) { - urlList[i] = args[1] + serverUtils.generateDataExtension(listToAdd.get(i)); - } - String outPutFile = args[2]; - TestingUtils.testList(urlList); - File f = new File(outPutFile); - f.getParentFile().mkdirs(); - f.createNewFile(); - } - - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/FtpServerTest.java b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/FtpServerTest.java deleted file mode 100644 index 5af5353..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/FtpServerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.rcsb.mmtf.preupdatetests; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.lang.StringUtils; -import org.rcsb.mmtf.update.PullFtpData; -import org.rcsb.mmtf.update.ServerUtils; - - -public class FtpServerTest { - - /** - * Can we get to the ftp site and download the data - * First argument is the URL - * Second argument is the file to write out - * @throws IOException - */ - public static void main(String[] args) throws IOException { - String url = args[0]; - String outPutFile = args[1]; - FtpServerTest ftpServerTest = new FtpServerTest(); - PullFtpData pullFtpData = new PullFtpData(url); - // Get the host and port - // First check we can ping the server - assertTrue(ServerUtils.pingServer(url)); - // Check this is not empty - String[] currentEntries; - currentEntries = pullFtpData.getAllCurrentEntries(); - ftpServerTest.checkAllPdbIds(currentEntries); - assertNotEquals(currentEntries, null); - assertNotEquals(currentEntries.length, 0); - assertNotEquals(currentEntries.length, 1); - // Now check the others aren't null - currentEntries = pullFtpData.getAllCurrentModels(); - ftpServerTest.checkAllPdbIds(currentEntries); - assertNotEquals(currentEntries, null); - assertNotEquals(currentEntries.length, 0); - assertNotEquals(currentEntries.length, 1); - currentEntries = pullFtpData.getAllObsoleteEntries(); - ftpServerTest.checkAllPdbIds(currentEntries); - assertNotEquals(currentEntries, null); - assertNotEquals(currentEntries.length, 0); - assertNotEquals(currentEntries.length, 1); - // Check there is something to be updated - assertNotEquals(currentEntries, null); - currentEntries = pullFtpData.getAdded(); - assertNotEquals(currentEntries.length, 0); - File f = new File(outPutFile); - f.getParentFile().mkdirs(); - f.createNewFile(); - } - - - private void checkAllPdbIds(String[] inputData) { - // Check they all equal 4 - for (String inputId : inputData) { - assertEquals(inputId.length(), 4); - assertTrue(StringUtils.isAlphanumeric(inputId)); - } - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/SandboxAccessTest.java b/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/SandboxAccessTest.java deleted file mode 100644 index 121e0e1..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/preupdatetests/SandboxAccessTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.rcsb.mmtf.preupdatetests; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; - -import org.rcsb.mmtf.update.ServerUtils; - -public class SandboxAccessTest { - public static void main(String[] args) throws IOException { - String url = args[0]; - String outPutFile = args[1]; - // Assert that we can reach this server - assertTrue(ServerUtils.pingServer(url)); - File f = new File(outPutFile); - f.getParentFile().mkdirs(); - f.createNewFile(); - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckBonds.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckBonds.java deleted file mode 100644 index 37c2e28..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckBonds.java +++ /dev/null @@ -1,315 +0,0 @@ -package org.rcsb.mmtf.testutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Bond; -import org.biojava.nbio.structure.Calc; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.GroupType; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompAtom; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompBond; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.biojava.nbio.structure.rcsb.GetRepresentatives; - -public class CheckBonds { - - private StringBuilder stringBuilder; - private Structure structure; - - private static final double MAX_NUCLEOTIDE_BOND_LENGTH = 2.2; - private static final double MAX_PEPTIDE_BOND_LENGTH = 1.9; - - public void testAllConsistency() throws IOException, StructureException { - - // Set up biojava - MmtfUtils.setUpBioJava(); - for (String testCase : GetRepresentatives.getAll()) { - Structure structure = StructureIO.getStructure(testCase); - MmtfUtils.fixMicroheterogenity(structure); - checkIfBondsExist(structure); - } - } - - /** - * Test to see if bonds exist for all atoms on a chain - * @return - */ - public String checkIfBondsExist(Structure inputStructure) { - // Set the structure as the input to the function - structure = inputStructure; - stringBuilder = new StringBuilder(); - // ONLY DO THE TEST FOR THE FIRST MODEL - for(int i=0;i<1;i++){ - List chainsOne = structure.getChains(i); - // Now loop over - for(int j=0; j groupsOne = chainOne.getAtomGroups(); - for(int k=0; k groupsOne, int k) { - // It has to be a nucleotide - if (!groupOne.getType().equals(GroupType.NUCLEOTIDE)){ - return; - } - // Find the P - Atom groupOneP = groupOne.getAtom("P"); - if (groupOneP==null) { - return; - } - // Find the neighhbouring O3P - // Now find the neighbouring Ns - if(k>0){ - Atom otherO3P = groupsOne.get(k-1).getAtom("O3'"); - if(otherO3P!=null){ - checkNucleotideBond(groupOneP, otherO3P); - } - - } - if(k MAX_NUCLEOTIDE_BOND_LENGTH) { - // It shouldn't have a bond - checkBonded(groupOneP, otherO3P, 1, false); - } - else { - // It should have a bond - checkBonded(groupOneP, otherO3P, 1, true); - } - - } - - /** - * Ensure a group that is part of a polypeptide has a peptide bond to it's next amino acid (if the group and atom exists). - * @param groupOne - * @param k - * @param groupsOne - */ - private void checkPeptideBondsAreMade(Group groupOne, List groupsOne, int k) { - // It has to be an amino acid - if (!groupOne.getType().equals(GroupType.AMINOACID)){ - return; - } - // Find the calpha - Atom groupOneCalpha = groupOne.getAtom("CA"); - // An amino acid without a calpha - skip - if (groupOneCalpha==null) { - return; - } - // Now find the neighbouring Ns - if(k>0){ - Atom otherN = groupsOne.get(k-1).getAtom("N"); - if(otherN!=null){ - checkPeptideBond(groupOneCalpha, otherN); - } - - } - if(k MAX_PEPTIDE_BOND_LENGTH) { - // It shouldn't have a bond - checkBonded(groupOneCalpha, otherN, 1, false); - } - else { - // It should have a bond - checkBonded(groupOneCalpha, otherN, 1, true); - } - } - - /** - * Check that all atoms in a given group have bonds. - * @param groupOne - */ - private void checkAllAtomsHaveBonds(Group groupOne) { - List atomsOne = new ArrayList<>(groupOne.getAtoms()); - for(Group altLocOne: groupOne.getAltLocs()){ - for(Atom atomAltLocOne: altLocOne.getAtoms()){ - atomsOne.add(atomAltLocOne); - } - } - // If it's just a single atom - if (groupOne.getAtoms().size()==1){ - return; - } - // If it's a water - if (groupOne.isWater()) { - return; - } - // If the sum of the occupancy is less than or equal to 1.00 - float occ = (float) 0.0; - for (Atom a: groupOne.getAtoms()) { - occ += a.getOccupancy(); - } - if (occ <= 1.0) { - return; - } - - // Now let's check to see if all atoms have bonds... - for(int l=0;l atomNameList = new ArrayList<>(); - for(ChemCompAtom thisAtom: groupOne.getChemComp().getAtoms()) { - atomNameList.add(thisAtom.getAtom_id()); - } - if (atomsOne.get(l).getBonds()==null){ - // Check if the ATOM is not in the CCD - if(!atomNameList.contains(atomsOne.get(l).getName())){ - stringBuilder.append(structure.getPDBCode()+": ### ATOM NOT IN CCD AND HAS NO BONDS ->> "+atomsOne.get(l).toPDB()+"\n"); - continue; - } - } - // Check that in all cases the other groups are found in this list... - if(!atomNameList.contains(atomsOne.get(l).getName())){ - stringBuilder.append(structure.getPDBCode()+": ### ATOM NOT IN CCD BUT HAS "+atomsOne.get(l).getBonds().size()+" BONDS ->> "+atomsOne.get(l).toPDB()+"\n"); - } - // Bonds should not be null (but they currently are - have this here to remind us so... - if (atomsOne.get(l).getBonds()==null){ - stringBuilder.append(structure.getPDBCode()+": ATOM IN CCD BUT HAS NULL BONDS ->> "+atomsOne.get(l).toPDB()+"\n"); - } - else{ - // And should not be empty lists - assertNotEquals(atomsOne.get(l).getBonds().size(), 0); - } - } - } - - /** - * Function to ensure that all bonds that can be made are being made. - * @param structure - */ - public void checkIfIntraGroupBondsAreCreated(Group inputGroup) { - - List allGroups = new ArrayList<>(inputGroup.getAltLocs()); - allGroups.add(inputGroup); - - for (Group group : allGroups) { - // Get the CCD - ChemComp inputChemComp = group.getChemComp(); - // Get the bonds - for (ChemCompBond inputBond : inputChemComp.getBonds()) { - String atomNameOne = inputBond.getAtom_id_1(); - String atomNameTwo = inputBond.getAtom_id_2(); - Atom atomOne = group.getAtom(atomNameOne); - Atom atomTwo = group.getAtom(atomNameTwo); - if (atomOne != null && atomTwo != null) { - // Ensure that if both atoms exist - the bond exists. - checkBonded(atomOne, atomTwo, inputBond.getNumericalBondOrder(), true); - } - } - } - - } - -/** - * Check that two atoms are bonded - * @param atomOne - * @param atomTwo - */ -private void checkBonded(Atom atomOne, Atom atomTwo, Integer bondOrder, boolean isBonded) { - List otherAtoms = new ArrayList<>(); - List bondInds = new ArrayList<>(); - for (Bond groupBond : atomOne.getBonds()) { - otherAtoms.add(groupBond.getOther(atomOne)); - bondInds.add(groupBond.getBondOrder()); - } - // Assert that it's bonded to the other - assertTrue(otherAtoms.contains(atomTwo)==isBonded); - // And that's it not bonded to itself - assertTrue(!otherAtoms.contains(atomOne)); - if (isBonded) { - // Assert that it's only bonded once to the other - if(otherAtoms.indexOf(atomTwo)!=otherAtoms.lastIndexOf(atomTwo)){ - System.out.println("Bonded more than once: "+atomOne.getGroup().getChain().getStructure().getPDBCode()); - System.out.println(atomOne); - System.out.println(atomTwo); - } - assertEquals(otherAtoms.indexOf(atomTwo), otherAtoms.lastIndexOf(atomTwo)); - // Assert that the bond order is correct - if(bondOrder != bondInds.get(otherAtoms.indexOf(atomTwo))){ - System.out.println("Wrong bond order: "+atomOne.getGroup().getChain().getStructure().getPDBCode()); - System.out.println(atomOne); - System.out.println(atomTwo); - } - assertEquals(bondOrder, bondInds.get(otherAtoms.indexOf(atomTwo))); - } -} -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java deleted file mode 100644 index cefa818..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnBiojava.java +++ /dev/null @@ -1,304 +0,0 @@ -package org.rcsb.mmtf.testutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertArrayEquals; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.Map.Entry; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Bond; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.EntityInfo; -import org.biojava.nbio.structure.ExperimentalTechnique; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.PDBHeader; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; -import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; - -public class CheckOnBiojava { - - public CheckOnBiojava() { - } - - /** - * Broad test of atom similarity - * @param structOne - * @param structTwo - * @param mmtfParams) - * @return - */ - private boolean checkIfAtomsSame(Structure structOne, Structure structTwo) { - int numModels = structOne.nrModels(); - if(numModels!=structTwo.nrModels()){ - System.out.println("Error - diff number models: "+structOne.getPDBCode()); - return false; - } - for(int i=0;i chainsOne = structOne.getChains(i); - List chainsTwo = structTwo.getChains(i); - - if(chainsOne.size()!=chainsTwo.size()){ - System.out.println("Error - diff number chains: "+structOne.getPDBCode()); - return false; - } - // Now loop over - for(int j=0; j groupsOne = chainOne.getAtomGroups(); - List groupsTwo = chainTwo.getAtomGroups(); - if(groupsOne.size()!=groupsTwo.size()){ - System.out.println("Error - diff number groups: "+structOne.getPDBCode()); - return false; - } - for(int k=0; k atomsOne = new ArrayList<>(groupOne.getAtoms()); - List atomsTwo = new ArrayList<>(groupTwo.getAtoms()); - if(groupOne.getAltLocs().size()!=0){ - if(groupTwo.getAltLocs().size()!=groupOne.getAltLocs().size()){ - System.out.println("Error - diff number alt locs: "+structOne.getPDBCode()+" "+groupOne.getPDBName()+" "+groupOne.getResidueNumber().getSeqNum()); - System.out.println(groupOne.getAltLocs().size()); - System.out.println(groupTwo.getAltLocs().size()); - - } - // Now go over the alt locs - for(Group altLocOne: groupOne.getAltLocs()){ - for(Atom atomAltLocOne: altLocOne.getAtoms()){ - atomsOne.add(atomAltLocOne); - } - } - for(Group altLocTwo: groupTwo.getAltLocs()){ - for(Atom atomAltLocTwo: altLocTwo.getAtoms()){ - atomsTwo.add(atomAltLocTwo); - } - } - } - if(atomsOne.size()!=atomsTwo.size()){ - System.out.println("Error - diff number atoms: "+structOne.getPDBCode()); - System.out.println(groupOne.getPDBName()+" vs "+groupTwo.getPDBName()); - System.out.println(atomsOne.size()+" vs "+atomsTwo.size()); - return false; - } - // Now sort the atoms - atomsOne.sort(new Comparator() { - - @Override - public int compare(Atom o1, Atom o2) { - // - if (o1.getPDBserial()() { - - @Override - public int compare(Atom o1, Atom o2) { - // - if (o1.getPDBserial() entityListOne = structOne.getEntityInfos(); - List entityListTwo = structTwo.getEntityInfos(); - assertEquals(entityListOne.size(), entityListTwo.size()); - for (int i=0; i bioassembliesOne = cleanUpBioass(structOne); - Map bioassembliesTwo = structTwo.getPDBHeader().getBioAssemblies(); - assertEquals(bioassembliesOne.keySet(), bioassembliesTwo.keySet()); - for(Entry entry: bioassembliesOne.entrySet()){ - // Get the bioassembly info - BioAssemblyInfo valueOne = entry.getValue(); - BioAssemblyInfo valueTwo = bioassembliesTwo.get(entry.getKey()); - assertEquals(valueOne.getId(), valueTwo.getId()); - // Check there's the same number of transforms - assertEquals(valueOne.getTransforms().size(), valueTwo.getTransforms().size()); - // Build a map of chain id to matrix 4d - Set keySetOne = new TreeSet<>(); - Set keySetTwo = new TreeSet<>(); - Set valSetOne = new TreeSet<>(); - Set valSetTwo = new TreeSet<>(); - for(int i= 0; i< valueOne.getTransforms().size();i++){ - BiologicalAssemblyTransformation transformOne = valueOne.getTransforms().get(i); - BiologicalAssemblyTransformation transformTwo = valueTwo.getTransforms().get(i); - // Check these are the same - keySetOne.add(transformOne.getChainId()); - keySetTwo.add(transformTwo.getChainId()); - valSetOne.add(transformOne.getTransformationMatrix().toString()); - valSetTwo.add(transformTwo.getTransformationMatrix().toString()); - } - assertEquals(keySetOne, keySetTwo); - assertEquals(valSetOne, valSetTwo); - - } - } - - /** - * Remove any transformation applying to empty chains. - * @param inputStruct The input Biojava Structure to be used. - * @return The bioassemblies cleande up. - */ - private Map cleanUpBioass(Structure inputStruct) { - // Get the bioassemblies - Map bioAssemblies = inputStruct.getPDBHeader().getBioAssemblies(); - // Create a list of chains - List chainList = new ArrayList<>(); - for (int i=0; i entry : bioAssemblies.entrySet()) { - BioAssemblyInfo val = entry.getValue(); - List removeList = new ArrayList<>(); - for (BiologicalAssemblyTransformation bioTrans : val.getTransforms()) { - // Check if it exists - if(!chainList.contains(bioTrans.getChainId())) { - removeList.add(bioTrans); - } - } - val.getTransforms().removeAll(removeList); - } - return bioAssemblies; - } - - /** - * Check if all features between the two structures are the same - * @param biojavaStruct the input Biojava structure parsed from the mmcif file - * @param structTwo the BioJava structure parsed from the MMTF file - * @param mmtfParams - */ - public void checkIfStructuresSame(Structure biojavaStruct, Structure structTwo){ - // First check the bioassemblies - checkIfBioassemblySame(biojavaStruct, structTwo); - // Now check the pdb header - checkIfHederSame(biojavaStruct, structTwo); - // Now check the entity information - checkIfEntitiesSame(biojavaStruct, structTwo); - assertTrue(checkIfAtomsSame(biojavaStruct, structTwo)); - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java deleted file mode 100644 index 7ebd832..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/CheckOnRawApi.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.rcsb.mmtf.testutils; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.EntityInfo; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.decoder.BeanToDataApi; -import org.rcsb.mmtf.deserializers.MessagePackDeserializer; - -/** - * Class to test the raw API - * @author Anthony Bradley - * - */ -public class CheckOnRawApi { - MmtfDecodedDataInterface dataApi; - public CheckOnRawApi(byte[] inputData) throws IOException { - dataApi = new BeanToDataApi(new MessagePackDeserializer().deserialize(inputData)); - } - - /** - * Check that required data is available the way we would expect. - * @param biojavaStruct The input structure (parsed from MMCIF) that can be used to compare. - * @param params The input file parsing parameters. - */ - public void checkRawDataConsistency(Structure biojavaStruct, FileParsingParameters params) { - // Series of tests on expected values from the raw API - assertNotEquals(dataApi.getMmtfProducer(), null); - assertNotEquals(dataApi.getMmtfVersion(), null); - checkIfSeqResInfoSame(biojavaStruct, params); - checkIfEntityInfoSame(biojavaStruct); - // Check other features in the data - } - - - /** - * Test to see if the roundtripped entity data is the same as is found in the MMCIF - */ - public void checkIfEntityInfoSame(Structure biojavaStruct) { - - // Fist check it's not null - assertNotEquals(dataApi.getNumEntities(), null); - // Second check it's the same length - assertEquals(dataApi.getNumEntities(), biojavaStruct.getEntityInfos().size()); - List totChains = new ArrayList<>(); - for (int i=0; i < biojavaStruct.nrModels(); i++) { - totChains.addAll(biojavaStruct.getChains(i)); - } - // Now check it has the same information as BioJava - for(int i=0; i bioJavaChains = biojavaEntity.getChains(); - int[] mmtfList = dataApi.getEntityChainIndexList(i); - assertEquals(mmtfList.length, bioJavaChains.size()); - int[] testList = new int[bioJavaChains.size()]; - for(int j=0; j thisChainSeqResList = new ArrayList<>(); - for(Group seqResGroup : currentChain.getSeqResGroups()){ - thisChainSeqResList.add(seqResGroup); - } - // Now go through and check the indices line up - for(int i = 0; i < currentChain.getAtomGroups().size(); i++){ - // Get the group - Group testGroup = currentChain.getAtomGroup(i); - int testGroupInd = thisChainSeqResList.indexOf(testGroup); - assertEquals(testGroupInd, decodedSeqResGroupList[groupCounter]); - groupCounter++; - } - chainCounter++; - } - } - // Otherwise we need to parse in a different - else{ - System.out.println("Using public facing chain ids -> seq res not tested"); - } - - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/IntegrationTestUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/IntegrationTestUtils.java deleted file mode 100644 index 84dd862..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/IntegrationTestUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.rcsb.mmtf.testutils; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.UUID; - -public class IntegrationTestUtils { - - public static final String[] TEST_CASES = new String[] { - // Another weird structure (jose's suggestion) - "3zyb", - //Standard structure - "4cup", - // Weird NMR structure - "1o2f", - // B-DNA structure - "1bna", - // DNA structure - "4y60", - // Sugar structure - "1skm", - // Calpha atom is missing (not marked as calpha) - "1lpv", - // NMR structure with multiple models - one of which has chain missing - "1msh", - // No ATOM records just HETATM records (in PDB). Opposite true for MMCif. It's a D-Peptide. - "1r9v", - // Biosynthetic protein - "5emg", - // Micro heterogenity - "4ck4", - // Ribosome - "4v5a", - // Negative residue numbers - "5esw" - }; - - public Path returnTempDir() { - Path tmpDir; - String uuid = UUID.randomUUID().toString(); - try { - tmpDir = Files.createTempDirectory(uuid); - } catch (IOException e) { - System.err.println("Error in making temp directory"); - e.printStackTrace(); - throw new RuntimeException(); - } - return tmpDir; - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java deleted file mode 100644 index c9283ee..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/testutils/Utils.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.rcsb.mmtf.testutils; - -import java.io.IOException; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; -import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.decoder.BeanToDataApi; -import org.rcsb.mmtf.decoder.DataApiToReader; -import org.rcsb.mmtf.deserializers.MessagePackDeserializer; -import org.rcsb.mmtf.encoder.DataApiToBean; -import org.rcsb.mmtf.encoder.WriterToDataApi; -import org.rcsb.mmtf.encoder.WriterUtils; - -public class Utils { - - public static Structure readFromByteArr(byte[] inputByteArr) throws IOException { - // Get the reader - this is the bit that people need to implement. - MmtfStructureReader mmtfStructureReader = new MmtfStructureReader(); - // Set up the inflator - DataApiToReader getToInflator = new DataApiToReader(); - // Now do the deserializer - MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); - // Do the inflation - getToInflator.read(new BeanToDataApi(messagePackDeserializer.deserialize(inputByteArr)), mmtfStructureReader); - // Get the structue - return mmtfStructureReader.getStructure(); - } - - - public static byte[] writeToByteArr(Structure structure) throws IOException { - // Set up this writer - WriterToDataApi inflatorToGet = new WriterToDataApi(); - // Get the writer - this is what people implement - MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); - // Now pass to the get API - mmtfStructureWriter.write(inflatorToGet); - return WriterUtils.getDataAsByteArr(inflatorToGet); - } - - /** - * Round trip a biojava structuree - * @param structure - * @return - * @throws IOException - */ - public static Structure roundTrip(Structure structure) throws IOException { - return readFromByteArr(writeToByteArr(structure)); - } - - - /** - * Get an MMTF bean from a pdb ID - * @param pdbId - * @return - * @throws StructureException - * @throws IOException - */ - public static MmtfBean getBean(String pdbId) throws IOException, StructureException { - Structure structure = StructureIO.getStructure(pdbId); - // Set up this writer - WriterToDataApi inflatorToGet = new WriterToDataApi(); - // Get the writer - this is what people implement - MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); - mmtfStructureWriter.write(inflatorToGet); - DataApiToBean dataApiToBean = new DataApiToBean(inflatorToGet); - return dataApiToBean.getMmtfBean(); - - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildFirstDataSet.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildFirstDataSet.java deleted file mode 100644 index 7c6ef59..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildFirstDataSet.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.SortedSet; - -import org.apache.hadoop.io.BytesWritable; - -import org.apache.hadoop.io.Text; -import org.apache.hadoop.mapred.SequenceFileOutputFormat; -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; - -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.rcsb.GetRepresentatives; -import org.rcsb.mmtf.mappers.PdbIdToMmtf; -import org.rcsb.mmtf.mappers.StringByteToTextByteWriter; - -public class BuildFirstDataSet { - - public static void main(String[] args ) - { - - // The arguments indicate where the PDB cache is AND what the version is. - if (args.length<2) { - System.err.println("NOT ENOUGH ARGUMENTS PROVIDED"); - throw new RuntimeException(); - } - // This is the default 2 line structure for Spark applications - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(BuildFirstDataSet.class.getSimpleName()); - // Set the config - JavaSparkContext sc = new JavaSparkContext(conf); - // A hack to make sure we're not downloading the whole pdb - Properties sysProps = System.getProperties(); - sysProps.setProperty("PDB_CACHE_DIR", args[0]); - sysProps.setProperty("PDB_DIR", args[0]); - AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - cache.setFetchBehavior(FetchBehavior.FETCH_FILES); - FileParsingParameters params = cache.getFileParsingParams(); - params.setCreateAtomBonds(true); - params.setAlignSeqRes(true); - params.setParseBioAssembly(true); - DownloadChemCompProvider dcc = new DownloadChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(dcc); - dcc.checkDoFirstInstall(); - dcc.setDownloadAll(true); - params.setUseInternalChainId(true); - cache.setFileParsingParams(params); - StructureIO.setAtomCache(cache); - // Get all the PDB IDs - SortedSet thisSet = GetRepresentatives.getAll(); - List pdbCodeList = new ArrayList(thisSet); - // Now read this list in - JavaPairRDD distData = - sc.parallelize(pdbCodeList) - .mapToPair(new PdbIdToMmtf()) - .mapToPair(new StringByteToTextByteWriter()); - // Now save this as a Hadoop sequence file - String uri = args[1]; - distData.saveAsHadoopFile(uri, Text.class, BytesWritable.class, SequenceFileOutputFormat.class, org.apache.hadoop.io.compress.BZip2Codec.class); - sc.close(); - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildSDFFile.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildSDFFile.java deleted file mode 100644 index 0279b74..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/BuildSDFFile.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Serializable; -import java.util.List; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.rcsb.mmtf.mappers.ByteArrayToBioJavaStructMapper; -import org.rcsb.mmtf.mappers.ByteWriteToByteArr; -import org.rcsb.mmtf.mappers.GroupToSDF; -import org.rcsb.mmtf.mappers.BiojavaStructureToBiojavaGroups; - -public class BuildSDFFile implements Serializable{ - - /** - * - */ - private static final long serialVersionUID = -3141464711627304724L; - - // private static final Logger logger = LoggerFactory.getLogger(SparkRead.class); - public static void main(String[] args ) throws IOException - { - String path = "/home/ubuntu/data/Total.hadoop.maindata.tested.bzip2"; - // This is the default 2 line structure for Spark applications - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(BuildSDFFile.class.getSimpleName()); - // Set the config - JavaSparkContext sc = new JavaSparkContext(conf); - // Time the proccess - long start = System.nanoTime(); - JavaPairRDD jprdd = sc - // Read the file - .sequenceFile(path, Text.class, BytesWritable.class, 12) - // Now get the structure - .mapToPair(new ByteWriteToByteArr()) - .mapToPair(new ByteArrayToBioJavaStructMapper()) - .flatMapToPair(new BiojavaStructureToBiojavaGroups()) -// .filter(new IsLigand()) - .mapToPair(new GroupToSDF()); - - File sdfFile = new File("/home/ubuntu/data/Total.sdf"); - BufferedWriter writer = new BufferedWriter(new FileWriter(sdfFile)); - - List output = jprdd.values().collect(); - for(String sdFile: output){ - writer.write(sdFile); - writer.write("$$$$\n"); - writer.flush(); - } - writer.close(); - sc.stop(); - sc.close(); - System.out.println("Time: " + (System.nanoTime() - start)/1E9 + " sec."); - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/FileWriters.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/FileWriters.java deleted file mode 100644 index 3b3bfe4..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/FileWriters.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; - -public class FileWriters { - - - /** - * Function to write out flat files - * to the file system - * @param collectAsMap - * @throws IOException - */ - public void writeOutFlatFiles(Map dataMap, String basePath) throws IOException { - for(Entry entry:dataMap.entrySet()){ - // Get the key value pairs - String pdbCode = entry.getKey(); - byte[] byteArr = entry.getValue(); - // Make the new dir - File theDir = new File(basePath+"/"+pdbCode.substring(1, 3)); - if(theDir.exists() == false){ - theDir.mkdirs(); - } - // Write the file - FileOutputStream fos = null; - // Try and except - try{ - fos = new FileOutputStream(basePath+"/"+pdbCode.substring(1, 3)+"/"+pdbCode); - fos.write(byteArr); - } - finally{ - fos.close(); - } - } - } - - public void writeOutFlatFilesToPath(String basePath, Map dataMap) throws IOException { - for(Entry entry:dataMap.entrySet()){ - // Get the key value pairs - String pdbCode = entry.getKey(); - byte[] byteArr = entry.getValue(); - // Make the new dir - File theDir = new File(basePath+"/"+pdbCode.substring(1, 3)); - if(theDir.exists() == false){ - theDir.mkdirs(); - } - // Write the file - FileOutputStream fos = null; - // Try and except - try{ - fos = new FileOutputStream(basePath+"/"+pdbCode.substring(1, 3)+"/"+pdbCode); - fos.write(byteArr); - } - finally{ - fos.close(); - } - } - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/OldFilter.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/OldFilter.java deleted file mode 100644 index 8b13789..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/OldFilter.java +++ /dev/null @@ -1 +0,0 @@ - diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/ProcessHadoopFile.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/ProcessHadoopFile.java deleted file mode 100644 index c5c1c6c..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/ProcessHadoopFile.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.hadoop.mapred.SequenceFileOutputFormat; -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.apache.spark.api.java.function.Function; -import org.rcsb.mmtf.mappers.ByteWriteToByteArr; -import org.rcsb.mmtf.mappers.StringByteToTextByteWriter; - -import scala.Tuple2; - -public class ProcessHadoopFile implements Serializable { - - - private static final long serialVersionUID = 1L; - - /** - * First argument is the path for the hadoop sequence file to read in. - * Second argument is the base path to write files out to. - * Third argument is the path of the file to write to demonstrate the work is done. - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException{ - - String inputUri = args[0]; - String basePath = args[1]; - String outPutFile = args[2]; - - - // Helper classes for writing files - WriteHashMap sparkHadoopHashMapWriter = new WriteHashMap(); - // The path of the hadoop file - // This is the default 2 line structure for Spark applications - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(ProcessHadoopFile.class.getSimpleName()); - conf.set("spark.driver.maxResultSize", "14g"); - // Set the config - JavaSparkContext sc = new JavaSparkContext(conf); - // Read in with spark - JavaPairRDD totalDataset = sc - .sequenceFile(inputUri, Text.class, BytesWritable.class, 24 * 3) - .mapToPair(new ByteWriteToByteArr()); - // GET THE TOTAL MAP - JavaPairRDD mainMap = totalDataset.filter(t -> t._1.endsWith("_total")) - .mapToPair(new RemoveSuffixAndGzip()); - - // NOW GET THE HEADER MAP - JavaPairRDD headerMap = totalDataset.filter(new Function, Boolean>() { - - /** - * - */ - private static final long serialVersionUID = 7574230201179927345L; - - @Override - public Boolean call(Tuple2 v1) throws Exception { - if(v1._1.endsWith("_header")==true){ - return true; - } - return false; - } - }).mapToPair(new RemoveSuffixAndGzip()); - - /// NOW GET THE CALPHA MAP - JavaPairRDD calphaMap = totalDataset.filter(new Function, Boolean>() { - - /** - * - */ - private static final long serialVersionUID = -8312184119385524L; - - @Override - public Boolean call(Tuple2 v1) throws Exception { - if(v1._1.endsWith("_calpha")==true){ - return true; - } - return false; - } - }).mapToPair(new RemoveSuffixAndGzip()); - - // Now write the hadoop sequence file as the whole pdb - // Now collect these as maps - - sparkHadoopHashMapWriter.writeHashMapToFile(headerMap.collectAsMap(), basePath+"headerMap.map"); - sparkHadoopHashMapWriter.writeHashMapToFile(calphaMap.collectAsMap(), basePath+"calphaMap.map"); - // Now do the main map - // Now write this out as a hash map - sparkHadoopHashMapWriter.writeHashMapToFile(mainMap.collectAsMap(), basePath+"mainMap.map"); - - // Now get the total dataset - without gzip and write to a hadoop sequence file - JavaPairRDD mainMapNoGzip = totalDataset.filter(new Function, Boolean>() { - - /** - * - */ - private static final long serialVersionUID = -7172364344277495432L; - - @Override - public Boolean call(Tuple2 v1) throws Exception { - if(v1._1.endsWith("_total")==true){ - return true; - } - return false; - } - }).mapToPair(new RemoveSuffix()); - - JavaPairRDD mainDataset = mainMapNoGzip.mapToPair(new StringByteToTextByteWriter()); - String outURI = basePath+"hadoopFullData"; - mainDataset.saveAsHadoopFile(outURI, Text.class, BytesWritable.class, SequenceFileOutputFormat.class, org.apache.hadoop.io.compress.BZip2Codec.class); - sc.close(); - File f = new File(outPutFile); - f.getParentFile().mkdirs(); - f.createNewFile(); - - } - - -} - - diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/PullFtpData.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/PullFtpData.java deleted file mode 100644 index e0f422b..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/PullFtpData.java +++ /dev/null @@ -1,258 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Current status - * all current entries and models - * all obsolete entries and models - - Weekly deltas - * added entries (and models = 0?) - * modified entries (and models=0?) - * reloaded entries (and models=0?) - * obsolete entries (and models=0?) - * - */ - -public class PullFtpData { - - - private String baseUrl; - - /** - * Constructor takes the url. - * @param inputUrl - */ - public PullFtpData(String inputUrl) { - this.setBaseUrl(inputUrl); - } - - /** - * - * @return A list of all the current PDB ids of PDB and NMR models (before the update) - */ - public String[] getAllCurrentEntries(){ - /** - all-pdb-list 2016-Jan-29 12:09:35 565.2K application/octet-stream - */ - List totList = new ArrayList(); - - // Get the NMR and the PDB - String[] pdbAll = readFile("all-pdb-list"); - totList.add(pdbAll); - - return joinLists(totList); - } - - /** - * - * @return A list of all the current PDB ids of computational models (before the update) - */ - public String[] getAllCurrentModels(){ - /** - all-model-list 2016-Jan-29 12:09:35 6.7K application/octet-stream - */ - List totList = new ArrayList(); - - // Get all the models - String[] allModels = readFile("all-model-list"); - totList.add(allModels); - - return joinLists(totList); - } - - /** - * - * @return A list of all obsolete computational models - */ - public String[] getAllObsoleteModels(){ - /** - obsolete-model-list 2016-Jan-29 12:09:35 0.1K application/octet-stream - */ - List totList = new ArrayList(); - - // Get the NMR and the PDB models that have ever been obsoleted - String[] modelObsolete = readFile("obsolete-model-list"); - totList.add(modelObsolete); - - return joinLists(totList); - } - - /** - * - * @return A list of all obsolete PDB and NMR models - */ - public String[] getAllObsoleteEntries(){ - /** - obsolete-pdb-list 2016-Jan-29 12:09:35 16.5K application/octet-stream - */ - List totList = new ArrayList(); - - // Get the NMR and the PDB models that have ever been obsoleted - String[] pdbObsolete = readFile("obsolete-pdb-list"); - totList.add(pdbObsolete); - - return joinLists(totList); - - - } - - - /** - * - * @return A list of all PDB and NMR models to be added this weekly update - */ - public String[] getAdded(){ - /** - added-entries 2016-Jan-29 12:09:35 1.0K application/octet-stream - */ - List totList = new ArrayList(); - // Get the NMR and the PDB - String[] pdbAdded = readFile("added-entries"); - totList.add(pdbAdded); - return joinLists(totList); - - } - - - /** - * - * @return A list of all PDB and NMR models to be modified this weekly update - */ - public String[] getModifiedUpdate(){ - /** - modified-entries 2016-Jan-29 12:09:35 0.9K application/octet-stream - */ - - List totList = new ArrayList(); - - // Get the NMR and the PDB - String[] pdbModified = readFile("modified-entries"); - totList.add(pdbModified); - - return joinLists(totList); - } - - /** - * - * @return A list of all PDB and NMR models to be reloaded this weekly update - */ - public String[] getReloadedUpdate(){ - /** - reload-entries 2016-Jan-29 12:09:35 0.0K application/octet-stream - */ - List totList = new ArrayList(); - - // Get the NMR and the PDB - String[] reloadEntries = readFile("reload-entries"); - totList.add(reloadEntries); - return joinLists(totList); - } - - - /** - * - * @return A list of all PDB and NMR models to be obsoloted this weekly update - */ - public String[] getObsoleteUpdate(){ - /** - obsolete-entries 2016-Jan-29 12:09:35 0.1K application/octet-stream - */ - - List totList = new ArrayList(); - - // Get the NMR and the PDB - String[] pdbObsolete = readFile("obsolete-entries"); - totList.add(pdbObsolete); - return joinLists(totList); - - } - - - /** - * Now a series of helper functions - */ - - - /** - * Takes a list of string arrays and joins them into one. - * @param totList - * @return - */ - private String[] joinLists(List totList) { - // Now join the lists together - // If it's empty then jusr return an empty list - if(totList.size()==0){ - return new String[0]; - } - // - List strings = new ArrayList(Arrays.asList(totList.get(0))); - if(totList.size()>1){ - for(int i=1;i outList = new ArrayList(); - // Check it's been set - String urlIn = baseUrl+fileIn; - try - { - // create a url object - URL url = new URL(urlIn); - - // create a urlconnection object - URLConnection urlConnection = url.openConnection(); - - // wrap the urlconnection in a bufferedreader - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); - - String line; - - // read from the urlconnection via the bufferedreader - while ((line = bufferedReader.readLine()) != null) - { - outList.add(line); - } - bufferedReader.close(); - } - catch(Exception e) - { - e.printStackTrace(); - } - - return outList.toArray(new String[0]); - } - - /** - * @return the baseUrl - */ - public String getBaseUrl() { - return baseUrl; - } - - /** - * @param baseUrl the baseUrl to set - */ - public void setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl; - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffix.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffix.java deleted file mode 100644 index 7eac0f6..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffix.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.rcsb.mmtf.update; - - -import org.apache.spark.api.java.function.PairFunction; - -import scala.Tuple2; - -public class RemoveSuffix implements PairFunction, String,byte[]> { - - /** - * - */ - private static final long serialVersionUID = -8038296891190383974L; - - @Override - public Tuple2 call(Tuple2 t) throws Exception { - // Now return the array with just the PDB code - // And gzip compress the byte arr - return new Tuple2(t._1.substring(0,4),t._2); - } - - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffixAndGzip.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffixAndGzip.java deleted file mode 100644 index 10a01ba..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/RemoveSuffixAndGzip.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.zip.GZIPOutputStream; - -import org.apache.spark.api.java.function.PairFunction; - -import scala.Tuple2; - -public class RemoveSuffixAndGzip implements PairFunction, String,byte[]> { - - /** - * - */ - private static final long serialVersionUID = -8038296891190383974L; - - @Override - public Tuple2 call(Tuple2 t) throws Exception { - // Now return the array with just the PDB code - // And gzip compress the byte arr - return new Tuple2(t._1.substring(0,4),gzipCompress(t._2)); - } - - private byte[] gzipCompress(byte[] dataToCompress) throws IOException { - // Function to gzip compress the data for the hashmaps - ByteArrayOutputStream byteStream = - new ByteArrayOutputStream(dataToCompress.length); - try - { - GZIPOutputStream zipStream = - new GZIPOutputStream(byteStream); - try - { - zipStream.write(dataToCompress); - } - finally - { - zipStream.close(); - } - } - finally - { - byteStream.close(); - } - - byte[] compressedData = byteStream.toByteArray(); - return compressedData; - - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/ServerUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/ServerUtils.java deleted file mode 100644 index 804ba11..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/ServerUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.Socket; -import java.net.URL; - -public class ServerUtils { - - - /** - * General function to a ping a generic server. - * @param host - * @param port - * @return - * @throws MalformedURLException - */ - public static boolean pingServer(String urlInput) throws MalformedURLException { - URL thisUrl = new URL(urlInput); - String host = thisUrl.getHost(); - int port = thisUrl.getPort(); - System.out.println("Pinging: "+host+" on port: "+port); - try (Socket socket = new Socket()) { - socket.connect(new InetSocketAddress(host, port), 100); - return true; - } catch (IOException e) { - return false; // Either timeout or unreachable or failed DNS lookup. - } - - } - - /** - * Build the extension to the url for accessing data. - * @param inputCode - * @return - */ - public String generateDataExtension(String inputCode) { - return inputCode.substring(1,3)+"/"+inputCode+"/"+inputCode+".cif.gz"; - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java deleted file mode 100644 index 1e58ff6..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/TestingUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.IOException; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.rcsb.mmtf.testutils.CheckOnBiojava; -import org.rcsb.mmtf.testutils.Utils; - -public class TestingUtils { - - /** - * Test a set of PDB ids found in the string list - * @param inputList the list of PDB ids to test - * @throws IOException - * @throws StructureException - */ - public static void testList(String[] inputList) throws IOException, StructureException{ - MmtfUtils.setUpBioJava(); - for (String pdbId : inputList){ - System.out.println("Testing: "+pdbId); - testSingleStructure(pdbId); - } - } - - /** - * Round trip and check a structure given by its PDB id - * @param pdbId the string PDB id for the structure - * @throws IOException - * @throws StructureException - */ - public static void testSingleStructure(String pdbId) throws IOException, StructureException { - MmtfUtils.setUpBioJava(); - CheckOnBiojava checkEquiv = new CheckOnBiojava(); - Structure mmcif = StructureIO.getStructure(pdbId); - checkEquiv.checkIfStructuresSame(mmcif,Utils.roundTrip(StructureIO.getStructure(pdbId))); - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateRun.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateRun.java deleted file mode 100644 index ddfe166..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateRun.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.rcsb.mmtf.mappers.MapperUtils; - -public class WeeklyUpdateRun { - - /** - * First argument is the path in the file system - * Second argument is the URL to the FTP site - * Third argument is the URL for the MMCifdata - * Fourth argument the output file - * Fifth+ pdb ids to ignore - * @param args - */ - public static void main(String args[]) { - - WeeklyUpdateUtils weeklyUpdate = new WeeklyUpdateUtils(); - MapperUtils mapperUtils = new MapperUtils(); - - String inputUri = args[0]; - String ftpSiteUrl = args[1]; - String mmcifDataUrl = args[2]; - String outputUri = args[3]; - String inputCcdUrl = args[4]; - - // Now get the list of PDB ids to ignore - List ignoreList = new ArrayList<>(); - for (int i=5; i totalDataset = weeklyUpdate.filterElements(sparkContext, inputUri); - List urlPdbList = new ArrayList<>(); - for (String pdbId : weeklyUpdate.getAddedList()) { - urlPdbList.add(mmcifDataUrl+"/"+pdbId+".cif.gz"); - } - JavaPairRDD distData = mapperUtils.generateRDD(sparkContext, urlPdbList, inputCcdUrl); - // Now join them - weeklyUpdate.joinDataSet(outputUri, totalDataset, distData); - sparkContext.close(); - } - -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateUtils.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateUtils.java deleted file mode 100644 index d4fd1e6..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/WeeklyUpdateUtils.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.hadoop.mapred.SequenceFileOutputFormat; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.rcsb.mmtf.mappers.ByteWriteToByteArr; -import org.rcsb.mmtf.mappers.StringByteToTextByteWriter; - -public class WeeklyUpdateUtils implements Serializable { - - - private static final long serialVersionUID = 4909752674491325131L; - private List removeList; - private List addedList; - - /** - * Function to filter out elements from a hadoop seqeunce file - * @param sparkContext The spark context for reading the file - * @param fileUri The full path for the hadoop seqeunce file - * @return The RDD of the data after filtering - */ - public JavaPairRDD filterElements(JavaSparkContext sparkContext, String fileUri) { - return sparkContext.sequenceFile(fileUri, Text.class, BytesWritable.class, 12) - .mapToPair(new ByteWriteToByteArr()) - .filter(t -> removeList.contains(t._1)==false) - .mapToPair(new StringByteToTextByteWriter()); - } - - /** - * Join to RDDs together into one larger one - * @param outUri - * @param datasetOne - * @param datasetTwo - */ - public void joinDataSet(String outUri, JavaPairRDD datasetOne, JavaPairRDD datasetTwo) { - // Now join them together - datasetOne.join(datasetTwo); - // Now save this as a Hadoop sequence file - datasetOne.saveAsHadoopFile(outUri, Text.class, BytesWritable.class, SequenceFileOutputFormat.class, org.apache.hadoop.io.compress.BZip2Codec.class); - } - - /** - * Get the update lists from the FTP server. Join them into remove lists and added lists. - * Updated items are in both lists. - * @param ignoreList - */ - public void getUpdateLists(String[] obsolete, String[] modified, String[] reloaded, String[] added, List ignoreList) { - // Now make the added and removed list - removeList = joinLists(reloaded,modified,obsolete); - List inputAddedList = joinLists(added,reloaded,modified); - for (String ignoreId : ignoreList) { - inputAddedList.remove(ignoreId.toLowerCase()); - inputAddedList.remove(ignoreId.toUpperCase()); - } - setAddedList(inputAddedList); - } - - - /** - * Retrieve the data from the FTP site and populate the added and remove lists. - */ - public void getDataFromFtpSite(String inputUrl, List ignoreList){ - // Get the class of functions here - PullFtpData pullFtpData = new PullFtpData(inputUrl); - // **** DO THIS - String[] obsolete = pullFtpData.getObsoleteUpdate(); - String[] modified = pullFtpData.getModifiedUpdate(); - String[] reloaded = pullFtpData.getReloadedUpdate(); - String[] added = pullFtpData.getAdded(); - // Now get these lists from the other lists - getUpdateLists(obsolete, modified, reloaded, added, ignoreList); - } - - /** - * Joins a series of three lists into a single lists. - * @param listOne - * @param listTwo - * @param listThree - * @return - */ - public List joinLists(String[] listOne, String[] listTwo, String[] listThree) { - List strings = new ArrayList(Arrays.asList(listOne)); - for(String item: listTwo){ - strings.add(item); - } - for(String item: listThree){ - strings.add(item); - } - return strings; - } - - /** - * The getters and setters - */ - - - public List getAddedList() { - return addedList; - } - - public void setAddedList(List addedList) { - this.addedList = addedList; - } - - - public List getRemoveList() { - return removeList; - } -} diff --git a/mmtf-update/src/main/java/org/rcsb/mmtf/update/WriteHashMap.java b/mmtf-update/src/main/java/org/rcsb/mmtf/update/WriteHashMap.java deleted file mode 100644 index 3bb2274..0000000 --- a/mmtf-update/src/main/java/org/rcsb/mmtf/update/WriteHashMap.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.rcsb.mmtf.update; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.util.Map; - -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.io.Text; -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaPairRDD; -import org.apache.spark.api.java.JavaSparkContext; -import org.apache.spark.api.java.function.Function; -import org.rcsb.mmtf.mappers.ByteWriteToByteArr; - -import scala.Tuple2; - - - -/* - * Class to write files that can be read in by the Java server - */ -public class WriteHashMap { - - public static void main(String[] args) throws Exception { - WriteHashMap sdhw = new WriteHashMap(); - // The path of the hadoop file - String uri = "/home/anthony/src/codec-devel/Total.hadoop.TRIAL.bzip2"; - // This is the default 2 line structure for Spark applications - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(WriteHashMap.class.getSimpleName()); - conf.set("spark.driver.maxResultSize", "14g"); - // Set the config - JavaSparkContext sc = new JavaSparkContext(conf); - // Read in with spark - JavaPairRDD totalDataset = sc - .sequenceFile(uri, Text.class, BytesWritable.class, 4 * 3) - .mapToPair(new ByteWriteToByteArr()); - - // - JavaPairRDD mainMap = totalDataset.filter(new Function, Boolean>() { - - /** - * - */ - private static final long serialVersionUID = -7172364344277495432L; - - @Override - public Boolean call(Tuple2 v1) throws Exception { - if(v1._1.endsWith("_total")==true){ - return true; - } - return false; - } - }); - JavaPairRDD headerMap = totalDataset.filter(new Function, Boolean>() { - - /** - * - */ - private static final long serialVersionUID = 7574230201179927345L; - - @Override - public Boolean call(Tuple2 v1) throws Exception { - if(v1._1.endsWith("_header")==true){ - return true; - } - return false; - } - }); - JavaPairRDD calphaMap = totalDataset.filter(new Function, Boolean>() { - - /** - * - */ - private static final long serialVersionUID = -8312184119385524L; - - @Override - public Boolean call(Tuple2 v1) throws Exception { - if(v1._1.endsWith("_calpha")==true){ - return true; - } - return false; - } - }); - // Now collect these as maps - sdhw.writeHashMapToFile(headerMap.collectAsMap(), "headerMap.map"); - sdhw.writeHashMapToFile(calphaMap.collectAsMap(), "calphaMap.map"); - sdhw.writeHashMapToFile(mainMap.collectAsMap(), "mainMap.map"); - // Close the spark context - sc.close(); - } - - /** - * - * @param mapToWrite - * @param fileName - * @throws IOException - */ - public void writeHashMapToFile(Map mapToWrite, String fileName) throws IOException{ - - File file = new File(fileName); - FileOutputStream f = new FileOutputStream(file); - ObjectOutputStream s = new ObjectOutputStream(f); - s.writeObject(mapToWrite); - s.close(); - - } - - -} diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java b/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java deleted file mode 100644 index b7fdf57..0000000 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/examples/TestHandleIO.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.rcsb.mmtf.examples; - -import org.junit.Test; -import org.rcsb.mmtf.testutils.IntegrationTestUtils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import java.io.IOException; -import java.nio.file.Path; - -import static org.junit.Assert.assertArrayEquals; - -/** - * Test that the file IO is being dealt with appropriately. - * @author Anthony Bradley - * - */ -public class TestHandleIO { - - private HandleIO handleIo; - - public TestHandleIO() { - // Generate this utility class - handleIo = new HandleIO(); - } - - - /** - * Basic test of being able to reach the server and get a byte array back - * @throws IOException - */ - @Test - public void testGetFileFromServer() throws IOException { - - // Get the base url - byte[] inputArr = handleIo.getFromUrl("4cup"); - assertNotEquals(inputArr, null); - assertNotEquals(inputArr.length, 1); - assertNotEquals(inputArr.length, 0); - // Get the base url - byte[] inputArrTwo = handleIo.getFromUrl("4cup"); - assertArrayEquals(inputArr, inputArrTwo); - // What if we give an nonsense PDB code - byte[] inputArrThree = handleIo.getFromUrl("12345"); - assertEquals(inputArrThree, null); - } - - /** - * Test whether we can read write the files where we want - */ - @Test - public void testReadWriteFiles() { - - IntegrationTestUtils integrationTestUtils = new IntegrationTestUtils(); - Path tmpDir = integrationTestUtils.returnTempDir(); - // If we set it as the tmp directory - System.setProperty("PDB_CACHE_DIR", tmpDir.toAbsolutePath().toString()); - // The input code - String inputCode = "4cup"; - // If we don't set where the cache is this should be empty - assertEquals(handleIo.getFromFile(inputCode), null); - byte[] urlData = handleIo.getByteArrFromUrlOrFile(inputCode); - byte[] fileData = handleIo.getFromFile(inputCode); - // First check neither are null - assertNotEquals(urlData, null); - assertNotEquals(fileData, null); - // Now check they are the same - assertArrayEquals(urlData, fileData); - } - - /** - * Test whether we can update files from the server and the updated file is created. - * Not implemented yet. As functionality isn't there. - */ - @Test - public void testUpdateFiles() { - - } - -} diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java deleted file mode 100644 index fabf296..0000000 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestBonds.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.rcsb.mmtf.integrationtest; - -import java.io.IOException; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.junit.Test; -import org.rcsb.mmtf.testutils.CheckBonds; -import org.rcsb.mmtf.testutils.IntegrationTestUtils; - -/** - * Tests to see that all bonds are being generated using Biojava. - * @author Anthony Bradley - * - */ -public class TestBonds { - - - /** - * Test whether all atoms (other than waters) have at least one bond. - * They should. - * @throws StructureException - * @throws IOException - */ - @Test - public void testBondConsistency() throws IOException, StructureException { - CheckBonds testUtils = new CheckBonds(); - // Set up biojava - MmtfUtils.setUpBioJava(); - for (String testCase : IntegrationTestUtils.TEST_CASES) { - Structure structure = StructureIO.getStructure(testCase); - testUtils.checkIfBondsExist(structure); - } - } - -} diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java deleted file mode 100644 index e5b7cf6..0000000 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestParseMMCif.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.rcsb.mmtf.integrationtest; - -import static org.junit.Assert.assertNotEquals; - -import java.io.IOException; - -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.junit.Test; -import org.rcsb.mmtf.dataholders.MmtfBean; -import org.rcsb.mmtf.testutils.IntegrationTestUtils; -import org.rcsb.mmtf.testutils.Utils; -import org.rcsb.mmtf.update.TestingUtils; -import org.unitils.reflectionassert.ReflectionAssert; - -/** - * Tests to see if parsing using Biojava using mmCIF and mmtf produces the same data structure. - * @author Anthony Bradley - * - */ -public class TestParseMMCif { - - @Test - public void testAll() throws IOException, StructureException{ - testDataComplete("4cup"); - TestingUtils.testList(IntegrationTestUtils.TEST_CASES); - } - - /** - * A specific mmtf test - to make sure none of the fields are empty when the thing is encoded - * @throws StructureException - * @throws IOException - */ - private void testDataComplete(String pdbId) throws IOException, StructureException { - MmtfUtils.setUpBioJava(); - // Get an mmtfBean - MmtfBean mmtfBean = Utils.getBean(pdbId); - // Make sure all fields are re-populated - ReflectionAssert.assertPropertiesNotNull("Some properties are null in mmtf generated from biojava object", mmtfBean); - // Now check the standard ones have been set - assertNotEquals(mmtfBean.getResolution(), (float) -1.0); - assertNotEquals(mmtfBean.getrFree(), (float) -1.0); - // Check that these integer values are set - assertNotEquals(mmtfBean.getNumAtoms(), -1); - assertNotEquals(mmtfBean.getNumBonds(), -1); - // And finally - check this is working - assertNotEquals(mmtfBean.getMmtfProducer(), "NA"); - } - -} diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java b/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java deleted file mode 100644 index 98c28fe..0000000 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/integrationtest/TestRoundTrip.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.rcsb.mmtf.integrationtest; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureIO; -import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter; -import org.biojava.nbio.structure.io.mmtf.MmtfUtils; -import org.junit.Test; -import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.decoder.BeanToDataApi; -import org.rcsb.mmtf.encoder.DataApiToBean; -import org.rcsb.mmtf.encoder.WriterToDataApi; -import org.rcsb.mmtf.update.TestingUtils; - - - -public class TestRoundTrip { - - - @Test - public void testApiRoundTrip() throws IOException, StructureException, IllegalArgumentException{ - // First set up Biojava - MmtfUtils.setUpBioJava(); - Structure structure = StructureIO.getStructure("1O2F"); - MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure); - WriterToDataApi mmtfApi = new WriterToDataApi(); - mmtfStructureWriter.write(mmtfApi); - DataApiToBean getToBean = new DataApiToBean(mmtfApi); - MmtfDecodedDataInterface beanToGet = new BeanToDataApi(getToBean.getMmtfBean()); - assertArrayEquals(beanToGet.getGroupTypeIndices(), mmtfApi.getGroupTypeIndices()); - assertArrayEquals(beanToGet.getGroupAtomNames(3), mmtfApi.getGroupAtomNames(3)); - assertArrayEquals(beanToGet.getGroupIds(), mmtfApi.getGroupIds()); - assertArrayEquals(beanToGet.getInterGroupBondOrders(), mmtfApi.getInterGroupBondOrders()); - assertArrayEquals(beanToGet.getInterGroupBondIndices(), mmtfApi.getInterGroupBondIndices()); - assertEquals(beanToGet.getNumBioassemblies(),mmtfApi.getNumBioassemblies()); - for(int i=0; i dataMap = getDummyData("abc"); - // First write this out - Path tmpDir = integrationTestUtils.returnTempDir(); - String tmpPathString = tmpDir.toAbsolutePath().toString(); - // Write out these flat files - fileWriters.writeOutFlatFiles(dataMap, tmpPathString); - // Check that they all exist - for ( Entry currentSet : dataMap.entrySet()) { - // Now read in the byte array - FileInputStream fileInput = new FileInputStream(tmpPathString+"/ab/"+currentSet.getKey()); - byte[] inputArr = IOUtils.toByteArray(fileInput); - assertNotNull(inputArr); - assertArrayEquals(currentSet.getValue(), inputArr); - } - } - - @Test - /** - * Can we write out then read back in a Hadoop sequence file of data. - */ - public void writeReadHadoopFile() { - - Map inputData = getDummyData("abc"); - // Get the spark context - JavaSparkContext sparkContext = getSparkContext(); - JavaPairRDD mainDataset = JavaPairRDD.fromJavaRDD(sparkContext.parallelize(convertToTuple(inputData))). - mapToPair(new StringByteToTextByteWriter()); - Path tmpDir = integrationTestUtils.returnTempDir(); - String tmpPathString = tmpDir.toAbsolutePath().toString(); - String outURI = tmpPathString+"/outData.bzip2"; - mainDataset.saveAsHadoopFile(outURI, Text.class, BytesWritable.class, SequenceFileOutputFormat.class, org.apache.hadoop.io.compress.BZip2Codec.class); - // Now read it in - List> outPutData = sparkContext.sequenceFile(outURI, Text.class, BytesWritable.class, 24 * 3) - .mapToPair(new ByteWriteToByteArr()).collect(); - // Now check we're the same - for (Tuple2 thisEntry : outPutData) { - // Check the byte arrs are the same - assertArrayEquals(inputData.get(thisEntry._1), thisEntry._2); - } - sparkContext.close(); - } - - - - @Test - /** - * Can we update the Hadoop file reasonably - */ - public void updateHadoopFile() { - // Should add three files to the output, read it back in and have the set number - JavaSparkContext sparkContext = getSparkContext(); - // - Map totalDataMap = new HashMap<>(); - - Map inputData = getDummyData("abc"); - Path tmpDir = integrationTestUtils.returnTempDir(); - String tmpPathString = tmpDir.toAbsolutePath().toString(); - String outURI = tmpPathString+"/outData.bzip2"; - JavaPairRDD mainDataset = JavaPairRDD.fromJavaRDD(sparkContext.parallelize(convertToTuple(inputData))). - mapToPair(new StringByteToTextByteWriter()); - mainDataset.saveAsHadoopFile(outURI, Text.class, BytesWritable.class, SequenceFileOutputFormat.class, org.apache.hadoop.io.compress.BZip2Codec.class); - // Now read this hadoop file and filter an element out - List dataToRemove = new ArrayList<>(); - dataToRemove.addAll(inputData.keySet()); - Collections.shuffle(dataToRemove); - dataToRemove = dataToRemove.subList(0, 4); - final List thisDataToRemove = new ArrayList<>(dataToRemove); - JavaPairRDD filteredDataset = sparkContext - .sequenceFile(outURI, Text.class, BytesWritable.class, 4 * 3) - .mapToPair(new ByteWriteToByteArr()) - .filter(t -> thisDataToRemove.contains(t._1)==false) - .mapToPair(new StringByteToTextByteWriter()); - - Map updateData = getDummyData("def"); - // Now generate the update data and convert - JavaPairRDD updateDataset = JavaPairRDD.fromJavaRDD(sparkContext.parallelize(convertToTuple(updateData))). - mapToPair(new StringByteToTextByteWriter()); - // Now join them together - filteredDataset.join(updateDataset); - String updateURI = tmpPathString+"/updateData.bzip2"; - filteredDataset.saveAsHadoopFile(updateURI, Text.class, BytesWritable.class, SequenceFileOutputFormat.class, org.apache.hadoop.io.compress.BZip2Codec.class); - - // Read it back in again - List> totalData = sparkContext - .sequenceFile(updateURI, Text.class, BytesWritable.class, 4 * 3) - .mapToPair(new ByteWriteToByteArr()).collect(); - // GENEREATE THE TEST DATA - for (Entry thisEntry : inputData.entrySet()) { - if (thisDataToRemove.contains(thisEntry.getKey()) ){ - System.out.println(thisEntry.getKey()); - continue; - } - totalDataMap.put(thisEntry.getKey(),thisEntry.getValue()); - } - for (Entry thisEntry : updateData.entrySet()) { - if (thisDataToRemove.contains(thisEntry.getKey()) ){ - continue; - } - totalDataMap.put(thisEntry.getKey(),thisEntry.getValue()); - } - // - for ( Tuple2 dataEntry : totalData) { - System.out.println(dataEntry._1); - assertArrayEquals(totalDataMap.get(dataEntry._1), dataEntry._2); - - } - - - - // Close spark down - sparkContext.close(); - - } - - - @Test - /** - * Test that the function to join lists actually works - */ - public void testJoinLists() { - WeeklyUpdateUtils weeklyUpdate = new WeeklyUpdateUtils(); - List testedList = weeklyUpdate.joinLists(new String[] {"A"}, new String[] {"B"}, new String[] {"C"}); - List testList = new ArrayList(); - testList.add("A"); - testList.add("B"); - testList.add("C"); - assertEquals(testList.size(), testedList.size()); - assertArrayEquals(testedList.toArray(new String[3]), testList.toArray(new String[3])); - } - - @Test - /** - * Test the generation of added and removed lists in the weekly update. - * Possibly add some integration tests to check - */ - public void testGenLists() { - WeeklyUpdateUtils weeklyUpdate = getLists(); - // Now get these and check they're the same as the should be - List addedList = weeklyUpdate.getAddedList(); - Collections.sort(addedList); - assertArrayEquals(addedList.toArray( new String[addedList.size()]), new String[] {"2abc", "3abc", "4abc"}); - List removedList = weeklyUpdate.getRemoveList(); - Collections.sort(removedList); - assertArrayEquals(removedList.toArray( new String[removedList.size()]), new String[] {"1abc","2abc", "3abc"}); - } - - @Test - /** - * Can we write and read the hashmaps - * @throws IOException - */ - public void writeReadHashMaps() throws IOException { - Map dataMap = getDummyData("abc"); - Path tmpDir = integrationTestUtils.returnTempDir(); - String tmpPathString = tmpDir.toAbsolutePath().toString(); - WriteHashMap sparkSDSCHashMapWriter = new WriteHashMap(); - // Write it out - sparkSDSCHashMapWriter.writeHashMapToFile(dataMap, tmpPathString+"mainMap.map"); - } - - /** - * Find the dummy data of the PDB - as would be produced from Encoding - * @return - */ - private Map getDummyData(String suffix) { - - Map dataMap = new HashMap<>(); - // First build the datamap -> random strings and random bytes - for (int i=0; i < 10; i++) { - byte[] b = new byte[ThreadLocalRandom.current().nextInt(1024, 4048)]; - new Random().nextBytes(b); - String dummyPdbCode = i+suffix; - dataMap.put(dummyPdbCode, b); - } - return dataMap; - - } - - /** - * Convert a dictionary to a tuple for spark. - * Input is a string/bytearr and output is text byteswriteable - * @param dummyData The input map of dummy string value pairs - * @return The output list of Tuples - */ - private List> convertToTuple(Map dummyData) { - // Set the out list - List> outList = new ArrayList<>(); - for ( Entry thisEntry : dummyData.entrySet() ) { - outList.add(new Tuple2(thisEntry.getKey(), thisEntry.getValue())); - } - return outList; - } - - private JavaSparkContext getSparkContext() { - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(APP_NAME); - // Set the config for the spark context - JavaSparkContext sparkContext = new JavaSparkContext(conf); - return sparkContext; - } - - /** - * Get the lists indicate which items should be removed or added - * for the weekly update. - * @return - */ - private WeeklyUpdateUtils getLists() { - WeeklyUpdateUtils weeklyUpdate = new WeeklyUpdateUtils(); - // Now get these lists - weeklyUpdate.getUpdateLists(OBSOLETE, MODIFIED, RELOADED, ADDED, new ArrayList()); - return weeklyUpdate; - } - -} diff --git a/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java b/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java deleted file mode 100644 index ba84f66..0000000 --- a/mmtf-update/src/test/java/org/rcsb/mmtf/update/TestSpark.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.rcsb.mmtf.update; - -import org.apache.spark.SparkConf; -import org.apache.spark.api.java.JavaSparkContext; -import static org.junit.Assert.*; -import org.junit.Test; - -/** - * Tests to see if Sparks can be launched succesfully. - * @author Anthony Bradley - * - */ -public class TestSpark { - - JavaSparkContext sc; - // App name - private static final String APP_NAME = "thisAppName"; - - public TestSpark() { - SparkConf conf = new SparkConf().setMaster("local[*]") - .setAppName(APP_NAME); - // Set the config for the spark context - sc = new JavaSparkContext(conf); - } - - @Test - /** - * Basic test that we can even get spark running - */ - public void testSparkContextSetup() { - assertEquals(sc.appName(), APP_NAME); - sc.close(); - sc.stop(); - } -} diff --git a/pom.xml b/pom.xml index 760d0c6..ae221ed 100644 --- a/pom.xml +++ b/pom.xml @@ -469,7 +469,6 @@ mmtf-api mmtf-decoder mmtf-encoder - mmtf-update 2015 @@ -477,8 +476,7 @@ https://github.com/rcsb/mmtf-java/issues - CruiseControl - http://ccpublic.rcsb.org/ + Travis + https://travis-ci.org/ - From 407e6d4914c247a24e018f8decb6f8eb53d1df16 Mon Sep 17 00:00:00 2001 From: abradle Date: Wed, 13 Apr 2016 04:16:12 -0700 Subject: [PATCH 096/108] Refactoring of the names of the interfaces and decoder/encoder classes. --- ...erInterface.java => DataTransferInterface.java} | 2 +- ...ataInterface.java => DecodedDataInterface.java} | 2 +- .../{DataApiToReader.java => DecoderToReader.java} | 14 +++++++------- .../java/org/rcsb/mmtf/decoder/DecoderUtils.java | 14 +++++++------- .../{BeanToDataApi.java => DefaultDecoder.java} | 6 +++--- .../{DataApiToBean.java => DefaultEncoder.java} | 6 +++--- .../java/org/rcsb/mmtf/encoder/EncoderUtils.java | 8 ++++---- .../{WriterToDataApi.java => WriterToEncoder.java} | 6 +++--- .../java/org/rcsb/mmtf/encoder/WriterUtils.java | 6 +++--- 9 files changed, 32 insertions(+), 32 deletions(-) rename mmtf-api/src/main/java/org/rcsb/mmtf/api/{MmtfDecoderInterface.java => DataTransferInterface.java} (99%) rename mmtf-api/src/main/java/org/rcsb/mmtf/api/{MmtfDecodedDataInterface.java => DecodedDataInterface.java} (99%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/{DataApiToReader.java => DecoderToReader.java} (95%) rename mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/{BeanToDataApi.java => DefaultDecoder.java} (98%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/{DataApiToBean.java => DefaultEncoder.java} (97%) rename mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/{WriterToDataApi.java => WriterToEncoder.java} (98%) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java similarity index 99% rename from mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java rename to mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java index 7dd5718..fcb06f1 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecoderInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java @@ -5,7 +5,7 @@ * * @author Anthony Bradley */ -public interface MmtfDecoderInterface { +public interface DataTransferInterface { /** * Used before any additions to do any required pre-processing. diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DecodedDataInterface.java similarity index 99% rename from mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java rename to mmtf-api/src/main/java/org/rcsb/mmtf/api/DecodedDataInterface.java index d335852..dcd5d5d 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/MmtfDecodedDataInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DecodedDataInterface.java @@ -22,7 +22,7 @@ * @author Anthony Bradley * @author Jose Duarte */ -public interface MmtfDecodedDataInterface { +public interface DecodedDataInterface { /** * Returns an array containing the X coordinates of the atoms in Angstroms. diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderToReader.java similarity index 95% rename from mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java rename to mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderToReader.java index ba481a1..c92a8f9 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DataApiToReader.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderToReader.java @@ -3,8 +3,8 @@ import java.util.HashSet; import java.util.Set; -import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.api.MmtfDecoderInterface; +import org.rcsb.mmtf.api.DecodedDataInterface; +import org.rcsb.mmtf.api.DataTransferInterface; /** * Decode an MMTF structure using a structure inflator. @@ -12,13 +12,13 @@ * @author Anthony Bradley * */ -public class DataApiToReader { +public class DecoderToReader { /** The struct inflator. */ - private MmtfDecoderInterface structInflator; + private DataTransferInterface structInflator; /** The api to the data */ - private MmtfDecodedDataInterface dataApi; + private DecodedDataInterface dataApi; // Intialises the counters. private int modelCounter = 0; @@ -28,14 +28,14 @@ public class DataApiToReader { private int currentAtomIndex = 0; private Set chainIdSet; - public DataApiToReader(){ + public DecoderToReader(){ } /** * Passes data from the data interface to the inflator interface. */ - public void read(MmtfDecodedDataInterface inputApi, MmtfDecoderInterface inputInflator){ + public void read(DecodedDataInterface inputApi, DataTransferInterface inputInflator){ // Set the api and the inflator dataApi = inputApi; structInflator = inputInflator; diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java index c6c0c3e..f9d5bcb 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DecoderUtils.java @@ -1,14 +1,14 @@ package org.rcsb.mmtf.decoder; -import org.rcsb.mmtf.api.MmtfDecodedDataInterface; -import org.rcsb.mmtf.api.MmtfDecoderInterface; +import org.rcsb.mmtf.api.DecodedDataInterface; +import org.rcsb.mmtf.api.DataTransferInterface; public class DecoderUtils { /** * Parses the bioassembly data and inputs it to the structure inflator */ - public static void generateBioAssembly(MmtfDecodedDataInterface dataApi, MmtfDecoderInterface structInflator) { + public static void generateBioAssembly(DecodedDataInterface dataApi, DataTransferInterface structInflator) { for (int i=0; i generateBioassemblies(MmtfDecodedDataInterface mmtfDecodedDataInterface) { + public static List generateBioassemblies(DecodedDataInterface mmtfDecodedDataInterface) { int numBioassemblies = mmtfDecodedDataInterface.getNumBioassemblies(); List outList = new ArrayList<>(); for (int i=0; i generateBioassemblies(MmtfDecodedDataInterfa * @param mmtfDecodedDataInterface the input interface * @return the list of entities */ - public static Entity[] generateEntityList(MmtfDecodedDataInterface mmtfDecodedDataInterface) { + public static Entity[] generateEntityList(DecodedDataInterface mmtfDecodedDataInterface) { int numEntities = mmtfDecodedDataInterface.getNumEntities(); Entity[] outList = new Entity[numEntities]; for (int i=0; i Date: Wed, 13 Apr 2016 04:42:06 -0700 Subject: [PATCH 097/108] Removed pointless SeDeserializer interfaces --- .../org/rcsb/mmtf/api/DeserializerInterface.java | 12 ------------ .../java/org/rcsb/mmtf/api/SerializerInterface.java | 12 ------------ .../mmtf/deserializers/MessagePackDeserializer.java | 4 +--- .../rcsb/mmtf/serializers/MessagePackSerializer.java | 7 +++---- 4 files changed, 4 insertions(+), 31 deletions(-) delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java delete mode 100644 mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java deleted file mode 100644 index 533d148..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DeserializerInterface.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.rcsb.mmtf.api; - -public interface DeserializerInterface { - - /** - * Convert a byte array to an object to then be procesed. - * e.g. a messagepack byte array can be coverted to an MMTFBean. - * @param byteArray the input byte data - * @return the object with defined getters and setters - */ - Object deserialize(byte[] byteArray); -} diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java deleted file mode 100644 index 75087c6..0000000 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/SerializerInterface.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.rcsb.mmtf.api; - -public interface SerializerInterface { - - - /** - * Convert an object to a byte array using reflection. - * @param object an object with getters and setters - * @return a byte array of the serialised object - */ - byte[] serialize(Object object); -} diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java index ac834d5..bdb2337 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java @@ -3,7 +3,6 @@ import java.io.IOException; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.api.DeserializerInterface; import org.rcsb.mmtf.dataholders.MmtfBean; import com.fasterxml.jackson.databind.ObjectMapper; @@ -13,9 +12,8 @@ * @author Anthony Bradley * */ -public class MessagePackDeserializer implements DeserializerInterface { +public class MessagePackDeserializer { - @Override public MmtfBean deserialize(byte[] byteArray) { MmtfBean mmtfBean = null; try { diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java index 5c948ed..0a77095 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java @@ -1,7 +1,7 @@ package org.rcsb.mmtf.serializers; import org.msgpack.jackson.dataformat.MessagePackFactory; -import org.rcsb.mmtf.api.SerializerInterface; +import org.rcsb.mmtf.dataholders.MmtfBean; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -12,10 +12,9 @@ * @author Anthony Bradley * */ -public class MessagePackSerializer implements SerializerInterface { +public class MessagePackSerializer { - @Override - public byte[] serialize(Object object) { + public byte[] serialize(MmtfBean object) { ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); byte[] byteArray; try { From b7b44b8217607adc15f7a2d690975d7697ff5211 Mon Sep 17 00:00:00 2001 From: abradle Date: Wed, 13 Apr 2016 04:49:43 -0700 Subject: [PATCH 098/108] Some more refactoring and docs for the encoder --- .../org/rcsb/mmtf/encoder/DefaultEncoder.java | 70 +++++++++---------- .../org/rcsb/mmtf/encoder/WriterUtils.java | 20 ++++-- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java index 1a86f52..c9eb054 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java @@ -10,7 +10,7 @@ import org.rcsb.mmtf.gitversion.GetRepoState; /** - * Class to take a encode the DecodedDataInterface into the MmtfBean. + * Default encoding class from a DecodedDataInterface. * @author Anthony Bradley * */ @@ -18,17 +18,17 @@ public class DefaultEncoder { private MmtfBean mmtfBean; - public DefaultEncoder(DecodedDataInterface mmtfDecodedDataInterface) throws IOException { + public DefaultEncoder(DecodedDataInterface decodedDataInterface) throws IOException { mmtfBean = new MmtfBean(); // Set the group types mmtfBean.setGroupTypeList( ArrayConverters.convertIntegersToFourByte( - mmtfDecodedDataInterface.getGroupTypeIndices())); + decodedDataInterface.getGroupTypeIndices())); // Encode the coordinate and B-factor arrays. List xCoords = ArrayConverters.splitIntegers( ArrayEncoders.deltaEncode( ArrayConverters.convertFloatsToInts( - mmtfDecodedDataInterface.getxCoords(), + decodedDataInterface.getxCoords(), MmtfBean.COORD_DIVIDER))); mmtfBean.setxCoordBig(ArrayConverters.convertIntegersToFourByte(xCoords.get(0))); mmtfBean.setxCoordSmall(ArrayConverters.convertIntegersToTwoBytes(xCoords.get(1))); @@ -36,7 +36,7 @@ public DefaultEncoder(DecodedDataInterface mmtfDecodedDataInterface) throws IOEx List yCoords = ArrayConverters.splitIntegers( ArrayEncoders.deltaEncode( ArrayConverters.convertFloatsToInts( - mmtfDecodedDataInterface.getyCoords(), + decodedDataInterface.getyCoords(), MmtfBean.COORD_DIVIDER))); mmtfBean.setyCoordBig(ArrayConverters.convertIntegersToFourByte(yCoords.get(0))); mmtfBean.setyCoordSmall(ArrayConverters.convertIntegersToTwoBytes(yCoords.get(1))); @@ -44,7 +44,7 @@ public DefaultEncoder(DecodedDataInterface mmtfDecodedDataInterface) throws IOEx List zCoords = ArrayConverters.splitIntegers( ArrayEncoders.deltaEncode( ArrayConverters.convertFloatsToInts( - mmtfDecodedDataInterface.getzCoords(), + decodedDataInterface.getzCoords(), MmtfBean.COORD_DIVIDER))); mmtfBean.setzCoordBig(ArrayConverters.convertIntegersToFourByte(zCoords.get(0))); mmtfBean.setzCoordSmall(ArrayConverters.convertIntegersToTwoBytes(zCoords.get(1))); @@ -53,7 +53,7 @@ public DefaultEncoder(DecodedDataInterface mmtfDecodedDataInterface) throws IOEx List bFactor = ArrayConverters.splitIntegers( ArrayEncoders.deltaEncode( ArrayConverters.convertFloatsToInts( - mmtfDecodedDataInterface.getbFactors(), + decodedDataInterface.getbFactors(), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER))); mmtfBean.setbFactorBig(ArrayConverters.convertIntegersToFourByte(bFactor.get(0))); mmtfBean.setbFactorSmall(ArrayConverters.convertIntegersToTwoBytes(bFactor.get(1))); @@ -63,68 +63,68 @@ public DefaultEncoder(DecodedDataInterface mmtfDecodedDataInterface) throws IOEx mmtfBean.setOccupancyList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( ArrayConverters.convertFloatsToInts( - mmtfDecodedDataInterface.getOccupancies(), + decodedDataInterface.getOccupancies(), MmtfBean.OCCUPANCY_BFACTOR_DIVIDER)))); // Run length and delta mmtfBean.setAtomIdList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( - ArrayEncoders.deltaEncode(mmtfDecodedDataInterface.getAtomIds())))); + ArrayEncoders.deltaEncode(decodedDataInterface.getAtomIds())))); // Run length encoded mmtfBean.setAltLocList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( ArrayConverters.convertCharToIntegers( - mmtfDecodedDataInterface.getAltLocIds())))); + decodedDataInterface.getAltLocIds())))); mmtfBean.setInsCodeList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( ArrayConverters.convertCharToIntegers( - mmtfDecodedDataInterface.getInsCodes())))); + decodedDataInterface.getInsCodes())))); // Set the groupNumber mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( ArrayEncoders.deltaEncode( - mmtfDecodedDataInterface.getGroupIds())))); + decodedDataInterface.getGroupIds())))); // Set the group map (all the unique groups in the structure). - mmtfBean.setGroupList(EncoderUtils.generateGroupMap(mmtfDecodedDataInterface)); + mmtfBean.setGroupList(EncoderUtils.generateGroupMap(decodedDataInterface)); // Set the indices for the groups mapping to the sequence mmtfBean.setSequenceIndexList(ArrayConverters.convertIntegersToFourByte( - mmtfDecodedDataInterface.getGroupSequenceIndices())); + decodedDataInterface.getGroupSequenceIndices())); // Set the number of chains per model - mmtfBean.setChainsPerModel(mmtfDecodedDataInterface.getChainsPerModel()); - mmtfBean.setGroupsPerChain(mmtfDecodedDataInterface.getGroupsPerChain()); + mmtfBean.setChainsPerModel(decodedDataInterface.getChainsPerModel()); + mmtfBean.setGroupsPerChain(decodedDataInterface.getGroupsPerChain()); // Set the internal and public facing chain ids - mmtfBean.setChainNameList(ArrayConverters.encodeChainList(mmtfDecodedDataInterface.getChainNames())); - mmtfBean.setChainIdList(ArrayConverters.encodeChainList(mmtfDecodedDataInterface.getChainIds())); + mmtfBean.setChainNameList(ArrayConverters.encodeChainList(decodedDataInterface.getChainNames())); + mmtfBean.setChainIdList(ArrayConverters.encodeChainList(decodedDataInterface.getChainIds())); // Set the space group information - mmtfBean.setSpaceGroup(mmtfDecodedDataInterface.getSpaceGroup()); - mmtfBean.setUnitCell(mmtfDecodedDataInterface.getUnitCell()); + mmtfBean.setSpaceGroup(decodedDataInterface.getSpaceGroup()); + mmtfBean.setUnitCell(decodedDataInterface.getUnitCell()); // Set the bioassembly and entity information mmtfBean.setBioAssemblyList( - EncoderUtils.generateBioassemblies(mmtfDecodedDataInterface)); + EncoderUtils.generateBioassemblies(decodedDataInterface)); mmtfBean.setEntityList( - EncoderUtils.generateEntityList(mmtfDecodedDataInterface) + EncoderUtils.generateEntityList(decodedDataInterface) ); // Set the bond orders and indcices mmtfBean.setBondOrderList(ArrayConverters.convertIntegersToBytes( - mmtfDecodedDataInterface.getInterGroupBondOrders())); + decodedDataInterface.getInterGroupBondOrders())); mmtfBean.setBondAtomList(ArrayConverters.convertIntegersToFourByte( - mmtfDecodedDataInterface.getInterGroupBondIndices())); + decodedDataInterface.getInterGroupBondIndices())); // Set the version and producer information mmtfBean.setMmtfProducer("RCSB-PDB Generator---version: "+GetRepoState.getCurrentVersion()); - mmtfBean.setStructureId(mmtfDecodedDataInterface.getStructureId()); + mmtfBean.setStructureId(decodedDataInterface.getStructureId()); // Set some header data - mmtfBean.setNumAtoms(mmtfDecodedDataInterface.getNumAtoms()); - mmtfBean.setNumBonds(mmtfDecodedDataInterface.getNumBonds()); - mmtfBean.setrFree(mmtfDecodedDataInterface.getRfree()); - mmtfBean.setrWork(mmtfDecodedDataInterface.getRwork()); - mmtfBean.setResolution(mmtfDecodedDataInterface.getResolution()); - mmtfBean.setTitle(mmtfDecodedDataInterface.getTitle()); - mmtfBean.setExperimentalMethods(mmtfDecodedDataInterface.getExperimentalMethods()); - mmtfBean.setDepositionDate(mmtfDecodedDataInterface.getDepositionDate()); - mmtfBean.setReleaseDate(mmtfDecodedDataInterface.getReleaseDate()); - mmtfBean.setSecStructList(ArrayConverters.convertIntegersToFourByte(mmtfDecodedDataInterface.getSecStructList())); + mmtfBean.setNumAtoms(decodedDataInterface.getNumAtoms()); + mmtfBean.setNumBonds(decodedDataInterface.getNumBonds()); + mmtfBean.setrFree(decodedDataInterface.getRfree()); + mmtfBean.setrWork(decodedDataInterface.getRwork()); + mmtfBean.setResolution(decodedDataInterface.getResolution()); + mmtfBean.setTitle(decodedDataInterface.getTitle()); + mmtfBean.setExperimentalMethods(decodedDataInterface.getExperimentalMethods()); + mmtfBean.setDepositionDate(decodedDataInterface.getDepositionDate()); + mmtfBean.setReleaseDate(decodedDataInterface.getReleaseDate()); + mmtfBean.setSecStructList(ArrayConverters.convertIntegersToFourByte(decodedDataInterface.getSecStructList())); } public MmtfBean getMmtfBean() { diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java index b864d9c..c3f30f4 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java @@ -8,23 +8,29 @@ public class WriterUtils { /** - * Function to write data to a file - * @param inflatorToGet - * @param path + * Function to write data to a file. + * @param writerToEncoder the writer to encoder instance + * @param path the full path to write to * @throws IOException */ - public static void writeDataToFile(WriterToEncoder inflatorToGet, String path) throws IOException { - byte[] byteArray = getDataAsByteArr(inflatorToGet); + public static void writeDataToFile(WriterToEncoder writerToEncoder, String path) throws IOException { + byte[] byteArray = getDataAsByteArr(writerToEncoder); FileOutputStream fos = new FileOutputStream(path); fos.write(byteArray); fos.close(); } - public static byte[] getDataAsByteArr(WriterToEncoder inflatorToGet) throws IOException { + /** + * Function to take data from a writer and return as a byte array (MessagePacked serialized). + * @param writerToEncoder the writer to encoder instance + * @return a byte array of the data + * @throws IOException + */ + public static byte[] getDataAsByteArr(WriterToEncoder writerToEncoder) throws IOException { MessagePackSerializer messagePackSerializer = new MessagePackSerializer(); // Get to bean - DefaultEncoder getToBean = new DefaultEncoder(inflatorToGet); + DefaultEncoder getToBean = new DefaultEncoder(writerToEncoder); return messagePackSerializer.serialize(getToBean.getMmtfBean()); } From 38e0f39632af63123ddd62b71cecd60b01c42a63 Mon Sep 17 00:00:00 2001 From: abradle Date: Wed, 13 Apr 2016 06:16:21 -0700 Subject: [PATCH 099/108] Added new tests for hte decoder --- mmtf-decoder/pom.xml | 9 +- .../org/rcsb/mmtf/decoder/DummyApiImpl.java | 288 ++++++++++++++++++ .../rcsb/mmtf/decoder/DummyTransferImpl.java | 71 +++++ .../rcsb/mmtf/decoder/TestDefaultDecoder.java | 43 +++ mmtf-encoder/pom.xml | 1 - pom.xml | 40 ++- 6 files changed, 435 insertions(+), 17 deletions(-) create mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java create mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyTransferImpl.java create mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java diff --git a/mmtf-decoder/pom.xml b/mmtf-decoder/pom.xml index d7a23fa..4aab870 100644 --- a/mmtf-decoder/pom.xml +++ b/mmtf-decoder/pom.xml @@ -37,7 +37,14 @@ jackson-dataformat-msgpack 0.7.1 - + + uk.co.jemos.podam + podam + + + org.unitils + unitils-core + junit diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java new file mode 100644 index 0000000..4a3f059 --- /dev/null +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java @@ -0,0 +1,288 @@ +package org.rcsb.mmtf.decoder; + +import org.rcsb.mmtf.api.DecodedDataInterface; + +public class DummyApiImpl implements DecodedDataInterface { + + + public final int numAtoms = 10; + public final int numGroups = 2; + public final int atomsPerGroup = 5; + public final int bondsPerGroup = 5; + public final int interGroupBonds = 2; + public final int numChains = 1; + public final int numModels = 1; + + + @Override + public float[] getxCoords() { + return new float[numAtoms]; + } + + @Override + public float[] getyCoords() { + return new float[numAtoms]; + } + + @Override + public float[] getzCoords() { + return new float[numAtoms]; + } + + @Override + public float[] getbFactors() { + return new float[numAtoms]; + } + + @Override + public float[] getOccupancies() { + return new float[numAtoms]; + } + + @Override + public int[] getAtomIds() { + return new int[numAtoms]; + } + + @Override + public char[] getAltLocIds() { + return new char[numAtoms]; + } + + @Override + public char[] getInsCodes() { + return new char[numGroups]; + } + + @Override + public int[] getGroupIds() { + return new int[numGroups]; + } + + @Override + public String getGroupName(int groupInd) { + return "NAME"; + } + + @Override + public int getNumAtomsInGroup(int groupInd) { + return atomsPerGroup; + } + + @Override + public String[] getGroupAtomNames(int groupInd) { + return new String[atomsPerGroup]; + } + + @Override + public String[] getGroupElementNames(int groupInd) { + return new String[atomsPerGroup]; + } + + @Override + public int[] getGroupBondOrders(int groupInd) { + return new int[bondsPerGroup]; + } + + @Override + public int[] getGroupBondIndices(int groupInd) { + return new int[bondsPerGroup*2]; + } + + @Override + public int[] getGroupAtomCharges(int groupInd) { + return new int[atomsPerGroup]; + } + + @Override + public char getGroupSingleLetterCode(int groupInd) { + return 0; + } + + @Override + public String getGroupChemCompType(int groupInd) { + return "CHEM"; + } + + @Override + public int[] getGroupTypeIndices() { + return new int[numGroups]; + } + + @Override + public int[] getGroupSequenceIndices() { + return new int[numGroups]; + } + + @Override + public String[] getChainIds() { + return new String[numChains]; + } + + @Override + public String[] getChainNames() { + return new String[numChains]; + } + + @Override + public int[] getChainsPerModel() { + + return new int[numModels]; + } + + @Override + public int[] getGroupsPerChain() { + return new int[numChains]; + } + + @Override + public String getSpaceGroup() { + return "SPACE"; + } + + @Override + public float[] getUnitCell() { + return new float[6]; + } + + @Override + public int getNumBioassemblies() { + return 1; + } + + @Override + public int getNumTransInBioassembly(int bioassemblyIndex) { + return 1; + } + + @Override + public int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex) { + return new int[1]; + } + + @Override + public double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex) { + return new double[1]; + } + + @Override + public int[] getInterGroupBondIndices() { + return new int[interGroupBonds*2]; + + } + + @Override + public int[] getInterGroupBondOrders() { + return new int[interGroupBonds]; + } + + @Override + public String getMmtfVersion() { + return "VERS"; + } + + @Override + public String getMmtfProducer() { + return "PROD"; + } + + @Override + public int getNumEntities() { + return 1; + } + + @Override + public String getEntityDescription(int entityInd) { + return "DESC"; + } + + @Override + public String getEntityType(int entityInd) { + return "TYPE"; + } + + @Override + public int[] getEntityChainIndexList(int entityInd) { + return new int[] {0}; + } + + @Override + public String getEntitySequence(int entityInd) { + return "SEQ"; + } + + @Override + public String getStructureId() { + return "1EG1"; + } + + @Override + public int getNumModels() { + return 1; + } + + @Override + public int getNumBonds() { + return bondsPerGroup*numGroups+interGroupBonds; + } + + @Override + public int getNumChains() { + return numChains; + } + + @Override + public int getNumGroups() { + return numGroups; + } + + @Override + public int getNumAtoms() { + return numAtoms; + } + + @Override + public float getRfree() { + return 1.0f; + + } + + @Override + public float getRwork() { + return 1.0f; + + } + + @Override + public float getResolution() { + return 1.0f; + } + + @Override + public String getTitle() { + return "NA"; + } + + @Override + public String[] getExperimentalMethods() { + return new String[] {"NA"}; + + } + + @Override + public String getDepositionDate() { + return "NA"; + + } + + @Override + public String getReleaseDate() { + return "NA"; + } + + @Override + public int[] getSecStructList() { + return new int[numGroups]; + } + +} diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyTransferImpl.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyTransferImpl.java new file mode 100644 index 0000000..380dd0a --- /dev/null +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyTransferImpl.java @@ -0,0 +1,71 @@ +package org.rcsb.mmtf.decoder; + +import org.rcsb.mmtf.api.DataTransferInterface; + +public class DummyTransferImpl implements DataTransferInterface { + + @Override + public void initStructure(int totalNumBonds, int totalNumAtoms, int totalNumGroups, int totalNumChains, + int totalNumModels, String structureId) { + + } + + @Override + public void finalizeStructure() { + + } + + @Override + public void setModelInfo(int modelId, int chainCount) { + + } + + @Override + public void setChainInfo(String chainId, String chainName, int groupCount) { + + } + + @Override + public void setEntityInfo(int[] chainIndices, String sequence, String description, String title) { + + } + + @Override + public void setGroupInfo(String groupName, int groupNumber, char insertionCode, String groupType, int atomCount, + int boundCount, char singleLetterCode, int sequenceIndex, int secondaryStructureType) { + + } + + @Override + public void setAtomInfo(String atomName, int serialNumber, char alternativeLocationId, float x, float y, float z, + float occupancy, float temperatureFactor, String element, int charge) { + + } + + @Override + public void setBioAssemblyTrans(int bioAssemblyIndex, int[] inputChainIndices, double[] inputTransform) { + + } + + @Override + public void setXtalInfo(String spaceGroup, float[] unitCell) { + + } + + @Override + public void setGroupBond(int atomIndexOne, int atomIndexTwo, int bondOrder) { + + } + + @Override + public void setInterGroupBond(int atomIndexOne, int atomIndexTwo, int bondOrder) { + + } + + @Override + public void setHeaderInfo(float rFree, float rWork, float resolution, String title, String depositionDate, + String releaseDate, String[] experimnetalMethods) { + + } + +} diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java new file mode 100644 index 0000000..e01a55c --- /dev/null +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java @@ -0,0 +1,43 @@ +package org.rcsb.mmtf.decoder; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.rcsb.mmtf.api.DataTransferInterface; +import org.rcsb.mmtf.dataholders.MmtfBean; +import org.unitils.reflectionassert.ReflectionAssert; + +import uk.co.jemos.podam.api.PodamFactory; +import uk.co.jemos.podam.api.PodamFactoryImpl; + +public class TestDefaultDecoder { + + private MmtfBean mmtfBean; + /** + * Build the bean before any tests + */ + @Before + public void beforeTests() { + PodamFactory factory = new PodamFactoryImpl(); + mmtfBean = factory.manufacturePojo(MmtfBean.class); + } + + + @Test + public void testDecodeAllFields() throws IOException { + DefaultDecoder defaultDecoder = new DefaultDecoder(mmtfBean); + ReflectionAssert.assertPropertiesNotNull("Some properties null after decoding", defaultDecoder); + } + + + @Test + public void testReader() throws IOException { + DummyApiImpl dummyApiImpl = new DummyApiImpl(); + DecoderToReader decoderToReader = new DecoderToReader(); + DataTransferInterface inputInflator = new DummyTransferImpl(); + decoderToReader.read(dummyApiImpl, inputInflator); + } + + +} diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index d7ead59..85b66ad 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -67,7 +67,6 @@ commons-beanutils 1.8.3 - diff --git a/pom.xml b/pom.xml index ae221ed..cf56112 100644 --- a/pom.xml +++ b/pom.xml @@ -215,21 +215,21 @@ - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - xml - 256m - - true - + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + xml + 256m + + true + - org.eluder.coveralls - coveralls-maven-plugin - 4.1.0 - + org.eluder.coveralls + coveralls-maven-plugin + 4.1.0 + org.sonatype.plugins @@ -324,11 +324,21 @@ 2.6 - - + + uk.co.jemos.podam + podam + 2.3.5.RELEASE + test + + + org.unitils + unitils-core + 3.4.2 + test + junit junit From ddb09556d8f6cc3cc3d2cd90b1f1c25756b75232 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 07:48:53 -0700 Subject: [PATCH 100/108] Updates to the encoder tests and fixed a couple of bugs found by the tests --- .../rcsb/mmtf/decoder/TestDefaultDecoder.java | 23 +- mmtf-encoder/pom.xml | 5 +- .../rcsb/mmtf/encoder/ArrayConverters.java | 5 +- .../rcsb/mmtf/encoder/WriterToEncoder.java | 4 +- .../org/rcsb/mmtf/encoder/DummyApiImpl.java | 288 ++++++++++++++++++ .../mmtf/encoder/TestArrayConverters.java | 5 +- .../rcsb/mmtf/encoder/TestDefaultEncoder.java | 43 +++ 7 files changed, 351 insertions(+), 22 deletions(-) create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/DummyApiImpl.java create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java index e01a55c..b5e48c4 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java @@ -13,31 +13,22 @@ public class TestDefaultDecoder { - private MmtfBean mmtfBean; - /** - * Build the bean before any tests - */ - @Before - public void beforeTests() { - PodamFactory factory = new PodamFactoryImpl(); - mmtfBean = factory.manufacturePojo(MmtfBean.class); - } - - @Test public void testDecodeAllFields() throws IOException { + PodamFactory factory = new PodamFactoryImpl(); + MmtfBean mmtfBean = factory.manufacturePojo(MmtfBean.class); DefaultDecoder defaultDecoder = new DefaultDecoder(mmtfBean); ReflectionAssert.assertPropertiesNotNull("Some properties null after decoding", defaultDecoder); } - - + + @Test - public void testReader() throws IOException { + public void testReader() { DummyApiImpl dummyApiImpl = new DummyApiImpl(); DecoderToReader decoderToReader = new DecoderToReader(); DataTransferInterface inputInflator = new DummyTransferImpl(); decoderToReader.read(dummyApiImpl, inputInflator); } - - + + } diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index 85b66ad..b521987 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -42,7 +42,10 @@ junit junit - + + org.unitils + unitils-core + diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java index 5a7998a..95dc22f 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/ArrayConverters.java @@ -157,7 +157,10 @@ public static byte[] encodeChainList(String[] chainNames) { private static void setChainId(String chainId, byte[] byteArr, int chainIndex) { // A char array to store the chars char[] outChar = new char[4]; - // The lenght of this chain id + // The lengthof this chain id + if(chainId==null){ + return; + } int chainIdLen = chainId.length(); chainId.getChars(0, chainIdLen, outChar, 0); // Set the bytrarray - chain ids can be up to 4 chars - pad with empty bytes diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java index 895476e..1d6c88d 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java @@ -84,10 +84,10 @@ public class WriterToEncoder implements DecodedDataInterface, DataTransferInterf private String[] chainList; /** The mmtf version */ - private String mmtfVersion; + private String mmtfVersion = "UNKNOWN"; /** The mmtf prodcuer */ - private String mmtfProducer; + private String mmtfProducer = "UNKNOWN"; /** The list of entities in this structure. */ private Entity[] entityList; diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/DummyApiImpl.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/DummyApiImpl.java new file mode 100644 index 0000000..f3d36a3 --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/DummyApiImpl.java @@ -0,0 +1,288 @@ +package org.rcsb.mmtf.encoder; + +import org.rcsb.mmtf.api.DecodedDataInterface; + +public class DummyApiImpl implements DecodedDataInterface { + + + public final int numAtoms = 10; + public final int numGroups = 2; + public final int atomsPerGroup = 5; + public final int bondsPerGroup = 5; + public final int interGroupBonds = 2; + public final int numChains = 1; + public final int numModels = 1; + + + @Override + public float[] getxCoords() { + return new float[numAtoms]; + } + + @Override + public float[] getyCoords() { + return new float[numAtoms]; + } + + @Override + public float[] getzCoords() { + return new float[numAtoms]; + } + + @Override + public float[] getbFactors() { + return new float[numAtoms]; + } + + @Override + public float[] getOccupancies() { + return new float[numAtoms]; + } + + @Override + public int[] getAtomIds() { + return new int[numAtoms]; + } + + @Override + public char[] getAltLocIds() { + return new char[numAtoms]; + } + + @Override + public char[] getInsCodes() { + return new char[numGroups]; + } + + @Override + public int[] getGroupIds() { + return new int[numGroups]; + } + + @Override + public String getGroupName(int groupInd) { + return "NAME"; + } + + @Override + public int getNumAtomsInGroup(int groupInd) { + return atomsPerGroup; + } + + @Override + public String[] getGroupAtomNames(int groupInd) { + return new String[atomsPerGroup]; + } + + @Override + public String[] getGroupElementNames(int groupInd) { + return new String[atomsPerGroup]; + } + + @Override + public int[] getGroupBondOrders(int groupInd) { + return new int[bondsPerGroup]; + } + + @Override + public int[] getGroupBondIndices(int groupInd) { + return new int[bondsPerGroup*2]; + } + + @Override + public int[] getGroupAtomCharges(int groupInd) { + return new int[atomsPerGroup]; + } + + @Override + public char getGroupSingleLetterCode(int groupInd) { + return 0; + } + + @Override + public String getGroupChemCompType(int groupInd) { + return "CHEM"; + } + + @Override + public int[] getGroupTypeIndices() { + return new int[numGroups]; + } + + @Override + public int[] getGroupSequenceIndices() { + return new int[numGroups]; + } + + @Override + public String[] getChainIds() { + return new String[numChains]; + } + + @Override + public String[] getChainNames() { + return new String[numChains]; + } + + @Override + public int[] getChainsPerModel() { + + return new int[numModels]; + } + + @Override + public int[] getGroupsPerChain() { + return new int[numChains]; + } + + @Override + public String getSpaceGroup() { + return "SPACE"; + } + + @Override + public float[] getUnitCell() { + return new float[6]; + } + + @Override + public int getNumBioassemblies() { + return 1; + } + + @Override + public int getNumTransInBioassembly(int bioassemblyIndex) { + return 1; + } + + @Override + public int[] getChainIndexListForTransform(int bioassemblyIndex, int transformationIndex) { + return new int[1]; + } + + @Override + public double[] getMatrixForTransform(int bioassemblyIndex, int transformationIndex) { + return new double[1]; + } + + @Override + public int[] getInterGroupBondIndices() { + return new int[interGroupBonds*2]; + + } + + @Override + public int[] getInterGroupBondOrders() { + return new int[interGroupBonds]; + } + + @Override + public String getMmtfVersion() { + return "VERS"; + } + + @Override + public String getMmtfProducer() { + return "PROD"; + } + + @Override + public int getNumEntities() { + return 1; + } + + @Override + public String getEntityDescription(int entityInd) { + return "DESC"; + } + + @Override + public String getEntityType(int entityInd) { + return "TYPE"; + } + + @Override + public int[] getEntityChainIndexList(int entityInd) { + return new int[] {0}; + } + + @Override + public String getEntitySequence(int entityInd) { + return "SEQ"; + } + + @Override + public String getStructureId() { + return "1EG1"; + } + + @Override + public int getNumModels() { + return 1; + } + + @Override + public int getNumBonds() { + return bondsPerGroup*numGroups+interGroupBonds; + } + + @Override + public int getNumChains() { + return numChains; + } + + @Override + public int getNumGroups() { + return numGroups; + } + + @Override + public int getNumAtoms() { + return numAtoms; + } + + @Override + public float getRfree() { + return 1.0f; + + } + + @Override + public float getRwork() { + return 1.0f; + + } + + @Override + public float getResolution() { + return 1.0f; + } + + @Override + public String getTitle() { + return "NA"; + } + + @Override + public String[] getExperimentalMethods() { + return new String[] {"NA"}; + + } + + @Override + public String getDepositionDate() { + return "NA"; + + } + + @Override + public String getReleaseDate() { + return "NA"; + } + + @Override + public int[] getSecStructList() { + return new int[numGroups]; + } + +} diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java index 915364c..6d1015d 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestArrayConverters.java @@ -16,10 +16,11 @@ public class TestArrayConverters { */ @Test public final void testSetChain() { - String[] stringList = {"A","ABC","abc"}; + String[] stringList = {"A","ABC","abc","abcd"}; byte[] testByteArray = {'A','\0','\0','\0', 'A','B','C','\0', - 'a','b','c','\0'}; + 'a','b','c','\0', + 'a','b','c','d'}; byte[] byteArray = ArrayConverters.encodeChainList(stringList); assertArrayEquals(testByteArray, byteArray); } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java new file mode 100644 index 0000000..24b9171 --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java @@ -0,0 +1,43 @@ +package org.rcsb.mmtf.encoder; + +import java.io.IOException; + +import org.junit.Test; +import org.unitils.reflectionassert.ReflectionAssert; + +public class TestDefaultEncoder { + + + + /** + * Test whether calling all the set methods gives a none null get + * @throws IOException + */ + @Test + public void testEncodeAllFields() throws IOException { + DummyApiImpl dummyApiImpl = new DummyApiImpl(); + DefaultEncoder defaultEncoder = new DefaultEncoder(dummyApiImpl); + ReflectionAssert.assertPropertiesNotNull("Some properties null after encoding", defaultEncoder.getMmtfBean()); + + } + + + @Test + public void testWriter() { + WriterToEncoder writerToEncoder = new WriterToEncoder(); + writerToEncoder.initStructure(1, 1, 1, 1, 1, "ABC"); + writerToEncoder.setModelInfo(0, 1); + writerToEncoder.setChainInfo("A","A",10); + writerToEncoder.setGroupInfo("HET", 1, 'a', "D", 1, 1, 'A', 0, -1); + writerToEncoder.setAtomInfo("A", 1, 'a', 1.0f, 1.0f, 1.0f,1.0f, 1.0f, "A", 1); + writerToEncoder.setEntityInfo(new int[1], "A", "A", "A"); + writerToEncoder.setGroupBond(0, 0, 1); + writerToEncoder.setHeaderInfo(1.0f, 1.0f, 1.0f, "A", "A", "A", new String[1]); + writerToEncoder.setInterGroupBond(0, 0, 1); + writerToEncoder.setBioAssemblyTrans(0, new int[1], new double[6]); + writerToEncoder.setXtalInfo("A", new float[6]); + writerToEncoder.finalizeStructure(); + ReflectionAssert.assertPropertiesNotNull("Some properties null after writing", writerToEncoder); + + } +} From eb712d5fd53ba89d2d76b3a3dbe8b8fbc83ab75a Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 10:10:09 -0700 Subject: [PATCH 101/108] Updates and refactoring to the encoder to fix data inconsistencies in writer --- .../org/rcsb/mmtf/api/DataTransferInterface.java | 4 ++-- mmtf-common/pom.xml | 12 ++++++++++++ .../java/org/rcsb/mmtf/dataholders/Entity.java | 1 - mmtf-decoder/pom.xml | 1 - .../java/org/rcsb/mmtf/decoder/DefaultDecoder.java | 12 +++++++----- .../org/rcsb/mmtf/decoder/TestDefaultDecoder.java | 1 - mmtf-encoder/pom.xml | 1 - .../java/org/rcsb/mmtf/encoder/DefaultEncoder.java | 14 ++++++++------ .../org/rcsb/mmtf/encoder/WriterToEncoder.java | 2 +- .../mmtf/serializers/MessagePackSerializer.java | 3 +++ .../org/rcsb/mmtf/encoder/TestDefaultEncoder.java | 1 - pom.xml | 6 ++++++ 12 files changed, 39 insertions(+), 19 deletions(-) diff --git a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java index fcb06f1..a384578 100644 --- a/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java +++ b/mmtf-api/src/main/java/org/rcsb/mmtf/api/DataTransferInterface.java @@ -47,9 +47,9 @@ void initStructure(int totalNumBonds, int totalNumAtoms, int totalNumGroups, int * @param chainIndices the indices of the chain this refers to. * @param sequence the full sequence of the entity * @param description the text description of the entity - * @param title + * @param type as a string (POLYMER/NON-POLYMER and WATER) */ - void setEntityInfo(int[] chainIndices, String sequence, String description, String title); + void setEntityInfo(int[] chainIndices, String sequence, String description, String type); /** * Sets the information for a given group / residue with atomic data. diff --git a/mmtf-common/pom.xml b/mmtf-common/pom.xml index d7552e2..3591fb8 100644 --- a/mmtf-common/pom.xml +++ b/mmtf-common/pom.xml @@ -26,6 +26,18 @@ junit junit + + uk.co.jemos.podam + podam + + + org.unitils + unitils-core + + + commons-beanutils + commons-beanutils + diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/Entity.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/Entity.java index 74600e8..d15f726 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/Entity.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/Entity.java @@ -24,7 +24,6 @@ public class Entity implements Serializable { private String sequence; - public String getDescription() { return description; } diff --git a/mmtf-decoder/pom.xml b/mmtf-decoder/pom.xml index 4aab870..253be8c 100644 --- a/mmtf-decoder/pom.xml +++ b/mmtf-decoder/pom.xml @@ -20,7 +20,6 @@ commons-beanutils commons-beanutils - 1.8.3 org.rcsb diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DefaultDecoder.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DefaultDecoder.java index 1f1eaad..fbbba10 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DefaultDecoder.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/DefaultDecoder.java @@ -70,8 +70,10 @@ public DefaultDecoder(MmtfBean inputData) throws IOException { // Get the group map (all the unique groups in the structure). groupMap = inputData.getGroupList(); // Get the seqRes groups - seqResGroupList = ArrayConverters.convertFourByteToIntegers( - inputData.getSequenceIndexList()); + seqResGroupList = ArrayDecoders.deltaDecode( + ArrayDecoders.runlengthDecode( + ArrayConverters.convertFourByteToIntegers( + inputData.getSequenceIndexList()))); // Get the number of chains per model chainsPerModel = inputData.getChainsPerModel(); groupsPerChain = inputData.getGroupsPerChain(); @@ -97,7 +99,7 @@ public DefaultDecoder(MmtfBean inputData) throws IOException { // Now get the relase information depositionDate = inputData.getDepositionDate(); releaseDate = inputData.getReleaseDate(); - secStructInfo = ArrayConverters.convertFourByteToIntegers(inputData.getSecStructList()); + secStructInfo = ArrayConverters.convertByteToIntegers(inputData.getSecStructList()); } /** The X coordinates */ @@ -195,10 +197,10 @@ public DefaultDecoder(MmtfBean inputData) throws IOException { /** The deposition date of the structure */ private String depositionDate; - + /** The release date of the structure */ private String releaseDate; - + private int[] secStructInfo; diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java index b5e48c4..41cf8ca 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java @@ -2,7 +2,6 @@ import java.io.IOException; -import org.junit.Before; import org.junit.Test; import org.rcsb.mmtf.api.DataTransferInterface; import org.rcsb.mmtf.dataholders.MmtfBean; diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index b521987..4895afe 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -68,7 +68,6 @@ commons-beanutils commons-beanutils - 1.8.3 diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java index c9eb054..7202d52 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/DefaultEncoder.java @@ -73,12 +73,12 @@ public DefaultEncoder(DecodedDataInterface decodedDataInterface) throws IOExcept // Run length encoded mmtfBean.setAltLocList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( - ArrayConverters.convertCharToIntegers( - decodedDataInterface.getAltLocIds())))); + ArrayConverters.convertCharToIntegers( + decodedDataInterface.getAltLocIds())))); mmtfBean.setInsCodeList(ArrayConverters.convertIntegersToFourByte( ArrayEncoders.runlengthEncode( - ArrayConverters.convertCharToIntegers( - decodedDataInterface.getInsCodes())))); + ArrayConverters.convertCharToIntegers( + decodedDataInterface.getInsCodes())))); // Set the groupNumber mmtfBean.setGroupIdList(ArrayConverters.convertIntegersToFourByte( @@ -90,7 +90,9 @@ public DefaultEncoder(DecodedDataInterface decodedDataInterface) throws IOExcept mmtfBean.setGroupList(EncoderUtils.generateGroupMap(decodedDataInterface)); // Set the indices for the groups mapping to the sequence mmtfBean.setSequenceIndexList(ArrayConverters.convertIntegersToFourByte( - decodedDataInterface.getGroupSequenceIndices())); + ArrayEncoders.runlengthEncode( + ArrayEncoders.deltaEncode( + decodedDataInterface.getGroupSequenceIndices())))); // Set the number of chains per model mmtfBean.setChainsPerModel(decodedDataInterface.getChainsPerModel()); mmtfBean.setGroupsPerChain(decodedDataInterface.getGroupsPerChain()); @@ -124,7 +126,7 @@ public DefaultEncoder(DecodedDataInterface decodedDataInterface) throws IOExcept mmtfBean.setExperimentalMethods(decodedDataInterface.getExperimentalMethods()); mmtfBean.setDepositionDate(decodedDataInterface.getDepositionDate()); mmtfBean.setReleaseDate(decodedDataInterface.getReleaseDate()); - mmtfBean.setSecStructList(ArrayConverters.convertIntegersToFourByte(decodedDataInterface.getSecStructList())); + mmtfBean.setSecStructList(ArrayConverters.convertIntegersToBytes(decodedDataInterface.getSecStructList())); } public MmtfBean getMmtfBean() { diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java index 1d6c88d..831cff8 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/encoder/WriterToEncoder.java @@ -491,7 +491,7 @@ public void setGroupInfo(String groupName, int groupNumber, char insertionCode, pdbGroup.setChemCompType(polymerType); pdbGroup.setElementList(new String[atomCount]); pdbGroup.setGroupName(groupName); - pdbGroup.setSingleLetterCode(insertionCode); + pdbGroup.setSingleLetterCode(singleAtomCode); groupAtomIndex=0; groupBondIndex=0; // Store the group level data diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java index 0a77095..5270443 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java @@ -3,6 +3,7 @@ import org.msgpack.jackson.dataformat.MessagePackFactory; import org.rcsb.mmtf.dataholders.MmtfBean; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -15,7 +16,9 @@ public class MessagePackSerializer { public byte[] serialize(MmtfBean object) { + ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); + objectMapper.setSerializationInclusion(Include.NON_NULL); byte[] byteArray; try { byteArray = objectMapper.writeValueAsBytes(object); diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java index 24b9171..d26b65f 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java @@ -18,7 +18,6 @@ public void testEncodeAllFields() throws IOException { DummyApiImpl dummyApiImpl = new DummyApiImpl(); DefaultEncoder defaultEncoder = new DefaultEncoder(dummyApiImpl); ReflectionAssert.assertPropertiesNotNull("Some properties null after encoding", defaultEncoder.getMmtfBean()); - } diff --git a/pom.xml b/pom.xml index cf56112..ea6a12e 100644 --- a/pom.xml +++ b/pom.xml @@ -345,6 +345,12 @@ 4.12 test + + commons-beanutils + commons-beanutils + 1.9.2 + test + org.slf4j slf4j-api From fec2df8ce9c3d4caf5018257bce1b181da16b6ec Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 10:39:35 -0700 Subject: [PATCH 102/108] Change to the DummAPIimpl to increase code coverage --- .../java/org/rcsb/mmtf/decoder/DummyApiImpl.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java index 4a3f059..19d474f 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/DummyApiImpl.java @@ -5,11 +5,11 @@ public class DummyApiImpl implements DecodedDataInterface { - public final int numAtoms = 10; - public final int numGroups = 2; - public final int atomsPerGroup = 5; - public final int bondsPerGroup = 5; - public final int interGroupBonds = 2; + public final int numAtoms = 1; + public final int numGroups = 1; + public final int atomsPerGroup = 1; + public final int bondsPerGroup = 1; + public final int interGroupBonds = 1; public final int numChains = 1; public final int numModels = 1; @@ -127,12 +127,12 @@ public String[] getChainNames() { @Override public int[] getChainsPerModel() { - return new int[numModels]; + return new int[] {numChains}; } @Override public int[] getGroupsPerChain() { - return new int[numChains]; + return new int[] {numGroups}; } @Override From 0cd57c0487480c501c55d244150a6f7bded405bc Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 10:43:47 -0700 Subject: [PATCH 103/108] Add test dataholder class --- .../mmtf/dataholders/BioAssemblyTrans.java | 20 ++++++-------- .../mmtf/dataholders/TestDataHolders.java | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java index 5854ca0..d1f54a0 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java @@ -11,18 +11,14 @@ * * @author Anthony Bradley */ -public class BioAssemblyTrans implements Serializable { - - - /** Serial id for this version of the format. */ - private static final long serialVersionUID = -8109941242652091495L; +public class BioAssemblyTrans { /** The indices of the chains this bioassembly references. */ private int[] chainIndexList; /** The 4x4 matrix transformation specifying a rotation and a translation. */ - private double[] transformation; + private double[] matrix; /** @@ -32,8 +28,8 @@ public class BioAssemblyTrans implements Serializable { * * @return the transformation */ - public final double[] getMatrix() { - return transformation; + public double[] getMatrix() { + return matrix; } /** @@ -43,8 +39,8 @@ public final double[] getMatrix() { * * @param inputTransformation the new transformation */ - public final void setMatrix(final double[] transformation) { - this.transformation = transformation; + public void setMatrix(double[] transformation) { + this.matrix = transformation; } /** @@ -52,7 +48,7 @@ public final void setMatrix(final double[] transformation) { * * @return a list of integers indicating the indices (zero indexed) of the chains this bioassembly refers to. */ - public final int[] getChainIndexList() { + public int[] getChainIndexList() { return chainIndexList; } @@ -61,7 +57,7 @@ public final int[] getChainIndexList() { * * @param a list of integers indicating the indices (zero indexed) of the chains this bioassembly refers to. */ - public final void setChainIndexList(final int[] inputChainId) { + public void setChainIndexList(int[] inputChainId) { this.chainIndexList = inputChainId; } diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java new file mode 100644 index 0000000..6e00acc --- /dev/null +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -0,0 +1,27 @@ +package org.rcsb.mmtf.dataholders; + + +import org.junit.Test; +import org.unitils.reflectionassert.ReflectionAssert; + +import uk.co.jemos.podam.api.PodamFactory; +import uk.co.jemos.podam.api.PodamFactoryImpl; + +public class TestDataHolders { + + @Test + public void testBeans(){ + PodamFactory factory = new PodamFactoryImpl(); + // Tests if setters are set appropriately + ReflectionAssert.assertPropertiesNotNull("Some properties null.", + factory.manufacturePojo(MmtfBean.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", + factory.manufacturePojo(BioAssemblyData.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", + factory.manufacturePojo(BioAssemblyTrans.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", + factory.manufacturePojo(Entity.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", + factory.manufacturePojo(PDBGroup.class)); + } +} From 712cea35b0b0dfd0a25f22f89d07677d436349be Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 11:39:13 -0700 Subject: [PATCH 104/108] Added tests for the message pack serializer / deserializers --- .../mmtf/dataholders/BioAssemblyTrans.java | 2 -- .../mmtf/dataholders/TestDataHolders.java | 35 +++++++++++++++++++ .../mmtf/deserializers/TestMessagePack.java | 17 +++++++++ mmtf-encoder/pom.xml | 12 ++++--- .../rcsb/mmtf/serializer/TestMessagePack.java | 23 ++++++++++++ 5 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java create mode 100644 mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java diff --git a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java index d1f54a0..3017a4a 100644 --- a/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java +++ b/mmtf-common/src/main/java/org/rcsb/mmtf/dataholders/BioAssemblyTrans.java @@ -1,8 +1,6 @@ package org.rcsb.mmtf.dataholders; -import java.io.Serializable; - /** * The transformation needed for generation of biological assemblies * from the contents of a PDB/mmCIF file. It contains both the actual diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index 6e00acc..c164a8c 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -1,6 +1,8 @@ package org.rcsb.mmtf.dataholders; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.unitils.reflectionassert.ReflectionAssert; @@ -24,4 +26,37 @@ public void testBeans(){ ReflectionAssert.assertPropertiesNotNull("Some properties null.", factory.manufacturePojo(PDBGroup.class)); } + + + @Test + public void testDsspType() { + + assertEquals(DsspType.dsspTypeFromString("pi Helix"), DsspType.dsspTypeFromInt(0)); + assertEquals(DsspType.PI_HELIX, DsspType.dsspTypeFromInt(0)); + + assertEquals(DsspType.dsspTypeFromString("Bend"), DsspType.dsspTypeFromInt(1)); + assertEquals(DsspType.BEND, DsspType.dsspTypeFromInt(1)); + + assertEquals(DsspType.dsspTypeFromString("alpha Helix"), DsspType.dsspTypeFromInt(2)); + assertEquals(DsspType.ALPHA_HELIX, DsspType.dsspTypeFromInt(2)); + + assertEquals(DsspType.dsspTypeFromString("Extended"), DsspType.dsspTypeFromInt(3)); + assertEquals(DsspType.EXTENDED, DsspType.dsspTypeFromInt(3)); + + assertEquals(DsspType.dsspTypeFromString("3-10 Helix"), DsspType.dsspTypeFromInt(4)); + assertEquals(DsspType.HELIX_3_10, DsspType.dsspTypeFromInt(4)); + + assertEquals(DsspType.dsspTypeFromString("Bridge"), DsspType.dsspTypeFromInt(5)); + assertEquals(DsspType.BRIDGE, DsspType.dsspTypeFromInt(5)); + + assertEquals(DsspType.dsspTypeFromString("Turn"), DsspType.dsspTypeFromInt(6)); + assertEquals(DsspType.TURN, DsspType.dsspTypeFromInt(6)); + + assertEquals(DsspType.dsspTypeFromString("Coil"), DsspType.dsspTypeFromInt(7)); + assertEquals(DsspType.COIL, DsspType.dsspTypeFromInt(7)); + + assertEquals(DsspType.dsspTypeFromString("NA"), DsspType.dsspTypeFromInt(-1)); + assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromInt(-1)); + + } } diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java new file mode 100644 index 0000000..c167af8 --- /dev/null +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java @@ -0,0 +1,17 @@ +package org.rcsb.mmtf.deserializers; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.rcsb.mmtf.dataholders.MmtfBean; + +public class TestMessagePack { + + + @Test + public void testBasic() { + MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); + MmtfBean mmtfBean = messagePackDeserializer.deserialize(new byte[] {(byte) (char) 129, (byte) (char)162, (byte) (char)100, (byte) (char)111, (byte) (char)1}); + assertNotNull(mmtfBean); + } +} diff --git a/mmtf-encoder/pom.xml b/mmtf-encoder/pom.xml index 4895afe..a540297 100644 --- a/mmtf-encoder/pom.xml +++ b/mmtf-encoder/pom.xml @@ -42,10 +42,14 @@ junit junit - - org.unitils - unitils-core - + + uk.co.jemos.podam + podam + + + org.unitils + unitils-core + diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java new file mode 100644 index 0000000..94b5062 --- /dev/null +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java @@ -0,0 +1,23 @@ +package org.rcsb.mmtf.serializer; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.rcsb.mmtf.dataholders.MmtfBean; +import org.rcsb.mmtf.serializers.MessagePackSerializer; + +import uk.co.jemos.podam.api.PodamFactory; +import uk.co.jemos.podam.api.PodamFactoryImpl; + +public class TestMessagePack { + + + @Test + public void testBasic() { + MessagePackSerializer messagePackSerializer = new MessagePackSerializer(); + PodamFactory factory = new PodamFactoryImpl(); + MmtfBean mmtfBean = factory.manufacturePojo(MmtfBean.class); + byte[] outArr = messagePackSerializer.serialize(mmtfBean); + assertNotNull(outArr); + } +} From c1e6b750e7f544fa9dab26c3a74e29d46ac1497b Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 11:47:50 -0700 Subject: [PATCH 105/108] Remove unuseful try catch --- .../mmtf/deserializers/MessagePackDeserializer.java | 12 ++++-------- .../org/rcsb/mmtf/deserializers/TestMessagePack.java | 7 ++++++- .../rcsb/mmtf/serializers/MessagePackSerializer.java | 10 ++-------- .../org/rcsb/mmtf/serializer/TestMessagePack.java | 4 +++- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java index bdb2337..271224b 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/deserializers/MessagePackDeserializer.java @@ -5,6 +5,8 @@ import org.msgpack.jackson.dataformat.MessagePackFactory; import org.rcsb.mmtf.dataholders.MmtfBean; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; /** @@ -14,15 +16,9 @@ */ public class MessagePackDeserializer { - public MmtfBean deserialize(byte[] byteArray) { + public MmtfBean deserialize(byte[] byteArray) throws JsonParseException, JsonMappingException, IOException { MmtfBean mmtfBean = null; - try { - mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(byteArray, MmtfBean.class); - } catch (IOException e) { - System.err.println("Error converting Byte array to message pack. IOError"); - e.printStackTrace(); - throw new RuntimeException(); - } + mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(byteArray, MmtfBean.class); return mmtfBean; } } diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java index c167af8..3252ff1 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/deserializers/TestMessagePack.java @@ -2,14 +2,19 @@ import static org.junit.Assert.assertNotNull; +import java.io.IOException; + import org.junit.Test; import org.rcsb.mmtf.dataholders.MmtfBean; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + public class TestMessagePack { @Test - public void testBasic() { + public void testBasic() throws JsonParseException, JsonMappingException, IOException { MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer(); MmtfBean mmtfBean = messagePackDeserializer.deserialize(new byte[] {(byte) (char) 129, (byte) (char)162, (byte) (char)100, (byte) (char)111, (byte) (char)1}); assertNotNull(mmtfBean); diff --git a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java index 5270443..249c06b 100644 --- a/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java +++ b/mmtf-encoder/src/main/java/org/rcsb/mmtf/serializers/MessagePackSerializer.java @@ -15,17 +15,11 @@ */ public class MessagePackSerializer { - public byte[] serialize(MmtfBean object) { + public byte[] serialize(MmtfBean object) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); objectMapper.setSerializationInclusion(Include.NON_NULL); - byte[] byteArray; - try { - byteArray = objectMapper.writeValueAsBytes(object); - } catch (JsonProcessingException e) { - e.printStackTrace(); - byteArray = new byte[0]; - } + byte[] byteArray = objectMapper.writeValueAsBytes(object); return byteArray; } } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java index 94b5062..382b386 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/serializer/TestMessagePack.java @@ -6,6 +6,8 @@ import org.rcsb.mmtf.dataholders.MmtfBean; import org.rcsb.mmtf.serializers.MessagePackSerializer; +import com.fasterxml.jackson.core.JsonProcessingException; + import uk.co.jemos.podam.api.PodamFactory; import uk.co.jemos.podam.api.PodamFactoryImpl; @@ -13,7 +15,7 @@ public class TestMessagePack { @Test - public void testBasic() { + public void testBasic() throws JsonProcessingException { MessagePackSerializer messagePackSerializer = new MessagePackSerializer(); PodamFactory factory = new PodamFactoryImpl(); MmtfBean mmtfBean = factory.manufacturePojo(MmtfBean.class); From 917c482e5a1952aa358efe8ccbbf616373051dc1 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 11:52:19 -0700 Subject: [PATCH 106/108] Check PDBGroup equals method works --- .../mmtf/dataholders/TestDataHolders.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index c164a8c..af49d9e 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; import org.unitils.reflectionassert.ReflectionAssert; @@ -59,4 +60,31 @@ public void testDsspType() { assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromInt(-1)); } + + + @Test + public void testPdbGroupType() { + + PDBGroup pdbGroupOne = new PDBGroup(); + pdbGroupOne.setAtomChargeList(new int[] {1,1}); + pdbGroupOne.setAtomNameList(new String[] {"A","B"}); + pdbGroupOne.setBondAtomList(new int[] {0,1}); + pdbGroupOne.setBondOrderList(new int[] {1}); + pdbGroupOne.setChemCompType("POLT"); + pdbGroupOne.setElementList(new String[] {"A","B"}); + pdbGroupOne.setGroupName("MET"); + pdbGroupOne.setSingleLetterCode('A'); + + PDBGroup pdbGroupTwo = new PDBGroup(); + pdbGroupTwo.setAtomChargeList(new int[] {1,1}); + pdbGroupTwo.setAtomNameList(new String[] {"A","B"}); + pdbGroupTwo.setBondAtomList(new int[] {0,1}); + pdbGroupTwo.setBondOrderList(new int[] {1}); + pdbGroupTwo.setChemCompType("POLT"); + pdbGroupTwo.setElementList(new String[] {"A","B"}); + pdbGroupTwo.setGroupName("MET"); + pdbGroupTwo.setSingleLetterCode('A'); + assertTrue(pdbGroupOne.equals(pdbGroupTwo)); + + } } From 2f015996703b1272b1b5bdc7c47e4be60b1dd945 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 14:47:04 -0700 Subject: [PATCH 107/108] Added new tests for the encoder decoder and common --- .../mmtf/dataholders/TestDataHolders.java | 82 +++++------------ .../rcsb/mmtf/dataholders/TestDsspType.java | 39 ++++++++ .../rcsb/mmtf/dataholders/TestPdbGroup.java | 89 +++++++++++++++++++ .../rcsb/mmtf/gitversion/TestGitVersion.java | 1 + .../rcsb/mmtf/decoder/TestDefaultDecoder.java | 12 ++- .../rcsb/mmtf/encoder/TestDefaultEncoder.java | 42 +++++++-- 6 files changed, 200 insertions(+), 65 deletions(-) create mode 100644 mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java create mode 100644 mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java index af49d9e..7b7e166 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDataHolders.java @@ -1,8 +1,12 @@ package org.rcsb.mmtf.dataholders; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; import org.junit.Test; import org.unitils.reflectionassert.ReflectionAssert; @@ -13,78 +17,38 @@ public class TestDataHolders { @Test - public void testBeans(){ + public void testBeans() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException{ PodamFactory factory = new PodamFactoryImpl(); // Tests if setters are set appropriately ReflectionAssert.assertPropertiesNotNull("Some properties null.", factory.manufacturePojo(MmtfBean.class)); + testData(MmtfBean.class, factory.manufacturePojo(MmtfBean.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", factory.manufacturePojo(BioAssemblyData.class)); + testData(BioAssemblyData.class, factory.manufacturePojo(BioAssemblyData.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", factory.manufacturePojo(BioAssemblyTrans.class)); + testData(BioAssemblyTrans.class, factory.manufacturePojo(BioAssemblyTrans.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", factory.manufacturePojo(Entity.class)); + testData(Entity.class, factory.manufacturePojo(Entity.class)); + ReflectionAssert.assertPropertiesNotNull("Some properties null.", factory.manufacturePojo(PDBGroup.class)); - } + testData(PDBGroup.class, factory.manufacturePojo(PDBGroup.class)); - - @Test - public void testDsspType() { - - assertEquals(DsspType.dsspTypeFromString("pi Helix"), DsspType.dsspTypeFromInt(0)); - assertEquals(DsspType.PI_HELIX, DsspType.dsspTypeFromInt(0)); - - assertEquals(DsspType.dsspTypeFromString("Bend"), DsspType.dsspTypeFromInt(1)); - assertEquals(DsspType.BEND, DsspType.dsspTypeFromInt(1)); - - assertEquals(DsspType.dsspTypeFromString("alpha Helix"), DsspType.dsspTypeFromInt(2)); - assertEquals(DsspType.ALPHA_HELIX, DsspType.dsspTypeFromInt(2)); - - assertEquals(DsspType.dsspTypeFromString("Extended"), DsspType.dsspTypeFromInt(3)); - assertEquals(DsspType.EXTENDED, DsspType.dsspTypeFromInt(3)); - - assertEquals(DsspType.dsspTypeFromString("3-10 Helix"), DsspType.dsspTypeFromInt(4)); - assertEquals(DsspType.HELIX_3_10, DsspType.dsspTypeFromInt(4)); - - assertEquals(DsspType.dsspTypeFromString("Bridge"), DsspType.dsspTypeFromInt(5)); - assertEquals(DsspType.BRIDGE, DsspType.dsspTypeFromInt(5)); - - assertEquals(DsspType.dsspTypeFromString("Turn"), DsspType.dsspTypeFromInt(6)); - assertEquals(DsspType.TURN, DsspType.dsspTypeFromInt(6)); - - assertEquals(DsspType.dsspTypeFromString("Coil"), DsspType.dsspTypeFromInt(7)); - assertEquals(DsspType.COIL, DsspType.dsspTypeFromInt(7)); - - assertEquals(DsspType.dsspTypeFromString("NA"), DsspType.dsspTypeFromInt(-1)); - assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromInt(-1)); - } - @Test - public void testPdbGroupType() { - - PDBGroup pdbGroupOne = new PDBGroup(); - pdbGroupOne.setAtomChargeList(new int[] {1,1}); - pdbGroupOne.setAtomNameList(new String[] {"A","B"}); - pdbGroupOne.setBondAtomList(new int[] {0,1}); - pdbGroupOne.setBondOrderList(new int[] {1}); - pdbGroupOne.setChemCompType("POLT"); - pdbGroupOne.setElementList(new String[] {"A","B"}); - pdbGroupOne.setGroupName("MET"); - pdbGroupOne.setSingleLetterCode('A'); - - PDBGroup pdbGroupTwo = new PDBGroup(); - pdbGroupTwo.setAtomChargeList(new int[] {1,1}); - pdbGroupTwo.setAtomNameList(new String[] {"A","B"}); - pdbGroupTwo.setBondAtomList(new int[] {0,1}); - pdbGroupTwo.setBondOrderList(new int[] {1}); - pdbGroupTwo.setChemCompType("POLT"); - pdbGroupTwo.setElementList(new String[] {"A","B"}); - pdbGroupTwo.setGroupName("MET"); - pdbGroupTwo.setSingleLetterCode('A'); - assertTrue(pdbGroupOne.equals(pdbGroupTwo)); - + private void testData(@SuppressWarnings("rawtypes") Class beanClass, Object object) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException { + for(PropertyDescriptor propertyDescriptor : + Introspector.getBeanInfo(beanClass).getPropertyDescriptors()){ + assertNotNull(propertyDescriptor.getReadMethod().invoke(object)); + } } + + } diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java new file mode 100644 index 0000000..1c037ba --- /dev/null +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java @@ -0,0 +1,39 @@ +package org.rcsb.mmtf.dataholders; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestDsspType { + @Test + public void testDsspType() { + + assertEquals(DsspType.dsspTypeFromString("pi Helix"), DsspType.dsspTypeFromInt(0)); + assertEquals(DsspType.PI_HELIX, DsspType.dsspTypeFromInt(0)); + + assertEquals(DsspType.dsspTypeFromString("Bend"), DsspType.dsspTypeFromInt(1)); + assertEquals(DsspType.BEND, DsspType.dsspTypeFromInt(1)); + + assertEquals(DsspType.dsspTypeFromString("alpha Helix"), DsspType.dsspTypeFromInt(2)); + assertEquals(DsspType.ALPHA_HELIX, DsspType.dsspTypeFromInt(2)); + + assertEquals(DsspType.dsspTypeFromString("Extended"), DsspType.dsspTypeFromInt(3)); + assertEquals(DsspType.EXTENDED, DsspType.dsspTypeFromInt(3)); + + assertEquals(DsspType.dsspTypeFromString("3-10 Helix"), DsspType.dsspTypeFromInt(4)); + assertEquals(DsspType.HELIX_3_10, DsspType.dsspTypeFromInt(4)); + + assertEquals(DsspType.dsspTypeFromString("Bridge"), DsspType.dsspTypeFromInt(5)); + assertEquals(DsspType.BRIDGE, DsspType.dsspTypeFromInt(5)); + + assertEquals(DsspType.dsspTypeFromString("Turn"), DsspType.dsspTypeFromInt(6)); + assertEquals(DsspType.TURN, DsspType.dsspTypeFromInt(6)); + + assertEquals(DsspType.dsspTypeFromString("Coil"), DsspType.dsspTypeFromInt(7)); + assertEquals(DsspType.COIL, DsspType.dsspTypeFromInt(7)); + + assertEquals(DsspType.dsspTypeFromString("NA"), DsspType.dsspTypeFromInt(-1)); + assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromInt(-1)); + + } +} diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java new file mode 100644 index 0000000..dda0d47 --- /dev/null +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java @@ -0,0 +1,89 @@ +package org.rcsb.mmtf.dataholders; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +public class TestPdbGroup { + + + private PDBGroup pdbGroupOne; + private PDBGroup pdbGroupTwo; + + @Before + public void beforeTest() { + + pdbGroupOne = makePdbGroup(); + pdbGroupTwo = makePdbGroup(); + + } + + + private PDBGroup makePdbGroup() { + PDBGroup pdbGroup = new PDBGroup(); + pdbGroup.setAtomChargeList(new int[] {1,1}); + pdbGroup.setAtomNameList(new String[] {"A","B"}); + pdbGroup.setBondAtomList(new int[] {0,1}); + pdbGroup.setBondOrderList(new int[] {1}); + pdbGroup.setChemCompType("POLT"); + pdbGroup.setElementList(new String[] {"A","B"}); + pdbGroup.setGroupName("MET"); + pdbGroup.setSingleLetterCode('A'); + return pdbGroup; + } + + + @Test + public void testPdbGroupEquals() { + assertTrue(pdbGroupOne.equals(pdbGroupTwo)); + } + + @Test + public void testPdbGroupNotEqualsCharge() { + pdbGroupOne.setAtomChargeList(new int[] {0,1}); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + + @Test + public void testPdbGroupNotEqualsName() { + pdbGroupOne.setAtomNameList(new String[] {"A","C"}); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + + @Test + public void testPdbGroupNotEqualsBond() { + pdbGroupOne.setBondAtomList(new int[] {1,1}); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + + @Test + public void testPdbGroupNotEqualsOrder() { + pdbGroupOne.setBondOrderList(new int[] {0}); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + + @Test + public void testPdbGroupNotEqualsChem() { + pdbGroupOne.setChemCompType("LL"); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + + + @Test + public void testPdbGroupNotEqualsEle() { + pdbGroupOne.setElementList(new String[] {"A","BC"}); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + @Test + public void testPdbGroupNotEqualsGroupName() { + pdbGroupOne.setGroupName("MES"); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + @Test + public void testPdbGroupNotEqualsSingle() { + pdbGroupOne.setSingleLetterCode('B'); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } +} diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java b/mmtf-common/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java index a07c166..087a71c 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/gitversion/TestGitVersion.java @@ -13,5 +13,6 @@ public class TestGitVersion { public void doesGitVersionExist(){ assertNotEquals("NA", GetRepoState.getCurrentVersion()); } + } diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java index 41cf8ca..850c64c 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java @@ -1,6 +1,12 @@ package org.rcsb.mmtf.decoder; +import static org.junit.Assert.assertNotNull; + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import org.junit.Test; import org.rcsb.mmtf.api.DataTransferInterface; @@ -13,11 +19,15 @@ public class TestDefaultDecoder { @Test - public void testDecodeAllFields() throws IOException { + public void testDecodeAllFields() throws IOException, IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { PodamFactory factory = new PodamFactoryImpl(); MmtfBean mmtfBean = factory.manufacturePojo(MmtfBean.class); DefaultDecoder defaultDecoder = new DefaultDecoder(mmtfBean); ReflectionAssert.assertPropertiesNotNull("Some properties null after decoding", defaultDecoder); + for(PropertyDescriptor propertyDescriptor : + Introspector.getBeanInfo(MmtfBean.class).getPropertyDescriptors()){ + assertNotNull(propertyDescriptor.getReadMethod().invoke(mmtfBean)); + } } diff --git a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java index d26b65f..7154e8d 100644 --- a/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java +++ b/mmtf-encoder/src/test/java/org/rcsb/mmtf/encoder/TestDefaultEncoder.java @@ -1,28 +1,61 @@ package org.rcsb.mmtf.encoder; +import static org.junit.Assert.assertNotNull; + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.unitils.reflectionassert.ReflectionAssert; public class TestDefaultEncoder { - + @Rule + public TemporaryFolder testFolder = new TemporaryFolder(); + /** * Test whether calling all the set methods gives a none null get * @throws IOException */ @Test public void testEncodeAllFields() throws IOException { + DummyApiImpl dummyApiImpl = new DummyApiImpl(); DefaultEncoder defaultEncoder = new DefaultEncoder(dummyApiImpl); ReflectionAssert.assertPropertiesNotNull("Some properties null after encoding", defaultEncoder.getMmtfBean()); } + + + @Test + public void testWriter() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException { + WriterToEncoder writerToEncoder = getWriterEncoder(); + ReflectionAssert.assertPropertiesNotNull("Some properties null after writing", writerToEncoder); + for(PropertyDescriptor propertyDescriptor : + Introspector.getBeanInfo(WriterToEncoder.class).getPropertyDescriptors()){ + if(propertyDescriptor.getReadMethod()!=null){ + assertNotNull(propertyDescriptor.getReadMethod().invoke(writerToEncoder)); + } + } + } + + + @Test + public void testWriteToFile() throws IOException { + WriterToEncoder writerToEncoder = getWriterEncoder(); + File tempFile = testFolder.newFile("tmpfile"); + WriterUtils.writeDataToFile(writerToEncoder, tempFile.getAbsolutePath()); + } - @Test - public void testWriter() { + + private WriterToEncoder getWriterEncoder() { WriterToEncoder writerToEncoder = new WriterToEncoder(); writerToEncoder.initStructure(1, 1, 1, 1, 1, "ABC"); writerToEncoder.setModelInfo(0, 1); @@ -36,7 +69,6 @@ public void testWriter() { writerToEncoder.setBioAssemblyTrans(0, new int[1], new double[6]); writerToEncoder.setXtalInfo("A", new float[6]); writerToEncoder.finalizeStructure(); - ReflectionAssert.assertPropertiesNotNull("Some properties null after writing", writerToEncoder); - + return writerToEncoder; } } From 5a23868bab0b057444875a09f73962c77682ea78 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Wed, 13 Apr 2016 15:06:40 -0700 Subject: [PATCH 108/108] Some more tests and test more cases. ReaderUtils still not tested --- .../rcsb/mmtf/dataholders/TestDsspType.java | 4 +++ .../rcsb/mmtf/dataholders/TestPdbGroup.java | 30 +++++++++++++++++++ .../org/rcsb/mmtf/decoder/ReaderUtils.java | 10 +++++-- .../rcsb/mmtf/decoder/TestDefaultDecoder.java | 10 +++++-- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java index 1c037ba..a75b6a6 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestDsspType.java @@ -35,5 +35,9 @@ public void testDsspType() { assertEquals(DsspType.dsspTypeFromString("NA"), DsspType.dsspTypeFromInt(-1)); assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromInt(-1)); + assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromString(null)); + assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromString("MMTF")); + assertEquals(DsspType.NULL_ENTRY, DsspType.dsspTypeFromInt(100)); + } } diff --git a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java index dda0d47..c5cc535 100644 --- a/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java +++ b/mmtf-common/src/test/java/org/rcsb/mmtf/dataholders/TestPdbGroup.java @@ -3,6 +3,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; + import org.junit.Before; import org.junit.Test; @@ -35,6 +37,12 @@ private PDBGroup makePdbGroup() { } + @Test + public void testPdbGroupEqualsItstelf() { + assertTrue(pdbGroupOne.equals(pdbGroupOne)); + } + + @Test public void testPdbGroupEquals() { assertTrue(pdbGroupOne.equals(pdbGroupTwo)); @@ -86,4 +94,26 @@ public void testPdbGroupNotEqualsSingle() { pdbGroupOne.setSingleLetterCode('B'); assertFalse(pdbGroupOne.equals(pdbGroupTwo)); } + + @Test + public void testPdbGroupNotEqualsNull() { + assertFalse(pdbGroupOne.equals(null)); + } + + @Test + public void testPdbGroupNotEqulasOtherObj() { + assertFalse(pdbGroupOne.equals(new ArrayList())); + } + + @Test + public void testPdbGroupNotEqualsNullChem() { + pdbGroupTwo.setChemCompType(null); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } + + @Test + public void testPdbGroupNotEqulasNullType() { + pdbGroupTwo.setGroupName(null); + assertFalse(pdbGroupOne.equals(pdbGroupTwo)); + } } diff --git a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java index dc01091..421a54b 100644 --- a/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java +++ b/mmtf-decoder/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java @@ -36,7 +36,6 @@ public static MmtfBean getDataFromUrl(String inputCode) throws IOException { is = url.openStream(); byte[] byteChunk = new byte[BYTE_BUFFER_CHUNK_SIZE]; // Or whatever size you want to read in at a time. int n; - while ( (n = is.read(byteChunk)) > 0 ) { baos.write(byteChunk, 0, n); } @@ -44,7 +43,6 @@ public static MmtfBean getDataFromUrl(String inputCode) throws IOException { catch (IOException e) { System.err.printf ("Failed while reading bytes from %s: %s", url.toExternalForm(), e.getMessage()); e.printStackTrace (); - // Perform any other exception handling that's appropriate. } finally { if (is != null) { is.close(); } @@ -62,7 +60,7 @@ public static MmtfBean getDataFromUrl(String inputCode) throws IOException { * @return A deflated byte array * @throws IOException Signals that an I/O exception has occurred. */ - private static byte[] deflateGzip(final byte[] inputBytes){ + public static byte[] deflateGzip(final byte[] inputBytes){ // Start the byte input stream ByteArrayInputStream bis = new ByteArrayInputStream(inputBytes); GZIPInputStream gis; @@ -116,6 +114,12 @@ public static MmtfBean getDataFromFile(String filePath) throws IOException { return messagePackDeserializer.deserialize(readFile(filePath)); } + /** + * Read a byte array from a file + * @param filePath the input file path + * @return the returned byte array + * @throws IOException + */ private static byte[] readFile(String filePath) throws IOException { Path path = Paths.get(filePath); byte[] data = Files.readAllBytes(path); diff --git a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java index 850c64c..eb3c1d2 100644 --- a/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java +++ b/mmtf-decoder/src/test/java/org/rcsb/mmtf/decoder/TestDefaultDecoder.java @@ -25,9 +25,16 @@ public void testDecodeAllFields() throws IOException, IntrospectionException, Il DefaultDecoder defaultDecoder = new DefaultDecoder(mmtfBean); ReflectionAssert.assertPropertiesNotNull("Some properties null after decoding", defaultDecoder); for(PropertyDescriptor propertyDescriptor : - Introspector.getBeanInfo(MmtfBean.class).getPropertyDescriptors()){ + Introspector.getBeanInfo(MmtfBean.class).getPropertyDescriptors()){ assertNotNull(propertyDescriptor.getReadMethod().invoke(mmtfBean)); } + // Check the decoder has been populated to + for(PropertyDescriptor propertyDescriptor : + Introspector.getBeanInfo(DefaultDecoder.class).getPropertyDescriptors()){ + if(propertyDescriptor.getReadMethod()!=null){ + assertNotNull(propertyDescriptor.getReadMethod().invoke(defaultDecoder)); + } + } } @@ -39,5 +46,4 @@ public void testReader() { decoderToReader.read(dummyApiImpl, inputInflator); } - }