2009-04-13 08:46:23 +08:00
|
|
|
package org.broadinstitute.sting.utils;
|
|
|
|
|
|
2009-04-14 22:49:12 +08:00
|
|
|
/**
|
|
|
|
|
* BaseUtils contains some basic utilities for manipulating nucleotides.
|
|
|
|
|
*
|
|
|
|
|
* @author Kiran Garimella
|
|
|
|
|
*/
|
2009-04-13 08:46:23 +08:00
|
|
|
public class BaseUtils {
|
2009-04-14 22:49:12 +08:00
|
|
|
/**
|
|
|
|
|
* Converts a simple base to a base index
|
|
|
|
|
*
|
|
|
|
|
* @param base [AaCcGgTt]
|
|
|
|
|
* @return 0, 1, 2, 3, or -1 if the base can't be understood
|
|
|
|
|
*/
|
2009-04-13 08:46:23 +08:00
|
|
|
static public int simpleBaseToBaseIndex(char base) {
|
|
|
|
|
switch (base) {
|
|
|
|
|
case 'A':
|
|
|
|
|
case 'a': return 0;
|
|
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
|
case 'c': return 1;
|
|
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
|
case 'g': return 2;
|
|
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
|
case 't': return 3;
|
|
|
|
|
|
|
|
|
|
default: return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-14 22:49:12 +08:00
|
|
|
/**
|
|
|
|
|
* Converts a base index to a simple base
|
|
|
|
|
*
|
|
|
|
|
* @param baseIndex 0, 1, 2, 3
|
|
|
|
|
* @return A, C, G, T, or '.' if the index can't be understood
|
|
|
|
|
*/
|
2009-04-13 08:46:23 +08:00
|
|
|
static public char baseIndexToSimpleBase(int baseIndex) {
|
|
|
|
|
switch (baseIndex) {
|
|
|
|
|
case 0: return 'A';
|
|
|
|
|
case 1: return 'C';
|
|
|
|
|
case 2: return 'G';
|
|
|
|
|
case 3: return 'T';
|
|
|
|
|
default: return '.';
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-14 22:49:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a base index to a base index representing its cross-talk partner
|
|
|
|
|
*
|
|
|
|
|
* @param baseIndex 0, 1, 2, 3
|
|
|
|
|
* @return 1, 0, 3, 2, or -1 if the index can't be understood
|
|
|
|
|
*/
|
|
|
|
|
static public int crossTalkPartnerIndex(int baseIndex) {
|
|
|
|
|
switch (baseIndex) {
|
|
|
|
|
case 0: return 1; // A -> C
|
|
|
|
|
case 1: return 0; // C -> A
|
|
|
|
|
case 2: return 3; // G -> T
|
|
|
|
|
case 3: return 2; // T -> G
|
|
|
|
|
default: return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a base to the base representing its cross-talk partner
|
2009-04-22 06:25:33 +08:00
|
|
|
*
|
2009-04-14 22:49:12 +08:00
|
|
|
* @param base [AaCcGgTt]
|
|
|
|
|
* @return C, A, T, G, or '.' if the base can't be understood
|
|
|
|
|
*/
|
|
|
|
|
static public char crossTalkPartnerBase(char base) {
|
|
|
|
|
return baseIndexToSimpleBase(crossTalkPartnerIndex(simpleBaseToBaseIndex(base)));
|
|
|
|
|
}
|
2009-04-22 06:25:33 +08:00
|
|
|
|
|
|
|
|
static public byte simpleComplement(char base) {
|
|
|
|
|
switch (base) {
|
|
|
|
|
case 'A':
|
|
|
|
|
case 'a': return 'T';
|
|
|
|
|
case 'C':
|
|
|
|
|
case 'c': return 'G';
|
|
|
|
|
case 'G':
|
|
|
|
|
case 'g': return 'C';
|
|
|
|
|
case 'T':
|
|
|
|
|
case 't': return 'A';
|
|
|
|
|
default: return '.';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public byte[] simpleReverseComplement(byte[] bases) {
|
|
|
|
|
byte[] rcbases = new byte[bases.length];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < bases.length; i++) {
|
|
|
|
|
rcbases[i] = simpleComplement((char) bases[bases.length - 1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rcbases;
|
|
|
|
|
}
|
2009-04-13 08:46:23 +08:00
|
|
|
}
|