Search in sources :

Example 1 with BitArray

use of com.milaboratory.util.BitArray in project mixcr by milaboratory.

the class VDJCAlignerPVFirst method performJAlignment.

/**
 * Preforms J alignment for a single read
 */
@SuppressWarnings("unchecked")
List<AlignmentHit<NucleotideSequence, VDJCGene>> performJAlignment(final Target target, final PairedHit[] vHits, final int index) {
    // Getting best V hit
    AlignmentHit<NucleotideSequence, VDJCGene> vHit = vHits.length == 0 ? null : vHits[0].get(index);
    final NucleotideSequence targetSequence = target.targets[index].getSequence();
    BitArray filterForJ = getFilter(GeneType.Joining, vHits);
    if (vHit == null)
        return jAligner.align(targetSequence, 0, targetSequence.size(), filterForJ).getHits();
    // TODO remove
    if (vHit.getAlignment().getSequence1Range().getTo() <= vHit.getRecordPayload().getPartitioning().getRelativePosition(parameters.getFeatureToAlign(GeneType.Variable), ReferencePoint.FR3Begin) || vHit.getAlignment().getSequence2Range().getTo() == targetSequence.size())
        return Collections.EMPTY_LIST;
    int jFrom = vHit.getAlignment().getSequence2Range().getTo() - parameters.getVJOverlapWindow();
    jFrom = jFrom < 0 ? 0 : jFrom;
    return jAligner.align(targetSequence, jFrom, targetSequence.size(), filterForJ).getHits();
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) BitArray(com.milaboratory.util.BitArray)

Example 2 with BitArray

use of com.milaboratory.util.BitArray in project mixcr by milaboratory.

the class ClonalSequenceTest method testCompatiblePair.

private static void testCompatiblePair(ClonalSequence c1, ClonalSequence c2, RandomGenerator random) {
    int delta = c1.getConcatenated().size() - c2.getConcatenated().size();
    int c1size = c1.getConcatenated().size();
    for (int t = 0; t < 100; ++t) {
        int k = 1 + random.nextInt(2);
        int deletions, insertions;
        if (delta > 0) {
            // c1 > c2
            insertions = k;
            deletions = delta + k;
        } else {
            // c1 < c2
            deletions = k;
            insertions = -delta + k;
        }
        int[] muts = new int[Math.abs(deletions + insertions)];
        int c = 0;
        BitArray usedDels = new BitArray(c1size);
        for (int i = 0; i < deletions; ++i) {
            int p = random.nextInt(c1size);
            usedDels.set(p);
            muts[c++] = Mutation.createDeletion(p, 0);
        }
        for (int i = 0; i < insertions; ++i) {
            int p;
            do {
                p = random.nextInt(c1size);
            } while (usedDels.get(p));
            muts[c++] = Mutation.createInsertion(p, 0);
        }
        Arrays.sort(muts);
        Mutations<NucleotideSequence> mutations = new Mutations<>(NucleotideSequence.ALPHABET, muts);
        assert mutations.getLengthDelta() + c1.getConcatenated().size() == c2.getConcatenated().size();
        Assert.assertTrue(c1.isCompatible(c2, mutations));
    }
}
Also used : Mutations(com.milaboratory.core.mutations.Mutations) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) BitArray(com.milaboratory.util.BitArray)

Example 3 with BitArray

use of com.milaboratory.util.BitArray in project mixcr by milaboratory.

the class VDJCAlignerAbstract method getFilter0.

private BitArray getFilter0(GeneType targetAlignerType, Chains chains) {
    BitArray ret = null;
    boolean cloned = false;
    for (String chain : chains) if (ret == null)
        ret = filters.get(targetAlignerType).get(chain);
    else {
        if (!cloned) {
            ret = ret.clone();
            cloned = true;
        }
        ret.or(filters.get(targetAlignerType).get(chain));
    }
    return ret;
}
Also used : BitArray(com.milaboratory.util.BitArray)

Example 4 with BitArray

use of com.milaboratory.util.BitArray in project mixcr by milaboratory.

the class VDJCAlignerAbstract method init.

@Override
protected void init() {
    DAlignerParameters dAlignerParameters = parameters.getDAlignerParameters();
    List<VDJCGene> dGenes = genesToAlign.get(GeneType.Diversity);
    if (dAlignerParameters != null && dGenes.size() != 0)
        singleDAligner = new SingleDAligner(dAlignerParameters, genesToAlign.get(GeneType.Diversity));
    vAligner = createKAligner(GeneType.Variable);
    jAligner = createKAligner(GeneType.Joining);
    cAligner = createKAligner(GeneType.Constant);
    Chains chains = new Chains();
    for (VDJCGene gene : getUsedGenes()) chains = chains.merge(gene.getChains());
    filters = new EnumMap<>(GeneType.class);
    for (GeneType geneType : GeneType.VJC_REFERENCE) {
        HashMap<String, BitArray> f = new HashMap<>();
        for (final String chain : chains) {
            BatchAlignerWithBaseWithFilter<NucleotideSequence, VDJCGene, AlignmentHit<NucleotideSequence, VDJCGene>> aligner = getAligner(geneType);
            if (aligner != null)
                f.put(chain, aligner.createFilter(new Filter<VDJCGene>() {

                    @Override
                    public boolean accept(VDJCGene object) {
                        return object.getChains().contains(chain);
                    }
                }));
        }
        filters.put(geneType, f);
    }
}
Also used : HashMap(java.util.HashMap) Chains(io.repseq.core.Chains) AlignmentHit(com.milaboratory.core.alignment.batch.AlignmentHit) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene) GeneType(io.repseq.core.GeneType) BitArray(com.milaboratory.util.BitArray)

Aggregations

BitArray (com.milaboratory.util.BitArray)4 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)3 AlignmentHit (com.milaboratory.core.alignment.batch.AlignmentHit)1 Mutations (com.milaboratory.core.mutations.Mutations)1 Chains (io.repseq.core.Chains)1 GeneType (io.repseq.core.GeneType)1 VDJCGene (io.repseq.core.VDJCGene)1 HashMap (java.util.HashMap)1