Skip to content

Commit 129a0a1

Browse files
authored
Merge pull request #890 from jean-philippe-martin/jp_gff3reader_overload
Add GFF3Reader overload that accepts Path
2 parents b9519e4 + f8148e9 commit 129a0a1

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

  • biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff

biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/GFF3Reader.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
*/
2121
package org.biojava.nbio.genome.parsers.gff;
2222

23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.nio.file.Paths;
2326
import org.slf4j.Logger;
2427
import org.slf4j.LoggerFactory;
2528

2629
import java.io.BufferedReader;
27-
import java.io.FileReader;
2830
import java.io.IOException;
2931
import java.util.ArrayList;
3032
import java.util.List;
@@ -65,13 +67,23 @@ public class GFF3Reader {
6567
* @return A FeatureList.
6668
* @throws IOException Something went wrong -- check exception detail message.
6769
*/
68-
6970
public static FeatureList read(String filename, List<String> indexes) throws IOException {
70-
logger.info("Reading: {}", filename);
71+
return read(Paths.get(filename), indexes);
72+
}
73+
74+
/**
75+
* Read a file into a FeatureList. Each line of the file becomes one Feature object.
76+
*
77+
* @param path The path to the GFF file.
78+
* @return A FeatureList.
79+
* @throws IOException Something went wrong -- check exception detail message.
80+
*/
81+
public static FeatureList read(Path path, List<String> indexes) throws IOException {
82+
logger.info("Reading: {}", path.toString());
7183

7284
FeatureList features = new FeatureList();
7385
features.addIndexes(indexes);
74-
BufferedReader br = new BufferedReader(new FileReader(filename));
86+
BufferedReader br = Files.newBufferedReader(path);
7587

7688
String s;
7789
for (s = br.readLine(); null != s; s = br.readLine()) {
@@ -103,6 +115,10 @@ public static FeatureList read(String filename) throws IOException {
103115
return read(filename,new ArrayList<String>(0));
104116
}
105117

118+
public static FeatureList read(Path path) throws IOException {
119+
return read(path,new ArrayList<String>(0));
120+
}
121+
106122

107123
/**
108124
* create Feature from line of GFF file

0 commit comments

Comments
 (0)