Search in sources :

Example 1 with VDJCAlignerS

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());
    }
}
Also used : VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) VDJCAlignerS(com.milaboratory.mixcr.vdjaligners.VDJCAlignerS) SingleFastqReader(com.milaboratory.core.io.sequence.fastq.SingleFastqReader) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VDJCGene(io.repseq.core.VDJCGene) SingleRead(com.milaboratory.core.io.sequence.SingleRead) Test(org.junit.Test)

Aggregations

SingleRead (com.milaboratory.core.io.sequence.SingleRead)1 SingleFastqReader (com.milaboratory.core.io.sequence.fastq.SingleFastqReader)1 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)1 VDJCAlignerS (com.milaboratory.mixcr.vdjaligners.VDJCAlignerS)1 VDJCGene (io.repseq.core.VDJCGene)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1