2013-01-11 06:04:08 +08:00
|
|
|
/*
|
2013-01-31 22:08:26 +08:00
|
|
|
* Copyright (c) 2012 The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
2013-01-11 06:04:08 +08:00
|
|
|
|
2013-01-31 01:54:57 +08:00
|
|
|
package org.broadinstitute.sting.utils;
|
2009-05-22 04:35:08 +08:00
|
|
|
|
2013-01-31 01:54:57 +08:00
|
|
|
import org.broadinstitute.sting.BaseTest;
|
2010-11-02 05:31:44 +08:00
|
|
|
import org.testng.Assert;
|
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
|
|
2009-05-22 04:35:08 +08:00
|
|
|
|
2013-01-31 01:54:57 +08:00
|
|
|
public class BaseUtilsUnitTest extends BaseTest {
|
2009-05-22 04:35:08 +08:00
|
|
|
@BeforeClass
|
2010-11-02 05:31:44 +08:00
|
|
|
public void init() { }
|
2009-05-22 04:35:08 +08:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testMostFrequentBaseFraction() {
|
2013-01-31 01:54:57 +08:00
|
|
|
logger.warn("Executing testMostFrequentBaseFraction");
|
|
|
|
|
|
2009-05-22 04:35:08 +08:00
|
|
|
compareFrequentBaseFractionToExpected("AAAAA", 1.0);
|
|
|
|
|
compareFrequentBaseFractionToExpected("ACCG", 0.5);
|
|
|
|
|
compareFrequentBaseFractionToExpected("ACCCCTTTTG", 4.0/10.0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-09 08:53:45 +08:00
|
|
|
private void compareFrequentBaseFractionToExpected(String sequence, double expected) {
|
|
|
|
|
double fraction = BaseUtils.mostFrequentBaseFraction(sequence.getBytes());
|
2013-01-31 01:54:57 +08:00
|
|
|
Assert.assertTrue(MathUtils.compareDoubles(fraction, expected) == 0);
|
2009-06-09 08:53:45 +08:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 23:22:43 +08:00
|
|
|
@Test
|
|
|
|
|
public void testConvertIUPACtoN() {
|
|
|
|
|
|
2013-01-17 04:05:49 +08:00
|
|
|
checkBytesAreEqual(BaseUtils.convertIUPACtoN(new byte[]{'A', 'A', 'A'}, false, false), new byte[]{'A', 'A', 'A'});
|
|
|
|
|
checkBytesAreEqual(BaseUtils.convertIUPACtoN(new byte[]{'W', 'A', 'A'}, false, false), new byte[]{'N', 'A', 'A'});
|
|
|
|
|
checkBytesAreEqual(BaseUtils.convertIUPACtoN(new byte[]{'A', 'M', 'A'}, false, false), new byte[]{'A', 'N', 'A'});
|
|
|
|
|
checkBytesAreEqual(BaseUtils.convertIUPACtoN(new byte[]{'A', 'A', 'K'}, false, false), new byte[]{'A', 'A', 'N'});
|
|
|
|
|
checkBytesAreEqual(BaseUtils.convertIUPACtoN(new byte[]{'M', 'M', 'M'}, false, false), new byte[]{'N', 'N', 'N'});
|
2013-01-16 23:22:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBytesAreEqual(final byte[] b1, final byte[] b2) {
|
|
|
|
|
for ( int i = 0; i < b1.length; i++ )
|
|
|
|
|
Assert.assertEquals(b1[i], b2[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-23 01:05:06 +08:00
|
|
|
@Test
|
|
|
|
|
public void testTransitionTransversion() {
|
2013-01-31 01:54:57 +08:00
|
|
|
logger.warn("Executing testTransitionTransversion");
|
|
|
|
|
|
2010-01-29 02:37:17 +08:00
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'G' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'C', (byte)'A' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'C', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'C', (byte)'G' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'T', (byte)'A' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'T', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'T', (byte)'G' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'G', (byte)'A' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'G', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'G', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
2009-05-23 01:05:06 +08:00
|
|
|
|
2010-01-29 02:37:17 +08:00
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'t' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'c' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'t' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
|
|
|
|
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'c' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
2009-05-23 01:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
2009-06-09 08:53:45 +08:00
|
|
|
@Test
|
|
|
|
|
public void testReverseComplementString() {
|
2013-01-31 01:54:57 +08:00
|
|
|
logger.warn("Executing testReverseComplementString");
|
|
|
|
|
|
2009-06-09 08:53:45 +08:00
|
|
|
compareRCStringToExpected("ACGGT", "ACCGT");
|
|
|
|
|
compareRCStringToExpected("TCGTATATCTCGCTATATATATATAGCTCTAGTATA", "TATACTAGAGCTATATATATATAGCGAGATATACGA");
|
|
|
|
|
compareRCStringToExpected("AAAN", "NTTT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void compareRCStringToExpected(String fw, String rcExp) {
|
|
|
|
|
String rcObs = BaseUtils.simpleReverseComplement(fw);
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(rcObs.equals(rcExp));
|
2009-05-22 04:35:08 +08:00
|
|
|
}
|
|
|
|
|
}
|