use of com.milaboratory.mixcr.basictypes.VDJCAlignments 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.basictypes.VDJCAlignments 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));
}
use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class ActionFilterAlignments method go.
@Override
public void go(ActionHelper helper) throws Exception {
try (VDJCAlignmentsReader reader = parameters.getInput();
VDJCAlignmentsWriter writer = parameters.getOutput()) {
CanReportProgress progress = reader;
OutputPort<VDJCAlignments> sReads = reader;
if (parameters.limit != 0) {
sReads = new CountLimitingOutputPort<>(sReads, parameters.limit);
progress = SmartProgressReporter.extractProgress((CountLimitingOutputPort<?>) sReads);
}
writer.header(reader.getParameters(), reader.getUsedGenes());
SmartProgressReporter.startProgressReport("Filtering", progress);
int total = 0, passed = 0;
final AlignmentsFilter filter = parameters.getFilter();
for (VDJCAlignments al : CUtils.it(CUtils.buffered(sReads, 2048))) {
++total;
if (filter.accept(al)) {
writer.write(al);
++passed;
}
}
writer.setNumberOfProcessedReads(reader.getNumberOfReads());
System.out.printf("%s alignments analysed\n", total);
System.out.printf("%s alignments written (%.1f%%)\n", passed, 100.0 * passed / total);
}
}
use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class ActionSortAlignments method go.
@Override
public void go(ActionHelper helper) throws Exception {
try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(parameters.getInputFile())) {
SmartProgressReporter.startProgressReport("Reading vdjca", reader);
try (OutputPortCloseable<VDJCAlignments> sorted = Sorter.sort(reader, idComparator, 1024 * 512, new VDJCAlignmentsSerializer(reader), TempFileManager.getTempFile());
VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(parameters.getOutputFile())) {
writer.header(reader.getParameters(), reader.getUsedGenes());
final long nReads = reader.getNumberOfReads();
final CountingOutputPort<VDJCAlignments> counter = new CountingOutputPort<>(sorted);
SmartProgressReporter.startProgressReport("Writing sorted alignments", SmartProgressReporter.extractProgress(counter, nReads));
for (VDJCAlignments res : CUtils.it(counter)) writer.write(res);
writer.setNumberOfProcessedReads(nReads);
}
}
}
use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class VDJCAlignerPVFirst method processPartial.
private VDJCAlignmentResult<PairedRead> processPartial(PairedRead input, PAlignmentHelper[] helpers) {
// Calculates which PTarget was aligned with the highest score
helpers[0].performCDAlignment();
PAlignmentHelper bestHelper = helpers[0];
for (int i = 1; i < helpers.length; ++i) {
helpers[i].performCDAlignment();
if (bestHelper.score() < helpers[i].score())
bestHelper = helpers[i];
}
if (!bestHelper.hasVOrJHits()) {
onFailedAlignment(input, VDJCAlignmentFailCause.NoHits);
return new VDJCAlignmentResult<>(input);
}
// Calculates if this score is bigger then the threshold
if (bestHelper.score() < parameters.getMinSumScore()) {
onFailedAlignment(input, VDJCAlignmentFailCause.LowTotalScore);
return new VDJCAlignmentResult<>(input);
}
// Finally filtering hits inside this helper to meet minSumScore and maxHits limits
bestHelper.filterHits(parameters.getMinSumScore(), parameters.getMaxHits());
// TODO do we really need this ?
if (!bestHelper.hasVOrJHits()) {
onFailedAlignment(input, VDJCAlignmentFailCause.LowTotalScore);
return new VDJCAlignmentResult<>(input);
}
VDJCAlignments alignments = bestHelper.createResult(input.getId(), this, input);
// Final check
if (!parameters.getAllowNoCDR3PartAlignments()) {
// CDR3 Begin / End
boolean containCDR3Parts = false;
final VDJCHit bestV = alignments.getBestHit(GeneType.Variable);
final VDJCHit bestJ = alignments.getBestHit(GeneType.Joining);
for (int i = 0; i < 2; i++) {
if ((bestV != null && bestV.getAlignment(i) != null && bestV.getAlignment(i).getSequence1Range().getTo() >= bestV.getGene().getPartitioning().getRelativePosition(parameters.getFeatureToAlign(GeneType.Variable), reqPointL)) || (bestJ != null && bestJ.getAlignment(i) != null && bestJ.getAlignment(i).getSequence1Range().getFrom() <= bestJ.getGene().getPartitioning().getRelativePosition(parameters.getFeatureToAlign(GeneType.Joining), reqPointR))) {
containCDR3Parts = true;
break;
}
}
if (!containCDR3Parts) {
onFailedAlignment(input, VDJCAlignmentFailCause.NoCDR3Parts);
return new VDJCAlignmentResult<>(input);
}
}
// Read successfully aligned
onSuccessfulAlignment(input, alignments);
if (bestHelper.vChimera)
onSegmentChimeraDetected(GeneType.Variable, input, alignments);
if (bestHelper.jChimera)
onSegmentChimeraDetected(GeneType.Joining, input, alignments);
return new VDJCAlignmentResult<>(input, alignments);
}
Aggregations