Skip to content

Commit

Permalink
[ADAM-351] Add simple support for symbolic alleles.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnothaft committed Aug 16, 2014
1 parent 49eac57 commit 5afa75b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,29 @@ class VariantContextConverter(dict: Option[SequenceDictionary] = None) extends S
return Seq(ADAMVariantContext(variant, genotypes, None))
}
case List(allele) => {
assert(allele.isNonReference && !allele.isSymbolic)
val variant = createADAMVariant(vc, Some(allele.getBaseString))
val genotypes = extractNonReferenceGenotypes(vc, variant, calling_annotations)
assert(allele.isNonReference,
"Assertion failed when converting: " + vc.toString)
val variant = createADAMVariant(vc, Some(allele.getDisplayString))
val genotypes = extractReferenceModelGenotypes(vc, variant, calling_annotations)
return Seq(ADAMVariantContext(variant, genotypes, None))
}
case List(allele, NON_REF_ALLELE) => {
assert(allele.isNonReference && !allele.isSymbolic)
val variant = createADAMVariant(vc, Some(allele.getBaseString))
assert(allele.isNonReference,
"Assertion failed when converting: " + vc.toString)
val variant = createADAMVariant(vc, Some(allele.getDisplayString))
val genotypes = extractReferenceModelGenotypes(vc, variant, calling_annotations)
return Seq(ADAMVariantContext(variant, genotypes, None))
}
case alleles :+ NON_REF_ALLELE => {
assert(false, "Multi-allelic site with non-ref symbolic allele")
Seq()
throw new IllegalArgumentException("Multi-allelic site with non-ref symbolic allele" +
vc.toString)
}
case _ => {
// Default case is multi-allelic without reference model
val vcb = new VariantContextBuilder(vc)
return vc.getAlternateAlleles.flatMap(allele => {
val idx = vc.getAlleleIndex(allele)
assert(idx >= 1, "Unexpected index for alternate allele")
assert(idx >= 1, "Unexpected index for alternate allele: " + vc.toString)
vcb.alleles(List(vc.getReference, allele, NON_REF_ALLELE))

def punchOutGenotype(g: org.broadinstitute.variant.variantcontext.Genotype, idx: Int): org.broadinstitute.variant.variantcontext.Genotype = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class VariantContextConverterSuite extends FunSuite {
.stop(1L)
.chr("1")

def gatkCNVBuilder: VariantContextBuilder = new VariantContextBuilder()
.alleles(List(Allele.create("A", true), Allele.create("<CN0>", false)))
.start(10L)
.stop(20L)
.chr("1")

def adamSNVBuilder(contig: String = "1"): Variant.Builder = Variant.newBuilder()
.setContig(Contig.newBuilder().setContigName(contig).build())
.setStart(0L)
Expand Down Expand Up @@ -82,6 +88,24 @@ class VariantContextConverterSuite extends FunSuite {
assert(variant.getContig.getContigName === "NC_000001.10")
}

test("Convert GATK site-only CNV to ADAM") {
val converter = new VariantContextConverter

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

assert(adamVC.genotypes.size === 0)

val variant = adamVC.variant
assert(variant.getContig.getContigName === "1")

assert(variant.getReferenceAllele === "A")
assert(variant.getAlternateAllele === "<CN0>")
assert(variant.getStart === 9L)
assert(variant.getEnd === 20L)
}

test("Convert GATK SNV w/ genotypes w/ phase information to ADAM") {
val vcb = gatkSNVBuilder

Expand Down

0 comments on commit 5afa75b

Please sign in to comment.