Permalink
Browse files

This adds amino acid sequence in exportAlignmentsPretty output. (#317)

* This fixes #316
* This supersedes #192
* Repseqio update.
  • Loading branch information...
dbolotin committed Dec 26, 2017
1 parent 2fd5928 commit c6be85643054561da030df6981ab3b510a1e83ed
@@ -61,6 +61,11 @@ protected Range getRange(GeneFeature.ReferenceRange refRange) {
null : range;
}
@Override
public boolean isReversed() {
return false;
}
@Override
protected int getLength(GeneFeature.ReferenceRange refRange) {
Range range = getRange(refRange);
@@ -35,9 +35,12 @@
import com.milaboratory.core.alignment.Aligner;
import com.milaboratory.core.alignment.Alignment;
import com.milaboratory.core.alignment.MultiAlignmentHelper;
import com.milaboratory.core.sequence.AminoAcidAlphabet;
import com.milaboratory.core.sequence.AminoAcidSequence;
import com.milaboratory.core.sequence.NSequenceWithQuality;
import com.milaboratory.core.sequence.NucleotideSequence;
import io.repseq.core.GeneType;
import io.repseq.core.RangeTranslationParameters;
import io.repseq.core.ReferencePoint;
import io.repseq.core.SequencePartitioning;
@@ -96,6 +99,8 @@ public static MultiAlignmentHelper getTargetAsMultiAlignment(VDJCObject vdjcObje
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)" : ""));
@@ -106,6 +111,50 @@ public static MultiAlignmentHelper getTargetAsMultiAlignment(VDJCObject vdjcObje
return helper;
}
public static void drawAASequence(MultiAlignmentHelper helper, SequencePartitioning partitioning,
NucleotideSequence target) {
List<RangeTranslationParameters> trParams = partitioning.getTranslationParameters(target.size());
char[] line = new char[helper.size()];
Arrays.fill(line, ' ');
for (RangeTranslationParameters trParam : trParams) {
NucleotideSequence mainSequence = target.getRange(trParam.range);
NucleotideSequence leftover = trParam.codonLeftoverRange == null
? null
: target.getRange(trParam.codonLeftoverRange);
NucleotideSequence bigSeq = leftover == null ? mainSequence :
trParam.leftIncompleteCodonRange() != null
? leftover.concatenate(mainSequence)
: mainSequence.concatenate(leftover);
AminoAcidSequence aa = AminoAcidSequence.translate(bigSeq,
trParam.translationParameters);
int aaPosition = 0;
int ntPosition = trParam.range.getFrom()
+ AminoAcidSequence.convertAAPositionToNt(aaPosition, mainSequence.size(),
trParam.translationParameters);
if (aa.codeAt(aaPosition) == AminoAcidAlphabet.INCOMPLETE_CODON) {
line[helper.subjectToAlignmentPosition(ntPosition)] =
AminoAcidSequence.ALPHABET.codeToSymbol(aa.codeAt(aaPosition));
++aaPosition;
}
do {
ntPosition = trParam.range.getFrom()
+ AminoAcidSequence.convertAAPositionToNt(aaPosition, mainSequence.size(),
trParam.translationParameters);
line[helper.subjectToAlignmentPosition(ntPosition + 1)] =
AminoAcidSequence.ALPHABET.codeToSymbol(aa.codeAt(aaPosition));
} while (++aaPosition < aa.size() &&
aa.codeAt(aaPosition) != AminoAcidAlphabet.INCOMPLETE_CODON);
if (aaPosition < aa.size() && aa.codeAt(aaPosition) == AminoAcidAlphabet.INCOMPLETE_CODON) {
ntPosition = trParam.range.getFrom()
+ AminoAcidSequence.convertAAPositionToNt(aaPosition, mainSequence.size(),
trParam.translationParameters);
line[helper.subjectToAlignmentPosition(ntPosition)] =
AminoAcidSequence.ALPHABET.codeToSymbol(aa.codeAt(aaPosition));
}
}
helper.addAnnotationString("", new String(line));
}
public static void drawPoints(MultiAlignmentHelper helper, SequencePartitioning partitioning,
PointToDraw... pointsToDraw) {
ArrayList<char[]> markers = new ArrayList<>();

0 comments on commit c6be856

Please sign in to comment.