Skip to content

Commit

Permalink
chore: increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Jul 28, 2024
1 parent 1b35229 commit 4c19d02
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object Disambiguate {
}

/** Command line configuration. */
private class NeodisambiguateConf(args: Seq[String]) extends ScallopConf(args) {
private[neodisambiguate] class NeodisambiguateConf(args: Seq[String]) extends ScallopConf(args) {
private val packageName: String = Option(this.getClass.getPackage.getImplementationTitle).getOrElse("neodisambiguate")
private val version: String = Option(this.getClass.getPackage.getImplementationVersion).getOrElse("UNKNOWN")
version(s"$packageName $version\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object MetricPair {

/** Build a [[MetricPair]] from a [[Template]]. A function is required to reduce the tag values to one canonical value. */
def apply[T](template: Template, tag: SAMTag)(fn: (T, T) => T)(implicit cmp: Ordering[T]): MetricPair[T] = {
apply(template = template, tag = tag.toString)(fn = fn)
apply(template = template, tag = tag.toString)(fn = fn)(cmp = cmp)
}

/** Build an empty [[MetricPair]]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import htsjdk.samtools.SAMSequenceRecord
import htsjdk.samtools.SAMTag.{AS, NM}
import io.cvbio.neodisambiguate.CommonsDef.BamExtension
import io.cvbio.neodisambiguate.DisambiguationStrategy.Classic
import io.cvbio.neodisambiguate.Disambiguate.NeodisambiguateConf
import io.cvbio.neodisambiguate.testing.{TemplateBuilder, UnitSpec}

class DisambiguateTest extends UnitSpec {
Expand Down Expand Up @@ -152,4 +153,36 @@ class DisambiguateTest extends UnitSpec {

Io.assertWritableDirectory(PathUtil.pathTo(dir.toString, more = "ambiguous-alignments")) // will raise exception if non-existent.
}

"NeoNeodisambiguate" should "run end-to-end via the CLI entrypoint" in {
val humanAssembly: String = "hg38"
val mouseAssembly: String = "mm10"
val dir: DirPath = Io.makeTempDir("disambiguate")
dir.toFile.deleteOnExit()

val humanBuilder = new SamBuilder(sort = Some(SamOrder.Queryname))
val mouseBuilder = new SamBuilder(sort = Some(SamOrder.Queryname))

val _ = humanBuilder.addPair(name = "pair", attrs = Map(NM.toString -> 6, AS.toString -> 32), start1 = 2, start2 = 101)
val mousePair = mouseBuilder.addPair(name = "pair", attrs = Map(NM.toString -> 2, AS.toString -> 32), start1 = 2, start2 = 101)

humanBuilder.header.getSequenceDictionary.getSequences.forEach { seq: SAMSequenceRecord => val _ = seq.setAssembly(humanAssembly) }
mouseBuilder.header.getSequenceDictionary.getSequences.forEach { seq: SAMSequenceRecord => val _ = seq.setAssembly(mouseAssembly) }

val prefix = PathUtil.pathTo(dir.toString, more = "insilico")

val mouseBam = mouseBuilder.toTempFile(deleteOnExit = true)
val humanBam = humanBuilder.toTempFile(deleteOnExit = true)

val conf = new NeodisambiguateConf(args = Seq("--input", mouseBam.toString, humanBam.toString, "--output", prefix.toString))
Disambiguate.main(Array.from(conf.args))

val humanSource = SamSource(PathUtil.pathTo(Seq(prefix, humanAssembly).mkString(".") + BamExtension))
val mouseSource = SamSource(PathUtil.pathTo(Seq(prefix, mouseAssembly).mkString(".") + BamExtension))

humanSource.iterator.toSeq shouldBe empty
mouseSource.map(_.name).toSeq should contain theSameElementsInOrderAs mousePair.map(_.name)

Io.assertWritableDirectory(PathUtil.pathTo(dir.toString, more = "ambiguous-alignments")) // will raise exception if non-existent.
}
}

0 comments on commit 4c19d02

Please sign in to comment.