Commit 1100b72d authored by Sander Bollen's avatar Sander Bollen
Browse files

Add minimum genome quality to VcfFilter

parent 07d1825f
...@@ -54,7 +54,8 @@ object VcfFilter extends ToolCommand { ...@@ -54,7 +54,8 @@ object VcfFilter extends ToolCommand {
filterHetVarToHomVar: List[(String, String)] = Nil, filterHetVarToHomVar: List[(String, String)] = Nil,
filterRefCalls: Boolean = false, filterRefCalls: Boolean = false,
filterNoCalls: Boolean = false, filterNoCalls: Boolean = false,
iDset: Set[String] = Set()) extends AbstractArgs iDset: Set[String] = Set(),
minGenomeQuality: Int = 0) extends AbstractArgs
class OptParser extends AbstractOptParser { class OptParser extends AbstractOptParser {
opt[File]('I', "inputVcf") required () maxOccurs 1 valueName "<file>" action { (x, c) => opt[File]('I', "inputVcf") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
...@@ -128,6 +129,8 @@ object VcfFilter extends ToolCommand { ...@@ -128,6 +129,8 @@ object VcfFilter extends ToolCommand {
opt[File]("idFile") unbounded () action { (x, c) => opt[File]("idFile") unbounded () action { (x, c) =>
c.copy(iDset = c.iDset ++ Source.fromFile(x).getLines()) c.copy(iDset = c.iDset ++ Source.fromFile(x).getLines())
} text "File that contain list of IDs to get from vcf file" } text "File that contain list of IDs to get from vcf file"
opt[Int]("minGenomeQuality") unbounded() action { (x, c) =>
c.copy(minGenomeQuality = x)}
} }
/** @param args the command line arguments */ /** @param args the command line arguments */
...@@ -161,6 +164,7 @@ object VcfFilter extends ToolCommand { ...@@ -161,6 +164,7 @@ object VcfFilter extends ToolCommand {
hasMinTotalDepth(record, cmdArgs.minTotalDepth) && hasMinTotalDepth(record, cmdArgs.minTotalDepth) &&
hasMinSampleDepth(record, cmdArgs.minSampleDepth, cmdArgs.minSamplesPass) && hasMinSampleDepth(record, cmdArgs.minSampleDepth, cmdArgs.minSamplesPass) &&
minAlternateDepth(record, cmdArgs.minAlternateDepth, cmdArgs.minSamplesPass) && minAlternateDepth(record, cmdArgs.minAlternateDepth, cmdArgs.minSamplesPass) &&
minGenomeQuality(record, cmdArgs.minGenomeQuality, cmdArgs.minSamplesPass) &&
(cmdArgs.mustHaveVariant.isEmpty || mustHaveVariant(record, cmdArgs.mustHaveVariant)) && (cmdArgs.mustHaveVariant.isEmpty || mustHaveVariant(record, cmdArgs.mustHaveVariant)) &&
calledIn(record, cmdArgs.calledIn) && calledIn(record, cmdArgs.calledIn) &&
hasGenotype(record, cmdArgs.mustHaveGenotype) && hasGenotype(record, cmdArgs.mustHaveGenotype) &&
...@@ -263,6 +267,18 @@ object VcfFilter extends ToolCommand { ...@@ -263,6 +267,18 @@ object VcfFilter extends ToolCommand {
}) >= minSamplesPass }) >= minSamplesPass
} }
/**
* Checks if genome quality field has minimum value
* @param record VCF record
* @param minGQ smallest GQ allowed
* @param minSamplesPass number of samples to consider
* @return
*/
def minGenomeQuality(record: VariantContext, minGQ: Int, minSamplesPass: Int = 1): Boolean = {
record.getGenotypes.count(x => if (!x.hasGQ) false
else if (x.getGQ >= minGQ) true else false) >= minSamplesPass
}
/** /**
* 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
......
...@@ -138,6 +138,15 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -138,6 +138,15 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {
minAlternateDepth(record, 20, 2) shouldBe false minAlternateDepth(record, 20, 2) shouldBe false
} }
@Test def testHasMinGQ() = {
val reader = new VCFFileReader(vepped, false)
val record = reader.iterator().next()
minGenomeQuality(record, 99, 1) shouldBe true
minGenomeQuality(record, 99, 2) shouldBe true
minGenomeQuality(record, 99, 3) shouldBe true
}
@Test def testMustHaveVariant() = { @Test def testMustHaveVariant() = {
val reader = new VCFFileReader(vepped, false) val reader = new VCFFileReader(vepped, false)
val record = reader.iterator().next() val record = reader.iterator().next()
......
Supports Markdown
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