Search in sources :

Example 6 with VDJCAlignerParameters

use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters 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 7 with VDJCAlignerParameters

use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.

the class FieldExtractorsTest method testAnchorPoints1.

@Test
public void testAnchorPoints1() throws Exception {
    final boolean print = false;
    final Well44497b rg = new Well44497b(12312);
    final VDJCAlignerParameters rnaSeqParams = VDJCParametersPresets.getByName("rna-seq");
    final PartialAlignmentsAssemblerAligner aligner = new PartialAlignmentsAssemblerAligner(rnaSeqParams);
    final VDJCLibrary lib = VDJCLibraryRegistry.getDefault().getLibrary("default", "hs");
    for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes()) if (gene.isFunctional())
        aligner.addGene(gene);
    final TargetBuilder.VDJCGenes genes = new TargetBuilder.VDJCGenes(lib, "TRBV12-3*00", "TRBD1*00", "TRBJ1-3*00", "TRBC2*00");
    // | 310  | 338   | 438
    // 250V + 60CDR3 (20V 7N 10D 3N 20J) + 28J + 100C + 100N
    // "{CDR3Begin(-250)}V*270 NNNNNNN {DBegin(0)}D*10 NNN {CDR3End(-20):FR4End} {CBegin}C*100 N*100"
    final FieldExtractors.ExtractDefaultReferencePointsPositions extractor = new FieldExtractors.ExtractDefaultReferencePointsPositions();
    F6 goAssert = new F6() {

        @Override
        public Integer[][] go(String seq, int len, int offset1, int offset2, int offset3, String expected) {
            final NucleotideSequence baseSeq = TargetBuilder.generateSequence(genes, seq, rg);
            NucleotideSequence seq1 = baseSeq.getRange(offset1, Math.min(baseSeq.size(), offset1 + len));
            NucleotideSequence seq2 = offset2 == -1 ? null : baseSeq.getRange(offset2, Math.min(baseSeq.size(), offset2 + len));
            NucleotideSequence seq3 = offset3 == -1 ? null : baseSeq.getRange(offset3, Math.min(baseSeq.size(), offset3 + len));
            VDJCAlignmentResult<VDJCMultiRead> alignment = offset3 == -1 ? offset2 == -1 ? aligner.process(MiXCRTestUtils.createMultiRead(seq1)) : aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2)) : aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2, seq3));
            VDJCAlignments al = alignment.alignment;
            Assert.assertNotNull(al);
            if (print) {
                MiXCRTestUtils.printAlignment(al);
                System.out.println();
                System.out.println("-------------------------------------------");
                System.out.println();
            }
            String val = extractor.extract(al);
            if (print)
                System.out.println(val);
            String[] spl = val.split(",");
            Integer[][] result = new Integer[spl.length][ReferencePoint.DefaultReferencePoints.length];
            for (int i = 0; i < spl.length; i++) {
                String[] spl1 = spl[i].split(":");
                for (int j = 0; j < spl1.length; j++) {
                    try {
                        result[i][j] = Integer.decode(spl1[j]);
                    } catch (NumberFormatException e) {
                    }
                }
            }
            return result;
        }
    };
    // No PSegments, just deletions
    Integer[][] r = goAssert.go("{CDR3Begin(-250):VEnd(-3)} 'CCAAA' {DBegin(0):DEnd(0)} 'AAA' {JBegin(2):FR4End} " + "{CBegin}C*100 N*100", 100, 240, 307, 450, "");
    assertExportPoint(r[0], ReferencePoint.VEnd, -3);
    assertExportPoint(r[0], ReferencePoint.DBegin, 0);
    assertExportPoint(r[0], ReferencePoint.DEnd, 0);
    assertExportPoint(r[0], ReferencePoint.JBegin, -2);
    r = goAssert.go("{CDR3Begin(-250):VEnd(0)} 'CCAAA' {DBegin(0):DEnd(-2)} 'AAA' {JBegin:FR4End} {CBegin}C*100 N*100", 100, 240, 307, 450, "");
    assertExportPoint(r[0], ReferencePoint.VEnd, 0);
    assertExportPoint(r[0], ReferencePoint.DBegin, 0);
    assertExportPoint(r[0], ReferencePoint.DEnd, -2);
    assertExportPoint(r[0], ReferencePoint.JBegin, 0);
    // With PSegments
    r = goAssert.go("{CDR3Begin(-250):VEnd(0)} {VEnd:VEnd(-3)} 'CCAAA' {DBegin(3):DBegin} {DBegin:DEnd(-2)} 'AAA' " + "{JBegin(2):JBegin} {JBegin:FR4End} {CBegin}C*100 N*100", 100, 240, 307, 450, "");
    assertExportPoint(r[0], ReferencePoint.VEnd, 3);
    assertExportPoint(r[0], ReferencePoint.DBegin, 3);
    assertExportPoint(r[0], ReferencePoint.DEnd, -2);
    assertExportPoint(r[0], ReferencePoint.JBegin, 2);
}
Also used : VDJCMultiRead(com.milaboratory.mixcr.partialassembler.VDJCMultiRead) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) PartialAlignmentsAssemblerAligner(com.milaboratory.mixcr.partialassembler.PartialAlignmentsAssemblerAligner) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Well44497b(org.apache.commons.math3.random.Well44497b) TargetBuilder(com.milaboratory.mixcr.tests.TargetBuilder) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) Test(org.junit.Test)

Example 8 with VDJCAlignerParameters

use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.

the class RunMiXCR method align.

public static AlignResult align(RunMiXCRAnalysis parameters) throws Exception {
    VDJCAlignerParameters alignerParameters = parameters.alignerParameters;
    VDJCAligner aligner = VDJCAligner.createAligner(alignerParameters, parameters.isInputPaired(), alignerParameters.getMergerParameters() != null);
    List<VDJCGene> genes = new ArrayList<>();
    for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary(parameters.library, parameters.species).getGenes(parameters.chains)) if (alignerParameters.containsRequiredFeature(gene) && (gene.isFunctional() || !parameters.isFunctionalOnly)) {
        genes.add(gene);
        aligner.addGene(gene);
    }
    AlignerReport report = new AlignerReport();
    aligner.setEventsListener(report);
    try (SequenceReaderCloseable<? extends SequenceRead> reader = parameters.getReader()) {
        // start progress reporting
        if (reader instanceof CanReportProgress)
            SmartProgressReporter.startProgressReport("align", (CanReportProgress) reader);
        OutputPort<Chunk<SequenceRead>> mainInputReads = CUtils.buffered((OutputPort) chunked(reader, 64), 16);
        OutputPort<VDJCAlignmentResult> alignments = unchunked(new ParallelProcessor(mainInputReads, chunked(aligner), parameters.threads));
        List<VDJCAlignments> als = new ArrayList<>();
        int ind = 0;
        for (VDJCAlignmentResult t : CUtils.it(new OrderedOutputPort<>(alignments, new Indexer<VDJCAlignmentResult>() {

            @Override
            public long getIndex(VDJCAlignmentResult r) {
                return r.read.getId();
            }
        }))) {
            if (t.alignment != null) {
                t.alignment.setAlignmentsIndex(ind++);
                als.add(t.alignment);
            }
        }
        return new AlignResult(parameters, reader.getNumberOfReads(), report, als, genes, aligner);
    }
}
Also used : AlignerReport(com.milaboratory.mixcr.cli.AlignerReport) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) ArrayList(java.util.ArrayList) VDJCAlignmentResult(com.milaboratory.mixcr.vdjaligners.VDJCAlignmentResult) Chunk(cc.redberry.pipe.util.Chunk) VDJCAligner(com.milaboratory.mixcr.vdjaligners.VDJCAligner) ParallelProcessor(cc.redberry.pipe.blocks.ParallelProcessor) Indexer(cc.redberry.pipe.util.Indexer) CanReportProgress(com.milaboratory.util.CanReportProgress) VDJCGene(io.repseq.core.VDJCGene) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 9 with VDJCAlignerParameters

use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.

the class JsonOverriderTest method test3.

@Test
public void test3() throws Exception {
    GeneFeature jRegion = GeneFeature.parse("JRegion");
    System.out.println(jRegion);
    System.out.println(GeneFeature.encode(jRegion));
    VDJCAlignerParameters params = VDJCParametersPresets.getByName("default");
    Map<String, String> overrides = new HashMap<String, String>() {

        {
            put("vParameters.geneFeatureToAlign", "VTranscript");
        }
    };
    Assert.assertNotNull(JsonOverrider.override(params, VDJCAlignerParameters.class, overrides));
}
Also used : GeneFeature(io.repseq.core.GeneFeature) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with VDJCAlignerParameters

use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.

the class PartialAlignmentsAssemblerAlignerTest method basicTest1.

@Test
public void basicTest1() throws Exception {
    Well44497b rg = new Well44497b(12312);
    VDJCAlignerParameters rnaSeqParams = VDJCParametersPresets.getByName("rna-seq");
    PartialAlignmentsAssemblerAligner aligner = new PartialAlignmentsAssemblerAligner(rnaSeqParams);
    VDJCLibrary lib = VDJCLibraryRegistry.getDefault().getLibrary("default", "hs");
    for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes()) if (gene.isFunctional())
        aligner.addGene(gene);
    TargetBuilder.VDJCGenes genes = new TargetBuilder.VDJCGenes(lib, "TRBV12-3*00", "TRBD1*00", "TRBJ1-3*00", "TRBC2*00");
    // | 305
    // 250V + 55CDR3 (20V 7N 10D 3N 15J) + 28J + 100C
    NucleotideSequence baseSeq = TargetBuilder.generateSequence(genes, "{CDR3Begin(-250)}V*270 NNNNNNN {DBegin(0)}D*10 NNN {CDR3End(-15):FR4End} {CBegin}C*100", rg);
    int len = 70;
    NucleotideSequence seq1 = baseSeq.getRange(0, len);
    NucleotideSequence seq2 = baseSeq.getRange(245, 245 + len);
    NucleotideSequence seq3 = baseSeq.getRange(320, 320 + len);
    VDJCAlignmentResult<VDJCMultiRead> alignment = aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2, seq3));
    VDJCAlignments al = alignment.alignment;
    Assert.assertNotNull(al);
    assertInHits(genes.v, al);
    assertInHits(genes.d, al);
    assertInHits(genes.j, al);
    assertInHits(genes.c, al);
    VDJCHit bestV = al.getBestHit(GeneType.Variable);
    VDJCHit bestD = al.getBestHit(GeneType.Diversity);
    VDJCHit bestJ = al.getBestHit(GeneType.Joining);
    VDJCHit bestC = al.getBestHit(GeneType.Constant);
    Assert.assertNotNull(bestV.getAlignment(0));
    Assert.assertNotNull(bestV.getAlignment(1));
    Assert.assertNull(bestV.getAlignment(2));
    Assert.assertNull(bestD.getAlignment(0));
    Assert.assertNotNull(bestD.getAlignment(1));
    Assert.assertNull(bestD.getAlignment(2));
    Assert.assertNull(bestJ.getAlignment(0));
    Assert.assertNotNull(bestJ.getAlignment(1));
    Assert.assertNotNull(bestJ.getAlignment(2));
    Assert.assertNull(bestC.getAlignment(0));
    Assert.assertNull(bestC.getAlignment(1));
    Assert.assertNotNull(bestC.getAlignment(2));
}
Also used : VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Well44497b(org.apache.commons.math3.random.Well44497b) VDJCLibrary(io.repseq.core.VDJCLibrary) VDJCGene(io.repseq.core.VDJCGene) TargetBuilder(com.milaboratory.mixcr.tests.TargetBuilder) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit) Test(org.junit.Test)

Aggregations

VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)12 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)6 VDJCGene (io.repseq.core.VDJCGene)6 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 ParallelProcessor (cc.redberry.pipe.blocks.ParallelProcessor)3 TargetBuilder (com.milaboratory.mixcr.tests.TargetBuilder)3 Well44497b (org.apache.commons.math3.random.Well44497b)3 Chunk (cc.redberry.pipe.util.Chunk)2 Indexer (cc.redberry.pipe.util.Indexer)2 ProcessException (com.milaboratory.cli.ProcessException)2 CloneAssemblerParameters (com.milaboratory.mixcr.assembler.CloneAssemblerParameters)2 PartialAlignmentsAssemblerAligner (com.milaboratory.mixcr.partialassembler.PartialAlignmentsAssemblerAligner)2 VDJCMultiRead (com.milaboratory.mixcr.partialassembler.VDJCMultiRead)2 PrimitivI (com.milaboratory.primitivio.PrimitivI)2 CUtils (cc.redberry.pipe.CUtils)1 OutputPort (cc.redberry.pipe.OutputPort)1 CountLimitingOutputPort (cc.redberry.pipe.util.CountLimitingOutputPort)1 DynamicParameter (com.beust.jcommander.DynamicParameter)1