use of io.repseq.core.SequencePartitioning in project mixcr by milaboratory.
the class VDJCAlignmentsFormatter method getTargetAsMultiAlignment.
public static MultiAlignmentHelper getTargetAsMultiAlignment(VDJCObject vdjcObject, int targetId, boolean addHitScore, boolean addReads) {
if (addReads && !(vdjcObject instanceof VDJCAlignments))
throw new IllegalArgumentException("Read alignments supported only for VDJCAlignments.");
NSequenceWithQuality target = vdjcObject.getTarget(targetId);
NucleotideSequence targetSeq = target.getSequence();
SequencePartitioning partitioning = vdjcObject.getPartitionedTarget(targetId).getPartitioning();
List<Alignment<NucleotideSequence>> alignments = new ArrayList<>();
List<String> alignmentLeftComments = new ArrayList<>();
List<String> alignmentRightComments = new ArrayList<>();
for (GeneType gt : GeneType.values()) for (VDJCHit hit : vdjcObject.getHits(gt)) {
Alignment<NucleotideSequence> alignment = hit.getAlignment(targetId);
if (alignment == null)
continue;
alignment = alignment.invert(targetSeq);
alignments.add(alignment);
alignmentLeftComments.add(hit.getGene().getName());
alignmentRightComments.add(" " + (int) (hit.getAlignment(targetId).getScore()) + (addHitScore ? " (" + (int) (hit.getScore()) + ")" : ""));
}
// Adding read information
if (addReads) {
VDJCAlignments vdjcAlignments = (VDJCAlignments) vdjcObject;
SequenceHistory history = vdjcAlignments.getHistory(targetId);
List<SequenceHistory.RawSequence> reads = history.rawReads();
for (SequenceHistory.RawSequence read : reads) {
NucleotideSequence seq = vdjcAlignments.getOriginalSequence(read.index).getSequence();
int offset = history.offset(read.index);
Alignment<NucleotideSequence> alignment = Aligner.alignOnlySubstitutions(targetSeq, seq, offset, seq.size(), 0, seq.size(), AffineGapAlignmentScoring.IGBLAST_NUCLEOTIDE_SCORING);
alignments.add(alignment);
alignmentLeftComments.add(read.index.toString());
alignmentRightComments.add("");
}
}
MultiAlignmentHelper helper = MultiAlignmentHelper.build(MultiAlignmentHelper.DEFAULT_SETTINGS, new Range(0, target.size()), targetSeq, alignments.toArray(new Alignment[alignments.size()]));
if (!alignments.isEmpty())
drawPoints(helper, partitioning, POINTS_FOR_REARRANGED);
drawAASequence(helper, partitioning, targetSeq);
helper.addSubjectQuality("Quality", target.getQuality());
helper.setSubjectLeftTitle("Target" + targetId);
helper.setSubjectRightTitle(" Score" + (addHitScore ? " (hit score)" : ""));
for (int i = 0; i < alignmentLeftComments.size(); i++) {
helper.setQueryLeftTitle(i, alignmentLeftComments.get(i));
helper.setQueryRightTitle(i, alignmentRightComments.get(i));
}
return helper;
}
Aggregations