use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class VDJCAlignerPVFirst method processStrict.
private VDJCAlignmentResult<PairedRead> processStrict(PairedRead input, PAlignmentHelper[] helpers) {
// Calculates which PTarget was aligned with the highest score
PAlignmentHelper bestHelper = helpers[0];
for (int i = 1; i < helpers.length; ++i) if (bestHelper.score() < helpers[i].score())
bestHelper = helpers[i];
// If V or J hits are absent
if (!bestHelper.hasVAndJHits()) {
if (!bestHelper.hasVOrJHits())
onFailedAlignment(input, VDJCAlignmentFailCause.NoHits);
else if (!bestHelper.hasVHits())
onFailedAlignment(input, VDJCAlignmentFailCause.NoVHits);
else
onFailedAlignment(input, VDJCAlignmentFailCause.NoJHits);
return new VDJCAlignmentResult<>(input);
}
// Performing alignment of C and D genes; if corresponding parameters are set include their scores to
// the total score value
bestHelper.performCDAlignment();
// 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());
// If hits for V or J are missing after filtration
if (!bestHelper.isGoodVJ()) {
if (!bestHelper.hasVHits())
onFailedAlignment(input, VDJCAlignmentFailCause.NoVHits);
else if (!bestHelper.hasJHits())
onFailedAlignment(input, VDJCAlignmentFailCause.NoJHits);
else if (!bestHelper.hasVJOnTheSameTarget())
onFailedAlignment(input, VDJCAlignmentFailCause.VAndJOnDifferentTargets);
else
onFailedAlignment(input, VDJCAlignmentFailCause.LowTotalScore);
return new VDJCAlignmentResult<>(input);
}
// Read successfully aligned
VDJCAlignments alignments = bestHelper.createResult(input.getId(), this, input);
onSuccessfulAlignment(input, alignments);
if (bestHelper.vChimera)
onSegmentChimeraDetected(GeneType.Variable, input, alignments);
if (bestHelper.jChimera)
onSegmentChimeraDetected(GeneType.Joining, input, alignments);
return new VDJCAlignmentResult<>(input, alignments);
}
use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class VDJCAlignerWithMerge method process0.
@Override
protected VDJCAlignmentResult<PairedRead> process0(final PairedRead read) {
PairedReadMergingResult merged = merger.process(read);
if (merged.isSuccessful()) {
VDJCAlignments alignment = singleAligner.process(new SingleReadImpl(read.getId(), merged.getOverlappedSequence(), "")).alignment;
if (listener != null)
listener.onSuccessfulSequenceOverlap(read, alignment);
if (alignment != null) {
boolean isRC = ((SequenceHistory.RawSequence) alignment.getHistory(0)).index.isReverseComplement;
alignment = alignment.setHistory(new SequenceHistory[] { new SequenceHistory.Merge(SequenceHistory.OverlapType.SequenceOverlap, new SequenceHistory.RawSequence(read.getId(), (byte) (isRC ? 1 : 0), false, read.getR1().getData().size()), new SequenceHistory.RawSequence(read.getId(), (byte) (isRC ? 0 : 1), merged.isReversed(), read.getR2().getData().size()), merged.getOffset(), merged.getErrors()) }, new SequenceRead[] { read });
}
return new VDJCAlignmentResult<>(read, alignment);
} else
return pairedAligner.process(read);
}
use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class AlignmentsMappingMerger method take.
@Override
public VDJCAlignments take() {
VDJCAlignments al = alignments.take();
if (al == null) {
assert readToCloneMappings.take() == null;
return null;
}
ReadToCloneMapping m = readToCloneMappings.take();
assert m.alignmentsId == al.getAlignmentsIndex();
return al.setMapping(m);
}
use of com.milaboratory.mixcr.basictypes.VDJCAlignments in project mixcr by milaboratory.
the class VDJCAlignerPVFirstTest method test1.
@Test
public void test1() throws Exception {
VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
List<VDJCAlignments> alignemntsList = new ArrayList<>();
int header;
int total = 0;
int leftHit = 0;
try (PairedFastqReader reader = new PairedFastqReader(VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R2.fastq"), true)) {
VDJCAlignerPVFirst aligner = new VDJCAlignerPVFirst(parameters);
for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) {
if (parameters.containsRequiredFeature(gene))
aligner.addGene(gene);
}
for (PairedRead read : CUtils.it(reader)) {
++total;
VDJCAlignmentResult<PairedRead> result = aligner.process(read);
if (result.alignment != null) {
alignemntsList.add(result.alignment);
for (VDJCHit hit : result.alignment.getHits(GeneType.Variable)) if (hit.getAlignment(0) != null && hit.getAlignment(1) != null)
++leftHit;
}
}
}
System.out.println(alignemntsList.size());
System.out.println(total);
System.out.println(leftHit);
Assert.assertTrue(alignemntsList.size() > 10);
int k = 10;
for (VDJCAlignments alignments : alignemntsList) {
for (int target = 0; target < alignments.numberOfTargets(); target++) {
MultiAlignmentHelper helperBig = VDJCAlignmentsFormatter.getTargetAsMultiAlignment(alignments, target);
if (helperBig == null)
continue;
for (MultiAlignmentHelper helper : helperBig.split(80)) {
System.out.println(helper);
System.out.println();
if (--k < 0)
return;
}
}
}
// System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
//
// try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()), ll)) {
// int i = 0;
// for (VDJCAlignments alignments : CUtils.it(reader))
// Assert.assertEquals(alignemntsList.get(i++), alignments);
// }
}
Aggregations