public void setRef(Allele refAllele, X newValue){ if (refAllele == null || newValue == null){ throw new IllegalArgumentException("refAllele or newValue is null"); } if (refAllele.isNonReference()){ throw new IllegalArgumentException("Setting Non-reference allele as reference"); } if (this.refAllele.isPresent()){ throw new IllegalArgumentException("Resetting the reference allele not permitted"); } this.refAllele = Optional.of(refAllele); this.refValue = Optional.of(newValue); }
/** * Set the list of alleles used in genotyping * * @param allelesUsedInGenotyping the list of alleles, where the first allele is reference */ @Requires({"allelesUsedInGenotyping != null", "allelesUsedInGenotyping.size() > 1"}) protected void setAllelesUsedInGenotyping(List<Allele> allelesUsedInGenotyping) { if ( allelesUsedInGenotyping == null || allelesUsedInGenotyping.isEmpty() ) throw new IllegalArgumentException("allelesUsedInGenotyping cannot be null or empty"); if ( allelesUsedInGenotyping.get(0).isNonReference() ) throw new IllegalArgumentException("The first element of allelesUsedInGenotyping must be the reference allele"); this.allelesUsedInGenotyping = allelesUsedInGenotyping; }
/** * @return true if we're het (observed alleles differ) and neither allele is reference; if the ploidy is less than 2 or if any alleles are no-calls, this method will return false. */ public boolean isHetNonRef() { return (getType() == GenotypeType.HET && getAllele(0).isNonReference() && getAllele(1).isNonReference()); }
/** * @return true if we're het (observed alleles differ) and neither allele is reference; if the ploidy is less than 2 or if any alleles are no-calls, this method will return false. */ public boolean isHetNonRef() { return (getType() == GenotypeType.HET && getAllele(0).isNonReference() && getAllele(1).isNonReference()); }
/** * @return true if we're het (observed alleles differ) and neither allele is reference; if the ploidy is less than 2 or if any alleles are no-calls, this method will return false. */ public boolean isHetNonRef() { return (getType() == GenotypeType.HET && getAllele(0).isNonReference() && getAllele(1).isNonReference()); }
@Override public int compareTo(final Allele other) { if ( isReference() && other.isNonReference() ) return -1; else if ( isNonReference() && other.isReference() ) return 1; else return getBaseString().compareTo(other.getBaseString()); // todo -- potential performance issue }
public int compareTo(Allele other) { if ( isReference() && other.isNonReference() ) return -1; else if ( isNonReference() && other.isReference() ) return 1; else return getBaseString().compareTo(other.getBaseString()); // todo -- potential performance issue }
private static List<Allele> makeAlleles(Collection<Allele> alleles) { final List<Allele> alleleList = new ArrayList<>(alleles.size()); boolean sawRef = false; for ( final Allele a : alleles ) { for (int i = 0, alleleListSize = alleleList.size(); i < alleleListSize; i++) { if (a.equals(alleleList.get(i), true)) { throw new IllegalArgumentException("Duplicate allele added to VariantContext: " + a); } } // deal with the case where the first allele isn't the reference if ( a.isReference() ) { if ( sawRef ) throw new IllegalArgumentException("Alleles for a VariantContext must contain at most one reference allele: " + alleles); alleleList.add(0, a); sawRef = true; } else alleleList.add(a); } if ( alleleList.isEmpty() ) throw new IllegalArgumentException("Cannot create a VariantContext with an empty allele list"); if ( alleleList.get(0).isNonReference() ) throw new IllegalArgumentException("Alleles for a VariantContext must contain at least one reference allele: " + alleles); return alleleList; }
@Override public int compareTo(final AlleleScoredByHaplotypeScores other) { if(allele.isReference() && other.allele.isNonReference()){ return -1; } else if(allele.isNonReference() && other.allele.isReference()){ return 1; } else if(bestHaplotypeScore > other.bestHaplotypeScore) { return -1; } else if (bestHaplotypeScore < other.bestHaplotypeScore) { return 1; } else if (!secondBestHaplotypeScore.equals(other.secondBestHaplotypeScore)) { return secondBestHaplotypeScore > other.secondBestHaplotypeScore ? -1 : 1; } else { return allele.compareTo(other.allele); } }
@Override public int compareTo(final Allele other) { if ( isReference() && other.isNonReference() ) return -1; else if ( isNonReference() && other.isReference() ) return 1; else return getBaseString().compareTo(other.getBaseString()); // todo -- potential performance issue }
public static int getEventLength(List<Allele> alleleList) { Allele refAllele = alleleList.get(0); Allele altAllele = alleleList.get(1); // look for alt allele that has biggest length distance to ref allele int maxLenDiff = 0; for (Allele a : alleleList) { if (a.isNonReference()) { int lenDiff = Math.abs(a.getBaseString().length() - refAllele.getBaseString().length()); if (lenDiff > maxLenDiff) { maxLenDiff = lenDiff; altAllele = a; } } } return altAllele.getBaseString().length() - refAllele.getBaseString().length(); }
/** * Are any of the alleles polymorphic w.r.t. #isPolymorphic? * * @param log10minPNonRef the confidence threshold, in log10 space * @return true if any are poly, false otherwise */ public boolean anyPolymorphic(final double log10minPNonRef) { for ( final Allele a : getAllelesUsedInGenotyping() ) if ( a.isNonReference() && isPolymorphic(a, log10minPNonRef) ) return true; return false; }
@Override public String toString() { final List<String> byAllele = new LinkedList<String>(); for ( final Allele a : getAllelesUsedInGenotyping() ) if ( a.isNonReference() ) byAllele.add(String.format("%s => MLE %d / posterior %.2f", a, getAlleleCountAtMLE(a), getLog10PosteriorOfAFEq0ForAllele(a))); return String.format("AFCalc%n\t\tlog10PosteriorOfAFGT0=%.2f%n\t\t%s", getLog10LikelihoodOfAFGT0(), Utils.join("\n\t\t", byAllele)); }
/** * Check if some samples have double alternate alleles * * @param vc1 variant context 1 * @param vc2 variant context 2 * @return true if there is a sample with double alternate alleles, false otherwise */ static boolean someSampleHasDoubleNonReferenceAllele(VariantContext vc1, VariantContext vc2) { for (final Genotype gt1 : vc1.getGenotypes()) { // gt2 from the same sample as gt1 final Genotype gt2 = vc2.getGenotype(gt1.getSampleName()); if ( gt2 != null ) { // Find the alleles with the same haplotype final SameHaplotypeAlleles hapAlleles = matchHaplotypeAlleles(gt1, gt2); // Find corresponding alternate alleles for (AlleleOneAndTwo all1all2 : hapAlleles.hapAlleles) { if (all1all2.all1.isNonReference() && all1all2.all2.isNonReference()) return true; } } } return false; }
@Test public void testCreatingSpanningDeletionAlleles() { Assert.assertTrue(SpandDel.isNonReference()); Assert.assertFalse(SpandDel.isReference()); Assert.assertTrue(SpandDel.basesMatch(Allele.SPAN_DEL_STRING)); Assert.assertEquals(SpandDel.length(), 1); }
private static AlleleCall determineAlleleCall(Allele altAllele, Allele allele) { if (allele.isNoCall()) { return AlleleCall.NO_CALL; } if (allele.isReference()) { return AlleleCall.REF; } // this is the key bit - we've originally split the VCF into single ref/alt alleles so that: // CHR POS REF ALT GT // VCF: 1 12345 A T,C 1/2 // becomes two variant alleles: // 1 12345 A T -/1 (altAlleleId = 0) // 1 12345 A C -/1 (altAlleleId = 1) // so a heterozygous non-ref genotype 1/2 should become two hets - one for each alt allele *where the alt allele matches* //so the -/1 genotype represents a split genotype where '-' means 'present, but in another allele' if (allele.isNonReference() && allele.equals(altAllele)) { return AlleleCall.ALT; } //does this make sense for symbolic? return AlleleCall.OTHER_ALT; }
@Test public void testCreatingNoCallAlleles() { Assert.assertTrue(NoCall.isNonReference()); Assert.assertFalse(NoCall.isReference()); Assert.assertFalse(NoCall.basesMatch(Allele.NO_CALL_STRING)); Assert.assertEquals(NoCall.length(), 0); Assert.assertTrue(NoCall.isNoCall()); Assert.assertFalse(NoCall.isCalled()); }
@Test public void testIncrementChromosomeCountsInfo() { final Map<Allele, Integer> calledAltAlleles = new LinkedHashMap<>(); final Map<Allele, Integer> expectedCalledAltAlleles = new LinkedHashMap<>(); final List<Allele> alleles = new ArrayList<>(Arrays.asList(Aref, C)); for ( final Allele allele : alleles ) { if ( allele.isNonReference() ) { calledAltAlleles.put(allele, 0); expectedCalledAltAlleles.put(allele, 1); } } int calledAlleles = 0; final Genotype genotype = new GenotypeBuilder().alleles(alleles).make(); calledAlleles = GATKVariantContextUtils.incrementChromosomeCountsInfo(calledAltAlleles, calledAlleles, genotype); Assert.assertEquals(calledAlleles, alleles.size()); Assert.assertEquals(calledAltAlleles, expectedCalledAltAlleles); }
@Test public void testCreatingSNPAlleles() { Assert.assertTrue(A.isNonReference()); Assert.assertFalse(A.isReference()); Assert.assertTrue(A.basesMatch("A")); Assert.assertEquals(A.length(), 1); Assert.assertTrue(ARef.isReference()); Assert.assertFalse(ARef.isNonReference()); Assert.assertTrue(ARef.basesMatch("A")); Assert.assertFalse(ARef.basesMatch("T")); Assert.assertTrue(T.isNonReference()); Assert.assertFalse(T.isReference()); Assert.assertTrue(T.basesMatch("T")); Assert.assertFalse(T.basesMatch("A")); }
@Test public void testUpdateChromosomeCountsInfo() { final Map<Allele, Integer> calledAltAlleles = new LinkedHashMap<>(); final Set<Double> alleleFrequency = new LinkedHashSet<Double>(calledAltAlleles.size()); final List<Allele> alleles = new ArrayList<>(Arrays.asList(Aref, C)); final int calledAlleles = alleles.size(); final List<Integer> numAltAlleles = new ArrayList<>(); final int alleleOccurence = 1; for ( final Allele allele : alleles ) { if ( allele.isNonReference() ) { calledAltAlleles.put(allele, alleleOccurence); alleleFrequency.add( ((double) alleleOccurence)/calledAlleles ); numAltAlleles.add(1); } } final VariantContextBuilder builder = new VariantContextBuilder("test", "chr1", 1, Aref.length(), alleles); GATKVariantContextUtils.updateChromosomeCountsInfo(calledAltAlleles, calledAlleles, builder); final VariantContext vc = builder.make(); Assert.assertEquals(vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY), numAltAlleles.toArray()); Assert.assertEquals(vc.getAttribute(VCFConstants.ALLELE_NUMBER_KEY), alleles.size()); Assert.assertEquals(vc.getAttribute(VCFConstants.ALLELE_FREQUENCY_KEY), alleleFrequency.toArray()); }