Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
biopet.biopet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Mirrors
biopet.biopet
Commits
162d021a
Commit
162d021a
authored
Apr 19, 2017
by
Peter van 't Hof
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make common methods for fraction
parent
1b13fd65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
23 deletions
+48
-23
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala
...a/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala
+45
-1
shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/variantcallers/HaplotypeCallerGvcf.scala
.../pipelines/shiva/variantcallers/HaplotypeCallerGvcf.scala
+3
-22
No files found.
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala
View file @
162d021a
...
...
@@ -17,7 +17,6 @@ package nl.lumc.sasc.biopet.utils.intervals
import
java.io.
{
File
,
PrintWriter
}
import
htsjdk.samtools.SAMSequenceDictionary
import
htsjdk.samtools.reference.FastaSequenceFile
import
scala.collection.JavaConversions._
import
scala.collection.mutable
...
...
@@ -112,6 +111,15 @@ case class BedRecordList(val chrRecords: Map[String, List[BedRecord]], val heade
allRecords
.
foreach
(
writer
.
println
)
writer
.
close
()
}
/** This return the fraction of the regions comparing to a length */
def
fractionOf
(
length
:
Long
)
:
Double
=
length
.
toDouble
/
length
/** This return the fraction of the regions comparing to a reference */
def
fractionOfReference
(
dict
:
SAMSequenceDictionary
)
:
Double
=
fractionOf
(
dict
.
getReferenceLength
)
/** This return the fraction of the regions comparing to a reference */
def
fractionOfReference
(
file
:
File
)
:
Double
=
fractionOfReference
(
FastaUtils
.
getCachedDict
(
file
))
}
object
BedRecordList
{
...
...
@@ -131,6 +139,42 @@ object BedRecordList {
def
fromList
(
records
:
TraversableOnce
[
BedRecord
])
:
BedRecordList
=
fromListWithHeader
(
records
,
Nil
)
/**
* This creates a [[BedRecordList]] based on multiple files
*
* @param bedFiles Input bed files
* @return
*/
def
fromFiles
(
bedFiles
:
File*
)
=
{
fromFiles
(
bedFiles
,
combine
=
false
)
}
/**
* This creates a [[BedRecordList]] based on multiple files. This method combines overlapping regions
*
* @param bedFiles Input bed files
* @return
*/
def
fromFilesCombine
(
bedFiles
:
File*
)
=
{
fromFiles
(
bedFiles
,
combine
=
true
)
}
/**
* This creates a [[BedRecordList]] based on multiple files
*
* @param bedFiles Input bed files
* @param combine When true overlaping regions are merged
* @return
*/
def
fromFiles
(
bedFiles
:
Seq
[
File
],
combine
:
Boolean
=
false
)
=
{
val
list
=
bedFiles
.
foldLeft
(
empty
)((
a
,
b
)
=>
fromList
(
fromFile
(
b
).
allRecords
++
a
.
allRecords
))
if
(
combine
)
list
.
combineOverlap
else
list
}
/** This created a empty [[BedRecordList]] */
def
empty
=
fromList
(
Nil
)
def
fromFile
(
bedFile
:
File
)
=
{
val
reader
=
Source
.
fromFile
(
bedFile
)
val
all
=
reader
.
getLines
().
toList
...
...
shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/variantcallers/HaplotypeCallerGvcf.scala
View file @
162d021a
...
...
@@ -43,28 +43,9 @@ class HaplotypeCallerGvcf(val parent: Configurable) extends Variantcaller {
val
haploidRegionsMale
:
Option
[
File
]
=
config
(
"haploid_regions_male"
)
val
haploidRegionsFemale
:
Option
[
File
]
=
config
(
"haploid_regions_female"
)
lazy
val
referenceSize
=
referenceDict
.
getReferenceLength
lazy
val
fractionMale
:
Double
=
calculateFraction
(
haploidRegions
,
haploidRegionsMale
)
lazy
val
fractionFemale
:
Double
=
calculateFraction
(
haploidRegions
,
haploidRegionsFemale
)
lazy
val
fractionUnknown
:
Double
=
calculateFraction
(
haploidRegions
,
None
)
/**
* This method will calculate the fraction of the given bed files of the used reference
*
* @param file1 Bed file
* @param file2 Bed file
* @return Fraction
*/
def
calculateFraction
(
file1
:
Option
[
File
],
file2
:
Option
[
File
])
:
Double
=
{
(
file1
.
map
(
BedRecordList
.
fromFile
(
_
)),
file2
.
map
(
BedRecordList
.
fromFile
(
_
)))
match
{
case
(
Some
(
l
),
None
)
=>
l
.
length
.
toDouble
/
referenceSize
case
(
None
,
Some
(
l
))
=>
l
.
length
.
toDouble
/
referenceSize
case
(
Some
(
l1
),
Some
(
l2
))
=>
BedRecordList
.
fromList
(
l1
.
allRecords
++
l2
.
allRecords
).
combineOverlap
.
length
.
toDouble
/
referenceSize
case
(
None
,
None
)
=>
0.0
}
}
lazy
val
fractionMale
:
Double
=
BedRecordList
.
fromFiles
(
Seq
(
haploidRegions
,
haploidRegionsMale
).
flatten
,
true
).
fractionOfReference
(
referenceDict
)
lazy
val
fractionFemale
:
Double
=
BedRecordList
.
fromFiles
(
Seq
(
haploidRegions
,
haploidRegionsFemale
).
flatten
,
true
).
fractionOfReference
(
referenceDict
)
lazy
val
fractionUnknown
:
Double
=
BedRecordList
.
fromFiles
(
Seq
(
haploidRegions
).
flatten
,
true
).
fractionOfReference
(
referenceDict
)
override
def
fixedValues
=
Map
(
"haplotypecaller"
->
Map
(
"emitRefConfidence"
->
"GVCF"
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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