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
7a3e8399
Commit
7a3e8399
authored
Jul 19, 2016
by
Peter van 't Hof
Browse files
Added unit testing to count / histogram
parent
fb27385e
Changes
4
Hide whitespace changes
Inline
Side-by-side
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/Histogram.scala
View file @
7a3e8399
...
...
@@ -7,8 +7,14 @@ import scala.collection.mutable
/**
* Created by pjvanthof on 05/07/16.
*/
class
Counts
[
T
](
implicit
ord
:
Ordering
[
T
])
{
protected
[
Counts
]
val
counts
:
mutable.Map
[
T
,
Long
]
=
mutable
.
Map
()
class
Counts
[
T
](
_counts
:
Map
[
T
,
Long
]
=
Map
[
T
,
Long
]())(
implicit
ord
:
Ordering
[
T
])
{
protected
[
Counts
]
val
counts
:
mutable.Map
[
T
,
Long
]
=
mutable
.
Map
()
++
_counts
/** Returns histogram as map */
def
countsMap
=
counts
.
toMap
/** Returns value if it does exist */
def
get
(
key
:
T
)
=
counts
.
get
(
key
)
/** This will add an other histogram to `this` */
def
+=
(
other
:
Counts
[
T
])
:
Counts
[
T
]
=
{
...
...
@@ -30,6 +36,6 @@ class Counts[T](implicit ord: Ordering[T]) {
}
}
class
Histogram
[
T
](
implicit
ord
:
Numeric
[
T
])
extends
Counts
[
T
]
{
class
Histogram
[
T
](
_counts
:
Map
[
T
,
Long
]
=
Map
[
T
,
Long
]())(
implicit
ord
:
Numeric
[
T
])
extends
Counts
[
T
]
(
_counts
)
{
}
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/Stats.scala
View file @
7a3e8399
...
...
@@ -8,13 +8,13 @@ case class Stats() {
var
totalReads
=
0L
var
unmapped
=
0L
var
secondary
=
0L
val
mappingQualityHistogram
=
new
Histogram
[
Int
]
val
insertSizeHistogram
=
new
Histogram
[
Int
]
val
clippingHistogram
=
new
Histogram
[
Int
]
val
leftClippingHistogram
=
new
Histogram
[
Int
]
val
rightClippingHistogram
=
new
Histogram
[
Int
]
val
_5_ClippingHistogram
=
new
Histogram
[
Int
]
val
_3_ClippingHistogram
=
new
Histogram
[
Int
]
val
mappingQualityHistogram
=
new
Histogram
[
Int
]
()
val
insertSizeHistogram
=
new
Histogram
[
Int
]
()
val
clippingHistogram
=
new
Histogram
[
Int
]
()
val
leftClippingHistogram
=
new
Histogram
[
Int
]
()
val
rightClippingHistogram
=
new
Histogram
[
Int
]
()
val
_5_ClippingHistogram
=
new
Histogram
[
Int
]
()
val
_3_ClippingHistogram
=
new
Histogram
[
Int
]
()
/** This will add an other [[Stats]] inside `this` */
def
+=
(
other
:
Stats
)
:
Stats
=
{
...
...
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/bamstats/CountsTest.scala
0 → 100644
View file @
7a3e8399
package
nl.lumc.sasc.biopet.tools.bamstats
import
java.io.File
import
org.scalatest.Matchers
import
org.scalatest.testng.TestNGSuite
import
org.testng.annotations.Test
import
scala.io.Source
/**
* Created by pjvan_thof on 19-7-16.
*/
class
CountsTest
extends
TestNGSuite
with
Matchers
{
@Test
def
testValues
:
Unit
=
{
val
data
:
Map
[
String
,
Long
]
=
Map
(
"1"
->
1
,
"2"
->
2
,
"3"
->
3
)
val
c1
=
new
Counts
[
String
](
data
)
c1
.
countsMap
shouldBe
data
c1
.
get
(
"1"
)
shouldBe
Some
(
1
)
c1
.
get
(
"2"
)
shouldBe
Some
(
2
)
c1
.
get
(
"3"
)
shouldBe
Some
(
3
)
c1
.
get
(
"4"
)
shouldBe
None
c1
.
add
(
"1"
)
c1
.
get
(
"1"
)
shouldBe
Some
(
2
)
c1
.
add
(
"4"
)
c1
.
get
(
"4"
)
shouldBe
Some
(
1
)
val
c2
=
new
Counts
[
String
](
data
)
c1
+=
c2
c1
.
get
(
"1"
)
shouldBe
Some
(
3
)
c1
.
get
(
"2"
)
shouldBe
Some
(
4
)
c1
.
get
(
"3"
)
shouldBe
Some
(
6
)
c1
.
get
(
"4"
)
shouldBe
Some
(
1
)
}
@Test
def
testEmpty
:
Unit
=
{
val
c1
=
new
Counts
[
Int
]()
c1
.
countsMap
.
isEmpty
shouldBe
true
}
@Test
def
testTsv
:
Unit
=
{
val
data
:
Map
[
Int
,
Long
]
=
Map
(
1
->
1
,
2
->
2
,
3
->
3
)
val
c1
=
new
Counts
[
Int
](
data
)
val
tsvFile
=
File
.
createTempFile
(
"counts."
,
".tsv"
)
tsvFile
.
deleteOnExit
()
c1
.
writeToTsv
(
tsvFile
)
val
reader
=
Source
.
fromFile
(
tsvFile
)
reader
.
getLines
().
toList
shouldBe
List
(
"value\tcount"
,
"1\t1"
,
"2\t2"
,
"3\t3"
)
reader
.
close
()
}
}
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/bamstats/HistogramTest.scala
0 → 100644
View file @
7a3e8399
package
nl.lumc.sasc.biopet.tools.bamstats
import
java.io.File
import
org.scalatest.Matchers
import
org.scalatest.testng.TestNGSuite
import
org.testng.annotations.Test
import
scala.io.Source
/**
* Created by pjvan_thof on 19-7-16.
*/
class
HistogramTest
extends
TestNGSuite
with
Matchers
{
@Test
def
testValues
:
Unit
=
{
val
data
:
Map
[
Int
,
Long
]
=
Map
(
1
->
1
,
2
->
2
,
3
->
3
)
val
c1
=
new
Histogram
[
Int
](
data
)
c1
.
countsMap
shouldBe
data
c1
.
get
(
1
)
shouldBe
Some
(
1
)
c1
.
get
(
2
)
shouldBe
Some
(
2
)
c1
.
get
(
3
)
shouldBe
Some
(
3
)
c1
.
get
(
4
)
shouldBe
None
c1
.
add
(
1
)
c1
.
get
(
1
)
shouldBe
Some
(
2
)
c1
.
add
(
4
)
c1
.
get
(
4
)
shouldBe
Some
(
1
)
val
c2
=
new
Counts
[
Int
](
data
)
c1
+=
c2
c1
.
get
(
1
)
shouldBe
Some
(
3
)
c1
.
get
(
2
)
shouldBe
Some
(
4
)
c1
.
get
(
3
)
shouldBe
Some
(
6
)
c1
.
get
(
4
)
shouldBe
Some
(
1
)
}
@Test
def
testEmpty
:
Unit
=
{
val
c1
=
new
Histogram
[
Int
]()
c1
.
countsMap
.
isEmpty
shouldBe
true
}
@Test
def
testTsv
:
Unit
=
{
val
data
:
Map
[
Int
,
Long
]
=
Map
(
1
->
1
,
2
->
2
,
3
->
3
)
val
c1
=
new
Histogram
[
Int
](
data
)
val
tsvFile
=
File
.
createTempFile
(
"counts."
,
".tsv"
)
tsvFile
.
deleteOnExit
()
c1
.
writeToTsv
(
tsvFile
)
val
reader
=
Source
.
fromFile
(
tsvFile
)
reader
.
getLines
().
toList
shouldBe
List
(
"value\tcount"
,
"1\t1"
,
"2\t2"
,
"3\t3"
)
reader
.
close
()
}
}
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