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
461567af
Commit
461567af
authored
May 11, 2015
by
Peter van 't Hof
Browse files
Refactor some code
parent
21ec56a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/VcfFilter.scala
View file @
461567af
...
...
@@ -56,7 +56,8 @@ class VcfFilter(val root: Configurable) extends BiopetJavaCommandLineFunction {
}
object
VcfFilter
extends
ToolCommand
{
case
class
Trio
(
child
:
String
,
father
:
String
,
mother
:
String
)
{
/** Container class for a trio */
protected
case
class
Trio
(
child
:
String
,
father
:
String
,
mother
:
String
)
{
def
this
(
arg
:
String
)
=
{
this
(
arg
.
split
(
":"
)(
0
),
arg
.
split
(
":"
)(
1
),
arg
.
split
(
":"
)(
2
))
}
...
...
@@ -157,9 +158,7 @@ object VcfFilter extends ToolCommand {
var
commandArgs
:
Args
=
_
/**
* @param args the command line arguments
*/
/** @param args the command line arguments */
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
logger
.
info
(
"Start"
)
val
argsParser
=
new
OptParser
...
...
@@ -184,15 +183,15 @@ object VcfFilter extends ToolCommand {
var
counterTotal
=
0
var
counterLeft
=
0
for
(
record
<-
reader
)
{
if
(
minQualscore
(
record
)
&&
filter
RefCalls
(
record
)
&&
filterNoCalls
(
record
)
&&
m
inTotalDepth
(
record
)
&&
m
inSampleDepth
(
record
)
&&
if
(
commandArgs
.
minQualScore
.
map
(
minQualscore
(
record
,
_
)).
getOrElse
(
true
)
&&
(!
commandArgs
.
filterRefCalls
||
hasNon
RefCalls
(
record
)
)
&&
(!
commandArgs
.
filterNoCalls
||
hasCalls
(
record
)
)
&&
hasM
inTotalDepth
(
record
,
commandArgs
.
minTotalDepth
)
&&
hasM
inSampleDepth
(
record
,
commandArgs
.
minSampleDepth
,
commandArgs
.
minSamplesPass
)
&&
minAlternateDepth
(
record
)
&&
minBamAlternateDepth
(
record
,
header
)
&&
mustHaveVariant
(
record
)
&&
called
(
record
)
&&
called
In
(
record
,
commandArgs
.
calledIn
)
&&
notSameGenotype
(
record
)
&&
filterHetVarToHomVar
(
record
)
&&
denovoInSample
(
record
)
&&
...
...
@@ -215,35 +214,44 @@ object VcfFilter extends ToolCommand {
logger
.
info
(
"Done"
)
}
def
called
(
record
:
VariantContext
)
:
Boolean
=
{
if
(!
commandArgs
.
calledIn
.
forall
(
record
.
getGenotype
(
_
).
isCalled
))
false
/**
* Checks if given samples are called
* @param record VCF record
* @param samples Samples that need this sample to be called
* @return false when filters fail
*/
def
calledIn
(
record
:
VariantContext
,
samples
:
List
[
String
])
:
Boolean
=
{
if
(!
samples
.
forall
(
record
.
getGenotype
(
_
).
isCalled
))
false
else
true
}
def
minQualscore
(
record
:
VariantContext
)
:
Boolean
=
{
if
(
commandArgs
.
minQualScore
.
isEmpty
)
return
true
record
.
getPhredScaledQual
>=
commandArgs
.
minQualScore
.
get
/**
* Checks if record has atleast minQualScore
* @param record VCF record
* @param minQualScore Minimal quality score
* @return false when filters fail
*/
def
minQualscore
(
record
:
VariantContext
,
minQualScore
:
Double
)
:
Boolean
=
{
record
.
getPhredScaledQual
>=
minQualScore
}
def
filterRefCalls
(
record
:
VariantContext
)
:
Boolean
=
{
if
(
commandArgs
.
filterNoCalls
)
record
.
getGenotypes
.
exists
(
g
=>
!
g
.
isHomRef
)
else
true
def
hasNonRefCalls
(
record
:
VariantContext
)
:
Boolean
=
{
record
.
getGenotypes
.
exists
(
g
=>
!
g
.
isHomRef
)
}
def
filterNoCalls
(
record
:
VariantContext
)
:
Boolean
=
{
if
(
commandArgs
.
filterNoCalls
)
record
.
getGenotypes
.
exists
(
g
=>
!
g
.
isNoCall
)
else
true
def
hasCalls
(
record
:
VariantContext
)
:
Boolean
=
{
record
.
getGenotypes
.
exists
(
g
=>
!
g
.
isNoCall
)
}
def
m
inTotalDepth
(
record
:
VariantContext
)
:
Boolean
=
{
record
.
getAttributeAsInt
(
"DP"
,
-
1
)
>=
commandArgs
.
minTotalDepth
def
hasM
inTotalDepth
(
record
:
VariantContext
,
minTotalDepth
:
Int
)
:
Boolean
=
{
record
.
getAttributeAsInt
(
"DP"
,
-
1
)
>=
minTotalDepth
}
def
m
inSampleDepth
(
record
:
VariantContext
)
:
Boolean
=
{
def
hasM
inSampleDepth
(
record
:
VariantContext
,
minSampleDepth
:
Int
,
minSamplesPass
:
Int
)
:
Boolean
=
{
record
.
getGenotypes
.
count
(
genotype
=>
{
val
DP
=
if
(
genotype
.
hasDP
)
genotype
.
getDP
else
-
1
DP
>=
commandArgs
.
minSampleDepth
})
>=
commandArgs
.
minSamplesPass
DP
>=
minSampleDepth
})
>=
minSamplesPass
}
def
minAlternateDepth
(
record
:
VariantContext
)
:
Boolean
=
{
...
...
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