Skip to content

Commit

Permalink
Extra test for unexpected sequence writer + bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomko committed Feb 5, 2024
1 parent d348e68 commit 0bbfcd4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object UnexpectedSequenceWriter {
val ret = mutable.HashSet[String]()
colReference.allBarcodes.foreach { dnaBarcode =>
val linesToRead: Int =
math.floor((unexpectedCountsByBarcode.getOrElse(dnaBarcode, 0) * samplePct).toDouble).toInt
math.ceil((unexpectedCountsByBarcode.getOrElse(dnaBarcode, 0) * samplePct).toDouble).toInt
val file = cacheDir.resolve(nameFor(dnaBarcode))
if (Files.exists(file)) {
Using.resource(Source.fromFile(file.toFile)) { src =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
CCCCCCCCAAAAAAAAAAAA
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GATGTGCAGTGAGTAGCGAG
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
GGGGGGGGGGTTTTTTTTTT
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import scala.util.{Random, Using}

import better.files._
import munit.{FunSuite, Location}
import org.broadinstitute.gpp.poolq3.PoolQ
import org.broadinstitute.gpp.poolq3.barcode.{Barcodes, FoundBarcode}
import org.broadinstitute.gpp.poolq3.parser.{CloseableIterable, ReferenceEntry}
import org.broadinstitute.gpp.poolq3.process.{ScoringConsumer, UnexpectedSequenceTracker}
import org.broadinstitute.gpp.poolq3.reference.{ExactReference, VariantReference}
import org.broadinstitute.gpp.poolq3.{PoolQ, TestResources}

class UnexpectedSequencesTest extends FunSuite {
class UnexpectedSequencesTest extends FunSuite with TestResources {

private[this] val rowReferenceBarcodes =
List("AAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAC", "AAAAAAAAAAAAAAAAAAAG", "AAAAAAAAAAAAAAAAAAAT").map(b =>
Expand Down Expand Up @@ -91,6 +91,40 @@ class UnexpectedSequencesTest extends FunSuite {

}

test("read unexpected sequence cache") {
val cachePath = resourcePath("unexpected-sequences")
val outputFile = Files.createTempFile("unexpected", ".txt")
try {
val unexpectedReadCount = 9

UnexpectedSequenceWriter
.write(
outputFile,
cachePath,
Map("AAAA" -> unexpectedReadCount, "CCCG" -> unexpectedReadCount, "AAAT" -> 0, "CCCC" -> 0),
100,
colReference,
Some(globalReference),
0.02f
)
.get

val expected =
s"""Sequence\tTotal\tAAAA\tAAAT\tCCCC\tCCCG\tPotential IDs
|GATGTGCAGTGAGTAGCGAG\t$unexpectedReadCount\t0\t0\t0\t$unexpectedReadCount\tOh, that one
|TTTTTTTTTTTTTTTTTTTT\t$unexpectedReadCount\t$unexpectedReadCount\t0\t0\t0\t
|""".stripMargin

Using.resource(Source.fromFile(outputFile.toFile)) { contents =>
// now check the contents
val actual = contents.mkString
assertEquals(actual, expected)
}
} finally {
val _ = Files.deleteIfExists(outputFile)
}
}

private def testIt(underlyingBarcodes: List[(String, String)], samplePct: Float, unexpectedReadCount: Int)(implicit
loc: Location
): Unit = {
Expand All @@ -106,17 +140,11 @@ class UnexpectedSequencesTest extends FunSuite {
new ScoringConsumer(rowReference, colReference, countAmbiguous = true, false, None, Some(ust), false)

// run PoolQ and write the file
val _ = PoolQ.runProcess(barcodes, consumer)

val _ = UnexpectedSequenceWriter.write(
outputFile,
cachePath,
ust.unexpectedBarcodeCounts,
100,
colReference,
Some(globalReference),
samplePct
)
val _ = PoolQ.runProcess(barcodes, consumer).get

UnexpectedSequenceWriter
.write(outputFile, cachePath, ust.unexpectedBarcodeCounts, 100, colReference, Some(globalReference), samplePct)
.get

val expected =
s"""Sequence\tTotal\tAAAA\tAAAT\tCCCC\tCCCG\tPotential IDs
Expand All @@ -129,7 +157,6 @@ class UnexpectedSequencesTest extends FunSuite {
val actual = contents.mkString
assertEquals(actual, expected)
}

} finally {
val _ = tmpPath.toFile.toScala.delete()
}
Expand Down

0 comments on commit 0bbfcd4

Please sign in to comment.