Search in sources :

Example 26 with VDJCAlignments

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

the class VDJCAlignerPVFirst method processStrict.

private VDJCAlignmentResult<PairedRead> processStrict(PairedRead input, PAlignmentHelper[] helpers) {
    // Calculates which PTarget was aligned with the highest score
    PAlignmentHelper bestHelper = helpers[0];
    for (int i = 1; i < helpers.length; ++i) if (bestHelper.score() < helpers[i].score())
        bestHelper = helpers[i];
    // If V or J hits are absent
    if (!bestHelper.hasVAndJHits()) {
        if (!bestHelper.hasVOrJHits())
            onFailedAlignment(input, VDJCAlignmentFailCause.NoHits);
        else if (!bestHelper.hasVHits())
            onFailedAlignment(input, VDJCAlignmentFailCause.NoVHits);
        else
            onFailedAlignment(input, VDJCAlignmentFailCause.NoJHits);
        return new VDJCAlignmentResult<>(input);
    }
    // Performing alignment of C and D genes; if corresponding parameters are set include their scores to
    // the total score value
    bestHelper.performCDAlignment();
    // 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());
    // If hits for V or J are missing after filtration
    if (!bestHelper.isGoodVJ()) {
        if (!bestHelper.hasVHits())
            onFailedAlignment(input, VDJCAlignmentFailCause.NoVHits);
        else if (!bestHelper.hasJHits())
            onFailedAlignment(input, VDJCAlignmentFailCause.NoJHits);
        else if (!bestHelper.hasVJOnTheSameTarget())
            onFailedAlignment(input, VDJCAlignmentFailCause.VAndJOnDifferentTargets);
        else
            onFailedAlignment(input, VDJCAlignmentFailCause.LowTotalScore);
        return new VDJCAlignmentResult<>(input);
    }
    // Read successfully aligned
    VDJCAlignments alignments = bestHelper.createResult(input.getId(), this, input);
    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)

Example 27 with VDJCAlignments

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

the class VDJCAlignerWithMerge method process0.

@Override
protected VDJCAlignmentResult<PairedRead> process0(final PairedRead read) {
    PairedReadMergingResult merged = merger.process(read);
    if (merged.isSuccessful()) {
        VDJCAlignments alignment = singleAligner.process(new SingleReadImpl(read.getId(), merged.getOverlappedSequence(), "")).alignment;
        if (listener != null)
            listener.onSuccessfulSequenceOverlap(read, alignment);
        if (alignment != null) {
            boolean isRC = ((SequenceHistory.RawSequence) alignment.getHistory(0)).index.isReverseComplement;
            alignment = alignment.setHistory(new SequenceHistory[] { new SequenceHistory.Merge(SequenceHistory.OverlapType.SequenceOverlap, new SequenceHistory.RawSequence(read.getId(), (byte) (isRC ? 1 : 0), false, read.getR1().getData().size()), new SequenceHistory.RawSequence(read.getId(), (byte) (isRC ? 0 : 1), merged.isReversed(), read.getR2().getData().size()), merged.getOffset(), merged.getErrors()) }, new SequenceRead[] { read });
        }
        return new VDJCAlignmentResult<>(read, alignment);
    } else
        return pairedAligner.process(read);
}
Also used : SingleReadImpl(com.milaboratory.core.io.sequence.SingleReadImpl) PairedReadMergingResult(com.milaboratory.core.merger.PairedReadMergingResult) SequenceRead(com.milaboratory.core.io.sequence.SequenceRead) SequenceHistory(com.milaboratory.mixcr.basictypes.SequenceHistory) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 28 with VDJCAlignments

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

the class AlignmentsMappingMerger method take.

@Override
public VDJCAlignments take() {
    VDJCAlignments al = alignments.take();
    if (al == null) {
        assert readToCloneMappings.take() == null;
        return null;
    }
    ReadToCloneMapping m = readToCloneMappings.take();
    assert m.alignmentsId == al.getAlignmentsIndex();
    return al.setMapping(m);
}
Also used : VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 29 with VDJCAlignments

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

the class VDJCAlignerPVFirstTest method test1.

@Test
public void test1() throws Exception {
    VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    List<VDJCAlignments> alignemntsList = new ArrayList<>();
    int header;
    int total = 0;
    int leftHit = 0;
    try (PairedFastqReader reader = new PairedFastqReader(VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R2.fastq"), true)) {
        VDJCAlignerPVFirst aligner = new VDJCAlignerPVFirst(parameters);
        for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) {
            if (parameters.containsRequiredFeature(gene))
                aligner.addGene(gene);
        }
        for (PairedRead read : CUtils.it(reader)) {
            ++total;
            VDJCAlignmentResult<PairedRead> result = aligner.process(read);
            if (result.alignment != null) {
                alignemntsList.add(result.alignment);
                for (VDJCHit hit : result.alignment.getHits(GeneType.Variable)) if (hit.getAlignment(0) != null && hit.getAlignment(1) != null)
                    ++leftHit;
            }
        }
    }
    System.out.println(alignemntsList.size());
    System.out.println(total);
    System.out.println(leftHit);
    Assert.assertTrue(alignemntsList.size() > 10);
    int k = 10;
    for (VDJCAlignments alignments : alignemntsList) {
        for (int target = 0; target < alignments.numberOfTargets(); target++) {
            MultiAlignmentHelper helperBig = VDJCAlignmentsFormatter.getTargetAsMultiAlignment(alignments, target);
            if (helperBig == null)
                continue;
            for (MultiAlignmentHelper helper : helperBig.split(80)) {
                System.out.println(helper);
                System.out.println();
                if (--k < 0)
                    return;
            }
        }
    }
// System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
// 
// try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()), ll)) {
// int i = 0;
// for (VDJCAlignments alignments : CUtils.it(reader))
// Assert.assertEquals(alignemntsList.get(i++), alignments);
// }
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PairedRead(com.milaboratory.core.io.sequence.PairedRead) VDJCGene(io.repseq.core.VDJCGene) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit) Test(org.junit.Test)

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