private void writeHeader() { // magic string final byte[] magic = BAMFileConstants.BAM_INDEX_MAGIC; codec.writeBytes(magic); codec.writeInt(nRef); }
private void writeHeader() { // magic string final byte[] magic = BAMFileConstants.BAM_INDEX_MAGIC; codec.writeBytes(magic); codec.writeInt(nRef); }
private void writeHeader(int nRef) { // magic string final byte[] magic = BAMFileConstants.BAM_INDEX_MAGIC; codec.writeBytes(magic); codec.writeInt(nRef); }
private void writeHeader() { // magic string final byte[] magic = BAMFileConstants.BAM_INDEX_MAGIC; codec.writeBytes(magic); codec.writeInt(nRef); }
private void writeHeader(int nRef) { // magic string final byte[] magic = BAMFileConstants.BAM_INDEX_MAGIC; codec.writeBytes(magic); codec.writeInt(nRef); }
private void writeBin(final Bin bin) { final int binNumber = bin.getBinNumber(); if (binNumber >= GenomicIndexUtil.MAX_BINS){ throw new SAMException("Unexpected bin number when writing bam index " + binNumber); } codec.writeInt(binNumber); if (bin.getChunkList() == null){ codec.writeInt(0); return; } final List<Chunk> chunkList = bin.getChunkList(); final int n_chunk = chunkList.size(); codec.writeInt(n_chunk); for (final Chunk c : chunkList) { codec.writeLong(c.getChunkStart()); codec.writeLong(c.getChunkEnd()); } }
private void writeBin(final Bin bin) { final int binNumber = bin.getBinNumber(); if (binNumber >= GenomicIndexUtil.MAX_BINS){ throw new SAMException("Unexpected bin number when writing bam index " + binNumber); } codec.writeInt(binNumber); if (bin.getChunkList() == null){ codec.writeInt(0); return; } final List<Chunk> chunkList = bin.getChunkList(); final int n_chunk = chunkList.size(); codec.writeInt(n_chunk); for (final Chunk c : chunkList) { codec.writeLong(c.getChunkStart()); codec.writeLong(c.getChunkEnd()); } }
private void writeHeader(final SAMFileHeader header) { binaryCodec.writeBytes("BAM\001".getBytes(Charset.forName("UTF8"))); final Writer sw = new StringWriter(); new SAMTextHeaderCodec().encode(sw, header); binaryCodec.writeString(sw.toString(), true, false); final SAMSequenceDictionary dict = header.getSequenceDictionary(); binaryCodec.writeInt(dict.size()); for (final SAMSequenceRecord rec : dict.getSequences()) { binaryCodec.writeString(rec.getSequenceName(), true, true); binaryCodec.writeInt (rec.getSequenceLength()); } } }
private void writeHeader(final SAMFileHeader header) { binaryCodec.writeBytes("BAM\001".getBytes(Charset.forName("UTF8"))); final Writer sw = new StringWriter(); new SAMTextHeaderCodec().encode(sw, header); binaryCodec.writeString(sw.toString(), true, false); final SAMSequenceDictionary dict = header.getSequenceDictionary(); binaryCodec.writeInt(dict.size()); for (final SAMSequenceRecord rec : dict.getSequences()) { binaryCodec.writeString(rec.getSequenceName(), true, true); binaryCodec.writeInt (rec.getSequenceLength()); } } }
private void writeHeader(final SAMFileHeader header) { binaryCodec.writeBytes("BAM\001".getBytes(Charset.forName("UTF8"))); final Writer sw = new StringWriter(); new SAMTextHeaderCodec().encode(sw, header); binaryCodec.writeString(sw.toString(), true, false); final SAMSequenceDictionary dict = header.getSequenceDictionary(); binaryCodec.writeInt(dict.size()); for (final SAMSequenceRecord rec : dict.getSequences()) { binaryCodec.writeString(rec.getSequenceName(), true, true); binaryCodec.writeInt (rec.getSequenceLength()); } } }
/** * Write the meta data represented by the chunkLists associated with bin MAX_BINS 37450 * * @param metaData information describing numAligned records, numUnAligned, etc */ private void writeChunkMetaData(final BAMIndexMetaData metaData) { codec.writeInt(GenomicIndexUtil.MAX_BINS); final int nChunk = 2; codec.writeInt(nChunk); codec.writeLong(metaData.getFirstOffset()); codec.writeLong(metaData.getLastOffset()); codec.writeLong(metaData.getAlignedRecordCount()); codec.writeLong(metaData.getUnalignedRecordCount()); }
static void writeHeader(final BinaryCodec outputBinaryCodec, final SAMFileHeader samFileHeader, final String headerText) { outputBinaryCodec.writeBytes("BAM\1".getBytes()); // calculate and write the length of the SAM file header text and the // header text outputBinaryCodec.writeString(headerText, true, false); // write the sequences binarily. This is redundant with the text header outputBinaryCodec.writeInt(samFileHeader.getSequenceDictionary().size()); for (final SAMSequenceRecord sequenceRecord : samFileHeader.getSequenceDictionary().getSequences()) { outputBinaryCodec.writeString(sequenceRecord.getSequenceName(), true, true); outputBinaryCodec.writeInt(sequenceRecord.getSequenceLength()); } }
/** * Write the meta data represented by the chunkLists associated with bin MAX_BINS 37450 * * @param metaData information describing numAligned records, numUnAligned, etc */ private void writeChunkMetaData(final BAMIndexMetaData metaData) { codec.writeInt(GenomicIndexUtil.MAX_BINS); final int nChunk = 2; codec.writeInt(nChunk); codec.writeLong(metaData.getFirstOffset()); codec.writeLong(metaData.getLastOffset()); codec.writeLong(metaData.getAlignedRecordCount()); codec.writeLong(metaData.getUnalignedRecordCount()); }
/** * Write the meta data represented by the chunkLists associated with bin MAX_BINS 37450 * * @param metaData information describing numAligned records, numUnAligned, etc */ private void writeChunkMetaData(final BAMIndexMetaData metaData) { codec.writeInt(GenomicIndexUtil.MAX_BINS); final int nChunk = 2; codec.writeInt(nChunk); codec.writeLong(metaData.getFirstOffset()); codec.writeLong(metaData.getLastOffset()); codec.writeLong(metaData.getAlignedRecordCount()); codec.writeLong(metaData.getUnalignedRecordCount()); }
/** * Write the meta data represented by the chunkLists associated with bin MAX_BINS 37450 * * @param metaData information describing numAligned records, numUnAligned, etc */ private void writeChunkMetaData(final BAMIndexMetaData metaData) { codec.writeInt(GenomicIndexUtil.MAX_BINS); final int nChunk = 2; codec.writeInt(nChunk); codec.writeLong(metaData.getFirstOffset()); codec.writeLong(metaData.getLastOffset()); codec.writeLong(metaData.getAlignedRecordCount()); codec.writeLong(metaData.getUnalignedRecordCount()); }
/** * Write the meta data represented by the chunkLists associated with bin MAX_BINS 37450 * * @param metaData information describing numAligned records, numUnAligned, etc */ private void writeChunkMetaData(final BAMIndexMetaData metaData) { codec.writeInt(GenomicIndexUtil.MAX_BINS); final int nChunk = 2; codec.writeInt(nChunk); codec.writeLong(metaData.getFirstOffset()); codec.writeLong(metaData.getLastOffset()); codec.writeLong(metaData.getAlignedRecordCount()); codec.writeLong(metaData.getUnalignedRecordCount()); }
/** * Writes a header to a BAM file. samFileHeader and headerText are redundant - one can be used to regenerate the other but in * some instances we already have both so this allows us to save some cycles */ protected static void writeHeader(final BinaryCodec outputBinaryCodec, final SAMFileHeader samFileHeader, final String headerText) { outputBinaryCodec.writeBytes(BAMFileConstants.BAM_MAGIC); // calculate and write the length of the SAM file header text and the header text outputBinaryCodec.writeString(headerText, true, false); // write the sequences binarily. This is redundant with the text header outputBinaryCodec.writeInt(samFileHeader.getSequenceDictionary().size()); for (final SAMSequenceRecord sequenceRecord: samFileHeader.getSequenceDictionary().getSequences()) { outputBinaryCodec.writeString(sequenceRecord.getSequenceName(), true, true); outputBinaryCodec.writeInt(sequenceRecord.getSequenceLength()); } }
/** * Writes a header to a BAM file. samFileHeader and headerText are redundant - one can be used to regenerate the other but in * some instances we already have both so this allows us to save some cycles */ protected static void writeHeader(final BinaryCodec outputBinaryCodec, final SAMFileHeader samFileHeader, final String headerText) { outputBinaryCodec.writeBytes(BAMFileConstants.BAM_MAGIC); // calculate and write the length of the SAM file header text and the header text outputBinaryCodec.writeString(headerText, true, false); // write the sequences binarily. This is redundant with the text header outputBinaryCodec.writeInt(samFileHeader.getSequenceDictionary().size()); for (final SAMSequenceRecord sequenceRecord: samFileHeader.getSequenceDictionary().getSequences()) { outputBinaryCodec.writeString(sequenceRecord.getSequenceName(), true, true); outputBinaryCodec.writeInt(sequenceRecord.getSequenceLength()); } }
/** * Writes a header to a BAM file. samFileHeader and headerText are redundant - one can be used to regenerate the other but in * some instances we already have both so this allows us to save some cycles */ protected static void writeHeader(final BinaryCodec outputBinaryCodec, final SAMFileHeader samFileHeader, final String headerText) { outputBinaryCodec.writeBytes(BAMFileConstants.BAM_MAGIC); // calculate and write the length of the SAM file header text and the header text outputBinaryCodec.writeString(headerText, true, false); // write the sequences binarily. This is redundant with the text header outputBinaryCodec.writeInt(samFileHeader.getSequenceDictionary().size()); for (final SAMSequenceRecord sequenceRecord: samFileHeader.getSequenceDictionary().getSequences()) { outputBinaryCodec.writeString(sequenceRecord.getSequenceName(), true, true); outputBinaryCodec.writeInt(sequenceRecord.getSequenceLength()); } }
@Test public void testReadAndWriteInt() throws IOException { final int value = 42; //Writing to file final File outputFile = File.createTempFile(TEST_BASENAME, ".bin"); outputFile.deleteOnExit(); final OutputStream stream = new FileOutputStream(outputFile); final BinaryCodec codec = new BinaryCodec(stream); codec.writeInt(value); codec.close(); //Reading from file final InputStream instream = new FileInputStream(outputFile); final BinaryCodec readCodec = new BinaryCodec(instream); Assert.assertEquals(value, readCodec.readInt()); readCodec.close(); }