Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 authored Feb 14, 2025
1 parent 721d9a1 commit a5037dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/main/scala/com/fulcrumgenomics/bam/api/SamSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ class SamSource private(private val reader: SamReader) extends View[SamRecord] w
override def iterator: SamIterator = new SamIterator(reader.getFileHeader, reader.iterator())

private def newQueryInterval(region: Locatable): QueryInterval = {
val contig = dict(region.getContig)
val contigIndex = contig.index
val start = Math.max(region.getStart, 1);
val end = Math.min(region.getEnd, contig.length)
new QueryInterval(contigIndex, start, end)
val contig = dict(region.getContig)
val start = Math.max(region.getStart, 1);
val end = Math.min(region.getEnd, contig.length)
new QueryInterval(contig.index, start, end)
}

/** Returns an iterator over the records in the regions provided. */
Expand Down
20 changes: 11 additions & 9 deletions src/test/scala/com/fulcrumgenomics/bam/api/SamIoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import java.nio.file.Files
import java.util.concurrent.{Callable, Executors, TimeUnit}

import com.fulcrumgenomics.FgBioDef._
import com.fulcrumgenomics.bam.api.QueryType.QueryType
import com.fulcrumgenomics.fasta.{SequenceDictionary, SequenceMetadata}
import com.fulcrumgenomics.testing.{SamBuilder, UnitSpec}
import com.fulcrumgenomics.util.Io
Expand Down Expand Up @@ -166,25 +167,26 @@ class SamIoTest extends UnitSpec {
}

"SamSource.query" should "" in {
val queryType = QueryType.Overlapping
val builder = new SamBuilder(readLength=10, baseQuality=20)
Range(0, 10).foreach { _ => builder.addFrag(start=100) }
val source = builder.toSource

// test a query before the contig start
source.query("chr1", 0, 1000).length shouldBe 10
source.query("chr1", -100, 1000).length shouldBe 10
source.query("chr1", 0, 1000, queryType).length shouldBe 10
source.query("chr1", -100, 1000, queryType).length shouldBe 10

// test a query after the contig end
val contigEnd = builder.dict("chr1").length
source.query("chr1", 100, contigEnd+1).length shouldBe 10
source.query("chr1", 100, contigEnd+100).length shouldBe 10
val contigEnd = builder.dict("chr1", queryType).length
source.query("chr1", 100, contigEnd+1, queryType).length shouldBe 10
source.query("chr1", 100, contigEnd+100, queryType).length shouldBe 10

// test a query both before and after the contig start and end respectively
source.query("chr1", -100, contigEnd+100).length shouldBe 10
source.query("chr1", -100, contigEnd+100, queryType).length shouldBe 10

// at the start and end
source.query("chr1", 1, 1000).length shouldBe 10
source.query("chr1", 100, contigEnd).length shouldBe 10
source.query("chr1", 1, contigEnd).length shouldBe 10
source.query("chr1", 1, 1000, queryType).length shouldBe 10
source.query("chr1", 100, contigEnd, queryType).length shouldBe 10
source.query("chr1", 1, contigEnd, queryType).length shouldBe 10
}
}

0 comments on commit a5037dc

Please sign in to comment.