VariantContextSampleGenotypeConverter { public static Map<String, SampleGenotype> createAlleleSampleGenotypes(VariantContext variantContext, int altAlleleId) { ImmutableMap.Builder<String, SampleGenotype> builder = ImmutableMap.builder(); Allele refAllele = variantContext.getReference(); Allele altAllele = variantContext.getAlternateAllele(altAlleleId); logger.debug("Making sample genotypes for altAllele: {} {} {} {}", altAlleleId, refAllele, altAllele, variantContext); for (Genotype genotype : variantContext.getGenotypes()) { logger.debug("Building sample genotype for {}", genotype); AlleleCall[] alleleCalls = buildAlleleCalls(refAllele, altAllele, genotype.getAlleles()); SampleGenotype sampleGenotype = buildSampleGenotype(genotype, alleleCalls); logger.debug("Variant [{} {}] sample {} {} has genotype {}", variantContext.getReference(), altAllele, genotype, genotype.getType(), sampleGenotype); String sampleName = genotype.getSampleName(); builder.put(sampleName, sampleGenotype); } return builder.build(); } private  VariantContextSampleGenotypeConverter(); static Map<String, SampleGenotype> createAlleleSampleGenotypes(VariantContext variantContext, int altAlleleId);  }
@Test void testNoGenotypeReturnsEmptyMap() { List<Allele> alleles = buildAlleles("A", "T"); VariantContext variantContext = buildVariantContext(1, 12345, alleles); Map<String, SampleGenotype> result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); assertThat(result.isEmpty(), is(true)); }
@Test public void testSingleSampleHetUnPhased() { List<Allele> alleles = buildAlleles("A", "T"); Genotype genotype = buildUnPhasedSampleGenotype("Adam", alleles.get(0), alleles.get(1)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, genotype); Map<String, SampleGenotype> result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); Map<String, SampleGenotype> expected = ImmutableMap.of("Adam", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT)); System.out.println(result); assertThat(result, equalTo(expected)); }
@Test public void testSingleSampleHetPhased() { List<Allele> alleles = buildAlleles("A", "T"); Genotype genotype = buildPhasedSampleGenotype("Adam", alleles.get(0), alleles.get(1)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, genotype); Map<String, SampleGenotype> result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); Map<String, SampleGenotype> expected = ImmutableMap.of("Adam", SampleGenotype.phased(AlleleCall.REF, AlleleCall.ALT)); System.out.println(result); assertThat(result, equalTo(expected)); }
@Test public void testSingleSampleHomRef() { List<Allele> alleles = buildAlleles("A", "T"); Genotype genotype = buildUnPhasedSampleGenotype("Adam", alleles.get(0), alleles.get(0)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, genotype); Map<String, SampleGenotype> result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); Map<String, SampleGenotype> expected = ImmutableMap.of("Adam", SampleGenotype.of(AlleleCall.REF, AlleleCall.REF)); System.out.println(result); assertThat(result, equalTo(expected)); }
@Test public void testSingleSampleHomAlt() { List<Allele> alleles = buildAlleles("A", "T"); Genotype genotype = buildUnPhasedSampleGenotype("Adam", alleles.get(1), alleles.get(1)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, genotype); Map<String, SampleGenotype> result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); Map<String, SampleGenotype> expected = ImmutableMap.of("Adam", SampleGenotype.of(AlleleCall.ALT, AlleleCall.ALT)); System.out.println(result); assertThat(result, equalTo(expected)); }
@Test public void testSingleSampleHetNonRef() { List<Allele> alleles = buildAlleles("A", "T", "G"); Genotype genotype = buildUnPhasedSampleGenotype("Adam", alleles.get(1), alleles.get(2)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, genotype); Map<String, SampleGenotype> allele1Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); System.out.println(allele1Result); Map<String, SampleGenotype> expected1 = ImmutableMap.of("Adam", SampleGenotype.of(AlleleCall.ALT, AlleleCall.OTHER_ALT)); assertThat(allele1Result, equalTo(expected1)); Map<String, SampleGenotype> allele2Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 1); System.out.println(allele2Result); Map<String, SampleGenotype> expected2 = ImmutableMap.of("Adam", SampleGenotype.of(AlleleCall.OTHER_ALT, AlleleCall.ALT)); assertThat(allele2Result, equalTo(expected2)); }
@Test public void testSingleSampleWithNoCall() { List<Allele> alleles = buildAlleles("A", "T"); Genotype proband = buildUnPhasedSampleGenotype("Cain", Allele.create((byte) '.'), alleles.get(1)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, proband); Map<String, SampleGenotype> allele1Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); System.out.println(allele1Result); Map<String, SampleGenotype> expected = ImmutableMap.of( "Cain", SampleGenotype.of(AlleleCall.NO_CALL, AlleleCall.ALT) ); assertThat(allele1Result, equalTo(expected)); }
@Test public void testMultiSample() { List<Allele> alleles = buildAlleles("A", "T", "C"); Genotype proband = buildUnPhasedSampleGenotype("Cain", alleles.get(1), alleles.get(2)); Genotype brother = buildUnPhasedSampleGenotype("Abel", alleles.get(1), alleles.get(1)); Genotype mother = buildUnPhasedSampleGenotype("Eve", alleles.get(0), alleles.get(1)); Genotype father = buildUnPhasedSampleGenotype("Adam", alleles.get(0), alleles.get(1)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, proband, brother, mother, father); Map<String, SampleGenotype> allele1Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); System.out.println(allele1Result); Map<String, SampleGenotype> expected1 = ImmutableMap.of( "Cain", SampleGenotype.of(AlleleCall.ALT, AlleleCall.OTHER_ALT), "Abel", SampleGenotype.of(AlleleCall.ALT, AlleleCall.ALT), "Eve", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT), "Adam", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT) ); assertThat(allele1Result, equalTo(expected1)); Map<String, SampleGenotype> allele2Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 1); System.out.println(allele2Result); Map<String, SampleGenotype> expected2 = ImmutableMap.of( "Cain", SampleGenotype.of(AlleleCall.ALT, AlleleCall.OTHER_ALT), "Abel", SampleGenotype.of(AlleleCall.OTHER_ALT, AlleleCall.OTHER_ALT), "Eve", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT), "Adam", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT) ); assertThat(allele2Result, equalTo(expected2)); }
@Test public void testCompHetAutosomalRecessiveFamilyTwoAlts() { List<Allele> alleles = buildAlleles("A", "T", "C"); Genotype proband = buildUnPhasedSampleGenotype("Cain", alleles.get(1), alleles.get(2)); Genotype brother = buildUnPhasedSampleGenotype("Abel", alleles.get(0), alleles.get(2)); Genotype mother = buildUnPhasedSampleGenotype("Eve", alleles.get(0), alleles.get(1)); Genotype father = buildUnPhasedSampleGenotype("Adam", alleles.get(0), alleles.get(2)); VariantContext variantContext = buildVariantContext(1, 12345, alleles, proband, brother, mother, father); Map<String, SampleGenotype> allele1Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 0); System.out.println(allele1Result); Map<String, SampleGenotype> expected1 = ImmutableMap.of( "Cain", SampleGenotype.of(AlleleCall.ALT, AlleleCall.OTHER_ALT), "Abel", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT), "Eve", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT), "Adam", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT) ); assertThat(allele1Result, equalTo(expected1)); Map<String, SampleGenotype> allele2Result = VariantContextSampleGenotypeConverter.createAlleleSampleGenotypes(variantContext, 1); System.out.println(allele2Result); Map<String, SampleGenotype> expected2 = ImmutableMap.of( "Cain", SampleGenotype.of(AlleleCall.ALT, AlleleCall.OTHER_ALT), "Abel", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT), "Eve", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT), "Adam", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT) ); assertThat(allele2Result, equalTo(expected2)); }