Skip to content

Commit c2a3294

Browse files
committed
Refactored function names in MMTFActions
Added new function to read from a URL
1 parent 789765a commit c2a3294

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

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

1717
public static void main(String[] args) throws IOException, StructureException {
18-
Structure structure = MmtfActions.readBiojavaStruct("/path/to/file");
18+
Structure structure = MmtfActions.readFromFile("/path/to/file");
1919
System.out.println(structure.getChains().size());
2020
}
2121

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-
MmtfActions.writeBiojavaStruct(structure, "/tmp/4cup.mmtf");
16+
MmtfActions.writeToFile(structure, "/tmp/4cup.mmtf");
1717
}
1818

1919

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
public class MmtfActions {
1818

1919
/**
20-
* Utility function to get a Biojava structure from a byte array.
20+
* Utility function to get a Biojava structure from a file.
2121
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
2222
* @return a Biojava structure object relating to the input byte array.
2323
* @throws IOException
2424
*/
25-
public static Structure readBiojavaStruct(String filePath) throws IOException {
25+
public static Structure readFromFile(String filePath) throws IOException {
2626
// Get the reader - this is the bit that people need to implement.
2727
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
2828
// Do the inflation
@@ -37,7 +37,7 @@ public static Structure readBiojavaStruct(String filePath) throws IOException {
3737
* @param path the full path of the file to write
3838
* @throws IOException
3939
*/
40-
public static void writeBiojavaStruct(Structure structure, String path) throws IOException {
40+
public static void writeToFile(Structure structure, String path) throws IOException {
4141
// Set up this writer
4242
WriterToEncoder writerToEncoder = new WriterToEncoder();
4343
// Get the writer - this is what people implement
@@ -46,4 +46,19 @@ public static void writeBiojavaStruct(Structure structure, String path) throws I
4646
WriterUtils.writeDataToFile(writerToEncoder, path);
4747
}
4848

49+
50+
/**
51+
* Utility function to get a Biojava structure from the REST service.
52+
* @param pdbId the PDB code of the required structure
53+
* @return a Biojava structure object relating to the input byte array
54+
* @throws IOException
55+
*/
56+
public static Structure readFromWeb(String pdbId) throws IOException {
57+
// Get the reader - this is the bit that people need to implement.
58+
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
59+
// Do the inflation
60+
new DecoderToReader(new DefaultDecoder(ReaderUtils.getDataFromUrl(pdbId)), mmtfStructureReader);
61+
// Get the structue
62+
return mmtfStructureReader.getStructure();
63+
}
4964
}

0 commit comments

Comments
 (0)