Example usage for org.apache.commons.math3.random Well1024a nextBoolean

List of usage examples for org.apache.commons.math3.random Well1024a nextBoolean

Introduction

In this page you can find the example usage for org.apache.commons.math3.random Well1024a nextBoolean.

Prototype

public boolean nextBoolean() 

Source Link

Usage

From source file:com.milaboratory.core.io.sequence.fasta.FastaReaderTest.java

private static TestItem createTestData(long seed, int readsCount, boolean withWildcards) throws IOException {
    Well1024a rnd = new Well1024a(seed);

    File tempFile = File.createTempFile("temp" + seed, ".fasta");
    tempFile.deleteOnExit();/*from  w w  w  .  ja  v a  2s. c  om*/
    FileOutputStream output = new FileOutputStream(tempFile);

    SingleRead[] reads = new SingleRead[readsCount];

    WildcardSymbol[] wildcards = NucleotideSequence.ALPHABET.getAllWildcards().toArray(new WildcardSymbol[0]);
    long id = 0;
    for (int i = 0; i < readsCount; ++i) {
        char[] seq = new char[50 + rnd.nextInt(100)];
        char[] seqExp = new char[seq.length];

        int qPointer = 0;
        byte[] qualityData = new byte[seq.length];
        Arrays.fill(qualityData, SequenceQuality.GOOD_QUALITY_VALUE);
        for (int j = 0; j < seq.length; ++j) {
            seq[j] = seqExp[j] = NucleotideSequence.ALPHABET.symbolFromCode((byte) rnd.nextInt(4));
            if (j != 0 && j != seq.length - 1 && ((4 * j) % seq.length == 0) && rnd.nextBoolean()) {
                //next line for sequence
                seq[j] = seqExp[j] = '\n';
                --qPointer;
            } else if (withWildcards && j % 5 == 0) {//wildcard
                WildcardSymbol wildcard = wildcards[rnd.nextInt(wildcards.length)];
                if (NucleotideSequence.ALPHABET.codeFromSymbol(wildcard.getSymbol()) == -1) {
                    seq[j] = wildcard.getSymbol();
                    seqExp[j] = NucleotideSequence.ALPHABET
                            .symbolFromCode(wildcard.getUniformlyDistributedSymbol(id ^ (j + qPointer)));//as used in FastaReader#getSequenceWithQuality(..)
                    qualityData[j + qPointer] = SequenceQuality.BAD_QUALITY_VALUE;
                }
            }
        }
        String description = ">seq" + i;
        String sequenceString = new String(seq);
        output.write(description.getBytes());
        output.write('\n');
        output.write(sequenceString.getBytes());
        output.write('\n');

        reads[i] = new SingleReadImpl(id,
                new NSequenceWithQuality(new NucleotideSequence(new String(seqExp).replace("\n", "")),
                        new SequenceQuality(Arrays.copyOfRange(qualityData, 0, seq.length + qPointer))),
                description.substring(1));
        ++id;
    }
    output.close();

    return new TestItem(tempFile, reads);
}