Java Code Examples for htsjdk.variant.variantcontext.VariantContext#getSampleNames()
The following examples show how to use
htsjdk.variant.variantcontext.VariantContext#getSampleNames() .
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: CreateSnpIntervalFromVcf.java From Drop-seq with MIT License | 5 votes |
private void validateRequestedSamples (final PeekableIterator<VariantContext> iterator, final Set<String> sample) { if (iterator.hasNext()) { final VariantContext site = iterator.peek(); Set<String> vCFSamples = site.getSampleNames(); for (String s: sample) if (!vCFSamples.contains(s)) throw new IllegalArgumentException("VCF doesn't have the requested sample " + s); } }
Example 2
Source File: FingerprintChecker.java From picard with MIT License | 5 votes |
/** * Loads genotypes from the supplied file into one or more Fingerprint objects and returns them in a * Map of Sample->Fingerprint. * * @param iterable - an iterable over variantContexts containing genotypes for one or more samples * @param specificSample - null to load genotypes for all samples contained in the file or the name * of an individual sample to load (and exclude all others). * @param source The path of the source file used. used to emit errors, and annotate the fingerprints. * @return a Map of Sample name to Fingerprint */ public Map<String, Fingerprint> loadFingerprintsFromVariantContexts(final Iterable<VariantContext> iterable, final String specificSample, final Path source) { final Map<String, Fingerprint> fingerprints = new HashMap<>(); Set<String> samples = null; for (final VariantContext ctx : iterable) { // Setup the sample names set if needed if (ctx == null) { continue; } if (samples == null) { if (specificSample != null) { samples = new HashSet<>(); samples.add(specificSample); } else { samples = ctx.getSampleNames(); if (samples == null) { log.warn("No samples found in file: " + source.toUri().toString() + ". Skipping."); return Collections.emptyMap(); } } samples.forEach(s -> fingerprints.put(s, new Fingerprint(s, source, null))); } try { getFingerprintFromVc(fingerprints, ctx); } catch (final IllegalArgumentException e) { log.warn(e, "There was a genotyping error in File: " + source.toUri().toString() + "\n" + e.getMessage()); } } return fingerprints; }
Example 3
Source File: SelectVariants.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Checks if the two variants have the same genotypes for the selected samples * * @param vc the variant rod VariantContext. * @param compVCs the comparison VariantContext * @return true if VariantContexts are concordant, false otherwise */ private boolean isConcordant (final VariantContext vc, final Collection<VariantContext> compVCs) { if (vc == null || compVCs == null || compVCs.isEmpty()) { return false; } // if we're not looking for specific samples then the fact that we have both VCs is enough to call it concordant. if (noSamplesSpecified) { return true; } // make a list of all samples contained in this variant VC that are being tracked by the user command line arguments. final Set<String> variantSamples = vc.getSampleNames(); variantSamples.retainAll(samples); // check if we can find all samples from the variant rod in the comp rod. for (final String sample : variantSamples) { boolean foundSample = false; for (final VariantContext compVC : compVCs) { final Genotype varG = vc.getGenotype(sample); final Genotype compG = compVC.getGenotype(sample); if (haveSameGenotypes(varG, compG)) { foundSample = true; break; } } // if at least one sample doesn't have the same genotype, we don't have concordance if (!foundSample) { return false; } } return true; }
Example 4
Source File: VariantContextTestUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void assertVariantContextsHaveSameGenotypes(final VariantContext actual, final VariantContext expected, final List<String> attributesToIgnore) { Assert.assertEquals(actual.hasGenotypes(), expected.hasGenotypes(), "hasGenotypes"); if ( expected.hasGenotypes() ) { BaseTest.assertEqualsSet(actual.getSampleNames(), expected.getSampleNames(), "sample names set"); Assert.assertEquals(actual.getSampleNamesOrderedByName(), expected.getSampleNamesOrderedByName(), "sample names"); final Set<String> samples = expected.getSampleNames(); for ( final String sample : samples ) { assertGenotypesAreEqual(actual.getGenotype(sample), expected.getGenotype(sample), attributesToIgnore); } } }