Commit 8a1ead0e authored by Peter van 't Hof's avatar Peter van 't Hof

Added unit testing

parent 5badc583
......@@ -8,13 +8,16 @@ import scala.collection.mutable.ListBuffer
import scala.io.Source
/**
* This tool will find all pairs above a cutoff in a data table
*
* Created by pjvan_thof on 21-9-16.
*/
object FindOverlapMatch extends ToolCommand {
case class Args(inputMetrics: File = null,
outputFile: Option[File] = None,
cutoff: Double = 0.0) extends AbstractArgs
cutoff: Double = 0.0,
filterSameNames: Boolean = true) extends AbstractArgs
class OptParser extends AbstractOptParser {
opt[File]('i', "input") required () unbounded () valueName "<file>" action { (x, c) =>
......@@ -26,6 +29,10 @@ object FindOverlapMatch extends ToolCommand {
opt[Double]('c', "cutoff") required () unbounded () valueName "<value>" action { (x, c) =>
c.copy(cutoff = x)
} text "minimum value to report it as pair"
opt[Unit]("use_same_names") unbounded () valueName "<value>" action { (x, c) =>
c.copy(filterSameNames = false)
} text "Do not compare samples with the same name"
}
/**
......@@ -55,7 +62,7 @@ object FindOverlapMatch extends ToolCommand {
val buffer = ListBuffer[(String, Double)]()
for (i2 <- samplesRowHeader) {
val value = data(i1._2)(i2._2).toDouble
if (value >= cmdArgs.cutoff && i1._2 != i2._2) {
if (value >= cmdArgs.cutoff && (!cmdArgs.filterSameNames || i1._2 != i2._2)) {
buffer.+=((i2._1, value))
}
}
......
sample1 sample2 sample3
sample1 1.0 0.5 0.9
sample2 0.5 1.0 0.5
sample3 0.9 0.5 1.0
package nl.lumc.sasc.biopet.tools
import java.io.File
import java.nio.file.Paths
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
import scala.io.Source
/**
* Created by pjvan_thof on 27-9-16.
*/
class FindOverlapMatchTest extends TestNGSuite with Matchers {
private def resourcePath(p: String): String = {
Paths.get(getClass.getResource(p).toURI).toString
}
@Test
def testOverlap: Unit = {
val input = new File(resourcePath("/overlapmetrics.txt"))
val output = File.createTempFile("overlap.", ".txt")
val shouldBeOutput = new File(resourcePath("/overlapmetrics.default.output"))
output.deleteOnExit()
FindOverlapMatch.main(Array("-i", input.getAbsolutePath, "-c", "0.9", "-o", output.getAbsolutePath))
Source.fromFile(output).getLines().toList shouldBe Source.fromFile(shouldBeOutput).getLines().toList
}
@Test
def testOverlapSameName: Unit = {
val input = new File(resourcePath("/overlapmetrics.txt"))
val output = File.createTempFile("overlap.", ".txt")
val shouldBeOutput = new File(resourcePath("/overlapmetrics.same_names.output"))
output.deleteOnExit()
FindOverlapMatch.main(Array("-i", input.getAbsolutePath, "-c", "0.9", "-o", output.getAbsolutePath, "--use_same_names"))
Source.fromFile(output).getLines().toList shouldBe Source.fromFile(shouldBeOutput).getLines().toList
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment