Skip to content
GitLab
Menu
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
299875bb
Commit
299875bb
authored
Dec 22, 2016
by
Peter van 't Hof
Browse files
Adding methods to agregate stats
parent
ef03063d
Changes
2
Hide whitespace changes
Inline
Side-by-side
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/vcfstats/Stats.scala
View file @
299875bb
...
...
@@ -51,7 +51,7 @@ case class Stats(generalStats: mutable.Map[String, mutable.Map[String, mutable.M
}
/** Function to write 1 specific general field */
def
write
Field
2
(
field
:
String
,
chr
:
String
=
"total"
)
:
Map
[
String
,
Array
[
Any
]]
=
{
def
get
Field
(
field
:
String
,
chr
:
String
=
"total"
)
:
Map
[
String
,
Array
[
Any
]]
=
{
val
data
=
this
.
generalStats
.
getOrElse
(
chr
,
mutable
.
Map
[
String
,
mutable.Map
[
Any
,
Int
]]()).
getOrElse
(
field
,
mutable
.
Map
[
Any
,
Int
]())
val
rows
=
for
(
key
<-
data
.
keySet
.
toArray
.
sortWith
(
sortAnyAny
))
yield
{
...
...
@@ -82,7 +82,7 @@ case class Stats(generalStats: mutable.Map[String, mutable.Map[String, mutable.M
}
/** Function to write 1 specific genotype field */
def
write
GenotypeField
2
(
samples
:
List
[
String
],
field
:
String
,
chr
:
String
=
"total"
)
:
Map
[
String
,
Map
[
String
,
Any
]]
=
{
def
get
GenotypeField
(
samples
:
List
[
String
],
field
:
String
,
chr
:
String
=
"total"
)
:
Map
[
String
,
Map
[
String
,
Any
]]
=
{
val
keySet
=
(
for
(
sample
<-
samples
)
yield
this
.
samplesStats
(
sample
).
genotypeStats
.
getOrElse
(
chr
,
Map
[
String
,
Map
[
Any
,
Int
]]()).
getOrElse
(
field
,
Map
[
Any
,
Int
]()).
keySet
).
fold
(
Set
[
Any
]())(
_
++
_
)
(
for
(
sample
<-
samples
)
yield
sample
->
{
...
...
@@ -91,6 +91,26 @@ case class Stats(generalStats: mutable.Map[String, mutable.Map[String, mutable.M
).
toMap
}).
toMap
}
/** This will generate stats for one contig */
def
getContigStats
(
contig
:
String
,
samples
:
List
[
String
],
genotypeFields
:
List
[
String
],
infoFields
:
List
[
String
])
:
Map
[
String
,
Any
]
=
{
Map
(
"genotype"
->
genotypeFields
.
map
(
f
=>
f
->
getGenotypeField
(
samples
,
f
,
contig
)).
toMap
,
"info"
->
infoFields
.
map
(
f
=>
f
->
getField
(
f
,
contig
))
)
}
/** This will generate stats for total */
def
getTotalStats
(
samples
:
List
[
String
],
genotypeFields
:
List
[
String
],
infoFields
:
List
[
String
])
=
getContigStats
(
"total"
,
samples
,
genotypeFields
,
infoFields
)
/** This will generate stats for total and contigs separated */
def
getAllStats
(
contigs
:
List
[
String
],
samples
:
List
[
String
],
genotypeFields
:
List
[
String
],
infoFields
:
List
[
String
])
:
Map
[
String
,
Any
]
=
{
Map
(
"contigs"
->
contigs
.
map
(
c
=>
c
->
getContigStats
(
c
,
samples
,
genotypeFields
,
infoFields
)).
toMap
,
"total"
->
getTotalStats
(
samples
,
genotypeFields
,
infoFields
)
)
}
}
object
Stats
{
...
...
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/vcfstats/VcfStats.scala
View file @
299875bb
...
...
@@ -195,7 +195,7 @@ object VcfStats extends ToolCommand {
}
// Triple for loop to not keep all bins in memory
val
statsFutures
=
(
for
(
intervals
<-
Random
.
shuffle
(
intervals
).
grouped
(
intervals
.
size
/
(
if
(
intervals
.
size
>
10
)
4
else
1
)).
toList
)
yield
Future
{
val
statsFutures
=
for
(
intervals
<-
Random
.
shuffle
(
intervals
).
grouped
(
intervals
.
size
/
(
if
(
intervals
.
size
>
10
)
4
else
1
)).
toList
)
yield
Future
{
val
chunkStats
=
for
(
intervals
<-
intervals
.
grouped
(
25
))
yield
{
val
binStats
=
for
(
interval
<-
intervals
.
par
)
yield
{
val
reader
=
new
VCFFileReader
(
cmdArgs
.
inputFile
,
true
)
...
...
@@ -243,7 +243,7 @@ object VcfStats extends ToolCommand {
binStats
.
toList
.
fold
(
createStats
)(
_
+=
_
)
}
chunkStats
.
toList
.
fold
(
createStats
)(
_
+=
_
)
}
)
}
val
stats
=
statsFutures
.
foldLeft
(
createStats
)
{
case
(
a
,
b
)
=>
a
+=
Await
.
result
(
b
,
Duration
.
Inf
)
}
logger
.
info
(
"Done reading vcf records"
)
...
...
Write
Preview
Supports
Markdown
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