Skip to content

Commit

Permalink
Refactoring of class names as per discussions.
Browse files Browse the repository at this point in the history
  • Loading branch information
abradle committed Apr 20, 2016
1 parent 3f16aab commit e910aae
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Anthony Bradley
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class MmtfBean implements Serializable {
public class MmtfEncodedStructure implements Serializable {


/** The number to divide coordinate int values by. */
Expand Down Expand Up @@ -147,7 +147,7 @@ public class MmtfBean implements Serializable {
private String releaseDate;

/** Constructor to set the default values for floats */
public MmtfBean() {
public MmtfEncodedStructure() {

/** The mmtf version. Set here. */
mmtfVersion = "0.1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import java.io.OutputStream;

import org.msgpack.jackson.dataformat.MessagePackFactory;
import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* A message pack implementation of the mmtf serializer / deserializer
* A message pack implementation of the mmtf serializer / deserializer.
* @author Anthony Bradley
*
*/
public class MmtfBeanSeDeMessagePackImpl implements MmtfBeanSeDerializerInterface {

@Override
public MmtfBean deserialize(InputStream byteArray){
MmtfBean mmtfBean = null;
public MmtfEncodedStructure deserialize(InputStream byteArray){
MmtfEncodedStructure mmtfBean = null;
try {
mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(byteArray, MmtfBean.class);
mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(byteArray, MmtfEncodedStructure.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand All @@ -30,7 +30,7 @@ public MmtfBean deserialize(InputStream byteArray){
}

@Override
public void serialize(MmtfBean object, OutputStream outputStream) {
public void serialize(MmtfEncodedStructure object, OutputStream outputStream) {
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
objectMapper.setSerializationInclusion(Include.NON_NULL);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
import java.io.InputStream;
import java.io.OutputStream;

import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;

/**
* An interface to carry out serializing / deserializing to mmtfBean
* An interface to carry out serializing / deserializing to mmtfBean.
* @author Anthony Bradley
*
*/
public interface MmtfBeanSeDerializerInterface {

public void serialize(MmtfBean mmtfBean, OutputStream outputStream);
/**
* Serialize an mmtfBean to a generic output stream.
* @param mmtfBean the compressed data
* @param outputStream the ouput stream to write to
*/
public void serialize(MmtfEncodedStructure mmtfBean, OutputStream outputStream);

public MmtfBean deserialize(InputStream dataInputStream);
/**
* Deserialize and input stream from an input stream.
* @param dataInputStream the inputstream to deserialize
* @return the compressed structure data.
*/
public MmtfEncodedStructure deserialize(InputStream dataInputStream);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void testBeans() throws IllegalAccessException, IllegalArgumentException,
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));
factory.manufacturePojo(MmtfEncodedStructure.class));
testData(MmtfEncodedStructure.class, factory.manufacturePojo(MmtfEncodedStructure.class));

ReflectionAssert.assertPropertiesNotNull("Some properties null.",
factory.manufacturePojo(BioAssemblyData.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.io.ByteArrayOutputStream;

import org.junit.Test;
import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;

import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;
Expand All @@ -27,7 +27,7 @@ public void testDeserialize() {
MmtfBeanSeDeMessagePackImpl mmtfBeanSeDeMessagePackImpl = new MmtfBeanSeDeMessagePackImpl();
byte[] source = new byte[] {(byte) (char) 129, (byte) (char)162, (byte) (char)100, (byte) (char)111, (byte) (char)1};
ByteArrayInputStream bis = new ByteArrayInputStream(source);
MmtfBean mmtfBean = mmtfBeanSeDeMessagePackImpl.deserialize(bis);
MmtfEncodedStructure mmtfBean = mmtfBeanSeDeMessagePackImpl.deserialize(bis);
assertNotNull(mmtfBean);
}

Expand All @@ -38,7 +38,7 @@ public void testDeserialize() {
public void testSerialize() {
MmtfBeanSeDeMessagePackImpl mmtfBeanSeDeMessagePackImpl = new MmtfBeanSeDeMessagePackImpl();
PodamFactory factory = new PodamFactoryImpl();
MmtfBean mmtfBean = factory.manufacturePojo(MmtfBean.class);
MmtfEncodedStructure mmtfBean = factory.manufacturePojo(MmtfEncodedStructure.class);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
mmtfBeanSeDeMessagePackImpl.serialize(mmtfBean, bos);
assertNotNull(bos.toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.rcsb.mmtf.api.StructureDataInterface;
import org.rcsb.mmtf.dataholders.BioAssemblyData;
import org.rcsb.mmtf.dataholders.Entity;
import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;
import org.rcsb.mmtf.dataholders.PDBGroup;

/**
Expand All @@ -20,38 +20,38 @@ public class DefaultDecoder implements StructureDataInterface {
* Constructor for the default decoder.
* @param inputData The input mmtfBean data to be decompressed.
*/
public DefaultDecoder(MmtfBean inputData) {
public DefaultDecoder(MmtfEncodedStructure inputData) {
groupList = ArrayConverters.convertFourByteToIntegers(inputData.getGroupTypeList());
// Decode the coordinate and B-factor arrays.
cartnX = ArrayConverters.convertIntsToFloats(
ArrayDecoders.deltaDecode(
ArrayConverters.combineIntegers(
ArrayConverters.convertTwoByteToIntegers(inputData.getxCoordSmall()),
ArrayConverters.convertFourByteToIntegers(inputData.getxCoordBig()))),
MmtfBean.COORD_DIVIDER);
MmtfEncodedStructure.COORD_DIVIDER);
cartnY = ArrayConverters.convertIntsToFloats(
ArrayDecoders.deltaDecode(
ArrayConverters.combineIntegers(
ArrayConverters.convertTwoByteToIntegers(inputData.getyCoordSmall()),
ArrayConverters.convertFourByteToIntegers(inputData.getyCoordBig()))),
MmtfBean.COORD_DIVIDER);
MmtfEncodedStructure.COORD_DIVIDER);
cartnZ = ArrayConverters.convertIntsToFloats(
ArrayDecoders.deltaDecode(
ArrayConverters.combineIntegers(
ArrayConverters.convertTwoByteToIntegers(inputData.getzCoordSmall()),
ArrayConverters.convertFourByteToIntegers(inputData.getzCoordBig()))),
MmtfBean.COORD_DIVIDER);
MmtfEncodedStructure.COORD_DIVIDER);
bFactor = ArrayConverters.convertIntsToFloats(
ArrayDecoders.deltaDecode(
ArrayConverters.combineIntegers(
ArrayConverters.convertTwoByteToIntegers(inputData.getbFactorSmall()),
ArrayConverters.convertFourByteToIntegers(inputData.getbFactorBig()))),
MmtfBean.OCCUPANCY_BFACTOR_DIVIDER);
MmtfEncodedStructure.OCCUPANCY_BFACTOR_DIVIDER);
// Run length decode the occupancy array
occupancy = ArrayConverters.convertIntsToFloats(
ArrayDecoders.runlengthDecode(
ArrayConverters.convertFourByteToIntegers(inputData.getOccupancyList())),
MmtfBean.OCCUPANCY_BFACTOR_DIVIDER);
MmtfEncodedStructure.OCCUPANCY_BFACTOR_DIVIDER);
// Run length and delta
atomId = ArrayDecoders.deltaDecode(
ArrayDecoders.runlengthDecode(
Expand Down Expand Up @@ -340,23 +340,23 @@ public int getNumAtoms() {
@Override
public float getRfree() {
if (rFree==null|| rFree ==0.0f) {
return MmtfBean.UNAVAILABLE_R_VALUE;
return MmtfEncodedStructure.UNAVAILABLE_R_VALUE;
}
return rFree;
}

@Override
public float getResolution() {
if (resolution==null || resolution==0.0f) {
return MmtfBean.UNAVAILABLE_RESOLUTION_VALUE;
return MmtfEncodedStructure.UNAVAILABLE_RESOLUTION_VALUE;
}
return resolution;
}

@Override
public float getRwork() {
if (rWork==null|| rWork ==0.0f) {
return MmtfBean.UNAVAILABLE_R_VALUE;
return MmtfEncodedStructure.UNAVAILABLE_R_VALUE;
}
return rWork;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.nio.file.Path;
import java.util.zip.GZIPInputStream;

import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;
import org.rcsb.mmtf.sedeserializers.MmtfBeanSeDeMessagePackImpl;
import org.rcsb.mmtf.utils.CodecUtils;

Expand All @@ -30,7 +30,7 @@ public class ReaderUtils {
* @return the MMTFBean of the deserialized data
* @throws IOException if the data cannot be read from the URL
*/
public static MmtfBean getDataFromUrl(String pdbCode) throws IOException {
public static MmtfEncodedStructure getDataFromUrl(String pdbCode) throws IOException {
// Get these as an inputstream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
Expand Down Expand Up @@ -90,7 +90,7 @@ public static byte[] deflateGzip(byte[] inputBytes) throws IOException {
* @return the deserialized mmtfBean
* @throws IOException an error reading the file
*/
public static MmtfBean getDataFromFile(Path filePath) throws IOException {
public static MmtfEncodedStructure getDataFromFile(Path filePath) throws IOException {
// Now return the gzip deflated and deserialized byte array
MmtfBeanSeDeMessagePackImpl mmtfBeanSeDeMessagePackImpl = new MmtfBeanSeDeMessagePackImpl();
return mmtfBeanSeDeMessagePackImpl.deserialize(new ByteArrayInputStream(readFile(filePath)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Anthony Bradley
*
*/
public class DecoderToReader {
public class StructureDataToAdapter {

/** The struct inflator. */
private StructureAdapterInterface structInflator;
Expand All @@ -30,7 +30,7 @@ public class DecoderToReader {
* @param inputApi the interface to the decoded data
* @param inputInflator the interface to put the data into the client object
*/
public DecoderToReader(StructureDataInterface inputApi, StructureAdapterInterface inputInflator){
public StructureDataToAdapter(StructureDataInterface inputApi, StructureAdapterInterface inputInflator){
// Set the counters to zero
modelCounter = 0;
chainCounter = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.lang.reflect.InvocationTargetException;

import org.junit.Test;
import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;
import org.unitils.reflectionassert.ReflectionAssert;

import uk.co.jemos.podam.api.PodamFactory;
Expand All @@ -33,11 +33,11 @@ public class TestDefaultDecoder {
@Test
public void testDecodeAllFields() throws IOException, IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
PodamFactory factory = new PodamFactoryImpl();
MmtfBean mmtfBean = factory.manufacturePojo(MmtfBean.class);
MmtfEncodedStructure mmtfBean = factory.manufacturePojo(MmtfEncodedStructure.class);
DefaultDecoder defaultDecoder = new DefaultDecoder(mmtfBean);
ReflectionAssert.assertPropertiesNotNull("Some properties null after decoding", defaultDecoder);
for(PropertyDescriptor propertyDescriptor :
Introspector.getBeanInfo(MmtfBean.class).getPropertyDescriptors()){
Introspector.getBeanInfo(MmtfEncodedStructure.class).getPropertyDescriptors()){
assertNotNull(propertyDescriptor.getReadMethod().invoke(mmtfBean));
}
// Check the decoder has been populated to
Expand All @@ -56,7 +56,7 @@ public void testDecodeAllFields() throws IOException, IntrospectionException, Il
@Test
public void testReader() {
DummyApiImpl dummyApiImpl = new DummyApiImpl();
new DecoderToReader(dummyApiImpl, new DummyTransferImpl());
new StructureDataToAdapter(dummyApiImpl, new DummyTransferImpl());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.rcsb.mmtf.decoder;

import org.junit.Test;
import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.dataholders.MmtfEncodedStructure;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testGzipDecompressText() throws IOException {
@Test
public void testReadFromFile() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
MmtfBean mmtfBean = ReaderUtils.getDataFromFile(Paths.get(classLoader.getResource("mmtf/4cup.mmtf").getFile()));
MmtfEncodedStructure mmtfBean = ReaderUtils.getDataFromFile(Paths.get(classLoader.getResource("mmtf/4cup.mmtf").getFile()));
assertNotEquals(mmtfBean, null);
assertEquals(mmtfBean.getDepositionDate(), "2014-03-21");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author Anthony Bradley
*
*/
public class WriterToEncoder implements StructureDataInterface, StructureAdapterInterface {
public class AdapterToStructureData implements StructureDataInterface, StructureAdapterInterface {


/** The X coordinates */
Expand All @@ -29,10 +29,10 @@ public class WriterToEncoder implements StructureDataInterface, StructureAdapter
/** The Z coordinates */
private float[] cartnZ;

/** The X coordinates */
/** The B factors */
private float[] bFactor;

/** The Y coordinates */
/** The occupancy */
private float[] occupancy;

/** The atom id. */
Expand Down
Loading

0 comments on commit e910aae

Please sign in to comment.