Skip to content

Commit

Permalink
test proportion argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidion committed Apr 3, 2024
1 parent 9ccb1e6 commit f6052af
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/fulcrumgenomics/vcf/DownsampleVcf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class DownsampleVcf
@arg(flag='p', doc="Proportion of bases to retain (for single-sample VCF).") val proportion: Option[Double] = None,
@arg(flag='b', doc="Original number of bases (for single-sample VCF).") val originalBases: Option[Double] = None,
@arg(flag='m', doc="Index file with bases per sample.") val metadata: Option[FilePath] = None,
@arg(flag='n', doc="Target number of bases to downsample to.") val downsampleToBases: Option[Double],
@arg(flag='n', doc="Target number of bases to downsample to.") val downsampleToBases: Option[Double] = None,
@arg(flag='o', doc="Output file name.") val output: PathToVcf,
@arg(flag='w', doc="Winnowing window size.") val windowSize: Int = 0,
@arg(flag='e', doc="Sequencing Error rate for genotyping.") val epsilon: Double = 0.01,
Expand Down
73 changes: 43 additions & 30 deletions src/test/scala/com/fulcrumgenomics/vcf/DownsampleVcfTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,22 +369,28 @@ class DownsampleVcfTest extends UnitSpec {
Metric.write(metadata, Seq(Sample(SAMPLE_NAME = sample, BASE_COUNT = 100)))

"DownsampleVcf" should "write a new vcf with downsampled genotypes when provided a vcf" in {
List(true, false).foreach(
use_metdata => {
List("proportion", "number", "metadata").foreach(
kind => {
// Construct the input VCF
val outVcf = makeTempFile("out", ".vcf.gz")
if(use_metdata) {
new DownsampleVcf(input=inVcf,
output=outVcf,
metadata=Some(metadata),
downsampleToBases=Some(1),
windowSize=150).execute()
} else {
new DownsampleVcf(input=inVcf,
output=outVcf,
originalBases=Some(100),
downsampleToBases=Some(1),
windowSize=150).execute()
kind match {
case "proportion" =>
new DownsampleVcf(input=inVcf,
output=outVcf,
proportion=Some(0.01),
windowSize=150).execute()
case "number" =>
new DownsampleVcf(input=inVcf,
output=outVcf,
originalBases=Some(100),
downsampleToBases=Some(1),
windowSize=150).execute()
case "metadata" =>
new DownsampleVcf(input=inVcf,
output=outVcf,
metadata=Some(metadata),
downsampleToBases=Some(1),
windowSize=150).execute()
}

val vs = readVcfRecs(outVcf)
Expand Down Expand Up @@ -428,24 +434,31 @@ class DownsampleVcfTest extends UnitSpec {

"DownsampleVcf" should "write a new vcf with downsampled genotypes when provided a vcf, keeping nocalls" in {
// Construct the input VCF
List(true, false).foreach(
use_metdata => {
List("proportion", "number", "metadata").foreach(
kind => {
// Construct the input VCF
val outVcf = makeTempFile("out", ".vcf.gz")
if (use_metdata) {
new DownsampleVcf(input=inVcf,
output=outVcf,
metadata=Some(metadata),
downsampleToBases=Some(1),
writeNoCall=true,
windowSize=150).execute()
} else {
new DownsampleVcf(input=inVcf,
output=outVcf,
originalBases=Some(100),
downsampleToBases=Some(1),
writeNoCall=true,
windowSize=150).execute()
kind match {
case "proportion" =>
new DownsampleVcf(input=inVcf,
output=outVcf,
proportion=Some(0.01),
writeNoCall=true,
windowSize=150).execute()
case "number" =>
new DownsampleVcf(input=inVcf,
output=outVcf,
originalBases=Some(100),
downsampleToBases=Some(1),
writeNoCall=true,
windowSize=150).execute()
case "metadata" =>
new DownsampleVcf(input=inVcf,
output=outVcf,
metadata=Some(metadata),
downsampleToBases=Some(1),
writeNoCall=true,
windowSize=150).execute()
}

val vs = readVcfRecs(outVcf)
Expand Down

0 comments on commit f6052af

Please sign in to comment.