Search in sources :

Example 6 with Range

use of com.milaboratory.core.Range in project mixcr by milaboratory.

the class FullSeqAssembler method assembleBranchSequences.

BranchSequences assembleBranchSequences(int[] points, VariantBranch branch) {
    long[] positionedStates = new long[points.length];
    for (int i = 0; i < points.length; i++) positionedStates[i] = ((long) points[i]) << 32 | branch.pointStates[i];
    Arrays.sort(positionedStates);
    List<NSequenceWithQuality> sequences = new ArrayList<>();
    List<Range> ranges = new ArrayList<>();
    NSequenceWithQualityBuilder sequenceBuilder = new NSequenceWithQualityBuilder();
    int blockStartPosition = -1;
    int assemblingFeatureTargetId = -1;
    int assemblingFeatureOffset = -1;
    int assemblingFeatureLength = -1;
    for (int i = 0; i < positionedStates.length; ++i) {
        if (isAbsent(positionedStates[i]))
            continue;
        if (blockStartPosition == -1)
            blockStartPosition = extractPosition(positionedStates[i]);
        int currentPosition = extractPosition(positionedStates[i]);
        int nextPosition = i == positionedStates.length - 1 ? Integer.MAX_VALUE : isAbsent(positionedStates[i + 1]) ? Integer.MAX_VALUE : extractPosition(positionedStates[i + 1]);
        assert currentPosition != nextPosition;
        NSequenceWithQuality seq = new NSequenceWithQuality(variantIdToSequence.get(((int) (positionedStates[i] >>> 8)) & 0xFFFFFF), (byte) positionedStates[i]);
        if (currentPosition == positionOfAssemblingFeature) {
            assert assemblingFeatureTargetId == -1;
            assemblingFeatureTargetId = ranges.size();
            assemblingFeatureOffset = sequenceBuilder.size();
            assemblingFeatureLength = seq.size();
        }
        sequenceBuilder.append(seq);
        if (currentPosition != nextPosition - 1) {
            sequences.add(sequenceBuilder.createAndDestroy());
            ranges.add(new Range(blockStartPosition, currentPosition + 1));
            sequenceBuilder = new NSequenceWithQualityBuilder();
            blockStartPosition = nextPosition;
        }
    }
    assert blockStartPosition != -1;
    assert assemblingFeatureTargetId != -1;
    return new BranchSequences(assemblingFeatureTargetId, assemblingFeatureOffset, assemblingFeatureLength, ranges.toArray(new Range[ranges.size()]), sequences.toArray(new NSequenceWithQuality[sequences.size()]));
}
Also used : Range(com.milaboratory.core.Range)

Example 7 with Range

use of com.milaboratory.core.Range in project mixcr by milaboratory.

the class RangeSetTest method testSubtract1.

@Test
public void testSubtract1() throws Exception {
    RangeSet s10 = createUnsafe(10, 20, 30, 40, 50, 60, 70, 80);
    RangeSet s11 = s10.subtract(new Range(19, 55));
    Assert.assertEquals(s11, createUnsafe(10, 19, 55, 60, 70, 80));
    RangeSet s12 = s10.intersection(new Range(19, 55));
    Assert.assertEquals(s10, s11.add(s12));
}
Also used : Range(com.milaboratory.core.Range) Test(org.junit.Test)

Example 8 with Range

use of com.milaboratory.core.Range in project mixcr by milaboratory.

the class RangeSetTest method testAdd1.

@Test
public void testAdd1() throws Exception {
    RangeSet s0 = new RangeSet();
    Assert.assertEquals(s0, new RangeSet());
    RangeSet s1 = s0.add(new Range(10, 20));
    Assert.assertEquals(s1, createUnsafe(10, 20));
    RangeSet s2 = s1.add(new Range(20, 30));
    Assert.assertEquals(s2, createUnsafe(10, 30));
    RangeSet s3 = s1.add(new Range(21, 30));
    Assert.assertEquals(s3, createUnsafe(10, 20, 21, 30));
    RangeSet s4 = s3.add(new Range(21, 30));
    Assert.assertEquals(s4, createUnsafe(10, 20, 21, 30));
    RangeSet s5 = s3.add(new Range(25, 35));
    Assert.assertEquals(s5, createUnsafe(10, 20, 21, 35));
    RangeSet s6 = s5.add(new Range(20, 21));
    Assert.assertEquals(s6, createUnsafe(10, 35));
    RangeSet s7 = s5.add(new Range(19, 22));
    Assert.assertEquals(s7, createUnsafe(10, 35));
    RangeSet s10 = createUnsafe(10, 20, 30, 40, 50, 60, 70, 80);
    RangeSet s11 = s10.add(new Range(19, 50));
    Assert.assertEquals(s11, createUnsafe(10, 60, 70, 80));
}
Also used : Range(com.milaboratory.core.Range) Test(org.junit.Test)

Example 9 with Range

use of com.milaboratory.core.Range in project mixcr by milaboratory.

the class AlignedTarget method getOverlapRange.

public static Range getOverlapRange(AlignedTarget target) {
    int begin = target.getBPoint(OverlapBegin);
    int end = target.getBPoint(OverlapEnd);
    if (begin == -1 || end == -1)
        return null;
    else
        return new Range(begin, end);
}
Also used : Range(com.milaboratory.core.Range)

Example 10 with Range

use of com.milaboratory.core.Range in project mixcr by milaboratory.

the class ReferencePointCoverageCollector method put.

@Override
public void put(VDJCAlignments alignments) {
    totalCount.incrementAndGet();
    VDJCHit hit = alignments.getBestHit(refPoint.getGeneType());
    int left = -1, right = -1;
    for (int i = 0; i < alignments.numberOfTargets(); ++i) {
        int position = hit.getPosition(i, refPoint);
        if (position == -1)
            continue;
        Range alignmentRange = hit.getAlignment(i).getSequence2Range();
        left = Math.max(position - alignmentRange.getLower(), left);
        right = Math.max(alignmentRange.getUpper() - position, right);
    }
    if (left == -1)
        return;
    left = Math.min(leftHist.length() - 1, left);
    leftHist.incrementAndGet(left);
    right = Math.min(rightHist.length() - 1, right);
    rightHist.incrementAndGet(right);
}
Also used : Range(com.milaboratory.core.Range) ReferencePoint(io.repseq.core.ReferencePoint) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit)

Aggregations

Range (com.milaboratory.core.Range)45 Test (org.junit.Test)23 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)19 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)4 ArrayList (java.util.ArrayList)4 SingleFastqReaderTest (com.milaboratory.core.io.sequence.fastq.SingleFastqReaderTest)3 MutationsBuilder (com.milaboratory.core.mutations.MutationsBuilder)3 ReferencePoint (io.repseq.core.ReferencePoint)3 Path (java.nio.file.Path)3 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)2 Clone (com.milaboratory.mixcr.basictypes.Clone)2 VDJCPartitionedSequence (com.milaboratory.mixcr.basictypes.VDJCPartitionedSequence)2 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 CUtils (cc.redberry.pipe.CUtils)1 OutputPort (cc.redberry.pipe.OutputPort)1 com.milaboratory.core.alignment (com.milaboratory.core.alignment)1 Alignment (com.milaboratory.core.alignment.Alignment)1 LinearGapAlignmentScoring (com.milaboratory.core.alignment.LinearGapAlignmentScoring)1 MultiAlignmentHelper (com.milaboratory.core.alignment.MultiAlignmentHelper)1 com.milaboratory.core.sequence (com.milaboratory.core.sequence)1