Skip to content

Commit

Permalink
Merge pull request #21 from rcsb/v0.2.2
Browse files Browse the repository at this point in the history
Version 0.2.2 of mmtf-java
  • Loading branch information
abradle committed Jul 5, 2016
2 parents 54261d4 + 3be09c9 commit 6985a00
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 32 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ All notable changes to this project will be documented in this file, following t
- Added package info for the codec project
- Improved docs and refactoring of test names

## v0.2.2 - 2016-07-05
### Changed
- Refactored the generation of Bioassemblies
- Refactored generateGroupMap to generateGroupList
- Update to the serialization module - only construct object mapper once

### Added
- getBioassemblyName added to the API - return the BioassemblyName as a string.
- Tests for EncoderUtils

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/rcsb/mmtf-java.svg?branch=master)](https://travis-ci.org/rcsb/mmtf-java)
[![Coverage Status](https://coveralls.io/repos/github/rcsb/mmtf-java/badge.svg?branch=master)](https://coveralls.io/github/rcsb/mmtf-java?branch=master)
[![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.2.1-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt)
[![Version](http://img.shields.io/badge/version-0.2.2-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt)



Expand All @@ -16,12 +16,12 @@ The alpha release is available on Maven central.
<dependency>
<groupId>org.rcsb</groupId>
<artifactId>mmtf-codec</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>org.rcsb</groupId>
<artifactId>mmtf-api</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,17 @@ public interface StructureDataInterface {
/**
* Returns the number of transformations in a given bioassembly.
* @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed).
* @return an integer specifying of transformations in a given bioassembly.
* @return an integer specifying the number of transformations in a given bioassembly.
*/
int getNumTransInBioassembly(int bioassemblyIndex);

/**
* Returns the name of the transformation for a bioassembly.
* @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed).
* @return a string specifying the name of a given bioassembly.
*/
String getBioassemblyName(int bioassemblyIndex);

/**
* Returns the list of chain indices for the given transformation for the given bioassembly.
* @param bioassemblyIndex an integer specifying the bioassembly index (zero indexed).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,9 @@ public double[][] getNcsOperatorList() {
return ncsOperMatrixList;
}

@Override
public String getBioassemblyName(int bioassemblyIndex) {
return bioAssembly.get(bioassemblyIndex).getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,17 @@ public void setAtomInfo(String atomName, int serialNumber, char alternativeLocat
@Override
public void setBioAssemblyTrans(int bioAssemblyIndex, int[] chainIndices, double[] transform, String name) {
BioAssemblyData bioAssemblyData;
List<BioAssemblyTransformation> bioAssemblyTranList;
if (bioAssembly.size()>bioAssemblyIndex) {
bioAssemblyTranList = bioAssembly.get(bioAssemblyIndex).getTransformList();
bioAssemblyData = bioAssembly.get(bioAssemblyIndex);
}
else{
bioAssemblyData = new BioAssemblyData();
bioAssemblyTranList = new ArrayList<>();
bioAssemblyData.setTransformList(bioAssemblyTranList);
bioAssemblyData = new BioAssemblyData(name);
bioAssembly.add(bioAssemblyData);
}
BioAssemblyTransformation bioAssemblyTrans = new BioAssemblyTransformation();
bioAssemblyTrans.setChainIndexList(chainIndices);
bioAssemblyTrans.setMatrix(transform);
bioAssemblyTranList.add(bioAssemblyTrans);
bioAssemblyData.getTransformList().add(bioAssemblyTrans);
}

@Override
Expand Down Expand Up @@ -610,4 +607,9 @@ public double[][] getNcsOperatorList() {
return ncsOperMatrixList;
}

@Override
public String getBioassemblyName(int bioassemblyIndex) {
return bioAssembly.get(bioassemblyIndex).getName();
}

}
36 changes: 21 additions & 15 deletions mmtf-codec/src/main/java/org/rcsb/mmtf/encoder/EncoderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class EncoderUtils {
* @param structureDataInterface the input interface
* @return a list of all the groups in the molecule
*/
public static Group[] generateGroupMap(StructureDataInterface structureDataInterface) {
public static Group[] generateGroupList(StructureDataInterface structureDataInterface) {
int[] groupTypeIndices = structureDataInterface.getGroupTypeIndices();
if(groupTypeIndices.length==0){
return new Group[0];
Expand All @@ -59,31 +59,37 @@ public static Group[] generateGroupMap(StructureDataInterface structureDataInter
/**
* Find the bioassembly information as a list from the {@link StructureDataInterface}.
* @param structureDataInterface the interface from where to find the data
* @return a list of bioassembly information
* @return a list of bioassembly information to be stored in the MMTF data structure.
*/
public static List<BioAssemblyData> generateBioassemblies(StructureDataInterface structureDataInterface) {
int numBioassemblies = structureDataInterface.getNumBioassemblies();
List<BioAssemblyData> outList = new ArrayList<>();
for (int i=0; i<numBioassemblies; i++) {
BioAssemblyData bioAssemblyData = new BioAssemblyData();
String name = Integer.toString(i+1);
bioAssemblyData.setName(name);
outList.add(bioAssemblyData);
List<BioAssemblyTransformation> transformList = new ArrayList<>();
bioAssemblyData.setTransformList(transformList);
BioAssemblyData bioassembly = new BioAssemblyData(structureDataInterface.getBioassemblyName(i));
outList.add(bioassembly);
int numTrans = structureDataInterface.getNumTransInBioassembly(i);
for (int j=0; j<numTrans; j++) {
BioAssemblyTransformation bioAssemblyTrans = new BioAssemblyTransformation();
transformList.add(bioAssemblyTrans);
bioAssemblyTrans.setChainIndexList(
structureDataInterface.getChainIndexListForTransform(i, j));
bioAssemblyTrans.setMatrix(
structureDataInterface.getMatrixForTransform(i,j));
addTransform(bioassembly, structureDataInterface.getChainIndexListForTransform(i, j),
structureDataInterface.getMatrixForTransform(i, j));
}
}
return outList;
}

/**
* Add a transform to a given {@link BioAssemblyData} object.
* @param bioassembly the {@link BioAssemblyData} object
* @param chainIndices the integer list of chain indices to add
* @param transformation the list of doubles describing a transformation
*/
private static void addTransform(BioAssemblyData bioassembly, int[] chainIndices, double[] transformation) {
BioAssemblyTransformation bioAssemblyTrans = new BioAssemblyTransformation();
bioassembly.getTransformList().add(bioAssemblyTrans);
bioAssemblyTrans.setChainIndexList(chainIndices);
bioAssemblyTrans.setMatrix(transformation);
}


/**
* Generate the entity level information from the {@link StructureDataInterface}.
* @param structureDataInterface the input interface
Expand Down Expand Up @@ -194,7 +200,7 @@ public static void transferBioassembly(StructureDataInterface structureDataInter
adapterToStructureData.setBioAssemblyTrans(i,
structureDataInterface.getChainIndexListForTransform(i, j),
structureDataInterface.getMatrixForTransform(i, j),
Integer.toString(i));
structureDataInterface.getBioassemblyName(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void encode(StructureDataInterface structureDataInterface) {

// Slightly unusual thing
// Set the group map (all the unique groups in the structure).
mmtfBean.setGroupList(EncoderUtils.generateGroupMap(structureDataInterface));
mmtfBean.setGroupList(EncoderUtils.generateGroupList(structureDataInterface));
// Set the bioassembly and entity information
mmtfBean.setBioAssemblyList(EncoderUtils.generateBioassemblies(structureDataInterface));
mmtfBean.setEntityList(EncoderUtils.generateEntityList(structureDataInterface));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,9 @@ public double[][] getNcsOperatorList() {
return new double[16][16];
}

@Override
public String getBioassemblyName(int bioassemblyIndex) {
return "NA";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,9 @@ public double[][] getNcsOperatorList() {
return new double[16][16];
}

@Override
public String getBioassemblyName(int bioassemblyIndex) {
return "NA";
}

}
169 changes: 169 additions & 0 deletions mmtf-codec/src/test/java/org/rcsb/mmtf/encoder/TestEncoderUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package org.rcsb.mmtf.encoder;

import org.junit.Test;
import static org.junit.Assert.*;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.rcsb.mmtf.api.StructureAdapterInterface;
import org.rcsb.mmtf.api.StructureDataInterface;
import org.rcsb.mmtf.codec.CharCodecs;
import org.rcsb.mmtf.codec.FloatCodecs;
import org.rcsb.mmtf.codec.IntCodecs;
import org.rcsb.mmtf.codec.OptionParser;
import org.rcsb.mmtf.codec.StringCodecs;
import org.rcsb.mmtf.dataholders.BioAssemblyData;
import org.rcsb.mmtf.dataholders.BioAssemblyTransformation;
import org.rcsb.mmtf.dataholders.Entity;
import org.rcsb.mmtf.dataholders.Group;
import org.rcsb.mmtf.decoder.GenericDecoder;
import org.rcsb.mmtf.decoder.ReaderUtils;

/**
* Tests for the {@link EncoderUtils} class of static methods.
* @author Anthony Bradley
*
*/
public class TestEncoderUtils {

/**
* Test that all of the codecs can handle and empty input array.
*/
@Test
public void testEmptyArrs() {

for (FloatCodecs inputCodec : FloatCodecs.values()) {
testOutput(EncoderUtils.encodeByteArr(inputCodec, new float[] {}, 0),
inputCodec.getCodecId());
}

for (CharCodecs inputCodec : CharCodecs.values()) {
testOutput(EncoderUtils.encodeByteArr(inputCodec, new char[] {}, 0),
inputCodec.getCodecId());
}

for (IntCodecs inputCodec : IntCodecs.values()) {
testOutput(EncoderUtils.encodeByteArr(inputCodec, new int[] {}, 0),
inputCodec.getCodecId());
}

for (StringCodecs inputCodec : StringCodecs.values()) {
testOutput(EncoderUtils.encodeByteArr(inputCodec, new String[] {}, 0),
inputCodec.getCodecId());
}
}

/**
* Test that Bioassemblies can be generated correctly form a {@link StructureDataInterface}
* to a {@link StructureAdapterInterface}
*/
@Test
public void testGenerateBioassemblies() {
List<BioAssemblyData> bioAssemblyData = new ArrayList<>();
BioAssemblyData bioAssemblyOne = new BioAssemblyData("1");
bioAssemblyData.add(bioAssemblyOne);
List<BioAssemblyTransformation> bioAssemblyOneTransforms = new ArrayList<>();
BioAssemblyTransformation bioassOneTransOne = new BioAssemblyTransformation();
bioassOneTransOne.setChainIndexList(new int[]{1,2,3,4});
bioassOneTransOne.setMatrix(new double[]{1.0,2.0,3.0,4.0});
bioAssemblyOneTransforms.add(bioassOneTransOne);
BioAssemblyTransformation bioassOneTransTwo = new BioAssemblyTransformation();
bioassOneTransTwo.setChainIndexList(new int[]{5,7,11});
bioassOneTransTwo.setMatrix(new double[]{5.0,2.0,8.0,4.0});
bioAssemblyOneTransforms.add(bioassOneTransTwo);
bioAssemblyOne.setTransformList(bioAssemblyOneTransforms);
AdapterToStructureData adapterToStructureData = new AdapterToStructureData();
adapterToStructureData.initStructure(0,0,0,0,0,"DUMMY");
for (int i=0; i< bioAssemblyData.size(); i++){
for (int j=0; j< bioAssemblyData.get(i).getTransformList().size();j++)
adapterToStructureData.setBioAssemblyTrans(i,
bioAssemblyData.get(i).getTransformList().get(j).getChainIndexList(),
bioAssemblyData.get(i).getTransformList().get(j).getMatrix(),
bioAssemblyData.get(i).getName());
}
List<BioAssemblyData> generateBioass = EncoderUtils.generateBioassemblies(adapterToStructureData);
assertEquals(bioAssemblyData.get(0).getName(), generateBioass.get(0).getName());
assertArrayEquals(bioAssemblyData.get(0).getTransformList().get(0).getChainIndexList(),
generateBioass.get(0).getTransformList().get(0).getChainIndexList());
assertArrayEquals(bioAssemblyData.get(0).getTransformList().get(0).getMatrix(),
generateBioass.get(0).getTransformList().get(0).getMatrix(),0.0);
}

/**
* Test that the entity type can be retrieved from a chain index
*/
@Test
public void testGetEntityType() {
StructureDataInterface structureDataInterface = getDefaultFullData();
assertEquals(EncoderUtils.getTypeFromChainId(structureDataInterface, 0),"polymer");
assertEquals(EncoderUtils.getTypeFromChainId(structureDataInterface, 1),"non-polymer");
assertEquals(EncoderUtils.getTypeFromChainId(structureDataInterface, 2),"non-polymer");
assertEquals(EncoderUtils.getTypeFromChainId(structureDataInterface, 3),"non-polymer");
assertEquals(EncoderUtils.getTypeFromChainId(structureDataInterface, 4),"non-polymer");
assertEquals(EncoderUtils.getTypeFromChainId(structureDataInterface, 5),"water");
}

/**
* Test that the entityList can be generated correctly.
*/
@Test
public void testGenerateEntityList() {
StructureDataInterface structureDataInterface = getDefaultFullData();
Entity[] entities = EncoderUtils.generateEntityList(structureDataInterface);
assertEquals(entities.length, 4);
assertArrayEquals(entities[0].getChainIndexList(), new int[] {0});
assertArrayEquals(entities[1].getChainIndexList(), new int[] {1});
assertArrayEquals(entities[2].getChainIndexList(), new int[] {2,3,4});
assertArrayEquals(entities[3].getChainIndexList(), new int[] {5});

assertEquals(entities[0].getDescription(),"BROMODOMAIN ADJACENT TO ZINC FINGER DOMAIN PROTEIN 2B");
assertEquals(entities[1].getDescription(),"4-FLUOROBENZAMIDOXIME");
assertEquals(entities[2].getDescription(),"METHANOL");
assertEquals(entities[3].getDescription(),"water");


assertEquals(entities[0].getSequence(),"SMSVKKPKRDDSKDLALCSMILTEMETHEDAWPFLLPVNLKLVPGYKKVIKKPMDFSTIREKLSSGQYPNLETFALDVRLVFDNCETFNEDDSDIGRAGHNMRKYFEKKWTDTFKVS");
assertEquals(entities[1].getSequence(),"");
assertEquals(entities[2].getSequence(),"");
assertEquals(entities[3].getSequence(),"");

assertEquals(entities[0].getType(),"polymer");
assertEquals(entities[1].getType(),"non-polymer");
assertEquals(entities[2].getType(),"non-polymer");
assertEquals(entities[3].getType(),"water");

}

/**
* Test that the groupList can be generated correctly
*/
@Test
public void testGenerateGroupMap() {
StructureDataInterface structureDataInterface = getDefaultFullData();
Group[] groupList = EncoderUtils.generateGroupList(structureDataInterface);
assertEquals(groupList.length, 29);
}

/**
* Get the default data for the full format.
* @return a {@link StructureDataInterface} for the full data.
*/
private StructureDataInterface getDefaultFullData() {
ClassLoader classLoader = getClass().getClassLoader();
Path inFile = Paths.get(classLoader.getResource("mmtf/4cup.mmtf").getFile());
try {
return new GenericDecoder(ReaderUtils.getDataFromFile(inFile));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
}

private void testOutput(byte[] encodeByteArr, int codecId) {
assertArrayEquals(encodeByteArr, new OptionParser(codecId, 0, 0).getHeader());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.rcsb.mmtf.dataholders;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -23,6 +24,22 @@ public class BioAssemblyData implements Serializable {
/** The name of the Bioassembly. Can be user defined. */
private String name;

/**
* Constructor setting the name and initialising an empty transform list.
* @param name the name of this {@link BioAssemblyData} object
*/
public BioAssemblyData(String name) {
transformList = new ArrayList<BioAssemblyTransformation>();
this.name = name;
}

/**
* Constructor without setting the name.
*/
public BioAssemblyData() {
transformList = new ArrayList<BioAssemblyTransformation>();
}

/**
* Gets the list of transforms.
*
Expand Down

0 comments on commit 6985a00

Please sign in to comment.