private int calculateTumorNNR(final VariantContext vc) { int nnr = 0; switch ( vc.getGenotype(tumorSample).getType() ) { case HET: case HOM_VAR: nnr += 1; break; case NO_CALL: case UNAVAILABLE: case HOM_REF: break; } return nnr; }
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); } } }
private int calculateTumorAC(final VariantContext vc) { int ac = 0; switch ( vc.getGenotype(tumorSample).getType() ) { case HET: ac += 1; break; case HOM_VAR: ac += 2; break; case NO_CALL: case UNAVAILABLE: case HOM_REF: break; } return ac; }
private double log10PLFromSamples(final VariantContext vc, final String sample, boolean calcRefP) { Genotype g = vc.getGenotype(sample); double log10pSample = -1000; if ( ! g.isNoCall() ) { final double[] gLikelihoods = MathUtils.normalizeFromLog10(g.getLikelihoods().getAsVector()); log10pSample = Math.log10(calcRefP ? gLikelihoods[0] : 1 - gLikelihoods[0]); log10pSample = Double.isInfinite(log10pSample) ? -10000 : log10pSample; } return log10pSample; }
private double calculateNChildren( final VariantContext vc, final Set<Sample> triosToTest, final int childIdx, final int momIdx, final int dadIdx ) { final double likelihoodVector[] = new double[triosToTest.size()]; int iii = 0; for( final Sample child : triosToTest ) { final double[] momGL = vc.getGenotype(child.getMaternalID()).getLikelihoods().getAsVector(); final double[] dadGL = vc.getGenotype(child.getPaternalID()).getLikelihoods().getAsVector(); final double[] childGL = vc.getGenotype(child.getID()).getLikelihoods().getAsVector(); likelihoodVector[iii++] = momGL[momIdx] + dadGL[dadIdx] + childGL[childIdx]; } return MathUtils.sumLog10(likelihoodVector); }
/** Incorporates the provided variant's data into the metric analysis. */ @Override public void accumulate(final VariantContext vc) { progress.record(vc.getContig(), vc.getStart()); if (!isVariantExcluded(vc)) { final String singletonSample = getSingletonSample(vc); updateSummaryMetric(summaryMetric, null, vc, singletonSample != null); // The summary metric has no genotype. vc.getSampleNames().stream() .filter(sampleName -> !vc.getGenotype(sampleName).isHomRef()) .forEach(sampleName -> updateDetailMetric(sampleMetricsMap.get(sampleName), vc.getGenotype(sampleName), vc, sampleName.equals(singletonSample))); } }
/** Incorporates the provided variant's data into the metric analysis. */ @Override public void accumulate(final VariantContext vc) { progress.record(vc.getContig(), vc.getStart()); if (!isVariantExcluded(vc)) { final String singletonSample = getSingletonSample(vc); updateSummaryMetric(summaryMetric, null, vc, singletonSample != null); // The summary metric has no genotype. vc.getSampleNames().stream() .filter(sampleName -> !vc.getGenotype(sampleName).isHomRef()) .forEach(sampleName -> updateDetailMetric(sampleMetricsMap.get(sampleName), vc.getGenotype(sampleName), vc, sampleName.equals(singletonSample))); } }
private boolean contextHasTrioLikelihoods(VariantContext context, Trio trio) { for ( String sample : Arrays.asList(trio.getMaternalID(),trio.getPaternalID(),trio.getChildID()) ) { if (trio.getMaternalID().isEmpty() || trio.getPaternalID().isEmpty() || trio.getChildID().isEmpty()) return false; if ( ! context.hasGenotype(sample) ) return false; if ( ! context.getGenotype(sample).hasLikelihoods() ) return false; } return true; }
private boolean contextHasTrioLikelihoods(VariantContext context, Trio trio) { for ( String sample : Arrays.asList(trio.getMaternalID(),trio.getPaternalID(),trio.getChildID()) ) { if ( ! context.hasGenotype(sample) ) return false; if ( ! context.getGenotype(sample).hasLikelihoods() ) return false; } return true; }
private void putContig(VariantContext vc, String sampleName) { final Statistics stats = perSampleStats.get(sampleName); if (sampleName == null) { stats.putContig(vc.getContig()); } else { final Genotype gt = vc.getGenotype(sampleName); if (!gt.isHomRef() && !gt.isNoCall()) stats.putContig(vc.getContig()); } }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
@Test public void testGLnotOverridePL() { final VariantContext variant; try (final VCFFileReader reader = new VCFFileReader( new File("src/test/resources/htsjdk/variant/test_withGLandPL.vcf"), false)) { variant = reader.iterator().next(); } Assert.assertEquals(variant.getGenotype(0).getPL(), new int[]{45, 0, 50}); } }
@Test(enabled = true, dataProvider = "TestMakeAlleleConditionalContexts") private void testMakeAlleleConditionalContexts(final VariantContext vc, final List<VariantContext> expectedVCs) { final IndependentAllelesDiploidExactAFCalculator calc = (IndependentAllelesDiploidExactAFCalculator) AFCalculatorImplementation.EXACT_INDEPENDENT.newInstance(); final List<VariantContext> biAllelicVCs = calc.makeAlleleConditionalContexts(vc); Assert.assertEquals(biAllelicVCs.size(), expectedVCs.size()); for ( int i = 0; i < biAllelicVCs.size(); i++ ) { final VariantContext actual = biAllelicVCs.get(i); final VariantContext expected = expectedVCs.get(i); Assert.assertEquals(actual.getAlleles(), expected.getAlleles()); for ( int j = 0; j < actual.getNSamples(); j++ ) Assert.assertEquals(actual.getGenotype(j).getPL(), expected.getGenotype(j).getPL(), "expected PLs " + Utils.join(",", expected.getGenotype(j).getPL()) + " not equal to actual " + Utils.join(",", actual.getGenotype(j).getPL())); } }
@Test private void testPriorIndel() { VariantContext inputIndel = makeVC("1", Arrays.asList(Aref,T), makeG("s1",T,T,40,20,0), makeG("s2",Aref,T,18,0,24), makeG("s3",Aref,T,22,0,12)); List<VariantContext> supplTest1 = new ArrayList<>(1); supplTest1.add(new VariantContextBuilder(makeVC("2",Arrays.asList(Aref,ATC,ATCATC))).attribute(GATKVCFConstants.MLE_ALLELE_COUNT_KEY,Arrays.asList(5,4)).attribute(VCFConstants.ALLELE_NUMBER_KEY,10).make()); VariantContext test1result = PosteriorLikelihoodsUtils.calculatePosteriorGLs(inputIndel,supplTest1,0,0.001,true,false,false); System.out.println(test1result); int[] GPs = _mleparse( (List<Integer>)test1result.getGenotype(0).getAnyAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)); int[] PLs = test1result.getGenotype(0).getPL(); Assert.assertEquals(PLs,GPs); }
@Test private void testInputIndel() { VariantContext inputIndel = makeVC("1", Arrays.asList(Aref, ATC), makeG("s1",ATC,ATC,40,20,0), makeG("s2",Aref,ATC,18,0,24), makeG("s3",Aref,ATC,22,0,12)); List<VariantContext> supplTest1 = new ArrayList<>(1); supplTest1.add(new VariantContextBuilder(makeVC("2",Arrays.asList(Aref,T,C))).attribute(GATKVCFConstants.MLE_ALLELE_COUNT_KEY,Arrays.asList(5,4)).attribute(VCFConstants.ALLELE_NUMBER_KEY,10).make()); VariantContext test1result = PosteriorLikelihoodsUtils.calculatePosteriorGLs(inputIndel,supplTest1,0,0.001,true,false,false); System.out.println(test1result); int[] GPs = _mleparse( (List<Integer>)test1result.getGenotype(0).getAnyAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)); int[] PLs = test1result.getGenotype(0).getPL(); Assert.assertEquals(PLs,GPs); }
@Test private void testCalculatePosteriorHOM_VARtoHET() { VariantContext testOverlappingBase = makeVC("1", Arrays.asList(Aref,T), makeG("s1",T,T,40,1,0)); List<VariantContext> supplTest1 = new ArrayList<>(1); supplTest1.add(new VariantContextBuilder(makeVC("2",Arrays.asList(Aref,T))).attribute(GATKVCFConstants.MLE_ALLELE_COUNT_KEY,500).attribute(VCFConstants.ALLELE_NUMBER_KEY,1000).make()); VariantContext test1result = PosteriorLikelihoodsUtils.calculatePosteriorGLs(testOverlappingBase,supplTest1,0,0.001,true,false,false); int[] GP = _mleparse( (List<Integer>)test1result.getGenotype(0).getAnyAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)); Assert.assertTrue(GP[2] > GP[1]); }
@Test private void testCalculatePosteriorHOM_REFtoHET() { VariantContext testOverlappingBase = makeVC("1", Arrays.asList(Aref,T), makeG("s1",T,T,0,1,40)); List<VariantContext> supplTest1 = new ArrayList<>(1); supplTest1.add(new VariantContextBuilder(makeVC("2",Arrays.asList(Aref,T))).attribute(GATKVCFConstants.MLE_ALLELE_COUNT_KEY,500).attribute(VCFConstants.ALLELE_NUMBER_KEY,1000).make()); VariantContext test1result = PosteriorLikelihoodsUtils.calculatePosteriorGLs(testOverlappingBase,supplTest1,0,0.001,true,false,false); int[] GP = _mleparse( (List<Integer>)test1result.getGenotype(0).getAnyAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)); Assert.assertTrue(GP[0] > GP[1]); }
@Test private void testCalculatePosteriorHETtoHOM_VAR() { VariantContext testOverlappingBase = makeVC("1", Arrays.asList(Aref,T), makeG("s1",T,T,40,0,1)); List<VariantContext> supplTest1 = new ArrayList<>(1); supplTest1.add(new VariantContextBuilder(makeVC("2",Arrays.asList(Aref,T))).attribute(GATKVCFConstants.MLE_ALLELE_COUNT_KEY,900).attribute(VCFConstants.ALLELE_NUMBER_KEY,1000).make()); VariantContext test1result = PosteriorLikelihoodsUtils.calculatePosteriorGLs(testOverlappingBase,supplTest1,0,0.001,true,false,false); int[] GP = _mleparse( (List<Integer>)test1result.getGenotype(0).getAnyAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)); Assert.assertTrue(GP[2] < GP[1]); }
@Test private void testCalculatePosteriorHETtoHOM_REF() { VariantContext testOverlappingBase = makeVC("1", Arrays.asList(Aref,T), makeG("s1",T,T,1,0,40)); List<VariantContext> supplTest1 = new ArrayList<>(1); supplTest1.add(new VariantContextBuilder(makeVC("2",Arrays.asList(Aref,T))).attribute(GATKVCFConstants.MLE_ALLELE_COUNT_KEY,100).attribute(VCFConstants.ALLELE_NUMBER_KEY,1000).make()); VariantContext test1result = PosteriorLikelihoodsUtils.calculatePosteriorGLs(testOverlappingBase,supplTest1,0,0.001,true,false,false); int[] GP = _mleparse( (List<Integer>)test1result.getGenotype(0).getAnyAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)); Assert.assertTrue(GP[0] < GP[1]); }