Skip to content

Commit

Permalink
The unmatched barcode incorrectly had a hyphen when multiple sample b…
Browse files Browse the repository at this point in the history
…arcode reads were being used. (#317)
  • Loading branch information
nh13 authored Nov 15, 2017
1 parent 0841a6b commit e2d1d8d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/com/fulcrumgenomics/fastq/DemuxFastqs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object DemuxFastqs {
require(barcodeSegments.nonEmpty, "No sample barcodes found in read structures: " + readStructures.mkString(", "))
require(barcodeSegments.forall(_.hasFixedLength), "Barcode segments must have fixed lengths in: " + readStructures.mkString(", "))

val noMatchBarcode: String = barcodeSegments.map("N" * _.fixedLength).mkString("-")
val noMatchBarcode: String = barcodeSegments.map("N" * _.fixedLength).mkString
Sample(sampleOrdinal=sampleOrdinal, sampleId=UnmatchedSampleId, sampleName=UnmatchedSampleId, libraryId=UnmatchedSampleId, i7IndexBases=Some(noMatchBarcode))
}

Expand Down Expand Up @@ -455,7 +455,7 @@ private class SamRecordWriter(output: PathToBam,
}
rec.sampleBarcode.foreach(bc => record("BC") = bc)
record(ReservedTagConstants.READ_GROUP_ID) = rgId
rec.molecularBarcode.foreach(mb => record(umiTag) = mb)
rec.molecularBarcode.foreach(mb => record(umiTag) = mb)
writer += record
}

Expand Down
58 changes: 57 additions & 1 deletion src/test/scala/com/fulcrumgenomics/fastq/DemuxFastqsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package com.fulcrumgenomics.fastq

import java.nio.file.Files

import com.fulcrumgenomics.FgBioDef.{DirPath, FilePath}
import com.fulcrumgenomics.FgBioDef.{DirPath, FilePath, PathToFastq}
import com.fulcrumgenomics.fastq.FastqDemultiplexer.{DemuxRecord, DemuxResult}
import com.fulcrumgenomics.illumina.{Sample, SampleSheet}
import com.fulcrumgenomics.testing.{ErrorLogLevel, UnitSpec}
Expand Down Expand Up @@ -614,6 +614,62 @@ class DemuxFastqsTest extends UnitSpec with OptionValues with ErrorLogLevel {
}
}

it should "demux dual-indexed paired end reads" in {
def write(rec: FastqRecord): PathToFastq = {
val path = makeTempFile("fastq", ".fastq")
val writer = FastqWriter(path)
writer.write(rec)
writer.close()
path
}

val fq1 = write(fq(name="frag", bases="AAAAAAAA"))
val fq2 = write(fq(name="frag", bases="A"*100))
val fq3 = write(fq(name="frag", bases="T"*100))
val fq4 = write(fq(name="frag", bases="GATTACAGA"))
val structures = Seq(ReadStructure("8B"), ReadStructure("100T"), ReadStructure("100T"), ReadStructure("9B"))

val output: DirPath = outputDir()
val metrics = makeTempFile("metrics", ".txt")

new DemuxFastqs(inputs=Seq(fq1, fq2, fq3, fq4), output=output, metadata=sampleSheetPath,
readStructures=structures, metrics=Some(metrics), maxMismatches=2, minMismatchDelta=3).execute()

val sampleBarcodMetrics = Metric.read[SampleBarcodeMetric](metrics)
val sampleInfos = toSampleInfos(structures)
val samples: Seq[Sample] = sampleInfos.map(_.sample)

sampleBarcodMetrics.zip(samples).foreach { case (metric, sample) =>
metric.barcode_name shouldBe sample.sampleName
metric.barcode shouldBe sample.sampleBarcodeString
metric.library_name shouldBe sample.libraryId
if (sample.sampleOrdinal == 1) {
metric.reads shouldBe 1
metric.pf_reads shouldBe 1
metric.perfect_matches shouldBe 1
metric.one_mismatch_matches shouldBe 0
metric.pf_perfect_matches shouldBe 1
metric.pf_one_mismatch_matches shouldBe 0
}
else if (sample.sampleId == UnmatchedSampleId) {
metric.reads shouldBe 0
metric.pf_reads shouldBe 0
metric.perfect_matches shouldBe 0
metric.one_mismatch_matches shouldBe 0
metric.pf_perfect_matches shouldBe 0
metric.pf_one_mismatch_matches shouldBe 0
}
else {
metric.reads shouldBe 0
metric.pf_reads shouldBe 0
metric.perfect_matches shouldBe 0
metric.one_mismatch_matches shouldBe 0
metric.pf_perfect_matches shouldBe 0
metric.pf_one_mismatch_matches shouldBe 0
}
}
}

"FastqRecordWriter.readName" should "set the read name based if it should follow Illumina standards" in {
val output = outputDir()
val baseRec = DemuxRecord(name="name", bases="", quals="", molecularBarcode=Some("MB"), sampleBarcode=Some("SB"), readNumber=1, pairedEnd=false, comment=None)
Expand Down

0 comments on commit e2d1d8d

Please sign in to comment.