Skip to content

Commit bce7fed

Browse files
committed
A class to download .2bit file
1 parent 3cefc3f commit bce7fed

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/twobit/SimpleTwoBitFileProvider.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.biojava.nbio.genome.parsers.twobit;
22

3+
import org.biojava.nbio.core.util.FileDownloadUtils;
4+
35
import java.io.File;
6+
import java.io.IOException;
47
import java.net.MalformedURLException;
58
import java.net.URL;
69

@@ -9,19 +12,19 @@
912
*/
1013
public class SimpleTwoBitFileProvider {
1114

12-
private File twoBitFileLocalLocation;
13-
private String genomeAssembly;
14-
15-
public SimpleTwoBitFileProvider(File twoBitFileLocalLocation, String genomeAssembly) throws MalformedURLException {
16-
17-
this.twoBitFileLocalLocation = twoBitFileLocalLocation;
18-
this.genomeAssembly = genomeAssembly;
15+
public static void downloadIfNoTwoBitFileExists(File twoBitFileLocalLocation, String genomeAssembly) throws IOException {
1916

2017
if ( ! twoBitFileLocalLocation.exists() ) {
2118

19+
// download to a temporary file
20+
File tmp = File.createTempFile("",".2bit");
2221
URL twoBitFileURL = getTwoBitURL(genomeAssembly);
2322

23+
// 2bit files are large and take a while to download
24+
FileDownloadUtils.downloadFile(twoBitFileURL, tmp);
2425

26+
// after the download rename
27+
tmp.renameTo(twoBitFileLocalLocation);
2528

2629
}
2730
}

0 commit comments

Comments
 (0)