use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerS in project mixcr by milaboratory.
the class IOTest method testSerialization1.
@Test
public void testSerialization1() throws Exception {
VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
List<VDJCAlignments> alignemntsList = new ArrayList<>();
int header;
long numberOfReads;
try (SingleFastqReader reader = new SingleFastqReader(IOTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), true)) {
VDJCAlignerS aligner = new VDJCAlignerS(parameters);
for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) {
if (parameters.containsRequiredFeature(gene))
aligner.addGene(gene);
}
try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(bos)) {
writer.header(aligner);
header = bos.size();
for (SingleRead read : CUtils.it(reader)) {
VDJCAlignmentResult<SingleRead> result = aligner.process(read);
if (result.alignment != null) {
writer.write(result.alignment);
alignemntsList.add(result.alignment);
}
}
writer.setNumberOfProcessedReads(numberOfReads = reader.getNumberOfReads());
}
}
assertTrue(alignemntsList.size() > 10);
assertTrue(numberOfReads > 10);
System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()))) {
int i = 0;
for (VDJCAlignments alignments : CUtils.it(reader)) assertEquals(alignemntsList.get(i++), alignments);
Assert.assertEquals(numberOfReads, reader.getNumberOfReads());
}
}
Aggregations