for (int i = 0; i < records.size(); i++) {
if (i < 10)
System.out.println(records.get(i).toString());
}
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(
BYTES);
ReadWrite.writeCramHeader(cramHeader, baos);
byte[] b = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
CramHeader cramHeader2 = ReadWrite.readCramHeader(bais);
assertEquals(toString(cramHeader.samFileHeader),
toString(cramHeader2.samFileHeader));
BLOCK_PROTO.recordsPerSlice = container.slices[0].nofRecords;
Container container2 = BLOCK_PROTO.buildContainer(records,
cramHeader.samFileHeader, true, 0, container.h.substitutionMatrix, true);
for (int i = 0; i < container.slices.length; i++) {
container2.slices[i].refMD5 = container.slices[i].refMD5;
}
ReadWrite.writeContainer(container2, baos);
bais = new ByteArrayInputStream(baos.toByteArray());
cramHeader2 = ReadWrite.readCramHeader(bais);
assertNotNull(cramHeader);
assertNotNull(cramHeader.samFileHeader);
assertEquals(2, cramHeader.majorVersion);
assertEquals(0, cramHeader.minorVersion);
Container container3 = new Container();
chio.readContainerHeader(container3, bais);
assertNotNull(container3);
System.out.println(container3);
CompressionHeaderBLock chb3 = new CompressionHeaderBLock(bais);
container3.h = chb3.getCompressionHeader();
assertNotNull(container3.h);
System.out.println(container3.h);
container3.slices = new Slice[container3.landmarks.length];
for (int s = 0; s < container3.landmarks.length; s++) {
Slice slice = new Slice();
sio.readSliceHeadBlock(slice, bais);
sio.readSliceBlocks(slice, true, bais);
container3.slices[s] = slice;
}
System.out.println(container3);
ArrayList<CramRecord> records3 = new ArrayList<CramRecord>(
container3.nofRecords);
BLOCK_PROTO.getRecords(container3.h, container3,
cramHeader.samFileHeader, records3);
testALignmentSpan(container3, cramHeader, records3);
for (int i = 0; i < records3.size(); i++) {
System.out.println(records3.get(i).toString());
if (i > 10)
break;
}
assertEquals(container.alignmentStart, container3.alignmentStart);
assertEquals(container.alignmentSpan, container3.alignmentSpan);
assertEquals(container.bases, container3.bases);
assertEquals(container.globalRecordCounter,
container3.globalRecordCounter);
assertEquals(container.landmarks.length, container3.landmarks.length);
assertEquals(container.nofRecords, container3.nofRecords);
assertEquals(container.sequenceId, container3.sequenceId);
assertEquals(records.size(), records3.size());
for (int i = 0; i < records.size(); i++) {
CramRecord r1 = records.get(i);
CramRecord r3 = records3.get(i);
assertTrue(
"Mismatch at " + i + ":\n" + r1.toString() + "\n"
+ r3.toString(), compare(r1, r3));
}
FileOutputStream fos = new FileOutputStream(new File("./src/test/resources/data/set1/small.cram2")) ;
fos.write(baos.getBuffer(), 0, baos.size()) ;
fos.close() ;
}