/** * What is the ploidy of this sample? * * @return the ploidy of this genotype. 0 if the site is no-called. */ public int getPloidy() { return getAlleles().size(); }
/** * What is the ploidy of this sample? * * @return the ploidy of this genotype. 0 if the site is no-called. */ public int getPloidy() { return getAlleles().size(); }
/** Tests whether the alleles of the offspring are possible given the alleles of the parents. */ private boolean isMendelianViolation(final Genotype p1, final Genotype p2, final Genotype off) { final Allele offAllele1 = off.getAllele(0); final Allele offAllele2 = off.getAllele(1); if(p1.getAlleles().contains(offAllele1) && p2.getAlleles().contains(offAllele2)) return false; if(p2.getAlleles().contains(offAllele1) && p1.getAlleles().contains(offAllele2)) return false; return true; }
/** Tests whether the alleles of the offspring are possible given the alleles of the parents. */ private boolean isMendelianViolation(final Genotype p1, final Genotype p2, final Genotype off) { final Allele offAllele1 = off.getAllele(0); final Allele offAllele2 = off.getAllele(1); if(p1.getAlleles().contains(offAllele1) && p2.getAlleles().contains(offAllele2)) return false; if(p2.getAlleles().contains(offAllele1) && p1.getAlleles().contains(offAllele2)) return false; return true; }
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; }
public boolean sameGenotype(final Genotype other, boolean ignorePhase) { if (getPloidy() != other.getPloidy()) return false; // gotta have the same number of allele to be equal // By default, compare the elements in the lists of alleles, element-by-element Collection<Allele> thisAlleles = this.getAlleles(); Collection<Allele> otherAlleles = other.getAlleles(); if (ignorePhase) { // do not care about order, only identity of Alleles thisAlleles = new TreeSet<Allele>(thisAlleles); //implemented Allele.compareTo() otherAlleles = new TreeSet<Allele>(otherAlleles); } return thisAlleles.equals(otherAlleles); }
private ArrayList<Double> calculateMLEAlleleFrequencies(List<Integer> alleleCountsofMLE, GenotypesContext genotypes) { int AN = 0; for (final Genotype g : genotypes) for (final Allele a : g.getAlleles()) if (!a.isNoCall()) AN++; final ArrayList<Double> MLEfrequencies = new ArrayList<>(alleleCountsofMLE.size()); // the MLEAC is allowed to be larger than the AN (e.g. in the case of all PLs being 0, the GT is ./. but the exact model may arbitrarily choose an AC>1) for (final int AC : alleleCountsofMLE ) MLEfrequencies.add(Math.min(1.0, (double)AC / (double)AN)); return MLEfrequencies; }
public boolean sameGenotype(final Genotype other, boolean ignorePhase) { if (getPloidy() != other.getPloidy()) return false; // gotta have the same number of allele to be equal // By default, compare the elements in the lists of alleles, element-by-element Collection<Allele> thisAlleles = this.getAlleles(); Collection<Allele> otherAlleles = other.getAlleles(); if (ignorePhase) { // do not care about order, only identity of Alleles thisAlleles = new TreeSet<Allele>(thisAlleles); //implemented Allele.compareTo() otherAlleles = new TreeSet<Allele>(otherAlleles); } return thisAlleles.equals(otherAlleles); }
public boolean sameGenotype(final Genotype other, boolean ignorePhase) { if (getPloidy() != other.getPloidy()) return false; // gotta have the same number of allele to be equal // By default, compare the elements in the lists of alleles, element-by-element Collection<Allele> thisAlleles = this.getAlleles(); Collection<Allele> otherAlleles = other.getAlleles(); if (ignorePhase) { // do not care about order, only identity of Alleles thisAlleles = new TreeSet<Allele>(thisAlleles); //implemented Allele.compareTo() otherAlleles = new TreeSet<Allele>(otherAlleles); } return thisAlleles.equals(otherAlleles); }
/** * What is the ploidy of this sample? * * @return the ploidy of this genotype. 0 if the site is no-called. */ @Ensures("result >= 0") public int getPloidy() { return getAlleles().size(); }
/** * Returns how many times allele appears in this genotype object? * * @param allele * @return a value >= 0 indicating how many times the allele occurred in this sample's genotype */ public int countAllele(final Allele allele) { int c = 0; for ( final Allele a : getAlleles() ) if ( a.equals(allele) ) c++; return c; }
public List<org.broad.igv.variant.Allele> getAlleles() { if (alleles == null) { alleles = new ArrayList<org.broad.igv.variant.Allele>(); List<htsjdk.variant.variantcontext.Allele> tmp = vcfGenotype.getAlleles(); if (tmp != null) { for (Allele a : tmp) { alleles.add(new VCFAllele(a.getBases())); } } } return alleles; }
/** * Utility that returns a list of allele strings corresponding to the alleles in this sample * @return */ protected List<String> getAlleleStrings() { final List<String> al = new ArrayList<String>(getPloidy()); for ( Allele a : getAlleles() ) al.add(a.getBaseString()); return al; }
/** * Utility that returns a list of allele strings corresponding to the alleles in this sample * @return */ protected List<String> getAlleleStrings() { final List<String> al = new ArrayList<String>(getPloidy()); for ( Allele a : getAlleles() ) al.add(a.getBaseString()); return al; }
/** * Utility that returns a list of allele strings corresponding to the alleles in this sample * @return */ protected List<String> getAlleleStrings() { final List<String> al = new ArrayList<String>(getPloidy()); for ( Allele a : getAlleles() ) al.add(a.getBaseString()); return al; }
private void validateGenotypes() { if ( this.genotypes == null ) throw new IllegalStateException("Genotypes is null"); for ( final Genotype g : this.genotypes ) { if ( g.isAvailable() ) { for ( Allele gAllele : g.getAlleles() ) { if ( ! hasAllele(gAllele) && gAllele.isCalled() ) throw new IllegalStateException("Allele in genotype " + gAllele + " not in the variant context " + alleles); } } } }
private boolean haveSameGenotypes(final Genotype g1, final Genotype g2) { if ( g1 == null || g2 == null ) return false; if ((g1.isCalled() && g2.isFiltered()) || (g2.isCalled() && g1.isFiltered()) || (g1.isFiltered() && g2.isFiltered() && XLfiltered)) return false; List<Allele> a1s = g1.getAlleles(); List<Allele> a2s = g2.getAlleles(); return (a1s.containsAll(a2s) && a2s.containsAll(a1s)); } @Override
public void calculateRawData(final VariantContext vc, final Map<String, PerReadAlleleLikelihoodMap> pralm, final ReducibleAnnotationData myData) { if( vc.getGenotypes().getSampleNames().size() != 1) throw new IllegalStateException("Calculating raw data for allele-specific rank sums requires variant context input with exactly one sample, as in a gVCF."); if(pralm == null) return; final Map<Allele, CompressedDataList<Integer>> perAlleleValues = myData.getAttributeMap(); for ( final PerReadAlleleLikelihoodMap likelihoodMap : pralm.values() ) { if ( likelihoodMap != null && !likelihoodMap.isEmpty() ) { fillQualsFromLikelihoodMap(vc.getGenotype(0).getAlleles(), vc.getStart(), likelihoodMap, perAlleleValues); } } }
public static void assertEquals(final GenotypesContext actual, final GenotypesContext expected) { if (expected == null) { Assert.assertNull(actual); return; } Assert.assertEquals(actual.getSampleNamesOrderedByName(), expected.getSampleNamesOrderedByName(), "Sample names differ"); for (final String name : expected.getSampleNamesOrderedByName()) { Assert.assertEquals(actual.get(name).getAlleles(), expected.get(name).getAlleles(), "Alleles differ for sample " + name); Assert.assertEquals(actual.get(name).getAD(), expected.get(name).getAD()); Assert.assertEquals(actual.get(name).getPL(), expected.get(name).getPL()); } }
@Requires("originalGenotypes != null && alleleMapper != null") protected static GenotypesContext updateGenotypesWithMappedAlleles(final GenotypesContext originalGenotypes, final AlleleMapper alleleMapper) { final GenotypesContext updatedGenotypes = GenotypesContext.create(originalGenotypes.size()); for ( final Genotype genotype : originalGenotypes ) { final List<Allele> updatedAlleles = alleleMapper.remap(genotype.getAlleles()); updatedGenotypes.add(new GenotypeBuilder(genotype).alleles(updatedAlleles).make()); } return updatedGenotypes; }