public static String genotypeToString(Map<Allele, String> allelesMap, htsjdk.variant.variantcontext.Genotype genotype) { String genotypeValue; StringBuilder gt = new StringBuilder(); for (Allele allele : genotype.getAlleles()) { if (gt.length() > 0) { gt.append(genotype.isPhased() ? VCFConstants.PHASED : VCFConstants.UNPHASED); } gt.append(allelesMap.get(allele)); } genotypeValue = gt.toString(); return genotypeValue; }
private void updatePairMetricsCounters(Genotype parent, Genotype child, int mvCount, HashMap<Byte,Integer> counters){ //Increment metrics counters if(parent.isCalled() && child.isCalled()){ counters.put(NUM_PAIR_GENOTYPES_CALLED,counters.get(NUM_PAIR_GENOTYPES_CALLED)+1); if(parent.isPhased()) counters.put(NUM_PAIR_GENOTYPES_PHASED,counters.get(NUM_PAIR_GENOTYPES_PHASED)+1); else{ counters.put(NUM_PAIR_VIOLATIONS,counters.get(NUM_PAIR_VIOLATIONS)+mvCount); if(parent.isHet() && child.isHet()) counters.put(NUM_PAIR_HET_HET,counters.get(NUM_PAIR_HET_HET)+1); } }else{ counters.put(NUM_PAIR_GENOTYPES_NOCALL,counters.get(NUM_PAIR_GENOTYPES_NOCALL)+1); } }
private static SampleGenotype buildSampleGenotype(Genotype genotype, AlleleCall[] alleleCalls) { return genotype.isPhased() ? SampleGenotype.phased(alleleCalls) : SampleGenotype.of(alleleCalls); } }
/** Get the sample genotype in the same format as it appears on the VCF file. * I.e. allele indexes separated by '/' or '|' (if phased). E.g. 0/0, 0/1 etc */ private String genotypeAsAlleleIndexes(VariantContext ctx, String sample) { Genotype gt = ctx.getGenotype(sample); char sep= gt.isPhased() ? '|' : '/'; List<String> all= new ArrayList<String>(); for(Allele a : gt.getAlleles()){ if(a.isNoCall()){ all.add("."); } else { int i= ctx.getAlleleIndex(a); all.add(Integer.toString(i)); } } return '"' + Joiner.on(sep).join(all) + '"'; }
private void updateTrioMetricsCounters(Genotype mother, Genotype father, Genotype child, int mvCount, HashMap<Byte,Integer> counters){ //Increment metrics counters if(mother.isCalled() && father.isCalled() && child.isCalled()){ counters.put(NUM_TRIO_GENOTYPES_CALLED,counters.get(NUM_TRIO_GENOTYPES_CALLED)+1); if(mother.isPhased()) counters.put(NUM_TRIO_GENOTYPES_PHASED,counters.get(NUM_TRIO_GENOTYPES_PHASED)+1); else{ if(mvCount > 0){ if(mvCount >1) counters.put(NUM_TRIO_DOUBLE_VIOLATIONS,counters.get(NUM_TRIO_DOUBLE_VIOLATIONS)+1); else counters.put(NUM_TRIO_VIOLATIONS,counters.get(NUM_TRIO_VIOLATIONS)+1); } else if(mother.isHet() && father.isHet() && child.isHet()) counters.put(NUM_TRIO_HET_HET_HET,counters.get(NUM_TRIO_HET_HET_HET)+1); } }else{ counters.put(NUM_TRIO_GENOTYPES_NOCALL,counters.get(NUM_TRIO_GENOTYPES_NOCALL)+1); } }
/** * Return a VCF-like string representation for the alleles of this genotype. * * If ignoreRefState is true, will not append the reference * marker on the alleles. * * @return a string representing the genotypes, or null if the type is unavailable. */ @Ensures("result != null || ! isAvailable()") public String getGenotypeString(boolean ignoreRefState) { if ( getPloidy() == 0 ) return "NA"; // Notes: // 1. Make sure to use the appropriate separator depending on whether the genotype is phased // 2. If ignoreRefState is true, then we want just the bases of the Alleles (ignoring the '*' indicating a ref Allele) // 3. So that everything is deterministic with regards to integration tests, we sort Alleles (when the genotype isn't phased, of course) return ParsingUtils.join(isPhased() ? PHASED_ALLELE_SEPARATOR : UNPHASED_ALLELE_SEPARATOR, ignoreRefState ? getAlleleStrings() : (isPhased() ? getAlleles() : ParsingUtils.sortList(getAlleles()))); }
/** * Return a VCF-like string representation for the alleles of this genotype. * * If ignoreRefState is true, will not append the reference * marker on the alleles. * * @return a string representing the genotypes, or null if the type is unavailable. */ public String getGenotypeString(boolean ignoreRefState) { if ( getPloidy() == 0 ) return "NA"; // Notes: // 1. Make sure to use the appropriate separator depending on whether the genotype is phased final String separator = isPhased() ? PHASED_ALLELE_SEPARATOR : UNPHASED_ALLELE_SEPARATOR; // 2. If ignoreRefState is true, then we want just the bases of the Alleles (ignoring the '*' indicating a ref Allele) if (ignoreRefState) { return ParsingUtils.join(separator, getAlleleStrings()); } // 3. So that everything is deterministic with regards to integration tests, we sort Alleles (when the genotype isn't phased, of course) List<Allele> alleles = isPhased() ? getAlleles() : ParsingUtils.sortList(getAlleles()); return ParsingUtils.join(separator, alleles); }
/** * Return a VCF-like string representation for the alleles of this genotype. * * If ignoreRefState is true, will not append the reference * marker on the alleles. * * @return a string representing the genotypes, or null if the type is unavailable. */ public String getGenotypeString(boolean ignoreRefState) { if ( getPloidy() == 0 ) return "NA"; // Notes: // 1. Make sure to use the appropriate separator depending on whether the genotype is phased final String separator = isPhased() ? PHASED_ALLELE_SEPARATOR : UNPHASED_ALLELE_SEPARATOR; // 2. If ignoreRefState is true, then we want just the bases of the Alleles (ignoring the '*' indicating a ref Allele) if (ignoreRefState) { return ParsingUtils.join(separator, getAlleleStrings()); } // 3. So that everything is deterministic with regards to integration tests, we sort Alleles (when the genotype isn't phased, of course) List<Allele> alleles = isPhased() ? getAlleles() : ParsingUtils.sortList(getAlleles()); return ParsingUtils.join(separator, alleles); }
@Override public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException { final int samplePloidy = g.getPloidy(); for ( int i = 0; i < nValuesPerGenotype; i++ ) { if ( i < samplePloidy ) { // we encode the actual allele final Allele a = g.getAllele(i); final int offset = getAlleleOffset(a); final int encoded = ((offset+1) << 1) | ((g.isPhased() && i!=0) ? 0x01 : 0x00); encoder.encodeRawBytes(encoded, encodingType); } else { // we need to pad with missing as we have ploidy < max for this sample encoder.encodeRawBytes(encodingType.getMissingBytes(), encodingType); } } }
@Override public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException { final int samplePloidy = g.getPloidy(); for ( int i = 0; i < nValuesPerGenotype; i++ ) { if ( i < samplePloidy ) { // we encode the actual allele final Allele a = g.getAllele(i); final int offset = getAlleleOffset(a); final int encoded = ((offset+1) << 1) | (g.isPhased() ? 0x01 : 0x00); encoder.encodeRawBytes(encoded, encodingType); } else { // we need to pad with missing as we have ploidy < max for this sample encoder.encodeRawBytes(encodingType.getMissingBytes(), encodingType); } } }
@Override public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException { final int samplePloidy = g.getPloidy(); for ( int i = 0; i < nValuesPerGenotype; i++ ) { if ( i < samplePloidy ) { // we encode the actual allele final Allele a = g.getAllele(i); final int offset = getAlleleOffset(a); final int encoded = ((offset+1) << 1) | ((g.isPhased() && i!=0) ? 0x01 : 0x00); encoder.encodeRawBytes(encoded, encodingType); } else { // we need to pad with missing as we have ploidy < max for this sample encoder.encodeRawBytes(encodingType.getMissingBytes(), encodingType); } } }
.log10PError(log10Error) .attributes(genotypeAttributes) .phased(phasedGenotype.isPhased()).make();
if(fatherFAlleleFirst && trioPhasedGenotypes.get(FamilyMember.CHILD).isPhased()){ ArrayList<Allele> childAlleles = new ArrayList<Allele>(trioPhasedGenotypes.get(FamilyMember.CHILD).getAlleles()); childAlleles.add(childAlleles.remove(0));
if (currGenotype.isPhased() && currGenotype.getPloidy() > 1) { vcBuilder.setPhaseset("*");
public static void assertGenotypesAreEqual(final Genotype actual, final Genotype expected) { Assert.assertEquals(actual.getSampleName(), expected.getSampleName(), "Genotype names"); Assert.assertEquals(actual.getAlleles(), expected.getAlleles(), "Genotype alleles"); Assert.assertEquals(actual.getGenotypeString(), expected.getGenotypeString(), "Genotype string"); Assert.assertEquals(actual.getType(), expected.getType(), "Genotype type"); // filters are the same Assert.assertEquals(actual.getFilters(), expected.getFilters(), "Genotype fields"); Assert.assertEquals(actual.isFiltered(), expected.isFiltered(), "Genotype isFiltered"); // inline attributes Assert.assertEquals(actual.getDP(), expected.getDP(), "Genotype dp"); Assert.assertTrue(Arrays.equals(actual.getAD(), expected.getAD())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype gq"); Assert.assertEquals(actual.hasPL(), expected.hasPL(), "Genotype hasPL"); Assert.assertEquals(actual.hasAD(), expected.hasAD(), "Genotype hasAD"); Assert.assertEquals(actual.hasGQ(), expected.hasGQ(), "Genotype hasGQ"); Assert.assertEquals(actual.hasDP(), expected.hasDP(), "Genotype hasDP"); Assert.assertEquals(actual.hasLikelihoods(), expected.hasLikelihoods(), "Genotype haslikelihoods"); Assert.assertEquals(actual.getLikelihoodsString(), expected.getLikelihoodsString(), "Genotype getlikelihoodsString"); Assert.assertEquals(actual.getLikelihoods(), expected.getLikelihoods(), "Genotype getLikelihoods"); Assert.assertTrue(Arrays.equals(actual.getPL(), expected.getPL())); Assert.assertEquals(actual.getPhredScaledQual(), expected.getPhredScaledQual(), "Genotype phredScaledQual"); assertAttributesEquals(actual.getExtendedAttributes(), expected.getExtendedAttributes()); Assert.assertEquals(actual.isPhased(), expected.isPhased(), "Genotype isPhased"); Assert.assertEquals(actual.getPloidy(), expected.getPloidy(), "Genotype getPloidy"); }
public static void assertEquals(final Genotype actual, final Genotype expected) { Assert.assertEquals(actual.getSampleName(), expected.getSampleName(), "Genotype names"); Assert.assertEquals(actual.getAlleles(), expected.getAlleles(), "Genotype alleles"); Assert.assertEquals(actual.getGenotypeString(), expected.getGenotypeString(), "Genotype string"); Assert.assertEquals(actual.getType(), expected.getType(), "Genotype type"); // filters are the same Assert.assertEquals(actual.getFilters(), expected.getFilters(), "Genotype fields"); Assert.assertEquals(actual.isFiltered(), expected.isFiltered(), "Genotype isFiltered"); // inline attributes Assert.assertEquals(actual.getDP(), expected.getDP(), "Genotype dp"); Assert.assertTrue(Arrays.equals(actual.getAD(), expected.getAD())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype gq"); Assert.assertEquals(actual.hasPL(), expected.hasPL(), "Genotype hasPL"); Assert.assertEquals(actual.hasAD(), expected.hasAD(), "Genotype hasAD"); Assert.assertEquals(actual.hasGQ(), expected.hasGQ(), "Genotype hasGQ"); Assert.assertEquals(actual.hasDP(), expected.hasDP(), "Genotype hasDP"); Assert.assertEquals(actual.hasLikelihoods(), expected.hasLikelihoods(), "Genotype haslikelihoods"); Assert.assertEquals(actual.getLikelihoodsString(), expected.getLikelihoodsString(), "Genotype getlikelihoodsString"); Assert.assertEquals(actual.getLikelihoods(), expected.getLikelihoods(), "Genotype getLikelihoods"); Assert.assertTrue(Arrays.equals(actual.getPL(), expected.getPL())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype phredScaledQual"); assertAttributesEquals(actual.getExtendedAttributes(), expected.getExtendedAttributes()); Assert.assertEquals(actual.isPhased(), expected.isPhased(), "Genotype isPhased"); Assert.assertEquals(actual.getPloidy(), expected.getPloidy(), "Genotype getPloidy"); }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }