Skip to content

Commit 63ebeed

Browse files
committed
Some refactoring and docs
1 parent 68ccb69 commit 63ebeed

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package demo;
22

33
import java.io.IOException;
4+
import java.nio.file.Paths;
45

56
import org.biojava.nbio.structure.Structure;
67
import org.biojava.nbio.structure.StructureException;
@@ -13,7 +14,7 @@ public class DemoMmtfWriter {
1314
public static void main(String[] args) throws IOException, StructureException {
1415
MmtfUtils.setUpBioJava();
1516
Structure structure = StructureIO.getStructure("4cup");
16-
MmtfActions.writeToFile(structure, "/tmp/4cup.mmtf");
17+
MmtfActions.writeToFile(structure, Paths.get("/tmp/4cup.mmtf"));
1718
}
1819

1920

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.biojava.nbio.structure.io.mmtf;
22

33
import java.io.IOException;
4+
import java.nio.file.Path;
45

56
import org.biojava.nbio.structure.Structure;
67
import org.rcsb.mmtf.decoder.DefaultDecoder;
@@ -17,12 +18,12 @@
1718
public class MmtfActions {
1819

1920
/**
20-
* Utility function to get a Biojava structure from a file.
21-
* @param inputByteArray Must be uncompressed (i.e. with entropy compression methods like gzip)
22-
* @return a Biojava structure object relating to the input byte array.
21+
* Utility function to get a Structure object from a mmtf file.
22+
* @param filePath the mmtf file
23+
* @return a Structure object relating to the input byte array.
2324
* @throws IOException
2425
*/
25-
public static Structure readFromFile(String filePath) throws IOException {
26+
public static Structure readFromFile(Path filePath) throws IOException {
2627
// Get the reader - this is the bit that people need to implement.
2728
MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
2829
// Do the inflation
@@ -32,12 +33,12 @@ public static Structure readFromFile(String filePath) throws IOException {
3233
}
3334

3435
/**
35-
* Utility function to write a Biojava structure object to a path.
36-
* @param structure the structure to write
37-
* @param path the full path of the file to write
36+
* Utility function to write a Structure object to a file.
37+
* @param structure the Structure to write
38+
* @param path the file to write
3839
* @throws IOException
3940
*/
40-
public static void writeToFile(Structure structure, String path) throws IOException {
41+
public static void writeToFile(Structure structure, Path path) throws IOException {
4142
// Set up this writer
4243
WriterToEncoder writerToEncoder = new WriterToEncoder();
4344
// Get the writer - this is what people implement
@@ -48,9 +49,9 @@ public static void writeToFile(Structure structure, String path) throws IOExcept
4849

4950

5051
/**
51-
* Utility function to get a Biojava structure from the REST service.
52+
* Utility function to get a Biojava structure from the mmtf REST service.
5253
* @param pdbId the PDB code of the required structure
53-
* @return a Biojava structure object relating to the input byte array
54+
* @return a Structure object relating to the input byte array
5455
* @throws IOException
5556
*/
5657
public static Structure readFromWeb(String pdbId) throws IOException {

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBasicMmtf.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.File;
66
import java.io.IOException;
7+
import java.nio.file.Paths;
78
import java.util.ArrayList;
89

910
import org.biojava.nbio.structure.AminoAcidImpl;
@@ -43,7 +44,7 @@ public class TestBasicMmtf {
4344
@Test
4445
public void testRead() throws IOException {
4546
ClassLoader classLoader = getClass().getClassLoader();
46-
Structure structure = MmtfActions.readFromFile((classLoader.getResource("org/biojava/nbio/structure/io/mmtf/4CUP.mmtf").getPath()));
47+
Structure structure = MmtfActions.readFromFile((Paths.get(classLoader.getResource("org/biojava/nbio/structure/io/mmtf/4CUP.mmtf").getPath())));
4748
assertEquals(structure.getPDBCode(),"4CUP");
4849
assertEquals(structure.getChains().size(),6);
4950
}
@@ -74,6 +75,6 @@ public void testWrite() throws IOException {
7475
group.setResidueNumber(residueNumber);
7576
structure.addChain(chain);
7677
File tempFile = testFolder.newFile("tmpfile");
77-
MmtfActions.writeToFile(structure, tempFile.getAbsolutePath());
78+
MmtfActions.writeToFile(structure, tempFile.toPath());
7879
}
7980
}

0 commit comments

Comments
 (0)