au.csiro.variantspark.output.CSVFeatureSink2.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of variant-spark_2.11 Show documentation
Show all versions of variant-spark_2.11 Show documentation
Genomic variants interpretation toolkit
The newest version!
package au.csiro.variantspark.output
import au.csiro.variantspark.input.FeatureSource
/**
* This only works for smallish datasets (used local files)
*/
case class CSVFeatureSink2(fileName: String) extends FeatureSink {
def save(fs: FeatureSource) {
val header = ("" :: fs.sampleNames).mkString(",")
fs.features
.map(f => (f.label :: f.valueAsStrings).mkString(","))
.mapPartitionsWithIndex({
case (i, it) =>
if (i > 0) it else Some(header).iterator ++ it
})
.coalesce(1, true)
.saveAsTextFile(fileName)
}
}