Commit 984ed8b0 authored by Dylan Aïssi's avatar Dylan Aïssi
Browse files

New upstream version 5.0-180928+dfsg

parent 169b5c18
Loading
Loading
Loading
Loading

blbutil/ByteArray.java

deleted100644 → 0
+0 −128
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014-2016 Brian L. Browning
 *
 * This file is part of Beagle
 *
 * Beagle is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Beagle is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package blbutil;

/**
 * <p>Class {@code ByteArray} represents an immutable array of integer
 * values between -128 and 127 that is stored as a {@code byte[]} array.
 * </p>
 * Instances of {@code ByteArray} are immutable.
 *
 * @author Brian L. Browning {@code <browning@uw.edu>}
 */
public final class ByteArray implements IntArray {

    private final byte[] ba;

    /**
     * Constructs a new {@code ByteArray} instance from
     * the specified data.
     * @param ba an array of integer values between -128 and 127 inclusive
     * @throws NullPointerException if {@code ba == null}
     */
    public ByteArray(byte[] ba) {
        this.ba = ba.clone();
    }

    /**
     * Constructs a new {@code ByteArray} instance from the specified data.
     * @param ia an array of integer values between -128 and 127 inclusive
     * @throws IllegalArgumentException if
     * {@code (ia[j] < -128 || ia[j] > 127)} for any index {@code j}
     * satisfying  {@code (j >= 0 && j < ia.length)}
     * @throws NullPointerException if {@code ia == null}
     */
    public ByteArray(int[] ia) {
        this(ia, 0, ia.length);
    }

    /**
     * Constructs a new {@code ByteArray} instance from the specified data.
     * @param il an list of integer values between -128 and 127 inclusive
     * @throws IllegalArgumentException if
     * {@code (il.get(j) < -128 || il.get(j) > 127)} for any index {@code j}
     * satisfying  {@code (j >= 0 && j < il.size())}
     * @throws NullPointerException if {@code il == null}
     */
    public ByteArray(IntList il) {
        this(il, 0, il.size());
    }

    /**
     * Constructs a new {@code ByteArray} instance from the
     * specified data.
     * @param ia an array of integer values between -128 and 127 inclusive
     * @param from the first element to be included (inclusive)
     * @param to the last element to be included (exclusive)
     * @throws IllegalArgumentException if
     * {@code (ia[j] < -128 || ia[j] > 127)} for any index {@code j}
     * satisfying  {@code (j >= from && j < to)}
     * @throws IndexOutOfBoundsException if {@code from < 0 || to > ia.length}
     * @throws NegativeArraySizeException if {@code to > from}
     * @throws NullPointerException if {@code ia == null}
     */
    public ByteArray(int[] ia, int from, int to) {
        this.ba = new byte[to - from];
        for (int j=from; j<to; ++j) {
            if (ia[j] < -128 || ia[j] > 127) {
                throw new IllegalArgumentException(String.valueOf(ia[j]));
            }
            ba[j - from] = (byte) ia[j];
        }
    }

    /**
     * Constructs a new {@code ByteArray} instance from the
     * specified data.
     * @param il an list of integer values between -128 and 127 inclusive
     * @param from the first element to be included (inclusive)
     * @param to the last element to be included (exclusive)
     * @throws IllegalArgumentException if
     * {@code (il.get(j) < -128 || il.get(j) > 127)} for any index {@code j}
     * satisfying  {@code (j >= from && j < to)}
     * @throws IndexOutOfBoundsException if {@code from < 0 || to > il.length}
     * @throws NegativeArraySizeException if {@code to > from}
     * @throws NullPointerException if {@code il == null}
     */
    public ByteArray(IntList il, int from, int to) {
        this.ba = new byte[to - from];
        for (int j=from; j<to; ++j) {
            int value = il.get(j);
            if (value < -128 || value > 127) {
                throw new IllegalArgumentException(String.valueOf(value));
            }
            ba[j - from] = (byte) value;
        }
    }

    @Override
    public int size() {
        return ba.length;
    }

    @Override
    public int get(int index) {
        return ba[index];
    }

    @Override
    public String toString() {
        return this.asString();
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -99,6 +99,20 @@ public class Utilities {
        return sdf.format(now);
    }

    /**
     * Returns the current minutes and seconds as a string.  The
     * exact details of the string representation
     * are unspecified and subject to change.
     *
     * @return the current local time as a string.
     */
    public static String minutesAndSeconds() {
        Date now = new Date();
        SimpleDateFormat sdf =
                new SimpleDateFormat("mm:ss");
        return sdf.format(now);
    }

    /**
     * <p>Returns a set of identifiers found in a text file that has
     * one identifier per line.  The empty set is returned if
+39 −12
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ package bref;
import beagleutil.ChromIds;
import beagleutil.Samples;
import blbutil.FileUtil;
import blbutil.IntArray;
import blbutil.IntList;
import ints.IntArray;
import ints.IntList;
import blbutil.Utilities;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@@ -54,6 +54,31 @@ import vcf.RefGTRec;
 */
public class AsIsBref3Writer implements BrefWriter {

    /**
     * The end of file code for a bref file.
     */
    public static final int END_OF_DATA = 0;

    /**
     * The integer denoting denoting the end of the index in a bref file
     */
    public static final long END_OF_INDEX = -999_999_999_999_999L;

    /**
     * The initial integer in a bref version 3 file.
     */
    public static final int MAGIC_NUMBER_V3 = 2055763188;

    /**
     * The byte value denoting a sequence coded record
     */
    public static final byte SEQ_CODED = 0;

    /**
     * The byte value denoting an allele coded record
     */
    public static final byte ALLELE_CODED = 1;

    private final String WRITE_ERR = "Error writing file";
    private final String CONTIGUITY_ERR = "Error: chromosomes not contiguous";

@@ -62,7 +87,6 @@ public class AsIsBref3Writer implements BrefWriter {
    private final Comparator<String[]> ALLELES_COMP = allelesComparator();

    public final int MAX_SAMPLES = (1 << 29) - 1;
    public final int MAX_BLOCK_BYTES = Integer.MAX_VALUE;

    private int lastChromIndex = -1;
    private IntArray hap2Seq = null;
@@ -145,10 +169,10 @@ public class AsIsBref3Writer implements BrefWriter {
        }
        if (rec.isAlleleCoded()==false) {
            if (hap2Seq==null) {
                hap2Seq = rec.hapToSeq();
                hap2Seq = rec.map(0);
            }
            else if (rec.hapToSeq()!=hap2Seq) {
                hap2Seq = rec.hapToSeq();
            else if (rec.map(0)!=hap2Seq) {
                hap2Seq = rec.map(0);
                startNewBlock = true;
            }
        }
@@ -214,10 +238,12 @@ public class AsIsBref3Writer implements BrefWriter {
            }
        }
        else {
            brefOut.writeChar(rec.seqToAllele().size());
            IntArray hap2seq = rec.hapToSeq();
            for (int j=0, n=hap2seq.size(); j<n; ++j) {
                brefOut.writeChar(hap2seq.get(j));
            assert rec.nMaps()==2;
            IntArray hapToSeq = rec.map(0);
            IntArray seqToAllele = rec.map(1);
            brefOut.writeChar(seqToAllele.size());
            for (int j=0, n=hapToSeq.size(); j<n; ++j) {
                brefOut.writeChar(hapToSeq.get(j));
            }
        }
        bytesWritten += (nHaps + 1)*Character.BYTES;
@@ -227,7 +253,8 @@ public class AsIsBref3Writer implements BrefWriter {
        if (rec.nAlleles() >= 256) {
            Utilities.exit("ERROR: more than 256 alleles: " + rec.marker());
        }
        IntArray seq2Allele = rec.seqToAllele();
        assert rec.nMaps()==2;
        IntArray seq2Allele = rec.map(1);
        writeMarker(rec.marker());
        brefOut.writeByte(SEQ_CODED);
        for (int j=0, n=seq2Allele.size(); j<n; ++j) {
@@ -367,7 +394,7 @@ public class AsIsBref3Writer implements BrefWriter {
    }

    private DataOutputStream dataOutputStream(File file) {
        OutputStream dos = null;
        OutputStream dos;
        if (file==null) {
            dos = new DataOutputStream(System.out);
        }
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public final class Bref3It implements SampleFileIt<RefGTRec> {

    /**
     * Constructs a new {@code Bref3It} instance.
     * @param brefFile a bref version 3 file or {@null} if the
     * @param brefFile a bref version 3 file or {@code null} if the
     * bref version 3 file is to be read from standard input
     *
     * @throws IllegalArgumentException if a format error is detected in a
+4 −4
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ package bref;

import beagleutil.ChromIds;
import beagleutil.Samples;
import blbutil.CharArray;
import ints.CharArray;
import blbutil.Const;
import blbutil.Filter;
import blbutil.IntArray;
import blbutil.UnsignedByteArray;
import ints.IntArray;
import ints.UnsignedByteArray;
import blbutil.Utilities;
import java.io.DataInput;
import java.io.IOException;
@@ -185,7 +185,7 @@ public final class Bref3Reader {

    private static void readAndCheckMagicNumber(DataInput di) throws IOException {
        int magicNumber=di.readInt();
        if (magicNumber!=BrefWriter.MAGIC_NUMBER_V3) {
        if (magicNumber!=AsIsBref3Writer.MAGIC_NUMBER_V3) {
            String s = "ERROR: Unrecognized input file.  Was input file created "
                    + Const.nl + "with a different version of the bref program?";
            Utilities.exit(s);
Loading