1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.bio.symbol;
import java.util.Iterator;
import java.util.Set;
import junit.framework.TestCase;
import org.biojava.bio.dist.Distribution;
import org.biojava.bio.seq.ProteinTools;
import org.biojava.bio.seq.RNATools;
/**
* Tests the CodonPrefTools class and
* the CodonPref functionality.
* @author David Huen
* @since 1.3
*/
public class SimpleCodonPrefTest extends TestCase
{
CodonPref testPref;
FiniteAlphabet aaAlfa = ProteinTools.getTAlphabet();
public SimpleCodonPrefTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
testPref = CodonPrefTools.getCodonPreference(CodonPrefTools.JUNIT);
assertNotNull(testPref);
}
public void testGetGeneticCode()
{
// get a copy of the genetic code and confirm
// correct one retrieved
ManyToOneTranslationTable prefGCode = testPref.getGeneticCode();
// retrieve the UNIVERSAL code and check
// that we have the same object
ManyToOneTranslationTable correctGCode = RNATools.getGeneticCode(TranslationTable.UNIVERSAL);
assertSame(prefGCode, correctGCode);
}
public void testGetFrequency()
{
// check that the sum is correct
try {
Distribution codonUse = testPref.getFrequency();
assertNotNull(codonUse);
// sum frequencies over all codons and check that it comes to one
FiniteAlphabet codons = RNATools.getCodonAlphabet();
double sum = 0.0;
for (Iterator codonI = codons.iterator(); codonI.hasNext(); ) {
sum += codonUse.getWeight((Symbol) codonI.next());
}
assertTrue( Math.abs(sum - 1.0) < 0.00001 );
// pick up a specific known frequency and check
SymbolList agc = RNATools.createRNA("agc");
Symbol testCodon = codons.getSymbol(agc.toList());
assertTrue(Math.abs(codonUse.getWeight(testCodon) - 0.0234375) < 0.0001);
}
catch (IllegalSymbolException ise) {
fail("IllegalSymbolException occurred on codon frequency lookup");
}
}
public void testGetFrequencyForSynonyms()
{
try {
// get synonyms for this residue
ManyToOneTranslationTable gCode = testPref.getGeneticCode();
for (Iterator residueI = ProteinTools.getTAlphabet().iterator(); residueI.hasNext(); ) {
Symbol residue = (Symbol) residueI.next();
// filter out selenocysteine!
if (residue.getName().equals("SEC")) continue;
// filter out pyrrolysine!
if (residue.getName().equals("PYL")) continue;
Distribution synonymUse = testPref.getFrequencyForSynonyms(residue);
assertNotNull(synonymUse);
// get set of synonyms
Set synonyms = gCode.untranslate(residue);
double sum = 0.0;
for (Iterator synonymsI = synonyms.iterator(); synonymsI.hasNext(); ) {
Symbol synonym = (Symbol) synonymsI.next();
sum += synonymUse.getWeight(synonym);
}
assertTrue(Math.abs(sum - 1.0) < 0.0001);
}
// check specific value: serine and agc
SymbolList serine = ProteinTools.createProtein("S");
assertNotNull(serine);
Distribution serineDist = testPref.getFrequencyForSynonyms(serine.symbolAt(1));
SymbolList agc = RNATools.createRNA("agc");
Symbol testCodon = RNATools.getCodonAlphabet().getSymbol(agc.toList());
assertTrue(Math.abs(serineDist.getWeight(testCodon) - 0.25) < 0.0001);
}
catch (IllegalSymbolException ise) {
fail("IllegalSymbolException occurred on codon frequency lookup");
}
}
public void testGetWobbleDistributionForSynonyms()
{
try {
// check that I can get back a WobbleDistribution
SymbolList serine = ProteinTools.createProtein("S");
assertNotNull(serine);
WobbleDistribution wobbleDist = testPref.getWobbleDistributionForSynonyms(serine.symbolAt(1));
assertNotNull(wobbleDist);
}
catch (IllegalSymbolException ise) {
fail("IllegalSymbolException occurred on wobble frequency lookup");
}
}
}
|