Added some methods to generate random bases or random base indexes, optionally disallowing the generation of a specified base or base index.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@943 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
13eb868536
commit
681e67c72c
|
|
@ -1,9 +1,9 @@
|
||||||
package org.broadinstitute.sting.utils;
|
package org.broadinstitute.sting.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaseUtils contains some basic utilities for manipulating nucleotides.
|
* BaseUtils contains some basic utilities for manipulating nucleotides.
|
||||||
*
|
|
||||||
* @author Kiran Garimella
|
|
||||||
*/
|
*/
|
||||||
public class BaseUtils {
|
public class BaseUtils {
|
||||||
|
|
||||||
|
|
@ -217,6 +217,51 @@ public class BaseUtils {
|
||||||
return ((double) baseCounts[mostFrequentBaseIndex])/((double) sequence.length);
|
return ((double) baseCounts[mostFrequentBaseIndex])/((double) sequence.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random base index (A=0, C=1, G=2, T=3).
|
||||||
|
*
|
||||||
|
* @return a random base index (A=0, C=1, G=2, T=3)
|
||||||
|
*/
|
||||||
|
static public int getRandomBaseIndex() {
|
||||||
|
return getRandomBaseIndex(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random base index, excluding some base index.
|
||||||
|
*
|
||||||
|
* @param excludeBaseIndex the base index to exclude
|
||||||
|
* @return a random base index, excluding the one specified (A=0, C=1, G=2, T=3)
|
||||||
|
*/
|
||||||
|
static public int getRandomBaseIndex(int excludeBaseIndex) {
|
||||||
|
int randomBaseIndex = excludeBaseIndex;
|
||||||
|
|
||||||
|
Random generator = new Random();
|
||||||
|
while (randomBaseIndex == excludeBaseIndex) {
|
||||||
|
randomBaseIndex = generator.nextInt(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomBaseIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random base (A, C, G, T).
|
||||||
|
*
|
||||||
|
* @return a random base (A, C, G, T)
|
||||||
|
*/
|
||||||
|
static public char getRandomBase() {
|
||||||
|
return getRandomBase('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random base, excluding some base.
|
||||||
|
*
|
||||||
|
* @param excludeBase the base to exclude
|
||||||
|
* @return a random base, excluding the one specified (A, C, G, T)
|
||||||
|
*/
|
||||||
|
static public char getRandomBase(char excludeBase) {
|
||||||
|
return BaseUtils.baseIndexToSimpleBase(getRandomBaseIndex(BaseUtils.simpleBaseToBaseIndex(excludeBase)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Computes the smallest period >= minPeriod for the specified string. The period is defined as such p,
|
/** Computes the smallest period >= minPeriod for the specified string. The period is defined as such p,
|
||||||
* that for all i = 0... seq.length-1, seq[ i % p ] = seq[i] (or equivalently seq[i] = seq[i+p] for i=0...seq.length-1-p).
|
* that for all i = 0... seq.length-1, seq[ i % p ] = seq[i] (or equivalently seq[i] = seq[i+p] for i=0...seq.length-1-p).
|
||||||
|
|
@ -261,7 +306,6 @@ public class BaseUtils {
|
||||||
}
|
}
|
||||||
return period;
|
return period;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* code snippet for testing sequencePeriod():
|
/* code snippet for testing sequencePeriod():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue