use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class ClonalSequenceTest method testIsCompatible4.
@Test
public void testIsCompatible4() throws Exception {
RandomGenerator generator = new Well1024a();
for (int i = 0; i < 1000; i++) {
TestData td = createRandomTestDara(1 + generator.nextInt(10), generator);
assertTestData(td);
int rp = generator.nextInt(td.c1.getConcatenated().size() / 2);
byte rl = td.c1.getConcatenated().getSequence().codeAt(rp);
if (rl == 0)
rl = 1;
else
rl = (byte) (rl - 1);
assert rp <= td.c1.getConcatenated().size();
Mutations<NucleotideSequence> incompatible = td.mutations.combineWith(Mutations.decode("I" + rp + "" + NucleotideSequence.ALPHABET.codeToSymbol(rl), NucleotideSequence.ALPHABET));
Assert.assertFalse(td.c1.isCompatible(td.c2, incompatible));
}
}
use of com.milaboratory.core.sequence.NucleotideSequence 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.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class ClonalSequenceTest method createRandom.
private ClonalSequence createRandom(int size, RandomGenerator generator) {
NSequenceWithQuality[] data = new NSequenceWithQuality[size];
for (int i = 0; i < size; ++i) {
NucleotideSequence s = TestUtil.randomSequence(NucleotideSequence.ALPHABET, generator, 2, 10);
SequenceQuality q = SequenceQuality.getUniformQuality((byte) 0, s.size());
data[i] = new NSequenceWithQuality(s, q);
}
return new ClonalSequence(data);
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class FieldExtractorsTest method testAnchorPoints1.
@Test
public void testAnchorPoints1() throws Exception {
final boolean print = false;
final Well44497b rg = new Well44497b(12312);
final VDJCAlignerParameters rnaSeqParams = VDJCParametersPresets.getByName("rna-seq");
final PartialAlignmentsAssemblerAligner aligner = new PartialAlignmentsAssemblerAligner(rnaSeqParams);
final VDJCLibrary lib = VDJCLibraryRegistry.getDefault().getLibrary("default", "hs");
for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes()) if (gene.isFunctional())
aligner.addGene(gene);
final TargetBuilder.VDJCGenes genes = new TargetBuilder.VDJCGenes(lib, "TRBV12-3*00", "TRBD1*00", "TRBJ1-3*00", "TRBC2*00");
// | 310 | 338 | 438
// 250V + 60CDR3 (20V 7N 10D 3N 20J) + 28J + 100C + 100N
// "{CDR3Begin(-250)}V*270 NNNNNNN {DBegin(0)}D*10 NNN {CDR3End(-20):FR4End} {CBegin}C*100 N*100"
final FieldExtractors.ExtractDefaultReferencePointsPositions extractor = new FieldExtractors.ExtractDefaultReferencePointsPositions();
F6 goAssert = new F6() {
@Override
public Integer[][] go(String seq, int len, int offset1, int offset2, int offset3, String expected) {
final NucleotideSequence baseSeq = TargetBuilder.generateSequence(genes, seq, rg);
NucleotideSequence seq1 = baseSeq.getRange(offset1, Math.min(baseSeq.size(), offset1 + len));
NucleotideSequence seq2 = offset2 == -1 ? null : baseSeq.getRange(offset2, Math.min(baseSeq.size(), offset2 + len));
NucleotideSequence seq3 = offset3 == -1 ? null : baseSeq.getRange(offset3, Math.min(baseSeq.size(), offset3 + len));
VDJCAlignmentResult<VDJCMultiRead> alignment = offset3 == -1 ? offset2 == -1 ? aligner.process(MiXCRTestUtils.createMultiRead(seq1)) : aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2)) : aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2, seq3));
VDJCAlignments al = alignment.alignment;
Assert.assertNotNull(al);
if (print) {
MiXCRTestUtils.printAlignment(al);
System.out.println();
System.out.println("-------------------------------------------");
System.out.println();
}
String val = extractor.extract(al);
if (print)
System.out.println(val);
String[] spl = val.split(",");
Integer[][] result = new Integer[spl.length][ReferencePoint.DefaultReferencePoints.length];
for (int i = 0; i < spl.length; i++) {
String[] spl1 = spl[i].split(":");
for (int j = 0; j < spl1.length; j++) {
try {
result[i][j] = Integer.decode(spl1[j]);
} catch (NumberFormatException e) {
}
}
}
return result;
}
};
// No PSegments, just deletions
Integer[][] r = goAssert.go("{CDR3Begin(-250):VEnd(-3)} 'CCAAA' {DBegin(0):DEnd(0)} 'AAA' {JBegin(2):FR4End} " + "{CBegin}C*100 N*100", 100, 240, 307, 450, "");
assertExportPoint(r[0], ReferencePoint.VEnd, -3);
assertExportPoint(r[0], ReferencePoint.DBegin, 0);
assertExportPoint(r[0], ReferencePoint.DEnd, 0);
assertExportPoint(r[0], ReferencePoint.JBegin, -2);
r = goAssert.go("{CDR3Begin(-250):VEnd(0)} 'CCAAA' {DBegin(0):DEnd(-2)} 'AAA' {JBegin:FR4End} {CBegin}C*100 N*100", 100, 240, 307, 450, "");
assertExportPoint(r[0], ReferencePoint.VEnd, 0);
assertExportPoint(r[0], ReferencePoint.DBegin, 0);
assertExportPoint(r[0], ReferencePoint.DEnd, -2);
assertExportPoint(r[0], ReferencePoint.JBegin, 0);
// With PSegments
r = goAssert.go("{CDR3Begin(-250):VEnd(0)} {VEnd:VEnd(-3)} 'CCAAA' {DBegin(3):DBegin} {DBegin:DEnd(-2)} 'AAA' " + "{JBegin(2):JBegin} {JBegin:FR4End} {CBegin}C*100 N*100", 100, 240, 307, 450, "");
assertExportPoint(r[0], ReferencePoint.VEnd, 3);
assertExportPoint(r[0], ReferencePoint.DBegin, 3);
assertExportPoint(r[0], ReferencePoint.DEnd, -2);
assertExportPoint(r[0], ReferencePoint.JBegin, 2);
}
use of com.milaboratory.core.sequence.NucleotideSequence 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;
}
Aggregations