Commit c779f1f0 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'fix-biopet-509' into 'develop'

Check whether sample exists in vcf file [Biopet-509]



See merge request !506
parents 8ead9c4f 7979998e
...@@ -319,6 +319,11 @@ object VcfFilter extends ToolCommand { ...@@ -319,6 +319,11 @@ object VcfFilter extends ToolCommand {
* @return true if filter passed * @return true if filter passed
*/ */
def mustHaveVariant(record: VariantContext, samples: List[String]): Boolean = { 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)) !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 { ...@@ -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")) shouldBe true
mustHaveVariant(record, List("Sample_101", "Sample_102", "Sample_103")) shouldBe false 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) val starReader = new VCFFileReader(star, false)
starReader.iterator().foreach(x => mustHaveVariant(x, List("Sample_101")) shouldBe 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