Skip to content

Commit

Permalink
[ADAM-1512] Support VCFs with +Inf/-Inf float values.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnothaft committed Oct 8, 2017
1 parent 45b9fe8 commit a703f18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,15 @@ class VariantContextConverter(
private def toFloat(obj: java.lang.Object): Float = {
tryAndCatchStringCast(obj, o => {
o.asInstanceOf[java.lang.Float]
}, o => o.toFloat)
}, o => {
if (o == "+Inf") {
Float.PositiveInfinity
} else if (o == "-Inf") {
Float.NegativeInfinity
} else {
o.toFloat
}
})
}

// don't shadow toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,20 @@ class VariantContextConverterSuite extends ADAMFunSuite {
assert(va.getAlleleFrequency > 0.09f && va.getAlleleFrequency < 0.11f)
}

test("single allele frequency is +Inf going htsjdk->adam") {
val acList: java.util.List[String] = List("+Inf")
val va = buildVariantAnnotation(Map(("AF", acList)),
converter.formatAlleleFrequency)
assert(va.getAlleleFrequency == Float.PositiveInfinity)
}

test("single allele frequency is -Inf going htsjdk->adam") {
val acList: java.util.List[String] = List("-Inf")
val va = buildVariantAnnotation(Map(("AF", acList)),
converter.formatAlleleFrequency)
assert(va.getAlleleFrequency == Float.NegativeInfinity)
}

test("multiple allele frequencies going htsjdk->adam") {
val acList: java.util.List[java.lang.Float] = List(
0.1f, 0.01f, 0.001f).map(i => i: java.lang.Float)
Expand Down

0 comments on commit a703f18

Please sign in to comment.