Search in sources :

Example 1 with VDJCGeneId

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

the class ActionClonesDiff method getKey.

private CKey getKey(Clone clone) {
    final NucleotideSequence[] clonalSequence = new NucleotideSequence[clone.numberOfTargets()];
    for (int i = 0; i < clonalSequence.length; i++) clonalSequence[i] = clone.getTarget(i).getSequence();
    final VDJCGeneId v = params.useV() ? getBestGene(clone, GeneType.Variable) : null;
    final VDJCGeneId j = params.useJ() ? getBestGene(clone, GeneType.Joining) : null;
    final VDJCGeneId c = params.useC() ? getBestGene(clone, GeneType.Constant) : null;
    return new CKey(clonalSequence, v, j, c);
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGeneId(io.repseq.core.VDJCGeneId)

Example 2 with VDJCGeneId

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

the class IOUtil method readGeneReferences.

public static List<VDJCGene> readGeneReferences(PrimitivI input, VDJCLibraryRegistry registry) {
    // Reading gene ids
    int count = input.readInt();
    List<VDJCGene> genes = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        VDJCGeneId id = input.readObject(VDJCGeneId.class);
        VDJCGene gene = registry.getGene(id);
        if (gene == null)
            throw new RuntimeException("Gene not found: " + id);
        genes.add(gene);
    }
    return genes;
}
Also used : ArrayList(java.util.ArrayList) VDJCGene(io.repseq.core.VDJCGene) VDJCGeneId(io.repseq.core.VDJCGeneId)

Example 3 with VDJCGeneId

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

the class CloneAccumulator method calculateScores.

public void calculateScores(CloneFactoryParameters parameters) {
    for (GeneType geneType : GeneType.VJC_REFERENCE) {
        VJCClonalAlignerParameters vjcParameters = parameters.getVJCParameters(geneType);
        if (vjcParameters == null)
            continue;
        TObjectFloatHashMap<VDJCGeneId> accumulatorGeneIds = geneScores.get(geneType);
        if (accumulatorGeneIds == null)
            continue;
        TObjectFloatIterator<VDJCGeneId> iterator = accumulatorGeneIds.iterator();
        float maxScore = 0;
        while (iterator.hasNext()) {
            iterator.advance();
            float value = iterator.value();
            if (value > maxScore)
                maxScore = value;
        }
        maxScore = maxScore * vjcParameters.getRelativeMinScore();
        iterator = accumulatorGeneIds.iterator();
        while (iterator.hasNext()) {
            iterator.advance();
            if (maxScore > iterator.value())
                iterator.remove();
            else
                iterator.setValue(Math.round(iterator.value() * 10f / coreCount) / 10f);
        }
    }
}
Also used : GeneType(io.repseq.core.GeneType) VDJCGeneId(io.repseq.core.VDJCGeneId)

Example 4 with VDJCGeneId

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

the class TargetMerger method extractHitsMapping.

@SuppressWarnings("unchecked")
static Map<VDJCGeneId, HitMappingRecord> extractHitsMapping(AlignedTarget targetLeft, AlignedTarget targetRight, GeneType geneType) {
    Map<VDJCGeneId, HitMappingRecord> map = new HashMap<>();
    for (VDJCHit l : targetLeft.getAlignments().getHits(geneType)) {
        final VDJCGene gene = l.getGene();
        final Alignment<NucleotideSequence> al = l.getAlignment(targetLeft.getTargetId());
        if (al != null)
            map.put(gene.getId(), new HitMappingRecord(gene, new Alignment[] { al, null }));
    }
    for (VDJCHit r : targetRight.getAlignments().getHits(geneType)) {
        final VDJCGene gene = r.getGene();
        final Alignment<NucleotideSequence> alignment = r.getAlignment(targetRight.getTargetId());
        if (alignment == null)
            continue;
        final HitMappingRecord als = map.get(gene.getId());
        if (als == null)
            map.put(gene.getId(), new HitMappingRecord(gene, new Alignment[] { null, alignment }));
        else {
            assert als.alignments[1] == null;
            als.alignments[1] = alignment;
        }
    }
    return map;
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene) VDJCGeneId(io.repseq.core.VDJCGeneId) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Example 5 with VDJCGeneId

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

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