Commit 7979998e authored by Sander Bollen's avatar Sander Bollen
Browse files

Check whether sample exists in vcf file

parent 725ed53a
......@@ -319,6 +319,11 @@ object VcfFilter extends ToolCommand {
* @return true if filter passed
*/
def mustHaveVariant(record: VariantContext, samples: List[String]): Boolean = {
samples.foreach { s =>
if (!record.getSampleNames.toList.contains(s)) {
throw new IllegalArgumentException(s"Sample name $s does not exist in VCF file")
}
}
!samples.map(record.getGenotype).exists(a => a.isHomRef || a.isNoCall || VcfUtils.isCompoundNoCall(a))
}
......
......@@ -186,6 +186,8 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {
mustHaveVariant(record, List("Sample_101", "Sample_102")) shouldBe true
mustHaveVariant(record, List("Sample_101", "Sample_102", "Sample_103")) shouldBe false
an[IllegalArgumentException] shouldBe thrownBy(mustHaveVariant(record, List("notExistant")))
val starReader = new VCFFileReader(star, false)
starReader.iterator().foreach(x => mustHaveVariant(x, List("Sample_101")) shouldBe false)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment