/** Tests to ensure that a locus is bi-allelic within the given set of samples. */ private boolean isVariant(final Genotype... gts) { for (final Genotype gt : gts) { if (gt.isCalled() && !gt.isHomRef()) return true; } return false; }
/** * Provides the next record from the underlying iterator after applying filter strings generated * by the set of filters in use by the iterator. */ @Override public VariantContext next() { final VariantContext ctx = this.iterator.next(); final Set<String> filterStrings = new HashSet<String>(); // Collect variant level filters for (final VariantFilter filter : this.filters) { final String val = filter.filter(ctx); if (val != null) filterStrings.add(val); } // Collect genotype level filters in a Map of Sample -> List<filter string> final ListMap<String, String> gtFilterStrings = new ListMap<String, String>(); final Set<String> variantSamples = new HashSet<String>(); for (final Genotype gt : ctx.getGenotypes()) { if (gt.isCalled() && !gt.isHomRef()) variantSamples.add(gt.getSampleName()); for (final GenotypeFilter filter : gtFilters) { final String filterString = filter.filter(ctx, gt); if (filterString != null) gtFilterStrings.add(gt.getSampleName(), filterString); } } // If all genotypes are filtered apply a site level filter if (gtFilterStrings.keySet().containsAll(variantSamples)) { filterStrings.add(ALL_GTS_FILTERED); } // Make a builder and set the site level filter appropriately final VariantContextBuilder builder = new VariantContextBuilder(ctx); if (filterStrings.isEmpty()) { builder.passFilters(); } else { builder.filters(filterStrings); } // Apply filters to the necessary genotypes builder.noGenotypes(); final List<Genotype> newGenotypes = new ArrayList<Genotype>(ctx.getNSamples()); for (final Genotype gt : ctx.getGenotypes()) { final GenotypeBuilder gtBuilder = new GenotypeBuilder(gt); final List<String> filtersLocal = gtFilterStrings.get(gt.getSampleName()); if (filtersLocal == null || filtersLocal.isEmpty()) { gtBuilder.filter(PASS_FILTER); } else { gtBuilder.filters(filtersLocal); } newGenotypes.add(gtBuilder.make()); } builder.genotypes(newGenotypes); return builder.make(); }
private void addVariant(final VariantContext ctx) { if (!ctx.getChr().equals(genes.get(0).getChromosome())) return; if (ctx.getStart() >= chromEnd) return; if (ctx.getStart() < chromStart) return; positions.add(ctx.getStart()); for (String sample : ctx.getSampleNames()) { Genotype g = ctx.getGenotype(sample); if (!g.isAvailable()) continue; if (!g.isCalled()) continue; if (g.isNoCall()) continue; if (g.isNonInformative()) continue; Set<Integer> set = sample2positions.get(sample); if (set == null) { set = new HashSet<Integer>(); sample2positions.put(sample, set); } set.add(ctx.getStart()); } }
/** * Checks if the input data is appropriate * * @param annotation the input genotype annotation key name(s) * @param walker input walker * @param map input map for each read, holds underlying alleles represented by an aligned read, * and corresponding relative likelihood. * @param g input genotype * @param warningsLogged array that enforces the warning is logged once for each caller * @param logger logger specific for each caller * @return true if the walker is a HaplotypeCaller, the likelihood map is non-null and the * genotype is non-null and called, false otherwise * @throws IllegalArgumentException if annotation, walker, g, warningsLogged, or logger are null. * @throws ReviewedGATKException if the size of warningsLogged is less than 3. */ public static boolean isAppropriateInput( final String annotation, final AnnotatorCompatible walker, final PerReadAlleleLikelihoodMap map, final Genotype g, final boolean[] warningsLogged, final Logger logger) { if (annotation == null) { throw new IllegalArgumentException("The input annotation cannot be null"); } if (walker == null) { throw new IllegalArgumentException("The input walker cannot be null"); } if (g == null) { throw new IllegalArgumentException("The input genotype cannot be null"); } if (warningsLogged == null) { throw new IllegalArgumentException("The input warnings logged cannot be null"); } if (logger == null) { throw new IllegalArgumentException("The input logger cannot be null"); } if (warningsLogged.length < WARNINGS_LOGGED_SIZE) { throw new ReviewedGATKException( "Warnings logged array must have at least " + WARNINGS_LOGGED_SIZE + " elements, but has " + warningsLogged.length); } if (!(walker instanceof HaplotypeCaller) && !(walker instanceof MuTect2)) { if (!warningsLogged[0]) { logger.warn( annotation + ANNOTATION_HC_WARN_MSG + ", not " + walker.getClass().getSimpleName()); warningsLogged[0] = true; } return false; } if (map == null) { if (!warningsLogged[1]) { logger.warn( "Annotation will not be calculated, can only be used with likelihood based annotations in the HaplotypeCaller"); warningsLogged[1] = true; } return false; } if (!g.isCalled()) { if (!warningsLogged[2]) { logger.warn("Annotation will not be calculated, genotype is not called"); warningsLogged[2] = true; } return false; } return true; }