-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from aehrc/load_vcf_bgz
Load bgzipped VCF files
- Loading branch information
Showing
2 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package au.csiro.variantspark.utils; | ||
|
||
import java.io.*; | ||
import java.util.zip.GZIPInputStream; | ||
import java.io.IOException; | ||
import htsjdk.samtools.util.BlockCompressedInputStream; | ||
|
||
public class FileUtils { | ||
|
||
/** | ||
* | ||
* @param file: an input file | ||
* @return true if input file is BGZIP by check the first two byte of input file | ||
*/ | ||
public static boolean isBGZFile(String filePath) { | ||
/** | ||
* .vcf.bgz is type of GZP file, work well with BlockCompressedInputStream | ||
* .vcf.gz is also GZP file but get java.lang.OutOfMemoryError at java.io.InputStreamReader.read(InputStreamReader.java:184) | ||
* .vcf.bz2 is not GZP file and get java.lang.OutOfMemoryError at java.io.InputStreamReader.read(InputStreamReader.java:184) | ||
* .vcf is not GZP file and get htsjdk.samtools.SAMFormatException: at header from java.io.BufferedReader.readLine(BufferedReader.java:389) | ||
*/ | ||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(filePath))) { | ||
boolean isValid = BlockCompressedInputStream.isValidFile(bufferedInputStream); | ||
return isValid; | ||
} catch (IOException e) { | ||
//handle exception for non proper bgzip file | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters