Search in sources :

Example 6 with VDJCGeneId

use of io.repseq.core.VDJCGeneId 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 7 with VDJCGeneId

use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.

the class CloneAccumulator method getBestGene.

public VDJCGeneId getBestGene(GeneType geneType) {
    TObjectFloatHashMap<VDJCGeneId> scores = geneScores.get(geneType);
    if (scores == null)
        return null;
    float maxScore = 0;
    VDJCGeneId maxAllele = null;
    TObjectFloatIterator<VDJCGeneId> iterator = scores.iterator();
    while (iterator.hasNext()) {
        iterator.advance();
        if (maxAllele == null || maxScore < iterator.value()) {
            maxAllele = iterator.key();
            maxScore = iterator.value();
        }
    }
    return maxAllele;
}
Also used : VDJCGeneId(io.repseq.core.VDJCGeneId)

Example 8 with VDJCGeneId

use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.

the class CloneAccumulator method accumulate.

public synchronized void accumulate(ClonalSequence data, VDJCAlignments alignment, boolean mapped) {
    if (!mapped) {
        // Core sequence accumulation
        coreCount += alignment.getNumberOfReads();
        // Accumulate information about V-D-J alignments only for strictly clustered reads
        // (only for core clonotypes members)
        float score;
        // Accumulate information about all genes
        for (GeneType geneType : GeneType.VJC_REFERENCE) {
            TObjectFloatHashMap<VDJCGeneId> geneScores = this.geneScores.get(geneType);
            VDJCHit[] hits = alignment.getHits(geneType);
            if (hits.length == 0)
                continue;
            if (geneScores == null)
                this.geneScores.put(geneType, geneScores = new TObjectFloatHashMap<>());
            for (VDJCHit hit : hits) {
                // Calculating sum of natural logarithms of scores
                score = hit.getScore();
                geneScores.adjustOrPutValue(hit.getGene().getId(), score, score);
            }
        }
        aggregator.aggregate(data.getConcatenated().getQuality());
    } else
        // Mapped sequence accumulation
        mappedCount += alignment.getNumberOfReads();
}
Also used : GeneType(io.repseq.core.GeneType) VDJCGeneId(io.repseq.core.VDJCGeneId) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Aggregations

VDJCGeneId (io.repseq.core.VDJCGeneId)8 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)4 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)3 GeneType (io.repseq.core.GeneType)3 VDJCGene (io.repseq.core.VDJCGene)3 BatchAlignerWithBaseParameters (com.milaboratory.core.alignment.batch.BatchAlignerWithBaseParameters)1 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)1 SequenceHistory (com.milaboratory.mixcr.basictypes.SequenceHistory)1 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)1 KGeneAlignmentParameters (com.milaboratory.mixcr.vdjaligners.KGeneAlignmentParameters)1 GeneFeature (io.repseq.core.GeneFeature)1 ArrayList (java.util.ArrayList)1