Skip to content

Commit

Permalink
chore: cleaned up the PR after review
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Mar 12, 2022
1 parent 1762908 commit e66f09e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/com/fulcrumgenomics/vcf/api/VcfWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object VcfWriter {
*
* If the path is meant to point to a regular file, then indexing will occur automatically. However, if the path
* already exists and the path is not a file or symbolic link, then this function will assume the path is a named
* pipe (such as `/dev/null`) and indexing will not occur.
* pipe or device (such as `/dev/null`) and indexing will not occur.
*
* @param path the path to write to
* @param header the header of the VCF
Expand All @@ -67,7 +67,7 @@ object VcfWriter {
def apply(path: PathToVcf, header: VcfHeader, async: Boolean = DefaultUseAsyncIo): VcfWriter = {
import com.fulcrumgenomics.fasta.Converters.ToSAMSequenceDictionary
val javaHeader = VcfConversions.toJavaHeader(header)
require(!Files.isDirectory(path), "Input path cannot be a directory!")
require(!Files.isDirectory(path), s"Path cannot be a directory! Found $path")

val builder = new VariantContextWriterBuilder()
.setOutputPath(path)
Expand Down
20 changes: 14 additions & 6 deletions src/test/scala/com/fulcrumgenomics/vcf/api/VcfIoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

package com.fulcrumgenomics.vcf.api

import com.fulcrumgenomics.commons.CommonsDef.SafelyClosable
import com.fulcrumgenomics.commons.io.{Io, PathUtil}
import com.fulcrumgenomics.testing.VcfBuilder.Gt
import com.fulcrumgenomics.testing.{UnitSpec, VcfBuilder}
import com.fulcrumgenomics.vcf.api.Allele.NoCallAllele
import htsjdk.samtools.util.FileExtensions.{BCF => BcfExtension, COMPRESSED_VCF => VcfGzExtension, TABIX_INDEX => TbiExtension, TRIBBLE_INDEX => IdxExtension, VCF => VcfExtension}
import htsjdk.samtools.util.FileExtensions.{BCF => BcfExtension, COMPRESSED_VCF => VcfGzExtension, CSI => CsiExtensions, TABIX_INDEX => TbiExtension, TRIBBLE_INDEX => IdxExtension, VCF => VcfExtension}
import org.scalatest.OptionValues

import java.nio.file.Files
Expand Down Expand Up @@ -244,7 +245,9 @@ class VcfIoTest extends UnitSpec with OptionValues {
val writer = VcfWriter(output, header = builder.header)
builder.add(chrom = "chr1", pos = 100, alleles = Seq("A", "C"), gts = Seq(Gt(sample = "sample", gt = "0/1")))
writer.close()
Files.exists(PathUtil.replaceExtension(output, VcfExtension + IdxExtension)) shouldBe true
val source = VcfSource(output)
source.isQueryable shouldBe true
source.safelyClose()
}

it should "write a sibling index when writing to a compressed VCF file" in {
Expand All @@ -254,7 +257,9 @@ class VcfIoTest extends UnitSpec with OptionValues {
val writer = VcfWriter(output, header = builder.header)
builder.add(chrom = "chr1", pos = 100, alleles = Seq("A", "C"), gts = Seq(Gt(sample = "sample", gt = "0/1")))
writer.close()
Files.exists(PathUtil.replaceExtension(PathUtil.removeExtension(output), VcfGzExtension + TbiExtension)) shouldBe true
val source = VcfSource(output)
source.isQueryable shouldBe true
source.safelyClose()
}

it should "write a sibling index when writing to a BCF file" in {
Expand All @@ -264,7 +269,9 @@ class VcfIoTest extends UnitSpec with OptionValues {
val writer = VcfWriter(output, header = builder.header)
builder.add(chrom = "chr1", pos = 100, alleles = Seq("A", "C"), gts = Seq(Gt(sample = "sample", gt = "0/1")))
writer.close()
Files.exists(PathUtil.replaceExtension(output, BcfExtension + IdxExtension)) shouldBe true
val source = VcfSource(output)
source.isQueryable shouldBe true
source.safelyClose()
}

it should "not attempt to write a sibling index when streaming to a named pipe like '/dev/null'" in {
Expand All @@ -273,7 +280,8 @@ class VcfIoTest extends UnitSpec with OptionValues {
val writer = VcfWriter(Io.DevNull, header = builder.header)
builder.add(chrom = "chr1", pos = 100, alleles = Seq("A", "C"), gts = Seq(Gt(sample = "sample", gt = "0/1")))
noException shouldBe thrownBy { writer.write(builder.toSeq); writer.close() }
Files.exists(PathUtil.pathTo(Io.DevNull.getFileName.toString + IdxExtension)) shouldBe false
Files.exists(PathUtil.pathTo(Io.DevNull.getFileName.toString + TbiExtension)) shouldBe false
Files.exists(PathUtil.pathTo(Io.DevNull.getFileName.toString + CsiExtensions)) shouldBe false
Files.exists(PathUtil.pathTo(Io.DevNull.getFileName.toString + IdxExtension)) shouldBe false
Files.exists(PathUtil.pathTo(Io.DevNull.getFileName.toString + TbiExtension)) shouldBe false
}
}

0 comments on commit e66f09e

Please sign in to comment.