Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix in ReferenceUtils.unionReferenceSet #671

Merged
merged 2 commits into from
May 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ object ReferenceUtils {
def folder(acc: Seq[ReferenceRegion], tref: ReferenceRegion): Seq[ReferenceRegion] =
acc match {
case Seq() => Seq(tref)
case (first: ReferenceRegion) +: Seq(rest) =>
case (first: ReferenceRegion) +: rest =>
if (first.overlaps(tref))
first.hull(tref) +: Seq(rest)
first.hull(tref) +: rest
else
tref +: first +: Seq(rest)
tref +: first +: rest
}

refs.toSeq.sorted.foldLeft(Seq[ReferenceRegion]())(folder)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Licensed to Big Data Genomics (BDG) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The BDG licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bdgenomics.adam.models

import org.bdgenomics.adam.models.ReferenceUtils._
import org.bdgenomics.adam.util.ADAMFunSuite

class ReferenceUtilsSuite extends ADAMFunSuite {

test("unionReferenceSet: empty") {
val regions = Seq()

assert(unionReferenceSet(regions) === regions)
}

test("unionReferenceSet: one region") {
val regions = Seq(ReferenceRegion("1", 3, 7))

assert(unionReferenceSet(regions) === regions)
}

test("unionReferenceSet: multiple regions on one contig, all overlap") {
val regions = Seq(ReferenceRegion("1", 3, 7),
ReferenceRegion("1", 1, 5),
ReferenceRegion("1", 6, 10))

assert(unionReferenceSet(regions) === Seq(ReferenceRegion("1", 1, 10)))
}

test("unionReferenceSet: multiple regions on one contig, some overlap") {
val regions = Seq(ReferenceRegion("1", 3, 7),
ReferenceRegion("1", 1, 5),
ReferenceRegion("1", 8, 10))

assert(unionReferenceSet(regions) === Seq(ReferenceRegion("1", 8, 10), ReferenceRegion("1", 1, 7)))
}

test("unionReferenceSet: multiple regions on multiple contigs") {
val regions = Seq(ReferenceRegion("1", 3, 7),
ReferenceRegion("1", 1, 5),
ReferenceRegion("2", 4, 8))

assert(unionReferenceSet(regions) === Seq(ReferenceRegion("2", 4, 8), ReferenceRegion("1", 1, 7)))
}

}