use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.
the class IOTest method testSerialization1.
@Test
public void testSerialization1() throws Exception {
VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
List<VDJCAlignments> alignemntsList = new ArrayList<>();
int header;
long numberOfReads;
try (SingleFastqReader reader = new SingleFastqReader(IOTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), true)) {
VDJCAlignerS aligner = new VDJCAlignerS(parameters);
for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) {
if (parameters.containsRequiredFeature(gene))
aligner.addGene(gene);
}
try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(bos)) {
writer.header(aligner);
header = bos.size();
for (SingleRead read : CUtils.it(reader)) {
VDJCAlignmentResult<SingleRead> result = aligner.process(read);
if (result.alignment != null) {
writer.write(result.alignment);
alignemntsList.add(result.alignment);
}
}
writer.setNumberOfProcessedReads(numberOfReads = reader.getNumberOfReads());
}
}
assertTrue(alignemntsList.size() > 10);
assertTrue(numberOfReads > 10);
System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()))) {
int i = 0;
for (VDJCAlignments alignments : CUtils.it(reader)) assertEquals(alignemntsList.get(i++), alignments);
Assert.assertEquals(numberOfReads, reader.getNumberOfReads());
}
}
use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters 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.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.
the class RunMiXCR method align.
public static AlignResult align(RunMiXCRAnalysis parameters) throws Exception {
VDJCAlignerParameters alignerParameters = parameters.alignerParameters;
VDJCAligner aligner = VDJCAligner.createAligner(alignerParameters, parameters.isInputPaired(), alignerParameters.getMergerParameters() != null);
List<VDJCGene> genes = new ArrayList<>();
for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary(parameters.library, parameters.species).getGenes(parameters.chains)) if (alignerParameters.containsRequiredFeature(gene) && (gene.isFunctional() || !parameters.isFunctionalOnly)) {
genes.add(gene);
aligner.addGene(gene);
}
AlignerReport report = new AlignerReport();
aligner.setEventsListener(report);
try (SequenceReaderCloseable<? extends SequenceRead> reader = parameters.getReader()) {
// start progress reporting
if (reader instanceof CanReportProgress)
SmartProgressReporter.startProgressReport("align", (CanReportProgress) reader);
OutputPort<Chunk<SequenceRead>> mainInputReads = CUtils.buffered((OutputPort) chunked(reader, 64), 16);
OutputPort<VDJCAlignmentResult> alignments = unchunked(new ParallelProcessor(mainInputReads, chunked(aligner), parameters.threads));
List<VDJCAlignments> als = new ArrayList<>();
int ind = 0;
for (VDJCAlignmentResult t : CUtils.it(new OrderedOutputPort<>(alignments, new Indexer<VDJCAlignmentResult>() {
@Override
public long getIndex(VDJCAlignmentResult r) {
return r.read.getId();
}
}))) {
if (t.alignment != null) {
t.alignment.setAlignmentsIndex(ind++);
als.add(t.alignment);
}
}
return new AlignResult(parameters, reader.getNumberOfReads(), report, als, genes, aligner);
}
}
use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.
the class JsonOverriderTest method test3.
@Test
public void test3() throws Exception {
GeneFeature jRegion = GeneFeature.parse("JRegion");
System.out.println(jRegion);
System.out.println(GeneFeature.encode(jRegion));
VDJCAlignerParameters params = VDJCParametersPresets.getByName("default");
Map<String, String> overrides = new HashMap<String, String>() {
{
put("vParameters.geneFeatureToAlign", "VTranscript");
}
};
Assert.assertNotNull(JsonOverrider.override(params, VDJCAlignerParameters.class, overrides));
}
use of com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters in project mixcr by milaboratory.
the class PartialAlignmentsAssemblerAlignerTest method basicTest1.
@Test
public void basicTest1() throws Exception {
Well44497b rg = new Well44497b(12312);
VDJCAlignerParameters rnaSeqParams = VDJCParametersPresets.getByName("rna-seq");
PartialAlignmentsAssemblerAligner aligner = new PartialAlignmentsAssemblerAligner(rnaSeqParams);
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");
// | 305
// 250V + 55CDR3 (20V 7N 10D 3N 15J) + 28J + 100C
NucleotideSequence baseSeq = TargetBuilder.generateSequence(genes, "{CDR3Begin(-250)}V*270 NNNNNNN {DBegin(0)}D*10 NNN {CDR3End(-15):FR4End} {CBegin}C*100", rg);
int len = 70;
NucleotideSequence seq1 = baseSeq.getRange(0, len);
NucleotideSequence seq2 = baseSeq.getRange(245, 245 + len);
NucleotideSequence seq3 = baseSeq.getRange(320, 320 + len);
VDJCAlignmentResult<VDJCMultiRead> alignment = aligner.process(MiXCRTestUtils.createMultiRead(seq1, seq2, seq3));
VDJCAlignments al = alignment.alignment;
Assert.assertNotNull(al);
assertInHits(genes.v, al);
assertInHits(genes.d, al);
assertInHits(genes.j, al);
assertInHits(genes.c, al);
VDJCHit bestV = al.getBestHit(GeneType.Variable);
VDJCHit bestD = al.getBestHit(GeneType.Diversity);
VDJCHit bestJ = al.getBestHit(GeneType.Joining);
VDJCHit bestC = al.getBestHit(GeneType.Constant);
Assert.assertNotNull(bestV.getAlignment(0));
Assert.assertNotNull(bestV.getAlignment(1));
Assert.assertNull(bestV.getAlignment(2));
Assert.assertNull(bestD.getAlignment(0));
Assert.assertNotNull(bestD.getAlignment(1));
Assert.assertNull(bestD.getAlignment(2));
Assert.assertNull(bestJ.getAlignment(0));
Assert.assertNotNull(bestJ.getAlignment(1));
Assert.assertNotNull(bestJ.getAlignment(2));
Assert.assertNull(bestC.getAlignment(0));
Assert.assertNull(bestC.getAlignment(1));
Assert.assertNotNull(bestC.getAlignment(2));
}
Aggregations