Skip to content

Commit

Permalink
Sequence translation fixes in export alignments pretty (#370)
Browse files Browse the repository at this point in the history
* Several fixes and tests for translation in exportAlignmentsPretty.

* More fixes to translation rules.

* repseqio SNAPSHOT upgrade
  • Loading branch information
dbolotin committed Apr 7, 2018
1 parent a25ba11 commit 799a4ed
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 14 deletions.
10 changes: 2 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,14 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<milib.version>1.8.3</milib.version>
<milib.version>1.8.4-SNAPSHOT</milib.version>
</properties>

<dependencies>
<dependency>
<groupId>io.repseq</groupId>
<artifactId>repseqio</artifactId>
<version>1.2.11</version>
<exclusions>
<exclusion>
<groupId>com.milaboratory</groupId>
<artifactId>milib</artifactId>
</exclusion>
</exclusions>
<version>1.2.12-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion repseqio
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,39 @@ public static void drawAASequence(MultiAlignmentHelper helper, SequencePartition
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;
}

while (aaPosition < aa.size() &&
(aaPosition < aa.size() - 1 || aa.codeAt(aaPosition) != AminoAcidAlphabet.INCOMPLETE_CODON)) {

ntPosition = trParam.range.getFrom()
+ AminoAcidSequence.convertAAPositionToNt(aaPosition, mainSequence.size(),
+ AminoAcidSequence.convertAAPositionToNt(aaPosition, bigSeq.size(),
trParam.translationParameters);
line[helper.subjectToAlignmentPosition(ntPosition + 1)] =
AminoAcidSequence.ALPHABET.codeToSymbol(aa.codeAt(aaPosition));

if (leftover != null && trParam.leftIncompleteCodonRange() != null)
ntPosition -= trParam.leftIncompleteCodonRange().length();
boolean isLeftover = false;
if (leftover != null) {
if (trParam.leftIncompleteCodonRange() != null)
isLeftover = (aaPosition == 0);
else
isLeftover = (aaPosition == aa.size() - 1);
}

if (aa.codeAt(aaPosition) != AminoAcidAlphabet.INCOMPLETE_CODON)
++ntPosition;
char c = AminoAcidSequence.ALPHABET.codeToSymbol(aa.codeAt(aaPosition));
if (isLeftover)
c = Character.toLowerCase(c);
line[helper.subjectToAlignmentPosition(ntPosition)] = c;
++aaPosition;
}
if (aaPosition < aa.size() &&
(aaPosition < aa.size() - 1 || aa.codeAt(aaPosition) != AminoAcidAlphabet.INCOMPLETE_CODON)) {
if (aaPosition < aa.size() && (aaPosition < aa.size() - 1 || aa.codeAt(aaPosition) == AminoAcidAlphabet.INCOMPLETE_CODON)) {
ntPosition = trParam.range.getFrom()
+ AminoAcidSequence.convertAAPositionToNt(aaPosition, mainSequence.size(),
trParam.translationParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2014-2018, Bolotin Dmitry, Chudakov Dmitry, Shugay Mikhail
* (here and after addressed as Inventors)
* All Rights Reserved
*
* Permission to use, copy, modify and distribute any part of this program for
* educational, research and non-profit purposes, by non-profit institutions
* only, without fee, and without a written agreement is hereby granted,
* provided that the above copyright notice, this paragraph and the following
* three paragraphs appear in all copies.
*
* Those desiring to incorporate this work into commercial products or use for
* commercial purposes should contact the Inventors using one of the following
* email addresses: chudakovdm@mail.ru, chudakovdm@gmail.com
*
* IN NO EVENT SHALL THE INVENTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE INVENTORS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE INVENTORS HAS
* NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS. THE INVENTORS MAKES NO REPRESENTATIONS AND EXTENDS NO
* WARRANTIES OF ANY KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
* PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE ANY
* PATENT, TRADEMARK OR OTHER RIGHTS.
*/
package com.milaboratory.mixcr.basictypes;

import com.milaboratory.core.Range;
import com.milaboratory.core.alignment.Alignment;
import com.milaboratory.core.alignment.MultiAlignmentHelper;
import com.milaboratory.core.mutations.Mutations;
import com.milaboratory.core.sequence.NucleotideSequence;
import io.repseq.core.ExtendedReferencePointsBuilder;
import io.repseq.core.ReferencePoint;
import org.junit.Assert;
import org.junit.Test;

import static com.milaboratory.core.alignment.MultiAlignmentHelper.DEFAULT_SETTINGS;

public class VDJCAlignmentsFormatterTest {
boolean show = true;

@Test
public void test0() {
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGGG",
ReferencePoint.CDR3Begin, ReferencePoint.CDR3End).endsWith(" G "));
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTAACCGTTGTAGGG",
ReferencePoint.CDR3Begin, ReferencePoint.CDR3End).endsWith(" G "));
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGAACCGTTGTAGGG",
ReferencePoint.CDR3Begin, ReferencePoint.CDR3End).endsWith(" G "));
}

@Test
public void test1() {
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGGG",
ReferencePoint.CDR3Begin, ReferencePoint.VEndTrimmed).endsWith(" G "));
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGG",
ReferencePoint.CDR3Begin, ReferencePoint.VEndTrimmed).endsWith("_ "));
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAG",
ReferencePoint.CDR3Begin, ReferencePoint.VEndTrimmed).endsWith("_"));
}

@Test
public void test2() {
Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGGG",
ReferencePoint.JBeginTrimmed, ReferencePoint.CDR3End).startsWith(" G "));
Assert.assertTrue(testWithoutLeftover("GTTCGGGGACCAGGTTAACCGTTGTAGGG",
ReferencePoint.JBeginTrimmed, ReferencePoint.CDR3End).startsWith("_ "));
Assert.assertTrue(testWithoutLeftover("TTCGGGGACCAGGTTAACCGTTGTAGGG",
ReferencePoint.JBeginTrimmed, ReferencePoint.CDR3End).startsWith("_"));
}

@Test
public void test3() {
testWithLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGG", "G",
ReferencePoint.L1Begin, ReferencePoint.L1End, ReferencePoint.L2Begin, ReferencePoint.L2End);
// Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGGG",
// ReferencePoint.JBeginTrimmed, ReferencePoint.CDR3End).startsWith(" G "));
// Assert.assertTrue(testWithoutLeftover("GGTTCGGGGACCAGGTTAACCGTTGTAGGG",
// ReferencePoint.JBeginTrimmed, ReferencePoint.CDR3End).startsWith(" G "));
}

public String testWithoutLeftover(String seqStr, ReferencePoint rp1, ReferencePoint rp2) {
NucleotideSequence seq = new NucleotideSequence(seqStr);
Alignment<NucleotideSequence> al = new Alignment<>(seq, Mutations.EMPTY_NUCLEOTIDE_MUTATIONS,
new Range(0, seq.size()), new Range(0, seq.size()), 100.0f);
MultiAlignmentHelper ml = MultiAlignmentHelper.build(DEFAULT_SETTINGS, new Range(0, seq.size()), al);
ExtendedReferencePointsBuilder b = new ExtendedReferencePointsBuilder();
b.setPosition(rp1, 0);
b.setPosition(rp2, seq.size());
VDJCAlignmentsFormatter.drawAASequence(ml, b.build(), seq);
if (show)
System.out.println(ml);
return ml.getAnnotationString(0);
}

public String testWithLeftover(String seqStr1, String seqStr2,
ReferencePoint rp1, ReferencePoint rp2,
ReferencePoint rp3, ReferencePoint rp4) {
NucleotideSequence seq = new NucleotideSequence(seqStr1 + "AAAAAAAAAA" + seqStr2);
Alignment<NucleotideSequence> al = new Alignment<>(seq, Mutations.EMPTY_NUCLEOTIDE_MUTATIONS,
new Range(0, seq.size()), new Range(0, seq.size()), 100.0f);
MultiAlignmentHelper ml = MultiAlignmentHelper.build(DEFAULT_SETTINGS, new Range(0, seq.size()), al);
ExtendedReferencePointsBuilder b = new ExtendedReferencePointsBuilder();
b.setPosition(rp1, 0);
b.setPosition(rp2, seqStr1.length());
b.setPosition(rp3, seqStr1.length() + 10);
b.setPosition(rp4, seqStr1.length() + 10 + seqStr2.length());
VDJCAlignmentsFormatter.drawAASequence(ml, b.build(), seq);
if (show)
System.out.println(ml);
return ml.getAnnotationString(0);
}
}

0 comments on commit 799a4ed

Please sign in to comment.