Search in sources :

Example 1 with SequencePartitioning

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;
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper) ArrayList(java.util.ArrayList) SequencePartitioning(io.repseq.core.SequencePartitioning) Range(com.milaboratory.core.Range) ReferencePoint(io.repseq.core.ReferencePoint) Alignment(com.milaboratory.core.alignment.Alignment) NSequenceWithQuality(com.milaboratory.core.sequence.NSequenceWithQuality) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GeneType(io.repseq.core.GeneType)

Aggregations

Range (com.milaboratory.core.Range)1 Alignment (com.milaboratory.core.alignment.Alignment)1 MultiAlignmentHelper (com.milaboratory.core.alignment.MultiAlignmentHelper)1 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 GeneType (io.repseq.core.GeneType)1 ReferencePoint (io.repseq.core.ReferencePoint)1 SequencePartitioning (io.repseq.core.SequencePartitioning)1 ArrayList (java.util.ArrayList)1