Skip to content

Commit adc0709

Browse files
committed
Updates and documentation to the MmtfActions class.
MmtfReader now will download the file. MmtfWriter still needs to write byte[]
1 parent 84e583a commit adc0709

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
import java.io.IOException;
44

5+
import org.biojava.nbio.structure.Structure;
56
import org.biojava.nbio.structure.StructureException;
67
import org.biojava.nbio.structure.io.mmtf.MmtfActions;
78
import org.biojava.nbio.structure.io.mmtf.MmtfUtils;
89

10+
/**
11+
* Class to show how to read a Biojava structure using MMTF
12+
* @author Anthony Bradley
13+
*
14+
*/
915
public class DemoMmtfReader {
1016

1117
public static void main(String[] args) throws IOException, StructureException {
1218
MmtfUtils.setUpBioJava();
13-
// TODO Read in the byte array
14-
byte[] inputByteArray = new byte[0];
15-
MmtfActions.getBiojavaStruct(inputByteArray);
19+
Structure structure = MmtfActions.getBiojavaStruct("4cup");
20+
System.out.println(structure.getChains().size());
1621
}
1722

1823
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +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-
// We can do somme comparisons on the round tripped structure
16+
// TODO write the byte array to a file
1717
MmtfActions.getByteArray(structure);
1818
}
1919

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
import org.rcsb.mmtf.encoder.DataApiToBean;
1414
import org.rcsb.mmtf.encoder.WriterToDataApi;
1515
import org.rcsb.mmtf.serializers.MessagePackSerializer;
16+
import org.rcsb.mmtf.utils.DownloadUtils;
1617

1718
public class MmtfActions {
1819

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+
}
29+
1930
/**
2031
* Utility function to get a Biojava structure from a byte array.
2132
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
22-
* @param parsingParams
23-
* @return
33+
* @return a Biojava structure object relating to the input byte array.
2434
* @throws IOException
2535
*/
2636
public static Structure getBiojavaStruct(byte[] inputByteArray) throws IOException {
@@ -41,9 +51,9 @@ public static Structure getBiojavaStruct(byte[] inputByteArray) throws IOExcepti
4151
}
4252

4353
/**
44-
*
45-
* @param pdbId
46-
* @return
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
4757
* @throws IOException
4858
* @throws StructureException
4959
*/
@@ -53,10 +63,9 @@ public static byte[] getByteArray(String pdbId) throws IOException, StructureExc
5363
}
5464

5565
/**
56-
* Utility function to get a byte array from a Biojava structure
57-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
58-
* @param parsingParams
59-
* @return
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
6069
* @throws IOException
6170
*/
6271
public static byte[] getByteArray(Structure structure) throws IOException {
@@ -65,10 +74,9 @@ public static byte[] getByteArray(Structure structure) throws IOException {
6574
}
6675

6776
/**
68-
* Utility function to get an mmtf bean from a Biojava structure
69-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
70-
* @param parsingParams
71-
* @return
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
7280
* @throws IOException
7381
*/
7482
public static MmtfBean getBean(Structure structure) throws IOException {
@@ -78,10 +86,9 @@ public static MmtfBean getBean(Structure structure) throws IOException {
7886
}
7987

8088
/**
81-
* Utility function to get an mmtf bean from a Biojava structure
82-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
83-
* @param parsingParams
84-
* @return
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
8592
* @throws IOException
8693
* @throws StructureException
8794
*/
@@ -92,10 +99,9 @@ public static MmtfBean getBean(String pdbId) throws IOException, StructureExcept
9299
}
93100

94101
/**
95-
* Utility function to get an mmtf bean from a Biojava structure
96-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
97-
* @param parsingParams
98-
* @return
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
99105
* @throws IOException
100106
*/
101107
public static MmtfDecodedDataInterface getApi(Structure structure) throws IOException {
@@ -110,10 +116,9 @@ public static MmtfDecodedDataInterface getApi(Structure structure) throws IOExce
110116
}
111117

112118
/**
113-
* Utility function to get an mmtf bean from a Biojava structure
114-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
115-
* @param parsingParams
116-
* @return
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
117122
* @throws IOException
118123
* @throws StructureException
119124
*/
@@ -130,8 +135,8 @@ public static MmtfDecodedDataInterface getApi(String pdbId) throws IOException,
130135
}
131136

132137
/**
133-
* Round trip a given structure. Mainly for testing purposes
134-
* @param structure the input structure
138+
* Round trip a given structure. Mainly for testing purposes.
139+
* @param structure the input Biojava structure object
135140
* @return the round tripped structure (conversion to messge pack mmtf and back).
136141
* @throws IOException
137142
*/

0 commit comments

Comments
 (0)