use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class TargetBuilderTest method testGenerate1.
@Test
public void testGenerate1() throws Exception {
VDJCLibrary library = VDJCLibraryRegistry.getDefault().getLibrary("default", "hs");
TargetBuilder.VDJCGenes genes = new TargetBuilder.VDJCGenes(library, "TRBV12-1*00", "TRBD1*00", "TRBJ1-3*00", "TRBC2*00");
String model = "{CDR3Begin(-20)}VVVVVVVVVVVvVVVvVVVVVVVVVVVVVNNNNNNN{DBegin(0)}DDDDDDDDDDNN{CDR3End(-10)}JJJJJJJJJJJJJJJJJJJJ";
NucleotideSequence nucleotideSequence = TargetBuilder.generateSequence(genes, model, new Well44497b());
Assert.assertEquals(36 + 12 + 20, nucleotideSequence.size());
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class VDJCObjectExtenderTest method testTripleRead.
@Test
public void testTripleRead() throws Exception {
final boolean print = true;
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);
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
final NucleotideSequence baseSeq = TargetBuilder.generateSequence(genes, "{CDR3Begin(-250)}V*270 NNNNNNN {DBegin(0)}D*10 NNN {CDR3End(-20):FR4End} {CBegin}C*100 N*100", rg);
F4 goAssert = new F4() {
@Override
public VDJCAlignments go(int len, int offset1, int offset2, int offset3) {
NucleotideSequence seq1 = baseSeq.getRange(offset1, offset1 + len);
NucleotideSequence seq2 = baseSeq.getRange(offset2, offset2 + len);
NucleotideSequence seq3 = offset3 == -1 ? null : baseSeq.getRange(offset3, offset3 + len);
VDJCAlignmentResult<VDJCMultiRead> alignment = offset3 == -1 ? aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2)) : aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2, seq3));
VDJCAlignments al = alignment.alignment;
Assert.assertNotNull(al);
VDJCObjectExtender<VDJCAlignments> extender = new VDJCObjectExtender<>(Chains.TCR, (byte) 35, rnaSeqParams.getVAlignerParameters().getParameters().getScoring(), rnaSeqParams.getJAlignerParameters().getParameters().getScoring(), 100, 70, ReferencePoint.CDR3Begin, ReferencePoint.CDR3End);
MiXCRTestUtils.assertAlignments(al);
if (print) {
MiXCRTestUtils.printAlignment(al);
System.out.println();
System.out.println("-------------------------------------------");
System.out.println();
}
VDJCAlignments processed = extender.process(al);
if (print) {
MiXCRTestUtils.printAlignment(processed);
System.out.println();
System.out.println("===========================================");
System.out.println();
System.out.println();
}
MiXCRTestUtils.assertAlignments(processed);
Assert.assertEquals(al.getFeature(GeneFeature.VDJunction), processed.getFeature(GeneFeature.VDJunction));
Assert.assertEquals(al.getFeature(GeneFeature.DJJunction), processed.getFeature(GeneFeature.DJJunction));
Assert.assertEquals(al.getFeature(GeneFeature.VJJunction), processed.getFeature(GeneFeature.VJJunction));
return processed;
}
};
VDJCAlignments a1 = goAssert.go(60, 245, 307, 450);
Assert.assertEquals(2, a1.numberOfTargets());
VDJCAlignments a2 = goAssert.go(60, 245, 315, 450);
Assert.assertEquals(3, a2.numberOfTargets());
VDJCAlignments a3 = goAssert.go(60, 245, 315, -1);
Assert.assertEquals(2, a3.numberOfTargets());
VDJCAlignments a4 = goAssert.go(60, 245, 307, -1);
Assert.assertEquals(1, a4.numberOfTargets());
VDJCAlignments a5 = goAssert.go(53, 252, 307, -1);
Assert.assertEquals(1, a5.numberOfTargets());
VDJCAlignments a6 = goAssert.go(53, 252, 307, 450);
Assert.assertEquals(2, a6.numberOfTargets());
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class VDJCAlignerPVFirstTest method test2.
@Test
@Ignore
public void test2() throws Exception {
PairedRead read1 = new PairedRead(new SingleReadImpl(0, new NSequenceWithQuality(new NucleotideSequence("GCTGTGTATTACTGTGCAAGAGGGCCCCAAGAAAATAGTGGTTATTACTACGGGTTTGACTACTGGGGCCAGGGA"), SequenceQuality.GOOD_QUALITY_VALUE), "206"), new SingleReadImpl(0, new NSequenceWithQuality(new NucleotideSequence("GGCGCCAGGGGGAAGACCGATGGGCCCTTGGTGGAGGCTGAGGAGACGGTGACCAGGGTTCCCTGGCCCCAGTAG"), SequenceQuality.GOOD_QUALITY_VALUE), "206"));
PairedRead read2 = new PairedRead(new SingleReadImpl(1, new NSequenceWithQuality(new NucleotideSequence("GCTGTGTATTACTGTGCAAGAGGGCCCCAAGAAAATAGTGGTTATTACTACGGGTTTGACTACTGGGGCCAGGGA"), SequenceQuality.GOOD_QUALITY_VALUE), "11621"), new SingleReadImpl(1, new NSequenceWithQuality(new NucleotideSequence("GGCGCCAGGGGGAAGACCGATGGGCCCTTGGTGGAGGCTGAGGAGACGGTGACCAGGGTTCCCTGGCCCCAGTAG"), SequenceQuality.GOOD_QUALITY_VALUE), "11621"));
RunMiXCR.RunMiXCRAnalysis params = new RunMiXCR.RunMiXCRAnalysis(read1);
RunMiXCR.AlignResult align = RunMiXCR.align(params);
for (VDJCAlignments al : align.alignments) {
for (int i = 0; i < al.numberOfTargets(); i++) {
System.out.println(VDJCAlignmentsFormatter.getTargetAsMultiAlignment(al, i));
System.out.println();
}
System.out.println();
System.out.println(" ================================================ ");
System.out.println();
}
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class VDJCAlignerSTest method test2.
@Test
@Ignore
public void test2() throws Exception {
// @
// GCTGTGTATTACTGTGCAAGAGGGCCCCAAGAAAATAGTGGTTATTACTACGGGTTTGACTACTGGGGCCAGGGAACCCTGGTCACCGTCTCCTCAGCCTCCACCAAGGGCCCATCGGTCTTCCCCCTGGCGCC
// +
// CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
VDJCAlignerS aligner = new VDJCAlignerS(parameters);
for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) if (parameters.containsRequiredFeature(gene))
aligner.addGene(gene);
SingleReadImpl read = new SingleReadImpl(0, new NSequenceWithQuality(new NucleotideSequence("GCTGTGTATTACTGTGCAAGAGGGCCCCAAGAAAATAGTGGTTATTACTACGGGTTTGACTACTGGGGCCAGGGAACCCTGGTCACCGTCTCCTCAGCCTCCACCAAGGGCCCATCGGTCTTCCCCCTGGCGCC"), SequenceQuality.GOOD_QUALITY_VALUE), "");
RandomUtil.getThreadLocalRandom().setSeed(29);
VDJCAlignmentResult<SingleRead> result = aligner.process0(read);
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class AlignedTarget method orderTargets.
public static List<AlignedTarget> orderTargets(List<AlignedTarget> targets) {
// Selecting best gene by total score
final EnumMap<GeneType, VDJCGene> bestGenes = new EnumMap<>(GeneType.class);
for (GeneType geneType : GeneType.VDJC_REFERENCE) {
TObjectLongMap<VDJCGene> scores = new TObjectLongHashMap<>();
for (AlignedTarget target : targets) {
for (VDJCHit hit : target.getAlignments().getHits(geneType)) {
Alignment<NucleotideSequence> alignment = hit.getAlignment(target.getTargetId());
if (alignment != null)
scores.adjustOrPutValue(hit.getGene(), (long) alignment.getScore(), (long) alignment.getScore());
}
}
VDJCGene bestGene = null;
long bestScore = Long.MIN_VALUE;
TObjectLongIterator<VDJCGene> it = scores.iterator();
while (it.hasNext()) {
it.advance();
if (bestScore < it.value()) {
bestScore = it.value();
bestGene = it.key();
}
}
if (bestGene != null)
bestGenes.put(geneType, bestGene);
}
// Class to facilitate comparison between targets
final class Wrapper implements Comparable<Wrapper> {
final AlignedTarget target;
final EnumMap<GeneType, Alignment<NucleotideSequence>> alignments = new EnumMap<>(GeneType.class);
Wrapper(AlignedTarget target) {
this.target = target;
for (VDJCGene gene : bestGenes.values()) for (VDJCHit hit : target.getAlignments().getHits(gene.getGeneType())) if (hit.getGene() == gene) {
Alignment<NucleotideSequence> alignment = hit.getAlignment(target.targetId);
if (alignment != null) {
alignments.put(gene.getGeneType(), alignment);
break;
}
}
}
GeneType firstAlignedGeneType() {
for (GeneType geneType : GeneType.VDJC_REFERENCE) if (alignments.containsKey(geneType))
return geneType;
return null;
}
@Override
public int compareTo(Wrapper o) {
GeneType thisFirstGene = firstAlignedGeneType();
GeneType otherFirstGene = o.firstAlignedGeneType();
int cmp = Byte.compare(thisFirstGene.getOrder(), otherFirstGene.getOrder());
return cmp != 0 ? cmp : Integer.compare(alignments.get(thisFirstGene).getSequence1Range().getLower(), o.alignments.get(thisFirstGene).getSequence1Range().getLower());
}
}
// Creating wrappers and sorting list
List<Wrapper> wrappers = new ArrayList<>(targets.size());
for (AlignedTarget target : targets) {
Wrapper wrapper = new Wrapper(target);
if (wrapper.firstAlignedGeneType() == null)
continue;
wrappers.add(wrapper);
}
Collections.sort(wrappers);
// Creating result
List<AlignedTarget> result = new ArrayList<>(wrappers.size());
for (Wrapper wrapper : wrappers) result.add(wrapper.target);
return result;
}
Aggregations