Java Code Examples for htsjdk.variant.variantcontext.Genotype#isFiltered()
The following examples show how to use
htsjdk.variant.variantcontext.Genotype#isFiltered() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectVariants.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the genotype filters * * @param vc the variant context * @param g the genotype * @return list of genotype filter names */ private List<String> getGenotypeFilters(final VariantContext vc, final Genotype g) { final List<String> filters = new ArrayList<>(); if (g.isFiltered()) { filters.add(g.getFilters()); } return filters; }
Example 2
Source File: SelectVariants.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; } final List<Allele> a1s = g1.getAlleles(); final List<Allele> a2s = g2.getAlleles(); return (a1s.containsAll(a2s) && a2s.containsAll(a1s)); }
Example 3
Source File: GenotypeFilterSummary.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void update1(VariantContext eval, ReferenceContext referenceContext, ReadsContext readsContext, FeatureContext featureContext) { Iterator<Genotype> it = eval.getGenotypes().iterator(); while (it.hasNext()){ Genotype g = it.next(); if (g.isCalled() && !g.isFiltered()){ nCalledNotFiltered++; } else if (g.isNoCall() || g.isFiltered()){ nNoCallOrFiltered++; } } }
Example 4
Source File: VcfToVariant.java From genomewarp with Apache License 2.0 | 4 votes |
@VisibleForTesting static List<VariantCall> getCalls(VariantContext vc, VCFHeader header) { List<VariantCall> toReturn = new ArrayList<>(); for (String currSample : header.getGenotypeSamples()) { if (!vc.hasGenotype(currSample)) { continue; } Genotype currGenotype = vc.getGenotype(currSample); VariantCall.Builder vcBuilder = VariantCall.newBuilder(); vcBuilder.setCallSetName(currSample); // Get GT info. final Map<Allele, Integer> alleleStrings = buildAlleleMap(vc); vcBuilder.addGenotype(alleleStrings.get(currGenotype.getAllele(0))); for (int i = 1; i < currGenotype.getPloidy(); i++) { vcBuilder.addGenotype(alleleStrings.get(currGenotype.getAllele(i))); } // Set phasing (not applicable to haploid). if (currGenotype.isPhased() && currGenotype.getPloidy() > 1) { vcBuilder.setPhaseset("*"); } // Get rest of the genotype info. Map<String, ListValue> genotypeInfo = new HashMap<>(); // Set filters if (currGenotype.isFiltered()) { genotypeInfo.put(VCFConstants.GENOTYPE_FILTER_KEY, ListValue.newBuilder() .addValues(Value.newBuilder().setStringValue(currGenotype.getFilters()).build()) .build()); } for (final String field : vc.calcVCFGenotypeKeys(header)) { // We've already handled genotype if (field.equals(VCFConstants.GENOTYPE_KEY)) { continue; } ListValue.Builder listValueBuilder = ListValue.newBuilder(); if (field.equals(VCFConstants.GENOTYPE_FILTER_KEY)) { // This field has already been dealt with continue; } else { final IntGenotypeFieldAccessors.Accessor accessor = GENOTYPE_FIELD_ACCESSORS.getAccessor(field); if (accessor != null) { // The field is a default inline field. if (!parseInlineGenotypeFields(field, vcBuilder, listValueBuilder, accessor, currGenotype)) { continue; } } else { // Other field, we'll get type/other info from header. if (!parseOtherGenotypeFields(field, vc, listValueBuilder, currGenotype, header)) { continue; } } } genotypeInfo.put(field, listValueBuilder.build()); } vcBuilder.putAllInfo(genotypeInfo); toReturn.add(vcBuilder.build()); } return toReturn; }
Example 5
Source File: SelectVariants.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
private boolean sampleHasVariant(final Genotype g) { return (g !=null && !g.isHomRef() && (g.isCalled() || (g.isFiltered() && !XLfiltered))); }
Example 6
Source File: SelectVariants.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void addAnnotations(final VariantContextBuilder builder, final VariantContext originalVC, final Set<String> selectedSampleNames) { if (fullyDecode) { return; // TODO -- annotations are broken with fully decoded data } if (keepOriginalChrCounts) { final int[] indexOfOriginalAlleleForNewAllele; final List<Allele> newAlleles = builder.getAlleles(); final int numOriginalAlleles = originalVC.getNAlleles(); // if the alleles already match up, we can just copy the previous list of counts if (numOriginalAlleles == newAlleles.size()) { indexOfOriginalAlleleForNewAllele = null; } // otherwise we need to parse them and select out the correct ones else { indexOfOriginalAlleleForNewAllele = new int[newAlleles.size() - 1]; Arrays.fill(indexOfOriginalAlleleForNewAllele, -1); // note that we don't care about the reference allele at position 0 for (int newI = 1; newI < newAlleles.size(); newI++) { final Allele newAlt = newAlleles.get(newI); for (int oldI = 0; oldI < numOriginalAlleles - 1; oldI++) { if (newAlt.equals(originalVC.getAlternateAllele(oldI), false)) { indexOfOriginalAlleleForNewAllele[newI - 1] = oldI; break; } } } } if (originalVC.hasAttribute(VCFConstants.ALLELE_COUNT_KEY)) { builder.attribute(GATKVCFConstants.ORIGINAL_AC_KEY, getReorderedAttributes(originalVC.getAttribute(VCFConstants.ALLELE_COUNT_KEY), indexOfOriginalAlleleForNewAllele)); } if (originalVC.hasAttribute(VCFConstants.ALLELE_FREQUENCY_KEY)) { builder.attribute(GATKVCFConstants.ORIGINAL_AF_KEY, getReorderedAttributes(originalVC.getAttribute(VCFConstants.ALLELE_FREQUENCY_KEY), indexOfOriginalAlleleForNewAllele)); } if (originalVC.hasAttribute(VCFConstants.ALLELE_NUMBER_KEY)) { builder.attribute(GATKVCFConstants.ORIGINAL_AN_KEY, originalVC.getAttribute(VCFConstants.ALLELE_NUMBER_KEY)); } } VariantContextUtils.calculateChromosomeCounts(builder, false); if (keepOriginalDepth && originalVC.hasAttribute(VCFConstants.DEPTH_KEY)) { builder.attribute(GATKVCFConstants.ORIGINAL_DP_KEY, originalVC.getAttribute(VCFConstants.DEPTH_KEY)); } boolean sawDP = false; int depth = 0; for (final String sample : selectedSampleNames ) { final Genotype g = originalVC.getGenotype(sample); if (!g.isFiltered()) { if (g.hasDP()) { depth += g.getDP(); sawDP = true; } } } if (sawDP) { builder.attribute(VCFConstants.DEPTH_KEY, depth); } }