htsjdk.tribble.util.LittleEndianOutputStream Java Examples

The following examples show how to use htsjdk.tribble.util.LittleEndianOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MatrixZoomData.java    From JuiceboxLegacy with MIT License 6 votes vote down vote up
private void dumpPearsons(PrintWriter pw, LittleEndianOutputStream les, ExpectedValueFunction df) throws IOException {
    BasicMatrix pearsons = getPearsons(df);
    if (pearsons != null) {
        int dim = pearsons.getRowDimension();
        for (int i = 0; i < dim; i++) {
            for (int j = 0; j < dim; j++) {
                float output = pearsons.getEntry(i, j);
                if (les != null) les.writeFloat(output);
                else pw.print(output + " ");
            }
            if (les == null) pw.println();
        }
        pw.flush();
    } else {
        log.error("Pearson's not available at zoom " + zoom);
    }
}
 
Example #2
Source File: Preprocessor.java    From Juicebox with MIT License 6 votes vote down vote up
private void writeZoomHeader(MatrixZoomDataPP zd, LittleEndianOutputStream los) throws IOException {

        int numberOfBlocks = zd.blockNumbers.size();
        los.writeString(zd.getUnit().toString());  // Unit
        los.writeInt(zd.getZoom());     // zoom index,  lowest res is zero
        los.writeFloat((float) zd.getSum());      // sum
        los.writeFloat((float) zd.getOccupiedCellCount());
        los.writeFloat((float) zd.getPercent5());
        los.writeFloat((float) zd.getPercent95());
        los.writeInt(zd.getBinSize());
        los.writeInt(zd.getBlockBinCount());
        los.writeInt(zd.getBlockColumnCount());
        los.writeInt(numberOfBlocks);

        zd.blockIndexPosition = los.getWrittenCount();

        // Placeholder for block index
        for (int i = 0; i < numberOfBlocks; i++) {
            los.writeInt(0);
            los.writeLong(0L);
            los.writeInt(0);
        }

    }
 
Example #3
Source File: MultithreadedPreprocessor.java    From Juicebox with MIT License 6 votes vote down vote up
@Override
// MatrixPP matrix, LittleEndianOutputStream los, Deflater compressor
protected Pair<Map<Long, List<IndexEntry>>, Long> writeMatrix(MatrixPP matrix, LittleEndianOutputStream[] localLos,
                                                              Deflater localCompressor, Map<String, IndexEntry> localMatrixPositions, int chromosomePairIndex, boolean doMultiThreadedBehavior) throws IOException {

    Pair<Map<Long, List<IndexEntry>>, Long> localBlockIndexes = super.writeMatrix(matrix, localLos, localCompressor, localMatrixPositions, chromosomePairIndex, true);

    chromosomePairBlockIndexes.put(chromosomePairIndex, localBlockIndexes.getFirst());
    long size = localLos[0].getWrittenCount() - localBlockIndexes.getSecond();
    matrixSizes.put(chromosomePairIndex, size);
    localLos[0].close();

    //System.out.print(".");

    return localBlockIndexes;
}
 
Example #4
Source File: ScratchPad.java    From JuiceboxLegacy with MIT License 5 votes vote down vote up
public static void writeHeader(String path) throws IOException {

        File f = new File(path);

        FileOutputStream fos = new FileOutputStream(f);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        LittleEndianOutputStream los = new LittleEndianOutputStream(bos);

        // Magic number - 4 bytes
        los.writeByte('h');
        los.writeByte('i');
        los.writeByte('c');
        los.writeByte(0);

        // Version number
        los.writeInt(1);

        // Genome --
        los.writeString("hg19");

        // Chromosomes
        los.writeString("14");
        los.writeString("14");

        // Resolution (bin size)
        los.writeInt(5000);

        // Statistics, other attributes
        los.writeFloat(-0.004103539418429137f);
        los.writeFloat(0.03536746241152287f);
        los.writeInt(21458);  // # rows, assuming square matrix

        los.close();
        bos.close();
        fos.close();

    }
 
Example #5
Source File: AsciiToBinConverter.java    From JuiceboxLegacy with MIT License 5 votes vote down vote up
/**
 * @param inputPath
 * @param outputFile
 */
public static void convert(String inputPath, String outputFile, List<Chromosome> chromosomes) throws IOException {

    Map<String, Integer> chromosomeOrdinals = new HashMap<String, Integer>();
    for (Chromosome c : chromosomes) {
        chromosomeOrdinals.put(c.getName(), c.getIndex());
    }

    AsciiPairIterator iter = null;
    BufferedOutputStream bos = null;
    try {
        bos = new BufferedOutputStream(new FileOutputStream(outputFile));
        LittleEndianOutputStream les = new LittleEndianOutputStream(bos);
        iter = new AsciiPairIterator(inputPath, chromosomeOrdinals
        );

        while (iter.hasNext()) {
            AlignmentPair pair = iter.next();
            les.writeBoolean(pair.getStrand1());
            les.writeInt(pair.getChr1());
            les.writeInt(pair.getPos1());
            les.writeInt(pair.getFrag1());
            les.writeBoolean(pair.getStrand2());
            les.writeInt(pair.getChr2());
            les.writeInt(pair.getPos2());
            les.writeInt(pair.getFrag2());
        }
        les.flush();
        bos.flush();
    } finally {
        if (iter != null) iter.close();
        if (bos != null) bos.close();

    }
}
 
Example #6
Source File: Preprocessor.java    From Juicebox with MIT License 5 votes vote down vote up
protected void updateIndexPositions(List<IndexEntry> blockIndex, LittleEndianOutputStream[] losArray, boolean doRestore,
                                    File outputFile, long currentPosition, long blockIndexPosition) throws IOException {

    // Temporarily close output stream.  Remember position
    long losPos = 0;
    if (doRestore) {
        losPos = losArray[0].getWrittenCount();
        losArray[0].close();
    }

    RandomAccessFile raf = null;
    try {
        raf = new RandomAccessFile(outputFile, "rw");

        // Block indices
        long pos = blockIndexPosition;
        raf.getChannel().position(pos);

        // Write as little endian
        BufferedByteWriter buffer = new BufferedByteWriter();
        for (IndexEntry aBlockIndex : blockIndex) {
            buffer.putInt(aBlockIndex.id);
            buffer.putLong(aBlockIndex.position + currentPosition);
            buffer.putInt(aBlockIndex.size);
        }
        raf.write(buffer.getBytes());

    } finally {
        if (raf != null) raf.close();
    }
    if (doRestore) {
        FileOutputStream fos = new FileOutputStream(outputFile, true);
        fos.getChannel().position(losPos);
        losArray[0] = new LittleEndianOutputStream(new BufferedOutputStream(fos, HiCGlobals.bufferSize));
        losArray[0].setWrittenCount(losPos);
    }
}
 
Example #7
Source File: AsciiToBinConverter.java    From Juicebox with MIT License 5 votes vote down vote up
/**
 * @param inputPath
 * @param outputFile
 * @param chromosomeHandler
 */
public static void convert(String inputPath, String outputFile, ChromosomeHandler chromosomeHandler) throws IOException {

    Map<String, Integer> chromosomeOrdinals = new HashMap<>();
    for (Chromosome c : chromosomeHandler.getChromosomeArray()) {
        chromosomeOrdinals.put(c.getName(), c.getIndex());
    }

    AsciiPairIterator iter = null;
    BufferedOutputStream bos = null;
    try {
        bos = new BufferedOutputStream(new FileOutputStream(outputFile));
        LittleEndianOutputStream les = new LittleEndianOutputStream(bos);
        iter = new AsciiPairIterator(inputPath, chromosomeOrdinals, chromosomeHandler);

        while (iter.hasNext()) {
            AlignmentPair pair = iter.next();
            les.writeBoolean(pair.getStrand1());
            les.writeInt(pair.getChr1());
            les.writeInt(pair.getPos1());
            les.writeInt(pair.getFrag1());
            les.writeBoolean(pair.getStrand2());
            les.writeInt(pair.getChr2());
            les.writeInt(pair.getPos2());
            les.writeInt(pair.getFrag2());
        }
        les.flush();
        bos.flush();
    } finally {
        if (iter != null) iter.close();
        if (bos != null) bos.close();

    }
}
 
Example #8
Source File: Pearsons.java    From Juicebox with MIT License 5 votes vote down vote up
private void writeHeader(LittleEndianOutputStream les, int dim, float lower, float upper) throws IOException {

        // Magic number - 4 bytes
        les.writeByte('h');
        les.writeByte('i');
        les.writeByte('c');
        les.writeByte(0);

        // Version number
        les.writeInt(1);

        // Genome --
        les.writeString(dataset.getGenomeId());

        // Chromosomes
        les.writeString(chromosome1.getName());
        les.writeString(chromosome1.getName());

        // Resolution (bin size)
        les.writeInt(binSize);

        // Statistics, other attributes
        les.writeFloat(lower);  // this is supposed to be lower quartile
        les.writeFloat(upper);  // this is supposed to be upper quartile
        les.writeInt(dim);  // # rows
        les.writeInt(dim);  // # cols
        les.writeInt(BLOCK_TILE);
    }