Search in sources :

Example 1 with RandomDNA

use of org.broadinstitute.hellbender.utils.RandomDNA in project gatk by broadinstitute.

the class SVKmerShortUnitTest method testRandomMaskedKmers.

@Test
public void testRandomMaskedKmers() {
    final int K = 31;
    final RandomDNA randDNA = new RandomDNA(379483L);
    final int seqLen = 1000;
    final byte[] baseBytes = randDNA.nextBases(seqLen);
    final String bases = new String(baseBytes);
    final Random rand = new Random(2738493L);
    for (int i = 0; i < seqLen - K; i++) {
        //Generate random indices to mask
        List<Byte> maskIndices = new ArrayList<>(K);
        for (int j = 0; j < K; j++) {
            maskIndices.add(new Byte((byte) j));
        }
        Collections.shuffle(maskIndices);
        int maskSize = rand.nextInt(K - 3) + 2;
        maskIndices = maskIndices.subList(0, maskSize);
        final byte[] maskIndicesBytes = new byte[maskIndices.size()];
        for (int j = 0; j < maskIndices.size(); j++) {
            maskIndicesBytes[j] = maskIndices.get(j).byteValue();
        }
        final SVKmerShort mask = SVKmerShort.getMask(maskIndicesBytes, K);
        //Create distinct kmers
        String substr = bases.substring(i, i + K);
        final byte[] maskedBasesA = substr.getBytes();
        final byte[] maskedBasesT = substr.getBytes();
        for (int j = 0; j < maskIndicesBytes.length; j++) {
            maskedBasesA[maskIndicesBytes[j]] = 'A';
            maskedBasesT[maskIndicesBytes[j]] = 'T';
        }
        final SVKmerShort kmerA = (SVKmerShort) SVKmerizer.toKmer(maskedBasesA, new SVKmerShort(K));
        final SVKmerShort kmerT = (SVKmerShort) SVKmerizer.toKmer(maskedBasesT, new SVKmerShort(K));
        Assert.assertEquals(kmerA.mask(mask), kmerT.mask(mask));
    }
}
Also used : RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) Test(org.testng.annotations.Test)

Example 2 with RandomDNA

use of org.broadinstitute.hellbender.utils.RandomDNA in project gatk by broadinstitute.

the class AssemblyResultSetUnitTest method trimmingData.

@DataProvider(name = "trimmingData")
public Iterator<Object[]> trimmingData() {
    final AssemblyRegion activeRegion = new AssemblyRegion(new SimpleInterval("1", 1000, 1100), 25, header);
    final int length = activeRegion.getExtendedSpan().size();
    // keep it prepoducible by fixing the seed to lucky 13.
    final RandomDNA rnd = new RandomDNA(13);
    final AssemblyRegionTestDataSet actd = new AssemblyRegionTestDataSet(10, new String(rnd.nextBases(length)), new String[] { "Civar:*1T*" }, new String[0], new byte[0], new byte[0], new byte[0]);
    final List<Haplotype> haplotypes = actd.haplotypeList();
    for (final Haplotype h : haplotypes) h.setGenomeLocation(activeRegion.getExtendedSpan());
    final ReadThreadingGraph rtg = new ReadThreadingGraph(10);
    for (final Haplotype h : haplotypes) rtg.addSequence("seq-" + Math.abs(h.hashCode()), h.getBases(), h.isReference());
    final SeqGraph seqGraph = rtg.toSequenceGraph();
    final AssemblyResult ar = new AssemblyResult(AssemblyResult.Status.ASSEMBLED_SOME_VARIATION, seqGraph, rtg);
    final Map<Haplotype, AssemblyResult> result = new HashMap<>();
    for (final Haplotype h : haplotypes) result.put(h, ar);
    return Collections.singleton(new Object[] { result, activeRegion }).iterator();
}
Also used : ReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph) TestingReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.TestingReadThreadingGraph) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) DataProvider(org.testng.annotations.DataProvider)

Example 3 with RandomDNA

use of org.broadinstitute.hellbender.utils.RandomDNA in project gatk-protected by broadinstitute.

the class AssemblyResultSetUnitTest method trimmingData.

@DataProvider(name = "trimmingData")
public Iterator<Object[]> trimmingData() {
    final AssemblyRegion activeRegion = new AssemblyRegion(new SimpleInterval("1", 1000, 1100), 25, header);
    final int length = activeRegion.getExtendedSpan().size();
    // keep it prepoducible by fixing the seed to lucky 13.
    final RandomDNA rnd = new RandomDNA(13);
    final AssemblyRegionTestDataSet actd = new AssemblyRegionTestDataSet(10, new String(rnd.nextBases(length)), new String[] { "Civar:*1T*" }, new String[0], new byte[0], new byte[0], new byte[0]);
    final List<Haplotype> haplotypes = actd.haplotypeList();
    for (final Haplotype h : haplotypes) h.setGenomeLocation(activeRegion.getExtendedSpan());
    final ReadThreadingGraph rtg = new ReadThreadingGraph(10);
    for (final Haplotype h : haplotypes) rtg.addSequence("seq-" + Math.abs(h.hashCode()), h.getBases(), h.isReference());
    final SeqGraph seqGraph = rtg.toSequenceGraph();
    final AssemblyResult ar = new AssemblyResult(AssemblyResult.Status.ASSEMBLED_SOME_VARIATION, seqGraph, rtg);
    final Map<Haplotype, AssemblyResult> result = new HashMap<>();
    for (final Haplotype h : haplotypes) result.put(h, ar);
    return Collections.singleton(new Object[] { result, activeRegion }).iterator();
}
Also used : ReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph) TestingReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.TestingReadThreadingGraph) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) DataProvider(org.testng.annotations.DataProvider)

Example 4 with RandomDNA

use of org.broadinstitute.hellbender.utils.RandomDNA in project gatk by broadinstitute.

the class IntelInflaterDeflaterIntegrationTest method deflateInflateWithIntel.

@Test
public void deflateInflateWithIntel() throws DataFormatException {
    if (!isIntelInflaterDeflaterSupported()) {
        throw new SkipException("IntelInflater/IntelDeflater not available on this platform");
    }
    // create buffers and random input
    final int LEN = 64 * 1024;
    final byte[] input = new RandomDNA().nextBases(LEN);
    final byte[] compressed = new byte[2 * LEN];
    final byte[] result = new byte[LEN];
    final IntelInflaterFactory intelInflaterFactory = new IntelInflaterFactory();
    final IntelDeflaterFactory intelDeflaterFactory = new IntelDeflaterFactory();
    Assert.assertTrue(intelInflaterFactory.usingIntelInflater());
    Assert.assertTrue(intelDeflaterFactory.usingIntelDeflater());
    for (int i = 0; i < 10; i++) {
        // create deflater with compression level i
        final Deflater deflater = intelDeflaterFactory.makeDeflater(i, true);
        // setup deflater
        deflater.setInput(input);
        deflater.finish();
        // compress data
        int compressedBytes = 0;
        // so this loop should always finish in one iteration
        while (!deflater.finished()) {
            compressedBytes = deflater.deflate(compressed, 0, compressed.length);
        }
        deflater.end();
        // decompress and check output == input
        Inflater inflater = intelInflaterFactory.makeInflater(true);
        inflater.setInput(compressed, 0, compressedBytes);
        inflater.inflate(result);
        inflater.end();
        Assert.assertEquals(input, result);
        // clear compressed and result buffers for next iteration
        Arrays.fill(compressed, (byte) 0);
        Arrays.fill(result, (byte) 0);
    }
}
Also used : IntelDeflaterFactory(com.intel.gkl.compression.IntelDeflaterFactory) IntelDeflater(com.intel.gkl.compression.IntelDeflater) Deflater(java.util.zip.Deflater) IntelInflaterFactory(com.intel.gkl.compression.IntelInflaterFactory) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) Inflater(java.util.zip.Inflater) IntelInflater(com.intel.gkl.compression.IntelInflater) SkipException(org.testng.SkipException) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

RandomDNA (org.broadinstitute.hellbender.utils.RandomDNA)4 AssemblyRegion (org.broadinstitute.hellbender.engine.AssemblyRegion)2 SeqGraph (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph)2 ReadThreadingGraph (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph)2 TestingReadThreadingGraph (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.TestingReadThreadingGraph)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)2 DataProvider (org.testng.annotations.DataProvider)2 Test (org.testng.annotations.Test)2 IntelDeflater (com.intel.gkl.compression.IntelDeflater)1 IntelDeflaterFactory (com.intel.gkl.compression.IntelDeflaterFactory)1 IntelInflater (com.intel.gkl.compression.IntelInflater)1 IntelInflaterFactory (com.intel.gkl.compression.IntelInflaterFactory)1 Deflater (java.util.zip.Deflater)1 Inflater (java.util.zip.Inflater)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1 SkipException (org.testng.SkipException)1