Skip to content

Commit 81eb1a1

Browse files
committed
Updates to the Demos so they are mains.
Moving the reader, writer and round tripper to utils clas
1 parent ffbb72d commit 81eb1a1

File tree

4 files changed

+100
-85
lines changed

4 files changed

+100
-85
lines changed

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

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,17 @@
22

33
import java.io.IOException;
44

5-
import org.biojava.nbio.structure.Structure;
6-
import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader;
7-
import org.rcsb.mmtf.dataholders.MmtfBean;
8-
import org.rcsb.mmtf.decoder.BeanToGet;
9-
import org.rcsb.mmtf.decoder.GetToInflator;
10-
import org.rcsb.mmtf.deserializers.MessagePackDeserializer;
5+
import org.biojava.nbio.structure.StructureException;
6+
import org.biojava.nbio.structure.io.mmtf.MmtfActions;
7+
import org.biojava.nbio.structure.io.mmtf.MmtfUtils;
118

129
public class DemoMmtfReader {
1310

14-
/**
15-
* Utility function to get a Biojava structure from a byte array.
16-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
17-
* @param parsingParams
18-
* @return
19-
* @throws IOException
20-
*/
21-
public static Structure getBiojavaStruct(byte[] inputByteArray) throws IOException {
22-
// Get the reader - this is the bit that people need to implement.
23-
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
24-
// Set up the deserializer
25-
MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer();
26-
// Get the data
27-
MmtfBean mmtfBean = messagePackDeserializer.deserialize(inputByteArray);
28-
// Set up the data API
29-
BeanToGet beanToGet = new BeanToGet(mmtfBean);
30-
// Set up the inflator
31-
GetToInflator getToInflator = new GetToInflator();
32-
// Do the inflation
33-
getToInflator.read(beanToGet, mmtfStructureReader);
34-
// Get the structue
35-
return mmtfStructureReader.getStructure();
11+
public static void main(String[] args) throws IOException, StructureException {
12+
MmtfUtils.setUpBioJava();
13+
// TODO Read in the byte array
14+
byte[] inputByteArray = new byte[0];
15+
MmtfActions.getBiojavaStruct(inputByteArray);
3616
}
17+
3718
}

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

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

55
import org.biojava.nbio.structure.Structure;
6-
import org.biojava.nbio.structure.io.mmtf.MmtfStructureReader;
7-
import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter;
8-
import org.rcsb.mmtf.dataholders.MmtfBean;
9-
import org.rcsb.mmtf.decoder.BeanToGet;
10-
import org.rcsb.mmtf.decoder.GetToInflator;
11-
import org.rcsb.mmtf.deserializers.MessagePackDeserializer;
12-
import org.rcsb.mmtf.encoder.GetToBean;
13-
import org.rcsb.mmtf.encoder.InflatorToGet;
14-
import org.rcsb.mmtf.serializers.MessagePackSerializer;
6+
import org.biojava.nbio.structure.StructureException;
7+
import org.biojava.nbio.structure.StructureIO;
8+
import org.biojava.nbio.structure.io.mmtf.MmtfActions;
9+
import org.biojava.nbio.structure.io.mmtf.MmtfUtils;
1510

1611
public class DemoMmtfRoundTrip {
1712

18-
public static Structure roundTrip(Structure structure) throws IOException {
19-
// Set up the transform from the inflator to the get api
20-
InflatorToGet inflatorToGet = new InflatorToGet();
21-
// Get the writer - this is what people implement
22-
MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure);
23-
// Do thte inflation
24-
mmtfStructureWriter.write(inflatorToGet);
25-
// Get the bean
26-
GetToBean getToBean = new GetToBean(inflatorToGet);
27-
// Serialize
28-
MessagePackSerializer messagePackSerializer = new MessagePackSerializer();
29-
byte[] byteArr = messagePackSerializer.serialize(getToBean.getMmtfBean());
30-
// Get the reader - this is the bit that people need to implement.
31-
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
32-
// Set up the deserializer
33-
MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer();
34-
// Get the data
35-
MmtfBean mmtfBean = messagePackDeserializer.deserialize(byteArr);
36-
// Set up the data API
37-
BeanToGet beanToGet = new BeanToGet(mmtfBean);
38-
// Set up the inflator
39-
GetToInflator getToInflator = new GetToInflator();
40-
// Do the inflation
41-
getToInflator.read(beanToGet, mmtfStructureReader);
42-
// Get the structue
43-
return mmtfStructureReader.getStructure();
13+
public static void main(String[] args) throws IOException, StructureException {
14+
MmtfUtils.setUpBioJava();
15+
Structure structure = StructureIO.getStructure("4cup");
16+
// We can do somme comparisons on the round tripped structure
17+
MmtfActions.roundTrip(structure);
4418
}
19+
20+
4521
}

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

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

55
import org.biojava.nbio.structure.Structure;
6-
import org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter;
7-
import org.rcsb.mmtf.encoder.GetToBean;
8-
import org.rcsb.mmtf.encoder.InflatorToGet;
9-
import org.rcsb.mmtf.serializers.MessagePackSerializer;
6+
import org.biojava.nbio.structure.StructureException;
7+
import org.biojava.nbio.structure.StructureIO;
8+
import org.biojava.nbio.structure.io.mmtf.MmtfActions;
9+
import org.biojava.nbio.structure.io.mmtf.MmtfUtils;
1010

1111
public class DemoMmtfWriter {
1212

13-
/**
14-
* Utility function to get a byte array from a Biojava structure
15-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
16-
* @param parsingParams
17-
* @return
18-
* @throws IOException
19-
*/
20-
public static byte[] getByteArray(Structure structure) throws IOException {
21-
// Set up the transform from the inflator to the get api
22-
InflatorToGet inflatorToGet = new InflatorToGet();
23-
// Get the writer - this is what people implement
24-
MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure);
25-
// Now deflate
26-
mmtfStructureWriter.write(inflatorToGet);
27-
// Get to bean
28-
GetToBean getToBean = new GetToBean(inflatorToGet);
29-
MessagePackSerializer messagePackSerializer = new MessagePackSerializer();
30-
return messagePackSerializer.serialize(getToBean.getMmtfBean());
13+
public static void main(String[] args) throws IOException, StructureException {
14+
MmtfUtils.setUpBioJava();
15+
Structure structure = StructureIO.getStructure("4cup");
16+
// We can do somme comparisons on the round tripped structure
17+
MmtfActions.getByteArray(structure);
3118
}
19+
20+
3221
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.biojava.nbio.structure.io.mmtf;
2+
3+
import java.io.IOException;
4+
5+
import org.biojava.nbio.structure.Structure;
6+
import org.rcsb.mmtf.dataholders.MmtfBean;
7+
import org.rcsb.mmtf.decoder.BeanToGet;
8+
import org.rcsb.mmtf.decoder.GetToInflator;
9+
import org.rcsb.mmtf.deserializers.MessagePackDeserializer;
10+
import org.rcsb.mmtf.encoder.GetToBean;
11+
import org.rcsb.mmtf.encoder.InflatorToGet;
12+
import org.rcsb.mmtf.serializers.MessagePackSerializer;
13+
14+
public class MmtfActions {
15+
16+
/**
17+
* Utility function to get a Biojava structure from a byte array.
18+
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
19+
* @param parsingParams
20+
* @return
21+
* @throws IOException
22+
*/
23+
public static Structure getBiojavaStruct(byte[] inputByteArray) throws IOException {
24+
// Get the reader - this is the bit that people need to implement.
25+
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
26+
// Set up the deserializer
27+
MessagePackDeserializer messagePackDeserializer = new MessagePackDeserializer();
28+
// Get the data
29+
MmtfBean mmtfBean = messagePackDeserializer.deserialize(inputByteArray);
30+
// Set up the data API
31+
BeanToGet beanToGet = new BeanToGet(mmtfBean);
32+
// Set up the inflator
33+
GetToInflator getToInflator = new GetToInflator();
34+
// Do the inflation
35+
getToInflator.read(beanToGet, mmtfStructureReader);
36+
// Get the structue
37+
return mmtfStructureReader.getStructure();
38+
}
39+
40+
/**
41+
* Utility function to get a byte array from a Biojava structure
42+
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
43+
* @param parsingParams
44+
* @return
45+
* @throws IOException
46+
*/
47+
public static byte[] getByteArray(Structure structure) throws IOException {
48+
// Set up the transform from the inflator to the get api
49+
InflatorToGet inflatorToGet = new InflatorToGet();
50+
// Get the writer - this is what people implement
51+
MmtfStructureWriter mmtfStructureWriter = new MmtfStructureWriter(structure);
52+
// Now deflate
53+
mmtfStructureWriter.write(inflatorToGet);
54+
// Get to bean
55+
GetToBean getToBean = new GetToBean(inflatorToGet);
56+
MessagePackSerializer messagePackSerializer = new MessagePackSerializer();
57+
return messagePackSerializer.serialize(getToBean.getMmtfBean());
58+
}
59+
60+
/**
61+
*
62+
* @param structure
63+
* @return
64+
* @throws IOException
65+
*/
66+
public static Structure roundTrip(Structure structure) throws IOException {
67+
return getBiojavaStruct(getByteArray(structure));
68+
}
69+
}

0 commit comments

Comments
 (0)