Created
March 10, 2011 13:31
-
-
Save chapmanb/864088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/main/java/org/biojava3/core/sequence/transcription/RNAToAminoAcidTranslator.java.orig 2011-03-09 15:32:39.295875004 -0500 | |
+++ src/main/java/org/biojava3/core/sequence/transcription/RNAToAminoAcidTranslator.java 2011-03-10 08:18:42.525875009 -0500 | |
@@ -85,7 +85,6 @@ | |
codonL.add(codon); | |
} | |
- | |
unknownAminoAcidCompound = aminoAcids.getCompoundForString("X"); | |
} | |
@@ -105,32 +104,32 @@ | |
new WindowedSequence<NucleotideCompound>(originalSequence, 3); | |
for (SequenceView<NucleotideCompound> element : iter) { | |
- AminoAcidCompound aminoAcid; | |
+ AminoAcidCompound aminoAcid = null; | |
int i =1; | |
Table.CaseInsensitiveTriplet triplet = new Table.CaseInsensitiveTriplet( | |
element.getCompoundAt(i++), element.getCompoundAt(i++), element.getCompoundAt(i++)); | |
- Codon target; | |
+ Codon target = null; | |
int arrayIndex = triplet.intValue(); | |
//So long as we're within range then access | |
if(arrayIndex > -1 && arrayIndex < codonArray.length) { | |
target = codonArray[arrayIndex]; | |
- aminoAcid = target.getAminoAcid(); | |
+ if (target != null) { | |
+ aminoAcid = target.getAminoAcid(); | |
+ } | |
} | |
//Otherwise we have to use the Map | |
else { | |
target = quickLookup.get(triplet); | |
aminoAcid = target.getAminoAcid(); | |
} | |
- | |
if(aminoAcid == null && translateNCodons()) { | |
aminoAcid = unknownAminoAcidCompound; | |
} | |
addCompoundsToList(Arrays.asList(aminoAcid), workingList); | |
} | |
- | |
postProcessCompoundLists(workingList); | |
return workingListToSequences(workingList); | |
@@ -157,11 +156,13 @@ | |
AminoAcidCompound initMet = getToCompoundSet().getCompoundForString("M"); | |
AminoAcidCompound start = sequence.get(0); | |
boolean isStart = false; | |
- for (Codon c : aminoAcidToCodon.get(start)) { | |
- if (c.isStart()) { | |
- isStart = true; | |
- break; | |
- } | |
+ if (aminoAcidToCodon.containsKey(start)) { | |
+ for (Codon c : aminoAcidToCodon.get(start)) { | |
+ if (c.isStart()) { | |
+ isStart = true; | |
+ break; | |
+ } | |
+ } | |
} | |
if (isStart) { | |
@@ -176,11 +177,13 @@ | |
protected void trimStop(List<AminoAcidCompound> sequence) { | |
AminoAcidCompound stop = sequence.get(sequence.size() - 1); | |
boolean isStop = false; | |
- for (Codon c : aminoAcidToCodon.get(stop)) { | |
- if (c.isStop()) { | |
- isStop = true; | |
- break; | |
- } | |
+ if (aminoAcidToCodon.containsKey(stop)) { | |
+ for (Codon c : aminoAcidToCodon.get(stop)) { | |
+ if (c.isStop()) { | |
+ isStop = true; | |
+ break; | |
+ } | |
+ } | |
} | |
if (isStop) { | |
--- src/test/java/org/biojava3/core/sequence/TranslationTest.java.orig 2011-03-09 12:14:11.035875001 -0500 | |
+++ src/test/java/org/biojava3/core/sequence/TranslationTest.java 2011-03-10 08:18:27.085875003 -0500 | |
@@ -91,6 +91,21 @@ | |
assertThat("Initator methionine wrong", initMet.toString(), is("M")); | |
} | |
+ @Test | |
+ public void translateN() { | |
+ TranscriptionEngine.Builder b = new TranscriptionEngine.Builder(); | |
+ b.translateNCodons(true).initMet(true); | |
+ TranscriptionEngine e = b.build(); | |
+ DNASequence dna = new DNASequence("ATN"); | |
+ RNASequence rna = dna.getRNASequence(e); | |
+ ProteinSequence protein = rna.getProteinSequence(e); | |
+ assertThat("Ambiguous translation problem", protein.toString(), is("X")); | |
+ DNASequence dna2 = new DNASequence("GTGGTNTAA"); | |
+ RNASequence rna2 = dna2.getRNASequence(e); | |
+ ProteinSequence protein2 = rna2.getProteinSequence(e); | |
+ assertThat("Ambiguous translation problem", protein2.toString(), is("VX")); | |
+ } | |
+ | |
@SuppressWarnings("serial") | |
@Test | |
public void multiFrameTranslation() { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment