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();
}
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));
}
}
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;
}
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);
}
}
Aggregations