forked from hammerlab/genomic-loci
/
ContigSuite.scala
66 lines (55 loc) · 2.05 KB
/
ContigSuite.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.hammerlab.genomics.loci.map
import com.google.common.collect.{ ImmutableRangeMap, Range }
import hammerlab.test.Suite
import org.hammerlab.genomics.reference.Locus
import org.hammerlab.genomics.reference.test.LociConversions._
import org.hammerlab.genomics.reference.test.{ ClearContigNames, ContigNameConversions }
class ContigSuite
extends Suite
with ContigNameConversions
with ClearContigNames {
test("empty") {
val contigMap = new Contig("chr1", ImmutableRangeMap.builder[Locus, String]().build())
contigMap.get(100) should ===(None)
contigMap.getAll(0, 10000) should be(Set())
contigMap.count should ===(0)
contigMap.toString should ===("")
}
test("basic operations") {
type JLong = java.lang.Long
val range100to200 = ImmutableRangeMap.of[Locus, String](Range.closedOpen[Locus](100, 200), "A")
val range200to300 = ImmutableRangeMap.of[Locus, String](Range.closedOpen[Locus](200, 300), "B")
val contigMap =
new Contig(
"chr1",
ImmutableRangeMap
.builder[Locus, String]()
.putAll(range100to200)
.putAll(range200to300)
.build()
)
contigMap.get(99) should be(None)
contigMap.get(100) should ===(Some("A"))
contigMap.get(199) should ===(Some("A"))
contigMap.get(200) should ===(Some("B"))
contigMap.get(299) should ===(Some("B"))
contigMap.get(300) should be(None)
contigMap.getAll(0, 100) should be(Set())
contigMap.getAll(0, 101) should ===(Set("A"))
contigMap.getAll(199, 200) should ===(Set("A"))
contigMap.getAll(199, 201) should ===(Set("A", "B"))
contigMap.getAll(200, 201) should ===(Set("B"))
contigMap.getAll(0, 10000) should ===(Set("A", "B"))
contigMap.count should ===(200)
contigMap.toString should ===("chr1:100-200=A,chr1:200-300=B")
}
test("getAll") {
val lociMap =
LociMap(
("chrM", 0, 8286, 0),
("chrM", 8286, 16571, 1)
)
lociMap("chrM").getAll(5, 10) should ===(Set(0))
lociMap("chrM").getAll(10000, 11000) should ===(Set(1))
}
}