Search in sources :

Example 1 with SingleFastqReader

use of com.milaboratory.core.io.sequence.fastq.SingleFastqReader in project mixcr by milaboratory.

the class VDJCAlignerSTest method testSerialization1.

@Test
public void testSerialization1() throws Exception {
    VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
    // LociLibrary ll = LociLibraryManager.getDefault().getLibrary("mi");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    List<VDJCAlignments> alignemntsList = new ArrayList<>();
    int header;
    try (SingleFastqReader reader = new SingleFastqReader(VDJCAlignerSTest.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);
                }
            }
        }
    }
    Assert.assertTrue(alignemntsList.size() > 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)) Assert.assertEquals(alignemntsList.get(i++), alignments);
    }
}
Also used : SingleFastqReader(com.milaboratory.core.io.sequence.fastq.SingleFastqReader) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) ArrayList(java.util.ArrayList) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VDJCGene(io.repseq.core.VDJCGene) SingleRead(com.milaboratory.core.io.sequence.SingleRead) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) Test(org.junit.Test)

Example 2 with SingleFastqReader

use of com.milaboratory.core.io.sequence.fastq.SingleFastqReader 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)

Example 3 with SingleFastqReader

use of com.milaboratory.core.io.sequence.fastq.SingleFastqReader in project mixcr by milaboratory.

the class CloneAssemblerRunnerTest method runFullPipeline.

private static CloneSet runFullPipeline(String... fastqFiles) throws IOException, InterruptedException {
    // building alignments
    VDJCAlignerParameters alignerParameters = VDJCParametersPresets.getByName("default");
    VDJCAligner aligner = fastqFiles.length == 1 ? new VDJCAlignerS(alignerParameters) : new VDJCAlignerWithMerge(alignerParameters);
    for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("mi", "hs").getGenes(Chains.IGH)) if (alignerParameters.containsRequiredFeature(gene))
        aligner.addGene(gene);
    SequenceReader reader;
    if (fastqFiles.length == 1)
        reader = new SingleFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]), true);
    else
        reader = new PairedFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]), CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[1]), true);
    // write alignments to byte array
    ByteArrayOutputStream alignmentsSerialized = new ByteArrayOutputStream();
    try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(alignmentsSerialized)) {
        writer.header(aligner);
        for (Object read : CUtils.it(reader)) {
            VDJCAlignmentResult result = (VDJCAlignmentResult) aligner.process((SequenceRead) read);
            if (result.alignment != null)
                writer.write(result.alignment);
        }
    }
    AlignmentsProvider alignmentsProvider = AlignmentsProvider.Util.createProvider(alignmentsSerialized.toByteArray(), VDJCLibraryRegistry.getDefault());
    LinearGapAlignmentScoring<NucleotideSequence> scoring = new LinearGapAlignmentScoring<>(NucleotideSequence.ALPHABET, 5, -9, -12);
    CloneFactoryParameters factoryParameters = new CloneFactoryParameters(new VJCClonalAlignerParameters(0.8f, scoring, 5), new VJCClonalAlignerParameters(0.8f, scoring, 5), null, new DAlignerParameters(GeneFeature.DRegion, 0.85f, 30.0f, 3, scoring));
    CloneAssemblerParameters assemblerParameters = new CloneAssemblerParameters(new GeneFeature[] { GeneFeature.CDR3 }, 12, QualityAggregationType.Average, new CloneClusteringParameters(2, 1, TreeSearchParameters.ONE_MISMATCH, new RelativeConcentrationFilter(1.0E-6)), factoryParameters, true, true, false, 0.4, true, (byte) 20, .8, "2 of 6", (byte) 15);
    System.out.println(GlobalObjectMappers.toOneLine(assemblerParameters));
    CloneAssemblerRunner assemblerRunner = new CloneAssemblerRunner(alignmentsProvider, new CloneAssembler(assemblerParameters, true, aligner.getUsedGenes(), alignerParameters), 2);
    SmartProgressReporter.startProgressReport(assemblerRunner);
    assemblerRunner.run();
    CloneSet cloneSet = assemblerRunner.getCloneSet(null);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CloneSetIO.write(cloneSet, bos);
    CloneSet cloneSetDeserialized = CloneSetIO.readClns(new ByteArrayInputStream(bos.toByteArray()));
    assertCSEquals(cloneSet, cloneSetDeserialized);
    OutputPortCloseable<ReadToCloneMapping> rrr = assemblerRunner.assembler.getAssembledReadsPort();
    ReadToCloneMapping take;
    while ((take = rrr.take()) != null) System.out.println(take);
    return cloneSet;
}
Also used : SingleFastqReader(com.milaboratory.core.io.sequence.fastq.SingleFastqReader) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) CloneSet(com.milaboratory.mixcr.basictypes.CloneSet) LinearGapAlignmentScoring(com.milaboratory.core.alignment.LinearGapAlignmentScoring) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) SequenceRead(com.milaboratory.core.io.sequence.SequenceRead) SequenceReader(com.milaboratory.core.io.sequence.SequenceReader) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader)

Aggregations

SingleFastqReader (com.milaboratory.core.io.sequence.fastq.SingleFastqReader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 SingleRead (com.milaboratory.core.io.sequence.SingleRead)2 VDJCAlignmentsWriter (com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter)2 VDJCGene (io.repseq.core.VDJCGene)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 LinearGapAlignmentScoring (com.milaboratory.core.alignment.LinearGapAlignmentScoring)1 SequenceRead (com.milaboratory.core.io.sequence.SequenceRead)1 SequenceReader (com.milaboratory.core.io.sequence.SequenceReader)1 PairedFastqReader (com.milaboratory.core.io.sequence.fastq.PairedFastqReader)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 CloneSet (com.milaboratory.mixcr.basictypes.CloneSet)1 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)1 VDJCAlignmentsReader (com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader)1 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)1 VDJCAlignerS (com.milaboratory.mixcr.vdjaligners.VDJCAlignerS)1