Search in sources :

Example 21 with VDJCAlignments

use of com.milaboratory.mixcr.basictypes.VDJCAlignments 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 22 with VDJCAlignments

use of com.milaboratory.mixcr.basictypes.VDJCAlignments 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)

Example 23 with VDJCAlignments

use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.

the class ActionFilterAlignments method go.

@Override
public void go(ActionHelper helper) throws Exception {
    try (VDJCAlignmentsReader reader = parameters.getInput();
        VDJCAlignmentsWriter writer = parameters.getOutput()) {
        CanReportProgress progress = reader;
        OutputPort<VDJCAlignments> sReads = reader;
        if (parameters.limit != 0) {
            sReads = new CountLimitingOutputPort<>(sReads, parameters.limit);
            progress = SmartProgressReporter.extractProgress((CountLimitingOutputPort<?>) sReads);
        }
        writer.header(reader.getParameters(), reader.getUsedGenes());
        SmartProgressReporter.startProgressReport("Filtering", progress);
        int total = 0, passed = 0;
        final AlignmentsFilter filter = parameters.getFilter();
        for (VDJCAlignments al : CUtils.it(CUtils.buffered(sReads, 2048))) {
            ++total;
            if (filter.accept(al)) {
                writer.write(al);
                ++passed;
            }
        }
        writer.setNumberOfProcessedReads(reader.getNumberOfReads());
        System.out.printf("%s alignments analysed\n", total);
        System.out.printf("%s alignments written (%.1f%%)\n", passed, 100.0 * passed / total);
    }
}
Also used : CountLimitingOutputPort(cc.redberry.pipe.util.CountLimitingOutputPort) CanReportProgress(com.milaboratory.util.CanReportProgress) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 24 with VDJCAlignments

use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.

the class ActionSortAlignments method go.

@Override
public void go(ActionHelper helper) throws Exception {
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(parameters.getInputFile())) {
        SmartProgressReporter.startProgressReport("Reading vdjca", reader);
        try (OutputPortCloseable<VDJCAlignments> sorted = Sorter.sort(reader, idComparator, 1024 * 512, new VDJCAlignmentsSerializer(reader), TempFileManager.getTempFile());
            VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(parameters.getOutputFile())) {
            writer.header(reader.getParameters(), reader.getUsedGenes());
            final long nReads = reader.getNumberOfReads();
            final CountingOutputPort<VDJCAlignments> counter = new CountingOutputPort<>(sorted);
            SmartProgressReporter.startProgressReport("Writing sorted alignments", SmartProgressReporter.extractProgress(counter, nReads));
            for (VDJCAlignments res : CUtils.it(counter)) writer.write(res);
            writer.setNumberOfProcessedReads(nReads);
        }
    }
}
Also used : VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) CountingOutputPort(cc.redberry.pipe.util.CountingOutputPort) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 25 with VDJCAlignments

use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.

the class VDJCAlignerPVFirst method processPartial.

private VDJCAlignmentResult<PairedRead> processPartial(PairedRead input, PAlignmentHelper[] helpers) {
    // Calculates which PTarget was aligned with the highest score
    helpers[0].performCDAlignment();
    PAlignmentHelper bestHelper = helpers[0];
    for (int i = 1; i < helpers.length; ++i) {
        helpers[i].performCDAlignment();
        if (bestHelper.score() < helpers[i].score())
            bestHelper = helpers[i];
    }
    if (!bestHelper.hasVOrJHits()) {
        onFailedAlignment(input, VDJCAlignmentFailCause.NoHits);
        return new VDJCAlignmentResult<>(input);
    }
    // Calculates if this score is bigger then the threshold
    if (bestHelper.score() < parameters.getMinSumScore()) {
        onFailedAlignment(input, VDJCAlignmentFailCause.LowTotalScore);
        return new VDJCAlignmentResult<>(input);
    }
    // Finally filtering hits inside this helper to meet minSumScore and maxHits limits
    bestHelper.filterHits(parameters.getMinSumScore(), parameters.getMaxHits());
    // TODO do we really need this ?
    if (!bestHelper.hasVOrJHits()) {
        onFailedAlignment(input, VDJCAlignmentFailCause.LowTotalScore);
        return new VDJCAlignmentResult<>(input);
    }
    VDJCAlignments alignments = bestHelper.createResult(input.getId(), this, input);
    // Final check
    if (!parameters.getAllowNoCDR3PartAlignments()) {
        // CDR3 Begin / End
        boolean containCDR3Parts = false;
        final VDJCHit bestV = alignments.getBestHit(GeneType.Variable);
        final VDJCHit bestJ = alignments.getBestHit(GeneType.Joining);
        for (int i = 0; i < 2; i++) {
            if ((bestV != null && bestV.getAlignment(i) != null && bestV.getAlignment(i).getSequence1Range().getTo() >= bestV.getGene().getPartitioning().getRelativePosition(parameters.getFeatureToAlign(GeneType.Variable), reqPointL)) || (bestJ != null && bestJ.getAlignment(i) != null && bestJ.getAlignment(i).getSequence1Range().getFrom() <= bestJ.getGene().getPartitioning().getRelativePosition(parameters.getFeatureToAlign(GeneType.Joining), reqPointR))) {
                containCDR3Parts = true;
                break;
            }
        }
        if (!containCDR3Parts) {
            onFailedAlignment(input, VDJCAlignmentFailCause.NoCDR3Parts);
            return new VDJCAlignmentResult<>(input);
        }
    }
    // Read successfully aligned
    onSuccessfulAlignment(input, alignments);
    if (bestHelper.vChimera)
        onSegmentChimeraDetected(GeneType.Variable, input, alignments);
    if (bestHelper.jChimera)
        onSegmentChimeraDetected(GeneType.Joining, input, alignments);
    return new VDJCAlignmentResult<>(input, alignments);
}
Also used : VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Aggregations

VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)29 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)11 Test (org.junit.Test)10 SequenceRead (com.milaboratory.core.io.sequence.SequenceRead)8 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)8 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)8 PairedRead (com.milaboratory.core.io.sequence.PairedRead)7 VDJCGene (io.repseq.core.VDJCGene)7 SingleReadImpl (com.milaboratory.core.io.sequence.SingleReadImpl)6 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)6 GeneType (io.repseq.core.GeneType)6 Well44497b (org.apache.commons.math3.random.Well44497b)6 Clone (com.milaboratory.mixcr.basictypes.Clone)5 VDJCAlignmentsReader (com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader)5 VDJCAlignmentsWriter (com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter)5 ArrayList (java.util.ArrayList)5 CUtils (cc.redberry.pipe.CUtils)4 Target (com.milaboratory.core.Target)4 CanReportProgress (com.milaboratory.util.CanReportProgress)4 GeneFeature (io.repseq.core.GeneFeature)4