Skip to content

Commit

Permalink
refactor: only import ConsensusTags
Browse files Browse the repository at this point in the history
  • Loading branch information
znorgaard committed Jul 24, 2024
1 parent 97c52ac commit c015aef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/com/fulcrumgenomics/umi/Umis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
package com.fulcrumgenomics.umi

import com.fulcrumgenomics.bam.api.SamRecord
import com.fulcrumgenomics.umi.ConsensusTags.PerBase.AbRawReadCount
import com.fulcrumgenomics.umi.ConsensusTags.PerRead.{BaRawReadCount, RawReadCount}
import com.fulcrumgenomics.umi.ConsensusTags
import com.fulcrumgenomics.util.Sequences

object Umis {
Expand Down Expand Up @@ -136,6 +135,7 @@ object Umis {
* @return boolean indicating if the record is a consensus or not
*/
def isConsensusRead(rec: SamRecord): Boolean = {
rec.contains(RawReadCount) | (rec.contains(AbRawReadCount) & rec.contains(BaRawReadCount))
rec.contains(ConsensusTags.PerRead.RawReadCount) ||
(rec.contains(ConsensusTags.PerRead.AbRawReadCount) && rec.contains(ConsensusTags.PerRead.BaRawReadCount))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import com.fulcrumgenomics.bam.api.SamOrder
import com.fulcrumgenomics.commons.util.SimpleCounter
import com.fulcrumgenomics.testing.SamBuilder.{Minus, Plus}
import com.fulcrumgenomics.testing.{SamBuilder, UnitSpec}
import com.fulcrumgenomics.umi.ConsensusTags.PerBase.AbRawReadCount
import com.fulcrumgenomics.umi.ConsensusTags.PerRead.{AllPerReadTags, BaRawReadCount}
import com.fulcrumgenomics.umi.ConsensusTags
import com.fulcrumgenomics.util.{Io, Metric, Rscript}
import htsjdk.samtools.util.{Interval, IntervalList}
import org.apache.commons.math3.distribution.NormalDistribution
Expand Down Expand Up @@ -320,7 +319,12 @@ class CollectDuplexSeqMetricsTest extends UnitSpec {
contig=1,
start1=1000,
start2=1100,
attrs=Map(RX -> "AAA-GGG", MI -> "1/A", AbRawReadCount -> 10, BaRawReadCount -> 10)
attrs=Map(
RX -> "AAA-GGG",
MI -> "1/A",
ConsensusTags.PerRead.AbRawReadCount -> 10,
ConsensusTags.PerRead.BaRawReadCount -> 10
)
)
an[IllegalArgumentException] shouldBe thrownBy { exec(builder) }
}
Expand Down
10 changes: 6 additions & 4 deletions src/test/scala/com/fulcrumgenomics/umi/UmisTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ package com.fulcrumgenomics.umi

import com.fulcrumgenomics.bam.api.{SamOrder, SamRecord}
import com.fulcrumgenomics.testing.{SamBuilder, UnitSpec}
import com.fulcrumgenomics.umi.ConsensusTags.PerBase.AbRawReadCount
import com.fulcrumgenomics.umi.ConsensusTags.PerRead.{BaRawReadCount, RawReadCount}
import com.fulcrumgenomics.umi.ConsensusTags
import org.scalatest.OptionValues

class UmisTest extends UnitSpec with OptionValues {
Expand Down Expand Up @@ -122,8 +121,11 @@ class UmisTest extends UnitSpec with OptionValues {

it should "return true for reads with consensus tags" in {
val builder = new SamBuilder(sort=Some(SamOrder.Coordinate), readLength=10, baseQuality=20)
builder.addFrag(start=10, attrs=Map(RawReadCount -> 10)).exists(Umis.isConsensusRead) shouldBe true
builder.addFrag(start=10, attrs=Map(AbRawReadCount -> 10, BaRawReadCount -> 10))
builder.addFrag(start=10, attrs=Map(ConsensusTags.PerRead.RawReadCount -> 10))
.exists(Umis.isConsensusRead) shouldBe true
builder.addFrag(
start=10,
attrs=Map(ConsensusTags.PerRead.AbRawReadCount -> 10, ConsensusTags.PerRead.BaRawReadCount -> 10)
).exists(Umis.isConsensusRead) shouldBe true
}
}

0 comments on commit c015aef

Please sign in to comment.