Skip to content
Snippets Groups Projects
Commit 0c7e6dae authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'fix-must-have-variant' into 'develop'

Fix must have variant

Fixes #386 

See merge request !455
parents 3d9a0df1 87dad15a
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ import java.io.File ...@@ -19,7 +19,7 @@ import java.io.File
import htsjdk.variant.variantcontext.{ GenotypeType, VariantContext } import htsjdk.variant.variantcontext.{ GenotypeType, VariantContext }
import htsjdk.variant.variantcontext.writer.{ AsyncVariantContextWriter, VariantContextWriterBuilder } import htsjdk.variant.variantcontext.writer.{ AsyncVariantContextWriter, VariantContextWriterBuilder }
import htsjdk.variant.vcf.VCFFileReader import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.ToolCommand import nl.lumc.sasc.biopet.utils.{ ToolCommand, VcfUtils }
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
import scala.io.Source import scala.io.Source
...@@ -315,11 +315,11 @@ object VcfFilter extends ToolCommand { ...@@ -315,11 +315,11 @@ object VcfFilter extends ToolCommand {
* Checks if given samples does have a variant hin this record * Checks if given samples does have a variant hin this record
* *
* @param record VCF record * @param record VCF record
* @param mustHaveVariant List of samples that should have this variant * @param samples List of samples that should have this variant
* @return true if filter passed * @return true if filter passed
*/ */
def mustHaveVariant(record: VariantContext, mustHaveVariant: List[String]): Boolean = { def mustHaveVariant(record: VariantContext, samples: List[String]): Boolean = {
!mustHaveVariant.map(record.getGenotype).exists(a => a.isHomRef || a.isNoCall) !samples.map(record.getGenotype).exists(a => a.isHomRef || a.isNoCall || VcfUtils.isCompoundNoCall(a))
} }
/** Checks if given samples have the same genotype */ /** Checks if given samples have the same genotype */
......
File added
File added
...@@ -39,7 +39,9 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -39,7 +39,9 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {
} }
val veppedPath = resourcePath("/VEP_oneline.vcf") val veppedPath = resourcePath("/VEP_oneline.vcf")
val starPath = resourcePath("/star_genotype.vcf.gz")
val vepped = new File(veppedPath) val vepped = new File(veppedPath)
val star = new File(starPath)
val rand = new Random() val rand = new Random()
@Test def testOutputTypeVcf() = { @Test def testOutputTypeVcf() = {
...@@ -183,6 +185,9 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -183,6 +185,9 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {
mustHaveVariant(record, List("Sample_101")) shouldBe true mustHaveVariant(record, List("Sample_101")) shouldBe true
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
val starReader = new VCFFileReader(star, false)
starReader.iterator().foreach(x => mustHaveVariant(x, List("Sample_101")) shouldBe false)
} }
@Test def testSameGenotype() = { @Test def testSameGenotype() = {
......
...@@ -140,4 +140,13 @@ object VcfUtils { ...@@ -140,4 +140,13 @@ object VcfUtils {
reader.close() reader.close()
!hasNext !hasNext
} }
/**
* Check whether genotype is of the form 0/.
* @param genotype genotype
* @return boolean
*/
def isCompoundNoCall(genotype: Genotype): Boolean = {
genotype.isCalled && genotype.getAlleles.exists(_.isNoCall) && genotype.getAlleles.exists(_.isReference)
}
} }
import htsjdk.variant.variantcontext.{ Allele, Genotype, GenotypeBuilder }
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
import scala.collection.JavaConversions._
import nl.lumc.sasc.biopet.utils.VcfUtils
/**
* Created by Sander Bollen on 4-10-16.
*/
class VcfUtilsTest extends TestNGSuite with Matchers {
@Test
def testCompoundNoCall(): Unit = {
val noAllele = Allele.NO_CALL
val refAllele = Allele.create("A", true)
val compoundNoCall = GenotypeBuilder.create("sample_01", List(noAllele, refAllele))
VcfUtils.isCompoundNoCall(compoundNoCall) shouldBe true
val altAllele = Allele.create("G", false)
val normalGenotype = GenotypeBuilder.create("sample_01", List(refAllele, altAllele))
VcfUtils.isCompoundNoCall(normalGenotype) shouldBe false
val completeNoCall = GenotypeBuilder.create("sample_01", List(noAllele, noAllele))
VcfUtils.isCompoundNoCall(completeNoCall) shouldBe false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment