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));
}
}
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();
}
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();
}
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);
}
}
Aggregations