Search in sources :

Example 11 with VDJCHit

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

the class PreVDJCHit method combine.

static VDJCHit[] combine(final List<VDJCGene> genes, final GeneFeature feature, final PreVDJCHit[][] hits) {
    for (int i = 0; i < hits.length; i++) Arrays.sort(hits[i]);
    ArrayList<VDJCHit> result = new ArrayList<>();
    final int[] pointers = new int[hits.length];
    Alignment<NucleotideSequence>[] alignments;
    int i, minId;
    while (true) {
        minId = Integer.MAX_VALUE;
        for (i = 0; i < pointers.length; ++i) if (pointers[i] < hits[i].length && minId > hits[i][pointers[i]].id)
            minId = hits[i][pointers[i]].id;
        if (minId == Integer.MAX_VALUE)
            break;
        alignments = new Alignment[hits.length];
        for (i = 0; i < pointers.length; ++i) if (pointers[i] < hits[i].length && minId == hits[i][pointers[i]].id) {
            alignments[i] = hits[i][pointers[i]].alignment;
            ++pointers[i];
        }
        result.add(new VDJCHit(genes.get(minId), alignments, feature));
    }
    VDJCHit[] vdjcHits = result.toArray(new VDJCHit[result.size()]);
    Arrays.sort(vdjcHits);
    return vdjcHits;
}
Also used : Alignment(com.milaboratory.core.alignment.Alignment) ArrayList(java.util.ArrayList) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Example 12 with VDJCHit

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

the class PreVDJCHit method convert.

static VDJCHit[] convert(List<VDJCGene> genes, GeneFeature feature, List<PreVDJCHit> preHits, int indexOfTargets, int numberOfTargets) {
    VDJCHit[] hits = new VDJCHit[preHits.size()];
    for (int i = 0; i < preHits.size(); i++) {
        PreVDJCHit h = preHits.get(i);
        Alignment<NucleotideSequence>[] alignments = new Alignment[numberOfTargets];
        alignments[indexOfTargets] = h.alignment;
        hits[i] = new VDJCHit(genes.get(h.id), alignments, feature);
    }
    return hits;
}
Also used : Alignment(com.milaboratory.core.alignment.Alignment) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Example 13 with VDJCHit

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

the class TargetMerger method extractSortedHits.

@SuppressWarnings("unchecked")
static List<HitMappingRecord> extractSortedHits(AlignedTarget targetLeft, AlignedTarget targetRight, GeneType geneType) {
    // Fast calculation for targets from the same PE-read (or multi-read)
    if (targetLeft.getAlignments() == targetRight.getAlignments()) {
        VDJCHit[] hits = targetLeft.getAlignments().getHits(geneType);
        List<HitMappingRecord> mRecords = new ArrayList<>(hits.length);
        for (VDJCHit hit : hits) mRecords.add(new HitMappingRecord(hit.getGene(), new Alignment[] { hit.getAlignment(targetLeft.getTargetId()), hit.getAlignment(targetRight.getTargetId()) }));
        // other parts of the multi-read object
        return mRecords;
    }
    // Full recalculation for targets form two different Alignments objects
    Map<VDJCGeneId, HitMappingRecord> map = extractHitsMapping(targetLeft, targetRight, geneType);
    List<HitMappingRecord> mRecords = new ArrayList<>(map.values());
    Collections.sort(mRecords, new Comparator<HitMappingRecord>() {

        @Override
        public int compare(HitMappingRecord o1, HitMappingRecord o2) {
            return Integer.compare(sumScore(o2.alignments), sumScore(o1.alignments));
        }
    });
    return mRecords;
}
Also used : VDJCGeneId(io.repseq.core.VDJCGeneId) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Example 14 with VDJCHit

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

the class TargetMerger method merge.

@SuppressWarnings("unchecked")
public AlignedTarget merge(AlignedTarget targetLeft, AlignedTarget targetRight, int offset, OverlapType overlapType, int nMismatches) {
    if (offset < 0)
        return merge(targetRight, targetLeft, -offset, overlapType, nMismatches);
    final NSequenceWithQuality mergedTarget = merger.overlap(targetLeft.getTarget(), targetRight.getTarget(), offset);
    EnumMap<GeneType, VDJCHit[]> result = new EnumMap<>(GeneType.class);
    for (GeneType geneType : GeneType.VJC_REFERENCE) {
        final BatchAlignerWithBaseParameters bp = ((KGeneAlignmentParameters) alignerParameters.getGeneAlignerParameters(geneType)).getParameters();
        final VDJCHit[] leftHits = targetLeft.getAlignments().getHits(geneType);
        final VDJCHit[] rightHits = targetRight.getAlignments().getHits(geneType);
        GeneFeature alignedFeature = leftHits.length == 0 ? rightHits.length == 0 ? null : rightHits[0].getAlignedFeature() : leftHits[0].getAlignedFeature();
        Map<VDJCGeneId, HitMappingRecord> map = extractHitsMapping(targetLeft, targetRight, geneType);
        ArrayList<VDJCHit> resultingHits = new ArrayList<>();
        for (Map.Entry<VDJCGeneId, HitMappingRecord> mE : map.entrySet()) {
            final VDJCGene gene = mE.getValue().gene;
            Alignment<NucleotideSequence> mergedAl = merge(bp.getScoring(), extractBandedWidth(bp), mergedTarget.getSequence(), offset, mE.getValue().alignments[0], mE.getValue().alignments[1]);
            resultingHits.add(new VDJCHit(gene, mergedAl, alignedFeature));
        }
        Collections.sort(resultingHits);
        // final float relativeMinScore = extractRelativeMinScore(bp);
        // int threshold = (int) (resultingHits.size() > 0 ? resultingHits.get(0).getScore() * relativeMinScore : 0);
        // for (int i = resultingHits.size() - 1; i > 0; --i)
        // if (resultingHits.get(i).getScore() < threshold)
        // resultingHits.remove(i);
        result.put(geneType, resultingHits.toArray(new VDJCHit[resultingHits.size()]));
    }
    VDJCAlignments alignments = new VDJCAlignments(result, new NSequenceWithQuality[] { mergedTarget }, new SequenceHistory[] { new SequenceHistory.Merge(overlapType, targetLeft.getHistory(), targetRight.getHistory(), offset, nMismatches) }, VDJCAlignments.mergeOriginalReads(targetLeft.getAlignments(), targetRight.getAlignments()));
    AlignedTarget resultTarget = new AlignedTarget(alignments, 0);
    for (BPoint bPoint : BPoint.values()) {
        int leftPoint = targetLeft.getBPoint(bPoint);
        int rightPoint = targetRight.getBPoint(bPoint);
        if (leftPoint != -1 && rightPoint != -1)
            throw new IllegalArgumentException("Same bPoint defined in both input targets.");
        else if (leftPoint != -1)
            resultTarget = resultTarget.setBPoint(bPoint, leftPoint);
        else if (rightPoint != -1)
            resultTarget = resultTarget.setBPoint(bPoint, offset + rightPoint);
    }
    return resultTarget;
}
Also used : GeneFeature(io.repseq.core.GeneFeature) SequenceHistory(com.milaboratory.mixcr.basictypes.SequenceHistory) VDJCGeneId(io.repseq.core.VDJCGeneId) NSequenceWithQuality(com.milaboratory.core.sequence.NSequenceWithQuality) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) BatchAlignerWithBaseParameters(com.milaboratory.core.alignment.batch.BatchAlignerWithBaseParameters) KGeneAlignmentParameters(com.milaboratory.mixcr.vdjaligners.KGeneAlignmentParameters) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene) GeneType(io.repseq.core.GeneType) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Example 15 with VDJCHit

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

VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)22 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)8 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)8 GeneType (io.repseq.core.GeneType)7 VDJCGene (io.repseq.core.VDJCGene)7 Range (com.milaboratory.core.Range)4 ArrayList (java.util.ArrayList)4 Alignment (com.milaboratory.core.alignment.Alignment)3 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)3 Clone (com.milaboratory.mixcr.basictypes.Clone)3 ReferencePoint (io.repseq.core.ReferencePoint)3 VDJCGeneId (io.repseq.core.VDJCGeneId)3 PairedRead (com.milaboratory.core.io.sequence.PairedRead)2 PairedFastqReader (com.milaboratory.core.io.sequence.fastq.PairedFastqReader)2 VDJCPartitionedSequence (com.milaboratory.mixcr.basictypes.VDJCPartitionedSequence)2 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 Chains (io.repseq.core.Chains)2 GeneFeature (io.repseq.core.GeneFeature)2 Test (org.junit.Test)2 CUtils (cc.redberry.pipe.CUtils)1