Skip to content

Commit aaf33b0

Browse files
committed
Updates to Biojava to remove any mention of the Messagepack serializer /deserializer
1 parent cb1bc5e commit aaf33b0

File tree

6 files changed

+22
-185
lines changed

6 files changed

+22
-185
lines changed

biojava-structure/src/main/java/demo/DemoMmtfReader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
public class DemoMmtfReader {
1616

1717
public static void main(String[] args) throws IOException, StructureException {
18-
MmtfUtils.setUpBioJava();
19-
Structure structure = MmtfActions.getBiojavaStruct("4cup");
18+
Structure structure = MmtfActions.readBiojavaStruct("/path/to/file");
2019
System.out.println(structure.getChains().size());
2120
}
2221

biojava-structure/src/main/java/demo/DemoMmtfRoundTrip.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

biojava-structure/src/main/java/demo/DemoMmtfWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public class DemoMmtfWriter {
1313
public static void main(String[] args) throws IOException, StructureException {
1414
MmtfUtils.setUpBioJava();
1515
Structure structure = StructureIO.getStructure("4cup");
16-
// TODO write the byte array to a file
17-
MmtfActions.getByteArray(structure);
16+
MmtfActions.writeBiojavaStruct(structure, "/tmp/4cup.mmtf");
1817
}
1918

2019

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfActions.java

Lines changed: 19 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -3,144 +3,51 @@
33
import java.io.IOException;
44

55
import org.biojava.nbio.structure.Structure;
6-
import org.biojava.nbio.structure.StructureException;
7-
import org.biojava.nbio.structure.StructureIO;
8-
import org.rcsb.mmtf.api.MmtfDecodedDataInterface;
9-
import org.rcsb.mmtf.dataholders.MmtfBean;
106
import org.rcsb.mmtf.decoder.BeanToDataApi;
117
import org.rcsb.mmtf.decoder.DataApiToReader;
12-
import org.rcsb.mmtf.deserializers.MessagePackDeserializer;
13-
import org.rcsb.mmtf.encoder.DataApiToBean;
8+
import org.rcsb.mmtf.decoder.ReaderUtils;
149
import org.rcsb.mmtf.encoder.WriterToDataApi;
15-
import org.rcsb.mmtf.serializers.MessagePackSerializer;
16-
import org.rcsb.mmtf.utils.DownloadUtils;
10+
import org.rcsb.mmtf.encoder.WriterUtils;
1711

12+
/**
13+
* A class of functions for reading and writing Biojava structures using MMTF
14+
* @author Anthony Bradley
15+
*
16+
*/
1817
public class MmtfActions {
19-
20-
/**
21-
* Utility function to get a Biojava structure from a PDB code.
22-
* @param pdbCode the pdb code of the structure you desire
23-
* @return a Biojava structure object relating to the input PDB code
24-
* @throws IOException
25-
*/
26-
public static Structure getBiojavaStruct(String pdbCode) throws IOException {
27-
return getBiojavaStruct(DownloadUtils.getDataFromUrl(pdbCode));
28-
}
2918

3019
/**
3120
* Utility function to get a Biojava structure from a byte array.
3221
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
3322
* @return a Biojava structure object relating to the input byte array.
3423
* @throws IOException
3524
*/
36-
public static Structure getBiojavaStruct(byte[] inputByteArray) throws IOException {
25+
public static Structure readBiojavaStruct(String filePath) throws IOException {
3726
// Get the reader - this is the bit that people need to implement.
3827
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
39-
// Set up the deserializer
40-
MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer();
41-
// Get the data
42-
MmtfBean mmtfBean = messagePackDeserializer.deserialize(inputByteArray);
43-
// Set up the data API
44-
BeanToDataApi beanToGet = new BeanToDataApi(mmtfBean);
4528
// Set up the inflator
4629
DataApiToReader getToInflator = new DataApiToReader();
4730
// Do the inflation
48-
getToInflator.read(beanToGet, mmtfStructureReader);
31+
getToInflator.read(new BeanToDataApi(ReaderUtils.getDataFromFile(filePath)), mmtfStructureReader);
4932
// Get the structue
5033
return mmtfStructureReader.getStructure();
5134
}
52-
53-
/**
54-
* Get the byte array (messagepack encoded) of the PDB code you desire.
55-
* @param pdbId the input PDB id for the structure you want
56-
* @return the byte array of the structure compressed and message pack encoded
57-
* @throws IOException
58-
* @throws StructureException
59-
*/
60-
public static byte[] getByteArray(String pdbId) throws IOException, StructureException {
61-
MmtfUtils.setUpBioJava();
62-
return getByteArray(StructureIO.getStructure(pdbId));
63-
}
64-
65-
/**
66-
* Utility function to get a byte array from a Biojava structure.
67-
* @param structure the input Biojava structure object
68-
* @return the byte array of the structure compressed and message pack encoded
69-
* @throws IOException
70-
*/
71-
public static byte[] getByteArray(Structure structure) throws IOException {
72-
MessagePackSerializer messagePackSerializer = new MessagePackSerializer();
73-
return messagePackSerializer.serialize(getBean(structure));
74-
}
75-
76-
/**
77-
* Utility function to get an mmtf bean from a Biojava structure.
78-
* @param structure the input Biojava structure object
79-
* @return the raw (compressed) data as an MmtfBean object
80-
* @throws IOException
81-
*/
82-
public static MmtfBean getBean(Structure structure) throws IOException {
83-
// Get to bean
84-
DataApiToBean getToBean = new DataApiToBean(getApi(structure));
85-
return getToBean.getMmtfBean();
86-
}
8735

8836
/**
89-
* Utility function to get an mmtf bean from a PDB id.
90-
* @param pdbId the input PDB id for the structure you want
91-
* @return the byte array of the structure compressed and message pack encoded
92-
* @throws IOException
93-
* @throws StructureException
94-
*/
95-
public static MmtfBean getBean(String pdbId) throws IOException, StructureException {
96-
// Get to bean
97-
DataApiToBean getToBean = new DataApiToBean(getApi(pdbId));
98-
return getToBean.getMmtfBean();
99-
}
100-
101-
/**
102-
* Utility function to get an API to the data from a Biojava structure
103-
* @param structure the input Biojava structure object
104-
* @return the API to the data in the form of an MmtfDecodedDataInterface
105-
* @throws IOException
37+
* Utility function to write a Biojava structure object to a path.
38+
* @param structure the structure to write
39+
* @param path the full path of the file to write
40+
* @throws IOException
10641
*/
107-
public static MmtfDecodedDataInterface getApi(Structure structure) throws IOException {
108-
// Set up the transform from the inflator to the get api
42+
public static void writeBiojavaStruct(Structure structure, String path) throws IOException {
43+
// Set up this writer
10944
WriterToDataApi inflatorToGet = new WriterToDataApi();
11045
// Get the writer - this is what people implement
11146
MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure);
112-
// Now deflate
47+
// Now pass to the get API
11348
mmtfStructureWriter.write(inflatorToGet);
114-
// Return the API
115-
return inflatorToGet;
49+
// Now write this dat to file
50+
WriterUtils.writeDataToFile(inflatorToGet, path);
11651
}
11752

118-
/**
119-
* Utility function to get an API to the data from a PDB code.
120-
* @param pdbId the input PDB id for the structure you want
121-
* @return the API to the data in the form of an MmtfDecodedDataInterface
122-
* @throws IOException
123-
* @throws StructureException
124-
*/
125-
public static MmtfDecodedDataInterface getApi(String pdbId) throws IOException, StructureException {
126-
// Set up the transform from the inflator to the get api
127-
WriterToDataApi inflatorToGet = new WriterToDataApi();
128-
// Get the writer - this is what people implement
129-
MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(
130-
StructureIO.getStructure(pdbId));
131-
// Now deflate
132-
mmtfStructureWriter.write(inflatorToGet);
133-
// Get to bean
134-
return inflatorToGet;
135-
}
136-
137-
/**
138-
* Round trip a given structure. Mainly for testing purposes.
139-
* @param structure the input Biojava structure object
140-
* @return the round tripped structure (conversion to messge pack mmtf and back).
141-
* @throws IOException
142-
*/
143-
public static Structure roundTrip(Structure structure) throws IOException {
144-
return getBiojavaStruct(getByteArray(structure));
145-
}
146-
}
53+
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void write(MmtfDecoderInterface decoder) {
5555
PDBHeader pdbHeader = structure.getPDBHeader();
5656
PDBCrystallographicInfo xtalInfo = pdbHeader.getCrystallographicInfo();
5757
// TODO Get release date information
58-
String releaseDate = "";
58+
String releaseDate = "NA";
5959
mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(), 1.0f, pdbHeader.getResolution(), pdbHeader.getTitle(), MmtfUtils.dateToIsoString(pdbHeader.getDepDate()),
6060
releaseDate, MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques()));
6161
mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()), MmtfUtils.getUnitCellAsArray(xtalInfo));

biojava-structure/src/test/java/org/biojava/nbio/structure/mmtf/TestMmtfParser.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)