|
| 1 | +package org.biojava.nbio.core; |
| 2 | + |
| 3 | +import junit.framework.TestCase; |
| 4 | +import org.biojava.nbio.core.exceptions.CompoundNotFoundException; |
| 5 | +import org.biojava.nbio.core.sequence.DNASequence; |
| 6 | +import org.biojava.nbio.core.sequence.RNASequence; |
| 7 | +import org.biojava.nbio.core.sequence.compound.AmbiguityDNACompoundSet; |
| 8 | +import org.biojava.nbio.core.sequence.compound.AmbiguityRNACompoundSet; |
| 9 | +import org.biojava.nbio.core.sequence.compound.NucleotideCompound; |
| 10 | +import org.biojava.nbio.core.sequence.io.RNASequenceCreator; |
| 11 | +import org.biojava.nbio.core.sequence.template.Compound; |
| 12 | +import org.biojava.nbio.core.sequence.template.CompoundSet; |
| 13 | +import org.biojava.nbio.core.sequence.template.Sequence; |
| 14 | +import org.biojava.nbio.core.sequence.transcription.DNAToRNATranslator; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +/** |
| 18 | + * A Test case for https://github.com/biojava/biojava/issues/344 |
| 19 | + * |
| 20 | + * Created by andreas on 12/4/15. |
| 21 | + */ |
| 22 | + |
| 23 | +public class TestAmbiguityCompoundSet extends TestCase{ |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testCompountSet(){ |
| 27 | + try { |
| 28 | + |
| 29 | + CompoundSet<NucleotideCompound> dnaSet = AmbiguityDNACompoundSet.getDNACompoundSet(); |
| 30 | + CompoundSet<NucleotideCompound> rnaSet = AmbiguityRNACompoundSet.getRNACompoundSet(); |
| 31 | + |
| 32 | + DNASequence dna=new DNASequence("AGTCS", dnaSet); |
| 33 | + |
| 34 | + assertEquals("AGTCS",dna.toString()); |
| 35 | + |
| 36 | + RNASequence rna = dna.getRNASequence(); |
| 37 | + |
| 38 | + rna = new RNASequence(dna.getSequenceAsString().replaceAll("T", "U"), AmbiguityRNACompoundSet.getRNACompoundSet()); //fails with missing compound S |
| 39 | + |
| 40 | + assertEquals("AGUCS",rna.toString()); |
| 41 | + |
| 42 | + /** now, do the translation also using the underlying API (should not be needed for a user) |
| 43 | + * |
| 44 | + */ |
| 45 | + DNAToRNATranslator translator = new DNAToRNATranslator(new RNASequenceCreator(rnaSet |
| 46 | + ),dnaSet,rnaSet,false); |
| 47 | + |
| 48 | + Sequence<NucleotideCompound> translated = translator.createSequence(dna); |
| 49 | + |
| 50 | + assertEquals("AGUCS", translated.toString()); |
| 51 | + |
| 52 | + } catch (CompoundNotFoundException e) { |
| 53 | + e.printStackTrace(); |
| 54 | + fail(e.getMessage()); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments