From 3eb895c3e71c7d4dbafa2a01320d723ab31c0a53 Mon Sep 17 00:00:00 2001 From: Thomas Moerman Date: Mon, 4 May 2015 15:44:15 +0200 Subject: [PATCH 1/2] - fixed pattern matching bug in ReferenceUtils.unionReferenceSet - added test suite --- .../org/bdgenomics/adam/models/Gene.scala | 6 +-- .../adam/models/ReferenceUtilsSuite.scala | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/models/Gene.scala b/adam-core/src/main/scala/org/bdgenomics/adam/models/Gene.scala index e931d7adec..56aaf3c55a 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/models/Gene.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/models/Gene.scala @@ -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) diff --git a/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala b/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala new file mode 100644 index 0000000000..670e685bea --- /dev/null +++ b/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala @@ -0,0 +1,44 @@ +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))) + } + +} From 9dc6a6cb2229aae0bca406f5656e97a1210a87e9 Mon Sep 17 00:00:00 2001 From: Thomas Moerman Date: Mon, 4 May 2015 17:30:31 +0200 Subject: [PATCH 2/2] now with proper header ./scripts/format-source --- .../adam/models/ReferenceUtilsSuite.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala b/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala index 670e685bea..9f1ca9eb1a 100644 --- a/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala +++ b/adam-core/src/test/scala/org/bdgenomics/adam/models/ReferenceUtilsSuite.scala @@ -1,3 +1,20 @@ +/** + * 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._