Skip to content

Commit

Permalink
Merge pull request bigdatagenomics#3 from mlinderm/adam-vcf
Browse files Browse the repository at this point in the history
Sent varIsFiltered appropriately if FILTER is PASS or "."
  • Loading branch information
nealsid committed Feb 5, 2014
2 parents 1004689 + f8f46f6 commit 2690144
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ private[adam] class VariantContextConverter(dict: Option[SequenceDictionary] = N

// VCF QUAL, FILTER and INFO fields
if (vc.hasLog10PError) shared_genotype_builder.setVarProbError(vc.getPhredScaledQual.asInstanceOf[Float])
if (vc.isFiltered) {
if (vc.isFiltered) { // not PASSing
shared_genotype_builder.setVarIsFiltered(vc.isFiltered).setVarFilters(new util.ArrayList(vc.getFilters))
}
} else if (vc.filtersWereApplied) // PASSing
shared_genotype_builder.setVarIsFiltered(false)
shared_genotype_builder.setVarCallAnno(convertINFOAttributes(vc))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ import org.scalatest.FunSuite
import org.broadinstitute.variant.variantcontext.{Allele, VariantContextBuilder, GenotypeBuilder}
import java.lang.Integer
import edu.berkeley.cs.amplab.adam.models.{SequenceRecord, SequenceDictionary}
import edu.berkeley.cs.amplab.adam.avro.ADAMGenotypeAllele

class VariantContextConverterSuite extends FunSuite {
val dictionary = SequenceDictionary(SequenceRecord(1, "chr1", 249250621, "file://ucsc.hg19.fasta", "1b22b98cdeb4a9304cb5d48026a85128"))

def snvBuilder: VariantContextBuilder = new VariantContextBuilder()
.alleles(List(Allele.create("A",true), Allele.create("T")).asJavaCollection)
.start(1L)
.stop(1L)
.chr("chr1")

test("Convert site-only SNV") {
val vc = new VariantContextBuilder()
.alleles(List(Allele.create("A",true), Allele.create("T")).asJavaCollection)
Expand Down Expand Up @@ -54,27 +61,48 @@ class VariantContextConverterSuite extends FunSuite {
}

test("Convert genotypes with phase information") {
val vcb = new VariantContextBuilder()
.alleles(List(Allele.create("A",true), Allele.create("T")).asJavaCollection)
.start(1L)
.stop(1L)
.chr("chr1")
val vcb = snvBuilder

val genotypeAttributes = JavaConversions.mapAsJavaMap(Map[String, Object]("PQ" -> new Integer(50), "PS" -> "1"))
val genotype = GenotypeBuilder.create("NA12878", vcb.getAlleles(), genotypeAttributes)
val vc = vcb.genotypes(List(genotype).asJavaCollection).make()
val vc = vcb.genotypes(GenotypeBuilder.create("NA12878", vcb.getAlleles(), genotypeAttributes)).make()

val converter = new VariantContextConverter(Some(dictionary))

val adamVCs = converter.convert(vc)
assert(adamVCs.length === 1)
val adamVC = adamVCs.head

assert(adamVC.genotypes.length === 1)
val adamGTs = adamVCs.flatMap(_.genotypes)
assert(adamGTs.length === 1)
val adamGT = adamGTs.head
assert(adamGT.getAlleles.asScala.sameElements(List(ADAMGenotypeAllele.Ref, ADAMGenotypeAllele.Alt)))
assert(adamGT.getPhaseSetId === "1")
assert(adamGT.getPhaseQuality === 50)
}

val variant = adamVC.variant
assert(variant.getReferenceAllele === "A")
assert(variant.getPosition === 0L)
test("PASSing variants") {
val vcb = snvBuilder
vcb.genotypes(GenotypeBuilder.create("NA12878", vcb.getAlleles))
vcb.passFilters()

val converter = new VariantContextConverter(Some(dictionary))

val adamVCs = converter.convert(vcb.make)
val adamGT = adamVCs.flatMap(_.genotypes).head

assert(adamGT.getVarIsFiltered === false)
}

test("non PASSing variants") {
val vcb = snvBuilder
vcb.genotypes(GenotypeBuilder.create("NA12878", vcb.getAlleles))
vcb.filter("LowMQ")

val converter = new VariantContextConverter(Some(dictionary))

val adamVCs = converter.convert(vcb.make)
val adamGT = adamVCs.flatMap(_.genotypes).head

assert(adamGT.getVarIsFiltered === true)
assert(adamGT.getVarFilters.asScala.sameElements(List("LowMQ")))
}
}

0 comments on commit 2690144

Please sign in to comment.