Search in sources :

Example 1 with PairHMMNativeArguments

use of org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments in project gatk-protected by broadinstitute.

the class PairHMMLikelihoodCalculationEngineUnitTest method testComputeLikelihoods.

@Test
public void testComputeLikelihoods() {
    final LikelihoodEngineArgumentCollection LEAC = new LikelihoodEngineArgumentCollection();
    PairHMMLikelihoodCalculationEngine.writeLikelihoodsToFile = true;
    final ReadLikelihoodCalculationEngine lce = new PairHMMLikelihoodCalculationEngine((byte) SAMUtils.MAX_PHRED_SCORE, new PairHMMNativeArguments(), PairHMM.Implementation.LOGLESS_CACHING, MathUtils.logToLog10(QualityUtils.qualToErrorProbLog10(LEAC.phredScaledGlobalReadMismappingRate)), PairHMMLikelihoodCalculationEngine.PCRErrorModel.CONSERVATIVE);
    final Map<String, List<GATKRead>> perSampleReadList = new HashMap<>();
    final int n = 10;
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode(n + "M"));
    read1.setMappingQuality(60);
    final String sample1 = "sample1";
    perSampleReadList.put(sample1, Arrays.asList(read1));
    final SampleList samples = new IndexedSampleList(sample1);
    final AssemblyResultSet assemblyResultSet = new AssemblyResultSet();
    final byte[] bases = Strings.repeat("A", n + 1).getBytes();
    final Haplotype hap1 = new Haplotype(bases, true);
    hap1.setGenomeLocation(read1);
    assemblyResultSet.add(hap1);
    final byte[] basesModified = bases;
    //different bases
    basesModified[5] = 'C';
    final Haplotype hap2 = new Haplotype(basesModified, false);
    //use same loc
    hap2.setGenomeLocation(read1);
    assemblyResultSet.add(hap2);
    final ReadLikelihoods<Haplotype> likes = lce.computeReadLikelihoods(assemblyResultSet, samples, perSampleReadList);
    final LikelihoodMatrix<Haplotype> mtx = likes.sampleMatrix(0);
    Assert.assertEquals(mtx.numberOfAlleles(), 2);
    Assert.assertEquals(mtx.numberOfReads(), 1);
    final double v1 = mtx.get(0, 0);
    final double v2 = mtx.get(1, 0);
    Assert.assertTrue(v1 > v2, "matching haplotype should have a higher likelihood");
    lce.close();
    new File(PairHMMLikelihoodCalculationEngine.LIKELIHOODS_FILENAME).delete();
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) PairHMMNativeArguments(org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) File(java.io.File) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 2 with PairHMMNativeArguments

use of org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments in project gatk by broadinstitute.

the class PairHMMLikelihoodCalculationEngineUnitTest method createPcrErrorModelTest.

@Test(dataProvider = "PcrErrorModelTestProvider", enabled = true)
public void createPcrErrorModelTest(final String repeat, final int repeatLength) {
    final PairHMMLikelihoodCalculationEngine engine = new PairHMMLikelihoodCalculationEngine((byte) 0, new PairHMMNativeArguments(), PairHMM.Implementation.ORIGINAL, 0.0, PairHMMLikelihoodCalculationEngine.PCRErrorModel.CONSERVATIVE);
    final String readString = Strings.repeat(repeat, repeatLength);
    final byte[] insQuals = new byte[readString.length()];
    final byte[] delQuals = new byte[readString.length()];
    Arrays.fill(insQuals, (byte) PairHMMLikelihoodCalculationEngine.INITIAL_QSCORE);
    Arrays.fill(delQuals, (byte) PairHMMLikelihoodCalculationEngine.INITIAL_QSCORE);
    engine.applyPCRErrorModel(readString.getBytes(), insQuals, delQuals);
    for (int i = 1; i < insQuals.length; i++) {
        final int repeatLengthFromCovariate = PairHMMLikelihoodCalculationEngine.findTandemRepeatUnits(readString.getBytes(), i - 1).getRight();
        final byte adjustedScore = PairHMMLikelihoodCalculationEngine.getErrorModelAdjustedQual(repeatLengthFromCovariate, 3.0);
        Assert.assertEquals(insQuals[i - 1], adjustedScore);
        Assert.assertEquals(delQuals[i - 1], adjustedScore);
    }
}
Also used : PairHMMNativeArguments(org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with PairHMMNativeArguments

use of org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments in project gatk-protected by broadinstitute.

the class PairHMMNativeArgumentCollection method getPairHMMArgs.

public PairHMMNativeArguments getPairHMMArgs() {
    final PairHMMNativeArguments args = new PairHMMNativeArguments();
    args.maxNumberOfThreads = pairHmmNativeThreads;
    args.useDoublePrecision = useDoublePrecision;
    return args;
}
Also used : PairHMMNativeArguments(org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments)

Example 4 with PairHMMNativeArguments

use of org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments in project gatk by broadinstitute.

the class VectorPairHMMUnitTest method getHMMs.

// Return a list of supported VectorLoglessPairHMM implementations, skip the test if none are supported
private List<Pair<PairHMM, Boolean>> getHMMs() {
    List<Pair<PairHMM, Boolean>> list = new ArrayList<>();
    PairHMMNativeArguments args = new PairHMMNativeArguments();
    args.useDoublePrecision = false;
    args.maxNumberOfThreads = 1;
    for (VectorLoglessPairHMM.Implementation imp : VectorLoglessPairHMM.Implementation.values()) {
        boolean loaded = true;
        PairHMM avxPairHMM = null;
        try {
            avxPairHMM = new VectorLoglessPairHMM(imp, args);
        //avxPairHMM.doNotUseTristateCorrection();
        } catch (UserException.HardwareFeatureException e) {
            loaded = false;
        }
        final Pair<PairHMM, Boolean> hmm_load = new ImmutablePair<PairHMM, Boolean>(avxPairHMM, new Boolean(loaded));
        list.add(hmm_load);
    }
    return list;
}
Also used : PairHMMNativeArguments(org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) UserException(org.broadinstitute.hellbender.exceptions.UserException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with PairHMMNativeArguments

use of org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments in project gatk-protected by broadinstitute.

the class PairHMMLikelihoodCalculationEngineUnitTest method createPcrErrorModelTest.

@Test(dataProvider = "PcrErrorModelTestProvider", enabled = true)
public void createPcrErrorModelTest(final String repeat, final int repeatLength) {
    final PairHMMLikelihoodCalculationEngine engine = new PairHMMLikelihoodCalculationEngine((byte) 0, new PairHMMNativeArguments(), PairHMM.Implementation.ORIGINAL, 0.0, PairHMMLikelihoodCalculationEngine.PCRErrorModel.CONSERVATIVE);
    final String readString = Strings.repeat(repeat, repeatLength);
    final byte[] insQuals = new byte[readString.length()];
    final byte[] delQuals = new byte[readString.length()];
    Arrays.fill(insQuals, (byte) PairHMMLikelihoodCalculationEngine.INITIAL_QSCORE);
    Arrays.fill(delQuals, (byte) PairHMMLikelihoodCalculationEngine.INITIAL_QSCORE);
    engine.applyPCRErrorModel(readString.getBytes(), insQuals, delQuals);
    for (int i = 1; i < insQuals.length; i++) {
        final int repeatLengthFromCovariate = PairHMMLikelihoodCalculationEngine.findTandemRepeatUnits(readString.getBytes(), i - 1).getRight();
        final byte adjustedScore = PairHMMLikelihoodCalculationEngine.getErrorModelAdjustedQual(repeatLengthFromCovariate, 3.0);
        Assert.assertEquals(insQuals[i - 1], adjustedScore);
        Assert.assertEquals(delQuals[i - 1], adjustedScore);
    }
}
Also used : PairHMMNativeArguments(org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

PairHMMNativeArguments (org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments)7 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)4 Test (org.testng.annotations.Test)4 File (java.io.File)2 IndexedSampleList (org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList)2 SampleList (org.broadinstitute.hellbender.utils.genotyper.SampleList)2 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)2 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 UserException (org.broadinstitute.hellbender.exceptions.UserException)1