Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
0c7e6dae
Commit
0c7e6dae
authored
Oct 04, 2016
by
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
Changes
6
Hide whitespace changes
Inline
Side-by-side
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/VcfFilter.scala
View file @
0c7e6dae
...
...
@@ -19,7 +19,7 @@ import java.io.File
import
htsjdk.variant.variantcontext.
{
GenotypeType
,
VariantContext
}
import
htsjdk.variant.variantcontext.writer.
{
AsyncVariantContextWriter
,
VariantContextWriterBuilder
}
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.io.Source
...
...
@@ -315,11 +315,11 @@ object VcfFilter extends ToolCommand {
* Checks if given samples does have a variant hin this 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
*/
def
mustHaveVariant
(
record
:
VariantContext
,
mustHaveVariant
:
List
[
String
])
:
Boolean
=
{
!
mustHaveVariant
.
map
(
record
.
getGenotype
).
exists
(
a
=>
a
.
isHomRef
||
a
.
isNoCall
)
def
mustHaveVariant
(
record
:
VariantContext
,
samples
:
List
[
String
])
:
Boolean
=
{
!
samples
.
map
(
record
.
getGenotype
).
exists
(
a
=>
a
.
isHomRef
||
a
.
isNoCall
||
VcfUtils
.
isCompoundNoCall
(
a
)
)
}
/** Checks if given samples have the same genotype */
...
...
biopet-tools/src/test/resources/star_genotype.vcf.gz
0 → 100644
View file @
0c7e6dae
File added
biopet-tools/src/test/resources/star_genotype.vcf.gz.tbi
0 → 100644
View file @
0c7e6dae
File added
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfFilterTest.scala
View file @
0c7e6dae
...
...
@@ -39,7 +39,9 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {
}
val
veppedPath
=
resourcePath
(
"/VEP_oneline.vcf"
)
val
starPath
=
resourcePath
(
"/star_genotype.vcf.gz"
)
val
vepped
=
new
File
(
veppedPath
)
val
star
=
new
File
(
starPath
)
val
rand
=
new
Random
()
@Test
def
testOutputTypeVcf
()
=
{
...
...
@@ -183,6 +185,9 @@ class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {
mustHaveVariant
(
record
,
List
(
"Sample_101"
))
shouldBe
true
mustHaveVariant
(
record
,
List
(
"Sample_101"
,
"Sample_102"
))
shouldBe
true
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
()
=
{
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/VcfUtils.scala
View file @
0c7e6dae
...
...
@@ -140,4 +140,13 @@ object VcfUtils {
reader
.
close
()
!
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
)
}
}
biopet-utils/src/test/scala/VcfUtilsTest.scala
0 → 100644
View file @
0c7e6dae
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
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment