public int[] getGLIndecesOfAlternateAllele(Allele targetAllele) { int index = 1; for (Allele allele : getAlternateAlleles()) { if (allele.equals(targetAllele)) break; index++; } return GenotypeLikelihoods.getPLIndecesOfAlleles(0, index); }
private static void addGenotypesAndGTests() { // for ( final int ploidy : Arrays.asList(2)) { for (final int ploidy : Arrays.asList(1, 2, 3, 4, 5)) { final List<List<String>> alleleCombinations = Arrays.asList( Arrays.asList("A"), Arrays.asList("A", "C"), Arrays.asList("A", "C", "G"), Arrays.asList("A", "C", "G", "T")); for (final List<String> alleles : alleleCombinations) { final VariantContextBuilder vcb = builder().alleles(alleles); final VariantContext site = vcb.make(); final int nAlleles = site.getNAlleles(); final Allele ref = site.getReference(); // base genotype is ref/.../ref up to ploidy final List<Allele> baseGenotype = new ArrayList<Allele>(ploidy); for (int i = 0; i < ploidy; i++) baseGenotype.add(ref); final int nPLs = GenotypeLikelihoods.numLikelihoods(nAlleles, ploidy); // ada is 0, 1, ..., nAlleles - 1 final List<Integer> ada = new ArrayList<Integer>(nAlleles); for (int i = 0; i < nAlleles - 1; i++) ada.add(i); // pl is 0, 1, ..., up to nPLs (complex calc of nAlleles and ploidy) final int[] pl = new int[nPLs]; for (int i = 0; i < pl.length; i++) pl[i] = i; final GenotypeBuilder gb = new GenotypeBuilder("ADA_PL_SAMPLE"); gb.alleles(baseGenotype); gb.PL(pl); gb.attribute("ADA", nAlleles == 2 ? ada.get(0) : ada); vcb.genotypes(gb.make()); add(vcb); } } }
/** * Read in a list of ExactCall objects from reader, keeping only those with starts in startsToKeep * or all sites (if this is empty) * * @param reader a just-opened reader sitting at the start of the file * @param startsToKeep a list of start position of the calls to keep, or empty if all calls should * be kept * @param parser a genome loc parser to create genome locs * @return a list of ExactCall objects in reader * @throws IOException */ public static List<ExactCall> readExactLog( final BufferedReader reader, final List<Integer> startsToKeep, GenomeLocParser parser) throws IOException { if (reader == null) throw new IllegalArgumentException("reader cannot be null"); if (startsToKeep == null) throw new IllegalArgumentException("startsToKeep cannot be null"); if (parser == null) throw new IllegalArgumentException("GenomeLocParser cannot be null"); List<ExactCall> calls = new LinkedList<ExactCall>(); // skip the header line reader.readLine(); // skip the first "type" line reader.readLine(); while (true) { final VariantContextBuilder builder = new VariantContextBuilder(); final List<Allele> alleles = new ArrayList<Allele>(); final List<Genotype> genotypes = new ArrayList<Genotype>(); final double[] posteriors = new double[2]; final double[] priors = MathUtils.normalizeFromLog10(new double[] {0.5, 0.5}, true); final List<Integer> mle = new ArrayList<Integer>(); final Map<Allele, Double> log10pNonRefByAllele = new HashMap<Allele, Double>(); long runtimeNano = -1; GenomeLoc currentLoc = null; while (true) { final String line = reader.readLine(); if (line == null) return calls; final String[] parts = line.split("\t"); final GenomeLoc lineLoc = parser.parseGenomeLoc(parts[0]); final String variable = parts[1]; final String key = parts[2]; final String value = parts[3]; if (currentLoc == null) currentLoc = lineLoc; if (variable.equals("type")) { if (startsToKeep.isEmpty() || startsToKeep.contains(currentLoc.getStart())) { builder.alleles(alleles); final int stop = currentLoc.getStart() + alleles.get(0).length() - 1; builder.chr(currentLoc.getContig()).start(currentLoc.getStart()).stop(stop); builder.genotypes(genotypes); final int[] mleInts = ArrayUtils.toPrimitive(mle.toArray(new Integer[] {})); final AFCalcResult result = new AFCalcResult(mleInts, 1, alleles, posteriors, priors, log10pNonRefByAllele); calls.add(new ExactCall(builder.make(), runtimeNano, result)); } break; } else if (variable.equals("allele")) { final boolean isRef = key.equals("0"); alleles.add(Allele.create(value, isRef)); } else if (variable.equals("PL")) { final GenotypeBuilder gb = new GenotypeBuilder(key); gb.PL(GenotypeLikelihoods.fromPLField(value).getAsPLs()); genotypes.add(gb.make()); } else if (variable.equals("log10PosteriorOfAFEq0")) { posteriors[0] = Double.valueOf(value); } else if (variable.equals("log10PosteriorOfAFGt0")) { posteriors[1] = Double.valueOf(value); } else if (variable.equals("MLE")) { mle.add(Integer.valueOf(value)); } else if (variable.equals("pNonRefByAllele")) { final Allele a = Allele.create(key); log10pNonRefByAllele.put(a, Double.valueOf(value)); } else if (variable.equals("runtime.nano")) { runtimeNano = Long.valueOf(value); } else { // nothing to do } } } }