Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of VariantContextSetBuilder in all unit tests #819

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
package com.fulcrumgenomics.bam

import java.nio.file.{Files, Path}

import com.fulcrumgenomics.bam.api.SamOrder
import com.fulcrumgenomics.commons.io.PathUtil
import com.fulcrumgenomics.fasta.Converters.ToSAMSequenceDictionary
import com.fulcrumgenomics.fasta.SequenceDictionary
import com.fulcrumgenomics.testing.SamBuilder.{Minus, Plus}
import com.fulcrumgenomics.testing.{ReferenceSetBuilder, SamBuilder, UnitSpec, VariantContextSetBuilder}
import com.fulcrumgenomics.testing.VcfBuilder.Gt
import com.fulcrumgenomics.testing.{ReferenceSetBuilder, SamBuilder, UnitSpec, VcfBuilder}
import com.fulcrumgenomics.util.{Metric, Rscript}
import htsjdk.samtools.util.{Interval, IntervalList}
import com.fulcrumgenomics.util.Metric.Count
Expand Down Expand Up @@ -74,11 +74,11 @@ class ErrorRateByReadPositionTest extends UnitSpec with OptionValues {
private val dict = SequenceDictionary.extract(ref)

private val vcf = {
val builder = new VariantContextSetBuilder().setSequenceDictionary(dict)
builder.addVariant(1, 500, variantAlleles=List("A", "C"), genotypeAlleles=List("A", "C"))
builder.addVariant(2, 500, variantAlleles=List("C", "T"), genotypeAlleles=List("C", "T"))
builder.addVariant(3, 500, variantAlleles=List("G", "A"), genotypeAlleles=List("G", "A"))
builder.addVariant(4, 500, variantAlleles=List("T", "C"), genotypeAlleles=List("T", "C"))
val builder = VcfBuilder(samples=List("sample1"))
builder.add("chr1", 500, alleles=List("A", "C"), gts=Seq(Gt(sample="sample1", gt="0/1")))
builder.add("chr2", 500, alleles=List("C", "T"), gts=Seq(Gt(sample="sample1", gt="0/1")))
builder.add("chr3", 500, alleles=List("G", "A"), gts=Seq(Gt(sample="sample1", gt="0/1")))
builder.add("chr4", 500, alleles=List("T", "C"), gts=Seq(Gt(sample="sample1", gt="0/1")))
builder.toTempFile()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import com.fulcrumgenomics.FgBioDef._
import com.fulcrumgenomics.bam.api.SamOrder
import com.fulcrumgenomics.commons.io.PathUtil
import com.fulcrumgenomics.testing.SamBuilder.{Minus, Plus}
import com.fulcrumgenomics.testing.{SamBuilder, UnitSpec, VariantContextSetBuilder}
import com.fulcrumgenomics.testing.VcfBuilder.Gt
import com.fulcrumgenomics.testing.{SamBuilder, UnitSpec, VcfBuilder}
import com.fulcrumgenomics.umi.ReviewConsensusVariants.ConsensusVariantReviewInfo
import com.fulcrumgenomics.util.{Io, Metric}
import com.fulcrumgenomics.vcf.api._
import htsjdk.samtools.SAMFileHeader
import htsjdk.samtools.reference.{ReferenceSequenceFile, ReferenceSequenceFileFactory}
import htsjdk.samtools.util.IntervalList
Expand Down Expand Up @@ -79,12 +81,19 @@ class ReviewConsensusVariantsTest extends UnitSpec {

lazy val ref: ReferenceSequenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(refFasta)

lazy val header = {
lazy val intervalListHeader = {
val h = new SAMFileHeader
h.setSequenceDictionary(ref.getSequenceDictionary)
h
}

lazy val vcfDefaultHeader: VcfHeader = VcfBuilder.DefaultHeader.copy(
contigs = ref.getSequenceDictionary.getSequences.iterator().map { r =>
VcfContigHeader(r.getSequenceIndex, r.getSequenceName, Some(r.getSequenceLength)) } .toIndexedSeq
)

// lazy val vcfHeader = VcfHeader(ref.)

// We're going to simulate raw reads and consensuses as if there were variants at:
// chr1:10
// chr1:20
Expand Down Expand Up @@ -180,7 +189,7 @@ class ReviewConsensusVariantsTest extends UnitSpec {
val rawOut = outBase.getParent.resolve(s"${outBase.getFileName}.grouped.bam")
val txtOut = outBase.getParent.resolve(s"${outBase.getFileName}.txt")
val intervals = makeTempFile("empty.", ".interval_list")
new IntervalList(header).write(intervals.toFile)
new IntervalList(intervalListHeader).write(intervals.toFile)
new ReviewConsensusVariants(input=intervals, consensusBam=consensusBam, groupedBam=rawBam, ref=refFasta, output=outBase).execute()

conOut.toFile.exists() shouldBe true
Expand All @@ -199,9 +208,9 @@ class ReviewConsensusVariantsTest extends UnitSpec {
val txtOut = outBase.getParent.resolve(s"${outBase.getFileName}.txt")
val intervals = makeTempFile("empty.", ".vcf")

val vcfBuilder = VariantContextSetBuilder("s1")
vcfBuilder.header.setSequenceDictionary(header.getSequenceDictionary)
val vcfBuilder = VcfBuilder(vcfDefaultHeader.copy(samples=IndexedSeq("s1")))
vcfBuilder.write(intervals)

new ReviewConsensusVariants(input=intervals, consensusBam=consensusBam, groupedBam=rawBam, ref=refFasta, output=outBase).execute()

conOut.toFile.exists() shouldBe true
Expand All @@ -219,12 +228,15 @@ class ReviewConsensusVariantsTest extends UnitSpec {
val rawOut = outBase.getParent.resolve(s"${outBase.getFileName}.grouped.bam")
val txtOut = outBase.getParent.resolve(s"${outBase.getFileName}.txt")

val vcfBuilder = new VariantContextSetBuilder(sampleNames=List("tumor"))
vcfBuilder.header.setSequenceDictionary(this.header.getSequenceDictionary)
vcfBuilder.addVariant(refIdx=0, start=10, variantAlleles=List("A","T"), genotypeAlleles=List("A","T"), genotypeAttributes=Map("AF" -> 0.01))
vcfBuilder.addVariant(refIdx=0, start=20, variantAlleles=List("A","C"), genotypeAlleles=List("A","C"), genotypeAttributes=Map("AF" -> 0.01))
vcfBuilder.addVariant(refIdx=0, start=30, variantAlleles=List("A","G"), genotypeAlleles=List("A","G"), genotypeAttributes=Map("AF" -> 0.01))
vcfBuilder.addVariant(refIdx=1, start=20, variantAlleles=List("C","T"), genotypeAlleles=List("C","T"), genotypeAttributes=Map("AD" -> Array(100,2)))
val vcfBuilder = VcfBuilder(vcfDefaultHeader.copy(
samples=IndexedSeq("tumor"),
infos = Seq(VcfInfoHeader(id="AF", count=VcfCount.OnePerAllele, kind=VcfFieldType("Float"), description="Allele Frequency"),
VcfInfoHeader(id="AD", count=VcfCount.OnePerAllele, kind=VcfFieldType("Integer"), description="Allele Depth)")))
)
vcfBuilder.add(chrom="chr1", pos=10, alleles=Seq("A", "T"), gts=Seq(Gt(sample="tumor", gt="0/1")),info=Map("AF" -> 0.01))
vcfBuilder.add(chrom="chr1", pos=20, alleles=Seq("A", "C"), gts=Seq(Gt(sample="tumor", gt="0/1")),info=Map("AF" -> 0.01))
vcfBuilder.add(chrom="chr1", pos=30, alleles=Seq("A", "G"), gts=Seq(Gt(sample="tumor", gt="0/1")),info=Map("AF" -> 0.01))
vcfBuilder.add(chrom="chr2", pos=20, alleles=Seq("C", "T"), gts=Seq(Gt(sample="tumor", gt="0/1")),info=Map("AD" -> Seq(100, 2)))

new ReviewConsensusVariants(input=vcfBuilder.toTempFile(), consensusBam=consensusBam, groupedBam=rawBam, ref=refFasta, output=outBase).execute()

Expand Down
Loading