-
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.
DEV: Integrate bgzipped file support in VCF import API (#237)
* .bgz loader function implemented by Christina
- Loading branch information
1 parent
279bd5b
commit 5ad8cc0
Showing
3 changed files
with
33 additions
and
4 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
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
26 changes: 26 additions & 0 deletions
26
src/main/scala/au/csiro/variantspark/utils/BGZLoader.scala
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,26 @@ | ||
package au.csiro.variantspark.utils | ||
|
||
import au.csiro.pbdava.ssparkle.spark.SparkApp | ||
import org.apache.spark.rdd.RDD | ||
import htsjdk.samtools.util.BlockCompressedInputStream | ||
import org.apache.hadoop.fs.Path | ||
import org.apache.spark.SparkContext | ||
|
||
object BGZLoader { | ||
def textFile(sc: SparkContext, inputFile: String): RDD[String] = { | ||
val isBGZ = FileUtils.isBGZFile(inputFile) | ||
println(inputFile + " is loading to spark RDD, isBGZFile: " + isBGZ) | ||
if (isBGZ) { | ||
// BGZIP file is compressed as blocks, requires specialized libraries htsjdk | ||
val path = new Path(inputFile) | ||
val fs = path.getFileSystem(sc.hadoopConfiguration) | ||
val bgzInputStream = new BlockCompressedInputStream(fs.open(path)) | ||
// each blocks can be decompressed independently and to be read in parallel | ||
sc.parallelize(Stream.continually(bgzInputStream.readLine()).takeWhile(_ != null).toList) | ||
} else { | ||
// The standard GZIP libraries can handle files compressed as a whole | ||
// load .vcf, .vcf.gz or .vcf.bz2 to RDD | ||
sc.textFile(inputFile) | ||
} | ||
} | ||
} |