use of com.milaboratory.mixcr.basictypes.VDJCHit in project mixcr by milaboratory.
the class PreVDJCHit method combine.
static VDJCHit[] combine(final List<VDJCGene> genes, final GeneFeature feature, final PreVDJCHit[][] hits) {
for (int i = 0; i < hits.length; i++) Arrays.sort(hits[i]);
ArrayList<VDJCHit> result = new ArrayList<>();
final int[] pointers = new int[hits.length];
Alignment<NucleotideSequence>[] alignments;
int i, minId;
while (true) {
minId = Integer.MAX_VALUE;
for (i = 0; i < pointers.length; ++i) if (pointers[i] < hits[i].length && minId > hits[i][pointers[i]].id)
minId = hits[i][pointers[i]].id;
if (minId == Integer.MAX_VALUE)
break;
alignments = new Alignment[hits.length];
for (i = 0; i < pointers.length; ++i) if (pointers[i] < hits[i].length && minId == hits[i][pointers[i]].id) {
alignments[i] = hits[i][pointers[i]].alignment;
++pointers[i];
}
result.add(new VDJCHit(genes.get(minId), alignments, feature));
}
VDJCHit[] vdjcHits = result.toArray(new VDJCHit[result.size()]);
Arrays.sort(vdjcHits);
return vdjcHits;
}
use of com.milaboratory.mixcr.basictypes.VDJCHit in project mixcr by milaboratory.
the class PreVDJCHit method convert.
static VDJCHit[] convert(List<VDJCGene> genes, GeneFeature feature, List<PreVDJCHit> preHits, int indexOfTargets, int numberOfTargets) {
VDJCHit[] hits = new VDJCHit[preHits.size()];
for (int i = 0; i < preHits.size(); i++) {
PreVDJCHit h = preHits.get(i);
Alignment<NucleotideSequence>[] alignments = new Alignment[numberOfTargets];
alignments[indexOfTargets] = h.alignment;
hits[i] = new VDJCHit(genes.get(h.id), alignments, feature);
}
return hits;
}
use of com.milaboratory.mixcr.basictypes.VDJCHit in project mixcr by milaboratory.
the class TargetMerger method extractSortedHits.
@SuppressWarnings("unchecked")
static List<HitMappingRecord> extractSortedHits(AlignedTarget targetLeft, AlignedTarget targetRight, GeneType geneType) {
// Fast calculation for targets from the same PE-read (or multi-read)
if (targetLeft.getAlignments() == targetRight.getAlignments()) {
VDJCHit[] hits = targetLeft.getAlignments().getHits(geneType);
List<HitMappingRecord> mRecords = new ArrayList<>(hits.length);
for (VDJCHit hit : hits) mRecords.add(new HitMappingRecord(hit.getGene(), new Alignment[] { hit.getAlignment(targetLeft.getTargetId()), hit.getAlignment(targetRight.getTargetId()) }));
// other parts of the multi-read object
return mRecords;
}
// Full recalculation for targets form two different Alignments objects
Map<VDJCGeneId, HitMappingRecord> map = extractHitsMapping(targetLeft, targetRight, geneType);
List<HitMappingRecord> mRecords = new ArrayList<>(map.values());
Collections.sort(mRecords, new Comparator<HitMappingRecord>() {
@Override
public int compare(HitMappingRecord o1, HitMappingRecord o2) {
return Integer.compare(sumScore(o2.alignments), sumScore(o1.alignments));
}
});
return mRecords;
}
use of com.milaboratory.mixcr.basictypes.VDJCHit in project mixcr by milaboratory.
the class TargetMerger method merge.
@SuppressWarnings("unchecked")
public AlignedTarget merge(AlignedTarget targetLeft, AlignedTarget targetRight, int offset, OverlapType overlapType, int nMismatches) {
if (offset < 0)
return merge(targetRight, targetLeft, -offset, overlapType, nMismatches);
final NSequenceWithQuality mergedTarget = merger.overlap(targetLeft.getTarget(), targetRight.getTarget(), offset);
EnumMap<GeneType, VDJCHit[]> result = new EnumMap<>(GeneType.class);
for (GeneType geneType : GeneType.VJC_REFERENCE) {
final BatchAlignerWithBaseParameters bp = ((KGeneAlignmentParameters) alignerParameters.getGeneAlignerParameters(geneType)).getParameters();
final VDJCHit[] leftHits = targetLeft.getAlignments().getHits(geneType);
final VDJCHit[] rightHits = targetRight.getAlignments().getHits(geneType);
GeneFeature alignedFeature = leftHits.length == 0 ? rightHits.length == 0 ? null : rightHits[0].getAlignedFeature() : leftHits[0].getAlignedFeature();
Map<VDJCGeneId, HitMappingRecord> map = extractHitsMapping(targetLeft, targetRight, geneType);
ArrayList<VDJCHit> resultingHits = new ArrayList<>();
for (Map.Entry<VDJCGeneId, HitMappingRecord> mE : map.entrySet()) {
final VDJCGene gene = mE.getValue().gene;
Alignment<NucleotideSequence> mergedAl = merge(bp.getScoring(), extractBandedWidth(bp), mergedTarget.getSequence(), offset, mE.getValue().alignments[0], mE.getValue().alignments[1]);
resultingHits.add(new VDJCHit(gene, mergedAl, alignedFeature));
}
Collections.sort(resultingHits);
// final float relativeMinScore = extractRelativeMinScore(bp);
// int threshold = (int) (resultingHits.size() > 0 ? resultingHits.get(0).getScore() * relativeMinScore : 0);
// for (int i = resultingHits.size() - 1; i > 0; --i)
// if (resultingHits.get(i).getScore() < threshold)
// resultingHits.remove(i);
result.put(geneType, resultingHits.toArray(new VDJCHit[resultingHits.size()]));
}
VDJCAlignments alignments = new VDJCAlignments(result, new NSequenceWithQuality[] { mergedTarget }, new SequenceHistory[] { new SequenceHistory.Merge(overlapType, targetLeft.getHistory(), targetRight.getHistory(), offset, nMismatches) }, VDJCAlignments.mergeOriginalReads(targetLeft.getAlignments(), targetRight.getAlignments()));
AlignedTarget resultTarget = new AlignedTarget(alignments, 0);
for (BPoint bPoint : BPoint.values()) {
int leftPoint = targetLeft.getBPoint(bPoint);
int rightPoint = targetRight.getBPoint(bPoint);
if (leftPoint != -1 && rightPoint != -1)
throw new IllegalArgumentException("Same bPoint defined in both input targets.");
else if (leftPoint != -1)
resultTarget = resultTarget.setBPoint(bPoint, leftPoint);
else if (rightPoint != -1)
resultTarget = resultTarget.setBPoint(bPoint, offset + rightPoint);
}
return resultTarget;
}
use of com.milaboratory.mixcr.basictypes.VDJCHit 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